On Mon, May 18, 2026 at 7:58 PM Markus Armbruster <[email protected]> wrote:
>
> Stefan Hajnoczi <[email protected]> writes:
>
> > On Mon, May 11, 2026 at 10:04:04PM +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.
> >> - 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.
> >>
> >> A later commit will add QMP commands to let management applications
> >> query the attachment status of IOThreads.
> >>
> >> Signed-off-by: Zhang Chen <[email protected]>
> >> ---
> >> include/system/iothread.h | 5 +++
> >> iothread.c | 67 +++++++++++++++++++++++++++++++++++++++
> >> qapi/misc.json | 48 ++++++++++++++++++++++++++++
> >> 3 files changed, 120 insertions(+)
> >>
> >> diff --git a/include/system/iothread.h b/include/system/iothread.h
> >> index a1ef7696cb..2871b06edc 100644
> >> --- a/include/system/iothread.h
> >> +++ b/include/system/iothread.h
> >> @@ -50,6 +50,11 @@ struct IOThread {
> >> bool stopping; /* has iothread_stop() been called? */
> >> bool running; /* should iothread_run() continue? */
> >> int thread_id;
> >> + /*
> >> + * The list elements are of type IoThreadHolder, which can
> >> + * represent either a QOM path or a block node name.
> >> + */
> >> + GList *holders;
> >>
> >> /* AioContext poll parameters */
> >> int64_t poll_max_ns;
> >> diff --git a/iothread.c b/iothread.c
> >> index 3558535b40..b805e4f97d 100644
> >> --- a/iothread.c
> >> +++ b/iothread.c
> >> @@ -25,6 +25,66 @@
> >> #include "qemu/rcu.h"
> >> #include "qemu/main-loop.h"
> >>
> >> +/*
> >> + * Add the @holder path to the iothread's tracking list.
> >> + * The @holder is a QOM path if it starts with '/', else a block node
> >> name.
> >> + */
> >
> > It would be cleaner to use IoThreadHolder in the iothread_ref() and
> > iothread_unref() APIs instead of a string:
> >
> > static void iothread_ref(IOThread *iothread, const IoThreadHolder
> > *holder);
> > static void iothread_unref(IOThread *iothread, const IoThreadHolder
> > *holder);
> >
> > That way the caller already uses IO_THREAD_HOLDER_KIND_QOM_OBJECT or
> > IO_THREAD_HOLDER_KIND_BLOCK_NODE to clearly distinguish QOM paths from
> > block node names. No string parsing is necessary.
>
> Exactly.
>
Please double-check the details:
We need every caller init its own IOThreadHolder then pass to the
AioContext *iothread_ref_and_get_aio_context(IOThread *iothread,
const IoThreadHolder *holder)
Like this:
IOThreadHolder holder = {
.type = IO_THREAD_HOLDER_KIND_QOM_OBJECT,
.u.qom_object.data = (char *)virtio_blk_path,
};
new_context = iothread_ref_and_get_aio_context(iothread, &holder);
Thanks
Chen
> [...]
>