[02/13] block: Fix is_allocated_above with resized files

Submitted by Stefan Hajnoczi on Feb. 1, 2013, 2:27 p.m.

Details

Message ID 1359728884-19422-3-git-send-email-stefanha@redhat.com
State New
Headers show

Commit Message

Stefan Hajnoczi Feb. 1, 2013, 2:27 p.m.
From: Vishvananda Ishaya <vishvananda@gmail.com>

In an image chain, if the base image is smaller than the current
image, we need to make sure to use the current images count of
unallocated blocks once we get to the end of the base image. Without
this change the code will return 0 blocks when it gets to the end
of the base image and mirror_run will fail its assertion.

Signed-off-by: Vishvananda Ishaya <vishvananda@gmail.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 block.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/block.c b/block.c
index ba67c0d..50dab8e 100644
--- a/block.c
+++ b/block.c
@@ -2800,7 +2800,9 @@  int coroutine_fn bdrv_co_is_allocated_above(BlockDriverState *top,
          *
          * [sector_num+x, nr_sectors] allocated.
          */
-        if (n > pnum_inter) {
+        if (n > pnum_inter &&
+            (intermediate == top ||
+             sector_num + pnum_inter < intermediate->total_sectors)) {
             n = pnum_inter;
         }