All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: Zhang Chen <zhangckid@gmail.com>
Cc: qemu-devel <qemu-devel@nongnu.org>,
	"Dr . David Alan Gilbert" <dave@treblig.org>,
	Eric Blake <eblake@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	"Michael S . Tsirkin" <mst@redhat.com>
Subject: Re: [PATCH V5 02/13] iothread: introduce iothread_ref/unref to track attached devices
Date: Mon, 9 Mar 2026 15:49:35 +0800	[thread overview]
Message-ID: <20260309074935.GA39949@fedora> (raw)
In-Reply-To: <20260305142459.52559-3-zhangckid@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3432 bytes --]

On Thu, Mar 05, 2026 at 10:24:48PM +0800, Zhang Chen wrote:
> Currently, IOThreads do not maintain a record of which devices are
> associated with them. This makes it difficult to monitor the
> workload distribution of IOThreads, especially in complex
> hotplug scenarios involving multiple virtio-blk or virtio-scsi devices.
> 
> This patch introduces a reference counting and tracking mechanism
> within the IOThread object:
> 
> - iothread_ref(): Prepends the device's QOM path to a list.
>   Note: The IOThread takes ownership of the passed 'holder' string.

This is outdated, the patch duplicates the string and the caller still
owns the holder argument:

  iothread->holders = g_list_prepend(iothread->holders, g_strdup(holder));

