On Mon, Jan 26, 2026 at 4:52 AM Zhang Chen <[email protected]> wrote:
>
> The attached flag depends on struct IOThreadInfo's
> 'attached': 'bool'. It can show whether the iothread
> is attached to an actual device. Show in the qmp/hmp
> CMD with "attached": true/false.

I mentioned that a ref/unref API is needed in my reply to Patch 2/3.
The API could look like:

void iothread_ref(IOThread *iothread, const char *holder);

And the holder string is added to a list inside iothread. That way the
monitor commands can report an actual list of holders rather than just
true/false:

  attached = ["/qom/path/to/virtio-blk-0", "/qom/path/to/block/export/nbd-0"]

The QOM path would be a useful string to use as a unique identifier.

>
> Signed-off-by: Zhang Chen <[email protected]>
> ---
>  iothread.c         |  1 +
>  monitor/hmp-cmds.c |  2 ++
>  qapi/misc.json     | 12 ++++++++++++
>  3 files changed, 15 insertions(+)
>
> diff --git a/iothread.c b/iothread.c
> index 38e38fb44d..fb4898e491 100644
> --- a/iothread.c
> +++ b/iothread.c
> @@ -358,6 +358,7 @@ static int query_one_iothread(Object *object, void 
> *opaque)
>      info = g_new0(IOThreadInfo, 1);
>      info->id = iothread_get_id(iothread);
>      info->thread_id = iothread->thread_id;
> +    info->attached = iothread->attached;
>      info->poll_max_ns = iothread->poll_max_ns;
>      info->poll_grow = iothread->poll_grow;
>      info->poll_shrink = iothread->poll_shrink;
> diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
> index 5a673cddb2..7463f34bf5 100644
> --- a/monitor/hmp-cmds.c
> +++ b/monitor/hmp-cmds.c
> @@ -202,6 +202,8 @@ void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
>          value = info->value;
>          monitor_printf(mon, "%s:\n", value->id);
>          monitor_printf(mon, "  thread_id=%" PRId64 "\n", value->thread_id);
> +        monitor_printf(mon, "  attached=%s" "\n",
> +                       value->attached ? "true" : "false");
>          monitor_printf(mon, "  poll-max-ns=%" PRId64 "\n", 
> value->poll_max_ns);
>          monitor_printf(mon, "  poll-grow=%" PRId64 "\n", value->poll_grow);
>          monitor_printf(mon, "  poll-shrink=%" PRId64 "\n", 
> value->poll_shrink);
> diff --git a/qapi/misc.json b/qapi/misc.json
> index 1f5062df2a..cb865d6e48 100644
> --- a/qapi/misc.json
> +++ b/qapi/misc.json
> @@ -76,6 +76,15 @@
>  #
>  # @thread-id: ID of the underlying host thread
>  #
> +# @attached: The attached parameter is a flag indicating whether
> +#     the IOThread is currently associated with an active device
> +#     (e.g., virtio-blk).  In hotplug scenarios, users can
> +#     pre-allocate multiple iothread objects to serve as a persistent
> +#     thread pool.  When a device is hot-unplugged, the corresponding
> +#     IOThread is released but remains available, allowing subsequent
> +#     hot-plugged devices to attach to and reuse the existing thread.
> +#     (since 12.0)

How is this supposed to work since Patch 2 does not support hot unplug
(attached remains true)?

I'm also curious what the use case for this property is. First I
thought it's for debugging, but based on this documentation it sounds
like maybe you want to use it to avoid having to keep track of which
IOThreads are used in a management tool?

> +#
>  # @poll-max-ns: maximum polling time in ns, 0 means polling is
>  #     disabled (since 2.9)
>  #
> @@ -93,6 +102,7 @@
>  { 'struct': 'IOThreadInfo',
>    'data': {'id': 'str',
>             'thread-id': 'int',
> +           'attached': 'bool',
>             'poll-max-ns': 'int',
>             'poll-grow': 'int',
>             'poll-shrink': 'int',
> @@ -118,6 +128,7 @@
>  #              {
>  #                 "id":"iothread0",
>  #                 "thread-id":3134,
> +#                 "attached":false,
>  #                 "poll-max-ns":32768,
>  #                 "poll-grow":0,
>  #                 "poll-shrink":0,
> @@ -126,6 +137,7 @@
>  #              {
>  #                 "id":"iothread1",
>  #                 "thread-id":3135,
> +#                 "attached":true,
>  #                 "poll-max-ns":32768,
>  #                 "poll-grow":0,
>  #                 "poll-shrink":0,
> --
> 2.49.0
>
>

Reply via email to