public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: passt-dev@passt.top
Subject: Re: [PATCH 2/6] tap: Improve handling of EINTR in tap_passt_input()
Date: Tue, 3 Sep 2024 21:25:39 +0200	[thread overview]
Message-ID: <20240903212539.1cb1adb3@elisabeth> (raw)
In-Reply-To: <20240903120235.1688429-3-david@gibson.dropbear.id.au>

On Tue,  3 Sep 2024 22:02:31 +1000
David Gibson <david@gibson.dropbear.id.au> wrote:

> When tap_passt_input() gets an error from recv() it (correctly) does not
> print any error message for EINTR, EAGAIN or EWOULDBLOCK.  However in all
> three cases it returns from the function.  That makes sense for EAGAIN and
> EWOULDBLOCK, since we then want to wait for the next EPOLLIN event before
> trying again.  For EINTR, however, it makes more sense to retry immediately
> - as it stands we're likely to get a renewer EPOLLIN event immediately in
> that case, since we're using level triggered signalling.
> 
> So, handle EINTR separately by immediately retrying until we succeed or
> get a different type of error.

I don't see an actual improvement: we don't know why we would get EINTR
(because of signals) so repeating the recv() right away isn't
necessarily a better choice.

I'd say whatever way we have of carrying on on EINTR is fine. If this
patch helps with brevity for the next ones, it makes sense, but
otherwise I don't see a real advantage.

Well, it's more consistent with the way we handle EINTR on other calls,
but that's about it.

> 
> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> ---
>  tap.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/tap.c b/tap.c
> index 14c88871..9ee59faa 100644
> --- a/tap.c
> +++ b/tap.c
> @@ -1003,10 +1003,13 @@ static void tap_passt_input(struct ctx *c, const struct timespec *now)
>  		memmove(pkt_buf, partial_frame, partial_len);
>  	}
>  
> -	n = recv(c->fd_tap, pkt_buf + partial_len, TAP_BUF_BYTES - partial_len,
> -		 MSG_DONTWAIT);
> +	do {
> +		n = recv(c->fd_tap, pkt_buf + partial_len,
> +			 TAP_BUF_BYTES - partial_len, MSG_DONTWAIT);
> +	} while ((n < 0) && errno == EINTR);
> +
>  	if (n < 0) {
> -		if (errno != EINTR && errno != EAGAIN && errno != EWOULDBLOCK) {
> +		if (errno != EAGAIN && errno != EWOULDBLOCK) {
>  			err_perror("Receive error on guest connection, reset");
>  			tap_sock_reset(c);
>  		}

-- 
Stefano


  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
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 [this message]
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=20240903212539.1cb1adb3@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).