[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 08/14] block: Convert bdrv_get_allocated_file_size() to co_wrappe
From: |
Kevin Wolf |
Subject: |
[PATCH 08/14] block: Convert bdrv_get_allocated_file_size() to co_wrapper |
Date: |
Tue, 13 Dec 2022 09:53:14 +0100 |
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
bdrv_get_allocated_file_size() is categorized as an I/O function, and it
currently doesn't run in a coroutine. We should let it take a graph
rdlock since it traverses the block nodes graph, which however is only
possible in a coroutine.
Therefore turn it into a co_wrapper to move the actual function into a
coroutine where the lock can be taken.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
include/block/block-io.h | 4 +++-
include/block/block_int-common.h | 3 ++-
block.c | 6 +++---
block/qcow2-refcount.c | 2 +-
4 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/include/block/block-io.h b/include/block/block-io.h
index fe1fa339be..b1c6abee7b 100644
--- a/include/block/block-io.h
+++ b/include/block/block-io.h
@@ -79,7 +79,9 @@ int64_t co_wrapper_mixed bdrv_nb_sectors(BlockDriverState
*bs);
int64_t coroutine_fn bdrv_co_getlength(BlockDriverState *bs);
int64_t co_wrapper_mixed bdrv_getlength(BlockDriverState *bs);
-int64_t bdrv_get_allocated_file_size(BlockDriverState *bs);
+int64_t coroutine_fn bdrv_co_get_allocated_file_size(BlockDriverState *bs);
+int64_t co_wrapper bdrv_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 0e705e08f4..7b324c3bfc 100644
--- a/include/block/block_int-common.h
+++ b/include/block/block_int-common.h
@@ -685,7 +685,8 @@ struct BlockDriver {
bool exact, PreallocMode prealloc,
BdrvRequestFlags flags, Error **errp);
int64_t coroutine_fn (*bdrv_getlength)(BlockDriverState *bs);
- int64_t (*bdrv_get_allocated_file_size)(BlockDriverState *bs);
+ int64_t coroutine_fn (*bdrv_get_allocated_file_size)(BlockDriverState *bs);
+
BlockMeasureInfo *(*bdrv_measure)(QemuOpts *opts, BlockDriverState *in_bs,
Error **errp);
diff --git a/block.c b/block.c
index e1a8f7af4d..f3d6693113 100644
--- a/block.c
+++ b/block.c
@@ -5732,7 +5732,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;
}
@@ -5747,7 +5747,7 @@ 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();
@@ -5768,7 +5768,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;
}
--
2.38.1
- Re: [PATCH 07/14] block: use bdrv_co_refresh_total_sectors when possible, (continued)
- [PATCH 01/14] block-coroutine-wrapper: support void functions, Kevin Wolf, 2022/12/13
- [PATCH 03/14] block: Convert bdrv_io_unplug() to co_wrapper, Kevin Wolf, 2022/12/13
- [PATCH 06/14] block-backend: use bdrv_getlength instead of blk_getlength, Kevin Wolf, 2022/12/13
- [PATCH 09/14] block: Convert bdrv_get_info() to co_wrapper_mixed, Kevin Wolf, 2022/12/13
- [PATCH 04/14] block: Rename refresh_total_sectors to bdrv_refresh_total_sectors, Kevin Wolf, 2022/12/13
- [PATCH 08/14] block: Convert bdrv_get_allocated_file_size() to co_wrapper,
Kevin Wolf <=
- [PATCH 10/14] block: Convert bdrv_is_inserted() to co_wrapper, Kevin Wolf, 2022/12/13
- [PATCH 05/14] block: Convert bdrv_refresh_total_sectors() to co_wrapper_mixed, Kevin Wolf, 2022/12/13
- [PATCH 13/14] block: Convert bdrv_debug_event to co_wrapper_mixed, Kevin Wolf, 2022/12/13
- [PATCH 12/14] block: convert bdrv_lock_medium in co_wrapper, Kevin Wolf, 2022/12/13
- [PATCH 14/14] block: Rename newly converted BlockDriver IO coroutine functions, Kevin Wolf, 2022/12/13
- [PATCH 11/14] block: Convert bdrv_eject() to co_wrapper, Kevin Wolf, 2022/12/13
- Re: [PATCH 00/14] block: Move more functions to coroutines, Emanuele Giuseppe Esposito, 2022/12/15