aboutsummaryrefslogtreecommitdiff
path: root/block/io.c
diff options
context:
space:
mode:
authorMax Reitz <mreitz@redhat.com>2019-02-13 18:05:23 +0100
committerKevin Wolf <kwolf@redhat.com>2020-09-07 12:31:31 +0200
commit549ec0d9783e1a94e502e677fe0ce4a90c0bd7df (patch)
treee9688e74c6fd5626fae327b3a52fab73250768e6 /block/io.c
parent05ea385afdfe5d0886265880bfd14d17192beb03 (diff)
block: Inline bdrv_co_block_status_from_*()
With bdrv_filter_bs(), we can easily handle this default filter behavior in bdrv_co_block_status(). blkdebug wants to have an additional assertion, so it keeps its own implementation, except bdrv_co_block_status_from_file() needs to be inlined there. Suggested-by: Eric Blake <eblake@redhat.com> Signed-off-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/io.c')
-rw-r--r--block/io.c51
1 files changed, 17 insertions, 34 deletions
diff --git a/block/io.c b/block/io.c
index 916464f089..a2389bb38c 100644
--- a/block/io.c
+++ b/block/io.c
@@ -2255,36 +2255,6 @@ typedef struct BdrvCoBlockStatusData {
BlockDriverState **file;
} BdrvCoBlockStatusData;
-int coroutine_fn bdrv_co_block_status_from_file(BlockDriverState *bs,
- bool want_zero,
- int64_t offset,
- int64_t bytes,
- int64_t *pnum,
- int64_t *map,
- BlockDriverState **file)
-{
- assert(bs->file && bs->file->bs);
- *pnum = bytes;
- *map = offset;
- *file = bs->file->bs;
- return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID;
-}
-
-int coroutine_fn bdrv_co_block_status_from_backing(BlockDriverState *bs,
- bool want_zero,
- int64_t offset,
- int64_t bytes,
- int64_t *pnum,
- int64_t *map,
- BlockDriverState **file)
-{
- assert(bs->backing && bs->backing->bs);
- *pnum = bytes;
- *map = offset;
- *file = bs->backing->bs;
- return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID;
-}
-
/*
* Returns the allocation status of the specified sectors.
* Drivers not implementing the functionality are assumed to not support
@@ -2325,6 +2295,7 @@ static int coroutine_fn bdrv_co_block_status(BlockDriverState *bs,
BlockDriverState *local_file = NULL;
int64_t aligned_offset, aligned_bytes;
uint32_t align;
+ bool has_filtered_child;
assert(pnum);
*pnum = 0;
@@ -2350,7 +2321,8 @@ static int coroutine_fn bdrv_co_block_status(BlockDriverState *bs,
/* Must be non-NULL or bdrv_getlength() would have failed */
assert(bs->drv);
- if (!bs->drv->bdrv_co_block_status) {
+ has_filtered_child = bdrv_filter_child(bs);
+ if (!bs->drv->bdrv_co_block_status && !has_filtered_child) {
*pnum = bytes;
ret = BDRV_BLOCK_DATA | BDRV_BLOCK_ALLOCATED;
if (offset + bytes == total_size) {
@@ -2371,9 +2343,20 @@ static int coroutine_fn bdrv_co_block_status(BlockDriverState *bs,
aligned_offset = QEMU_ALIGN_DOWN(offset, align);
aligned_bytes = ROUND_UP(offset + bytes, align) - aligned_offset;
- ret = bs->drv->bdrv_co_block_status(bs, want_zero, aligned_offset,
- aligned_bytes, pnum, &local_map,
- &local_file);
+ if (bs->drv->bdrv_co_block_status) {
+ ret = bs->drv->bdrv_co_block_status(bs, want_zero, aligned_offset,
+ aligned_bytes, pnum, &local_map,
+ &local_file);
+ } else {
+ /* Default code for filters */
+
+ local_file = bdrv_filter_bs(bs);
+ assert(local_file);
+
+ *pnum = aligned_bytes;
+ local_map = aligned_offset;
+ ret = BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID;
+ }
if (ret < 0) {
*pnum = 0;
goto out;