qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>
Subject: [Qemu-devel] [PATCH v4 4/6] qemu-img: Use bdrv_filename_alloc() for map
Date: Tue, 18 Aug 2015 16:10:13 -0700	[thread overview]
Message-ID: <1439939415-18180-5-git-send-email-mreitz@redhat.com> (raw)
In-Reply-To: <1439939415-18180-1-git-send-email-mreitz@redhat.com>

Replaces bs->filename by the result of bdrv_filename_alloc() 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(-)

diff --git a/qemu-img.c b/qemu-img.c
index 75f4ee4..b2ea059 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -2141,6 +2141,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,
@@ -2155,7 +2156,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.
@@ -2305,6 +2306,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_alloc(next.bs);
+        }
+
         if (curr.length != 0 && curr.flags == next.flags &&
             curr.depth == next.depth &&
             ((curr.flags & BDRV_BLOCK_OFFSET_VALID) == 0 ||
@@ -2316,10 +2323,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);
-- 
2.4.3

  parent reply	other threads:[~2015-08-18 23:10 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-18 23:10 [Qemu-devel] [PATCH v4 0/6] block: Drop BDS.filename Max Reitz
2015-08-18 23:10 ` [Qemu-devel] [PATCH v4 1/6] block: Change bdrv_get_encrypted_filename() Max Reitz
2015-08-31 20:50   ` Eric Blake
2015-09-02 14:53     ` Max Reitz
2015-08-18 23:10 ` [Qemu-devel] [PATCH v4 2/6] block: Avoid BlockDriverState.filename Max Reitz
2015-08-31 20:53   ` Eric Blake
2015-08-18 23:10 ` [Qemu-devel] [PATCH v4 3/6] block: Add bdrv_filename() Max Reitz
2015-08-31 21:00   ` Eric Blake
2015-09-02 14:59     ` Max Reitz
2015-08-18 23:10 ` Max Reitz [this message]
2015-08-31 21:23   ` [Qemu-devel] [PATCH v4 4/6] qemu-img: Use bdrv_filename_alloc() for map Eric Blake
2015-08-18 23:10 ` [Qemu-devel] [PATCH v4 5/6] block: Drop BlockDriverState.filename Max Reitz
2015-08-31 21:50   ` Eric Blake
2015-08-18 23:10 ` [Qemu-devel] [PATCH v4 6/6] iotests: Test changed Quorum filename Max Reitz
2015-08-31 21:54   ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1439939415-18180-5-git-send-email-mreitz@redhat.com \
    --to=mreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).