[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 06/15] block: convert bdrv_get_allocated_file_size in generated_c
From: |
Emanuele Giuseppe Esposito |
Subject: |
[PATCH 06/15] block: convert bdrv_get_allocated_file_size in generated_co_wrapper_simple |
Date: |
Wed, 16 Nov 2022 09:07:21 -0500 |
BlockDriver->bdrv_get_allocated_file_size is categorized as IO callback, and
it currently doesn't run in a coroutine.
This makes very difficult to add the graph rdlock, since the
callback traverses the block nodes graph.
Therefore use generated_co_wrapper_simple to automatically
create a wrapper with the same name that will take care of
always calling the function in a coroutine.
This is a generated_co_wrapper_simple callback, which means
it assumes that bdrv_get_allocated_file_size is never caled in a coroutine
context.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
block.c | 7 ++++---
block/qcow2-refcount.c | 2 +-
include/block/block-io.h | 5 ++++-
include/block/block_int-common.h | 3 ++-
4 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/block.c b/block.c
index c7b32ba17a..5650d6fe63 100644
--- a/block.c
+++ b/block.c
@@ -5708,7 +5708,7 @@ static int64_t
bdrv_sum_allocated_file_size(BlockDriverState *bs)
if (child->role & (BDRV_CHILD_DATA | BDRV_CHILD_METADATA |
BDRV_CHILD_FILTERED))
{
- child_size = bdrv_get_allocated_file_size(child->bs);
+ child_size = bdrv_co_get_allocated_file_size(child->bs);
if (child_size < 0) {
return child_size;
}
@@ -5723,10 +5723,11 @@ static int64_t
bdrv_sum_allocated_file_size(BlockDriverState *bs)
* Length of a allocated file in bytes. Sparse files are counted by actual
* allocated space. Return < 0 if error or unknown.
*/
-int64_t bdrv_get_allocated_file_size(BlockDriverState *bs)
+int64_t coroutine_fn bdrv_co_get_allocated_file_size(BlockDriverState *bs)
{
BlockDriver *drv = bs->drv;
IO_CODE();
+ assert_bdrv_graph_readable();
if (!drv) {
return -ENOMEDIUM;
@@ -5744,7 +5745,7 @@ int64_t bdrv_get_allocated_file_size(BlockDriverState *bs)
return -ENOTSUP;
} else if (drv->is_filter) {
/* Filter drivers default to the size of their filtered child */
- return bdrv_get_allocated_file_size(bdrv_filter_bs(bs));
+ return bdrv_co_get_allocated_file_size(bdrv_filter_bs(bs));
} else {
/* Other drivers default to summing their children's sizes */
return bdrv_sum_allocated_file_size(bs);
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 81264740f0..487681d85e 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -3719,7 +3719,7 @@ int coroutine_fn
qcow2_detect_metadata_preallocation(BlockDriverState *bs)
return file_length;
}
- real_allocation = bdrv_get_allocated_file_size(bs->file->bs);
+ real_allocation = bdrv_co_get_allocated_file_size(bs->file->bs);
if (real_allocation < 0) {
return real_allocation;
}
diff --git a/include/block/block-io.h b/include/block/block-io.h
index 4fb95e9b7a..ac509c461f 100644
--- a/include/block/block-io.h
+++ b/include/block/block-io.h
@@ -74,7 +74,10 @@ int64_t generated_co_wrapper
bdrv_nb_sectors(BlockDriverState *bs);
int64_t coroutine_fn bdrv_co_getlength(BlockDriverState *bs);
int64_t generated_co_wrapper bdrv_getlength(BlockDriverState *bs);
-int64_t bdrv_get_allocated_file_size(BlockDriverState *bs);
+int64_t generated_co_wrapper_simple bdrv_get_allocated_file_size(
+ BlockDriverState *bs);
+int64_t coroutine_fn bdrv_co_get_allocated_file_size(BlockDriverState *bs);
+
BlockMeasureInfo *bdrv_measure(BlockDriver *drv, QemuOpts *opts,
BlockDriverState *in_bs, Error **errp);
void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr);
diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h
index d1cf52d4f7..42daf86c65 100644
--- a/include/block/block_int-common.h
+++ b/include/block/block_int-common.h
@@ -725,7 +725,8 @@ struct BlockDriver {
BdrvRequestFlags flags, Error **errp);
/* Called with graph rdlock held. */
int64_t coroutine_fn (*bdrv_getlength)(BlockDriverState *bs);
- int64_t (*bdrv_get_allocated_file_size)(BlockDriverState *bs);
+ /* Called with graph rdlock held. */
+ int64_t coroutine_fn (*bdrv_get_allocated_file_size)(BlockDriverState *bs);
/* Does not need graph rdlock, since it does not traverse the graph */
BlockMeasureInfo *(*bdrv_measure)(QemuOpts *opts, BlockDriverState *in_bs,
--
2.31.1
- [PATCH 00/15] Protect the block layer with a rwlock: part 3, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 06/15] block: convert bdrv_get_allocated_file_size in generated_co_wrapper_simple,
Emanuele Giuseppe Esposito <=
- [PATCH 05/15] block: use bdrv_co_refresh_total_sectors when possible, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 03/15] block-backend: use bdrv_getlength instead of blk_getlength, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 11/15] block: convert bdrv_lock_medium in generated_co_wrapper_simple, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 08/15] block: convert bdrv_is_inserted in generated_co_wrapper_simple, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 09/15] block-coroutine-wrapper: support void functions, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 02/15] block: rename refresh_total_sectors in bdrv_refresh_total_sectors, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 07/15] block: convert bdrv_get_info in generated_co_wrapper, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 12/15] block: convert bdrv_debug_event in generated_co_wrapper, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 15/15] block: rename newly converted BlockDriver IO coroutine functions, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 04/15] block: convert bdrv_refresh_total_sectors in generated_co_wrapper, Emanuele Giuseppe Esposito, 2022/11/16