All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Tim Pambor <timpambor@gmail.com>
Cc: qemu-devel@nongnu.org, "Michael S. Tsirkin" <mst@redhat.com>,
	"Stefano Garzarella" <sgarzare@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Kevin Wolf" <kwolf@redhat.com>,
	"Hanna Reitz" <hreitz@redhat.com>,
	"Jason Wang" <jasowangio@gmail.com>,
	"Pierrick Bouvier" <pierrick.bouvier@oss.qualcomm.com>,
	qemu-block@nongnu.org, "Raphael Norwitz" <rnorwitz@nvidia.com>,
	"Brad Smith" <brad@comstyle.com>
Subject: Re: [PATCH 3/8] io/channel-socket: only clear O_NONBLOCK on received fds if set
Date: Mon, 26 Oct 2026 11:29:56 +0000	[thread overview]
Message-ID: <at85tCIzl2Buw6Yy@redhat.com> (raw)
In-Reply-To: <20261022-vhost-user-posix-v1-3-0bd4d450d23c@gmail.com>

On Thu, Oct 22, 2026 at 03:47:24PM +0200, Tim Pambor wrote:
> After receiving descriptors with SCM_RIGHTS the socket channel resets
> O_NONBLOCK on each of them with fcntl(F_SETFL).  macOS rejects F_SETFL
> on POSIX shared memory descriptors, so every message carrying such a
> descriptor caused the connection to drop.  Those descriptors are passed
> in blocking mode anyway, so there is nothing to change on them.  Query
> the flags with F_GETFL first and only issue F_SETFL when O_NONBLOCK is
> actually set.
> 
> Signed-off-by: Tim Pambor <timpambor@gmail.com>
> ---
>  io/channel-socket.c | 19 +++++++++++++++++--
>  1 file changed, 17 insertions(+), 2 deletions(-)
> 
> diff --git a/io/channel-socket.c b/io/channel-socket.c
> index 7920cee639..1785fd5bfe 100644
> --- a/io/channel-socket.c
> +++ b/io/channel-socket.c
> @@ -520,8 +520,23 @@ static bool qio_channel_handle_fds(int *fds, size_t nfds,
>          }
>  
>          if (!preserve_blocking) {
> -            /* O_NONBLOCK is preserved across SCM_RIGHTS so reset it */
> -            if (!qemu_set_blocking(*fd, true, errp)) {
> +            /*
> +             * O_NONBLOCK is preserved across SCM_RIGHTS so reset it.
> +             *
> +             * Some descriptors reject F_SETFL outright, e.g. POSIX
> +             * shared memory on macOS.  They are passed in blocking
> +             * mode anyway, so only touch descriptors that have it set.
> +             */
> +            int flags = fcntl(*fd, F_GETFL);
> +
> +            if (flags < 0) {
> +                error_setg_errno(errp, errno,
> +                                 "Can't get file descriptor %d flags", *fd);
> +                return false;
> +            }
> +
> +            if ((flags & O_NONBLOCK) &&
> +                !qemu_set_blocking(*fd, true, errp)) {

I'd be inclined to put this logic in qemu_set_blocking itself
so that it does the right thing for all possible callers.

At that point we might as well get rid of the use of
g_unix_set_fd_nonblocking in that function and directly call
fcntl so we avoid the duplicate F_GETFL calls, eg something more
like:

  int flags, newflags;
  flag = fcntl(fd, F_GETFL);
  if (flags < 0) {
     error_setg_errno(....)
     return -1;
  }

  if (nonblock)
    newflags = flags | O_NONBLOCK;
  else
    newflags = flags & ~O_NONBLOCK;

  if (newflags != flags &&
      fcntl(fd, F_SETFL, newflags) < 0) {
     error_setg_errno(...);
     return -1;
  }

With regards,
Daniel
-- 
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|



  reply	other threads:[~2026-10-26 11:30 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-22 13:47 [PATCH 0/8] vhost-user: another try at supporting any POSIX system Tim Pambor
2026-10-22 13:47 ` [PATCH 1/8] vhost-user: kick via event_notifier_set() Tim Pambor
2026-10-29 11:43   ` Stefano Garzarella
2026-10-22 13:47 ` [PATCH 2/8] libvhost-user: self-kick through a library-owned notifier Tim Pambor
2026-10-29 11:43   ` Stefano Garzarella
2026-10-22 13:47 ` [PATCH 3/8] io/channel-socket: only clear O_NONBLOCK on received fds if set Tim Pambor
2026-10-26 11:29   ` Daniel P. Berrangé [this message]
2026-10-22 13:47 ` [PATCH 4/8] chardev/char-socket: detect peer close portably Tim Pambor
2026-10-22 13:47 ` [PATCH 5/8] vhost-user: enable frontends on any POSIX system Tim Pambor
2026-10-27 19:24   ` Stefan Hajnoczi
2026-10-28  8:32     ` Stefano Garzarella
2026-10-28 12:33       ` Stefan Hajnoczi
2026-10-28 13:23         ` Stefano Garzarella
2026-10-28 18:43           ` Stefan Hajnoczi
2026-10-28 19:33             ` Tim Pambor
2026-10-29  9:05               ` Stefano Garzarella
2026-10-29 12:10               ` Stefan Hajnoczi
2026-10-22 13:47 ` [PATCH 6/8] libvhost-user: enable it " Tim Pambor
2026-10-22 13:47 ` [PATCH 7/8] contrib/vhost-user-blk: " Tim Pambor
2026-10-22 13:47 ` [PATCH 8/8] libvhost-user: detect memfd support with a link test Tim Pambor
2026-10-29 11:44   ` Stefano Garzarella
2026-10-23 16:00 ` [PATCH 0/8] vhost-user: another try at supporting any POSIX system Stefano Garzarella
2026-10-26  9:17   ` Tim Pambor

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=at85tCIzl2Buw6Yy@redhat.com \
    --to=berrange@redhat.com \
    --cc=brad@comstyle.com \
    --cc=hreitz@redhat.com \
    --cc=jasowangio@gmail.com \
    --cc=kwolf@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=pierrick.bouvier@oss.qualcomm.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rnorwitz@nvidia.com \
    --cc=sgarzare@redhat.com \
    --cc=timpambor@gmail.com \
    /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.