Commit 4b25bbc4 authored by Max Reitz's avatar Max Reitz Committed by Kevin Wolf

qemu-io: Respect early image end for map

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: default avatarMax Reitz <mreitz@redhat.com>
Reviewed-by: default avatarEric Blake <eblake@redhat.com>
Reviewed-by: default avatarBenoît Canet <benoit.canet@nodalink.com>
Reviewed-by: default avatarKevin Wolf <kwolf@redhat.com>
Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
parent 59c9a95f
...@@ -1900,7 +1900,7 @@ static int map_is_allocated(BlockDriverState *bs, int64_t sector_num, ...@@ -1900,7 +1900,7 @@ static int map_is_allocated(BlockDriverState *bs, int64_t sector_num,
num_checked = MIN(nb_sectors, INT_MAX); num_checked = MIN(nb_sectors, INT_MAX);
ret = bdrv_is_allocated(bs, sector_num, num_checked, &num); ret = bdrv_is_allocated(bs, sector_num, num_checked, &num);
if (ret == firstret) { if (ret == firstret && num) {
*pnum += num; *pnum += num;
} else { } else {
break; break;
...@@ -1927,6 +1927,9 @@ static int map_f(BlockDriverState *bs, int argc, char **argv) ...@@ -1927,6 +1927,9 @@ static int map_f(BlockDriverState *bs, int argc, char **argv)
if (ret < 0) { if (ret < 0) {
error_report("Failed to get allocation status: %s", strerror(-ret)); error_report("Failed to get allocation status: %s", strerror(-ret));
return 0; return 0;
} else if (!num) {
error_report("Unexpected end of image");
return 0;
} }
retstr = ret ? " allocated" : "not allocated"; retstr = ret ? " allocated" : "not allocated";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment