diff mbox series

[v6,3/5] block/io: bdrv_common_block_status_above: support bs == base

Message ID 20200916122008.20303-4-vsementsov@virtuozzo.com
State New
Headers show
Series fix & merge block_status_above and is_allocated_above | expand

Commit Message

Vladimir Sementsov-Ogievskiy Sept. 16, 2020, 12:20 p.m. UTC
We are going to reuse bdrv_common_block_status_above in
bdrv_is_allocated_above. bdrv_is_allocated_above may be called with
include_base == false and still bs == base (for ex. from img_rebase()).

So, support this corner case.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 block/io.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Alberto Garcia Sept. 23, 2020, 4:22 p.m. UTC | #1
On Wed 16 Sep 2020 02:20:06 PM CEST, Vladimir Sementsov-Ogievskiy wrote:
> We are going to reuse bdrv_common_block_status_above in

> bdrv_is_allocated_above. bdrv_is_allocated_above may be called with

> include_base == false and still bs == base (for ex. from img_rebase()).

>

> So, support this corner case.

>

> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>

> Reviewed-by: Kevin Wolf <kwolf@redhat.com>

> Reviewed-by: Eric Blake <eblake@redhat.com>


Reviewed-by: Alberto Garcia <berto@igalia.com>


(my question about include_base remains, but otherwise this patch is
correct)

Berto
diff mbox series

Patch

diff --git a/block/io.c b/block/io.c
index 0cc2dd7a3e..d864d035ac 100644
--- a/block/io.c
+++ b/block/io.c
@@ -2371,9 +2371,13 @@  bdrv_co_common_block_status_above(BlockDriverState *bs,
     BlockDriverState *p;
     int64_t eof = 0;
 
-    assert(include_base || bs != base);
     assert(!include_base || base); /* Can't include NULL base */
 
+    if (!include_base && bs == base) {
+        *pnum = bytes;
+        return 0;
+    }
+
     ret = bdrv_co_block_status(bs, want_zero, offset, bytes, pnum, map, file);
     if (ret < 0 || *pnum == 0 || ret & BDRV_BLOCK_ALLOCATED || bs == base) {
         return ret;