aboutsummaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2023-06-05 10:57:10 +0200
committerKevin Wolf <kwolf@redhat.com>2023-06-28 08:46:23 +0200
commit31b2ddfea304afc498aca8cac171020ef33eb89b (patch)
tree3d0f42e0e2539c0f354169ffc2678456e8653190 /block
parent22dd9405446f5301f32be4f9e88db6d9b582fd03 (diff)
downloadqemu-31b2ddfea304afc498aca8cac171020ef33eb89b.zip
qemu-31b2ddfea304afc498aca8cac171020ef33eb89b.tar.gz
qemu-31b2ddfea304afc498aca8cac171020ef33eb89b.tar.bz2
graph-lock: Unlock the AioContext while polling
If the caller keeps the AioContext lock for a block node in an iothread, polling in bdrv_graph_wrlock() deadlocks if the condition isn't fulfilled immediately. Now that all callers make sure to actually have the AioContext locked when they call bdrv_replace_child_noperm() like they should, we can change bdrv_graph_wrlock() to take a BlockDriverState whose AioContext lock the caller holds (NULL if it doesn't) and unlock it temporarily while polling. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Message-ID: <20230605085711.21261-11-kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block')
-rw-r--r--block/graph-lock.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/block/graph-lock.c b/block/graph-lock.c
index a92c6ae..3bf2591 100644
--- a/block/graph-lock.c
+++ b/block/graph-lock.c
@@ -110,8 +110,10 @@ static uint32_t reader_count(void)
}
#endif
-void bdrv_graph_wrlock(void)
+void bdrv_graph_wrlock(BlockDriverState *bs)
{
+ AioContext *ctx = NULL;
+
GLOBAL_STATE_CODE();
/*
* TODO Some callers hold an AioContext lock when this is called, which
@@ -120,7 +122,22 @@ void bdrv_graph_wrlock(void)
*/
#if 0
assert(!qatomic_read(&has_writer));
+#endif
+
+ /*
+ * Release only non-mainloop AioContext. The mainloop often relies on the
+ * BQL and doesn't lock the main AioContext before doing things.
+ */
+ if (bs) {
+ ctx = bdrv_get_aio_context(bs);
+ if (ctx != qemu_get_aio_context()) {
+ aio_context_release(ctx);
+ } else {
+ ctx = NULL;
+ }
+ }
+#if 0
/* Make sure that constantly arriving new I/O doesn't cause starvation */
bdrv_drain_all_begin_nopoll();
@@ -150,6 +167,10 @@ void bdrv_graph_wrlock(void)
bdrv_drain_all_end();
#endif
+
+ if (ctx) {
+ aio_context_acquire(bdrv_get_aio_context(bs));
+ }
}
void bdrv_graph_wrunlock(void)