aboutsummaryrefslogtreecommitdiff
path: root/block.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2016-02-26 10:22:16 +0100
committerKevin Wolf <kwolf@redhat.com>2016-05-19 16:45:31 +0200
commit4c265bf9f434d4b47f42e3c079adc205b7625ad6 (patch)
treefd9b775bf928f0d79cdd10cc74223b7673a0fdb7 /block.c
parent5c8cab48087d3544cb788309ac729bca08244020 (diff)
downloadqemu-4c265bf9f434d4b47f42e3c079adc205b7625ad6.zip
qemu-4c265bf9f434d4b47f42e3c079adc205b7625ad6.tar.gz
qemu-4c265bf9f434d4b47f42e3c079adc205b7625ad6.tar.bz2
block: User BdrvChild callback for device name
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> Reviewed-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'block.c')
-rw-r--r--block.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/block.c b/block.c
index ab592ac..fd4cf81 100644
--- a/block.c
+++ b/block.c
@@ -2894,10 +2894,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
@@ -2906,7 +2924,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)