aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFiona Ebner <f.ebner@proxmox.com>2025-05-30 17:11:06 +0200
committerKevin Wolf <kwolf@redhat.com>2025-07-14 15:41:57 +0200
commitc7af387c7b58f8ffcd412b175768f6ccd591b1fc (patch)
tree61234bcf46f950f2b3a46cd9fb3f97a8c616be30
parentde0d24c711f6d4deaf51de2d5001c0516a10ef22 (diff)
downloadqemu-c7af387c7b58f8ffcd412b175768f6ccd591b1fc.zip
qemu-c7af387c7b58f8ffcd412b175768f6ccd591b1fc.tar.gz
qemu-c7af387c7b58f8ffcd412b175768f6ccd591b1fc.tar.bz2
blockdev: avoid locking and draining multiple times in external_snapshot_abort()
By using the appropriate variants bdrv_set_backing_hd_drained() and bdrv_try_change_aio_context_locked(), there only needs to be a single drained and write-locked section in external_snapshot_abort(). Signed-off-by: Fiona Ebner <f.ebner@proxmox.com> Message-ID: <20250530151125.955508-30-f.ebner@proxmox.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
-rw-r--r--blockdev.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/blockdev.c b/blockdev.c
index e625534..3c53472 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1580,11 +1580,19 @@ static void external_snapshot_abort(void *opaque)
AioContext *tmp_context;
int ret;
+ bdrv_graph_wrlock_drained();
+
aio_context = bdrv_get_aio_context(state->old_bs);
- bdrv_ref(state->old_bs); /* we can't let bdrv_set_backind_hd()
- close state->old_bs; we need it */
- bdrv_set_backing_hd(state->new_bs, NULL, &error_abort);
+ /*
+ * Note that state->old_bs would not disappear during the
+ * write-locked section, because the unref from
+ * bdrv_set_backing_hd_drained() only happens at the end of the
+ * write-locked section. However, just be explicit about keeping a
+ * reference and don't rely on that implicit detail.
+ */
+ bdrv_ref(state->old_bs);
+ bdrv_set_backing_hd_drained(state->new_bs, NULL, &error_abort);
/*
* The call to bdrv_set_backing_hd() above returns state->old_bs to
@@ -1593,16 +1601,14 @@ static void external_snapshot_abort(void *opaque)
*/
tmp_context = bdrv_get_aio_context(state->old_bs);
if (aio_context != tmp_context) {
- ret = bdrv_try_change_aio_context(state->old_bs,
- aio_context, NULL, NULL);
+ ret = bdrv_try_change_aio_context_locked(state->old_bs,
+ aio_context, NULL,
+ NULL);
assert(ret == 0);
}
- bdrv_drained_begin(state->new_bs);
- bdrv_graph_wrlock();
bdrv_replace_node(state->new_bs, state->old_bs, &error_abort);
bdrv_graph_wrunlock();
- bdrv_drained_end(state->new_bs);
bdrv_unref(state->old_bs); /* bdrv_replace_node() ref'ed old_bs */
}