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 <[email protected]> --- 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
