[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 2/9] block: User BdrvChild callback for device na
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH v2 2/9] block: User BdrvChild callback for device name |
Date: |
Wed, 27 Apr 2016 15:20:24 +0200 |
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 <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
---
block.c | 22 ++++++++++++++++++++--
block/block-backend.c | 6 ++++++
include/block/block_int.h | 5 +++++
3 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/block.c b/block.c
index 69ee791..a8df72f 100644
--- a/block.c
+++ b/block.c
@@ -2896,10 +2896,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
@@ -2908,7 +2926,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 7f507ba..34f747e 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -97,11 +97,17 @@ static void blk_root_drained_end(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,
.drained_begin = blk_root_drained_begin,
.drained_end = blk_root_drained_end,
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 9938a3d..f4a0941 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -365,6 +365,11 @@ struct BdrvChildRole {
void (*change_media)(BdrvChild *child, bool load);
void (*resize)(BdrvChild *child);
+ /* Returns a name that is supposedly more useful for human users than the
+ * node name for identifying the node in question (in particular, a BB
+ * name), or NULL if the parent can't provide a better name. */
+ const char* (*get_name)(BdrvChild *child);
+
void (*drained_begin)(BdrvChild *child);
void (*drained_end)(BdrvChild *child);
};
--
1.8.3.1
- [Qemu-devel] [PATCH v2 0/9] block: Remove BlockDriverState.blk, Kevin Wolf, 2016/04/27
- [Qemu-devel] [PATCH v2 3/9] blockjob: Don't set iostatus of target, Kevin Wolf, 2016/04/27
- [Qemu-devel] [PATCH v2 6/9] block: Add bdrv_has_blk(), Kevin Wolf, 2016/04/27
- [Qemu-devel] [PATCH v2 1/9] block: Use BdrvChild callbacks for change_media/resize, Kevin Wolf, 2016/04/27
- [Qemu-devel] [PATCH v2 7/9] block: Avoid bs->blk in bdrv_next(), Kevin Wolf, 2016/04/27
- [Qemu-devel] [PATCH v2 8/9] block: Don't return throttling info in query-named-block-nodes, Kevin Wolf, 2016/04/27
- [Qemu-devel] [PATCH v2 2/9] block: User BdrvChild callback for device name,
Kevin Wolf <=
- [Qemu-devel] [PATCH v2 9/9] block: Remove BlockDriverState.blk, Kevin Wolf, 2016/04/27
- [Qemu-devel] [PATCH v2 5/9] block: Remove bdrv_aio_multiwrite(), Kevin Wolf, 2016/04/27
- [Qemu-devel] [PATCH v2 4/9] blockjob: Don't touch BDS iostatus, Kevin Wolf, 2016/04/27