qemu-devel.nongnu.org archive mirror
 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, peterx@redhat.com, qemu-block@nongnu.org,
	leiyang@redhat.com, marcandre.lureau@redhat.com,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Stefano Garzarella <sgarzare@redhat.com>,
	Jason Wang <jasowang@redhat.com>,
	Michael Roth <michael.roth@amd.com>,
	Kostiantyn Kostiuk <kkostiuk@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>, Stefan Weil <sw@weilnetz.de>,
	Coiby Xu <Coiby.Xu@gmail.com>
Subject: Re: [PATCH v2 4/8] util: drop qemu_socket_set_nonblock()
Date: Fri, 12 Sep 2025 17:59:14 +0100	[thread overview]
Message-ID: <aMRRYhbRAnTu4Sew@redhat.com> (raw)
In-Reply-To: <20250911092007.1370002-5-vsementsov@yandex-team.ru>

On Thu, Sep 11, 2025 at 12:20:02PM +0300, Vladimir Sementsov-Ogievskiy wrote:
> Use common qemu_set_blocking() instead.
> 
> Note that pre-patch the behavior of Win32 and Linux realizations
> are inconsistent: we ignore failure for Win32, and assert success
> for Linux.
> 
> How do we convert the callers?

> 3. io/channel-socket.c: here we convert both old calls to
> qemu_socket_set_nonblock() and qemu_socket_set_block() to
> one new call. Pre-patch we assert success for Linux in
> qemu_socket_set_nonblock(), and ignore all other errors here.
> Still, all callers pass errp=NULL to qio_channel_set_blocking(),
> so after patch we ignore all errors. Switching from assertion
> to ignoring may be not very good, but still acceptable, keeping
> in mind that all callers of qio_channel_set_blocking() do
> explicitly ignore the error.

This is a bit questionable. IMHO the reason why nearly all
callers pass errp=NULL is laziness based on the assumption
that the code actually asserts, and no one thinking to check
the win impl which didn't asset.

IOW, I think we need a prior patch that sets the 'errp'
in all these callers, either to &error_abort, or to
propage the error if practical.

> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> Reviewed-by: Peter Xu <peterx@redhat.com>
> ---
>  contrib/ivshmem-server/ivshmem-server.c |  6 +++++-
>  hw/hyperv/syndbg.c                      |  4 +++-
>  hw/virtio/vhost-user.c                  |  5 ++++-
>  include/qemu/sockets.h                  |  1 -
>  io/channel-socket.c                     |  7 +++----
>  net/dgram.c                             | 16 +++++++++++++---
>  net/l2tpv3.c                            |  5 +++--
>  net/socket.c                            | 20 ++++++++++++++++----
>  qga/channel-posix.c                     |  7 ++++++-
>  tests/unit/socket-helpers.c             |  5 ++++-
>  tests/unit/test-crypto-tlssession.c     |  8 ++++----
>  util/oslib-posix.c                      |  7 -------
>  util/oslib-win32.c                      |  5 -----
>  util/vhost-user-server.c                |  4 ++--
>  14 files changed, 63 insertions(+), 37 deletions(-)
> 
> diff --git a/contrib/ivshmem-server/ivshmem-server.c b/contrib/ivshmem-server/ivshmem-server.c
> index 2f3c7320a6..a65943d0b8 100644
> --- a/contrib/ivshmem-server/ivshmem-server.c
> +++ b/contrib/ivshmem-server/ivshmem-server.c
> @@ -146,9 +146,13 @@ ivshmem_server_handle_new_conn(IvshmemServer *server)
>          return -1;
>      }
>  
> -    qemu_socket_set_nonblock(newfd);
>      IVSHMEM_SERVER_DEBUG(server, "accept()=%d\n", newfd);
>  
> +    if (!qemu_set_blocking(newfd, false, NULL)) {

&error_warn here so we diagnose the reason we're returning -1
to the caller ?

> +        close(newfd);
> +        return -1;
> +    }
> +
>      /* allocate new structure for this peer */
>      peer = g_malloc0(sizeof(*peer));
>      peer->sock_fd = newfd;

