This serial of patches does two things: merge some info code in qemu-img, and add following interfaces: 1) qmp: query-images 2) qmp: query-snapshots 3) hmp: show internal snapshot info on a single block device These patches follows the rule that use qmp to retieve information, hmp layer just do a translation from qmp object it got, so almost every hmp interface may have a correlated qmp interface. To make code graceful, snapshot retrieving code in qemu and qemu-img are merged into block.c, and some function name was adjusted to make it tips better. Now it works as:
qemu qemu-img dump_monitor dump_stdout |--------------| | qmp | block v2: Rename and adjusted qmp interface according to comments from Eric. Spelling fix. Information retrieving function in block layer goes to seperated patch. Free qmp object after usage in hmp. Added counterpart in qmp-commands.hx. Better tips in qmp-schema.json. v3: Spelling fix in commit message, patch 03/11. Spelling fix in code, patch 06/11. Add comments that vm-state-size is in bytes, and change size of it in example to a reasonable number, patch 08/11. v4: 02/13: in bdrv_get_filename(), add const to parameter *bs. 03/13: new added, in which the function correct the behavior in info retrieving. 04/13: in bdrv_query_snapshot_infolist(), remove NULL check before call err_setg(), added TODO comments that let block layer function set error instead of this layer to tip better for errors, Split out patch about image info to patch 05/13. 05/13: new splitted, and it checks *bs by calling bdrv_can_read_snapshot() before collect internal snasphot info to avoid *err is set unexpectly now. 06/13: check if error happens after calling bdrv_query_image_info(). 08/13: rename info to image in DeviceImageInfo and make it optional, when device is not inserted it will be empty, added error handling code when met error in calling block layer API. 09/13: distinguish *id and *name in bdrv_find_snapshots(), caller can choose what to search with. id_wellformed() should be called in new snapshot creation interface above this function in the future. 10/13: now this interface have addtional parameter *device, which enable showing internal snapshots on a single device. Also use bdrv_can_read_snapshot() instead of bdrv_can_snapshot() now. 11/13: this function goes to hmp.c so hmp_handler_error is not exported any more, split out patch that switch snapshot info function to patch 12/13. 12/13: new splitted. 13/13: use qmp API instead of directly calling block layer API, now all hmp function have correspond qmp funtion in this serial. v5: 04/13: spelling fix in commit message, better comments and better tips of error, after calling bdrv_snapshot_list(). v6: ==Address Kevin's comments==: 04/14: seperate patch for code moving, 05/14: use strerror() for error tipping after call of bdrv_snapshot_list(), use "switch" instead of "if else" for error checking, replace info_list->value->* by info->*. 06/14: access bs->backing_file directly instead of calling of bdrv_get_backing_filename in collect_image_info. Function switch patch of last version is merged into this patch. 08/14: API change, add optional parameter of "device" and "backing", which allow showing all image info in the backing file chain of block device, add related implemention. 09/14: seperate patch for code moving. 10/14: seperate patch for function change, return what got from bdrv_snapshot_list() instead of -ENOENT. ==Address Eric's comments==: 02/14: return bool instead of int for this new function. 03/14: return bool instead of int for old function bdrv_can_snapshot(). Wenchao Xia (14): 1 qemu-img: remove unused parameter in collect_image_info() 2 block: add bdrv_can_read_snapshot() function 3 block: return bool for bdrv_can_snapshot() 4 block: move collect_snapshots() and collect_image_info() to block.c 5 block: add snapshot info query function bdrv_query_snapshot_infolist() 6 block: add image info query function bdrv_query_image_info() 7 block: rename bdrv_query_info() to bdrv_query_block_info() 8 qmp: add interface query-images. 9 block: move bdrv_snapshot_find() to block.c 10 block: distinguish id and name in bdrv_find_snapshot() 11 qmp: add interface query-snapshots 12 hmp: add function hmp_info_snapshots() 13 hmp: switch snapshot info function to qmp based one 14 hmp: show snapshots on single block device block.c | 355 ++++++++++++++++++++++++++++++++++++++++++++++++- hmp.c | 47 +++++++ hmp.h | 1 + include/block/block.h | 16 ++- monitor.c | 8 +- qapi-schema.json | 54 ++++++++ qemu-img.c | 91 +------------ qmp-commands.hx | 129 ++++++++++++++++++ savevm.c | 94 +------------- 9 files changed, 607 insertions(+), 188 deletions(-)