From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MSuBk-0003QW-UZ for qemu-devel@nongnu.org; Mon, 20 Jul 2009 10:50:00 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MSuBg-0003LL-IW for qemu-devel@nongnu.org; Mon, 20 Jul 2009 10:50:00 -0400 Received: from [199.232.76.173] (port=47440 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MSuBg-0003Kr-Ct for qemu-devel@nongnu.org; Mon, 20 Jul 2009 10:49:56 -0400 Received: from mx2.redhat.com ([66.187.237.31]:59236) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MSuBf-00049H-UJ for qemu-devel@nongnu.org; Mon, 20 Jul 2009 10:49:56 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n6KEntJb028302 for ; Mon, 20 Jul 2009 10:49:55 -0400 From: Kevin Wolf Date: Mon, 20 Jul 2009 16:48:43 +0200 Message-Id: <1248101323-10261-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH] qemu-io: Rework alloc command List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf The alloc command in qemu-io is mostly useless currently. Instead of doing a single call to bdrv_is_allocated, we must call bdrv_is_allocated in a loop until we have found out for each requested sector if it is allocated or not (bdrv_is_allocated returns a number of sectors that are known to be in the same state as the first one, but it is not required to include all of them) This changes the output format of the alloc command so that a change to the expected output of qemu-iotests 019 is necessary once this is included. Signed-off-by: Kevin Wolf --- qemu-io.c | 22 ++++++++++++++-------- 1 files changed, 14 insertions(+), 8 deletions(-) diff --git a/qemu-io.c b/qemu-io.c index 6c35a07..f938575 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -1170,11 +1170,10 @@ static int alloc_f(int argc, char **argv) { int64_t offset; - int nb_sectors; + int nb_sectors, remaining; char s1[64]; - int num; + int num, sum_alloc; int ret; - const char *retstr; offset = cvtnum(argv[1]); if (offset & 0x1ff) { @@ -1188,16 +1187,23 @@ alloc_f(int argc, char **argv) else nb_sectors = 1; - ret = bdrv_is_allocated(bs, offset >> 9, nb_sectors, &num); + remaining = nb_sectors; + sum_alloc = 0; + while (remaining) { + ret = bdrv_is_allocated(bs, offset >> 9, nb_sectors, &num); + remaining -= num; + if (ret) { + sum_alloc += num; + } + } cvtstr(offset, s1, sizeof(s1)); - retstr = ret ? "allocated" : "not allocated"; if (nb_sectors == 1) - printf("sector %s at offset %s\n", retstr, s1); + printf("sector allocated at offset %s\n", s1); else - printf("%d/%d sectors %s at offset %s\n", - num, nb_sectors, retstr, s1); + printf("%d/%d sectors allocated at offset %s\n", + sum_alloc, nb_sectors, s1); return 0; } -- 1.6.0.6