aio: remove AioContext lock
Subsystems (2)
cover aio: remove AioContext lock
This series removes the AioContext locking APIs from QEMU. aio_context_acquire() and aio_context_release() are currently only needed to support the locking discipline required by AIO_POLL_WHILE() (except for a stray user that I converted in Patch 1). AIO_POLL_WHILE() doesn't really need the AioContext lock anymore, so it's possible to remove the API. This is a nice simplification because the AioContext locking rules were sometimes tricky or underspecified, leading to many bugs of the years.
This patch series removes these APIs across the codebase and cleans up the documentation/comments that refers to them.
Patch 1 is a AioContext lock user I forgot to convert in my earlier SCSI conversion series.
Patch 2 removes tests for the AioContext lock because they will no longer be needed when the lock is gone.
Patches 3-9 remove the AioContext lock. These can be reviewed by categorizing the call sites into 1. places that take the lock because they call an API that requires the lock (ultimately AIO_POLL_WHILE()) and 2. places that take the lock to protect state. There should be no instances of case 2 left. If you see one, you've found a bug in this patch series!
Patches 10-12 remove comments.
Based-on: [email protected] ("[PATCH 0/4] scsi: eliminate AioContext lock") Since SCSI needs to stop relying on the AioContext lock before we can remove
the lock.
Stefan Hajnoczi (12):
virtio-scsi: replace AioContext lock with tmf_bh_lock
tests: remove aio_context_acquire() tests
aio: make aio_context_acquire()/aio_context_release() a no-op
graph-lock: remove AioContext locking
block: remove AioContext locking
scsi: remove AioContext locking
aio-wait: draw equivalence between AIO_WAIT_WHILE() and
AIO_WAIT_WHILE_UNLOCKED()
aio: remove aio_context_acquire()/aio_context_release() API
docs: remove AioContext lock from IOThread docs
scsi: remove outdated AioContext lock comment
job: remove outdated AioContext locking comments
block: remove outdated AioContext locking comments
docs/devel/multiple-iothreads.txt | 45 ++-- include/block/aio-wait.h | 16 +- include/block/aio.h | 17 -- include/block/block-common.h | 3 - include/block/block-global-state.h | 9 +- include/block/block-io.h | 12 +- include/block/block_int-common.h | 2 - include/block/graph-lock.h | 21 +- include/block/snapshot.h | 2 - include/hw/virtio/virtio-scsi.h | 17 +- include/qemu/job.h | 20 -- block.c | 357 ++++----------------------- block/backup.c | 4 +- block/blklogwrites.c | 8 +- block/blkverify.c | 4 +- block/block-backend.c | 33 +-- block/commit.c | 16 +- block/copy-before-write.c | 22 +- block/export/export.c | 22 +- block/export/vhost-user-blk-server.c | 4 - block/graph-lock.c | 44 +--- block/io.c | 45 +--- block/mirror.c | 41 +-- block/monitor/bitmap-qmp-cmds.c | 20 +- block/monitor/block-hmp-cmds.c | 29 --- block/qapi-sysemu.c | 27 +- block/qapi.c | 18 +- block/qcow2.c | 4 +- block/quorum.c | 8 +- block/raw-format.c | 5 - block/replication.c | 72 +----- block/snapshot.c | 26 +- block/stream.c | 12 +- block/vmdk.c | 20 +- block/write-threshold.c | 6 - blockdev.c | 315 +++++------------------ blockjob.c | 30 +-- hw/block/dataplane/virtio-blk.c | 10 - hw/block/dataplane/xen-block.c | 17 +- hw/block/virtio-blk.c | 45 +--- hw/core/qdev-properties-system.c | 9 - hw/scsi/scsi-bus.c | 2 - hw/scsi/scsi-disk.c | 29 +-- hw/scsi/virtio-scsi.c | 80 +++--- job.c | 16 -- migration/block.c | 33 +-- migration/migration-hmp-cmds.c | 3 - migration/savevm.c | 22 -- net/colo-compare.c | 2 - qemu-img.c | 4 - qemu-io.c | 10 +- qemu-nbd.c | 2 - replay/replay-debugging.c | 4 - tests/unit/test-aio.c | 67 +---- tests/unit/test-bdrv-drain.c | 91 ++----- tests/unit/test-bdrv-graph-mod.c | 26 +- tests/unit/test-block-iothread.c | 31 --- tests/unit/test-blockjob.c | 137 ---------- tests/unit/test-replication.c | 11 - util/async.c | 14 -- util/vhost-user-server.c | 3 - scripts/block-coroutine-wrapper.py | 7 +- tests/qemu-iotests/202 | 2 +- tests/qemu-iotests/203 | 3 +- tests/tsan/suppressions.tsan | 1 - 65 files changed, 324 insertions(+), 1713 deletions(-)
Signature · 1 line
2.42.0
PATCH 1/12 virtio-scsi: replace AioContext lock with tmf_bh_lock
Protect the Task Management Function BH state with a lock. The TMF BH runs in the main loop thread. An IOThread might process a TMF at the same time as the TMF BH is running. Therefore tmf_bh_list and tmf_bh must be protected by a lock.
Run TMF request completion in the IOThread using aio_wait_bh_oneshot(). This avoids more locking to protect the virtqueue and SCSI layer state.
--- include/hw/virtio/virtio-scsi.h | 3 +- hw/scsi/virtio-scsi.c | 62 ++++++++++++++++++++++----------- 2 files changed, 43 insertions(+), 22 deletions(-)
include/hw/virtio/virtio-scsi.h +2 -1
@@ -85,8 +85,9 @@ struct VirtIOSCSI {/* * TMFs deferred to main loop BH. These fields are protected by -* virtio_scsi_acquire(). +* tmf_bh_lock. */ +QemuMutex tmf_bh_lock;QEMUBH *tmf_bh; QTAILQ_HEAD(, VirtIOSCSIReq) tmf_bh_list;
hw/scsi/virtio-scsi.c +41 -21
114 lines not on this page · raw message
Signature · 1 line
2.42.0
Re: [PATCH 01/12] virtio-scsi: replace AioContext lock with tmf_bh_lock
Quoted 7 lines · Stefan Hajnoczi
Protect the Task Management Function BH state with a lock. The TMF BH runs in the main loop thread. An IOThread might process a TMF at the same time as the TMF BH is running. Therefore
tmf_bh_listandtmf_bhmust be protected by a lock.Run TMF request completion in the IOThread using
aio_wait_bh_oneshot(). This avoids more locking to protect the virtqueue and SCSI layer state.
Are we trying to get this into 8.2?
Quoted 7 lines
Signed-off-by Stefan Hajnoczi <[email protected]>--- include/hw/virtio/virtio-scsi.h | 3 +- hw/scsi/virtio-scsi.c | 62 ++++++++++++++++++++++----------- 2 files changed, 43 insertions(+), 22 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Re: [PATCH 01/12] virtio-scsi: replace AioContext lock with tmf_bh_lock
Quoted 10 lines · Eric Blake
Quoted 7 lines · Stefan Hajnoczi
Protect the Task Management Function BH state with a lock. The TMF BH runs in the main loop thread. An IOThread might process a TMF at the same time as the TMF BH is running. Therefore
tmf_bh_listandtmf_bhmust be protected by a lock.Run TMF request completion in the IOThread using
aio_wait_bh_oneshot(). This avoids more locking to protect the virtqueue and SCSI layer state.Are we trying to get this into 8.2?
No. 8.2 still has the AioContext lock is therefore safe without this patch.
Stefan
Quoted 16 lines
Quoted 8 lines
Signed-off-by Stefan Hajnoczi <[email protected]>--- include/hw/virtio/virtio-scsi.h | 3 +- hw/scsi/virtio-scsi.c | 62 ++++++++++++++++++++++----------- 2 files changed, 43 insertions(+), 22 deletions(-)Reviewed-by Eric Blake <[email protected]>Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Re: [PATCH 01/12] virtio-scsi: replace AioContext lock with tmf_bh_lock
In reply to Stefan HajnocziAm 29.11.2023 um 20:55 hat Stefan Hajnoczi geschrieben:
Quoted 9 lines
Protect the Task Management Function BH state with a lock. The TMF BH runs in the main loop thread. An IOThread might process a TMF at the same time as the TMF BH is running. Therefore
tmf_bh_listandtmf_bhmust be protected by a lock.Run TMF request completion in the IOThread using
aio_wait_bh_oneshot(). This avoids more locking to protect the virtqueue and SCSI layer state.Signed-off-by Stefan Hajnoczi <[email protected]>
Re: [PATCH 01/12] virtio-scsi: replace AioContext lock with tmf_bh_lock
In reply to Stefan HajnocziAm 29.11.2023 um 20:55 hat Stefan Hajnoczi geschrieben:
Quoted 9 lines
Protect the Task Management Function BH state with a lock. The TMF BH runs in the main loop thread. An IOThread might process a TMF at the same time as the TMF BH is running. Therefore
tmf_bh_listandtmf_bhmust be protected by a lock.Run TMF request completion in the IOThread using
aio_wait_bh_oneshot(). This avoids more locking to protect the virtqueue and SCSI layer state.Signed-off-by Stefan Hajnoczi <[email protected]>
The second part reminds me that the implicit protection of the virtqueue and SCSI data structures by having all accesses in a single thread is hard to review and I think we wanted to put some assertions there to check that we're really running in the right thread. I don't think we have done that so far, so I suppose after this patch would be the place in the series to add them, before we remove the protection by the AioContext lock?
Kevin
Re: [PATCH 01/12] virtio-scsi: replace AioContext lock with tmf_bh_lock
Quoted 11 lines · Kevin Wolf
Am 29.11.2023 um 20:55 hat Stefan Hajnoczi geschrieben:
Quoted 9 lines
Protect the Task Management Function BH state with a lock. The TMF BH runs in the main loop thread. An IOThread might process a TMF at the same time as the TMF BH is running. Therefore
tmf_bh_listandtmf_bhmust be protected by a lock.Run TMF request completion in the IOThread using
aio_wait_bh_oneshot(). This avoids more locking to protect the virtqueue and SCSI layer state.Signed-off-by Stefan Hajnoczi <[email protected]>
Quoted 7 lines
The second part reminds me that the implicit protection of the virtqueue and SCSI data structures by having all accesses in a single thread is hard to review and I think we wanted to put some assertions there to check that we're really running in the right thread. I don't think we have done that so far, so I suppose after this patch would be the place in the series to add them, before we remove the protection by the AioContext lock?
Thanks for reminding me. I will add assertions in the next revision of this series.
Stefan
PATCH 2/12 tests: remove aio_context_acquire() tests
In reply to Stefan HajnocziThe aio_context_acquire() API is being removed. Drop the test case that calls the API.
--- tests/unit/test-aio.c | 67 +------------------------------------------ 1 file changed, 1 insertion(+), 66 deletions(-)
tests/unit/test-aio.c +1 -66
@@ -100,76 +100,12 @@ static void event_ready_cb(EventNotifier *e)/* Tests using aio_*. */ -typedef struct { -QemuMutex start_lock; -EventNotifier notifier; -bool thread_acquired; -}AcquireTestData ; - -static void *test_acquire_thread (void *opaque) -{ -AcquireTestData *data = opaque; - -/* Wait for other thread to let us start */ -qemu_mutex_lock (&data->start_lock); -qemu_mutex_unlock (&data->start_lock); - -/* event_notifier_set might be called either before or after -* the main thread's call to poll(). The test case's outcome -* should be the same in either case. -*/ -event_notifier_set (&data->notifier); -aio_context_acquire (ctx); -aio_context_release (ctx); - - data->thread_acquired = true;/* success, we got here */ - -return NULL ; -} -static void set_event_notifier (AioContext *nctx,EventNotifier *notifier,EventNotifierHandler *handler) {aio_set_event_notifier (nctx, notifier, handler,NULL ,NULL ); } -static void dummy_notifier_read (EventNotifier *n) -{ -event_notifier_test_and_clear (n); -} - -static void test_acquire (void ) -{ -QemuThread thread; -AcquireTestData data; - -/* Dummy event notifier ensures aio_poll() will block */ -event_notifier_init (&data.notifier, false); -set_event_notifier (ctx, &data.notifier, dummy_notifier_read); -g_assert (!aio_poll (ctx, false));/* consume aio_notify() */ - -qemu_mutex_init (&data.start_lock); -qemu_mutex_lock (&data.start_lock); - data.thread_acquired = false; - -qemu_thread_create (&thread,"test_acquire_thread" , - test_acquire_thread, - &data,QEMU_THREAD_JOINABLE ); - -/* Block in aio_poll(), let other thread kick us and acquire context */ -aio_context_acquire (ctx); -qemu_mutex_unlock (&data.start_lock);/* let the thread run */ -g_assert (aio_poll (ctx, true)); -g_assert (!data.thread_acquired); -aio_context_release (ctx); - -qemu_thread_join (&thread); -set_event_notifier (ctx, &data.notifier,NULL ); -event_notifier_cleanup (&data.notifier); - -g_assert (data.thread_acquired); -} -static void test_bh_schedule (void ) {BHTestData data = { .n =0 };
@@ -879,7 +815,7 @@ static void test_worker_thread_co_enter(void)qemu_thread_get_self (&this_thread); co =qemu_coroutine_create (co_check_current_thread, &this_thread); -qemu_thread_create (&worker_thread,"test_acquire_thread" , +qemu_thread_create (&worker_thread,"test_aio_co_enter" , test_aio_co_enter, co,QEMU_THREAD_JOINABLE );
@@ -899,7 +835,6 @@ int main(int argc, char **argv)while (g_main_context_iteration (NULL , false));g_test_init (&argc, &argv,NULL ); -g_test_add_func ("/aio/acquire" , test_acquire);g_test_add_func ("/aio/bh/schedule" , test_bh_schedule);g_test_add_func ("/aio/bh/schedule10" , test_bh_schedule10);g_test_add_func ("/aio/bh/cancel" , test_bh_cancel);
Signature · 1 line
2.42.0
Re: [PATCH 02/12] tests: remove aio_context_acquire() tests
Quoted 7 lines · Stefan Hajnoczi
The
aio_context_acquire()API is being removed. Drop the test case that calls the API.Signed-off-by Stefan Hajnoczi <[email protected]>--- tests/unit/test-aio.c | 67 +------------------------------------------ 1 file changed, 1 insertion(+), 66 deletions(-)
The rest of this series should not hold up 8.2.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Re: [PATCH 02/12] tests: remove aio_context_acquire() tests
In reply to Stefan HajnocziAm 29.11.2023 um 20:55 hat Stefan Hajnoczi geschrieben:
Quoted 4 lines
The
aio_context_acquire()API is being removed. Drop the test case that calls the API.Signed-off-by Stefan Hajnoczi <[email protected]>
PATCH 3/12 aio: make aio_context_acquire()/aio_context_release() a no-op
In reply to Stefan Hajnocziaio_context_acquire()/aio_context_release() has been replaced by fine-grained locking to protect state shared by multiple threads. The AioContext lock still plays the role of balancing locking in AIO_WAIT_WHILE() and many functions in QEMU either require that the AioContext lock is held or not held for this reason. In other words, the AioContext lock is purely there for consistency with itself and serves no real purpose anymore.
Stop actually acquiring/releasing the lock in aio_context_acquire()/aio_context_release() so that subsequent patches can remove callers across the codebase incrementally.
I have performed "make check" and qemu-iotests stress tests across x86-64, ppc64le, and aarch64 to confirm that there are no failures as a result of eliminating the lock.
--- util/async.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
util/async.c +2 -2
@@ -725,12 +725,12 @@ void aio_context_unref(AioContext *ctx)void aio_context_acquire (AioContext *ctx) { -qemu_rec_mutex_lock (&ctx->lock); +/* TODO remove this function */ }void aio_context_release (AioContext *ctx) { -qemu_rec_mutex_unlock (&ctx->lock); +/* TODO remove this function */ } QEMU_DEFINE_STATIC_CO_TLS(AioContext *, my_aiocontext)
Signature · 1 line
2.42.0
Re: [PATCH 03/12] aio: make aio_context_acquire()/aio_context_release() a no-op
Quoted 42 lines · Stefan Hajnoczi
aio_context_acquire()/aio_context_release() has been replaced by fine-grained locking to protect state shared by multiple threads. The AioContext lock still plays the role of balancing locking in
AIO_WAIT_WHILE()and many functions in QEMU either require that the AioContext lock is held or not held for this reason. In other words, the AioContext lock is purely there for consistency with itself and serves no real purpose anymore.Stop actually acquiring/releasing the lock in aio_context_acquire()/aio_context_release() so that subsequent patches can remove callers across the codebase incrementally.
I have performed "make check" and qemu-iotests stress tests across x86-64, ppc64le, and aarch64 to confirm that there are no failures as a result of eliminating the lock.
Signed-off-by Stefan Hajnoczi <[email protected]>--- util/async.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)util/async.c +2
-2@@ -725,12 +725,12 @@ void aio_context_unref(AioContext *ctx)void aio_context_acquire (AioContext *ctx) { -qemu_rec_mutex_lock (&ctx->lock); +/* TODO remove this function */ }void aio_context_release (AioContext *ctx) { -qemu_rec_mutex_unlock (&ctx->lock); +/* TODO remove this function */ } QEMU_DEFINE_STATIC_CO_TLS(AioContext *, my_aiocontext)Signature · 1 line
2.42.0
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Re: [PATCH 03/12] aio: make aio_context_acquire()/aio_context_release() a no-op
In reply to Stefan HajnocziAm 29.11.2023 um 20:55 hat Stefan Hajnoczi geschrieben:
Quoted 12 lines
aio_context_acquire()/aio_context_release() has been replaced by fine-grained locking to protect state shared by multiple threads. The AioContext lock still plays the role of balancing locking in
AIO_WAIT_WHILE()and many functions in QEMU either require that the AioContext lock is held or not held for this reason. In other words, the AioContext lock is purely there for consistency with itself and serves no real purpose anymore.Stop actually acquiring/releasing the lock in aio_context_acquire()/aio_context_release() so that subsequent patches can remove callers across the codebase incrementally.
Quoted 5 lines
I have performed "make check" and qemu-iotests stress tests across x86-64, ppc64le, and aarch64 to confirm that there are no failures as a result of eliminating the lock.
Signed-off-by Stefan Hajnoczi <[email protected]>
YOLO.
PATCH 4/12 graph-lock: remove AioContext locking
In reply to Stefan HajnocziStop acquiring/releasing the AioContext lock in bdrv_graph_wrlock()/bdrv_graph_unlock() since the lock no longer has any effect.
The distinction between bdrv_graph_wrunlock() and bdrv_graph_wrunlock_ctx() becomes meaningless and they can be collapsed into one function.
--- include/block/graph-lock.h | 21 ++----------- block.c | 50 +++++++++++++++--------------- block/backup.c | 4 +-- block/blklogwrites.c | 8 ++--- block/blkverify.c | 4 +-- block/block-backend.c | 11 +++---- block/commit.c | 16 +++++----- block/graph-lock.c | 44 ++------------------------ block/mirror.c | 22 ++++++------- block/qcow2.c | 4 +-- block/quorum.c | 8 ++--- block/replication.c | 14 ++++----- block/snapshot.c | 4 +-- block/stream.c | 12 +++---- block/vmdk.c | 20 ++++++------ blockdev.c | 8 ++--- blockjob.c | 12 +++---- tests/unit/test-bdrv-drain.c | 40 ++++++++++++------------ tests/unit/test-bdrv-graph-mod.c | 20 ++++++------ scripts/block-coroutine-wrapper.py | 4 +-- 20 files changed, 133 insertions(+), 193 deletions(-)
include/block/graph-lock.h +2 -19
@@ -110,34 +110,17 @@ void unregister_aiocontext(AioContext *ctx);* * The wrlock can only be taken from the main loop, with BQL held, as only the * main loop is allowed to modify the graph. -* -* If @bs is non-NULL, its AioContext is temporarily released. -* -* This function polls. Callers must not hold the lock of any AioContext other -* than the current one and the one of @bs. */ void no_coroutine_fn TSA_ACQUIRE(graph_lock) TSA_NO_TSA -bdrv_graph_wrlock(BlockDriverState *bs); +bdrv_graph_wrlock(void); /* * bdrv_graph_wrunlock: * Write finished, reset global has_writer to 0 and restart * all readers that are waiting. - * - * If @bs is non-NULL, its AioContext is temporarily released. */ void no_coroutine_fn TSA_RELEASE(graph_lock) TSA_NO_TSA -bdrv_graph_wrunlock(BlockDriverState *bs); - -/* - * bdrv_graph_wrunlock_ctx: - * Write finished, reset global has_writer to 0 and restart - * all readers that are waiting. - * - * If @ctx is non-NULL, its lock is temporarily released. - */ -void no_coroutine_fn TSA_RELEASE(graph_lock) TSA_NO_TSA -bdrv_graph_wrunlock_ctx(AioContext *ctx); +bdrv_graph_wrunlock(void);/* * bdrv_graph_co_rdlock:
block.c +25 -25
170 lines not on this page · raw message
block/backup.c +2 -2
@@ -496,10 +496,10 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,block_copy_set_speed (bcs, speed);/* Required permissions are taken by copy-before-write filter target */ -bdrv_graph_wrlock (target); +bdrv_graph_wrlock ();block_job_add_bdrv (&job->common,"target" , target,0 ,BLK_PERM_ALL , &error_abort); -bdrv_graph_wrunlock (target); +bdrv_graph_wrunlock ();return &job->common;
block/blklogwrites.c +4 -4
@@ -251,9 +251,9 @@ static int blk_log_writes_open(BlockDriverState *bs, QDict *options, int flags, ret =0 ; fail_log:if (ret <0 ) { -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock ();bdrv_unref_child (bs, s->log_file); -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock (); s->log_file =NULL ; } fail:
@@ -265,10 +265,10 @@ static void blk_log_writes_close(BlockDriverState *bs) {BDRVBlkLogWritesState *s = bs->opaque; -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock ();bdrv_unref_child (bs, s->log_file); s->log_file =NULL ; -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock (); } static int64_t coroutine_fn GRAPH_RDLOCK
block/blkverify.c +2 -2
@@ -151,10 +151,10 @@ static void blkverify_close(BlockDriverState *bs) {BDRVBlkverifyState *s = bs->opaque; -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock ();bdrv_unref_child (bs, s->test_file); s->test_file =NULL ; -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock (); } static int64_t coroutine_fn GRAPH_RDLOCK
block/block-backend.c +4 -7
@@ -889,7 +889,6 @@ void blk_remove_bs(BlockBackend *blk) {ThrottleGroupMember *tgm = &blk->public.throttle_group_member;BdrvChild *root; -AioContext *ctx;GLOBAL_STATE_CODE ();
@@ -919,10 +918,9 @@ void blk_remove_bs(BlockBackend *blk) root = blk->root; blk->root =NULL ; - ctx =bdrv_get_aio_context (root->bs); -bdrv_graph_wrlock (root->bs); +bdrv_graph_wrlock ();bdrv_root_unref_child (root); -bdrv_graph_wrunlock_ctx (ctx); +bdrv_graph_wrunlock (); }/*
@@ -933,16 +931,15 @@ void blk_remove_bs(BlockBackend *blk)int blk_insert_bs (BlockBackend *blk,BlockDriverState *bs,Error **errp) {ThrottleGroupMember *tgm = &blk->public.throttle_group_member; -AioContext *ctx =bdrv_get_aio_context (bs);GLOBAL_STATE_CODE ();bdrv_ref (bs); -bdrv_graph_wrlock (bs); +bdrv_graph_wrlock (); blk->root =bdrv_root_attach_child (bs,"root" , &child_root,BDRV_CHILD_FILTERED |BDRV_CHILD_PRIMARY , blk->perm, blk->shared_perm, blk, errp); -bdrv_graph_wrunlock_ctx (ctx); +bdrv_graph_wrunlock ();if (blk->root ==NULL ) {return -EPERM ; }
block/commit.c +8 -8
@@ -100,9 +100,9 @@ static void commit_abort(Job *job)bdrv_graph_rdunlock_main_loop ();bdrv_drained_begin (commit_top_backing_bs); -bdrv_graph_wrlock (commit_top_backing_bs); +bdrv_graph_wrlock ();bdrv_replace_node (s->commit_top_bs, commit_top_backing_bs, &error_abort); -bdrv_graph_wrunlock (commit_top_backing_bs); +bdrv_graph_wrunlock ();bdrv_drained_end (commit_top_backing_bs);bdrv_unref (s->commit_top_bs);
@@ -339,7 +339,7 @@ void commit_start(const char *job_id, BlockDriverState *bs,* this is the responsibility of the interface (i.e. whoever calls * commit_start()). */ -bdrv_graph_wrlock (top); +bdrv_graph_wrlock (); s->base_overlay =bdrv_find_overlay (top, base);assert (s->base_overlay);
@@ -370,19 +370,19 @@ void commit_start(const char *job_id, BlockDriverState *bs, ret =block_job_add_bdrv (&s->common,"intermediate node" , iter,0 , iter_shared_perms, errp);if (ret <0 ) { -bdrv_graph_wrunlock (top); +bdrv_graph_wrunlock (); goto fail; } }if (bdrv_freeze_backing_chain (commit_top_bs, base, errp) <0 ) { -bdrv_graph_wrunlock (top); +bdrv_graph_wrunlock (); goto fail; } s->chain_frozen = true; ret =block_job_add_bdrv (&s->common,"base" , base,0 ,BLK_PERM_ALL , errp); -bdrv_graph_wrunlock (top); +bdrv_graph_wrunlock ();if (ret <0 ) { goto fail;
@@ -434,9 +434,9 @@ fail:* otherwise this would fail because of lack of permissions. */ if (commit_top_bs) {bdrv_drained_begin (top); -bdrv_graph_wrlock (top); +bdrv_graph_wrlock ();bdrv_replace_node (commit_top_bs, top, &error_abort); -bdrv_graph_wrunlock (top); +bdrv_graph_wrunlock ();bdrv_drained_end (top); } }
block/graph-lock.c +2 -42
73 lines not on this page · raw message
block/mirror.c +11 -11
@@ -764,7 +764,7 @@ static int mirror_exit_common(Job *job)* check for an op blocker on @to_replace, and we have our own * there. */ -bdrv_graph_wrlock (target_bs); +bdrv_graph_wrlock ();if (bdrv_recurse_can_replace (src, to_replace)) {bdrv_replace_node (to_replace, target_bs, &local_err); }else {
@@ -773,7 +773,7 @@ static int mirror_exit_common(Job *job)"would not lead to an abrupt change of visible data" , to_replace->node_name, target_bs->node_name); } -bdrv_graph_wrunlock (target_bs); +bdrv_graph_wrunlock ();bdrv_drained_end (to_replace);if (local_err) {error_report_err (local_err);
@@ -796,9 +796,9 @@ static int mirror_exit_common(Job *job)* valid. */ block_job_remove_all_bdrv (bjob); -bdrv_graph_wrlock (mirror_top_bs); +bdrv_graph_wrlock ();bdrv_replace_node (mirror_top_bs, mirror_top_bs->backing->bs, &error_abort); -bdrv_graph_wrunlock (mirror_top_bs); +bdrv_graph_wrunlock ();bdrv_drained_end (target_bs);bdrv_unref (target_bs);
@@ -1914,13 +1914,13 @@ static BlockJob *mirror_start_job(*/ bdrv_disable_dirty_bitmap (s->dirty_bitmap); -bdrv_graph_wrlock (bs); +bdrv_graph_wrlock (); ret =block_job_add_bdrv (&s->common,"source" , bs,0 ,BLK_PERM_WRITE_UNCHANGED |BLK_PERM_WRITE |BLK_PERM_CONSISTENT_READ , errp);if (ret <0 ) { -bdrv_graph_wrunlock (bs); +bdrv_graph_wrunlock (); goto fail; }
@@ -1965,17 +1965,17 @@ static BlockJob *mirror_start_job( ret =block_job_add_bdrv (&s->common,"intermediate node" , iter,0 , iter_shared_perms, errp);if (ret <0 ) { -bdrv_graph_wrunlock (bs); +bdrv_graph_wrunlock (); goto fail; } }if (bdrv_freeze_backing_chain (mirror_top_bs, target, errp) <0 ) { -bdrv_graph_wrunlock (bs); +bdrv_graph_wrunlock (); goto fail; } } -bdrv_graph_wrunlock (bs); +bdrv_graph_wrunlock ();QTAILQ_INIT (&s->ops_in_flight);
@@ -2001,12 +2001,12 @@ fail: bs_opaque->stop = true;bdrv_drained_begin (bs); -bdrv_graph_wrlock (bs); +bdrv_graph_wrlock ();assert (mirror_top_bs->backing->bs == bs);bdrv_child_refresh_perms (mirror_top_bs, mirror_top_bs->backing, &error_abort);bdrv_replace_node (mirror_top_bs, bs, &error_abort); -bdrv_graph_wrunlock (bs); +bdrv_graph_wrunlock ();bdrv_drained_end (bs);bdrv_unref (mirror_top_bs);
block/qcow2.c +2 -2
@@ -2807,9 +2807,9 @@ qcow2_do_close(BlockDriverState *bs, bool close_data_file)if (close_data_file &&has_data_file (bs)) {GLOBAL_STATE_CODE ();bdrv_graph_rdunlock_main_loop (); -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock ();bdrv_unref_child (bs, s->data_file); -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock (); s->data_file =NULL ;bdrv_graph_rdlock_main_loop (); }
block/quorum.c +4 -4
@@ -1037,14 +1037,14 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags, close_exit:/* cleanup on error */ -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock ();for (i =0 ; i < s->num_children; i++) {if (!opened[i]) {continue ; }bdrv_unref_child (bs, s->children[i]); } -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock ();g_free (s->children);g_free (opened); exit:
@@ -1057,11 +1057,11 @@ static void quorum_close(BlockDriverState *bs)BDRVQuorumState *s = bs->opaque;int i; -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock ();for (i =0 ; i < s->num_children; i++) {bdrv_unref_child (bs, s->children[i]); } -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock ();g_free (s->children); }
block/replication.c +7 -7
@@ -560,7 +560,7 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode,return ; } -bdrv_graph_wrlock (bs); +bdrv_graph_wrlock ();bdrv_ref (hidden_disk->bs); s->hidden_disk = bdrv_attach_child(bs, hidden_disk->bs, "hidden disk",
@@ -568,7 +568,7 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode, &local_err);if (local_err) {error_propagate (errp, local_err); -bdrv_graph_wrunlock (bs); +bdrv_graph_wrunlock ();aio_context_release (aio_context);return ; }
@@ -579,7 +579,7 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode, BDRV_CHILD_DATA, &local_err);if (local_err) {error_propagate (errp, local_err); -bdrv_graph_wrunlock (bs); +bdrv_graph_wrunlock ();aio_context_release (aio_context);return ; }
@@ -592,7 +592,7 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode,if (!top_bs || !bdrv_is_root_node (top_bs) || !check_top_bs (top_bs, bs)) {error_setg (errp,"No top_bs or it is invalid" ); -bdrv_graph_wrunlock (bs); +bdrv_graph_wrunlock ();reopen_backing_file (bs, false,NULL );aio_context_release (aio_context);return ;
@@ -600,7 +600,7 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode,bdrv_op_block_all (top_bs, s->blocker);bdrv_op_unblock (top_bs,BLOCK_OP_TYPE_DATAPLANE , s->blocker); -bdrv_graph_wrunlock (bs); +bdrv_graph_wrunlock (); s->backup_job = backup_job_create( NULL, s->secondary_disk->bs, s->hidden_disk->bs,
@@ -691,12 +691,12 @@ static void replication_done(void *opaque, int ret)if (ret ==0 ) { s->stage =BLOCK_REPLICATION_DONE ; -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock ();bdrv_unref_child (bs, s->secondary_disk); s->secondary_disk =NULL ;bdrv_unref_child (bs, s->hidden_disk); s->hidden_disk =NULL ; -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock (); s->error =0 ; }else {
block/snapshot.c +2 -2
@@ -290,9 +290,9 @@ int bdrv_snapshot_goto(BlockDriverState *bs, }/* .bdrv_open() will re-attach it */ -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock ();bdrv_unref_child (bs, fallback); -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock (); ret =bdrv_snapshot_goto (fallback_bs, snapshot_id, errp); open_ret = drv->bdrv_open (bs, options, bs->open_flags, &local_err);
block/stream.c +6 -6
@@ -99,9 +99,9 @@ static int stream_prepare(Job *job) } } -bdrv_graph_wrlock (s->target_bs); +bdrv_graph_wrlock ();bdrv_set_backing_hd_drained (unfiltered_bs, base, &local_err); -bdrv_graph_wrunlock (s->target_bs); +bdrv_graph_wrunlock ();/* * This call will do I/O, so the graph can change again from here on.
@@ -366,10 +366,10 @@ void stream_start(const char *job_id, BlockDriverState *bs,* already have our own plans. Also don't allow resize as the image size is * queried only at the job start and then cached. */ -bdrv_graph_wrlock (bs); +bdrv_graph_wrlock ();if (block_job_add_bdrv (&s->common,"active node" , bs,0 , basic_flags |BLK_PERM_WRITE , errp)) { -bdrv_graph_wrunlock (bs); +bdrv_graph_wrunlock (); goto fail; }
@@ -389,11 +389,11 @@ void stream_start(const char *job_id, BlockDriverState *bs, ret =block_job_add_bdrv (&s->common,"intermediate node" , iter,0 , basic_flags, errp);if (ret <0 ) { -bdrv_graph_wrunlock (bs); +bdrv_graph_wrunlock (); goto fail; } } -bdrv_graph_wrunlock (bs); +bdrv_graph_wrunlock (); s->base_overlay = base_overlay; s->above_base = above_base;
block/vmdk.c +10 -10
@@ -272,7 +272,7 @@ static void vmdk_free_extents(BlockDriverState *bs)BDRVVmdkState *s = bs->opaque;VmdkExtent *e; -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock ();for (i =0 ; i < s->num_extents; i++) { e = &s->extents[i];g_free (e->l1_table);
@@ -283,7 +283,7 @@ static void vmdk_free_extents(BlockDriverState *bs)bdrv_unref_child (bs, e->file); } } -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock ();g_free (s->extents); }
@@ -1247,9 +1247,9 @@ vmdk_parse_extents(const char *desc, BlockDriverState *bs, QDict *options, 0, 0, 0, 0, 0, &extent, errp);if (ret <0 ) {bdrv_graph_rdunlock_main_loop (); -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock ();bdrv_unref_child (bs, extent_file); -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock ();bdrv_graph_rdlock_main_loop (); goto out; }
@@ -1266,9 +1266,9 @@ vmdk_parse_extents(const char *desc, BlockDriverState *bs, QDict *options,g_free (buf);if (ret) {bdrv_graph_rdunlock_main_loop (); -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock ();bdrv_unref_child (bs, extent_file); -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock ();bdrv_graph_rdlock_main_loop (); goto out; }
@@ -1277,9 +1277,9 @@ vmdk_parse_extents(const char *desc, BlockDriverState *bs, QDict *options, ret =vmdk_open_se_sparse (bs, extent_file, bs->open_flags, errp);if (ret) {bdrv_graph_rdunlock_main_loop (); -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock ();bdrv_unref_child (bs, extent_file); -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock ();bdrv_graph_rdlock_main_loop (); goto out; }
@@ -1287,9 +1287,9 @@ vmdk_parse_extents(const char *desc, BlockDriverState *bs, QDict *options, }else {error_setg (errp,"Unsupported extent type '%s'" , type);bdrv_graph_rdunlock_main_loop (); -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock ();bdrv_unref_child (bs, extent_file); -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock ();bdrv_graph_rdlock_main_loop (); ret = -ENOTSUP ; goto out;
blockdev.c +4 -4
@@ -1611,9 +1611,9 @@ static void external_snapshot_abort(void *opaque) }bdrv_drained_begin (state->new_bs); -bdrv_graph_wrlock (state->old_bs); +bdrv_graph_wrlock ();bdrv_replace_node (state->new_bs, state->old_bs, &error_abort); -bdrv_graph_wrunlock (state->old_bs); +bdrv_graph_wrunlock ();bdrv_drained_end (state->new_bs);bdrv_unref (state->old_bs);/* bdrv_replace_node() ref'ed old_bs */
@@ -3656,7 +3656,7 @@ void qmp_x_blockdev_change(const char *parent, const char *child,BlockDriverState *parent_bs, *new_bs =NULL ;BdrvChild *p_child; -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock (); parent_bs =bdrv_lookup_bs (parent, parent, errp);if (!parent_bs) {
@@ -3692,7 +3692,7 @@ void qmp_x_blockdev_change(const char *parent, const char *child, } out: -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock (); }BlockJobInfoList *qmp_query_block_jobs (Error **errp)
blockjob.c +6 -6
@@ -199,7 +199,7 @@ void block_job_remove_all_bdrv(BlockJob *job)* to process an already freed BdrvChild. */ aio_context_release (job->job.aio_context); -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock ();aio_context_acquire (job->job.aio_context);while (job->nodes) {GSList *l = job->nodes;
@@ -212,7 +212,7 @@ void block_job_remove_all_bdrv(BlockJob *job)g_slist_free_1 (l); } -bdrv_graph_wrunlock_ctx (job->job.aio_context); +bdrv_graph_wrunlock (); }bool block_job_has_bdrv (BlockJob *job,BlockDriverState *bs)
@@ -514,7 +514,7 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver,int ret;GLOBAL_STATE_CODE (); -bdrv_graph_wrlock (bs); +bdrv_graph_wrlock ();if (job_id ==NULL && !(flags &JOB_INTERNAL )) { job_id =bdrv_get_device_name (bs);
@@ -523,7 +523,7 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver, job =job_create (job_id, &driver->job_driver, txn,bdrv_get_aio_context (bs), flags, cb, opaque, errp);if (job ==NULL ) { -bdrv_graph_wrunlock (bs); +bdrv_graph_wrunlock ();return NULL ; }
@@ -563,11 +563,11 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver, goto fail; } -bdrv_graph_wrunlock (bs); +bdrv_graph_wrunlock ();return job; fail: -bdrv_graph_wrunlock (bs); +bdrv_graph_wrunlock ();job_early_fail (&job->job);return NULL ; }
tests/unit/test-bdrv-drain.c +20 -20
@@ -807,9 +807,9 @@ static void test_blockjob_common_drain_node(enum drain_type drain_type, tjob->bs = src; job = &tjob->common; -bdrv_graph_wrlock (target); +bdrv_graph_wrlock ();block_job_add_bdrv (job,"target" , target,0 ,BLK_PERM_ALL , &error_abort); -bdrv_graph_wrunlock (target); +bdrv_graph_wrunlock ();switch (result) {case TEST_JOB_SUCCESS :
@@ -991,11 +991,11 @@ static void bdrv_test_top_close(BlockDriverState *bs) {BdrvChild *c, *next_c; -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock (); QLIST_FOREACH_SAFE(c, &bs->children, next, next_c) {bdrv_unref_child (bs, c); } -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock (); } static int coroutine_fn GRAPH_RDLOCK
@@ -1085,10 +1085,10 @@ static void do_test_delete_by_drain(bool detach_instead_of_delete, null_bs =bdrv_open ("null-co://" ,NULL ,NULL ,BDRV_O_RDWR |BDRV_O_PROTOCOL , &error_abort); -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock ();bdrv_attach_child (bs, null_bs,"null-child" , &child_of_bds,BDRV_CHILD_DATA , &error_abort); -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock ();/* This child will be the one to pass to requests through to, and * it will stall until a drain occurs */
@@ -1096,21 +1096,21 @@ static void do_test_delete_by_drain(bool detach_instead_of_delete, &error_abort); child_bs->total_sectors =65536 >>BDRV_SECTOR_BITS ;/* Takes our reference to child_bs */ -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock (); tts->wait_child =bdrv_attach_child (bs, child_bs,"wait-child" , &child_of_bds,BDRV_CHILD_DATA |BDRV_CHILD_PRIMARY , &error_abort); -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock ();/* This child is just there to be deleted * (for detach_instead_of_delete == true) */ null_bs =bdrv_open ("null-co://" ,NULL ,NULL ,BDRV_O_RDWR |BDRV_O_PROTOCOL , &error_abort); -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock ();bdrv_attach_child (bs, null_bs,"null-child" , &child_of_bds,BDRV_CHILD_DATA , &error_abort); -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock (); blk =blk_new (qemu_get_aio_context (),BLK_PERM_ALL ,BLK_PERM_ALL );blk_insert_bs (blk, bs, &error_abort);
@@ -1193,14 +1193,14 @@ static void no_coroutine_fn detach_indirect_bh(void *opaque)bdrv_dec_in_flight (data->child_b->bs); -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock ();bdrv_unref_child (data->parent_b, data->child_b);bdrv_ref (data->c); data->child_c =bdrv_attach_child (data->parent_b, data->c,"PB-C" , &child_of_bds,BDRV_CHILD_DATA , &error_abort); -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock (); } static void coroutine_mixed_fn detach_by_parent_aio_cb(void *opaque, int ret)
@@ -1298,7 +1298,7 @@ static void TSA_NO_TSA test_detach_indirect(bool by_parent_cb)/* Set child relationships */ bdrv_ref (b);bdrv_ref (a); -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock (); child_b =bdrv_attach_child (parent_b, b,"PB-B" , &child_of_bds,BDRV_CHILD_DATA , &error_abort); child_a = bdrv_attach_child(parent_b, a, "PB-A", &child_of_bds,
@@ -1308,7 +1308,7 @@ static void TSA_NO_TSA test_detach_indirect(bool by_parent_cb)bdrv_attach_child (parent_a, a,"PA-A" , by_parent_cb ? &child_of_bds : &detach_by_driver_cb_class,BDRV_CHILD_DATA , &error_abort); -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock (); g_assert_cmpint(parent_a->refcnt, ==, 1); g_assert_cmpint(parent_b->refcnt, ==, 1);
@@ -1727,7 +1727,7 @@ static void test_drop_intermediate_poll(void)* Establish the chain last, so the chain links are the first * elements in the BDS.parents lists */ -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock ();for (i =0 ; i <3 ; i++) {if (i) {/* Takes the reference to chain[i - 1] */
@@ -1735,7 +1735,7 @@ static void test_drop_intermediate_poll(void) &chain_child_class, BDRV_CHILD_COW, &error_abort); } } -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock (); job =block_job_create ("job" , &test_simple_job_driver,NULL , job_node,0 ,BLK_PERM_ALL ,0 ,0 ,NULL ,NULL , &error_abort);
@@ -1982,10 +1982,10 @@ static void do_test_replace_child_mid_drain(int old_drain_count, new_child_bs->total_sectors =1 ;bdrv_ref (old_child_bs); -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock ();bdrv_attach_child (parent_bs, old_child_bs,"child" , &child_of_bds,BDRV_CHILD_COW , &error_abort); -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock (); parent_s->setup_completed = true;for (i =0 ; i < old_drain_count; i++) {
@@ -2016,9 +2016,9 @@ static void do_test_replace_child_mid_drain(int old_drain_count,g_assert (parent_bs->quiesce_counter == old_drain_count);bdrv_drained_begin (old_child_bs);bdrv_drained_begin (new_child_bs); -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock ();bdrv_replace_node (old_child_bs, new_child_bs, &error_abort); -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock ();bdrv_drained_end (new_child_bs);bdrv_drained_end (old_child_bs);g_assert (parent_bs->quiesce_counter == new_drain_count);
tests/unit/test-bdrv-graph-mod.c +10 -10
@@ -137,10 +137,10 @@ static void test_update_perm_tree(void)blk_insert_bs (root, bs, &error_abort); -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock ();bdrv_attach_child (filter, bs,"child" , &child_of_bds,BDRV_CHILD_DATA , &error_abort); -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock ();aio_context_acquire (qemu_get_aio_context ()); ret =bdrv_append (filter, bs,NULL );
@@ -206,11 +206,11 @@ static void test_should_update_child(void)bdrv_set_backing_hd (target, bs, &error_abort); -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock ();g_assert (target->backing->bs == bs);bdrv_attach_child (filter, target,"target" , &child_of_bds,BDRV_CHILD_DATA , &error_abort); -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock ();aio_context_acquire (qemu_get_aio_context ());bdrv_append (filter, bs, &error_abort);aio_context_release (qemu_get_aio_context ());
@@ -248,7 +248,7 @@ static void test_parallel_exclusive_write(void)bdrv_ref (base);bdrv_ref (fl1); -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock ();bdrv_attach_child (top, fl1,"backing" , &child_of_bds,BDRV_CHILD_FILTERED |BDRV_CHILD_PRIMARY , &error_abort);
@@ -260,7 +260,7 @@ static void test_parallel_exclusive_write(void) &error_abort);bdrv_replace_node (fl1, fl2, &error_abort); -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock ();bdrv_drained_end (fl2);bdrv_drained_end (fl1);
@@ -367,7 +367,7 @@ static void test_parallel_perm_update(void)*/ bdrv_ref (base); -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock ();bdrv_attach_child (top, ws,"file" , &child_of_bds,BDRV_CHILD_DATA , &error_abort); c_fl1 = bdrv_attach_child(ws, fl1, "first", &child_of_bds,
@@ -380,7 +380,7 @@ static void test_parallel_perm_update(void)bdrv_attach_child (fl2, base,"backing" , &child_of_bds,BDRV_CHILD_FILTERED |BDRV_CHILD_PRIMARY , &error_abort); -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock ();/* Select fl1 as first child to be active */ s->selected = c_fl1;
@@ -434,11 +434,11 @@ static void test_append_greedy_filter(void)BlockDriverState *base =no_perm_node ("base" );BlockDriverState *fl =exclusive_writer_node ("fl1" ); -bdrv_graph_wrlock (NULL ); +bdrv_graph_wrlock ();bdrv_attach_child (top, base,"backing" , &child_of_bds,BDRV_CHILD_FILTERED |BDRV_CHILD_PRIMARY , &error_abort); -bdrv_graph_wrunlock (NULL ); +bdrv_graph_wrunlock ();aio_context_acquire (qemu_get_aio_context ());bdrv_append (fl, base, &error_abort);
scripts/block-coroutine-wrapper.py +2 -2
@@ -261,8 +261,8 @@ def gen_no_co_wrapper(func: FuncDecl) -> str: graph_lock=' bdrv_graph_rdlock_main_loop();' graph_unlock=' bdrv_graph_rdunlock_main_loop();' elif func.graph_wrlock: - graph_lock=' bdrv_graph_wrlock(NULL);' - graph_unlock=' bdrv_graph_wrunlock(NULL);' + graph_lock=' bdrv_graph_wrlock();' + graph_unlock=' bdrv_graph_wrunlock();' return f"""\ /*
Signature · 1 line
2.42.0
Re: [PATCH 04/12] graph-lock: remove AioContext locking
Quoted 10 lines · Stefan Hajnoczi
Stop acquiring/releasing the AioContext lock in bdrv_graph_wrlock()/bdrv_graph_unlock() since the lock no longer has any effect.
The distinction between
bdrv_graph_wrunlock()andbdrv_graph_wrunlock_ctx()becomes meaningless and they can be collapsed into one function.Signed-off-by Stefan Hajnoczi <[email protected]>---
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Re: [PATCH 04/12] graph-lock: remove AioContext locking
In reply to Stefan HajnocziAm 29.11.2023 um 20:55 hat Stefan Hajnoczi geschrieben:
Quoted 9 lines
Stop acquiring/releasing the AioContext lock in bdrv_graph_wrlock()/bdrv_graph_unlock() since the lock no longer has any effect.
The distinction between
bdrv_graph_wrunlock()andbdrv_graph_wrunlock_ctx()becomes meaningless and they can be collapsed into one function.Signed-off-by Stefan Hajnoczi <[email protected]>
PATCH 5/12 block: remove AioContext locking
In reply to Stefan HajnocziThis is the big patch that removes aio_context_acquire()/aio_context_release() from the block layer and affected block layer users.
There isn't a clean way to split this patch and the reviewers are likely the same group of people, so I decided to do it in one patch.
--- include/block/block-global-state.h | 9 +- include/block/block-io.h | 3 +- include/block/snapshot.h | 2 - block.c | 234 +--------------------- block/block-backend.c | 14 -- block/copy-before-write.c | 22 +-- block/export/export.c | 22 +-- block/io.c | 45 +---- block/mirror.c | 19 -- block/monitor/bitmap-qmp-cmds.c | 20 +- block/monitor/block-hmp-cmds.c | 29 --- block/qapi-sysemu.c | 27 +-- block/qapi.c | 18 +- block/raw-format.c | 5 - block/replication.c | 58 +----- block/snapshot.c | 22 +-- block/write-threshold.c | 6 - blockdev.c | 307 +++++------------------------ blockjob.c | 18 -- hw/block/dataplane/virtio-blk.c | 10 - hw/block/dataplane/xen-block.c | 17 +- hw/block/virtio-blk.c | 45 +---- hw/core/qdev-properties-system.c | 9 - job.c | 16 -- migration/block.c | 33 +--- migration/migration-hmp-cmds.c | 3 - migration/savevm.c | 22 --- net/colo-compare.c | 2 - qemu-img.c | 4 - qemu-io.c | 10 +- qemu-nbd.c | 2 - replay/replay-debugging.c | 4 - tests/unit/test-bdrv-drain.c | 51 +---- tests/unit/test-bdrv-graph-mod.c | 6 - tests/unit/test-block-iothread.c | 31 --- tests/unit/test-blockjob.c | 137 ------------- tests/unit/test-replication.c | 11 -- util/async.c | 4 - util/vhost-user-server.c | 3 - scripts/block-coroutine-wrapper.py | 3 - tests/tsan/suppressions.tsan | 1 - 41 files changed, 102 insertions(+), 1202 deletions(-)
include/block/block-global-state.h +4 -5
@@ -31,11 +31,10 @@/* * Global state (GS) API. These functions run under the BQL. * -* If a function modifies the graph, it also uses drain and/or -* aio_context_acquire/release to be sure it has unique access. -* aio_context locking is needed together with BQL because of -* the thread-safe I/O API that concurrently runs and accesses -* the graph without the BQL. +* If a function modifies the graph, it also uses the graph lock to be sure it +* has unique access. The graph lock is needed together with BQL because of the +* thread-safe I/O API that concurrently runs and accesses the graph without +* the BQL. * * It is important to note that not all of these functions are * necessarily limited to running under the BQL, but they would
include/block/block-io.h +1 -2
@@ -31,8 +31,7 @@/* * I/O API functions. These functions are thread-safe, and therefore -* can run in any thread as long as the thread has called -* aio_context_acquire/release(). +* can run in any thread. * * These functions can only call functions from I/O and Common categories, * but can be invoked by GS, "I/O or GS" and I/O APIs.
include/block/snapshot.h +0 -2
@@ -86,8 +86,6 @@ int bdrv_snapshot_load_tmp_by_id_or_name(BlockDriverState *bs,/* * Group operations. All block drivers are involved. -* These functions will properly handle dataplane (take aio_context_acquire -* when appropriate for appropriate block drivers */ bool bdrv_all_can_snapshot(bool has_devices, strList *devices,
block.c +8 -226
580 lines not on this page · raw message
block/block-backend.c +0 -14
@@ -429,7 +429,6 @@ BlockBackend *blk_new_open(const char *filename, const char *reference, {BlockBackend *blk;BlockDriverState *bs; -AioContext *ctx;uint64_t perm =0 ;uint64_t shared =BLK_PERM_ALL ;
@@ -459,23 +458,18 @@ BlockBackend *blk_new_open(const char *filename, const char *reference, shared =BLK_PERM_CONSISTENT_READ |BLK_PERM_WRITE_UNCHANGED ; } -aio_context_acquire (qemu_get_aio_context ()); bs =bdrv_open (filename, reference, options, flags, errp); -aio_context_release (qemu_get_aio_context ());if (!bs) {return NULL ; }/* bdrv_open() could have moved bs to a different AioContext */ - ctx =bdrv_get_aio_context (bs); blk =blk_new (bdrv_get_aio_context (bs), perm, shared); blk->perm = perm; blk->shared_perm = shared; -aio_context_acquire (ctx);blk_insert_bs (blk, bs, errp);bdrv_unref (bs); -aio_context_release (ctx);if (!blk->root) {blk_unref (blk);
@@ -577,13 +571,9 @@ void blk_remove_all_bs(void)GLOBAL_STATE_CODE ();while ((blk =blk_all_next (blk)) !=NULL ) { -AioContext *ctx =blk_get_aio_context (blk); - -aio_context_acquire (ctx);if (blk->root) {blk_remove_bs (blk); } -aio_context_release (ctx); } }
@@ -2736,20 +2726,16 @@ int blk_commit_all(void)GRAPH_RDLOCK_GUARD_MAINLOOP ();while ((blk =blk_all_next (blk)) !=NULL ) { -AioContext *aio_context =blk_get_aio_context (blk);BlockDriverState *unfiltered_bs =bdrv_skip_filters (blk_bs (blk)); -aio_context_acquire (aio_context);if (blk_is_inserted (blk) &&bdrv_cow_child (unfiltered_bs)) {int ret; ret =bdrv_commit (unfiltered_bs);if (ret <0 ) { -aio_context_release (aio_context);return ret; } } -aio_context_release (aio_context); }return 0 ; }
block/copy-before-write.c +5 -17
@@ -412,7 +412,6 @@ static int cbw_open(BlockDriverState *bs, QDict *options, int flags,int64_t cluster_size;g_autoptr (BlockdevOptions) full_opts =NULL ;BlockdevOptionsCbw *opts; -AioContext *ctx;int ret; full_opts =cbw_parse_options (options, errp);
@@ -435,15 +434,11 @@ static int cbw_open(BlockDriverState *bs, QDict *options, int flags,GRAPH_RDLOCK_GUARD_MAINLOOP (); - ctx =bdrv_get_aio_context (bs); -aio_context_acquire (ctx); -if (opts->bitmap) { bitmap =block_dirty_bitmap_lookup (opts->bitmap->node, opts->bitmap->name,NULL , errp);if (!bitmap) { - ret = -EINVAL ; - goto out; +return -EINVAL ; } } s->on_cbw_error = opts->has_on_cbw_error ? opts->on_cbw_error :
@@ -461,24 +456,21 @@ static int cbw_open(BlockDriverState *bs, QDict *options, int flags, s->bcs =block_copy_state_new (bs->file, s->target, bitmap, errp);if (!s->bcs) {error_prepend (errp,"Cannot create block-copy-state: " ); - ret = -EINVAL ; - goto out; +return -EINVAL ; } cluster_size =block_copy_cluster_size (s->bcs); s->done_bitmap =bdrv_create_dirty_bitmap (bs, cluster_size,NULL , errp);if (!s->done_bitmap) { - ret = -EINVAL ; - goto out; +return -EINVAL ; }bdrv_disable_dirty_bitmap (s->done_bitmap);/* s->access_bitmap starts equal to bcs bitmap */ s->access_bitmap =bdrv_create_dirty_bitmap (bs, cluster_size,NULL , errp);if (!s->access_bitmap) { - ret = -EINVAL ; - goto out; +return -EINVAL ; }bdrv_disable_dirty_bitmap (s->access_bitmap); bdrv_dirty_bitmap_merge_internal(s->access_bitmap,
@@ -487,11 +479,7 @@ static int cbw_open(BlockDriverState *bs, QDict *options, int flags,qemu_co_mutex_init (&s->lock);QLIST_INIT (&s->frozen_read_reqs); - - ret =0 ; -out: -aio_context_release (ctx); -return ret; +return 0 ; }static void cbw_close (BlockDriverState *bs)
block/export/export.c +1 -21
@@ -114,7 +114,6 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) } ctx =bdrv_get_aio_context (bs); -aio_context_acquire (ctx);if (export->iothread) {IOThread *iothread;
@@ -133,8 +132,6 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) set_context_errp = fixed_iothread ? errp :NULL ; ret =bdrv_try_change_aio_context (bs, new_ctx,NULL , set_context_errp);if (ret ==0 ) { -aio_context_release (ctx); -aio_context_acquire (new_ctx); ctx = new_ctx; }else if (fixed_iothread) { goto fail;
@@ -191,8 +188,6 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp)assert (exp->blk !=NULL );QLIST_INSERT_HEAD (&block_exports, exp, next); - -aio_context_release (ctx);return exp; fail:
@@ -200,7 +195,6 @@ fail:blk_set_dev_ops (blk,NULL ,NULL );blk_unref (blk); } -aio_context_release (ctx);if (exp) {g_free (exp->id);g_free (exp);
@@ -218,9 +212,6 @@ void blk_exp_ref(BlockExport *exp)static void blk_exp_delete_bh (void *opaque) {BlockExport *exp = opaque; -AioContext *aio_context = exp->ctx; - -aio_context_acquire (aio_context);assert (exp->refcount ==0 );QLIST_REMOVE (exp, next);
@@ -230,8 +221,6 @@ static void blk_exp_delete_bh(void *opaque)qapi_event_send_block_export_deleted (exp->id);g_free (exp->id);g_free (exp); - -aio_context_release (aio_context); }void blk_exp_unref (BlockExport *exp)
@@ -249,22 +238,16 @@ void blk_exp_unref(BlockExport *exp)* connections and other internally held references start to shut down. When * the function returns, there may still be active references while the export * is in the process of shutting down. -* -* Acquires exp->ctx internally. Callers must *not* hold the lock. */ void blk_exp_request_shutdown (BlockExport *exp) { -AioContext *aio_context = exp->ctx; - -aio_context_acquire (aio_context); -/* * If the user doesn't own the export any more, it is already shutting * down. We must not call .request_shutdown and decrease the refcount a * second time. */ if (!exp->user_owned) { - goto out; +return ; } exp->drv->request_shutdown (exp);
@@ -272,9 +255,6 @@ void blk_exp_request_shutdown(BlockExport *exp)assert (exp->user_owned); exp->user_owned = false;blk_exp_unref (exp); - -out: -aio_context_release (aio_context); }/*
block/io.c +5 -40
106 lines not on this page · raw message
block/mirror.c +0 -19
@@ -662,7 +662,6 @@ static int mirror_exit_common(Job *job)MirrorBlockJob *s =container_of (job, MirrorBlockJob, common.job);BlockJob *bjob = &s->common;MirrorBDSOpaque *bs_opaque; -AioContext *replace_aio_context =NULL ;BlockDriverState *src;BlockDriverState *target_bs;BlockDriverState *mirror_top_bs;
@@ -677,7 +676,6 @@ static int mirror_exit_common(Job *job) } s->prepared = true; -aio_context_acquire (qemu_get_aio_context ());bdrv_graph_rdlock_main_loop (); mirror_top_bs = s->mirror_top_bs;
@@ -742,11 +740,6 @@ static int mirror_exit_common(Job *job) }bdrv_graph_rdunlock_main_loop (); -if (s->to_replace) { - replace_aio_context =bdrv_get_aio_context (s->to_replace); -aio_context_acquire (replace_aio_context); - } -if (s->should_complete && !abort) {BlockDriverState *to_replace = s->to_replace ?: src;bool ro =bdrv_is_read_only (to_replace);
@@ -785,9 +778,6 @@ static int mirror_exit_common(Job *job)error_free (s->replace_blocker);bdrv_unref (s->to_replace); } -if (replace_aio_context) { -aio_context_release (replace_aio_context); - }g_free (s->replaces);/*
@@ -811,8 +801,6 @@ static int mirror_exit_common(Job *job)bdrv_unref (mirror_top_bs);bdrv_unref (src); -aio_context_release (qemu_get_aio_context ()); -return ret; }
@@ -1191,24 +1179,17 @@ static void mirror_complete(Job *job, Error **errp)/* block all operations on to_replace bs */ if (s->replaces) { -AioContext *replace_aio_context; - s->to_replace =bdrv_find_node (s->replaces);if (!s->to_replace) {error_setg (errp,"Node name '%s' not found" , s->replaces);return ; } - replace_aio_context =bdrv_get_aio_context (s->to_replace); -aio_context_acquire (replace_aio_context); -/* TODO Translate this into child freeze system. */ error_setg (&s->replace_blocker,"block device is in use by block-job-complete" );bdrv_op_block_all (s->to_replace, s->replace_blocker);bdrv_ref (s->to_replace); - -aio_context_release (replace_aio_context); } s->should_complete = true;
block/monitor/bitmap-qmp-cmds.c +3 -17
@@ -95,7 +95,6 @@ void qmp_block_dirty_bitmap_add(const char *node, const char *name, {BlockDriverState *bs;BdrvDirtyBitmap *bitmap; -AioContext *aio_context;if (!name || name[0 ] =='\0' ) {error_setg (errp,"Bitmap name cannot be empty" );
@@ -107,14 +106,11 @@ void qmp_block_dirty_bitmap_add(const char *node, const char *name,return ; } - aio_context =bdrv_get_aio_context (bs); -aio_context_acquire (aio_context); -if (has_granularity) {if (granularity <512 || !is_power_of_2 (granularity)) {error_setg (errp,"Granularity must be power of 2 " "and at least 512" ); - goto out; +return ; } }else {/* Default to cluster size, if available: */
@@ -132,12 +128,12 @@ void qmp_block_dirty_bitmap_add(const char *node, const char *name,if (persistent && !bdrv_can_store_new_dirty_bitmap (bs, name, granularity, errp)) { - goto out; +return ; } bitmap =bdrv_create_dirty_bitmap (bs, granularity, name, errp);if (bitmap ==NULL ) { - goto out; +return ; }if (disabled) {
@@ -145,9 +141,6 @@ void qmp_block_dirty_bitmap_add(const char *node, const char *name, }bdrv_dirty_bitmap_set_persistence (bitmap, persistent); - -out: -aio_context_release (aio_context); } BdrvDirtyBitmap *block_dirty_bitmap_remove(const char *node, const char *name,
@@ -157,7 +150,6 @@ BdrvDirtyBitmap *block_dirty_bitmap_remove(const char *node, const char *name, {BlockDriverState *bs;BdrvDirtyBitmap *bitmap; -AioContext *aio_context;GLOBAL_STATE_CODE ();
@@ -166,19 +158,14 @@ BdrvDirtyBitmap *block_dirty_bitmap_remove(const char *node, const char *name,return NULL ; } - aio_context =bdrv_get_aio_context (bs); -aio_context_acquire (aio_context); -if (bdrv_dirty_bitmap_check (bitmap,BDRV_BITMAP_BUSY |BDRV_BITMAP_RO , errp)) { -aio_context_release (aio_context);return NULL ; }if (bdrv_dirty_bitmap_get_persistence (bitmap) &&bdrv_remove_persistent_dirty_bitmap (bs, name, errp) <0 ) { -aio_context_release (aio_context);return NULL ; }
@@ -190,7 +177,6 @@ BdrvDirtyBitmap *block_dirty_bitmap_remove(const char *node, const char *name, *bitmap_bs = bs; } -aio_context_release (aio_context);return release ?NULL : bitmap; }
block/monitor/block-hmp-cmds.c +0 -29
@@ -141,7 +141,6 @@ void hmp_drive_del(Monitor *mon, const QDict *qdict)const char *id =qdict_get_str (qdict,"id" );BlockBackend *blk;BlockDriverState *bs; -AioContext *aio_context;Error *local_err =NULL ;GLOBAL_STATE_CODE ();
@@ -168,14 +167,10 @@ void hmp_drive_del(Monitor *mon, const QDict *qdict)return ; } - aio_context =blk_get_aio_context (blk); -aio_context_acquire (aio_context); - bs =blk_bs (blk);if (bs) {if (bdrv_op_is_blocked (bs,BLOCK_OP_TYPE_DRIVE_DEL , &local_err)) {error_report_err (local_err); -aio_context_release (aio_context);return ; }
@@ -196,8 +191,6 @@ void hmp_drive_del(Monitor *mon, const QDict *qdict) }else {blk_unref (blk); } - -aio_context_release (aio_context); }void hmp_commit (Monitor *mon,const QDict *qdict)
@@ -213,7 +206,6 @@ void hmp_commit(Monitor *mon, const QDict *qdict) ret =blk_commit_all (); }else {BlockDriverState *bs; -AioContext *aio_context; blk =blk_by_name (device);if (!blk) {
@@ -222,18 +214,13 @@ void hmp_commit(Monitor *mon, const QDict *qdict) } bs =bdrv_skip_implicit_filters (blk_bs (blk)); - aio_context =bdrv_get_aio_context (bs); -aio_context_acquire (aio_context);if (!blk_is_available (blk)) {error_report ("Device '%s' has no medium" , device); -aio_context_release (aio_context);return ; } ret =bdrv_commit (bs); - -aio_context_release (aio_context); }if (ret <0 ) {error_report ("'commit' error for '%s': %s" , device,strerror (-ret));
@@ -560,7 +547,6 @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict)BlockBackend *blk =NULL ;BlockDriverState *bs =NULL ;BlockBackend *local_blk =NULL ; -AioContext *ctx =NULL ;bool qdev =qdict_get_try_bool (qdict,"qdev" , false);const char *device =qdict_get_str (qdict,"device" );const char *command =qdict_get_str (qdict,"command" );
@@ -582,9 +568,6 @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict) } } - ctx = blk ?blk_get_aio_context (blk) :bdrv_get_aio_context (bs); -aio_context_acquire (ctx); -if (bs) { blk = local_blk =blk_new (bdrv_get_aio_context (bs),0 ,BLK_PERM_ALL ); ret =blk_insert_bs (blk, bs, &err);
@@ -622,11 +605,6 @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict) fail:blk_unref (local_blk); - -if (ctx) { -aio_context_release (ctx); - } -hmp_handle_error (mon, err); }
@@ -882,7 +860,6 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qdict)int nb_sns, i;int total;int *global_snapshots; -AioContext *aio_context; typedef struct SnapshotEntry { QEMUSnapshotInfo sn;
@@ -909,11 +886,8 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qdict)error_report_err (err);return ; } - aio_context =bdrv_get_aio_context (bs); -aio_context_acquire (aio_context); nb_sns =bdrv_snapshot_list (bs, &sn_tab); -aio_context_release (aio_context);if (nb_sns <0 ) {monitor_printf (mon,"bdrv_snapshot_list: error %d\n" , nb_sns);
@@ -924,9 +898,7 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qdict)int bs1_nb_sns =0 ;ImageEntry *ie;SnapshotEntry *se; -AioContext *ctx =bdrv_get_aio_context (bs1); -aio_context_acquire (ctx);if (bdrv_can_snapshot (bs1)) { sn =NULL ; bs1_nb_sns =bdrv_snapshot_list (bs1, &sn);
@@ -944,7 +916,6 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qdict) }g_free (sn); } -aio_context_release (ctx); }if (no_snapshot) {
block/qapi-sysemu.c +3 -24
@@ -174,7 +174,6 @@ blockdev_remove_medium(const char *device, const char *id, Error **errp) {BlockBackend *blk;BlockDriverState *bs; -AioContext *aio_context;bool has_attached_device;GLOBAL_STATE_CODE ();
@@ -204,13 +203,10 @@ blockdev_remove_medium(const char *device, const char *id, Error **errp)return ; } - aio_context =bdrv_get_aio_context (bs); -aio_context_acquire (aio_context); -bdrv_graph_rdlock_main_loop ();if (bdrv_op_is_blocked (bs,BLOCK_OP_TYPE_EJECT , errp)) {bdrv_graph_rdunlock_main_loop (); - goto out; +return ; }bdrv_graph_rdunlock_main_loop ();
@@ -223,9 +219,6 @@ blockdev_remove_medium(const char *device, const char *id, Error **errp)* value passed here (i.e. false). */ blk_dev_change_media_cb (blk, false, &error_abort); } - -out: -aio_context_release (aio_context); }void qmp_blockdev_remove_medium (const char *id,Error **errp)
@@ -237,7 +230,6 @@ static void qmp_blockdev_insert_anon_medium(BlockBackend *blk, BlockDriverState *bs, Error **errp) {Error *local_err =NULL ; -AioContext *ctx;bool has_device;int ret;
@@ -259,11 +251,7 @@ static void qmp_blockdev_insert_anon_medium(BlockBackend *blk,return ; } - ctx =bdrv_get_aio_context (bs); -aio_context_acquire (ctx); ret =blk_insert_bs (blk, bs, errp); -aio_context_release (ctx); -if (ret <0 ) {return ; }
@@ -374,9 +362,7 @@ void qmp_blockdev_change_medium(const char *device,qdict_put_str (options,"driver" , format); } -aio_context_acquire (qemu_get_aio_context ()); medium_bs =bdrv_open (filename,NULL , options, bdrv_flags, errp); -aio_context_release (qemu_get_aio_context ());if (!medium_bs) { goto fail;
@@ -437,20 +423,16 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp)ThrottleConfig cfg;BlockDriverState *bs;BlockBackend *blk; -AioContext *aio_context; blk =qmp_get_blk (arg->device, arg->id, errp);if (!blk) {return ; } - aio_context =blk_get_aio_context (blk); -aio_context_acquire (aio_context); - bs =blk_bs (blk);if (!bs) {error_setg (errp,"Device has no medium" ); - goto out; +return ; }throttle_config_init (&cfg);
@@ -505,7 +487,7 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) }if (!throttle_is_valid (&cfg, errp)) { - goto out; +return ; }if (throttle_enabled (&cfg)) {
@@ -522,9 +504,6 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp)/* If all throttling settings are set to 0, disable I/O limits */ blk_io_limits_disable (blk); } - -out: -aio_context_release (aio_context); } void qmp_block_latency_histogram_set(
block/qapi.c +3 -15
@@ -234,13 +234,11 @@ bdrv_do_query_node_info(BlockDriverState *bs, BlockNodeInfo *info, Error **errp)int ret;Error *err =NULL ; -aio_context_acquire (bdrv_get_aio_context (bs)); - size =bdrv_getlength (bs);if (size <0 ) {error_setg_errno (errp, -size,"Can't get image size '%s'" , bs->exact_filename); - goto out; +return ; }bdrv_refresh_filename (bs);
@@ -265,7 +263,7 @@ bdrv_do_query_node_info(BlockDriverState *bs, BlockNodeInfo *info, Error **errp) info->format_specific =bdrv_get_specific_info (bs, &err);if (err) {error_propagate (errp, err); - goto out; +return ; } backing_filename = bs->backing_file;if (backing_filename[0 ] !='\0' ) {
@@ -300,11 +298,8 @@ bdrv_do_query_node_info(BlockDriverState *bs, BlockNodeInfo *info, Error **errp)break ;default :error_propagate (errp, err); - goto out; +return ; } - -out: -aio_context_release (bdrv_get_aio_context (bs)); }/**
@@ -709,15 +704,10 @@ BlockStatsList *qmp_query_blockstats(bool has_query_nodes,/* Just to be safe if query_nodes is not always initialized */ if (has_query_nodes && query_nodes) {for (bs =bdrv_next_node (NULL ); bs; bs =bdrv_next_node (bs)) { -AioContext *ctx =bdrv_get_aio_context (bs); - -aio_context_acquire (ctx);QAPI_LIST_APPEND (tail,bdrv_query_bds_stats (bs, false)); -aio_context_release (ctx); } }else {for (blk =blk_all_next (NULL ); blk; blk =blk_all_next (blk)) { -AioContext *ctx =blk_get_aio_context (blk);BlockStats *s;char *qdev;
@@ -725,7 +715,6 @@ BlockStatsList *qmp_query_blockstats(bool has_query_nodes,continue ; } -aio_context_acquire (ctx); s =bdrv_query_bds_stats (blk_bs (blk), true); s->device =g_strdup (blk_name (blk));
@@ -737,7 +726,6 @@ BlockStatsList *qmp_query_blockstats(bool has_query_nodes, }bdrv_query_blk_stats (s->stats, blk); -aio_context_release (ctx);QAPI_LIST_APPEND (tail, s); }
block/raw-format.c +0 -5
@@ -470,7 +470,6 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) {BDRVRawState *s = bs->opaque; -AioContext *ctx;bool has_size;uint64_t offset, size;BdrvChildRole file_role;
@@ -522,11 +521,7 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags, bs->file->bs->filename); } - ctx =bdrv_get_aio_context (bs); -aio_context_acquire (ctx); ret =raw_apply_options (bs, s, offset, has_size, size, errp); -aio_context_release (ctx); -if (ret <0 ) {return ret; }
block/replication.c +3 -55
233 lines not on this page · raw message
block/snapshot.c +1 -21
@@ -525,9 +525,7 @@ static bool GRAPH_RDLOCK bdrv_all_snapshots_includes_bs(BlockDriverState *bs)return bdrv_has_blk (bs) ||QLIST_EMPTY (&bs->parents); } -/* Group operations. All block drivers are involved. -* These functions will properly handle dataplane (take aio_context_acquire -* when appropriate for appropriate block drivers) */ +/* Group operations. All block drivers are involved. */ bool bdrv_all_can_snapshot (bool has_devices,strList *devices,Error **errp)
@@ -545,14 +543,11 @@ bool bdrv_all_can_snapshot(bool has_devices, strList *devices, iterbdrvs = bdrvs;while (iterbdrvs) {BlockDriverState *bs = iterbdrvs->data; -AioContext *ctx =bdrv_get_aio_context (bs);bool ok = true; -aio_context_acquire (ctx);if (devices ||bdrv_all_snapshots_includes_bs (bs)) { ok =bdrv_can_snapshot (bs); } -aio_context_release (ctx);if (!ok) {error_setg (errp,"Device '%s' is writable but does not support " "snapshots" ,bdrv_get_device_or_node_name (bs));
@@ -582,18 +577,15 @@ int bdrv_all_delete_snapshot(const char *name, iterbdrvs = bdrvs;while (iterbdrvs) {BlockDriverState *bs = iterbdrvs->data; -AioContext *ctx =bdrv_get_aio_context (bs);QEMUSnapshotInfo sn1, *snapshot = &sn1;int ret =0 ; -aio_context_acquire (ctx);if ((devices ||bdrv_all_snapshots_includes_bs (bs)) &&bdrv_snapshot_find (bs, snapshot, name) >=0 ) { ret =bdrv_snapshot_delete (bs, snapshot->id_str, snapshot->name, errp); } -aio_context_release (ctx);if (ret <0 ) {error_prepend (errp,"Could not delete snapshot '%s' on '%s': " , name,bdrv_get_device_or_node_name (bs));
@@ -628,17 +620,14 @@ int bdrv_all_goto_snapshot(const char *name, iterbdrvs = bdrvs;while (iterbdrvs) {BlockDriverState *bs = iterbdrvs->data; -AioContext *ctx =bdrv_get_aio_context (bs);bool all_snapshots_includes_bs; -aio_context_acquire (ctx);bdrv_graph_rdlock_main_loop (); all_snapshots_includes_bs =bdrv_all_snapshots_includes_bs (bs);bdrv_graph_rdunlock_main_loop (); ret = (devices || all_snapshots_includes_bs) ?bdrv_snapshot_goto (bs, name, errp) :0 ; -aio_context_release (ctx);if (ret <0 ) {bdrv_graph_rdlock_main_loop (); error_prepend(errp, "Could not load snapshot '%s' on '%s': ",
@@ -670,15 +659,12 @@ int bdrv_all_has_snapshot(const char *name, iterbdrvs = bdrvs;while (iterbdrvs) {BlockDriverState *bs = iterbdrvs->data; -AioContext *ctx =bdrv_get_aio_context (bs);QEMUSnapshotInfo sn;int ret =0 ; -aio_context_acquire (ctx);if (devices ||bdrv_all_snapshots_includes_bs (bs)) { ret =bdrv_snapshot_find (bs, &sn, name); } -aio_context_release (ctx);if (ret <0 ) {if (ret == -ENOENT ) {return 0 ;
@@ -715,10 +701,8 @@ int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn, iterbdrvs = bdrvs;while (iterbdrvs) {BlockDriverState *bs = iterbdrvs->data; -AioContext *ctx =bdrv_get_aio_context (bs);int ret =0 ; -aio_context_acquire (ctx);if (bs == vm_state_bs) { sn->vm_state_size = vm_state_size; ret =bdrv_snapshot_create (bs, sn);
@@ -726,7 +710,6 @@ int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn, sn->vm_state_size =0 ; ret =bdrv_snapshot_create (bs, sn); } -aio_context_release (ctx);if (ret <0 ) {error_setg (errp,"Could not create snapshot '%s' on '%s'" , sn->name,bdrv_get_device_or_node_name (bs));
@@ -757,13 +740,10 @@ BlockDriverState *bdrv_all_find_vmstate_bs(const char *vmstate_bs, iterbdrvs = bdrvs;while (iterbdrvs) {BlockDriverState *bs = iterbdrvs->data; -AioContext *ctx =bdrv_get_aio_context (bs);bool found = false; -aio_context_acquire (ctx); found = (devices ||bdrv_all_snapshots_includes_bs (bs)) &&bdrv_can_snapshot (bs); -aio_context_release (ctx);if (vmstate_bs) { if (g_str_equal(vmstate_bs,
block/write-threshold.c +0 -6
@@ -33,7 +33,6 @@ void qmp_block_set_write_threshold(const char *node_name, Error **errp) {BlockDriverState *bs; -AioContext *aio_context; bs =bdrv_find_node (node_name);if (!bs) {
@@ -41,12 +40,7 @@ void qmp_block_set_write_threshold(const char *node_name,return ; } - aio_context =bdrv_get_aio_context (bs); -aio_context_acquire (aio_context); -bdrv_write_threshold_set (bs, threshold_bytes); - -aio_context_release (aio_context); } void bdrv_write_threshold_check_write(BlockDriverState *bs, int64_t offset,
blockdev.c +53 -254
1,003 lines not on this page · raw message
blockjob.c +0 -18
@@ -198,9 +198,7 @@ void block_job_remove_all_bdrv(BlockJob *job)* one to make sure that such a concurrent access does not attempt * to process an already freed BdrvChild. */ -aio_context_release (job->job.aio_context);bdrv_graph_wrlock (); -aio_context_acquire (job->job.aio_context);while (job->nodes) {GSList *l = job->nodes;BdrvChild *c = l->data;
@@ -234,28 +232,12 @@ int block_job_add_bdrv(BlockJob *job, const char *name, BlockDriverState *bs, uint64_t perm, uint64_t shared_perm, Error **errp) { BdrvChild *c; -AioContext *ctx =bdrv_get_aio_context (bs); -bool need_context_ops;GLOBAL_STATE_CODE ();bdrv_ref (bs); - need_context_ops = ctx != job->job.aio_context; - -if (need_context_ops) { -if (job->job.aio_context !=qemu_get_aio_context ()) { -aio_context_release (job->job.aio_context); - } -aio_context_acquire (ctx); - } c =bdrv_root_attach_child (bs, name, &child_job,0 , perm, shared_perm, job, errp); -if (need_context_ops) { -aio_context_release (ctx); -if (job->job.aio_context !=qemu_get_aio_context ()) { -aio_context_acquire (job->job.aio_context); - } - }if (c ==NULL ) {return -EPERM ; }
hw/block/dataplane/virtio-blk.c +0 -10
@@ -124,7 +124,6 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev)VirtIOBlockDataPlane *s = vblk->dataplane;BusState *qbus =BUS (qdev_get_parent_bus (DEVICE (vblk)));VirtioBusClass *k =VIRTIO_BUS_GET_CLASS (qbus); -AioContext *old_context;unsigned i;unsigned nvqs = s->conf->num_queues;Error *local_err =NULL ;
@@ -178,10 +177,7 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev)trace_virtio_blk_data_plane_start (s); - old_context =blk_get_aio_context (s->conf->conf.blk); -aio_context_acquire (old_context); r =blk_set_aio_context (s->conf->conf.blk, s->ctx, &local_err); -aio_context_release (old_context);if (r <0 ) {error_report_err (local_err); goto fail_aio_context;
@@ -208,13 +204,11 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev)/* Get this show started by hooking up our callbacks */ if (!blk_in_drain (s->conf->conf.blk)) { -aio_context_acquire (s->ctx);for (i =0 ; i < nvqs; i++) {VirtQueue *vq =virtio_get_queue (s->vdev, i);virtio_queue_aio_attach_host_notifier (vq, s->ctx); } -aio_context_release (s->ctx); }return 0 ;
@@ -314,8 +308,6 @@ void virtio_blk_data_plane_stop(VirtIODevice *vdev)*/ vblk->dataplane_started = false; -aio_context_acquire (s->ctx); -/* Wait for virtio_blk_dma_restart_bh() and in flight I/O to complete */ blk_drain (s->conf->conf.blk);
@@ -325,8 +317,6 @@ void virtio_blk_data_plane_stop(VirtIODevice *vdev)*/ blk_set_aio_context (s->conf->conf.blk,qemu_get_aio_context (),NULL ); -aio_context_release (s->ctx); -/* Clean up guest notifier (irq) */ k->set_guest_notifiers (qbus->parent, nvqs, false);
hw/block/dataplane/xen-block.c +2 -15
@@ -260,8 +260,6 @@ static void xen_block_complete_aio(void *opaque, int ret)XenBlockRequest *request = opaque;XenBlockDataPlane *dataplane = request->dataplane; -aio_context_acquire (dataplane->ctx); -if (ret !=0 ) { error_report("%s I/O error", request->req.operation == BLKIF_OP_READ ?
@@ -273,10 +271,10 @@ static void xen_block_complete_aio(void *opaque, int ret)if (request->presync) { request->presync =0 ;xen_block_do_aio (request); - goto done; +return ; }if (request->aio_inflight >0 ) { - goto done; +return ; }switch (request->req.operation) {
@@ -318,9 +316,6 @@ static void xen_block_complete_aio(void *opaque, int ret)if (dataplane->more_work) {qemu_bh_schedule (dataplane->bh); } - -done: -aio_context_release (dataplane->ctx); } static bool xen_block_split_discard(XenBlockRequest *request,
@@ -601,9 +596,7 @@ static void xen_block_dataplane_bh(void *opaque) {XenBlockDataPlane *dataplane = opaque; -aio_context_acquire (dataplane->ctx);xen_block_handle_requests (dataplane); -aio_context_release (dataplane->ctx); }static bool xen_block_dataplane_event (void *opaque)
@@ -703,10 +696,8 @@ void xen_block_dataplane_stop(XenBlockDataPlane *dataplane)xen_block_dataplane_detach (dataplane); } -aio_context_acquire (dataplane->ctx);/* Xen doesn't have multiple users for nodes, so this can't fail */ blk_set_aio_context (dataplane->blk,qemu_get_aio_context (), &error_abort); -aio_context_release (dataplane->ctx);/* * Now that the context has been moved onto the main thread, cancel
@@ -752,7 +743,6 @@ void xen_block_dataplane_start(XenBlockDataPlane *dataplane, {ERRP_GUARD ();XenDevice *xendev = dataplane->xendev; -AioContext *old_context;unsigned int ring_size;unsigned int i;
@@ -836,11 +826,8 @@ void xen_block_dataplane_start(XenBlockDataPlane *dataplane, goto stop; } - old_context =blk_get_aio_context (dataplane->blk); -aio_context_acquire (old_context);/* If other users keep the BlockBackend in the iothread, that's ok */ blk_set_aio_context (dataplane->blk, dataplane->ctx,NULL ); -aio_context_release (old_context);if (!blk_in_drain (dataplane->blk)) {xen_block_dataplane_attach (dataplane);
hw/block/virtio-blk.c +2 -43
135 lines not on this page · raw message
tests/unit/test-bdrv-drain.c +2 -49
51 lines not on this page · raw message
tests/unit/test-blockjob.c +0 -137
137 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.42.0
Part of the diff is not shown here. View the raw message.
Re: [PATCH 05/12] block: remove AioContext locking
Quoted 43 lines · Stefan Hajnoczi
This is the big patch that removes aio_context_acquire()/aio_context_release() from the block layer and affected block layer users.
There isn't a clean way to split this patch and the reviewers are likely the same group of people, so I decided to do it in one patch.
Signed-off-by Stefan Hajnoczi <[email protected]>--- include/block/block-global-state.h | 9 +- include/block/block-io.h | 3 +- include/block/snapshot.h | 2 - block.c | 234 +--------------------- block/block-backend.c | 14 -- block/copy-before-write.c | 22 +-- block/export/export.c | 22 +-- block/io.c | 45 +---- block/mirror.c | 19 -- block/monitor/bitmap-qmp-cmds.c | 20 +- block/monitor/block-hmp-cmds.c | 29 --- block/qapi-sysemu.c | 27 +-- block/qapi.c | 18 +- block/raw-format.c | 5 - block/replication.c | 58 +----- block/snapshot.c | 22 +-- block/write-threshold.c | 6 - blockdev.c | 307 +++++------------------------ blockjob.c | 18 -- hw/block/dataplane/virtio-blk.c | 10 - hw/block/dataplane/xen-block.c | 17 +- hw/block/virtio-blk.c | 45 +---- hw/core/qdev-properties-system.c | 9 - job.c | 16 -- migration/block.c | 33 +--- migration/migration-hmp-cmds.c | 3 - migration/savevm.c | 22 --- net/colo-compare.c | 2 - qemu-img.c | 4 - qemu-io.c | 10 +- qemu-nbd.c | 2 - replay/replay-debugging.c | 4 - tests/unit/test-bdrv-drain.c | 51 +---- tests/unit/test-bdrv-graph-mod.c | 6 -
Quoted 9 lines
tests/unit/test-block-iothread.c | 31 --- tests/unit/test-blockjob.c | 137 ------------- tests/unit/test-replication.c | 11 -- util/async.c | 4 - util/vhost-user-server.c | 3 - scripts/block-coroutine-wrapper.py | 3 - tests/tsan/suppressions.tsan | 1 - 41 files changed, 102 insertions(+), 1202 deletions(-)
Re: [PATCH 05/12] block: remove AioContext locking
In reply to Stefan HajnocziQuoted 15 lines · Stefan Hajnoczi
This is the big patch that removes aio_context_acquire()/aio_context_release() from the block layer and affected block layer users.
There isn't a clean way to split this patch and the reviewers are likely the same group of people, so I decided to do it in one patch.
Signed-off-by Stefan Hajnoczi <[email protected]>---
+++
b/block.cblock.c +0
-0@@ -7585,29 +7433,12 @@ void coroutine_fn bdrv_co_leave(BlockDriverState *bs, AioContext *old_ctx) void coroutine_fn bdrv_co_lock(BlockDriverState *bs) {
block.c void coroutine_fn bdrv_co_leave(BlockDriverState *bs, AioContext *old_ctx) · line 7597
Quoted 10 lines
block.c +0
-10-AioContext *ctx =bdrv_get_aio_context (bs); - -/* In the main thread, bs->aio_context won't change concurrently */ -assert (qemu_get_current_aio_context () ==qemu_get_aio_context ()); - -/* -* We're in coroutine context, so we already hold the lock of the main -* loop AioContext. Don't lock it twice to avoid deadlocks. -*/ -assert (qemu_in_coroutine ());
Is this assertion worth keeping in the short term?...
block.c void coroutine_fn bdrv_co_leave(BlockDriverState *bs, AioContext *old_ctx) · line 7437
Quoted 5 lines
block.c +1
-3-if (ctx !=qemu_get_aio_context ()) { -aio_context_acquire (ctx); - } +/* TODO removed in next patch */ }
...I guess I'll see in the next patch.
block.c void coroutine_fn bdrv_co_leave(BlockDriverState *bs, AioContext *old_ctx) · line 7442
Quoted 11 lines
block.c +1
-6void coroutine_fn bdrv_co_unlock(BlockDriverState *bs) { -AioContext *ctx =bdrv_get_aio_context (bs); - -assert (qemu_in_coroutine ()); -if (ctx !=qemu_get_aio_context ()) { -aio_context_release (ctx); - } +/* TODO removed in next patch */ }
Same comment.
blockdev.c static void external_snapshot_action(TransactionAction *action, · line 1357
Quoted 9 lines
blockdev.c +1
-1+++ b/blockdev.c@@ -1395,7 +1352,6 @@ static void external_snapshot_action(TransactionAction *action,/* File name of the new image (for 'blockdev-snapshot-sync') */ const char *new_image_file;ExternalSnapshotState *state =g_new0 (ExternalSnapshotState,1 ); -AioContext *aio_context;uint64_t perm, shared;/* TODO We'll eventually have to take a writer lock in this function */
I'm guessing removal of the locking gets us one step closer to implementing this TODO at a later time? Or is it now a stale comment? Either way, it doesn't affect this patch.
Quoted 6 lines
+++
b/migration/block.cmigration/block.c +0
-1@@ -270,7 +270,6 @@ static int mig_save_device_bulk(QEMUFile *f, BlkMigDevState *bmds)if (bmds->shared_base) {qemu_mutex_lock_iothread (); -aio_context_acquire (blk_get_aio_context (bb));
...
Quoted 4 lines
migration/block.c +0
-0@@ -313,22 +311,10 @@ static int mig_save_device_bulk(QEMUFile *f, BlkMigDevState *bmds) block_mig_state.submitted++;blk_mig_unlock ();
migration/block.c static int mig_save_device_bulk(QEMUFile *f, BlkMigDevState *bmds) · line 325
Quoted 10 lines
migration/block.c +0
-10-/* We do not know if bs is under the main thread (and thus does -* not acquire the AioContext when doing AIO) or rather under -* dataplane. Thus acquire both the iothread mutex and the -* AioContext. -* -* This is ugly and will disappear when we make bdrv_* thread-safe, -* without the need to acquire the AioContext. -*/ -qemu_mutex_lock_iothread (); -aio_context_acquire (blk_get_aio_context (bmds->blk));
Will conflict, but with trivial resolution, with your other thread renaming things to qemu_bql_lock().
Quoted 7 lines
tests/unit/test-blockjob.c +1
-2+++ b/tests/unit/test-blockjob.c -static void test_complete_in_standby (void ) -{@@ -531,13 +402,5 @@ int main(int argc, char **argv)g_test_add_func ("/blockjob/cancel/standby" , test_cancel_standby);
tests/unit/test-blockjob.c int main(int argc, char **argv) · line 541
Quoted 10 lines
tests/unit/test-blockjob.c +0
-8g_test_add_func ("/blockjob/cancel/pending" , test_cancel_pending);g_test_add_func ("/blockjob/cancel/concluded" , test_cancel_concluded); - -/* -* This test is flaky and sometimes fails in CI and otherwise: -* don't run unless user opts in via environment variable. -*/ -if (getenv ("QEMU_TEST_FLAKY_TESTS" )) { -g_test_add_func ("/blockjob/complete_in_standby" , test_complete_in_standby); - }
Looks like you ripped out this entire test, because it is no longer viable. I might have mentioned it in the commit message, or squashed the removal of this test into the earlier 02/12 patch.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Re: [PATCH 05/12] block: remove AioContext locking
Quoted 14 lines · Eric Blake
Quoted 13 lines · Stefan Hajnoczi
This is the big patch that removes aio_context_acquire()/aio_context_release() from the block layer and affected block layer users.
There isn't a clean way to split this patch and the reviewers are likely the same group of people, so I decided to do it in one patch.
Signed-off-by Stefan Hajnoczi <[email protected]>---
+++
b/block.c(quoted diff) +0
-0@@ -7585,29 +7433,12 @@ void coroutine_fn bdrv_co_leave(BlockDriverState *bs, AioContext *old_ctx)
Quoted 14 lines
block.c void coroutine_fn bdrv_co_leave(BlockDriverState *bs, AioContext *old_ctx) · line 7597
Quoted 12 lines
block.c +0
-10void coroutine_fn bdrv_co_lock(BlockDriverState *bs) { -AioContext *ctx =bdrv_get_aio_context (bs); - -/* In the main thread, bs->aio_context won't change concurrently */ -assert (qemu_get_current_aio_context () ==qemu_get_aio_context ()); - -/* -* We're in coroutine context, so we already hold the lock of the main -* loop AioContext. Don't lock it twice to avoid deadlocks. -*/ -assert (qemu_in_coroutine ());Is this assertion worth keeping in the short term?...
Probably not because coroutine vs non-coroutine functions don't change in this patch series, so it's unlikely that this will break.
Quoted 31 lines
block.c void coroutine_fn bdrv_co_leave(BlockDriverState *bs, AioContext *old_ctx) · line 7437
Quoted 6 lines
block.c +1
-3-if (ctx !=qemu_get_aio_context ()) { -aio_context_acquire (ctx); - } +/* TODO removed in next patch */ }...I guess I'll see in the next patch.
block.c void coroutine_fn bdrv_co_leave(BlockDriverState *bs, AioContext *old_ctx) · line 7442
Quoted 11 lines
block.c +1
-6void coroutine_fn bdrv_co_unlock(BlockDriverState *bs) { -AioContext *ctx =bdrv_get_aio_context (bs); - -assert (qemu_in_coroutine ()); -if (ctx !=qemu_get_aio_context ()) { -aio_context_release (ctx); - } +/* TODO removed in next patch */ }Same comment.
Quoted 8 lines
blockdev.c +1
-1+++ b/blockdev.c@@ -1395,7 +1352,6 @@ static void external_snapshot_action(TransactionAction *action,/* File name of the new image (for 'blockdev-snapshot-sync') */ const char *new_image_file;ExternalSnapshotState *state =g_new0 (ExternalSnapshotState,1 ); -AioContext *aio_context;uint64_t perm, shared;
Quoted 5 lines
blockdev.c static void external_snapshot_action(TransactionAction *action, · line 1357
Quoted 1 line
blockdev.c +0
-0/* TODO We'll eventually have to take a writer lock in this function */ I'm guessing removal of the locking gets us one step closer to implementing this TODO at a later time? Or is it now a stale comment? Either way, it doesn't affect this patch.
I'm not sure. Kevin can answer questions about the graph lock.
Quoted 5 lines
Quoted 4 lines
+++
b/tests/unit/test-blockjob.ctests/unit/test-blockjob.c +0
-2-static void test_complete_in_standby (void ) -{
Quoted 16 lines
tests/unit/test-blockjob.c int main(int argc, char **argv) · line 541
Quoted 12 lines
tests/unit/test-blockjob.c +0
-8@@ -531,13 +402,5 @@ int main(int argc, char **argv)g_test_add_func ("/blockjob/cancel/standby" , test_cancel_standby);g_test_add_func ("/blockjob/cancel/pending" , test_cancel_pending);g_test_add_func ("/blockjob/cancel/concluded" , test_cancel_concluded); - -/* -* This test is flaky and sometimes fails in CI and otherwise: -* don't run unless user opts in via environment variable. -*/ -if (getenv ("QEMU_TEST_FLAKY_TESTS" )) { -g_test_add_func ("/blockjob/complete_in_standby" , test_complete_in_standby); - }Looks like you ripped out this entire test, because it is no longer viable. I might have mentioned it in the commit message, or squashed the removal of this test into the earlier 02/12 patch.
I have sent a separate patch to remove this test and once it's merged this hunk will disappear this patch series:
https://lore.kernel.org/qemu-devel/[email protected]/
Stefan
Re: [PATCH 05/12] block: remove AioContext locking
In reply to Stefan HajnocziAm 29.11.2023 um 20:55 hat Stefan Hajnoczi geschrieben:
Quoted 18 lines
This is the big patch that removes aio_context_acquire()/aio_context_release() from the block layer and affected block layer users.
There isn't a clean way to split this patch and the reviewers are likely the same group of people, so I decided to do it in one patch.
Signed-off-by Stefan Hajnoczi <[email protected]>block.c +0
-5@@ -7585,29 +7433,12 @@ void coroutine_fn bdrv_co_leave(BlockDriverState *bs, AioContext *old_ctx) void coroutine_fn bdrv_co_lock(BlockDriverState *bs) { -AioContext *ctx =bdrv_get_aio_context (bs); - -/* In the main thread, bs->aio_context won't change concurrently */ -assert (qemu_get_current_aio_context () ==qemu_get_aio_context ()); -
block.c void coroutine_fn bdrv_co_leave(BlockDriverState *bs, AioContext *old_ctx) · line 7437
Quoted 10 lines
block.c +1
-8-/* -* We're in coroutine context, so we already hold the lock of the main -* loop AioContext. Don't lock it twice to avoid deadlocks. -*/ -assert (qemu_in_coroutine ()); -if (ctx !=qemu_get_aio_context ()) { -aio_context_acquire (ctx); - } +/* TODO removed in next patch */ }
It's still there at the end of the series.
block.c void coroutine_fn bdrv_co_leave(BlockDriverState *bs, AioContext *old_ctx) · line 7442
Quoted 10 lines
block.c +1
-6void coroutine_fn bdrv_co_unlock(BlockDriverState *bs) { -AioContext *ctx =bdrv_get_aio_context (bs); - -assert (qemu_in_coroutine ()); -if (ctx !=qemu_get_aio_context ()) { -aio_context_release (ctx); - } +/* TODO removed in next patch */ }
This one, too.
Re: [PATCH 05/12] block: remove AioContext locking
Quoted 23 lines · Kevin Wolf
Am 29.11.2023 um 20:55 hat Stefan Hajnoczi geschrieben:
Quoted 22 lines
This is the big patch that removes aio_context_acquire()/aio_context_release() from the block layer and affected block layer users.
There isn't a clean way to split this patch and the reviewers are likely the same group of people, so I decided to do it in one patch.
Signed-off-by Stefan Hajnoczi <[email protected]>block.c +0
-9@@ -7585,29 +7433,12 @@ void coroutine_fn bdrv_co_leave(BlockDriverState *bs, AioContext *old_ctx) void coroutine_fn bdrv_co_lock(BlockDriverState *bs) { -AioContext *ctx =bdrv_get_aio_context (bs); - -/* In the main thread, bs->aio_context won't change concurrently */ -assert (qemu_get_current_aio_context () ==qemu_get_aio_context ()); - -/* -* We're in coroutine context, so we already hold the lock of the main -* loop AioContext. Don't lock it twice to avoid deadlocks. -*/
Quoted 8 lines
block.c void coroutine_fn bdrv_co_leave(BlockDriverState *bs, AioContext *old_ctx) · line 7437
Quoted 6 lines
block.c +1
-4-assert (qemu_in_coroutine ()); -if (ctx !=qemu_get_aio_context ()) { -aio_context_acquire (ctx); - } +/* TODO removed in next patch */ }It's still there at the end of the series.
Will fix in v2. Thanks!
PATCH 6/12 scsi: remove AioContext locking
In reply to Stefan HajnocziThe AioContext lock no longer has any effect. Remove it.
--- include/hw/virtio/virtio-scsi.h | 14 -------------- hw/scsi/scsi-bus.c | 2 -- hw/scsi/scsi-disk.c | 28 ++++------------------------ hw/scsi/virtio-scsi.c | 18 ------------------ 4 files changed, 4 insertions(+), 58 deletions(-)
include/hw/virtio/virtio-scsi.h +0 -14
@@ -101,20 +101,6 @@ struct VirtIOSCSI {uint32_t host_features; }; -static inline void virtio_scsi_acquire (VirtIOSCSI *s) -{ -if (s->ctx) { -aio_context_acquire (s->ctx); - } -} - -static inline void virtio_scsi_release (VirtIOSCSI *s) -{ -if (s->ctx) { -aio_context_release (s->ctx); - } -} - void virtio_scsi_common_realize(DeviceState *dev, VirtIOHandleOutput ctrl, VirtIOHandleOutput evt,
hw/scsi/scsi-bus.c +0 -2
@@ -1725,9 +1725,7 @@ void scsi_device_purge_requests(SCSIDevice *sdev, SCSISense sense) {scsi_device_for_each_req_async (sdev, scsi_device_purge_one_req,NULL ); -aio_context_acquire (blk_get_aio_context (sdev->conf.blk));blk_drain (sdev->conf.blk); -aio_context_release (blk_get_aio_context (sdev->conf.blk));scsi_device_set_ua (sdev, sense); }
hw/scsi/scsi-disk.c +4 -24
@@ -2325,14 +2325,10 @@ static void scsi_disk_reset(DeviceState *dev) {SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev.qdev, dev);uint64_t nb_sectors; -AioContext *ctx;scsi_device_purge_requests (&s->qdev,SENSE_CODE (RESET )); - ctx =blk_get_aio_context (s->qdev.conf.blk); -aio_context_acquire (ctx);blk_get_geometry (s->qdev.conf.blk, &nb_sectors); -aio_context_release (ctx); nb_sectors /= s->qdev.blocksize /BDRV_SECTOR_SIZE ;if (nb_sectors) {
@@ -2531,13 +2527,11 @@ static void scsi_unrealize(SCSIDevice *dev)static void scsi_hd_realize (SCSIDevice *dev,Error **errp) {SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, dev); -AioContext *ctx =NULL ; +/* can happen for devices without drive. The error message for missing * backend will be issued in scsi_realize */ if (s->qdev.conf.blk) { - ctx =blk_get_aio_context (s->qdev.conf.blk); -aio_context_acquire (ctx);if (!blkconf_blocksizes (&s->qdev.conf, errp)) { goto out; }
@@ -2549,15 +2543,11 @@ static void scsi_hd_realize(SCSIDevice *dev, Error **errp) }scsi_realize (&s->qdev, errp); out: -if (ctx) { -aio_context_release (ctx); - } }static void scsi_cd_realize (SCSIDevice *dev,Error **errp) {SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, dev); -AioContext *ctx;int ret;uint32_t blocksize =2048 ;
@@ -2573,8 +2563,6 @@ static void scsi_cd_realize(SCSIDevice *dev, Error **errp) blocksize = dev->conf.physical_block_size; } - ctx =blk_get_aio_context (dev->conf.blk); -aio_context_acquire (ctx); s->qdev.blocksize = blocksize; s->qdev.type =TYPE_ROM ; s->features |=1 <<SCSI_DISK_F_REMOVABLE ;
@@ -2582,7 +2570,6 @@ static void scsi_cd_realize(SCSIDevice *dev, Error **errp) s->product =g_strdup ("QEMU CD-ROM" ); }scsi_realize (&s->qdev, errp); -aio_context_release (ctx); }
@@ -2713,7 +2700,6 @@ static int get_device_type(SCSIDiskState *s)static void scsi_block_realize (SCSIDevice *dev,Error **errp) {SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, dev); -AioContext *ctx;int sg_version;int rc;
@@ -2728,9 +2714,6 @@ static void scsi_block_realize(SCSIDevice *dev, Error **errp) "be removed in a future version"); } - ctx =blk_get_aio_context (s->qdev.conf.blk); -aio_context_acquire (ctx); -/* check we are using a driver managing SG_IO (version 3 and after) */ rc =blk_ioctl (s->qdev.conf.blk,SG_GET_VERSION_NUM , &sg_version);if (rc <0 ) {
@@ -2738,18 +2721,18 @@ static void scsi_block_realize(SCSIDevice *dev, Error **errp)if (rc != -EPERM ) {error_append_hint (errp,"Is this a SCSI device?\n" ); } - goto out; +return ; }if (sg_version <30000 ) {error_setg (errp,"scsi generic interface too old" ); - goto out; +return ; }/* get device type from INQUIRY data */ rc =get_device_type (s);if (rc <0 ) {error_setg (errp,"INQUIRY failed" ); - goto out; +return ; }/* Make a guess for the block size, we'll fix it when the guest sends.
@@ -2769,9 +2752,6 @@ static void scsi_block_realize(SCSIDevice *dev, Error **errp)scsi_realize (&s->qdev, errp);scsi_generic_read_device_inquiry (&s->qdev); - -out: -aio_context_release (ctx); } typedef struct SCSIBlockReq {
hw/scsi/virtio-scsi.c +0 -18
@@ -642,9 +642,7 @@ static void virtio_scsi_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)return ; } -virtio_scsi_acquire (s);virtio_scsi_handle_ctrl_vq (s, vq); -virtio_scsi_release (s); }static void virtio_scsi_complete_cmd_req (VirtIOSCSIReq *req)
@@ -882,9 +880,7 @@ static void virtio_scsi_handle_cmd(VirtIODevice *vdev, VirtQueue *vq)return ; } -virtio_scsi_acquire (s);virtio_scsi_handle_cmd_vq (s, vq); -virtio_scsi_release (s); } static void virtio_scsi_get_config(VirtIODevice *vdev,
@@ -1031,9 +1027,7 @@ static void virtio_scsi_handle_event(VirtIODevice *vdev, VirtQueue *vq)return ; } -virtio_scsi_acquire (s);virtio_scsi_handle_event_vq (s, vq); -virtio_scsi_release (s); }static void virtio_scsi_change (SCSIBus *bus,SCSIDevice *dev,SCSISense sense)
@@ -1052,9 +1046,7 @@ static void virtio_scsi_change(SCSIBus *bus, SCSIDevice *dev, SCSISense sense) }, }; -virtio_scsi_acquire (s);virtio_scsi_push_event (s, &info); -virtio_scsi_release (s); } }
@@ -1071,17 +1063,13 @@ static void virtio_scsi_hotplug(HotplugHandler *hotplug_dev, DeviceState *dev,VirtIODevice *vdev =VIRTIO_DEVICE (hotplug_dev);VirtIOSCSI *s =VIRTIO_SCSI (vdev);SCSIDevice *sd =SCSI_DEVICE (dev); -AioContext *old_context;int ret;if (s->ctx && !s->dataplane_fenced) {if (blk_op_is_blocked (sd->conf.blk,BLOCK_OP_TYPE_DATAPLANE , errp)) {return ; } - old_context =blk_get_aio_context (sd->conf.blk); -aio_context_acquire (old_context); ret =blk_set_aio_context (sd->conf.blk, s->ctx, errp); -aio_context_release (old_context);if (ret <0 ) {return ; }
@@ -1097,10 +1085,8 @@ static void virtio_scsi_hotplug(HotplugHandler *hotplug_dev, DeviceState *dev, }, }; -virtio_scsi_acquire (s);virtio_scsi_push_event (s, &info);scsi_bus_set_ua (&s->bus,SENSE_CODE (REPORTED_LUNS_CHANGED )); -virtio_scsi_release (s); } }
@@ -1122,17 +1108,13 @@ static void virtio_scsi_hotunplug(HotplugHandler *hotplug_dev, DeviceState *dev,qdev_simple_device_unplug_cb (hotplug_dev, dev, errp);if (s->ctx) { -virtio_scsi_acquire (s);/* If other users keep the BlockBackend in the iothread, that's ok */ blk_set_aio_context (sd->conf.blk,qemu_get_aio_context (),NULL ); -virtio_scsi_release (s); }if (virtio_vdev_has_feature (vdev,VIRTIO_SCSI_F_HOTPLUG )) { -virtio_scsi_acquire (s);virtio_scsi_push_event (s, &info);scsi_bus_set_ua (&s->bus,SENSE_CODE (REPORTED_LUNS_CHANGED )); -virtio_scsi_release (s); } }
Signature · 1 line
2.42.0
Re: [PATCH 06/12] scsi: remove AioContext locking
Quoted 10 lines · Stefan Hajnoczi
The AioContext lock no longer has any effect. Remove it.
Signed-off-by Stefan Hajnoczi <[email protected]>--- include/hw/virtio/virtio-scsi.h | 14 -------------- hw/scsi/scsi-bus.c | 2 -- hw/scsi/scsi-disk.c | 28 ++++------------------------ hw/scsi/virtio-scsi.c | 18 ------------------ 4 files changed, 4 insertions(+), 58 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Re: [PATCH 06/12] scsi: remove AioContext locking
In reply to Stefan HajnocziAm 29.11.2023 um 20:55 hat Stefan Hajnoczi geschrieben:
Quoted 26 lines
The AioContext lock no longer has any effect. Remove it.
Signed-off-by Stefan Hajnoczi <[email protected]>--- include/hw/virtio/virtio-scsi.h | 14 -------------- hw/scsi/scsi-bus.c | 2 -- hw/scsi/scsi-disk.c | 28 ++++------------------------ hw/scsi/virtio-scsi.c | 18 ------------------ 4 files changed, 4 insertions(+), 58 deletions(-)hw/scsi/scsi-disk.c +1
-3@@ -2531,13 +2527,11 @@ static void scsi_unrealize(SCSIDevice *dev)static void scsi_hd_realize (SCSIDevice *dev,Error **errp) {SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, dev); -AioContext *ctx =NULL ; +/* can happen for devices without drive. The error message for missing * backend will be issued in scsi_realize */ if (s->qdev.conf.blk) { - ctx =blk_get_aio_context (s->qdev.conf.blk); -aio_context_acquire (ctx);if (!blkconf_blocksizes (&s->qdev.conf, errp)) { goto out; }
hw/scsi/scsi-disk.c static void scsi_hd_realize(SCSIDevice *dev, Error **errp) · line 2546
Quoted 7 lines
hw/scsi/scsi-disk.c +0
-3@@ -2549,15 +2543,11 @@ static void scsi_hd_realize(SCSIDevice *dev, Error **errp) }scsi_realize (&s->qdev, errp); out: -if (ctx) { -aio_context_release (ctx); - } }
This doesn't build for me:
../hw/scsi/scsi-disk.c:2545:1: error: label at end of compound statement is a C2x extension [-Werror,-Wc2x-extensions] }
^
1 error generated.
Kevin
Re: [PATCH 06/12] scsi: remove AioContext locking
Quoted 37 lines · Kevin Wolf
Am 29.11.2023 um 20:55 hat Stefan Hajnoczi geschrieben:
Quoted 26 lines
The AioContext lock no longer has any effect. Remove it.
Signed-off-by Stefan Hajnoczi <[email protected]>--- include/hw/virtio/virtio-scsi.h | 14 -------------- hw/scsi/scsi-bus.c | 2 -- hw/scsi/scsi-disk.c | 28 ++++------------------------ hw/scsi/virtio-scsi.c | 18 ------------------ 4 files changed, 4 insertions(+), 58 deletions(-)hw/scsi/scsi-disk.c +1
-3@@ -2531,13 +2527,11 @@ static void scsi_unrealize(SCSIDevice *dev)static void scsi_hd_realize (SCSIDevice *dev,Error **errp) {SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, dev); -AioContext *ctx =NULL ; +/* can happen for devices without drive. The error message for missing * backend will be issued in scsi_realize */ if (s->qdev.conf.blk) { - ctx =blk_get_aio_context (s->qdev.conf.blk); -aio_context_acquire (ctx);if (!blkconf_blocksizes (&s->qdev.conf, errp)) { goto out; }hw/scsi/scsi-disk.c static void scsi_hd_realize(SCSIDevice *dev, Error **errp) · line 2546
Quoted 7 lines
hw/scsi/scsi-disk.c +0
-3@@ -2549,15 +2543,11 @@ static void scsi_hd_realize(SCSIDevice *dev, Error **errp) }scsi_realize (&s->qdev, errp); out: -if (ctx) { -aio_context_release (ctx); - } }This doesn't build for me:
Quoted 4 lines
../hw/scsi/scsi-disk.c:2545:1: error: label at end of compound statement is a C2x extension [-Werror,-Wc2x-extensions] }
^
1 error generated.
Will fix in v2. Thanks!
Stefan
PATCH 7/12 aio-wait: draw equivalence between AIO_WAIT_WHILE() and AIO_WAIT_WHILE_UNLOCKED()
In reply to Stefan HajnocziNow that the AioContext lock no longer exists, AIO_WAIT_WHILE() and AIO_WAIT_WHILE_UNLOCKED() are equivalent.
A future patch will get rid of AIO_WAIT_WHILE_UNLOCKED().
--- include/block/aio-wait.h | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
include/block/aio-wait.h +4 -12
@@ -63,9 +63,6 @@ extern AioWait global_aio_wait;* @ctx: the aio context, or NULL if multiple aio contexts (for which the * caller does not hold a lock) are involved in the polling condition. * @cond: wait while this conditional expression is true -* @unlock: whether to unlock and then lock again @ctx. This applies -* only when waiting for another AioContext from the main loop. -* Otherwise it's ignored. * * Wait while a condition is true. Use this to implement synchronous * operations that require event loop activity.
@@ -78,7 +75,7 @@ extern AioWait global_aio_wait;* wait on conditions between two IOThreads since that could lead to deadlock, * go via the main loop instead. */ -#define AIO_WAIT_WHILE_INTERNAL (ctx, cond, unlock) ({ \ +#define AIO_WAIT_WHILE_INTERNAL (ctx, cond) ({ \ bool waited_ = false; \ AioWait *wait_ = &global_aio_wait; \ AioContext *ctx_ = (ctx); \
@@ -95,13 +92,7 @@ extern AioWait global_aio_wait;assert (qemu_get_current_aio_context () == \qemu_get_aio_context ()); \while ((cond)) { \ -if (unlock && ctx_) { \ -aio_context_release (ctx_); \ - } \aio_poll (qemu_get_aio_context (), true); \ -if (unlock && ctx_) { \ -aio_context_acquire (ctx_); \ - } \ waited_ = true; \ } \ } \
@@ -109,10 +100,11 @@ extern AioWait global_aio_wait; waited_; })#define AIO_WAIT_WHILE (ctx, cond) \ - AIO_WAIT_WHILE_INTERNAL(ctx, cond, true) + AIO_WAIT_WHILE_INTERNAL(ctx, cond) +/* TODO replace this with AIO_WAIT_WHILE() in a future patch */ #define AIO_WAIT_WHILE_UNLOCKED (ctx, cond) \ - AIO_WAIT_WHILE_INTERNAL(ctx, cond, false) + AIO_WAIT_WHILE_INTERNAL(ctx, cond)/** * aio_wait_kick:
Signature · 1 line
2.42.0
Re: [PATCH 07/12] aio-wait: draw equivalence between AIO_WAIT_WHILE() and AIO_WAIT_WHILE_UNLOCKED()
Quoted 10 lines · Stefan Hajnoczi
Now that the AioContext lock no longer exists,
AIO_WAIT_WHILE()andAIO_WAIT_WHILE_UNLOCKED()are equivalent.A future patch will get rid of
AIO_WAIT_WHILE_UNLOCKED().Signed-off-by Stefan Hajnoczi <[email protected]>--- include/block/aio-wait.h | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
PATCH 8/12 aio: remove aio_context_acquire()/aio_context_release() API
In reply to Stefan HajnocziDelete these functions because nothing calls these functions anymore.
I introduced these APIs in commit 98563fc3ec44 ("aio: add aio_context_acquire() and aio_context_release()") in 2014. It's with a sigh of relief that I delete these APIs almost 10 years later.
Thanks to Paolo Bonzini's vision for multi-queue QEMU, we got an understanding of where the code needed to go in order to remove the limitations that the original dataplane and the IOThread/AioContext approach that followed it.
Emanuele Giuseppe Esposito had the splendid determination to convert large parts of the codebase so that they no longer needed the AioContext lock. This was a painstaking process, both in the actual code changes required and the iterations of code review that Emanuele eeked out of Kevin and me over many months.
Kevin Wolf tackled multitudes of graph locking conversions to protect in-flight I/O from run-time changes to the block graph as well as the clang Thread Safety Analysis annotations that allow the compiler to check whether the graph lock is being used correctly.
And me, well, I'm just here to add some pizzazz to the QEMU multi-queue block layer :). Thank you to everyone who helped with this effort, including Eric Blake, code reviewer extraordinaire, and others who I've forgotten to mention.
--- include/block/aio.h | 17 ----------------- util/async.c | 10 ---------- 2 files changed, 27 deletions(-)
include/block/aio.h +0 -17
@@ -278,23 +278,6 @@ void aio_context_ref(AioContext *ctx);*/ void aio_context_unref (AioContext *ctx); -/* Take ownership of the AioContext. If the AioContext will be shared between -* threads, and a thread does not want to be interrupted, it will have to -* take ownership around calls to aio_poll(). Otherwise, aio_poll() -* automatically takes care of calling aio_context_acquire and -* aio_context_release. -* -* Note that this is separate from bdrv_drained_begin/bdrv_drained_end. A -* thread still has to call those to avoid being interrupted by the guest. -* -* Bottom halves, timers and callbacks can be created or removed without -* acquiring the AioContext. -*/ -void aio_context_acquire (AioContext *ctx); - -/* Relinquish ownership of the AioContext. */ -void aio_context_release (AioContext *ctx); -/** * aio_bh_schedule_oneshot_full: Allocate a new bottom half structure that will * run only once and as soon as possible.
util/async.c +0 -10
@@ -719,16 +719,6 @@ void aio_context_unref(AioContext *ctx)g_source_unref (&ctx->source); } -void aio_context_acquire (AioContext *ctx) -{ -/* TODO remove this function */ -} - -void aio_context_release (AioContext *ctx) -{ -/* TODO remove this function */ -} - QEMU_DEFINE_STATIC_CO_TLS(AioContext *, my_aiocontext) AioContext *qemu_get_current_aio_context(void)
Signature · 1 line
2.42.0
Re: [PATCH 08/12] aio: remove aio_context_acquire()/aio_context_release() API
Quoted 11 lines · Stefan Hajnoczi
Delete these functions because nothing calls these functions anymore.
I introduced these APIs in commit
98563fc3ec44("aio: addaio_context_acquire()andaio_context_release()") in 2014. It's with a sigh of relief that I delete these APIs almost 10 years later.Thanks to Paolo Bonzini's vision for multi-queue QEMU, we got an understanding of where the code needed to go in order to remove the limitations that the original dataplane and the IOThread/AioContext approach that followed it.
Quoted 4 lines
Emanuele Giuseppe Esposito had the splendid determination to convert large parts of the codebase so that they no longer needed the AioContext lock. This was a painstaking process, both in the actual code changes required and the iterations of code review that Emanuele eeked out of
s/eeked/eked/
Quoted 12 lines
Kevin and me over many months.
Kevin Wolf tackled multitudes of graph locking conversions to protect in-flight I/O from run-time changes to the block graph as well as the clang Thread Safety Analysis annotations that allow the compiler to check whether the graph lock is being used correctly.
And me, well, I'm just here to add some pizzazz to the QEMU multi-queue block layer :). Thank you to everyone who helped with this effort, including Eric Blake, code reviewer extraordinaire, and others who I've forgotten to mention.
Quoted 6 lines
Signed-off-by Stefan Hajnoczi <[email protected]>--- include/block/aio.h | 17 ----------------- util/async.c | 10 ---------- 2 files changed, 27 deletions(-)
Yay!
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
PATCH 9/12 docs: remove AioContext lock from IOThread docs
In reply to Stefan HajnocziEncourage the use of locking primitives and stop mentioning the AioContext lock since it is being removed.
--- docs/devel/multiple-iothreads.txt | 45 +++++++++++-------------------- 1 file changed, 15 insertions(+), 30 deletions(-)
docs/devel/multiple-iothreads.txt +15 -30
@@ -88,27 +88,18 @@ loop, depending on which AioContext instance the caller passes in. How to synchronize with an IOThread ----------------------------------- -AioContext is not thread-safe so some rules must be followed when using file -descriptors, event notifiers, timers, or BHs across threads: +Variables that can be accessed by multiple threads require some form of +synchronization such as qemu_mutex_lock(), rcu_read_lock(), etc. -1. AioContext functions can always be called safely. They handle their -own locking internally. - -2. Other threads wishing to access the AioContext must use -aio_context_acquire()/aio_context_release() for mutual exclusion. Once the -context is acquired no other thread can access it or run event loop iterations -in this AioContext. - -Legacy code sometimes nests aio_context_acquire()/aio_context_release() calls. -Do not use nesting anymore, it is incompatible with the BDRV_POLL_WHILE() macro -used in the block layer and can lead to hangs. - -There is currently no lock ordering rule if a thread needs to acquire multiple -AioContexts simultaneously. Therefore, it is only safe for code holding the -QEMU global mutex to acquire other AioContexts. +AioContext functions like aio_set_fd_handler(), aio_set_event_notifier(), +aio_bh_new(), and aio_timer_new() are thread-safe. They can be used to trigger +activity in an IOThread. Side note: the best way to schedule a function call across threads is to call -aio_bh_schedule_oneshot(). No acquire/release or locking is needed. +aio_bh_schedule_oneshot(). + +The main loop thread can wait synchronously for a condition using +AIO_WAIT_WHILE(). AioContext and the block layer ------------------------------
@@ -124,22 +115,16 @@ Block layer code must therefore expect to run in an IOThread and avoid using old APIs that implicitly use the main loop. See the "How to program for IOThreads" above for information on how to do that. -If main loop code such as a QMP function wishes to access a BlockDriverState -it must first call aio_context_acquire(bdrv_get_aio_context(bs)) to ensure -that callbacks in the IOThread do not run in parallel. - Code running in the monitor typically needs to ensure that past requests from the guest are completed. When a block device is running in an IOThread, the IOThread can also process requests from the guest (via ioeventfd). To achieve both objects, wrap the code between bdrv_drained_begin() and bdrv_drained_end(), thus creating a "drained -section". The functions must be called between aio_context_acquire() -and aio_context_release(). You can freely release and re-acquire the -AioContext within a drained section. +section". -Long-running jobs (usually in the form of coroutines) are best scheduled in -the BlockDriverState's AioContext to avoid the need to acquire/release around -each bdrv_*() call. The functions bdrv_add/remove_aio_context_notifier, -or alternatively blk_add/remove_aio_context_notifier if you use BlockBackends, -can be used to get a notification whenever bdrv_try_change_aio_context() moves a +Long-running jobs (usually in the form of coroutines) are often scheduled in +the BlockDriverState's AioContext. The functions +bdrv_add/remove_aio_context_notifier, or alternatively +blk_add/remove_aio_context_notifier if you use BlockBackends, can be used to +get a notification whenever bdrv_try_change_aio_context() moves a BlockDriverState to a different AioContext.
Signature · 1 line
2.42.0
Re: [PATCH 09/12] docs: remove AioContext lock from IOThread docs
docs/devel/multiple-iothreads.txt
Quoted 11 lines · Stefan Hajnoczi
Encourage the use of locking primitives and stop mentioning the AioContext lock since it is being removed.
Signed-off-by Stefan Hajnoczi <[email protected]>--- docs/devel/multiple-iothreads.txt | 45 +++++++++++-------------------- 1 file changed, 15 insertions(+), 30 deletions(-)docs/devel/multiple-iothreads.txt +0
-1--- a/docs/devel/multiple-iothreads.txt
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
PATCH 10/12 scsi: remove outdated AioContext lock comment
In reply to Stefan HajnocziThe SCSI subsystem no longer uses the AioContext lock. Request processing runs exclusively in the BlockBackend's AioContext since "scsi: only access SCSIDevice->requests from one thread" and hence the lock is unnecessary.
--- hw/scsi/scsi-disk.c | 1 - 1 file changed, 1 deletion(-)
hw/scsi/scsi-disk.c +0 -1
@@ -351,7 +351,6 @@ done:scsi_req_unref (&r->req); } -/* Called with AioContext lock held */ static void scsi_dma_complete (void *opaque,int ret) {SCSIDiskReq *r = (SCSIDiskReq *)opaque;
Signature · 1 line
2.42.0
Re: [PATCH 10/12] scsi: remove outdated AioContext lock comment
Quoted 10 lines · Stefan Hajnoczi
The SCSI subsystem no longer uses the AioContext lock. Request processing runs exclusively in the BlockBackend's AioContext since "scsi: only access
SCSIDevice->requestsfrom one thread" and hence the lock is unnecessary.Signed-off-by Stefan Hajnoczi <[email protected]>--- hw/scsi/scsi-disk.c | 1 - 1 file changed, 1 deletion(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
PATCH 11/12 job: remove outdated AioContext locking comments
In reply to Stefan HajnocziThe AioContext lock no longer exists.
--- include/qemu/job.h | 20 -------------------- 1 file changed, 20 deletions(-)
include/qemu/job.h +0 -20
@@ -67,8 +67,6 @@ typedef struct Job {/** * The completion function that will be called when the job completes. -* Called with AioContext lock held, since many callback implementations -* use bdrv_* functions that require to hold the lock. */ BlockCompletionFunc *cb;
@@ -264,9 +262,6 @@ struct JobDriver {* * This callback will not be invoked if the job has already failed. * If it fails, abort and then clean will be called. -* -* Called with AioContext lock held, since many callbacs implementations -* use bdrv_* functions that require to hold the lock. */ int (*prepare)(Job *job);
@@ -277,9 +272,6 @@ struct JobDriver {* * All jobs will complete with a call to either .commit() or .abort() but * never both. -* -* Called with AioContext lock held, since many callback implementations -* use bdrv_* functions that require to hold the lock. */ void (*commit)(Job *job);
@@ -290,9 +282,6 @@ struct JobDriver {* * All jobs will complete with a call to either .commit() or .abort() but * never both. -* -* Called with AioContext lock held, since many callback implementations -* use bdrv_* functions that require to hold the lock. */ void (*abort)(Job *job);
@@ -301,9 +290,6 @@ struct JobDriver {* .commit() or .abort(). Regardless of which callback is invoked after * completion, .clean() will always be called, even if the job does not * belong to a transaction group. -* -* Called with AioContext lock held, since many callbacs implementations -* use bdrv_* functions that require to hold the lock. */ void (*clean)(Job *job);
@@ -318,17 +304,12 @@ struct JobDriver {* READY). * (If the callback is NULL, the job is assumed to terminate * without I/O.) -* -* Called with AioContext lock held, since many callback implementations -* use bdrv_* functions that require to hold the lock. */ bool (*cancel)(Job *job,bool force);/** * Called when the job is freed. -* Called with AioContext lock held, since many callback implementations -* use bdrv_* functions that require to hold the lock. */ void (*free)(Job *job); };
@@ -424,7 +405,6 @@ void job_ref_locked(Job *job);* Release a reference that was previously acquired with job_ref_locked() or * job_create(). If it's the last reference to the object, it will be freed. * -* Takes AioContext lock internally to invoke a job->driver callback. * Called with job lock held. */ void job_unref_locked (Job *job);
Signature · 1 line
2.42.0
Re: [PATCH 11/12] job: remove outdated AioContext locking comments
Quoted 7 lines · Stefan Hajnoczi
The AioContext lock no longer exists.
Signed-off-by Stefan Hajnoczi <[email protected]>--- include/qemu/job.h | 20 -------------------- 1 file changed, 20 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
PATCH 12/12 block: remove outdated AioContext locking comments
In reply to Stefan HajnocziThe AioContext lock no longer exists.
There is one noteworthy change:
- * More specifically, these functions use BDRV_POLL_WHILE(bs), which
- * requires the caller to be either in the main thread and hold
- * the BlockdriverState (bs) AioContext lock, or directly in the
- * home thread that runs the bs AioContext. Calling them from
- * another thread in another AioContext would cause deadlocks.
+ * More specifically, these functions use BDRV_POLL_WHILE(bs), which requires
+ * the caller to be either in the main thread or directly in the home thread
+ * that runs the bs AioContext. Calling them from another thread in another
+ * AioContext would cause deadlocks.
I am not sure whether deadlocks are still possible. Maybe they have just moved to the fine-grained locks that have replaced the AioContext. Since I am not sure if the deadlocks are gone, I have kept the substance unchanged and just removed mention of the AioContext.
--- include/block/block-common.h | 3 -- include/block/block-io.h | 9 ++-- include/block/block_int-common.h | 2 - block.c | 73 ++++++---------------------- block/block-backend.c | 8 --- block/export/vhost-user-blk-server.c | 4 -- tests/qemu-iotests/202 | 2 +- tests/qemu-iotests/203 | 3 +- 8 files changed, 22 insertions(+), 82 deletions(-)
include/block/block-common.h +0 -3
@@ -70,9 +70,6 @@* automatically takes the graph rdlock when calling the wrapped function. In * the same way, no_co_wrapper_bdrv_wrlock functions automatically take the * graph wrlock. -* -* If the first parameter of the function is a BlockDriverState, BdrvChild or -* BlockBackend pointer, the AioContext lock for it is taken in the wrapper. */ #define no_co_wrapper#define no_co_wrapper_bdrv_rdlock
include/block/block-io.h +4 -5
@@ -332,11 +332,10 @@ bdrv_co_copy_range(BdrvChild *src, int64_t src_offset,* "I/O or GS" API functions. These functions can run without * the BQL, but only in one specific iothread/main loop. * -* More specifically, these functions use BDRV_POLL_WHILE(bs), which -* requires the caller to be either in the main thread and hold -* the BlockdriverState (bs) AioContext lock, or directly in the -* home thread that runs the bs AioContext. Calling them from -* another thread in another AioContext would cause deadlocks. +* More specifically, these functions use BDRV_POLL_WHILE(bs), which requires +* the caller to be either in the main thread or directly in the home thread +* that runs the bs AioContext. Calling them from another thread in another +* AioContext would cause deadlocks. * * Therefore, these functions are not proper I/O, because they * can't run in *any* iothreads, but only in a specific one.
include/block/block_int-common.h +0 -2
@@ -1192,8 +1192,6 @@ struct BlockDriverState {/* The error object in use for blocking operations on backing_hd */ Error *backing_blocker; -/* Protected by AioContext lock */ -/* * If we are reading a disk image, give its size in sectors. * Generally read-only; it is written to by load_snapshot and
block.c +15 -58
194 lines not on this page · raw message
block/block-backend.c +0 -8
@@ -390,8 +390,6 @@ BlockBackend *blk_new(AioContext *ctx, uint64_t perm, uint64_t shared_perm)* Both sets of permissions can be changed later using blk_set_perm(). * * Return the new BlockBackend on success, null on failure. -* -* Callers must hold the AioContext lock of @bs. */ BlockBackend *blk_new_with_bs (BlockDriverState *bs,uint64_t perm,uint64_t shared_perm,Error **errp)
@@ -416,8 +414,6 @@ BlockBackend *blk_new_with_bs(BlockDriverState *bs, uint64_t perm,* Just as with bdrv_open(), after having called this function the reference to * @options belongs to the block layer (even on failure). * -* Called without holding an AioContext lock. -* * TODO: Remove @filename and @flags; it should be possible to specify a whole * BDS tree just by specifying the @options QDict (or @reference, * alternatively). At the time of adding this function, this is not possible,
@@ -872,8 +868,6 @@ BlockBackend *blk_by_public(BlockBackendPublic *public)/* * Disassociates the currently associated BlockDriverState from @blk. -* -* The caller must hold the AioContext lock for the BlockBackend. */ void blk_remove_bs (BlockBackend *blk) {
@@ -915,8 +909,6 @@ void blk_remove_bs(BlockBackend *blk)/* * Associates a new BlockDriverState with @blk. -* -* Callers must hold the AioContext lock of @bs. */ int blk_insert_bs (BlockBackend *blk,BlockDriverState *bs,Error **errp) {
block/export/vhost-user-blk-server.c +0 -4
@@ -278,7 +278,6 @@ static void vu_blk_exp_resize(void *opaque)vu_config_change_msg (&vexp->vu_server.vu_dev); } -/* Called with vexp->export.ctx acquired */ static void vu_blk_drained_begin (void *opaque) {VuBlkExport *vexp = opaque;
@@ -287,7 +286,6 @@ static void vu_blk_drained_begin(void *opaque)vhost_user_server_detach_aio_context (&vexp->vu_server); } -/* Called with vexp->export.blk AioContext acquired */ static void vu_blk_drained_end (void *opaque) {VuBlkExport *vexp = opaque;
@@ -300,8 +298,6 @@ static void vu_blk_drained_end(void *opaque)* Ensures that bdrv_drained_begin() waits until in-flight requests complete * and the server->co_trip coroutine has terminated. It will be restarted in * vhost_user_server_attach_aio_context(). -* -* Called with vexp->export.ctx acquired. */ static bool vu_blk_drained_poll (void *opaque) {
tests/qemu-iotests/202 +1 -1
@@ -21,7 +21,7 @@ # Check that QMP 'transaction' blockdev-snapshot-sync with multiple drives on a # single IOThread completes successfully. This particular command triggered a # hang due to recursive AioContext locking and BDRV_POLL_WHILE(). Protect -# against regressions. +# against regressions even though the AioContext lock no longer exists. import iotests
tests/qemu-iotests/203 +2 -1
@@ -21,7 +21,8 @@ # Check that QMP 'migrate' with multiple drives on a single IOThread completes # successfully. This particular command triggered a hang in the source QEMU # process due to recursive AioContext locking in bdrv_invalidate_all() and -# BDRV_POLL_WHILE(). +# BDRV_POLL_WHILE(). Protect against regressions even though the AioContext +# lock no longer exists. import iotests
Signature · 1 line
2.42.0
Re: [PATCH 12/12] block: remove outdated AioContext locking comments
Quoted 14 lines · Stefan Hajnoczi
The AioContext lock no longer exists.
There is one noteworthy change:
- * More specifically, these functions use
BDRV_POLL_WHILE(bs), which
- * requires the caller to be either in the main thread and hold
- * the BlockdriverState (bs) AioContext lock, or directly in the
- * home thread that runs the bs AioContext. Calling them from
- * another thread in another AioContext would cause deadlocks.
+ * More specifically, these functions useBDRV_POLL_WHILE(bs), which requires
+ * the caller to be either in the main thread or directly in the home thread
+ * that runs the bs AioContext. Calling them from another thread in another
+ * AioContext would cause deadlocks.
Quoted 4 lines
I am not sure whether deadlocks are still possible. Maybe they have just moved to the fine-grained locks that have replaced the AioContext. Since I am not sure if the deadlocks are gone, I have kept the substance unchanged and just removed mention of the AioContext.
I'd rather text that may be overly conservative than an omission that could lead to a bug; so I'm okay with your action there.
Quoted 3 lines
Signed-off-by Stefan Hajnoczi <[email protected]>---
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org