From: Zhang Chen <zhangckid@gmail.com>
To: 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>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Kevin Wolf" <kwolf@redhat.com>,
"Jason Wang" <jasowang@redhat.com>, "Fam Zheng" <fam@euphon.net>,
"Daniel P . Berrangé" <berrange@redhat.com>
Cc: Zhang Chen <zhangckid@gmail.com>
Subject: [PATCH V10 14/15] iothread: simplify API by merging iothread_get_aio_context variants
Date: Thu, 16 Jul 2026 22:40:39 +0800 [thread overview]
Message-ID: <20260716144043.76414-15-zhangckid@gmail.com> (raw)
In-Reply-To: <20260716144043.76414-1-zhangckid@gmail.com>
Simplify the interface by merging iothread_ref_and_get_aio_context()
into iothread_get_aio_context(). The updated function now requires a
'holder' parameter, ensuring that every retrieval of an AioContext for
long-term use is automatically registered in the IOThread's holder list.
Update all callers across block, virtio, scsi, net, and monitor
subsystems to match the new signature. This cleanup reduces code
redundancy and improves the reliability of IOThread introspection.
Signed-off-by: Zhang Chen <zhangckid@gmail.com>
---
block/export/export.c | 5 ++---
hw/block/dataplane/xen-block.c | 4 ++--
hw/block/virtio-blk.c | 4 ++--
hw/scsi/virtio-scsi-dataplane.c | 4 ++--
hw/vfio-user/proxy.c | 3 +--
hw/virtio/iothread-vq-mapping.c | 3 +--
hw/virtio/virtio-balloon.c | 2 +-
include/system/iothread.h | 16 ++++++++--------
iothread.c | 9 ++-------
monitor/monitor.c | 2 +-
net/colo-compare.c | 2 +-
11 files changed, 23 insertions(+), 31 deletions(-)
diff --git a/block/export/export.c b/block/export/export.c
index 4dbd71de6a..32c7ef7d28 100644
--- a/block/export/export.c
+++ b/block/export/export.c
@@ -146,7 +146,7 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp)
.u.block_export.export_name = (char *)holder_name,
};
- new_ctx = iothread_ref_and_get_aio_context(iothread, &holder);
+ new_ctx = iothread_get_aio_context(iothread, &holder);
multithread_count = 1;
local_iothreads = g_new0(IOThread *, 1);
local_iothreads[0] = iothread;
@@ -190,8 +190,7 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp)
goto fail;
}
local_iothreads[i] = iothread;
- multithread_ctxs[i++] = iothread_ref_and_get_aio_context(iothread,
- &holder);
+ multithread_ctxs[i++] = iothread_get_aio_context(iothread, &holder);
}
assert(i == multithread_count);
}
diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c
index b5bf8d359f..46bfd62f5a 100644
--- a/hw/block/dataplane/xen-block.c
+++ b/hw/block/dataplane/xen-block.c
@@ -628,8 +628,8 @@ XenBlockDataPlane *xen_block_dataplane_create(XenDevice *xendev,
};
dataplane->iothread = iothread;
- dataplane->ctx = iothread_ref_and_get_aio_context(dataplane->iothread,
- &io_holder);
+ dataplane->ctx = iothread_get_aio_context(dataplane->iothread,
+ &io_holder);
} else {
dataplane->ctx = qemu_get_aio_context();
}
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index 1865890fad..2c296986ee 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -1508,8 +1508,8 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBlock *s, Error **errp)
.type = IO_THREAD_HOLDER_KIND_QOM_OBJECT,
.u.qom_object.qom_path = (char *)path,
};
- AioContext *ctx = iothread_ref_and_get_aio_context(conf->iothread,
- &io_holder);
+ AioContext *ctx = iothread_get_aio_context(conf->iothread,
+ &io_holder);
for (unsigned i = 0; i < conf->num_queues; i++) {
s->vq_aio_context[i] = ctx;
}
diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplane.c
index c71f33b41e..76ab22610f 100644
--- a/hw/scsi/virtio-scsi-dataplane.c
+++ b/hw/scsi/virtio-scsi-dataplane.c
@@ -78,8 +78,8 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **errp)
.type = IO_THREAD_HOLDER_KIND_QOM_OBJECT,
.u.qom_object.qom_path = (char *)path,
};
- AioContext *ctx = iothread_ref_and_get_aio_context(vs->conf.iothread,
- &io_holder);
+ AioContext *ctx = iothread_get_aio_context(vs->conf.iothread,
+ &io_holder);
for (uint16_t i = 0; i < vs->conf.num_queues; i++) {
s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED + i] = ctx;
}
diff --git a/hw/vfio-user/proxy.c b/hw/vfio-user/proxy.c
index b4f749f245..8ad0f4cfd3 100644
--- a/hw/vfio-user/proxy.c
+++ b/hw/vfio-user/proxy.c
@@ -942,8 +942,7 @@ VFIOUserProxy *vfio_user_connect_dev(SocketAddress *addr, Error **errp)
vfio_user_iothread = iothread_create("vfio-user", errp);
}
- proxy->ctx = iothread_ref_and_get_aio_context(vfio_user_iothread,
- &io_holder);
+ proxy->ctx = iothread_get_aio_context(vfio_user_iothread, &io_holder);
proxy->req_bh = qemu_bh_new(vfio_user_request, proxy);
QTAILQ_INIT(&proxy->outgoing);
diff --git a/hw/virtio/iothread-vq-mapping.c b/hw/virtio/iothread-vq-mapping.c
index 2cb48dd387..727358a483 100644
--- a/hw/virtio/iothread-vq-mapping.c
+++ b/hw/virtio/iothread-vq-mapping.c
@@ -99,8 +99,7 @@ bool iothread_vq_mapping_apply(
.u.qom_object.qom_path = (char *)holder,
};
- AioContext *ctx = iothread_ref_and_get_aio_context(iothread,
- &io_holder);
+ AioContext *ctx = iothread_get_aio_context(iothread, &io_holder);
if (node->value->vqs) {
uint16List *vq;
diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index e9d023b4ec..4405a87ed0 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -903,7 +903,7 @@ static void virtio_balloon_device_realize(DeviceState *dev, Error **errp)
precopy_add_notifier(&s->free_page_hint_notify);
s->free_page_bh = aio_bh_new_guarded(
- iothread_ref_and_get_aio_context(s->iothread, &io_holder),
+ iothread_get_aio_context(s->iothread, &io_holder),
virtio_ballloon_get_free_page_hints, s,
&dev->mem_reentrancy_guard);
}
diff --git a/include/system/iothread.h b/include/system/iothread.h
index 3cce5eeb09..3a6010b9f0 100644
--- a/include/system/iothread.h
+++ b/include/system/iothread.h
@@ -73,22 +73,22 @@ DECLARE_INSTANCE_CHECKER(IOThread, IOTHREAD,
char *iothread_get_id(IOThread *iothread);
IOThread *iothread_by_id(const char *id);
-/*
- * The iothread_get_aio_context() and iothread_put_aio_context() are not
- * thread-safe and must be called under the Big QEMU Lock (BQL).
- */
-AioContext *iothread_get_aio_context(IOThread *iothread);
+
/*
* Normally the IOThread's AioContext is fetched using
- * iothread_ref_and_get_aio_context(), but there are legacy callers
+ * iothread_get_aio_context(), but there are legacy callers
* without a clear ref/unref lifecycle. They cannot unref (e.g. because
* they do not have an IOThread pointer), so provide an unsafe way to
* fetch the AioContext without holding a reference count. This unsafe
* API serves legacy callers - do not use it in new code.
*/
AioContext *iothread_unsafe_get_aio_context(IOThread *iothread);
-AioContext *iothread_ref_and_get_aio_context(IOThread *iothread,
- const IOThreadHolder *holder);
+/*
+ * The iothread_get_aio_context() and iothread_put_aio_context() are not
+ * thread-safe and must be called under the Big QEMU Lock (BQL).
+ */
+AioContext *iothread_get_aio_context(IOThread *iothread,
+ const IOThreadHolder *holder);
void iothread_put_aio_context(IOThread *iothread, const IOThreadHolder *holder);
GMainContext *iothread_get_g_main_context(IOThread *iothread);
diff --git a/iothread.c b/iothread.c
index 157bb4d302..9d278efc45 100644
--- a/iothread.c
+++ b/iothread.c
@@ -429,13 +429,8 @@ char *iothread_get_id(IOThread *iothread)
return g_strdup(object_get_canonical_path_component(OBJECT(iothread)));
}
-AioContext *iothread_get_aio_context(IOThread *iothread)
-{
- return iothread->ctx;
-}
-
-AioContext *iothread_ref_and_get_aio_context(IOThread *iothread,
- const IOThreadHolder *holder)
+AioContext *iothread_get_aio_context(IOThread *iothread,
+ const IOThreadHolder *holder)
{
/* Add IOThreadHolder to the list */
iothread_ref(iothread, holder);
diff --git a/monitor/monitor.c b/monitor/monitor.c
index 688bb85c81..0b75f9f69b 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -749,7 +749,7 @@ static void monitor_complete(UserCreatable *uc, Error **errp)
.u.qom_object.qom_path = path,
};
- mon->ctx = iothread_ref_and_get_aio_context(mon_iothread, &io_holder);
+ mon->ctx = iothread_get_aio_context(mon_iothread, &io_holder);
ctx = mon->ctx;
} else {
ctx = qemu_get_aio_context();
diff --git a/net/colo-compare.c b/net/colo-compare.c
index a7bbb1056d..6cd642d0b7 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -969,7 +969,7 @@ static void colo_compare_iothread(CompareState *s)
.u.qom_object.qom_path = (char *)path,
};
- AioContext *ctx = iothread_ref_and_get_aio_context(s->iothread, &io_holder);
+ AioContext *ctx = iothread_get_aio_context(s->iothread, &io_holder);
s->iothread_ctx = ctx;
s->worker_context = iothread_get_g_main_context(s->iothread);
--
2.49.0
next prev parent reply other threads:[~2026-07-16 14:46 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-16 14:40 [PATCH V10 00/15] iothread: Support tracking and querying IOThread holders Zhang Chen
2026-07-16 14:40 ` [PATCH V10 01/15] qapi/misc: Fix missed query-iothreads items Zhang Chen
2026-07-16 14:40 ` [PATCH V10 02/15] iothread: introduce iothread_ref/unref to track attached devices Zhang Chen
2026-07-16 14:40 ` [PATCH V10 03/15] iothread: tracking iothread users with holder name Zhang Chen
2026-07-16 14:40 ` [PATCH V10 04/15] iothread: introduce iothread_unsafe_get_aio_context() Zhang Chen
2026-07-16 14:40 ` [PATCH V10 05/15] block/export: track IOThread reference in BlockExport Zhang Chen
2026-07-16 14:40 ` [PATCH V10 06/15] monitor: Update tracking iothread users with holder Zhang Chen
2026-07-16 15:11 ` Daniel P. Berrangé
2026-07-16 16:18 ` Zhang Chen
2026-07-16 14:40 ` [PATCH V10 07/15] virtio-vq-mapping: track iothread-vq-mapping references using device path Zhang Chen
2026-07-16 14:40 ` [PATCH V10 08/15] virtio: use iothread_get/put_aio_context for thread pinning Zhang Chen
2026-07-16 14:40 ` [PATCH V10 09/15] net/colo: track IOThread references using path-based holder Zhang Chen
2026-07-16 14:40 ` [PATCH V10 10/15] virtio-balloon: Update tracking iothread users with holder Zhang Chen
2026-07-16 14:40 ` [PATCH V10 11/15] vfio-user/proxy: Update tracking iothread users with holder name Zhang Chen
2026-07-16 14:40 ` [PATCH V10 12/15] xen-block: " Zhang Chen
2026-07-16 14:40 ` [PATCH V10 13/15] monitor/hmp: Add holders support for hmp_info_iothreads Zhang Chen
2026-07-16 14:40 ` Zhang Chen [this message]
2026-07-16 14:40 ` [PATCH V10 15/15] tests/unit/iothread: Update the iothread_get_aio_context 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=20260716144043.76414-15-zhangckid@gmail.com \
--to=zhangckid@gmail.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=dave@treblig.org \
--cc=eblake@redhat.com \
--cc=fam@euphon.net \
--cc=jasowang@redhat.com \
--cc=kwolf@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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.