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 03/13] iothread: tracking iothread users with holder name
Date: Mon, 9 Mar 2026 16:02:01 +0800	[thread overview]
Message-ID: <20260309080201.GB39949@fedora> (raw)
In-Reply-To: <20260305142459.52559-4-zhangckid@gmail.com>

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

On Thu, Mar 05, 2026 at 10:24:49PM +0800, Zhang Chen wrote:
> Introduce iothread_get_aio_context() with a 'holder' argument and its
> counterpart iothread_put_aio_context().
> 
> Previously, users of an IOThread's AioContext did not explicitly
> record their identity, making it difficult to debug which devices or
> subsystems were pinning an IOThread.
> 
> This patch enhances the reference counting mechanism by:
> 1. Automatically incrementing the object reference count when a context
>    is retrieved.
> 2. Tracking holders by name using iothread_ref() and iothread_unref().
> 
> In iothread_instance_finalize(), we now retrieve the source name from
> the GMainContext to correctly unref the initial internal holder.
> 
> Signed-off-by: Zhang Chen <zhangckid@gmail.com>
> ---
>  include/system/iothread.h |  3 ++-
>  iothread.c                | 28 ++++++++++++++++++++++++++--
>  2 files changed, 28 insertions(+), 3 deletions(-)
> 
> diff --git a/include/system/iothread.h b/include/system/iothread.h
> index 21a76bd70d..595abeefbe 100644
> --- a/include/system/iothread.h
> +++ b/include/system/iothread.h
> @@ -47,7 +47,8 @@ DECLARE_INSTANCE_CHECKER(IOThread, IOTHREAD,
>  
>  char *iothread_get_id(IOThread *iothread);
>  IOThread *iothread_by_id(const char *id);
> -AioContext *iothread_get_aio_context(IOThread *iothread);
> +AioContext *iothread_get_aio_context(IOThread *iothread, const char *holder);
> +void iothread_put_aio_context(IOThread *iothread, const char *holder);
>  GMainContext *iothread_get_g_main_context(IOThread *iothread);
>  
>  /*
> diff --git a/iothread.c b/iothread.c
> index 80a8cf4b32..da98fbb9ad 100644
> --- a/iothread.c
> +++ b/iothread.c
> @@ -172,7 +172,8 @@ static void iothread_init_gcontext(IOThread *iothread, const char *thread_name)
>      g_autofree char *name = g_strdup_printf("%s aio-context", thread_name);
>  
>      iothread->worker_context = g_main_context_new();
> -    source = aio_get_g_source(iothread_get_aio_context(iothread));
> +    /* No need setup itself as the init holder */
> +    source = aio_get_g_source(iothread_get_aio_context(iothread, NULL));

This is cleaner:

  source = aio_get_g_source(iothread->ctx);

That way iothread_get_aio_context() doesn't need a special case for
NULL.

>      g_source_set_name(source, name);
>      g_source_attach(source, iothread->worker_context);
>      g_source_unref(source);
> @@ -362,11 +363,34 @@ char *iothread_get_id(IOThread *iothread)
>      return g_strdup(object_get_canonical_path_component(OBJECT(iothread)));
>  }
>  
> -AioContext *iothread_get_aio_context(IOThread *iothread)
> +AioContext *iothread_get_aio_context(IOThread *iothread, const char *holder)
>  {
> +    /*
> +     * In some cases, iothread user need the ctx to clearup other resource.
> +     * When holder is empty, back to the legacy way.
> +     */
> +    if (holder) {
> +        /*
> +         * This guarantees that the IOThread and its AioContext remain alive
> +         * as long as there is a holder.
> +         */
> +        object_ref(OBJECT(iothread));

Can this be done in iothread_ref()/iothread_unref()? That would ensure
that callers always increment the QOM reference count regardless of
whether the iothread_ref() or iothread_get_aio_context() API is used.

> +
> +        /* Add holder device path to the list */
> +        iothread_ref(iothread, holder);
> +    }
> +
>      return iothread->ctx;
>  }
>  
> +void iothread_put_aio_context(IOThread *iothread, const char *holder)
> +{
> +    object_unref(OBJECT(iothread));
> +
> +    /* Delete holder device path from the list */
> +    iothread_unref(iothread, holder);
> +}
> +
>  static int query_one_iothread(Object *object, void *opaque)
>  {
>      IOThreadInfoList ***tail = opaque;
> -- 
> 2.49.0
> 

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

  reply	other threads:[~2026-03-09  8:02 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
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 [this message]
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=20260309080201.GB39949@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.