aboutsummaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2023-10-27 17:53:28 +0200
committerKevin Wolf <kwolf@redhat.com>2023-11-08 17:56:17 +0100
commite2dd273754eb9a47c33660b4e14074e8e96ada4d (patch)
treee637b007eaa807c7f8073a3f2173273efeb937de /block
parent244b26d259bc56097b2d82690847cb7657e22830 (diff)
block: Introduce bdrv_co_change_backing_file()
bdrv_change_backing_file() is called both inside and outside coroutine context. This makes it difficult for it to take the graph lock internally. It also means that driver implementations need to be able to run outside of coroutines, too. Switch it to the usual model with a coroutine based implementation and a co_wrapper instead. The new function is marked GRAPH_RDLOCK. As the co_wrapper now runs the function in the AioContext of the node (as it should always have done), this is not GLOBAL_STATE_CODE() any more. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Message-ID: <20231027155333.420094-20-kwolf@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block')
-rw-r--r--block/qcow2.c128
-rw-r--r--block/qed.c64
2 files changed, 98 insertions, 94 deletions
diff --git a/block/qcow2.c b/block/qcow2.c
index a1443a31aa..875e613ea9 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -3155,8 +3155,9 @@ fail:
return ret;
}
-static int qcow2_change_backing_file(BlockDriverState *bs,
- const char *backing_file, const char *backing_fmt)
+static int coroutine_fn GRAPH_RDLOCK
+qcow2_co_change_backing_file(BlockDriverState *bs, const char *backing_file,
+ const char *backing_fmt)
{
BDRVQcow2State *s = bs->opaque;
@@ -3816,8 +3817,11 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
backing_format = BlockdevDriver_str(qcow2_opts->backing_fmt);
}
- ret = bdrv_change_backing_file(blk_bs(blk), qcow2_opts->backing_file,
- backing_format, false);
+ bdrv_graph_co_rdlock();
+ ret = bdrv_co_change_backing_file(blk_bs(blk), qcow2_opts->backing_file,
+ backing_format, false);
+ bdrv_graph_co_rdunlock();
+
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not assign backing file '%s' "
"with format '%s'", qcow2_opts->backing_file,
@@ -6115,64 +6119,64 @@ static const char *const qcow2_strong_runtime_opts[] = {
};
BlockDriver bdrv_qcow2 = {
- .format_name = "qcow2",
- .instance_size = sizeof(BDRVQcow2State),
- .bdrv_probe = qcow2_probe,
- .bdrv_open = qcow2_open,
- .bdrv_close = qcow2_close,
- .bdrv_reopen_prepare = qcow2_reopen_prepare,
- .bdrv_reopen_commit = qcow2_reopen_commit,
- .bdrv_reopen_commit_post = qcow2_reopen_commit_post,
- .bdrv_reopen_abort = qcow2_reopen_abort,
- .bdrv_join_options = qcow2_join_options,
- .bdrv_child_perm = bdrv_default_perms,
- .bdrv_co_create_opts = qcow2_co_create_opts,
- .bdrv_co_create = qcow2_co_create,
- .bdrv_has_zero_init = qcow2_has_zero_init,
- .bdrv_co_block_status = qcow2_co_block_status,
-
- .bdrv_co_preadv_part = qcow2_co_preadv_part,
- .bdrv_co_pwritev_part = qcow2_co_pwritev_part,
- .bdrv_co_flush_to_os = qcow2_co_flush_to_os,
-
- .bdrv_co_pwrite_zeroes = qcow2_co_pwrite_zeroes,
- .bdrv_co_pdiscard = qcow2_co_pdiscard,
- .bdrv_co_copy_range_from = qcow2_co_copy_range_from,
- .bdrv_co_copy_range_to = qcow2_co_copy_range_to,
- .bdrv_co_truncate = qcow2_co_truncate,
- .bdrv_co_pwritev_compressed_part = qcow2_co_pwritev_compressed_part,
- .bdrv_make_empty = qcow2_make_empty,
-
- .bdrv_snapshot_create = qcow2_snapshot_create,
- .bdrv_snapshot_goto = qcow2_snapshot_goto,
- .bdrv_snapshot_delete = qcow2_snapshot_delete,
- .bdrv_snapshot_list = qcow2_snapshot_list,
- .bdrv_snapshot_load_tmp = qcow2_snapshot_load_tmp,
- .bdrv_measure = qcow2_measure,
- .bdrv_co_get_info = qcow2_co_get_info,
- .bdrv_get_specific_info = qcow2_get_specific_info,
-
- .bdrv_co_save_vmstate = qcow2_co_save_vmstate,
- .bdrv_co_load_vmstate = qcow2_co_load_vmstate,
-
- .is_format = true,
- .supports_backing = true,
- .bdrv_change_backing_file = qcow2_change_backing_file,
-
- .bdrv_refresh_limits = qcow2_refresh_limits,
- .bdrv_co_invalidate_cache = qcow2_co_invalidate_cache,
- .bdrv_inactivate = qcow2_inactivate,
-
- .create_opts = &qcow2_create_opts,
- .amend_opts = &qcow2_amend_opts,
- .strong_runtime_opts = qcow2_strong_runtime_opts,
- .mutable_opts = mutable_opts,
- .bdrv_co_check = qcow2_co_check,
- .bdrv_amend_options = qcow2_amend_options,
- .bdrv_co_amend = qcow2_co_amend,
-
- .bdrv_detach_aio_context = qcow2_detach_aio_context,
- .bdrv_attach_aio_context = qcow2_attach_aio_context,
+ .format_name = "qcow2",
+ .instance_size = sizeof(BDRVQcow2State),
+ .bdrv_probe = qcow2_probe,
+ .bdrv_open = qcow2_open,
+ .bdrv_close = qcow2_close,
+ .bdrv_reopen_prepare = qcow2_reopen_prepare,
+ .bdrv_reopen_commit = qcow2_reopen_commit,
+ .bdrv_reopen_commit_post = qcow2_reopen_commit_post,
+ .bdrv_reopen_abort = qcow2_reopen_abort,
+ .bdrv_join_options = qcow2_join_options,
+ .bdrv_child_perm = bdrv_default_perms,
+ .bdrv_co_create_opts = qcow2_co_create_opts,
+ .bdrv_co_create = qcow2_co_create,
+ .bdrv_has_zero_init = qcow2_has_zero_init,
+ .bdrv_co_block_status = qcow2_co_block_status,
+
+ .bdrv_co_preadv_part = qcow2_co_preadv_part,
+ .bdrv_co_pwritev_part = qcow2_co_pwritev_part,
+ .bdrv_co_flush_to_os = qcow2_co_flush_to_os,
+
+ .bdrv_co_pwrite_zeroes = qcow2_co_pwrite_zeroes,
+ .bdrv_co_pdiscard = qcow2_co_pdiscard,
+ .bdrv_co_copy_range_from = qcow2_co_copy_range_from,
+ .bdrv_co_copy_range_to = qcow2_co_copy_range_to,
+ .bdrv_co_truncate = qcow2_co_truncate,
+ .bdrv_co_pwritev_compressed_part = qcow2_co_pwritev_compressed_part,
+ .bdrv_make_empty = qcow2_make_empty,
+
+ .bdrv_snapshot_create = qcow2_snapshot_create,
+ .bdrv_snapshot_goto = qcow2_snapshot_goto,
+ .bdrv_snapshot_delete = qcow2_snapshot_delete,
+ .bdrv_snapshot_list = qcow2_snapshot_list,
+ .bdrv_snapshot_load_tmp = qcow2_snapshot_load_tmp,
+ .bdrv_measure = qcow2_measure,
+ .bdrv_co_get_info = qcow2_co_get_info,
+ .bdrv_get_specific_info = qcow2_get_specific_info,
+
+ .bdrv_co_save_vmstate = qcow2_co_save_vmstate,
+ .bdrv_co_load_vmstate = qcow2_co_load_vmstate,
+
+ .is_format = true,
+ .supports_backing = true,
+ .bdrv_co_change_backing_file = qcow2_co_change_backing_file,
+
+ .bdrv_refresh_limits = qcow2_refresh_limits,
+ .bdrv_co_invalidate_cache = qcow2_co_invalidate_cache,
+ .bdrv_inactivate = qcow2_inactivate,
+
+ .create_opts = &qcow2_create_opts,
+ .amend_opts = &qcow2_amend_opts,
+ .strong_runtime_opts = qcow2_strong_runtime_opts,
+ .mutable_opts = mutable_opts,
+ .bdrv_co_check = qcow2_co_check,
+ .bdrv_amend_options = qcow2_amend_options,
+ .bdrv_co_amend = qcow2_co_amend,
+
+ .bdrv_detach_aio_context = qcow2_detach_aio_context,
+ .bdrv_attach_aio_context = qcow2_attach_aio_context,
.bdrv_supports_persistent_dirty_bitmap =
qcow2_supports_persistent_dirty_bitmap,
diff --git a/block/qed.c b/block/qed.c
index 686ad711f7..996aa384fe 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -1498,9 +1498,9 @@ bdrv_qed_co_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
return 0;
}
-static int bdrv_qed_change_backing_file(BlockDriverState *bs,
- const char *backing_file,
- const char *backing_fmt)
+static int coroutine_fn GRAPH_RDLOCK
+bdrv_qed_co_change_backing_file(BlockDriverState *bs, const char *backing_file,
+ const char *backing_fmt)
{
BDRVQEDState *s = bs->opaque;
QEDHeader new_header, le_header;
@@ -1562,7 +1562,7 @@ static int bdrv_qed_change_backing_file(BlockDriverState *bs,
}
/* Write new header */
- ret = bdrv_pwrite_sync(bs->file, 0, buffer_len, buffer, 0);
+ ret = bdrv_co_pwrite_sync(bs->file, 0, buffer_len, buffer, 0);
g_free(buffer);
if (ret == 0) {
memcpy(&s->header, &new_header, sizeof(new_header));
@@ -1636,34 +1636,34 @@ static QemuOptsList qed_create_opts = {
};
static BlockDriver bdrv_qed = {
- .format_name = "qed",
- .instance_size = sizeof(BDRVQEDState),
- .create_opts = &qed_create_opts,
- .is_format = true,
- .supports_backing = true,
-
- .bdrv_probe = bdrv_qed_probe,
- .bdrv_open = bdrv_qed_open,
- .bdrv_close = bdrv_qed_close,
- .bdrv_reopen_prepare = bdrv_qed_reopen_prepare,
- .bdrv_child_perm = bdrv_default_perms,
- .bdrv_co_create = bdrv_qed_co_create,
- .bdrv_co_create_opts = bdrv_qed_co_create_opts,
- .bdrv_has_zero_init = bdrv_has_zero_init_1,
- .bdrv_co_block_status = bdrv_qed_co_block_status,
- .bdrv_co_readv = bdrv_qed_co_readv,
- .bdrv_co_writev = bdrv_qed_co_writev,
- .bdrv_co_pwrite_zeroes = bdrv_qed_co_pwrite_zeroes,
- .bdrv_co_truncate = bdrv_qed_co_truncate,
- .bdrv_co_getlength = bdrv_qed_co_getlength,
- .bdrv_co_get_info = bdrv_qed_co_get_info,
- .bdrv_refresh_limits = bdrv_qed_refresh_limits,
- .bdrv_change_backing_file = bdrv_qed_change_backing_file,
- .bdrv_co_invalidate_cache = bdrv_qed_co_invalidate_cache,
- .bdrv_co_check = bdrv_qed_co_check,
- .bdrv_detach_aio_context = bdrv_qed_detach_aio_context,
- .bdrv_attach_aio_context = bdrv_qed_attach_aio_context,
- .bdrv_drain_begin = bdrv_qed_drain_begin,
+ .format_name = "qed",
+ .instance_size = sizeof(BDRVQEDState),
+ .create_opts = &qed_create_opts,
+ .is_format = true,
+ .supports_backing = true,
+
+ .bdrv_probe = bdrv_qed_probe,
+ .bdrv_open = bdrv_qed_open,
+ .bdrv_close = bdrv_qed_close,
+ .bdrv_reopen_prepare = bdrv_qed_reopen_prepare,
+ .bdrv_child_perm = bdrv_default_perms,
+ .bdrv_co_create = bdrv_qed_co_create,
+ .bdrv_co_create_opts = bdrv_qed_co_create_opts,
+ .bdrv_has_zero_init = bdrv_has_zero_init_1,
+ .bdrv_co_block_status = bdrv_qed_co_block_status,
+ .bdrv_co_readv = bdrv_qed_co_readv,
+ .bdrv_co_writev = bdrv_qed_co_writev,
+ .bdrv_co_pwrite_zeroes = bdrv_qed_co_pwrite_zeroes,
+ .bdrv_co_truncate = bdrv_qed_co_truncate,
+ .bdrv_co_getlength = bdrv_qed_co_getlength,
+ .bdrv_co_get_info = bdrv_qed_co_get_info,
+ .bdrv_refresh_limits = bdrv_qed_refresh_limits,
+ .bdrv_co_change_backing_file = bdrv_qed_co_change_backing_file,
+ .bdrv_co_invalidate_cache = bdrv_qed_co_invalidate_cache,
+ .bdrv_co_check = bdrv_qed_co_check,
+ .bdrv_detach_aio_context = bdrv_qed_detach_aio_context,
+ .bdrv_attach_aio_context = bdrv_qed_attach_aio_context,
+ .bdrv_drain_begin = bdrv_qed_drain_begin,
};
static void bdrv_qed_init(void)