block: Wire up 'flat' mode also for 'query-block'
v2 cover block: Wire up 'flat' mode also for 'query-block'
v2:
- More descriptive docs text for the new QAPI option (Markus; new wording not approved)
- use new options in hmp_nbd_server_start to avoid fetching unused backing image info, impossible in 'info block' worker (Markus)
Peter Krempa (2):
block: Wire up 'flat' mode also for 'query-block'
hmp_nbd_server_start: Don't ask for backing image data
block/monitor/block-hmp-cmds.c | 4 ++-- block/qapi.c | 9 +++++---- qapi/block-core.json | 7 +++++++ ui/cocoa.m | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-)
Signature · 1 line
2.52.0
PATCH v2 2/2 hmp_nbd_server_start: Don't ask for backing image data
From: Peter Krempa <[email protected]>
'hmp_nbd_server_start' uses only the device name from the data returned from 'qmp_query_block', thus no backing file information. Use the new options to suppress asking for the unused parts to save on resources.
--- block/monitor/block-hmp-cmds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/monitor/block-hmp-cmds.c +1 -1
@@ -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 (false, false,NULL ); + block_list =qmp_query_block (true, true,NULL );for (info = block_list; info; info = info->next) {if (!info->value->inserted) {
Signature · 1 line
2.52.0
PATCH v2 1/2 block: Wire up 'flat' mode also for 'query-block'
In reply to Peter KrempaFrom: Peter Krempa <[email protected]>
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'.
--- block/monitor/block-hmp-cmds.c | 4 ++-- block/qapi.c | 9 +++++---- qapi/block-core.json | 7 +++++++ ui/cocoa.m | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-)
block/monitor/block-hmp-cmds.c +2 -2
@@ -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 ; }
block/qapi.c +5 -4
@@ -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,11 +698,12 @@ 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;Error *local_err =NULL ; +bool return_flat = has_flat && flat;GRAPH_RDLOCK_GUARD_MAINLOOP ();
@@ -714,7 +715,7 @@ BlockInfoList *qmp_query_block(Error **errp) } info =g_malloc0 (sizeof (*info)); -bdrv_query_info (blk, &info->value, &local_err); +bdrv_query_info (blk, return_flat, &info->value, &local_err);if (local_err) {error_propagate (errp, local_err);g_free (info);
qapi/block-core.json +7 -0
@@ -855,6 +855,12 @@ # # Get a list of `BlockInfo` for all virtual block devices. # +# @flat: Omit the nested data about backing image (Omitted are +# contents of 'backing-image' key of the 'ImageInfo' struct +# which is returned as 'image' key of 'BlockDeviceInfo' struct +# returned as 'inserted' key in 'BlockInfo' struct returned +# by this command). 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 +951,7 @@ # } ## { 'command': 'query-block', 'returns': ['BlockInfo'], + 'data': { '*flat': 'bool' }, 'allow-preconfig': true } ##
ui/cocoa.m +1 -1
@@ -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];
Signature · 1 line
2.52.0
Quoted 25 lines · Peter Krempa
From: Peter Krempa <[email protected]>
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 <[email protected]>--- block/monitor/block-hmp-cmds.c | 4 ++-- block/qapi.c | 9 +++++---- qapi/block-core.json | 7 +++++++ ui/cocoa.m | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-)+++
b/qapi/block-core.json
qapi/block-core.json line 861
Quoted 7 lines
qapi/block-core.json +4
-0@@ -855,6 +855,12 @@ # # Get a list of `BlockInfo` for all virtual block devices. # +# @flat: Omit the nested data about backing image (Omitted are +# contents of 'backing-image' key of the 'ImageInfo' struct +# which is returned as 'image' key of 'BlockDeviceInfo' struct +# returned as 'inserted' key in 'BlockInfo' struct returned
Extra space.
qapi/block-core.json line 862
Quoted 1 line
qapi/block-core.json +1
-0+# by this command). Default is false (Since 11.0)
Still hard to parse. Maybe:
@flat: Omit nested data about the backing image (ie. the contents at
'inserted.image.backing-image' are trimmed to avoid duplicate data about that backing image). Default is false (Since 11.0)
The idea makes sense to me, but I will defer to Markus on whether the wording still needs a tweak.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Re: [PATCH v2 2/2] hmp_nbd_server_start: Don't ask for backing image data
In reply to Peter KrempaQuoted 10 lines · Peter Krempa
From: Peter Krempa <[email protected]>
'
hmp_nbd_server_start' uses only the device name from the data returned from 'qmp_query_block', thus no backing file information. Use the new options to suppress asking for the unused parts to save on resources.Signed-off-by Peter Krempa <[email protected]>--- block/monitor/block-hmp-cmds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Quoted 36 lines · Eric Blake
Quoted 25 lines · Peter Krempa
From: Peter Krempa <[email protected]>
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 <[email protected]>--- block/monitor/block-hmp-cmds.c | 4 ++-- block/qapi.c | 9 +++++---- qapi/block-core.json | 7 +++++++ ui/cocoa.m | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-)+++
b/qapi/block-core.jsonqapi/block-core.json line 861
Quoted 7 lines
qapi/block-core.json +4
-0@@ -855,6 +855,12 @@ # # Get a list of `BlockInfo` for all virtual block devices. # +# @flat: Omit the nested data about backing image (Omitted are +# contents of 'backing-image' key of the 'ImageInfo' struct +# which is returned as 'image' key of 'BlockDeviceInfo' struct +# returned as 'inserted' key in 'BlockInfo' struct returnedExtra space.
Quoted 7 lines
qapi/block-core.json line 862
Quoted 1 line
qapi/block-core.json +1
-0+# by this command). Default is false (Since 11.0)Still hard to parse. Maybe:
@flat: Omit nested data about the backing image (ie. the contents at
'inserted.image.backing-image' are trimmed to avoid duplicate data about that backing image). Default is false (Since 11.0)
In this case the 'backing-image' data is not duplicate as it was the case with 'query-named-block-nodes', as it is not repeated on top level.
Here using 'flat' decreases the amount of returned information, but in case of libvirt we don't use anything from the 'backing-image', just stuff that is related to the frontend device which is not queryable via 'query-named-block-nodes'.
So then perhaps just shorten it to:
@flat: Omit nested data about the backing image (ie. the contents at
'inserted.image.backing-image' are trimmed). Default is false (Since 11.0)
Quoted 2 lines
The idea makes sense to me, but I will defer to Markus on whether the wording still needs a tweak.
Should I post a v3?