From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:59968) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSRsq-000271-JM for qemu-devel@nongnu.org; Thu, 10 May 2012 07:50:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SSRsk-0006Tn-AO for qemu-devel@nongnu.org; Thu, 10 May 2012 07:50:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53255) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSRsk-0006Rl-2f for qemu-devel@nongnu.org; Thu, 10 May 2012 07:50:06 -0400 From: Kevin Wolf Date: Thu, 10 May 2012 13:49:26 +0200 Message-Id: <1336650574-12835-23-git-send-email-kwolf@redhat.com> In-Reply-To: <1336650574-12835-1-git-send-email-kwolf@redhat.com> References: <1336650574-12835-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 22/30] qemu-io: fix the alloc command List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Paolo Bonzini Because sector_num is not updated, the loop would either go on forever or return garbage. Signed-off-by: Paolo Bonzini Signed-off-by: Kevin Wolf --- qemu-io.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-) diff --git a/qemu-io.c b/qemu-io.c index b48364f..5882067 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -1560,7 +1560,7 @@ out: static int alloc_f(int argc, char **argv) { - int64_t offset; + int64_t offset, sector_num; int nb_sectors, remaining; char s1[64]; int num, sum_alloc; @@ -1581,12 +1581,18 @@ static int alloc_f(int argc, char **argv) remaining = nb_sectors; sum_alloc = 0; + sector_num = offset >> 9; while (remaining) { - ret = bdrv_is_allocated(bs, offset >> 9, nb_sectors, &num); + ret = bdrv_is_allocated(bs, sector_num, remaining, &num); + sector_num += num; remaining -= num; if (ret) { sum_alloc += num; } + if (num == 0) { + nb_sectors -= remaining; + remaining = 0; + } } cvtstr(offset, s1, sizeof(s1)); -- 1.7.6.5