> - iothread_unref(): Searches for the device path using a custom
>   string comparison (g_strcmp0), releases the associated memory
>   upon a successful match.
> - holders: A GList storing the QOM paths of attached devices
>   for runtime introspection.
> 
> This infrastructure allows management tools and QMP commands to
> query the attachment status of IOThreads.
> 
> Signed-off-by: Zhang Chen <zhangckid@gmail.com>
> ---
>  include/system/iothread.h |  1 +
>  iothread.c                | 28 ++++++++++++++++++++++++++++
>  2 files changed, 29 insertions(+)
> 
> diff --git a/include/system/iothread.h b/include/system/iothread.h
> index e26d13c6c7..21a76bd70d 100644
> --- a/include/system/iothread.h
> +++ b/include/system/iothread.h
> @@ -33,6 +33,7 @@ struct IOThread {
>      bool stopping;              /* has iothread_stop() been called? */
>      bool running;               /* should iothread_run() continue? */
>      int thread_id;
> +    GList *holders;             /* an array of QOM paths for attached devices */
>  
>      /* AioContext poll parameters */
>      int64_t poll_max_ns;
> diff --git a/iothread.c b/iothread.c
> index caf68e0764..80a8cf4b32 100644
> --- a/iothread.c
> +++ b/iothread.c
> @@ -36,6 +36,34 @@
>  #define IOTHREAD_POLL_MAX_NS_DEFAULT 0ULL
>  #endif
>  
> +/*
> + * Add holder device path to the list.
> + */
> +static void iothread_ref(IOThread *iothread, const char *holder)
> +{
> +    iothread->holders = g_list_prepend(iothread->holders, g_strdup(holder));
> +}
> +
> +/*
> + * Delete holder device path from the list.
> + */
> +static void iothread_unref(IOThread *iothread, const char *holder)
> +{
> +    if (iothread->holders) {

g_list_find_customer(NULL, ...) returns NULL rather than crashing, so
there is no need for if (iothread->holders).

> +        GList *link = g_list_find_custom(iothread->holders, holder,
> +                                         (GCompareFunc)g_strcmp0);
> +
> +        if (link) {

assert(link) is usually used in QEMU instead. If the reference has
already been released then the program is in an invalid state and it's
not safe to continue running.

Please also add assert(iothread->holders == NULL) to
iothread_instance_finalize() so that leaked references are caught.

> +            g_free(link->data);
> +            iothread->holders = g_list_delete_link(iothread->holders, link);
> +        } else {
> +            error_report("iothread_unref can't find the holder %s", holder);
> +        }
> +    } else {
> +        error_report("iohtread_unref iothread is not held by any devices");

iohtread -> iothread

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2026-03-09  7:50 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-05 14:24 [PATCH V5 00/13] iothread: Support tracking and querying IOThread holders Zhang Chen
2026-03-05 14:24 ` [PATCH V5 01/13] qapi/misc: Fix missed query-iothreads items Zhang Chen
2026-03-05 14:24 ` [PATCH V5 02/13] iothread: introduce iothread_ref/unref to track attached devices Zhang Chen
2026-03-09  7:49   ` Stefan Hajnoczi [this message]
2026-03-10  9:49     ` Zhang Chen
2026-03-05 14:24 ` [PATCH V5 03/13] iothread: tracking iothread users with holder name Zhang Chen
2026-03-09  8:02   ` Stefan Hajnoczi
2026-03-10  9:49     ` Zhang Chen
2026-03-09  8:33   ` Stefan Hajnoczi
2026-03-10  9:51     ` Zhang Chen
2026-03-05 14:24 ` [PATCH V5 04/13] blockdev: Update " Zhang Chen
2026-03-09  8:15   ` Stefan Hajnoczi
2026-03-10 10:02     ` Zhang Chen
2026-03-12  5:24       ` Stefan Hajnoczi
2026-03-12  7:05         ` Zhang Chen
2026-03-12  7:44           ` Stefan Hajnoczi
2026-03-12  9:16         ` Markus Armbruster
2026-03-17 13:25           ` Zhang Chen
2026-03-18  6:19             ` Markus Armbruster
2026-03-18  9:13               ` Stefan Hajnoczi
2026-03-30  3:13                 ` Zhang Chen
2026-03-30  9:02                   ` Markus Armbruster
2026-03-30 13:31                     ` Stefan Hajnoczi
2026-03-30 17:43                       ` Zhang Chen
2026-03-30 17:52                         ` Stefan Hajnoczi
2026-03-30 18:58                           ` Zhang Chen
2026-03-31  5:14                         ` Markus Armbruster
2026-03-05 14:24 ` [PATCH V5 05/13] virtio-vq-mapping: track iothread-vq-mapping references using device path Zhang Chen
2026-03-09  8:21   ` Stefan Hajnoczi
2026-03-10 10:03     ` Zhang Chen
2026-03-05 14:24 ` [PATCH V5 06/13] virtio: use iothread_get/put_aio_context for thread pinning Zhang Chen
2026-03-09  8:27   ` Stefan Hajnoczi
2026-03-10 10:07     ` Zhang Chen
2026-03-05 14:24 ` [PATCH V5 07/13] net/colo: track IOThread references using path-based holder Zhang Chen
2026-03-09  8:44   ` Stefan Hajnoczi
2026-03-10 10:15     ` Zhang Chen
2026-03-12  5:36       ` Stefan Hajnoczi
2026-03-12  6:31         ` Zhang Chen
2026-03-12  7:36           ` Stefan Hajnoczi
2026-03-12  8:45             ` Zhang Chen
2026-03-05 14:24 ` [PATCH V5 08/13] block/export: Update tracking iothread users with holder name Zhang Chen
2026-03-09  8:52   ` Stefan Hajnoczi
2026-03-05 14:24 ` [PATCH V5 09/13] monitor: " Zhang Chen
2026-03-09  8:56   ` Stefan Hajnoczi
2026-03-10 10:24     ` Zhang Chen
2026-03-05 14:24 ` [PATCH V5 10/13] virtio-balloon: " Zhang Chen
2026-03-05 14:24 ` [PATCH V5 11/13] vfio-user/proxy: " Zhang Chen
2026-03-05 14:24 ` [PATCH V5 12/13] xen-block: " Zhang Chen
2026-03-05 14:24 ` [PATCH V5 13/13] qapi: examine IOThread attachment status via query-iothreads Zhang Chen
2026-03-18  6:09   ` Markus Armbruster
2026-03-18 13:25     ` Zhang Chen

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=20260309074935.GA39949@fedora \
    --to=stefanha@redhat.com \
    --cc=armbru@redhat.com \
    --cc=dave@treblig.org \
    --cc=eblake@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=zhangckid@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.