Patchwork block: Fix is_allocated_above with resized files

login
register
mail settings
Submitter Vishvananda Ishaya
Date Jan. 24, 2013, 6:02 p.m.
Message ID <1359050528-52668-1-git-send-email-vishvananda@gmail.com>
Download mbox | patch
Permalink /patch/215462/
State New
Headers show

Comments

Vishvananda Ishaya - Jan. 24, 2013, 6:02 p.m.
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>
---
Fixes https://bugs.launchpad.net/qemu/+bug/1103868

 block.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Stefan Hajnoczi - Jan. 29, 2013, 2:51 p.m.
On Thu, Jan 24, 2013 at 10:02:08AM -0800, Vishvananda Ishaya wrote:
> 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>
> ---
> Fixes https://bugs.launchpad.net/qemu/+bug/1103868
> 
>  block.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan

Patch

diff --git a/block.c b/block.c
index 6fa7c90..6474d9e 100644
--- a/block.c
+++ b/block.c
@@ -2831,7 +2831,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;
         }