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

Some time ago (commit facda5443f) 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>
This commit is contained in:
Peter Krempa
2026-02-04 14:15:43 +01:00
committed by Kevin Wolf
parent cfda94eddb
commit d57bdcae9a
4 changed files with 12 additions and 7 deletions

View File

@@ -422,7 +422,7 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
/* Then try adding all block devices. If one fails, close all and
* exit.
*/
block_list = qmp_query_block(NULL);
block_list = qmp_query_block(false, false, NULL);
for (info = block_list; info; info = info->next) {
if (!info->value->inserted) {
@@ -741,7 +741,7 @@ void hmp_info_block(Monitor *mon, const QDict *qdict)
/* Print BlockBackend information */
if (!nodes) {
block_list = qmp_query_block(NULL);
block_list = qmp_query_block(false, false, NULL);
} else {
block_list = NULL;
}

View File

@@ -456,7 +456,7 @@ fail:
/* @p_info will be set only on success. */
static void GRAPH_RDLOCK
bdrv_query_info(BlockBackend *blk, BlockInfo **p_info, Error **errp)
bdrv_query_info(BlockBackend *blk, bool flat, BlockInfo **p_info, Error **errp)
{
BlockInfo *info = g_malloc0(sizeof(*info));
BlockDriverState *bs = blk_bs(blk);
@@ -488,7 +488,7 @@ bdrv_query_info(BlockBackend *blk, BlockInfo **p_info, Error **errp)
}
if (bs && bs->drv) {
info->inserted = bdrv_block_device_info(blk, bs, false, errp);
info->inserted = bdrv_block_device_info(blk, bs, flat, errp);
if (info->inserted == NULL) {
goto err;
}
@@ -698,7 +698,7 @@ bdrv_query_bds_stats(BlockDriverState *bs, bool blk_level)
return s;
}
BlockInfoList *qmp_query_block(Error **errp)
BlockInfoList *qmp_query_block(bool has_flat, bool flat, Error **errp)
{
BlockInfoList *head = NULL, **p_next = &head;
BlockBackend *blk;
@@ -714,7 +714,7 @@ BlockInfoList *qmp_query_block(Error **errp)
}
info = g_malloc0(sizeof(*info));
bdrv_query_info(blk, &info->value, &local_err);
bdrv_query_info(blk, flat, &info->value, &local_err);
if (local_err) {
error_propagate(errp, local_err);
g_free(info);

View File

@@ -855,6 +855,10 @@
#
# Get a list of `BlockInfo` for all virtual block devices.
#
# @flat: Omit nested data about the backing image, i.e. `BlockInfo`
# member 'inserted.image.backing-image' will be absent.
# Default is false. (Since 11.0)
#
# Returns: a list describing each virtual block device. Filter nodes
# that were created implicitly are skipped over.
#
@@ -945,6 +949,7 @@
# }
##
{ 'command': 'query-block', 'returns': ['BlockInfo'],
'data': { '*flat': 'bool' },
'allow-preconfig': true }
##

View File

@@ -1849,7 +1849,7 @@ static void addRemovableDevicesMenuItems(void)
BlockInfoList *currentDevice, *pointerToFree;
NSString *deviceName;
currentDevice = qmp_query_block(NULL);
currentDevice = qmp_query_block(false, false, NULL);
pointerToFree = currentDevice;
menu = [[[NSApp mainMenu] itemWithTitle:@"Machine"] submenu];