Skip to content

Commit

Permalink
qemu-io: Respect early image end for map
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
XanClic authored and kevmw committed Oct 23, 2014
1 parent 59c9a95 commit 4b25bbc
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion qemu-io-cmds.c
Expand Up @@ -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;
Expand All @@ -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";
Expand Down

0 comments on commit 4b25bbc

Please sign in to comment.