In order to reuse bdrv_common_block_status_above in bdrv_is_allocated_above, let's support include_base parameter.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsement...@virtuozzo.com> --- block/io.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/block/io.c b/block/io.c index 4d7fa99bd2..df3ecf2430 100644 --- a/block/io.c +++ b/block/io.c @@ -2196,6 +2196,7 @@ int bdrv_flush_all(void) typedef struct BdrvCoBlockStatusData { BlockDriverState *bs; BlockDriverState *base; + bool include_base; bool want_zero; int64_t offset; int64_t bytes; @@ -2418,6 +2419,7 @@ early_out: static int coroutine_fn bdrv_co_block_status_above(BlockDriverState *bs, BlockDriverState *base, + bool include_base, bool want_zero, int64_t offset, int64_t bytes, @@ -2429,8 +2431,8 @@ static int coroutine_fn bdrv_co_block_status_above(BlockDriverState *bs, int ret = 0; bool first = true; - assert(bs != base); - for (p = bs; p != base; p = backing_bs(p)) { + assert(include_base || bs != base); + for (p = bs; include_base || p != base; p = backing_bs(p)) { ret = bdrv_co_block_status(p, want_zero, offset, bytes, pnum, map, file); if (ret < 0) { @@ -2466,6 +2468,10 @@ static int coroutine_fn bdrv_co_block_status_above(BlockDriverState *bs, return ret; } + if (p == base) { + break; + } + /* Proceed to backing */ assert(*pnum <= bytes); bytes = *pnum; @@ -2481,7 +2487,7 @@ static void coroutine_fn bdrv_block_status_above_co_entry(void *opaque) BdrvCoBlockStatusData *data = opaque; data->ret = bdrv_co_block_status_above(data->bs, data->base, - data->want_zero, + data->include_base, data->want_zero, data->offset, data->bytes, data->pnum, data->map, data->file); data->done = true; @@ -2495,6 +2501,7 @@ static void coroutine_fn bdrv_block_status_above_co_entry(void *opaque) */ static int bdrv_common_block_status_above(BlockDriverState *bs, BlockDriverState *base, + bool include_base, bool want_zero, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, @@ -2504,6 +2511,7 @@ static int bdrv_common_block_status_above(BlockDriverState *bs, BdrvCoBlockStatusData data = { .bs = bs, .base = base, + .include_base = include_base, .want_zero = want_zero, .offset = offset, .bytes = bytes, @@ -2528,7 +2536,7 @@ int bdrv_block_status_above(BlockDriverState *bs, BlockDriverState *base, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, BlockDriverState **file) { - return bdrv_common_block_status_above(bs, base, true, offset, bytes, + return bdrv_common_block_status_above(bs, base, false, true, offset, bytes, pnum, map, file); } @@ -2545,7 +2553,7 @@ int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t offset, int ret; int64_t dummy; - ret = bdrv_common_block_status_above(bs, backing_bs(bs), false, offset, + ret = bdrv_common_block_status_above(bs, bs, true, false, offset, bytes, pnum ? pnum : &dummy, NULL, NULL); if (ret < 0) { -- 2.21.0