There currently does not seem to be a good way to obtain information about the file child of a node, so add a custom command. The query-block and query-named-block-nodes commands lack the necessary info and while x-debug-query-block-graph exists, that is explicitly only for debugging and experimental.
This is requried for e.g. blockdev-mirror in PVE to determine the node below the top throttle node. Signed-off-by: Fiona Ebner <f.eb...@proxmox.com> --- Alternatively, we could think about adding the node name of the file child to the info returned by query-named-block-nodes. I can give that a shot and also ask upstream which approach is prefered. blockdev.c | 22 ++++++++++++++++++++++ qapi/block-core.json | 13 +++++++++++++ 2 files changed, 35 insertions(+) diff --git a/blockdev.c b/blockdev.c index 17de5d2ae4..3be209767a 100644 --- a/blockdev.c +++ b/blockdev.c @@ -57,6 +57,7 @@ #include "system/system.h" #include "system/iothread.h" #include "block/block_int.h" +#include "block/qapi.h" #include "block/trace.h" #include "system/runstate.h" #include "system/replay.h" @@ -2782,6 +2783,27 @@ XDbgBlockGraph *qmp_x_debug_query_block_graph(Error **errp) return bdrv_get_xdbg_block_graph(errp); } +BlockDeviceInfo *qmp_block_node_query_file_child(const char *node_name, + Error **errp) +{ + GRAPH_RDLOCK_GUARD_MAINLOOP(); + + BlockDriverState *bs; + + bs = bdrv_find_node(node_name); + if (!bs) { + error_setg(errp, "Failed to find node with node-name='%s'", node_name); + return NULL; + } + + if (!bs->file || !bs->file->bs) { + error_setg(errp, "Node '%s' has no 'file' child", node_name); + return NULL; + } + + return bdrv_block_device_info(NULL, bs->file->bs, false, errp); +} + void qmp_blockdev_backup(BlockdevBackup *backup, Error **errp) { TransactionAction action = { diff --git a/qapi/block-core.json b/qapi/block-core.json index f8ed564cf0..6c683b00ec 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2463,6 +2463,19 @@ 'features': [ 'unstable' ], 'allow-preconfig': true } +## +# @block-node-query-file-child: +# +# Get information about a child of the specified block node. +# +# @node-name: the block node name of the node to query. +# +# Returns: the BlockDeviceInfo of the file child. +## +{ 'command': 'block-node-query-file-child', + 'data': { 'node-name': 'str' }, + 'returns': 'BlockDeviceInfo' } + ## # @drive-mirror: # -- 2.47.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel