From: Stefano Brivio <sbrivio@redhat.com>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: passt-dev@passt.top
Subject: Re: [PATCH 1/6] tap: Split out handling of EPOLLIN events
Date: Tue, 3 Sep 2024 21:25:35 +0200 [thread overview]
Message-ID: <20240903212535.5c66fb90@elisabeth> (raw)
In-Reply-To: <20240903120235.1688429-2-david@gibson.dropbear.id.au>
On Tue, 3 Sep 2024 22:02:30 +1000
David Gibson <david@gibson.dropbear.id.au> wrote:
> Currently, tap_handler_pas{st,ta}() check for EPOLLRDHUP, EPOLLHUP and
> EPOLLERR events, then assume anything left is EPOLLIN. We have some future
> cases that may want to also handle EPOLLOUT, so in preparation explicitly
> handle EPOLLIN, moving the logic to a subfunction.
>
> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> tap.c | 50 ++++++++++++++++++++++++++++++++++++--------------
> 1 file changed, 36 insertions(+), 14 deletions(-)
>
> diff --git a/tap.c b/tap.c
> index 852d8376..14c88871 100644
> --- a/tap.c
> +++ b/tap.c
> @@ -982,24 +982,17 @@ static void tap_sock_reset(struct ctx *c)
> }
>
> /**
> - * tap_handler_passt() - Packet handler for AF_UNIX file descriptor
> + * tap_passt_input() - Handler for new data on the socket to qemu
> * @c: Execution context
> - * @events: epoll events
> * @now: Current timestamp
> */
> -void tap_handler_passt(struct ctx *c, uint32_t events,
> - const struct timespec *now)
> +static void tap_passt_input(struct ctx *c, const struct timespec *now)
> {
> static const char *partial_frame;
> static ssize_t partial_len = 0;
> ssize_t n;
> char *p;
>
> - if (events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR)) {
> - tap_sock_reset(c);
> - return;
> - }
> -
> tap_flush_pools();
>
> if (partial_len) {
> @@ -1052,20 +1045,33 @@ void tap_handler_passt(struct ctx *c, uint32_t events,
> }
>
> /**
> - * tap_handler_pasta() - Packet handler for /dev/net/tun file descriptor
> + * tap_handler_passt() - Event handler for AF_UNIX file descriptor
> * @c: Execution context
> * @events: epoll events
> * @now: Current timestamp
> */
> -void tap_handler_pasta(struct ctx *c, uint32_t events,
> +void tap_handler_passt(struct ctx *c, uint32_t events,
> const struct timespec *now)
> +{
> + if (events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR)) {
> + tap_sock_reset(c);
> + return;
> + }
> +
> + if (events & EPOLLIN)
> + tap_passt_input(c, now);
> +}
> +
> +/**
> + * tap_passt_input() - Handler for new data on the socket to qemu
tap_pasta_input(), QEMU (we could just call it hypervisor, given that
libkrun/krun also use this path).
> + * @c: Execution context
> + * @now: Current timestamp
> + */
> +static void tap_pasta_input(struct ctx *c, const struct timespec *now)
> {
> ssize_t n, len;
> int ret;
>
> - if (events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR))
> - die("Disconnect event on /dev/net/tun device, exiting");
> -
> redo:
> n = 0;
>
> @@ -1102,6 +1108,22 @@ restart:
> die("Error on tap device, exiting");
> }
>
> +/**
> + * tap_handler_pasta() - Packet handler for /dev/net/tun file descriptor
> + * @c: Execution context
> + * @events: epoll events
> + * @now: Current timestamp
> + */
> +void tap_handler_pasta(struct ctx *c, uint32_t events,
> + const struct timespec *now)
> +{
> + if (events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR))
> + die("Disconnect event on /dev/net/tun device, exiting");
> +
> + if (events & EPOLLIN)
> + tap_pasta_input(c, now);
> +}
> +
> /**
> * tap_sock_unix_open() - Create and bind AF_UNIX socket
> * @sock_path: Socket path. If empty, set on return (UNIX_SOCK_PATH as prefix)
--
Stefano
next prev parent reply other threads:[~2024-09-03 19:25 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-03 12:02 [PATCH 0/6] RFC: Clean up tap-side event handling David Gibson
2024-09-03 12:02 ` [PATCH 1/6] tap: Split out handling of EPOLLIN events David Gibson
2024-09-03 19:25 ` Stefano Brivio [this message]
2024-09-04 1:17 ` David Gibson
2024-09-03 12:02 ` [PATCH 2/6] tap: Improve handling of EINTR in tap_passt_input() David Gibson
2024-09-03 19:25 ` Stefano Brivio
2024-09-04 1:30 ` David Gibson
2024-09-03 12:02 ` [PATCH 3/6] tap: Restructure in tap_pasta_input() David Gibson
2024-09-03 19:25 ` Stefano Brivio
2024-09-04 1:33 ` David Gibson
2024-09-03 12:02 ` [PATCH 4/6] tap: Don't risk truncating frames on full buffer " David Gibson
2024-09-03 19:25 ` Stefano Brivio
2024-09-04 1:33 ` David Gibson
2024-09-03 12:02 ` [PATCH 5/6] tap: Re-introduce EPOLLET for tap connections David Gibson
2024-09-03 19:25 ` Stefano Brivio
2024-09-04 1:36 ` David Gibson
2024-09-03 12:02 ` [PATCH 6/6] tap: Stub EPOLLOUT handling David Gibson
2024-09-03 19:25 ` [PATCH 0/6] RFC: Clean up tap-side event handling Stefano Brivio
2024-09-04 3:17 ` David Gibson
2024-09-04 17:19 ` Stefano Brivio
2024-09-05 0:35 ` David Gibson
2024-09-05 8:32 ` Stefano Brivio
2024-09-05 11:33 ` Stefano Brivio
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240903212535.5c66fb90@elisabeth \
--to=sbrivio@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).