From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59895) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIj7a-0003Yx-Uz for qemu-devel@nongnu.org; Sat, 16 Aug 2014 14:54:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XIj7T-0001wV-Pl for qemu-devel@nongnu.org; Sat, 16 Aug 2014 14:54:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:19131) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIj7T-0001wR-HD for qemu-devel@nongnu.org; Sat, 16 Aug 2014 14:54:27 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s7GIsQYD014330 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Sat, 16 Aug 2014 14:54:26 -0400 From: Max Reitz Date: Sat, 16 Aug 2014 20:54:17 +0200 Message-Id: <1408215258-12545-3-git-send-email-mreitz@redhat.com> In-Reply-To: <1408215258-12545-1-git-send-email-mreitz@redhat.com> References: <1408215258-12545-1-git-send-email-mreitz@redhat.com> Subject: [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: qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi , Max Reitz 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 --- 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