Patchwork [RFC,22/24] qemu-io: make map command use new block mapping function

login
register
mail settings
Submitter Devin Nakamura
Date July 29, 2011, 4:49 a.m.
Message ID <1311914994-20482-23-git-send-email-devin122@gmail.com>
Download mbox | patch
Permalink /patch/107347/
State New
Headers show

Comments

Devin Nakamura - July 29, 2011, 4:49 a.m.
bdrv_get_mapping will be used when it is defined,
otherwise default to old behaviour.

Signed-off-by: Devin Nakamura <devin122@gmail.com>
---
 qemu-io.c |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)
Kevin Wolf - Aug. 1, 2011, 3:38 p.m.
Am 29.07.2011 06:49, schrieb Devin Nakamura:
> bdrv_get_mapping will be used when it is defined,
> otherwise default to old behaviour.
> 
> Signed-off-by: Devin Nakamura <devin122@gmail.com>

Hm, I think I would use a new command for this, like 'get_mapping'. The
old 'map' command can still be useful even for formats supporting
bdrv_get_mapping. You would use it whenever you are only interested
which offsets are allocated, but don't care about the offsets in the
image file to which they are mapped. This makes the output much shorter.

Kevin
Devin Nakamura - Aug. 2, 2011, 4:02 a.m.
On Mon, Aug 1, 2011 at 11:38 AM, Kevin Wolf <kwolf@redhat.com> wrote:
> Am 29.07.2011 06:49, schrieb Devin Nakamura:
>> bdrv_get_mapping will be used when it is defined,
>> otherwise default to old behaviour.
>>
>> Signed-off-by: Devin Nakamura <devin122@gmail.com>
>
> Hm, I think I would use a new command for this, like 'get_mapping'. The
> old 'map' command can still be useful even for formats supporting
> bdrv_get_mapping. You would use it whenever you are only interested
> which offsets are allocated, but don't care about the offsets in the
> image file to which they are mapped. This makes the output much shorter.
>
> Kevin
>

Ok, no problem. Its on the todo list.

Patch

diff --git a/qemu-io.c b/qemu-io.c
index a553d0c..caf51fe 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -1543,7 +1543,7 @@  static const cmdinfo_t alloc_cmd = {
     .oneline    = "checks if a sector is present in the file",
 };
 
-static int map_f(int argc, char **argv)
+static int map_f_old(int argc, char **argv)
 {
     int64_t offset;
     int64_t nb_sectors;
@@ -1570,6 +1570,27 @@  static int map_f(int argc, char **argv)
     return 0;
 }
 
+static int map_f(int argc, char **argv)
+{
+    uint64_t host_offset, guest_offset, count;
+    int ret;
+
+    if (!bs->drv->bdrv_get_mapping) {
+        return map_f_old(argc, argv);
+    }
+
+    guest_offset = count = 0;
+    printf("  Guest Offset   -    Host Offset   -      Count\n");
+    do {
+        ret = bdrv_get_mapping(bs, &guest_offset, &host_offset, &count);
+        if (count) {
+            printf("%016lx - %016lx - %016lx\n", guest_offset, host_offset,
+                   count);
+        }
+    } while (!ret && count > 0);
+    return ret;
+}
+
 static const cmdinfo_t map_cmd = {
        .name           = "map",
        .argmin         = 0,