[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 2/3] qemu-io: Respect early image end for map
From: |
Benoît Canet |
Subject: |
Re: [Qemu-devel] [PATCH 2/3] qemu-io: Respect early image end for map |
Date: |
Sat, 11 Oct 2014 20:47:38 +0200 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
The Saturday 16 Aug 2014 à 20:54:17 (+0200), Max Reitz wrote :
> 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 <address@hidden>
> ---
> qemu-io-cmds.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
> index c503fc6..860b834 100644
> --- a/qemu-io-cmds.c
> +++ b/qemu-io-cmds.c
> @@ -1909,7 +1909,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;
> @@ -1936,6 +1936,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";
> --
> 2.0.4
>
>
Reviewed-by: Benoît Canet <address@hidden>