Received: from eggs.gnu.org ([2001:4830:134:3::10]:41089) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xd1k6-0007BG-SE for qemu-devel@nongnu.org; Sat, 11 Oct 2014 14:50:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xd1k1-0008GO-Pw for qemu-devel@nongnu.org; Sat, 11 Oct 2014 14:50:14 -0400 Received: from lputeaux-656-01-25-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:47596 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xd1k1-0008GJ-KF for qemu-devel@nongnu.org; Sat, 11 Oct 2014 14:50:09 -0400 Date: Sat, 11 Oct 2014 20:47:38 +0200 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20141011184737.GB7688@irqsave.net> References: <1408215258-12545-1-git-send-email-mreitz@redhat.com> <1408215258-12545-3-git-send-email-mreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1408215258-12545-3-git-send-email-mreitz@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 2/3] qemu-io: Respect early image end for map List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi The Saturday 16 Aug 2014 =E0 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 t= o > avoid an infinite loop. >=20 > Signed-off-by: Max Reitz > --- > qemu-io-cmds.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) >=20 > 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, > =20 > num_checked =3D MIN(nb_sectors, INT_MAX); > ret =3D bdrv_is_allocated(bs, sector_num, num_checked, &num); > - if (ret =3D=3D firstret) { > + if (ret =3D=3D firstret && num) { > *pnum +=3D 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", strerr= or(-ret)); > return 0; > + } else if (!num) { > + error_report("Unexpected end of image"); > + return 0; > } > =20 > retstr =3D ret ? " allocated" : "not allocated"; > --=20 > 2.0.4 >=20 >=20 Reviewed-by: Beno=EEt Canet