All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com
Subject: [Qemu-devel] [PATCH 2/9] block: User BdrvChild callback for device name
Date: Tue, 22 Mar 2016 20:36:30 +0100	[thread overview]
Message-ID: <1458675397-24956-3-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1458675397-24956-1-git-send-email-kwolf@redhat.com>

In order to get rid of bs->blk for bdrv_get_device_name() and
bdrv_get_device_or_node_name(), ask all parents for their name and
simply pick the first one.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block.c                   | 22 ++++++++++++++++++++--
 block/block-backend.c     |  6 ++++++
 include/block/block_int.h |  1 +
 3 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/block.c b/block.c
index 1fb5dac..4cc117d 100644
--- a/block.c
+++ b/block.c
@@ -2924,10 +2924,28 @@ const char *bdrv_get_node_name(const BlockDriverState *bs)
     return bs->node_name;
 }
 
+static const char *bdrv_get_parent_name(const BlockDriverState *bs)
+{
+    BdrvChild *c;
+    const char *name;
+
+    /* If multiple parents have a name, just pick the first one. */
+    QLIST_FOREACH(c, &bs->parents, next_parent) {
+        if (c->role->get_name) {
+            name = c->role->get_name(c);
+            if (name && *name) {
+                return name;
+            }
+        }
+    }
+
+    return NULL;
+}
+
 /* TODO check what callers really want: bs->node_name or blk_name() */
 const char *bdrv_get_device_name(const BlockDriverState *bs)
 {
-    return bs->blk ? blk_name(bs->blk) : "";
+    return bdrv_get_parent_name(bs) ?: "";
 }
 
 /* This can be used to identify nodes that might not have a device
@@ -2936,7 +2954,7 @@ const char *bdrv_get_device_name(const BlockDriverState *bs)
  * absent, then this returns an empty (non-null) string. */
 const char *bdrv_get_device_or_node_name(const BlockDriverState *bs)
 {
-    return bs->blk ? blk_name(bs->blk) : bs->node_name;
+    return bdrv_get_parent_name(bs) ?: bs->node_name;
 }
 
 int bdrv_get_flags(BlockDriverState *bs)
diff --git a/block/block-backend.c b/block/block-backend.c
index 9d973ba..c4c0dc0 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -95,11 +95,17 @@ static bool blk_drain_throttling_queue(BdrvChild *child);
 static void blk_root_change_media(BdrvChild *child, bool load);
 static void blk_root_resize(BdrvChild *child);
 
+static const char *blk_root_get_name(BdrvChild *child)
+{
+    return blk_name(child->opaque);
+}
+
 static const BdrvChildRole child_root = {
     .inherit_options    = blk_root_inherit_options,
 
     .change_media       = blk_root_change_media,
     .resize             = blk_root_resize,
+    .get_name           = blk_root_get_name,
 
     .drain_queue        = blk_drain_throttling_queue,
 };
diff --git a/include/block/block_int.h b/include/block/block_int.h
index f60cb7c..195abe8 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -358,6 +358,7 @@ struct BdrvChildRole {
 
     void (*change_media)(BdrvChild *child, bool load);
     void (*resize)(BdrvChild *child);
+    const char* (*get_name)(BdrvChild *child);
 
     bool (*drain_queue)(BdrvChild *child);
 };
-- 
1.8.3.1

  parent reply	other threads:[~2016-03-22 19:36 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-22 19:36 [Qemu-devel] [PATCH 0/9] block: Remove BlockDriverState.blk Kevin Wolf
2016-03-22 19:36 ` [Qemu-devel] [PATCH 1/9] block: Use BdrvChild callbacks for change_media/resize Kevin Wolf
2016-03-29 17:36   ` Max Reitz
2016-03-22 19:36 ` Kevin Wolf [this message]
2016-03-29 17:43   ` [Qemu-devel] [PATCH 2/9] block: User BdrvChild callback for device name Max Reitz
2016-03-22 19:36 ` [Qemu-devel] [PATCH 3/9] block jobs: Use BdrvChild callbacks for iostatus operations Kevin Wolf
2016-03-29 18:15   ` Max Reitz
2016-03-22 19:36 ` [Qemu-devel] [PATCH 4/9] block: Remove bdrv_aio_multiwrite() Kevin Wolf
2016-03-29 18:22   ` Max Reitz
2016-03-22 19:36 ` [Qemu-devel] [PATCH 5/9] block: Avoid BDS.blk in bdrv_next() Kevin Wolf
2016-03-29 18:26   ` Max Reitz
2016-03-22 19:36 ` [Qemu-devel] [PATCH 6/9] block: Remove bdrv_move_feature_fields() Kevin Wolf
2016-03-29 18:28   ` Max Reitz
2016-03-22 19:36 ` [Qemu-devel] [PATCH 7/9] block: Avoid bs->blk in bdrv_next() Kevin Wolf
2016-03-29 18:50   ` Max Reitz
2016-03-22 19:36 ` [Qemu-devel] [PATCH 8/9] block: Don't return throttling info in query-named-block-nodes Kevin Wolf
2016-03-29 18:53   ` Max Reitz
2016-03-22 19:36 ` [Qemu-devel] [PATCH 9/9] block: Remove BlockDriverState.blk Kevin Wolf
2016-03-29 18:59   ` Max Reitz
2016-03-22 21:34 ` [Qemu-devel] [PATCH 0/9] " Paolo Bonzini

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=1458675397-24956-3-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=mreitz@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.