All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Guillaume Vincke <guillaume.vincke@ovhcloud.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org,
	 Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>,
	Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>
Subject: Re: [PATCH 1/2] nbd/client-connection: Fix client returning a closed channel
Date: Fri, 25 Sep 2026 16:00:06 -0500	[thread overview]
Message-ID: <arbf-WK4eJCeNX35@redhat.com> (raw)
In-Reply-To: <20260925155346.357703-2-guillaume.vincke@ovhcloud.com>

On Fri, Sep 25, 2026 at 05:53:45PM +0200, Guillaume Vincke wrote:
> When a server closes the connection after a successful handshake but
> before running any operations, the channel returned by
> nbd_co_establish_connection() is the closed one and the connect thread
> is not started.
> 
> When configured with reconnect-delay=0 (the default), this situation
> generates at least two IO errors. The first one happens when trying to
> issue an operation to the closed socket. The connect thread will be
> started on the next request, which may happen long after, and will
> create the second error as nbd_co_establish_connection() returns a NULL
> channel.
> 
> Peeking the channel to detect FIN or RST avoids the first IO error and
> does not delay the starting of the connect thread.
> 
> Signed-off-by: Guillaume Vincke <guillaume.vincke@ovhcloud.com>
> ---
>  nbd/client-connection.c | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
> 
> diff --git a/nbd/client-connection.c b/nbd/client-connection.c
> index 6a4f080717..878219fede 100644
> --- a/nbd/client-connection.c
> +++ b/nbd/client-connection.c
> @@ -274,6 +274,26 @@ void nbd_client_connection_release(NBDClientConnection *conn)
>      }
>  }
>  
> +/* only true when the peer closed the channel. Does not detect if dead */

For consistent style, I would use

/* Only true when the peer closed the channel. Does not detect if dead. */

> +static bool nbd_channel_is_closed(QIOChannel *ioc)
> +{
> +    char data;
> +    struct iovec iov = { .iov_base = &data, .iov_len = 1 };
> +    ssize_t len = -1;
> +
> +    if (!qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_READ_MSG_PEEK)) {
> +        return false;
> +    }
> +
> +    len = qio_channel_readv_full(
> +        ioc, &iov, 1, NULL, NULL, QIO_CHANNEL_READ_FLAG_MSG_PEEK, NULL);
> +
> +    if (len == 0 || (len < 0 && len != QIO_CHANNEL_ERR_BLOCK)) {
> +        return true;
> +    }
> +    return false;

The last group could be shortened to:

   return len == 0 || (len < 0 && len != QIO_CHANNEL_ERR_BLOCK);

but that is not mandatory.

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org



  reply	other threads:[~2026-09-25 21:02 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-25 15:53 [PATCH 0/2] nbd/client-connection: Fix client returning a closed channel Guillaume Vincke
2026-09-25 15:53 ` [PATCH 1/2] " Guillaume Vincke
2026-09-25 21:00   ` Eric Blake [this message]
2026-09-28  8:23     ` guillaume vincke
2026-10-06 19:13       ` Eric Blake
2026-10-07 12:47         ` guillaume vincke
2026-09-25 15:53 ` [PATCH 2/2] iotests: Add coverage for NBD connect thread start delay Guillaume Vincke
2026-10-05 18:44   ` Eric Blake
2026-10-05 19:29     ` Eric Blake

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=arbf-WK4eJCeNX35@redhat.com \
    --to=eblake@redhat.com \
    --cc=guillaume.vincke@ovhcloud.com \
    --cc=hreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@yandex-team.ru \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.