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 04/15] iothread: introduce iothread_unsafe_get_aio_context()
Date: Thu, 16 Jul 2026 22:40:29 +0800 [thread overview]
Message-ID: <20260716144043.76414-5-zhangckid@gmail.com> (raw)
In-Reply-To: <20260716144043.76414-1-zhangckid@gmail.com>
Normally the IOThread's AioContext is fetched using
iothread_ref_and_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.
Signed-off-by: Zhang Chen <zhangckid@gmail.com>
---
blockdev.c | 2 +-
include/system/iothread.h | 9 +++++++++
iothread.c | 6 ++++++
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/blockdev.c b/blockdev.c
index 6e86c6262f..baeab3a3e1 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -3683,7 +3683,7 @@ void qmp_x_blockdev_set_iothread(const char *node_name, StrOrNull *iothread,
goto out;
}
- new_context = iothread_get_aio_context(obj);
+ new_context = iothread_unsafe_get_aio_context(obj);
} else {
new_context = qemu_get_aio_context();
}
diff --git a/include/system/iothread.h b/include/system/iothread.h
index 86f02c5a7d..3cce5eeb09 100644
--- a/include/system/iothread.h
+++ b/include/system/iothread.h
@@ -78,6 +78,15 @@ IOThread *iothread_by_id(const char *id);
* 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
+ * 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);
void iothread_put_aio_context(IOThread *iothread, const IOThreadHolder *holder);
diff --git a/iothread.c b/iothread.c
index f5d4708b25..157bb4d302 100644
--- a/iothread.c
+++ b/iothread.c
@@ -449,6 +449,12 @@ void iothread_put_aio_context(IOThread *iothread, const IOThreadHolder *holder)
iothread_unref(iothread, holder);
}
+/* Recommend migrating to the new API with IOThreadHolder as much as possible */
+AioContext *iothread_unsafe_get_aio_context(IOThread *iothread)
+{
+ return iothread->ctx;
+}
+
static int query_one_iothread(Object *object, void *opaque)
{
IOThreadInfoList ***tail = opaque;
--
2.49.0
next prev parent reply other threads:[~2026-07-16 14:47 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 ` Zhang Chen [this message]
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 ` [PATCH V10 14/15] iothread: simplify API by merging iothread_get_aio_context variants Zhang Chen
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-5-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.