[pve-devel] [PATCH qemu v2 04/49] block: include child references in block device info
Fiona Ebner
f.ebner at proxmox.com
Tue Jul 1 17:40:24 CEST 2025
In combination with using a throttle filter to enforce IO limits for
a guest device, knowing the 'file' child of a block device can be
useful. If the throttle filter is only intended for guest IO, block
jobs should not also be limited by the throttle filter, so the
block operations need to be done with the 'file' child of the top
throttle node as the target. In combination with mirroring, the name
of that child is not fixed.
Another scenario is when unplugging a guest device after mirroring
below a top throttle node, where the mirror target is added explicitly
via blockdev-add. After mirroring, the target becomes the new 'file'
child of the throttle node. For unplugging, both the top throttle node
and the mirror target need to be deleted, because only implicitly
added child nodes are deleted automatically, and the current 'file'
child of the throttle node was explicitly added (as the mirror
target).
In other scenarios, it could be useful to follow the backing chain.
Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---
New approach in v2 based on latest upstream feedback:
[0]: https://lore.kernel.org/qemu-devel/74a66925-12a5-42af-8f93-4031d663a90d@proxmox.com/T/
block/qapi.c | 12 ++++++++++++
qapi/block-core.json | 16 ++++++++++++++++
tests/qemu-iotests/184.out | 1 +
tests/qemu-iotests/191.out | 8 ++++++++
tests/qemu-iotests/273.out | 2 ++
5 files changed, 39 insertions(+)
diff --git a/block/qapi.c b/block/qapi.c
index 2c50a6bf3b..372e0f3419 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -51,6 +51,8 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk,
ImageInfo *backing_info;
BlockDriverState *backing;
BlockDeviceInfo *info;
+ BlockdevChildRefList **children_list_tail;
+ BdrvChild *child;
if (!bs->drv) {
error_setg(errp, "Block device %s is ejected", bs->node_name);
@@ -77,6 +79,16 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk,
info->node_name = g_strdup(bs->node_name);
}
+ children_list_tail = &info->children;
+ QLIST_FOREACH(child, &bs->children, next) {
+ BlockdevChildRef *child_ref = g_new0(BlockdevChildRef, 1);
+ child_ref->child_name = g_strdup(child->name);
+ if (child->bs && child->bs->node_name[0]) {
+ child_ref->node_name = g_strdup(child->bs->node_name);
+ }
+ QAPI_LIST_APPEND(children_list_tail, child_ref);
+ }
+
backing = bdrv_cow_bs(bs);
if (backing) {
info->backing_file = g_strdup(backing->filename);
diff --git a/qapi/block-core.json b/qapi/block-core.json
index 07c5773717..8d115ec7a3 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -461,6 +461,19 @@
'direct': 'bool',
'no-flush': 'bool' } }
+##
+# @BlockdevChildRef:
+#
+# @child-name: the name/type of the child, e.g. 'file', 'backing'.
+#
+# @node-name: the node-name of the child.
+#
+# Since: 10.1
+##
+{ 'struct': 'BlockdevChildRef',
+ 'data': { 'child-name': 'str',
+ '*node-name': 'str' } }
+
##
# @BlockDeviceInfo:
#
@@ -486,6 +499,8 @@
# @backing_file_depth: number of files in the backing file chain
# (since: 1.2)
#
+# @children: Information about child block nodes. (since: 10.1)
+#
# @active: true if the backend is active; typical cases for inactive backends
# are on the migration source instance after migration completes and on the
# destination before it completes. (since: 10.0)
@@ -560,6 +575,7 @@
{ 'struct': 'BlockDeviceInfo',
'data': { 'file': 'str', '*node-name': 'str', 'ro': 'bool', 'drv': 'str',
'*backing_file': 'str', 'backing_file_depth': 'int',
+ 'children': ['BlockdevChildRef'],
'active': 'bool', 'encrypted': 'bool',
'detect_zeroes': 'BlockdevDetectZeroesOptions',
'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int',
diff --git a/tests/qemu-iotests/184.out b/tests/qemu-iotests/184.out
index 52692b6b3b..aa02df950b 100644
--- a/tests/qemu-iotests/184.out
+++ b/tests/qemu-iotests/184.out
@@ -47,6 +47,7 @@ Testing:
"iops": 0,
"bps_wr": 0,
"write_threshold": 0,
+ "file-child-node-name": "disk0",
"encrypted": false,
"bps": 0,
"bps_rd": 0,
diff --git a/tests/qemu-iotests/191.out b/tests/qemu-iotests/191.out
index 2a72ca7106..f29e1b5209 100644
--- a/tests/qemu-iotests/191.out
+++ b/tests/qemu-iotests/191.out
@@ -143,6 +143,7 @@ wrote 65536/65536 bytes at offset 1048576
"bps_wr": 0,
"write_threshold": 0,
"backing_file": "TEST_DIR/t.IMGFMT.base",
+ "file-child-node-name": "NODE_NAME",
"encrypted": false,
"bps": 0,
"bps_rd": 0,
@@ -214,6 +215,7 @@ wrote 65536/65536 bytes at offset 1048576
"bps_wr": 0,
"write_threshold": 0,
"backing_file": "TEST_DIR/t.IMGFMT.base",
+ "file-child-node-name": "NODE_NAME",
"encrypted": false,
"bps": 0,
"bps_rd": 0,
@@ -285,6 +287,7 @@ wrote 65536/65536 bytes at offset 1048576
"bps_wr": 0,
"write_threshold": 0,
"backing_file": "TEST_DIR/t.IMGFMT.base",
+ "file-child-node-name": "NODE_NAME",
"encrypted": false,
"bps": 0,
"bps_rd": 0,
@@ -344,6 +347,7 @@ wrote 65536/65536 bytes at offset 1048576
"iops": 0,
"bps_wr": 0,
"write_threshold": 0,
+ "file-child-node-name": "NODE_NAME",
"encrypted": false,
"bps": 0,
"bps_rd": 0,
@@ -558,6 +562,7 @@ wrote 65536/65536 bytes at offset 1048576
"bps_wr": 0,
"write_threshold": 0,
"backing_file": "TEST_DIR/t.IMGFMT.base",
+ "file-child-node-name": "NODE_NAME",
"encrypted": false,
"bps": 0,
"bps_rd": 0,
@@ -640,6 +645,7 @@ wrote 65536/65536 bytes at offset 1048576
"bps_wr": 0,
"write_threshold": 0,
"backing_file": "TEST_DIR/t.IMGFMT.ovl2",
+ "file-child-node-name": "NODE_NAME",
"encrypted": false,
"bps": 0,
"bps_rd": 0,
@@ -699,6 +705,7 @@ wrote 65536/65536 bytes at offset 1048576
"iops": 0,
"bps_wr": 0,
"write_threshold": 0,
+ "file-child-node-name": "NODE_NAME",
"encrypted": false,
"bps": 0,
"bps_rd": 0,
@@ -770,6 +777,7 @@ wrote 65536/65536 bytes at offset 1048576
"bps_wr": 0,
"write_threshold": 0,
"backing_file": "TEST_DIR/t.IMGFMT.base",
+ "file-child-node-name": "NODE_NAME",
"encrypted": false,
"bps": 0,
"bps_rd": 0,
diff --git a/tests/qemu-iotests/273.out b/tests/qemu-iotests/273.out
index c19753c685..eabe95c1a0 100644
--- a/tests/qemu-iotests/273.out
+++ b/tests/qemu-iotests/273.out
@@ -62,6 +62,7 @@ Testing: -blockdev file,node-name=base,filename=TEST_DIR/t.IMGFMT.base -blockdev
"bps_wr": 0,
"write_threshold": 0,
"backing_file": "TEST_DIR/t.IMGFMT.mid",
+ "file-child-node-name": "topf",
"encrypted": false,
"bps": 0,
"bps_rd": 0,
@@ -132,6 +133,7 @@ Testing: -blockdev file,node-name=base,filename=TEST_DIR/t.IMGFMT.base -blockdev
"bps_wr": 0,
"write_threshold": 0,
"backing_file": "TEST_DIR/t.IMGFMT.base",
+ "file-child-node-name": "midf",
"encrypted": false,
"bps": 0,
"bps_rd": 0,
--
2.47.2
More information about the pve-devel
mailing list