diff mbox

[v5,4/6] qemu-img: Use bdrv_filename() for map

Message ID 1445280546-26226-5-git-send-email-mreitz@redhat.com
State New
Headers show

Commit Message

Max Reitz Oct. 19, 2015, 6:49 p.m. UTC
Replaces bs->filename by the result of bdrv_filename() in the
qemu-img map subcommand. Since that value is queried relatively often,
however, it should be cached.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 qemu-img.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

Comments

Eric Blake Oct. 19, 2015, 9:02 p.m. UTC | #1
On 10/19/2015 12:49 PM, Max Reitz wrote:
> Replaces bs->filename by the result of bdrv_filename() in the
> qemu-img map subcommand. Since that value is queried relatively often,
> however, it should be cached.
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  qemu-img.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>
Kevin Wolf Oct. 26, 2015, 6:21 p.m. UTC | #2
Am 19.10.2015 um 20:49 hat Max Reitz geschrieben:
> Replaces bs->filename by the result of bdrv_filename() in the
> qemu-img map subcommand. Since that value is queried relatively often,
> however, it should be cached.
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>

Reviewed-by: Kevin Wolf <kwolf@redhat.com>
diff mbox

Patch

diff --git a/qemu-img.c b/qemu-img.c
index 3025776..a44c77a 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -2142,6 +2142,7 @@  typedef struct MapEntry {
     int64_t length;
     int64_t offset;
     BlockDriverState *bs;
+    char *bs_filename;
 } MapEntry;
 
 static void dump_map_entry(OutputFormat output_format, MapEntry *e,
@@ -2156,7 +2157,7 @@  static void dump_map_entry(OutputFormat output_format, MapEntry *e,
         }
         if ((e->flags & (BDRV_BLOCK_DATA|BDRV_BLOCK_ZERO)) == BDRV_BLOCK_DATA) {
             printf("%#-16"PRIx64"%#-16"PRIx64"%#-16"PRIx64"%s\n",
-                   e->start, e->length, e->offset, e->bs->filename);
+                   e->start, e->length, e->offset, e->bs_filename);
         }
         /* This format ignores the distinction between 0, ZERO and ZERO|DATA.
          * Modify the flags here to allow more coalescing.
@@ -2306,6 +2307,12 @@  static int img_map(int argc, char **argv)
             goto out;
         }
 
+        if (next.bs == curr.bs) {
+            next.bs_filename = curr.bs_filename;
+        } else {
+            next.bs_filename = bdrv_filename(next.bs, NULL, 0);
+        }
+
         if (curr.length != 0 && curr.flags == next.flags &&
             curr.depth == next.depth &&
             ((curr.flags & BDRV_BLOCK_OFFSET_VALID) == 0 ||
@@ -2317,10 +2324,15 @@  static int img_map(int argc, char **argv)
         if (curr.length > 0) {
             dump_map_entry(output_format, &curr, &next);
         }
+
+        if (curr.bs != next.bs) {
+            g_free(curr.bs_filename);
+        }
         curr = next;
     }
 
     dump_map_entry(output_format, &curr, NULL);
+    g_free(curr.bs_filename);
 
 out:
     blk_unref(blk);