Skip to content

Commit 3edf660

Browse files
stefanhaRHkevmw
authored andcommitted
aio-wait: avoid AioContext lock in aio_wait_bh_oneshot()
There is no need for the AioContext lock in aio_wait_bh_oneshot(). It's easy to remove the lock from existing callers and then switch from AIO_WAIT_WHILE() to AIO_WAIT_WHILE_UNLOCKED() in aio_wait_bh_oneshot(). Document that the AioContext lock should not be held across aio_wait_bh_oneshot(). Holding a lock across aio_poll() can cause deadlock so we don't want callers to do that. This is a step towards getting rid of the AioContext lock. Cc: Paolo Bonzini <[email protected]> Signed-off-by: Stefan Hajnoczi <[email protected]> Message-Id: <[email protected]> Reviewed-by: Paolo Bonzini <[email protected]> Reviewed-by: Emanuele Giuseppe Esposito <[email protected]> Reviewed-by: Kevin Wolf <[email protected]> Signed-off-by: Kevin Wolf <[email protected]>
1 parent 17ac39c commit 3edf660

File tree

4 files changed

+4
-5
lines changed

4 files changed

+4
-5
lines changed

hw/block/dataplane/virtio-blk.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,10 @@ void virtio_blk_data_plane_stop(VirtIODevice *vdev)
315315
s->stopping = true;
316316
trace_virtio_blk_data_plane_stop(s);
317317

318-
aio_context_acquire(s->ctx);
319318
aio_wait_bh_oneshot(s->ctx, virtio_blk_data_plane_stop_bh, s);
320319

320+
aio_context_acquire(s->ctx);
321+
321322
/* Wait for virtio_blk_dma_restart_bh() and in flight I/O to complete */
322323
blk_drain(s->conf->conf.blk);
323324

hw/scsi/virtio-scsi-dataplane.c

-2
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,7 @@ void virtio_scsi_dataplane_stop(VirtIODevice *vdev)
197197
}
198198
s->dataplane_stopping = true;
199199

200-
aio_context_acquire(s->ctx);
201200
aio_wait_bh_oneshot(s->ctx, virtio_scsi_dataplane_stop_bh, s);
202-
aio_context_release(s->ctx);
203201

204202
blk_drain_all(); /* ensure there are no in-flight requests */
205203

include/block/aio-wait.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void aio_wait_kick(void);
131131
*
132132
* Run a BH in @ctx and wait for it to complete.
133133
*
134-
* Must be called from the main loop thread with @ctx acquired exactly once.
134+
* Must be called from the main loop thread without @ctx acquired.
135135
* Note that main loop event processing may occur.
136136
*/
137137
void aio_wait_bh_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque);

util/aio-wait.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,5 @@ void aio_wait_bh_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
8282
assert(qemu_get_current_aio_context() == qemu_get_aio_context());
8383

8484
aio_bh_schedule_oneshot(ctx, aio_wait_bh, &data);
85-
AIO_WAIT_WHILE(ctx, !data.done);
85+
AIO_WAIT_WHILE_UNLOCKED(NULL, !data.done);
8686
}

0 commit comments

Comments
 (0)