enhancement for qmp/hmp interfaces of block info
v13 cover enhancement for qmp/hmp interfaces of block info
This serial let qmp interface show delaied info, including internal snapshot
/backing chain on all block device at runtime, which helps management stack and human user, by retrieving exactly the same info of what qemu saws.
Example:
-> { "execute": "query-block" }
<- {
"return":[
{
"io-status": "ok",
"device":"ide0-hd0",
"locked":false,
"removable":false,
"inserted":{
"ro":false,
"drv":"qcow2",
"encrypted":false,
"file":"disks/test.qcow2",
"backing_file_depth":1,
"bps":1000000,
"bps_rd":0,
"bps_wr":0,
"iops":1000000,
"iops_rd":0,
"iops_wr":0,
"image":{
"filename":"disks/test.qcow2",
"format":"qcow2",
"virtual-size":2048000,
"backing_file":"base.qcow2",
"full-backing-filename":"disks/base.qcow2",
"backing-filename-format:"qcow2",
"snapshots":[
{
"id": "1",
"name": "snapshot1",
"vm-state-size": 0,
"date-sec": 10000200,
"date-nsec": 12,
"vm-clock-sec": 206,
"vm-clock-nsec": 30
}
],
"backing-image":{
"filename":"disks/base.qcow2",
"format":"qcow2",
"virtual-size":2048000
}
}
},
"type":"unknown"
},
{
"io-status": "ok",
"device":"ide1-cd0",
"locked":false,
"removable":true,
"type":"unknown"
},
{
"device":"floppy0",
"locked":false,
"removable":true,
"type":"unknown"
},
{
"device":"sd0",
"locked":false,
"removable":true,
"type":"unknown"
}
]}
These patches follows the rule that use qmp to retieve information,
hmp layer just does a translation from qmp object it got. To make code graceful, snapshot and image info retrieving code in qemu and qemu-img are merged into block layer, and some function name was adjusted to make it tips better. For the part touch by the serial, it works as:
qemu qemu-img
dump_monitor dump_stdout
|--------------|
| block/qapi.c
Special thanks for Markus, Stefan, Kevin, Eric reviewing many times.
v13:
Renamed the serial as "enhancement for qmp/hmp interfaces of block info". Seperated the common part of code moving and hmp printf as a standalone
serial, which can be used by both mine and Pavel's work. This serial depend on it: "[PATCH V3 0/4] qapi and snapshot code clean up in block layer",
https://lists.gnu.org/archive/html/qemu-devel/2013-05/msg03539.html
Removed the VM snapshot info part, since it relate to VM snapshot creating
logic, which should be changed together with Pavel's serial.
Address Eric's comments:
2/6: bdrv_query_image_info() returns void now, only use *errp to tip error.
Wenchao Xia (6):
1 block: add snapshot info query function bdrv_query_snapshot_info_list() 2 block: add image info query function bdrv_query_image_info() 3 qmp: add recursive member in ImageInfo
4 qmp: add ImageInfo in BlockDeviceInfo used by query-block
5 hmp: show ImageInfo in 'info block'
6 hmp: add parameters device and -v for info block
block/qapi.c | 148 ++++++++++++++++++++++++++++++++++++++++++-------- hmp.c | 21 +++++++ include/block/qapi.h | 14 +++-- monitor.c | 7 ++- qapi-schema.json | 10 +++- qemu-img.c | 10 +++- qmp-commands.hx | 69 +++++++++++++++++++++++- 7 files changed, 242 insertions(+), 37 deletions(-)
PATCH v13 1/6 block: add snapshot info query function bdrv_query_snapshot_info_list()
This patch adds function bdrv_query_snapshot_info_list(), which will retrieve snapshot info of an image in qmp object format. The implementation is based on the code moved from qemu-img.c with modification to fit more for qmp based block layer API.
--- block/qapi.c | 55 ++++++++++++++++++++++++++++++++++++++----------- include/block/qapi.h | 4 ++- qemu-img.c | 5 +++- 3 files changed, 49 insertions(+), 15 deletions(-)
block/qapi.c +42 -13
@@ -26,29 +26,56 @@#include "block/block_int.h" #include "qmp-commands.h" -void bdrv_collect_snapshots (BlockDriverState *bs ,ImageInfo *info) +/* +* Returns 0 on success, with *p_list either set to describe snapshot +* information, or NULL because there are no snapshots. Returns -errno on +* error, with *p_list untouched. +*/ +int bdrv_query_snapshot_info_list (BlockDriverState *bs, +SnapshotInfoList **p_list, +Error **errp) {int i, sn_count;QEMUSnapshotInfo *sn_tab =NULL ; -SnapshotInfoList *info_list, *cur_item =NULL ; +SnapshotInfoList *info_list, *cur_item =NULL , *head =NULL ; +SnapshotInfo *info; + sn_count =bdrv_snapshot_list (bs, &sn_tab); +if (sn_count <0 ) { +const char *dev =bdrv_get_device_name (bs); +switch (sn_count) { +case -ENOMEDIUM : +error_setg (errp,"Device '%s' is not inserted" , dev); +break ; +case -ENOTSUP : +error_setg (errp, +"Device '%s' does not support internal snapshots" , + dev); +break ; +default : +error_setg_errno (errp, -sn_count, +"Can't list snapshots of device '%s'" , dev); +break ; + } +return sn_count; + }for (i =0 ; i < sn_count; i++) { - info->has_snapshots = true; - info_list =g_new0 (SnapshotInfoList,1 ); + info =g_new0 (SnapshotInfo,1 ); + info->id =g_strdup (sn_tab[i].id_str); + info->name =g_strdup (sn_tab[i].name); + info->vm_state_size = sn_tab[i].vm_state_size; + info->date_sec = sn_tab[i].date_sec; + info->date_nsec = sn_tab[i].date_nsec; + info->vm_clock_sec = sn_tab[i].vm_clock_nsec /1000000000 ; + info->vm_clock_nsec = sn_tab[i].vm_clock_nsec %1000000000 ; - info_list->value =g_new0 (SnapshotInfo,1 ); - info_list->value->id =g_strdup (sn_tab[i].id_str); - info_list->value->name =g_strdup (sn_tab[i].name); - info_list->value->vm_state_size = sn_tab[i].vm_state_size; - info_list->value->date_sec = sn_tab[i].date_sec; - info_list->value->date_nsec = sn_tab[i].date_nsec; - info_list->value->vm_clock_sec = sn_tab[i].vm_clock_nsec /1000000000 ; - info_list->value->vm_clock_nsec = sn_tab[i].vm_clock_nsec %1000000000 ; + info_list =g_new0 (SnapshotInfoList,1 ); + info_list->value = info;/* XXX: waiting for the qapi to support qemu-queue.h types */ if (!cur_item) { - info->snapshots = cur_item = info_list; + head = cur_item = info_list; }else { cur_item->next = info_list; cur_item = info_list;
@@ -57,6 +84,8 @@ void bdrv_collect_snapshots(BlockDriverState *bs , ImageInfo *info) }g_free (sn_tab); + *p_list = head; +return 0 ; } void bdrv_collect_image_info(BlockDriverState *bs,
include/block/qapi.h +3 -1
@@ -29,7 +29,9 @@#include "block/block.h" #include "block/snapshot.h" -void bdrv_collect_snapshots (BlockDriverState *bs ,ImageInfo *info); +int bdrv_query_snapshot_info_list (BlockDriverState *bs, +SnapshotInfoList **p_list, +Error **errp);void bdrv_collect_image_info (BlockDriverState *bs,ImageInfo *info,const char *filename);
qemu-img.c +4 -1
@@ -1665,7 +1665,10 @@ static ImageInfoList *collect_image_info_list(const char *filename, info =g_new0 (ImageInfo,1 );bdrv_collect_image_info (bs, info, filename); -bdrv_collect_snapshots (bs, info); +bdrv_query_snapshot_info_list (bs, &info->snapshots,NULL ); +if (info->snapshots) { + info->has_snapshots = true; + } elem =g_new0 (ImageInfoList,1 ); elem->value = info;
Signature · 1 line
1.7.1
PATCH v13 2/6 block: add image info query function bdrv_query_image_info()
In reply to Wenchao XiaThis patch adds function bdrv_query_image_info(), which will retrieve image info in qmp object format. The implementation is based on the code moved from qemu-img.c, but uses block layer function to get snapshot info.
--- block/qapi.c | 36 ++++++++++++++++++++++++++++++------ include/block/qapi.h | 6 +++--- qemu-img.c | 11 ++++++----- 3 files changed, 39 insertions(+), 14 deletions(-)
block/qapi.c +30 -6
@@ -88,18 +88,22 @@ int bdrv_query_snapshot_info_list(BlockDriverState *bs,return 0 ; } -void bdrv_collect_image_info (BlockDriverState *bs, -ImageInfo *info, -const char *filename) +/* @p_info will be set only on success. */ +void bdrv_query_image_info (BlockDriverState *bs, +ImageInfo **p_info, +Error **errp) {uint64_t total_sectors; -char backing_filename[1024 ]; +const char *backing_filename;char backing_filename2[1024 ];BlockDriverInfo bdi; +int ret; +Error *err =NULL ; +ImageInfo *info =g_new0 (ImageInfo,1 );bdrv_get_geometry (bs, &total_sectors); - info->filename =g_strdup (filename); + info->filename =g_strdup (bs->filename); info->format =g_strdup (bdrv_get_format_name (bs)); info->virtual_size = total_sectors *512 ; info->actual_size =bdrv_get_allocated_file_size (bs);
@@ -116,7 +120,7 @@ void bdrv_collect_image_info(BlockDriverState *bs, info->dirty_flag = bdi.is_dirty; info->has_dirty_flag = true; } -bdrv_get_backing_filename (bs, backing_filename,sizeof (backing_filename)); + backing_filename = bs->backing_file;if (backing_filename[0 ] !='\0' ) { info->backing_filename =g_strdup (backing_filename); info->has_backing_filename = true;
@@ -134,6 +138,26 @@ void bdrv_collect_image_info(BlockDriverState *bs, info->has_backing_filename_format = true; } } + + ret =bdrv_query_snapshot_info_list (bs, &info->snapshots, &err); +switch (ret) { +case 0 : +if (info->snapshots) { + info->has_snapshots = true; + } +break ; +/* recoverable error */ +case -ENOMEDIUM : +case -ENOTSUP : +error_free (err); +break ; +default : +error_propagate (errp, err); +qapi_free_ImageInfo (info); +return ; + } + + *p_info = info; }BlockInfo *bdrv_query_info (BlockDriverState *bs)
include/block/qapi.h +3 -3
@@ -32,9 +32,9 @@int bdrv_query_snapshot_info_list (BlockDriverState *bs,SnapshotInfoList **p_list,Error **errp); -void bdrv_collect_image_info (BlockDriverState *bs, -ImageInfo *info, -const char *filename); +void bdrv_query_image_info (BlockDriverState *bs, +ImageInfo **p_info, +Error **errp);BlockInfo *bdrv_query_info (BlockDriverState *s);BlockStats *bdrv_query_stats (const BlockDriverState *bs);
qemu-img.c +6 -5
@@ -1642,6 +1642,7 @@ static ImageInfoList *collect_image_info_list(const char *filename,ImageInfoList *head =NULL ;ImageInfoList **last = &head;GHashTable *filenames; +Error *err =NULL ; filenames =g_hash_table_new_full (g_str_hash, str_equal_func,NULL ,NULL );
@@ -1663,11 +1664,11 @@ static ImageInfoList *collect_image_info_list(const char *filename, goto err; } - info =g_new0 (ImageInfo,1 ); -bdrv_collect_image_info (bs, info, filename); -bdrv_query_snapshot_info_list (bs, &info->snapshots,NULL ); -if (info->snapshots) { - info->has_snapshots = true; +bdrv_query_image_info (bs, &info, &err); +if (error_is_set (&err)) { +error_report ("%s" ,error_get_pretty (err)); +error_free (err); + goto err; } elem =g_new0 (ImageInfoList,1 );
Signature · 1 line
1.7.1
PATCH v13 3/6 qmp: add recursive member in ImageInfo
In reply to Wenchao XiaNew member *backing-image is added to reflect the backing chain status.
--- block/qapi.c | 16 +++++++++++++++- qapi-schema.json | 5 ++++- 2 files changed, 19 insertions(+), 2 deletions(-)
block/qapi.c +15 -1
@@ -88,7 +88,21 @@ int bdrv_query_snapshot_info_list(BlockDriverState *bs,return 0 ; } -/* @p_info will be set only on success. */ +/** +* bdrv_query_image_info: +* @bs: block device to examine +* @p_info: location to store image information +* @errp: location to store error information +* +* Store "flat" image inforation in @p_info. +* +* "Flat" means it does *not* query backing image information, +* i.e. (*pinfo)->has_backing_image will be set to false and +* (*pinfo)->backing_image to NULL even when the image does in fact have +* a backing image. +* +* @p_info will be set only on success. On error, store error in @errp. +*/ void bdrv_query_image_info (BlockDriverState *bs,ImageInfo **p_info,Error **errp)
qapi-schema.json +4 -1
@@ -236,6 +236,8 @@ # # @snapshots: #optional list of VM snapshots # +# @backing-image: #optional info of the backing image (since 1.6) +# # Since: 1.3 # ##
@@ -245,7 +247,8 @@ '*actual-size': 'int', 'virtual-size': 'int', '*cluster-size': 'int', '*encrypted': 'bool', '*backing-filename': 'str', '*full-backing-filename': 'str', - '*backing-filename-format': 'str', '*snapshots': ['SnapshotInfo'] } } + '*backing-filename-format': 'str', '*snapshots': ['SnapshotInfo'], + '*backing-image': 'ImageInfo' } } ## # @ImageCheck:
Signature · 1 line
1.7.1
PATCH v13 4/6 qmp: add ImageInfo in BlockDeviceInfo used by query-block
In reply to Wenchao XiaNow image info will be retrieved as an embbed json object inside BlockDeviceInfo, backing chain info and all related internal snapshot info can be got in the enhanced recursive structure of ImageInfo.
--- block/qapi.c | 43 +++++++++++++++++++++++++++++-- include/block/qapi.h | 4 ++- qapi-schema.json | 5 +++- qmp-commands.hx | 69 ++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 114 insertions(+), 7 deletions(-)
block/qapi.c +40 -3
@@ -174,9 +174,15 @@ void bdrv_query_image_info(BlockDriverState *bs, *p_info = info; } -BlockInfo *bdrv_query_info (BlockDriverState *bs) +/* @p_info will be set only on success. */ +void bdrv_query_info (BlockDriverState *bs, +BlockInfo **p_info, +Error **errp) {BlockInfo *info =g_malloc0 (sizeof (*info)); +BlockDriverState *bs0; +ImageInfo **p_image_info; +Error *local_err =NULL ; info->device =g_strdup (bs->device_name); info->type =g_strdup ("unknown" ); info->locked =bdrv_dev_is_medium_locked (bs);
@@ -230,8 +236,30 @@ BlockInfo *bdrv_query_info(BlockDriverState *bs) info->inserted->iops_wr = bs->io_limits.iops[BLOCK_IO_LIMIT_WRITE ]; } + + bs0 = bs; + p_image_info = &info->inserted->image; +while (1 ) { +bdrv_query_image_info (bs0, p_image_info, &local_err); +if (error_is_set (&local_err)) { +error_propagate (errp, local_err); + goto err; + } +if (bs0->drv && bs0->backing_hd) { + bs0 = bs0->backing_hd; + (*p_image_info)->has_backing_image = true; + p_image_info = &((*p_image_info)->backing_image); + }else { +break ; + } + } } -return info; + + *p_info = info; +return ; + + err: +qapi_free_BlockInfo (info); }BlockStats *bdrv_query_stats (const BlockDriverState *bs)
@@ -268,16 +296,25 @@ BlockInfoList *qmp_query_block(Error **errp) {BlockInfoList *head =NULL , **p_next = &head;BlockDriverState *bs =NULL ; +Error *local_err =NULL ;while ((bs =bdrv_next (bs))) {BlockInfoList *info =g_malloc0 (sizeof (*info)); - info->value =bdrv_query_info (bs); +bdrv_query_info (bs, &info->value, &local_err); +if (error_is_set (&local_err)) { +error_propagate (errp, local_err); + goto err; + } *p_next = info; p_next = &info->next; }return head; + + err: +qapi_free_BlockInfoList (head); +return NULL ; }BlockStatsList *qmp_query_blockstats (Error **errp)
include/block/qapi.h +3 -1
@@ -35,7 +35,9 @@ int bdrv_query_snapshot_info_list(BlockDriverState *bs,void bdrv_query_image_info (BlockDriverState *bs,ImageInfo **p_info,Error **errp); -BlockInfo *bdrv_query_info (BlockDriverState *s); +void bdrv_query_info (BlockDriverState *bs, +BlockInfo **p_info, +Error **errp);BlockStats *bdrv_query_stats (const BlockDriverState *bs); void bdrv_snapshot_dump(fprintf_function func_fprintf, void *f,
qapi-schema.json +4 -1
@@ -759,6 +759,8 @@ # # @iops_wr: write I/O operations per second is specified # +# @image: the info of image used (since: 1.6) +# # Since: 0.14.0 # # Notes: This interface is only found in @BlockInfo.
@@ -768,7 +770,8 @@ '*backing_file': 'str', 'backing_file_depth': 'int', 'encrypted': 'bool', 'encryption_key_missing': 'bool', 'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int', - 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int'} } + 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int', + 'image': 'ImageInfo' } } ## # @BlockDeviceIoStatus:
qmp-commands.hx +67 -2
87 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v13 5/6 hmp: show ImageInfo in 'info block'
In reply to Wenchao XiaNow human monitor can show image details, include internal snapshot and backing chain info for every block device.
--- hmp.c | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-)
hmp.c +14 -0
@@ -22,6 +22,7 @@#include "qemu/sockets.h" #include "monitor/monitor.h" #include "ui/console.h" +#include "block/qapi.h" static void hmp_handle_error (Monitor *mon,Error **errp) {
@@ -277,6 +278,7 @@ void hmp_info_cpus(Monitor *mon, const QDict *qdict)void hmp_info_block (Monitor *mon,const QDict *qdict) {BlockInfoList *block_list, *info; +ImageInfo *image_info; block_list =qmp_query_block (NULL );
@@ -318,6 +320,18 @@ void hmp_info_block(Monitor *mon, const QDict *qdict) info->value->inserted->iops, info->value->inserted->iops_rd, info->value->inserted->iops_wr); + +monitor_printf (mon," images:\n" ); + image_info = info->value->inserted->image; +while (1 ) { +bdrv_image_info_dump ((fprintf_function )monitor_printf, mon, + image_info); +if (image_info->has_backing_image) { + image_info = image_info->backing_image; + }else { +break ; + } + } }else {monitor_printf (mon," [not inserted]" ); }
Signature · 1 line
1.7.1
PATCH v13 6/6 hmp: add parameters device and -v for info block
In reply to Wenchao XiaWith these parameters, user can choose the information to be showed, to avoid message flood in the monitor.
--- hmp.c | 25 ++++++++++++++++--------- monitor.c | 7 ++++--- 2 files changed, 20 insertions(+), 12 deletions(-)
hmp.c +16 -9
@@ -279,10 +279,15 @@ void hmp_info_block(Monitor *mon, const QDict *qdict) {BlockInfoList *block_list, *info;ImageInfo *image_info; +const char *device =qdict_get_try_str (qdict,"device" ); +int verbose =qdict_get_try_bool (qdict,"verbose" ,0 ); block_list =qmp_query_block (NULL );for (info = block_list; info; info = info->next) { +if (device &&strcmp (device, info->value->device)) { +continue ; + }monitor_printf (mon,"%s: removable=%d" , info->value->device, info->value->removable);
@@ -321,15 +326,17 @@ void hmp_info_block(Monitor *mon, const QDict *qdict) info->value->inserted->iops_rd, info->value->inserted->iops_wr); -monitor_printf (mon," images:\n" ); - image_info = info->value->inserted->image; -while (1 ) { -bdrv_image_info_dump ((fprintf_function )monitor_printf, mon, - image_info); -if (image_info->has_backing_image) { - image_info = image_info->backing_image; - }else { -break ; +if (verbose) { +monitor_printf (mon," images:\n" ); + image_info = info->value->inserted->image; +while (1 ) { +bdrv_image_info_dump ((fprintf_function )monitor_printf, + mon, image_info); +if (image_info->has_backing_image) { + image_info = image_info->backing_image; + }else { +break ; + } } } }else {
monitor.c +4 -3
@@ -2472,9 +2472,10 @@ static mon_cmd_t info_cmds[] = { }, { .name = "block", - .args_type = "", - .params = "", - .help = "show the block devices", + .args_type = "verbose:-v,device:B?", + .params = "[-v] [device]", + .help ="show info of one block device or all block devices " + "(and details of images with -v option)", .mhandler.cmd = hmp_info_block, }, {
Signature · 1 line
1.7.1
On 05/24/2013 10:24 PM, Wenchao Xia wrote:
The cover letter doesn't get committed into git; but if you do respin, it might be worth cleaning up some of the grammar. I know English is not your native language, and you're doing a fine job of coping as it is, but this might help you improve your skills.
Quoted 1 line
This serial let qmp interface show delaied info, including internal snapshot
s/serial let/series lets/
not sure what word you meant for 'delaied'
Quoted 2 lines
/backing chain on all block device at runtime, which helps management stack and human user, by retrieving exactly the same info of what qemu saws.
s/saws/sees/
Quoted 15 lines
Example:
-> { "execute": "query-block" }<- { "return":[ { "io-status": "ok", "device":"ide0-hd0", "locked":false, "removable":false, "inserted":{ "ro":false, "drv":"qcow2", "encrypted":false, "file":"disks/test.qcow2",
Here...
Quoted 9 lines
"backing_file_depth":1,
"bps":1000000,
"bps_rd":0,
"bps_wr":0,
"iops":1000000,
"iops_rd":0,
"iops_wr":0,
"image":{
"filename":"disks/test.qcow2",...and here, it looks like we have redundant information. But that's okay; I think we're stuck with preserving backwards compatibility while still providing the new information in a saner structure.
Quoted 5 lines
"format":"qcow2",
"virtual-size":2048000,
"backing_file":"base.qcow2",
"full-backing-filename":"disks/base.qcow2",
"backing-filename-format:"qcow2",And here's another case of information...
Quoted 6 lines
"snapshots":[
{
"id": "1",
"name": "snapshot1",
"vm-state-size": 0,
"date-sec": 10000200,Quoted 8 lines
"date-nsec": 12,
"vm-clock-sec": 206,
"vm-clock-nsec": 30
}
],
"backing-image":{
"filename":"disks/base.qcow2",
"format":"qcow2",...that gets repeated later. Oh well.
Quoted 2 lines
These patches follows the rule that use qmp to retieve information,
s/retieve/retrieve/
Quoted 3 lines
hmp layer just does a translation from qmp object it got. To make code graceful, snapshot and image info retrieving code in qemu and qemu-img are merged into block layer, and some function name was adjusted to make it tips
s/name was/names were/
Quoted 1 line
better. For the part touch by the serial, it works as:
s/make it tips better/describe them better/
s/touch/touched/
s/serial/series/
Quoted 6 lines
qemu qemu-img
dump_monitordump_stdout|--------------| |
Quoted 7 lines
block/qapi.cSpecial thanks for Markus, Stefan, Kevin, Eric reviewing many times.
v13:
Renamed the serial as "enhancement for qmp/hmp interfaces of block info". Seperated the common part of code moving and hmp printf as a standalone
s/Seperated/Separated/
Quoted 1 line
serial, which can be used by both mine and Pavel's work. This serial depend
s/serial/series/
Quoted 4 lines
on it: "[PATCH V3 0/4] qapi and snapshot code clean up in block layer",
https://lists.gnu.org/archive/html/qemu-devel/2013-05/msg03539.html
Removed the VM snapshot info part, since it relate to VM snapshot creating
logic, which should be changed together with Pavel's serial.
s/serial/series/
Quoted 2 lines
Address Eric's comments:
2/6:bdrv_query_image_info()returns void now, only use *errp to tip error.
s/tip/record/
Quoted 21 lines
Wenchao Xia (6):
1 block: add snapshot info query functionbdrv_query_snapshot_info_list()2 block: add image info query functionbdrv_query_image_info()3 qmp: add recursive member in ImageInfo
4 qmp: add ImageInfo in BlockDeviceInfo used by query-block
5 hmp: show ImageInfo in 'info block'
6 hmp: add parameters device and -v for info blockblock/qapi.c | 148 ++++++++++++++++++++++++++++++++++++++++++-------- hmp.c | 21 +++++++ include/block/qapi.h | 14 +++-- monitor.c | 7 ++- qapi-schema.json | 10 +++- qemu-img.c | 10 +++- qmp-commands.hx | 69 +++++++++++++++++++++++- 7 files changed, 242 insertions(+), 37 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH V13 2/6] block: add image info query function bdrv_query_image_info()
In reply to Wenchao XiaQuoted 5 lines · Wenchao Xia
This patch adds function
bdrv_query_image_info(), which will retrieve image info in qmp object format. The implementation is based on the code moved fromqemu-img.c, but uses block layer function to get snapshot info.
Quoted 7 lines
Signed-off-by Wenchao Xia <[email protected]>--- block/qapi.c | 36 ++++++++++++++++++++++++++++++------ include/block/qapi.h | 6 +++--- qemu-img.c | 11 ++++++----- 3 files changed, 39 insertions(+), 14 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH V13 3/6] qmp: add recursive member in ImageInfo
In reply to Wenchao XiaQuoted 15 lines · Wenchao Xia
New member *backing-image is added to reflect the backing chain status.
Signed-off-by Wenchao Xia <[email protected]>--- block/qapi.c | 16 +++++++++++++++- qapi-schema.json | 5 ++++- 2 files changed, 19 insertions(+), 2 deletions(-)block/qapi.c +0
-0@@ -88,7 +88,21 @@ int bdrv_query_snapshot_info_list(BlockDriverState *bs,return 0 ;
block/qapi.c int bdrv_query_snapshot_info_list(BlockDriverState *bs, · line 97
Quoted 10 lines
block/qapi.c +7
-1} -/* @p_info will be set only on success. */ +/** +* bdrv_query_image_info: +* @bs: block device to examine +* @p_info: location to store image information +* @errp: location to store error information +* +* Store "flat" image inforation in @p_info.
s/inforation/information/
block/qapi.c int bdrv_query_snapshot_info_list(BlockDriverState *bs, · line 105
Quoted 8 lines
block/qapi.c +8
-0+* +* "Flat" means it does *not* query backing image information, +* i.e. (*pinfo)->has_backing_image will be set to false and +* (*pinfo)->backing_image to NULL even when the image does in fact have +* a backing image. +* +* @p_info will be set only on success. On error, store error in @errp. +*/
Does this comment hunk belong in the previous patch?
Quoted 17 lines
block/qapi.c +0
-0void bdrv_query_image_info (BlockDriverState *bs,ImageInfo **p_info,Error **errp)qapi-schema.json +2
-0@@ -236,6 +236,8 @@ # # @snapshots: #optional list of VM snapshots # +# @backing-image: #optional info of the backing image (since 1.6) +# # Since: 1.3 # ##
qapi-schema.json line 251
Quoted 6 lines
qapi-schema.json +2
-1@@ -245,7 +247,8 @@ '*actual-size': 'int', 'virtual-size': 'int', '*cluster-size': 'int', '*encrypted': 'bool', '*backing-filename': 'str', '*full-backing-filename': 'str', - '*backing-filename-format': 'str', '*snapshots': ['SnapshotInfo'] } } + '*backing-filename-format': 'str', '*snapshots': ['SnapshotInfo'], + '*backing-image': 'ImageInfo' } }
The API change looks fine, except there is no code change to actually populate the new field. This hunk should probably be squashed with the patch that implements the field. Also, are you missing any changes to qmp-commands.hx?
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH V13 3/6] qmp: add recursive member in ImageInfo
Quoted 38 lines · Eric Blake
Quoted 15 lines · Wenchao Xia
New member *backing-image is added to reflect the backing chain status.
Signed-off-by Wenchao Xia <[email protected]>--- block/qapi.c | 16 +++++++++++++++- qapi-schema.json | 5 ++++- 2 files changed, 19 insertions(+), 2 deletions(-)block/qapi.c +0
-0@@ -88,7 +88,21 @@ int bdrv_query_snapshot_info_list(BlockDriverState *bs,return 0 ;block/qapi.c int bdrv_query_snapshot_info_list(BlockDriverState *bs, · line 97
Quoted 10 lines
block/qapi.c +7
-1} -/* @p_info will be set only on success. */ +/** +* bdrv_query_image_info: +* @bs: block device to examine +* @p_info: location to store image information +* @errp: location to store error information +* +* Store "flat" image inforation in @p_info. s/inforation/information/
block/qapi.c int bdrv_query_snapshot_info_list(BlockDriverState *bs, · line 105
Quoted 8 lines
block/qapi.c +8
-0+* +* "Flat" means it does *not* query backing image information, +* i.e. (*pinfo)->has_backing_image will be set to false and +* (*pinfo)->backing_image to NULL even when the image does in fact have +* a backing image. +* +* @p_info will be set only on success. On error, store error in @errp. +*/
Quoted 2 lines
Does this comment hunk belong in the previous patch?
Yes, it got modified again in this one, will move it.
Quoted 20 lines
Quoted 20 lines
block/qapi.c +0
-0void bdrv_query_image_info (BlockDriverState *bs,ImageInfo **p_info,Error **errp)qapi-schema.json +2
-0@@ -236,6 +236,8 @@ # # @snapshots: #optional list of VM snapshots # +# @backing-image: #optional info of the backing image (since 1.6) +# # Since: 1.3 # ##@@ -245,7 +247,8 @@ '*actual-size': 'int', 'virtual-size': 'int', '*cluster-size': 'int', '*encrypted': 'bool', '*backing-filename': 'str', '*full-backing-filename': 'str',
Quoted 9 lines
qapi-schema.json line 251
Quoted 3 lines
qapi-schema.json +2
-1- '*backing-filename-format': 'str', '*snapshots': ['SnapshotInfo'] } } + '*backing-filename-format': 'str', '*snapshots': ['SnapshotInfo'], + '*backing-image': 'ImageInfo' } }The API change looks fine, except there is no code change to actually populate the new field. This hunk should probably be squashed with the patch that implements the field. Also, are you missing any changes to qmp-commands.hx?
nop, in next patch qmp-commands.hx parts is added. Just to make
review easier, after that I am fine to squash them.
Signature · 3 lines
Best Regards Wenchao Xia
Re: [Qemu-devel] [PATCH V13 3/6] qmp: add recursive member in ImageInfo
Quoted 31 lines · Wenchao Xia
Quoted 21 lines · Eric Blake
Quoted 20 lines · Wenchao Xia
void bdrv_query_image_info(BlockDriverState *bs,
ImageInfo **p_info,
Error **errp)qapi-schema.json +2
-0@@ -236,6 +236,8 @@ # # @snapshots: #optional list of VM snapshots # +# @backing-image: #optional info of the backing image (since 1.6) +# # Since: 1.3 # ##@@ -245,7 +247,8 @@ '*actual-size': 'int', 'virtual-size': 'int', '*cluster-size': 'int', '*encrypted': 'bool', '*backing-filename': 'str', '*full-backing-filename': 'str',Quoted 9 lines
qapi-schema.json line 251
Quoted 3 lines
qapi-schema.json +2
-1- '*backing-filename-format': 'str', '*snapshots': ['SnapshotInfo'] } } + '*backing-filename-format': 'str', '*snapshots': ['SnapshotInfo'], + '*backing-image': 'ImageInfo' } }The API change looks fine, except there is no code change to actually populate the new field. This hunk should probably be squashed with the patch that implements the field. Also, are you missing any changes to qmp-commands.hx?
Quoted 2 lines
nop, in next patch qmp-commands.hx parts is added. Just to make
review easier, after that I am fine to squash them.
The qapi change should be together with the code that implements it. I need to see the code in order to review the documentation change.
Stefan
Re: [Qemu-devel] [PATCH V13 6/6] hmp: add parameters device and -v for info block
In reply to Wenchao Xiahmp.c void hmp_info_block(Monitor *mon, const QDict *qdict) · line 283
Quoted 10 lines · Wenchao Xia
hmp.c +2
-0@@ -279,10 +279,15 @@ void hmp_info_block(Monitor *mon, const QDict *qdict) {BlockInfoList *block_list, *info;ImageInfo *image_info; +const char *device =qdict_get_try_str (qdict,"device" ); +int verbose =qdict_get_try_bool (qdict,"verbose" ,0 );
bool verbose
Quoted 108 lines · Wenchao Xia
This serial let qmp interface show delaied info, including internal snapshot
/backing chain on all block device at runtime, which helps management stack and human user, by retrieving exactly the same info of what qemu saws.Example:
-> { "execute": "query-block" }<- { "return":[ { "io-status": "ok", "device":"ide0-hd0", "locked":false, "removable":false, "inserted":{ "ro":false, "drv":"qcow2", "encrypted":false, "file":"disks/test.qcow2", "backing_file_depth":1, "bps":1000000, "bps_rd":0, "bps_wr":0, "iops":1000000, "iops_rd":0, "iops_wr":0, "image":{ "filename":"disks/test.qcow2", "format":"qcow2", "virtual-size":2048000, "backing_file":"base.qcow2", "full-backing-filename":"disks/base.qcow2", "backing-filename-format:"qcow2", "snapshots":[ { "id": "1", "name": "snapshot1", "vm-state-size": 0, "date-sec": 10000200, "date-nsec": 12, "vm-clock-sec": 206, "vm-clock-nsec": 30 } ], "backing-image":{ "filename":"disks/base.qcow2", "format":"qcow2", "virtual-size":2048000 } } }, "type":"unknown" }, { "io-status": "ok", "device":"ide1-cd0", "locked":false, "removable":true, "type":"unknown" }, { "device":"floppy0", "locked":false, "removable":true, "type":"unknown" }, { "device":"sd0", "locked":false, "removable":true, "type":"unknown" } ]}
These patches follows the rule that use qmp to retieve information,
hmp layer just does a translation from qmp object it got. To make code graceful, snapshot and image info retrieving code in qemu and qemu-img are merged into block layer, and some function name was adjusted to make it tips better. For the part touch by the serial, it works as:qemu qemu-img
dump_monitordump_stdout|--------------| |
block/qapi.cSpecial thanks for Markus, Stefan, Kevin, Eric reviewing many times.
v13:
Renamed the serial as "enhancement for qmp/hmp interfaces of block info". Seperated the common part of code moving and hmp printf as a standalone
serial, which can be used by both mine and Pavel's work. This serial depend on it: "[PATCH V3 0/4] qapi and snapshot code clean up in block layer",
https://lists.gnu.org/archive/html/qemu-devel/2013-05/msg03539.html
Removed the VM snapshot info part, since it relate to VM snapshot creating
logic, which should be changed together with Pavel's serial.
Address Eric's comments:
2/6:bdrv_query_image_info()returns void now, only use *errp to tip error.Wenchao Xia (6):
1 block: add snapshot info query functionbdrv_query_snapshot_info_list()2 block: add image info query functionbdrv_query_image_info()3 qmp: add recursive member in ImageInfo
4 qmp: add ImageInfo in BlockDeviceInfo used by query-block
5 hmp: show ImageInfo in 'info block'
6 hmp: add parameters device and -v for info block
Quoted 8 lines
block/qapi.c | 148 ++++++++++++++++++++++++++++++++++++++++++-------- hmp.c | 21 +++++++ include/block/qapi.h | 14 +++-- monitor.c | 7 ++- qapi-schema.json | 10 +++- qemu-img.c | 10 +++- qmp-commands.hx | 69 +++++++++++++++++++++++- 7 files changed, 242 insertions(+), 37 deletions(-)
I left comments but overall this looks very close to merge now.