[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 06/11] block: Convert bdrv_query_block_graph_info to coroutine
From: |
Fabiano Rosas |
Subject: |
[PATCH v3 06/11] block: Convert bdrv_query_block_graph_info to coroutine |
Date: |
Tue, 9 Apr 2024 11:59:12 -0300 |
We're converting callers of bdrv_co_get_allocated_file_size() to run
in coroutines because that function will be made asynchronous when
called (indirectly) from the QMP dispatcher.
This function is a candidate because it calls bdrv_do_query_node_info(),
which in turn calls bdrv_co_get_allocated_file_size().
All the functions called from bdrv_do_query_node_info() onwards are
coroutine-safe, either have a coroutine version themselves[1] or are
mostly simple code/string manipulation[2].
1) bdrv_co_getlength(), bdrv_co_get_allocated_file_size(),
bdrv_co_get_info();
2) bdrv_refresh_filename(), bdrv_get_format_name(),
bdrv_get_full_backing_filename(), bdrv_query_snapshot_info_list(),
bdrv_get_specific_info();
Signed-off-by: Fabiano Rosas <farosas@suse.de>
Reviewed-by: Hanna Czenczek <hreitz@redhat.com>
---
block/qapi.c | 14 ++++++++------
include/block/qapi.h | 6 +++++-
qemu-img.c | 3 ---
3 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/block/qapi.c b/block/qapi.c
index 26a9510345..7b1cf48246 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -370,7 +370,7 @@ fail:
}
/**
- * bdrv_query_block_graph_info:
+ * bdrv_co_query_block_graph_info:
* @bs: root node to start from
* @p_info: location to store image information
* @errp: location to store error information
@@ -379,17 +379,19 @@ fail:
*
* @p_info will be set only on success. On error, store error in @errp.
*/
-void bdrv_query_block_graph_info(BlockDriverState *bs,
- BlockGraphInfo **p_info,
- Error **errp)
+void coroutine_fn
+bdrv_co_query_block_graph_info(BlockDriverState *bs, BlockGraphInfo **p_info,
+ Error **errp)
{
ERRP_GUARD();
BlockGraphInfo *info;
BlockChildInfoList **children_list_tail;
BdrvChild *c;
+ assert_bdrv_graph_readable();
+
info = g_new0(BlockGraphInfo, 1);
- bdrv_do_query_node_info(bs, qapi_BlockGraphInfo_base(info), errp);
+ bdrv_co_do_query_node_info(bs, qapi_BlockGraphInfo_base(info), errp);
if (*errp) {
goto fail;
}
@@ -403,7 +405,7 @@ void bdrv_query_block_graph_info(BlockDriverState *bs,
QAPI_LIST_APPEND(children_list_tail, c_info);
c_info->name = g_strdup(c->name);
- bdrv_query_block_graph_info(c->bs, &c_info->info, errp);
+ bdrv_co_query_block_graph_info(c->bs, &c_info->info, errp);
if (*errp) {
goto fail;
}
diff --git a/include/block/qapi.h b/include/block/qapi.h
index 234730b3de..76be9cc3e5 100644
--- a/include/block/qapi.h
+++ b/include/block/qapi.h
@@ -41,7 +41,11 @@ bdrv_query_snapshot_info_list(BlockDriverState *bs,
void GRAPH_RDLOCK
bdrv_query_image_info(BlockDriverState *bs, ImageInfo **p_info, bool flat,
bool skip_implicit_filters, Error **errp);
-void GRAPH_RDLOCK
+
+void coroutine_fn GRAPH_RDLOCK
+bdrv_co_query_block_graph_info(BlockDriverState *bs, BlockGraphInfo **p_info,
+ Error **errp);
+void co_wrapper_bdrv_rdlock
bdrv_query_block_graph_info(BlockDriverState *bs, BlockGraphInfo **p_info,
Error **errp);
diff --git a/qemu-img.c b/qemu-img.c
index 7668f86769..19db8f18fc 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -2958,10 +2958,7 @@ static BlockGraphInfoList *collect_image_info_list(bool
image_opts,
* duplicate the backing chain information that we obtain by walking
* the chain manually here.
*/
- bdrv_graph_rdlock_main_loop();
bdrv_query_block_graph_info(bs, &info, &err);
- bdrv_graph_rdunlock_main_loop();
-
if (err) {
error_report_err(err);
blk_unref(blk);
--
2.35.3
- [PATCH v3 00/11] block: Convert qmp_query_block into a coroutine, Fabiano Rosas, 2024/04/09
- [PATCH v3 01/11] block: Allow the wrapper script to see functions declared in qapi.h, Fabiano Rosas, 2024/04/09
- [PATCH v3 02/11] block: Temporarily mark bdrv_co_get_allocated_file_size as mixed, Fabiano Rosas, 2024/04/09
- [PATCH v3 03/11] block: Take the graph lock in bdrv_snapshot_list, Fabiano Rosas, 2024/04/09
- [PATCH v3 04/11] block: Reschedule query-block during qcow2 invalidation, Fabiano Rosas, 2024/04/09
- [PATCH v3 05/11] block: Run bdrv_do_query_node_info in a coroutine, Fabiano Rosas, 2024/04/09
- [PATCH v3 06/11] block: Convert bdrv_query_block_graph_info to coroutine,
Fabiano Rosas <=
- [PATCH v3 07/11] block: Convert bdrv_query_image_info to coroutine, Fabiano Rosas, 2024/04/09
- [PATCH v3 08/11] block: Convert bdrv_block_device_info into co_wrapper, Fabiano Rosas, 2024/04/09
- [PATCH v3 09/11] block: Don't query all block devices at hmp_nbd_server_start, Fabiano Rosas, 2024/04/09
- [PATCH v3 10/11] block: Convert qmp_query_block and qmp_query_named_block_nodes to coroutine, Fabiano Rosas, 2024/04/09
- [PATCH v3 11/11] block: Add a thread-pool version of fstat, Fabiano Rosas, 2024/04/09