[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 16/31] block: User BdrvChild callback for device name
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 16/31] block: User BdrvChild callback for device name |
Date: |
Thu, 19 May 2016 17:21:54 +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 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)
diff --git a/block/block-backend.c b/block/block-backend.c
index a085455..a31fc20 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 9555429..80e2da5 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -368,6 +368,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);
+
/*
* If this pair of functions is implemented, the parent doesn't issue new
* requests after returning from .drained_begin() until .drained_end() is
--
1.8.3.1
- [Qemu-devel] [PULL 00/31] Block layer patches, Kevin Wolf, 2016/05/19
- [Qemu-devel] [PULL 06/31] block: Move actual I/O throttling to BlockBackend, Kevin Wolf, 2016/05/19
- [Qemu-devel] [PULL 01/31] block: Make sure throttled BDSes always have a BB, Kevin Wolf, 2016/05/19
- [Qemu-devel] [PULL 09/31] block: Drain throttling queue with BdrvChild callback, Kevin Wolf, 2016/05/19
- [Qemu-devel] [PULL 04/31] block: Convert throttle_group_get_name() to BlockBackend, Kevin Wolf, 2016/05/19
- [Qemu-devel] [PULL 02/31] block: Introduce BlockBackendPublic, Kevin Wolf, 2016/05/19
- [Qemu-devel] [PULL 08/31] block: Introduce BdrvChild.opaque, Kevin Wolf, 2016/05/19
- [Qemu-devel] [PULL 03/31] block: throttle-groups: Use BlockBackend pointers internally, Kevin Wolf, 2016/05/19
- [Qemu-devel] [PULL 14/31] block: Don't check throttled reqs in bdrv_requests_pending(), Kevin Wolf, 2016/05/19
- [Qemu-devel] [PULL 16/31] block: User BdrvChild callback for device name,
Kevin Wolf <=
- [Qemu-devel] [PULL 07/31] block: Move I/O throttling configuration functions to BlockBackend, Kevin Wolf, 2016/05/19
- [Qemu-devel] [PULL 12/31] block: Remove bdrv_move_feature_fields(), Kevin Wolf, 2016/05/19
- [Qemu-devel] [PULL 05/31] block: Move throttling fields from BDS to BB, Kevin Wolf, 2016/05/19
- [Qemu-devel] [PULL 10/31] block/io: Quiesce parents between drained_begin/end, Kevin Wolf, 2016/05/19
- [Qemu-devel] [PULL 11/31] block: Decouple throttling from BlockDriverState, Kevin Wolf, 2016/05/19
- [Qemu-devel] [PULL 18/31] blockjob: Don't touch BDS iostatus, Kevin Wolf, 2016/05/19
- [Qemu-devel] [PULL 15/31] block: Use BdrvChild callbacks for change_media/resize, Kevin Wolf, 2016/05/19
- [Qemu-devel] [PULL 28/31] block: clarify error message for qmp-eject, Kevin Wolf, 2016/05/19
- [Qemu-devel] [PULL 25/31] qcow2: fix condition in is_zero_cluster, Kevin Wolf, 2016/05/19
- [Qemu-devel] [PULL 13/31] Revert "block: Forbid I/O throttling on nodes with multiple parents for 2.6", Kevin Wolf, 2016/05/19