> diff --git a/tests/unit/socket-helpers.c b/tests/unit/socket-helpers.c
> index 37db24f72a..1b7e283f24 100644
> --- a/tests/unit/socket-helpers.c
> +++ b/tests/unit/socket-helpers.c
> @@ -88,7 +88,10 @@ static int socket_can_bind_connect(const char *hostname, int family)
>          goto cleanup;
>      }
>  
> -    qemu_socket_set_nonblock(cfd);
> +    if (!qemu_set_blocking(cfd, false, NULL)) {

&error_abort here.

> +        goto cleanup;
> +    }
> +
>      if (connect(cfd, (struct sockaddr *)&ss, sslen) < 0) {
>          if (errno == EINPROGRESS) {
>              check_soerr = true;
 
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-12 16:59 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-11  9:19 [PATCH v2 0/8] io: deal with blocking/non-blocking fds Vladimir Sementsov-Ogievskiy
2025-09-11  9:19 ` [PATCH v2 1/8] char-socket: tcp_chr_recv(): drop extra _set_(block, cloexec) Vladimir Sementsov-Ogievskiy
2025-09-12 16:49   ` [PATCH v2 1/8] char-socket: tcp_chr_recv(): drop extra _set_(block,cloexec) Daniel P. Berrangé
2025-09-11  9:20 ` [PATCH v2 2/8] char-socket: tcp_chr_recv(): add comment Vladimir Sementsov-Ogievskiy
2025-09-12 16:50   ` Daniel P. Berrangé
2025-09-11  9:20 ` [PATCH v2 3/8] util: add qemu_set_blocking() function Vladimir Sementsov-Ogievskiy
2025-09-12 16:51   ` Daniel P. Berrangé
2025-09-11  9:20 ` [PATCH v2 4/8] util: drop qemu_socket_set_nonblock() Vladimir Sementsov-Ogievskiy
2025-09-12 16:59   ` Daniel P. Berrangé [this message]
2025-09-15  8:07     ` Vladimir Sementsov-Ogievskiy
2025-09-15  8:09     ` Vladimir Sementsov-Ogievskiy
2025-09-11  9:20 ` [PATCH v2 5/8] util: drop qemu_socket_try_set_nonblock() Vladimir Sementsov-Ogievskiy
2025-09-12 17:00   ` Daniel P. Berrangé
2025-09-11  9:20 ` [PATCH v2 6/8] io/channel-socket: rework qio_channel_socket_copy_fds() Vladimir Sementsov-Ogievskiy
2025-09-12 17:05   ` Daniel P. Berrangé
2025-09-15  8:47     ` Vladimir Sementsov-Ogievskiy
2025-09-11  9:20 ` [PATCH v2 7/8] util: drop qemu_socket_set_block() Vladimir Sementsov-Ogievskiy
2025-09-12 17:06   ` Daniel P. Berrangé
2025-09-11  9:20 ` [PATCH v2 8/8] use qemu_set_blocking instead of g_unix_set_fd_nonblocking Vladimir Sementsov-Ogievskiy
2025-09-12 17:11   ` Daniel P. Berrangé
2025-09-15 10:04     ` Vladimir Sementsov-Ogievskiy
2025-09-11  9:22 ` [PATCH v2 0/8] io: deal with blocking/non-blocking fds Vladimir Sementsov-Ogievskiy

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=aMRRYhbRAnTu4Sew@redhat.com \
    --to=berrange@redhat.com \
    --cc=Coiby.Xu@gmail.com \
    --cc=jasowang@redhat.com \
    --cc=kkostiuk@redhat.com \
    --cc=leiyang@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=sw@weilnetz.de \
    --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 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 NNTP newsgroup(s).