qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, kwolf@redhat.com,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Peter Xu" <peterx@redhat.com>, "Fabiano Rosas" <farosas@suse.de>
Subject: Re: [PATCH v2 08/12] qio: Provide accessor around QIONetListener->sioc
Date: Tue, 11 Nov 2025 14:15:56 +0000	[thread overview]
Message-ID: <aRNFHAvkloB41tPr@redhat.com> (raw)
In-Reply-To: <20251108230525.3169174-22-eblake@redhat.com>

On Sat, Nov 08, 2025 at 04:59:29PM -0600, Eric Blake wrote:
> An upcoming patch needs to pass more than just sioc as the opaque
> pointer to an AioContext; but since our AioContext code in general
> (and its QIO Channel wrapper code) lacks a notify callback present
> with GSource, we do not have the trivial option of just g_malloc'ing a
> small struct to hold all that data coupled with a notify of g_free.
> Instead, the data pointer must outlive the registered handler; in
> fact, having the data pointer have the same lifetime as QIONetListener
> is adequate.
> 
> But the cleanest way to stick such a helper struct in QIONetListener
> will be to rearrange internal struct members.  And that in turn means
> that all existing code that currently directly accesses
> listener->nsioc and listener->sioc[] should instead go through
> accessor functions, to be immune to the upcoming struct layout
> changes.  So this patch adds accessor methods qio_net_listener_nsioc()
> and qio_net_listener_sioc(), and puts them to use.
> 
> Signed-off-by: Eric Blake <eblake@redhat.com>
> 
> ---
> v2: new patch
> ---
>  include/io/net-listener.h | 24 ++++++++++++++++++++++++
>  chardev/char-socket.c     |  3 ++-
>  io/net-listener.c         | 12 ++++++++++++
>  migration/socket.c        |  5 +++--
>  ui/vnc.c                  | 36 +++++++++++++++++++++++-------------
>  5 files changed, 64 insertions(+), 16 deletions(-)
> 
> diff --git a/include/io/net-listener.h b/include/io/net-listener.h
> index 42fbfab5467..2605d6aae1e 100644
> --- a/include/io/net-listener.h
> +++ b/include/io/net-listener.h
> @@ -184,4 +184,28 @@ void qio_net_listener_disconnect(QIONetListener *listener);
>   */
>  bool qio_net_listener_is_connected(QIONetListener *listener);
> 
> +
> +/**
> + * qio_net_listener_nsioc:
> + * @listener: the network listener object
> + *
> + * Determine the number of listener channels currently owned by the
> + * given listener.
> + *
> + * Returns: number of channels, or 0 if not listening
> + */
> +size_t qio_net_listener_nsioc(QIONetListener *listener);
> +
> +
> +/**
> + * qio_net_listener_sioc:
> + * @listener: the network listener object
> + * @n: index of the sioc to grab
> + *
> + * Accessor for the nth sioc owned by the listener.
> + *
> + * Returns: the requested listener, or #NULL if not in bounds
> + */
> +QIOChannelSocket *qio_net_listener_sioc(QIONetListener *listener, size_t n);
> +
>  #endif /* QIO_NET_LISTENER_H */
> diff --git a/chardev/char-socket.c b/chardev/char-socket.c
> index 62852e3caf5..022ae47d726 100644
> --- a/chardev/char-socket.c
> +++ b/chardev/char-socket.c
> @@ -1255,7 +1255,8 @@ static int qmp_chardev_open_socket_server(Chardev *chr,
>      }
> 
>      qapi_free_SocketAddress(s->addr);
> -    s->addr = socket_local_address(s->listener->sioc[0]->fd, errp);
> +    s->addr = socket_local_address(qio_net_listener_sioc(s->listener, 0)->fd,
> +                                   errp);

Oh pre-existing bug / undesirable code pattern. This should be calling
qio_channel_socket_get_local_address, which avoids the needs to re-call
getsockname() as QIOChanelSocket has cached the local address.

Once we do that, then we would have 4 cases in this patch doing

            qio_channel_socket_get_local_address(
                qio_net_listener_sioc(listener, i), errp);

which would suggest adding a helper we could call as

      qio_net_listener_get_local_address(listener, i, errp)



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 :|



  parent reply	other threads:[~2025-11-11 14:17 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-08 22:59 [PATCH v2 00/12] Fix deadlock with bdrv_open of self-served NBD Eric Blake
2025-11-08 22:59 ` [PATCH v2 01/12] iotests: Drop execute permissions on vvfat.out Eric Blake
2025-11-10 15:57   ` Daniel P. Berrangé
2025-11-08 22:59 ` [PATCH v2 02/12] qio: Add trace points to net_listener Eric Blake
2025-11-10 15:58   ` Daniel P. Berrangé
2025-11-08 22:59 ` [PATCH v2 03/12] qio: Unwatch before notify in QIONetListener Eric Blake
2025-11-10 16:00   ` Daniel P. Berrangé
2025-11-08 22:59 ` [PATCH v2 04/12] qio: Remember context of qio_net_listener_set_client_func_full Eric Blake
2025-11-10 16:08   ` Daniel P. Berrangé
2025-11-08 22:59 ` [PATCH v2 05/12] qio: Minor optimization when callback function is unchanged Eric Blake
2025-11-10 16:09   ` Daniel P. Berrangé
2025-11-08 22:59 ` [PATCH v2 06/12] qio: Factor out helpers qio_net_listener_[un]watch Eric Blake
2025-11-10 16:14   ` Daniel P. Berrangé
2025-11-08 22:59 ` [PATCH v2 07/12] qio: Hoist ref of listener outside loop Eric Blake
2025-11-11 14:43   ` Daniel P. Berrangé
2025-11-08 22:59 ` [PATCH v2 08/12] qio: Provide accessor around QIONetListener->sioc Eric Blake
2025-11-10 18:31   ` Eric Blake
2025-11-11 14:15   ` Daniel P. Berrangé [this message]
2025-11-08 22:59 ` [PATCH v2 09/12] qio: Prepare NetListener to use AioContext Eric Blake
2025-11-11 14:17   ` Daniel P. Berrangé
2025-11-08 22:59 ` [PATCH v2 10/12] qio: Add QIONetListener API for using AioContext Eric Blake
2025-11-11 14:18   ` Daniel P. Berrangé
2025-11-08 22:59 ` [PATCH v2 11/12] nbd: Avoid deadlock in client connecting to same-process server Eric Blake
2025-11-11 14:20   ` Daniel P. Berrangé
2025-11-08 22:59 ` [PATCH v2 12/12] iotests: Add coverage of recent NBD qio deadlock fix Eric Blake
2025-11-10 16:19   ` Daniel P. Berrangé
2025-11-12  6:35   ` 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=aRNFHAvkloB41tPr@redhat.com \
    --to=berrange@redhat.com \
    --cc=eblake@redhat.com \
    --cc=farosas@suse.de \
    --cc=kwolf@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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).