diff options
author | Fiona Ebner <f.ebner@proxmox.com> | 2025-05-30 17:11:03 +0200 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2025-07-14 15:41:38 +0200 |
commit | 47bc2ed6f6a8eb637ede90c0545bca082b68379f (patch) | |
tree | 9da5b95153d6bf7e7ba6eca3460482e4b421b624 | |
parent | 9918b2e95ed55680e5b2016149dd51610c698611 (diff) | |
download | qemu-47bc2ed6f6a8eb637ede90c0545bca082b68379f.zip qemu-47bc2ed6f6a8eb637ede90c0545bca082b68379f.tar.gz qemu-47bc2ed6f6a8eb637ede90c0545bca082b68379f.tar.bz2 |
block/commit: switch to bdrv_set_backing_hd_drained() variant
This is in preparation to mark bdrv_set_backing_hd() as
GRAPH_UNLOCKED.
Switch to using the bdrv_set_backing_hd_drained() variant. For the
first pair of calls to avoid draining and locking twice in a row
within the individual calls. For the third call, so that the drained
and locked section can also cover bdrv_cow_bs().
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
Message-ID: <20250530151125.955508-27-f.ebner@proxmox.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
-rw-r--r-- | block/commit.c | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/block/commit.c b/block/commit.c index dc19424..c9690a5 100644 --- a/block/commit.c +++ b/block/commit.c @@ -514,28 +514,32 @@ int bdrv_commit(BlockDriverState *bs) Error *local_err = NULL; GLOBAL_STATE_CODE(); - GRAPH_RDLOCK_GUARD_MAINLOOP(); if (!drv) return -ENOMEDIUM; + bdrv_graph_rdlock_main_loop(); + backing_file_bs = bdrv_cow_bs(bs); if (!backing_file_bs) { - return -ENOTSUP; + ret = -ENOTSUP; + goto out; } if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_COMMIT_SOURCE, NULL) || bdrv_op_is_blocked(backing_file_bs, BLOCK_OP_TYPE_COMMIT_TARGET, NULL)) { - return -EBUSY; + ret = -EBUSY; + goto out; } ro = bdrv_is_read_only(backing_file_bs); if (ro) { if (bdrv_reopen_set_read_only(backing_file_bs, false, NULL)) { - return -EACCES; + ret = -EACCES; + goto out; } } @@ -559,8 +563,14 @@ int bdrv_commit(BlockDriverState *bs) goto ro_cleanup; } - bdrv_set_backing_hd(commit_top_bs, backing_file_bs, &error_abort); - bdrv_set_backing_hd(bs, commit_top_bs, &error_abort); + bdrv_graph_rdunlock_main_loop(); + + bdrv_graph_wrlock_drained(); + bdrv_set_backing_hd_drained(commit_top_bs, backing_file_bs, &error_abort); + bdrv_set_backing_hd_drained(bs, commit_top_bs, &error_abort); + bdrv_graph_wrunlock(); + + bdrv_graph_rdlock_main_loop(); ret = blk_insert_bs(backing, backing_file_bs, &local_err); if (ret < 0) { @@ -635,9 +645,14 @@ int bdrv_commit(BlockDriverState *bs) ret = 0; ro_cleanup: blk_unref(backing); + + bdrv_graph_rdunlock_main_loop(); + bdrv_graph_wrlock_drained(); if (bdrv_cow_bs(bs) != backing_file_bs) { - bdrv_set_backing_hd(bs, backing_file_bs, &error_abort); + bdrv_set_backing_hd_drained(bs, backing_file_bs, &error_abort); } + bdrv_graph_wrunlock(); + bdrv_graph_rdlock_main_loop(); bdrv_unref(commit_top_bs); blk_unref(src); @@ -646,5 +661,8 @@ ro_cleanup: bdrv_reopen_set_read_only(backing_file_bs, true, NULL); } +out: + bdrv_graph_rdunlock_main_loop(); + return ret; } |