All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, peterx@redhat.com,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Gustavo Romero" <gustavo.romero@linaro.org>,
	"Stefano Garzarella" <sgarzare@redhat.com>,
	"Jason Wang" <jasowang@redhat.com>,
	"Michael Roth" <michael.roth@amd.com>,
	"Kostiantyn Kostiuk" <kkostiuk@redhat.com>,
	"Alexander Bulekov" <alxndr@bu.edu>,
	"Bandan Das" <bsd@redhat.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Fabiano Rosas" <farosas@suse.de>,
	"Darren Kenny" <darren.kenny@oracle.com>,
	"Qiuhao Li" <Qiuhao.Li@outlook.com>,
	"Laurent Vivier" <lvivier@redhat.com>
Subject: Re: [PATCH 07/10] use qemu_set_blocking instead of g_unix_set_fd_nonblocking
Date: Tue, 9 Sep 2025 10:15:56 +0100	[thread overview]
Message-ID: <aL_wTKuHCaTdDFRd@redhat.com> (raw)
In-Reply-To: <4b0de513-12fa-4891-8dde-82971efa4778@yandex-team.ru>

On Tue, Sep 09, 2025 at 12:11:19PM +0300, Vladimir Sementsov-Ogievskiy wrote:
> On 09.09.25 12:00, Daniel P. Berrangé wrote:
> > On Wed, Sep 03, 2025 at 12:44:07PM +0300, Vladimir Sementsov-Ogievskiy wrote:
> > > Instead of open-coded g_unix_set_fd_nonblocking() calls, use
> > > QEMU wrapper qemu_socket_set_nonblock().
> > > 
> > > Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> > > ---
> > >   chardev/char-fd.c                  |  4 ++--
> > >   chardev/char-pty.c                 |  3 +--
> > >   chardev/char-serial.c              |  3 +--
> > >   chardev/char-stdio.c               |  3 +--
> > >   hw/input/virtio-input-host.c       |  3 +--
> > >   hw/misc/ivshmem-flat.c             |  4 +++-
> > >   hw/misc/ivshmem-pci.c              |  8 +++++++-
> > >   hw/virtio/vhost-vsock.c            |  8 ++------
> > >   io/channel-command.c               |  9 ++++++---
> > >   io/channel-file.c                  |  3 +--
> > >   net/tap-bsd.c                      | 12 ++++++++++--
> > >   net/tap-linux.c                    |  8 +++++++-
> > >   net/tap-solaris.c                  |  7 ++++++-
> > >   net/tap.c                          | 21 ++++++---------------
> > >   qga/commands-posix.c               |  3 +--
> > >   tests/qtest/fuzz/virtio_net_fuzz.c |  2 +-
> > >   tests/qtest/vhost-user-test.c      |  3 +--
> > >   tests/unit/test-iov.c              |  5 +++--
> > >   ui/input-linux.c                   |  3 +--
> > >   util/event_notifier-posix.c        |  5 +++--
> > >   util/main-loop.c                   |  6 +++++-
> > >   21 files changed, 69 insertions(+), 54 deletions(-)
> > 
> > > diff --git a/io/channel-command.c b/io/channel-command.c
> > > index 8966dd3a2b..8ae9a026b3 100644
> > > --- a/io/channel-command.c
> > > +++ b/io/channel-command.c
> > > @@ -277,9 +277,12 @@ static int qio_channel_command_set_blocking(QIOChannel *ioc,
> > >       cioc->blocking = enabled;
> > >   #else
> > > -    if ((cioc->writefd >= 0 && !g_unix_set_fd_nonblocking(cioc->writefd, !enabled, NULL)) ||
> > > -        (cioc->readfd >= 0 && !g_unix_set_fd_nonblocking(cioc->readfd, !enabled, NULL))) {
> > > -        error_setg_errno(errp, errno, "Failed to set FD nonblocking");
> > > +    if (cioc->writefd >= 0 &&
> > > +        !qemu_set_blocking(cioc->writefd, enabled, errp)) {
> > > +        return -1;
> > > +    }
> > > +    if (cioc->readfd >= 0 &&
> > > +        !qemu_set_blocking(cioc->readfd, enabled, errp)) {
> > >           return -1;
> > >       }
> > >   #endif
> > > diff --git a/io/channel-file.c b/io/channel-file.c
> > > index ca3f180cc2..5cef75a67c 100644
> > > --- a/io/channel-file.c
> > > +++ b/io/channel-file.c
> > > @@ -223,8 +223,7 @@ static int qio_channel_file_set_blocking(QIOChannel *ioc,
> > >   #else
> > >       QIOChannelFile *fioc = QIO_CHANNEL_FILE(ioc);
> > > -    if (!g_unix_set_fd_nonblocking(fioc->fd, !enabled, NULL)) {
> > > -        error_setg_errno(errp, errno, "Failed to set FD nonblocking");
> > > +    if (!qemu_set_blocking(fioc->fd, enabled, errp)) {
> > >           return -1;
> > >       }
> > >       return 0;
> > 
> > This is wrong for Windows. fioc->fd is not a socket, but this is passing
> > it to an API whose impl assume it is receiving a socket.
> > 
> 
> But what is changed with the patch? g_unix_set_fd_nonblocking(fioc->fd, ..) is wrong for Windows as well.

Actually I missed the #ifdef. This code is in an #else branch that excludes
compilation on Wnidows - the Windows brach just raise an error.

> And making separate qemu_set_blocking() and qemu_socket_set_blocking(), which do the same
> thing, doesn't make sense..
> 
> Hmm. But we can define qemu_set_blocking() only for Linux, keeping qemu_socket_set_blocking() the generic
> function. Still, nothing prevents using qemu_socket_set_blocking() on non-sockets..

We just relying on the name of the function alerting the developer / reviewer.
If you're dealing with a FIFO pipe FD you are (hopefully) going to realize
that qemu_socket_XXX is not a function to be used.

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



  reply	other threads:[~2025-09-09  9:17 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-03  9:44 [PATCH 00/10] io: deal with blocking/non-blocking fds Vladimir Sementsov-Ogievskiy
2025-09-03  9:44 ` [PATCH 01/10] io/channel: document how qio_channel_readv_full() handles fds Vladimir Sementsov-Ogievskiy
2025-09-09  8:34   ` Daniel P. Berrangé
2025-09-03  9:44 ` [PATCH 02/10] char-socket: rework tcp_chr_recv() Vladimir Sementsov-Ogievskiy
2025-09-08 21:53   ` Peter Xu
2025-09-09  7:49     ` Vladimir Sementsov-Ogievskiy
2025-09-09  8:38   ` Daniel P. Berrangé
2025-09-09  8:46     ` Vladimir Sementsov-Ogievskiy
2025-09-03  9:44 ` [PATCH 03/10] util: add qemu_set_blocking() function Vladimir Sementsov-Ogievskiy
2025-09-08 22:02   ` Peter Xu
2025-09-09  7:51     ` Vladimir Sementsov-Ogievskiy
2025-09-09  8:59   ` Daniel P. Berrangé
2025-09-03  9:44 ` [PATCH 04/10] util: drop qemu_socket_set_nonblock() Vladimir Sementsov-Ogievskiy
2025-09-08 22:16   ` Peter Xu
2025-09-09  8:19     ` Vladimir Sementsov-Ogievskiy
2025-09-10  9:41       ` Daniel P. Berrangé
2025-09-10 10:32         ` Vladimir Sementsov-Ogievskiy
2025-09-10  9:44   ` Daniel P. Berrangé
2025-09-10 10:33     ` Vladimir Sementsov-Ogievskiy
2025-09-10 15:30       ` Vladimir Sementsov-Ogievskiy
2025-09-10 17:55     ` Vladimir Sementsov-Ogievskiy
2025-09-10 18:15       ` Daniel P. Berrangé
2025-09-10 18:52         ` Vladimir Sementsov-Ogievskiy
2025-09-12 14:51           ` Daniel P. Berrangé
2025-09-03  9:44 ` [PATCH 05/10] util: drop qemu_socket_try_set_nonblock() Vladimir Sementsov-Ogievskiy
2025-09-09  0:09   ` Peter Xu
2025-09-03  9:44 ` [PATCH 06/10] util: drop qemu_socket_set_block() Vladimir Sementsov-Ogievskiy
2025-09-03  9:44 ` [PATCH 07/10] use qemu_set_blocking instead of g_unix_set_fd_nonblocking Vladimir Sementsov-Ogievskiy
2025-09-09  9:00   ` Daniel P. Berrangé
2025-09-09  9:11     ` Vladimir Sementsov-Ogievskiy
2025-09-09  9:15       ` Daniel P. Berrangé [this message]
2025-09-09  9:50         ` Vladimir Sementsov-Ogievskiy
2025-09-10  9:32           ` Daniel P. Berrangé
2025-09-09 14:24   ` Stefan Hajnoczi
2025-09-03  9:44 ` [PATCH 08/10] oslib-posix: add qemu_fds_set_blocking() helper Vladimir Sementsov-Ogievskiy
2025-09-03  9:48   ` Vladimir Sementsov-Ogievskiy
2025-09-10  9:52   ` Daniel P. Berrangé
2025-09-10 10:42     ` Vladimir Sementsov-Ogievskiy
2025-09-03  9:44 ` [PATCH 09/10] qio_channel_readv_full(): move setting fd blocking to callers Vladimir Sementsov-Ogievskiy
2025-09-03  9:44 ` [PATCH 10/10] migration/qemu-file: don't make incoming fds blocking again Vladimir Sementsov-Ogievskiy
2025-09-03  9:47   ` Vladimir Sementsov-Ogievskiy
2025-09-04 14:35 ` [PATCH 00/10] io: deal with blocking/non-blocking fds Lei Yang
2025-09-09  8:12 ` Vladimir Sementsov-Ogievskiy
2025-09-09 14:25   ` Stefan Hajnoczi

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=aL_wTKuHCaTdDFRd@redhat.com \
    --to=berrange@redhat.com \
    --cc=Qiuhao.Li@outlook.com \
    --cc=alxndr@bu.edu \
    --cc=bsd@redhat.com \
    --cc=darren.kenny@oracle.com \
    --cc=farosas@suse.de \
    --cc=gustavo.romero@linaro.org \
    --cc=jasowang@redhat.com \
    --cc=kkostiuk@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=michael.roth@amd.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=sgarzare@redhat.com \
    --cc=stefanha@redhat.com \
    --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.