]> xenbits.xensource.com Git - people/sstabellini/qemu-dm.git/.git/commitdiff
qemu-io: Respect early image end for map
authorMax Reitz <mreitz@redhat.com>
Wed, 22 Oct 2014 15:00:16 +0000 (17:00 +0200)
committerKevin Wolf <kwolf@redhat.com>
Thu, 23 Oct 2014 13:34:02 +0000 (15:34 +0200)
bdrv_is_allocated() may report zero clusters which most probably means
the image (file) is shorter than expected. Respect this case in order to
avoid an infinite loop.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: BenoƮt Canet <benoit.canet@nodalink.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
qemu-io-cmds.c

index b224ede5fa0ef309005042b8e5459a59cb74a6ea..d94fb1e2ea1c88d6a3ff74313a9d5df8726ae32c 100644 (file)
@@ -1900,7 +1900,7 @@ static int map_is_allocated(BlockDriverState *bs, int64_t sector_num,
 
         num_checked = MIN(nb_sectors, INT_MAX);
         ret = bdrv_is_allocated(bs, sector_num, num_checked, &num);
-        if (ret == firstret) {
+        if (ret == firstret && num) {
             *pnum += num;
         } else {
             break;
@@ -1927,6 +1927,9 @@ static int map_f(BlockDriverState *bs, int argc, char **argv)
         if (ret < 0) {
             error_report("Failed to get allocation status: %s", strerror(-ret));
             return 0;
+        } else if (!num) {
+            error_report("Unexpected end of image");
+            return 0;
         }
 
         retstr = ret ? "    allocated" : "not allocated";