]> git.proxmox.com Git - qemu.git/commitdiff
qemu-io: Rework alloc command
authorKevin Wolf <kwolf@redhat.com>
Mon, 20 Jul 2009 14:48:43 +0000 (16:48 +0200)
committerAnthony Liguori <aliguori@us.ibm.com>
Wed, 22 Jul 2009 15:58:47 +0000 (10:58 -0500)
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 <kwolf@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
qemu-io.c

index 6c35a071c4d09536926572a2aa66c0be5001c8b7..f9385751d2cf2a75d5f2c328db60552e8f479b96 100644 (file)
--- 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;
 }