@@ -2223,6 +2223,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;
@@ -2445,6 +2446,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,
@@ -2456,8 +2458,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) {
@@ -2495,6 +2497,11 @@ static int coroutine_fn bdrv_co_block_status_above(BlockDriverState *bs,
/* [offset, pnum] unallocated on this layer, which could be only
* the first part of [offset, bytes]. */
+
+ if (p == base) {
+ break;
+ }
+
assert(*pnum <= bytes);
bytes = *pnum;
first = false;
@@ -2509,7 +2516,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;
@@ -2523,6 +2530,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,
@@ -2532,6 +2540,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,
@@ -2556,7 +2565,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);
}
@@ -2573,7 +2582,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) {