@samitouri / QOSamiQemu / commits / d57bdcae9a

block: Wire up 'flat' mode also for 'query-block'

Some time ago (commit facda5443f5a8) I've added 'flat' mode (which omits 'backing-image' key in reply) to 'query-named-block-nodes' to minimize the size of the returned JSON for deeper backing chains. While 'query-block' behaved slightly better it turns out that in libvirt we do call 'query-block' to figure out some information about the block device (e.g. throttling info) but we don't look at the backing chain itself. Wire up 'flat' for 'query-block' so that libvirt can ask for an abbreviated output. The implementation is much simpler as the internals are shared with 'query-named-block-nodes'. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Acked-by: Markus Armbruster <armbru@redhat.com> Message-ID: <f4476e9f7e8fda74c02be3f806acaa9aa2df4d9a.1770210044.git.pkrempa@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>

Peter Krempa committed Feb 4, 2026 at 14:15 UTC d57bdcae9a8a90b3e1ffb4d5b5ee2909ce5416c2
4 files changed +12 -7
block/monitor/block-hmp-cmds.c
+2 -2
@@ -422,7 +422,7 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
422 /* Then try adding all block devices. If one fails, close all and
423 * exit.
424 */
425 - block_list = qmp_query_block(NULL);
425 + block_list = qmp_query_block(false, false, NULL);
426
427 for (info = block_list; info; info = info->next) {
428 if (!info->value->inserted) {
@@ -741,7 +741,7 @@ void hmp_info_block(Monitor *mon, const QDict *qdict)
741
742 /* Print BlockBackend information */
743 if (!nodes) {
744 - block_list = qmp_query_block(NULL);
744 + block_list = qmp_query_block(false, false, NULL);
745 } else {
746 block_list = NULL;
747 }
block/qapi.c
+4 -4
@@ -456,7 +456,7 @@ fail:
456
457 /* @p_info will be set only on success. */
458 static void GRAPH_RDLOCK
459 -bdrv_query_info(BlockBackend *blk, BlockInfo **p_info, Error **errp)
459 +bdrv_query_info(BlockBackend *blk, bool flat, BlockInfo **p_info, Error **errp)
460 {
461 BlockInfo *info = g_malloc0(sizeof(*info));
462 BlockDriverState *bs = blk_bs(blk);
@@ -488,7 +488,7 @@ bdrv_query_info(BlockBackend *blk, BlockInfo **p_info, Error **errp)
488 }
489
490 if (bs && bs->drv) {
491 - info->inserted = bdrv_block_device_info(blk, bs, false, errp);
491 + info->inserted = bdrv_block_device_info(blk, bs, flat, errp);
492 if (info->inserted == NULL) {
493 goto err;
494 }
@@ -698,7 +698,7 @@ bdrv_query_bds_stats(BlockDriverState *bs, bool blk_level)
698 return s;
699 }
700
701 -BlockInfoList *qmp_query_block(Error **errp)
701 +BlockInfoList *qmp_query_block(bool has_flat, bool flat, Error **errp)
702 {
703 BlockInfoList *head = NULL, **p_next = &head;
704 BlockBackend *blk;
@@ -714,7 +714,7 @@ BlockInfoList *qmp_query_block(Error **errp)
714 }
715
716 info = g_malloc0(sizeof(*info));
717 - bdrv_query_info(blk, &info->value, &local_err);
717 + bdrv_query_info(blk, flat, &info->value, &local_err);
718 if (local_err) {
719 error_propagate(errp, local_err);
720 g_free(info);
qapi/block-core.json
+5
@@ -855,6 +855,10 @@
855 #
856 # Get a list of `BlockInfo` for all virtual block devices.
857 #
858 +# @flat: Omit nested data about the backing image, i.e. `BlockInfo`
859 +# member 'inserted.image.backing-image' will be absent.
860 +# Default is false. (Since 11.0)
861 +#
862 # Returns: a list describing each virtual block device. Filter nodes
863 # that were created implicitly are skipped over.
864 #
@@ -945,6 +949,7 @@
949 # }
950 ##
951 { 'command': 'query-block', 'returns': ['BlockInfo'],
952 + 'data': { '*flat': 'bool' },
953 'allow-preconfig': true }
954
955 ##
ui/cocoa.m
+1 -1
@@ -1849,7 +1849,7 @@ static void addRemovableDevicesMenuItems(void)
1849 BlockInfoList *currentDevice, *pointerToFree;
1850 NSString *deviceName;
1851
1852 - currentDevice = qmp_query_block(NULL);
1852 + currentDevice = qmp_query_block(false, false, NULL);
1853 pointerToFree = currentDevice;
1854
1855 menu = [[[NSApp mainMenu] itemWithTitle:@"Machine"] submenu];