From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:50978) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UDU1R-0006t4-Jm for qemu-devel@nongnu.org; Thu, 07 Mar 2013 01:09:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UDU1F-0003ul-Jl for qemu-devel@nongnu.org; Thu, 07 Mar 2013 01:09:45 -0500 Received: from e28smtp02.in.ibm.com ([122.248.162.2]:47548) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UDU1E-0003uT-OC for qemu-devel@nongnu.org; Thu, 07 Mar 2013 01:09:33 -0500 Received: from /spool/local by e28smtp02.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 7 Mar 2013 11:35:45 +0530 Received: from d28relay02.in.ibm.com (d28relay02.in.ibm.com [9.184.220.59]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id 4EE7F1258023 for ; Thu, 7 Mar 2013 11:40:25 +0530 (IST) Received: from d28av03.in.ibm.com (d28av03.in.ibm.com [9.184.220.65]) by d28relay02.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2769N8L32047274 for ; Thu, 7 Mar 2013 11:39:24 +0530 Received: from d28av03.in.ibm.com (loopback [127.0.0.1]) by d28av03.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2769Mbw028174 for ; Thu, 7 Mar 2013 17:09:25 +1100 From: Wenchao Xia Date: Thu, 7 Mar 2013 14:07:05 +0800 Message-Id: <1362636445-7188-1-git-send-email-xiawenc@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH V8 00/20] qmp/hmp interfaces for internal snapshot info List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, aliguori@us.ibm.com, capitulino@redhat.com, stefanha@gmail.com, armbru@redhat.com, pbonzini@redhat.com, Wenchao Xia In the use of snapshot a way to retrieve related info at runtime is needed, so this serial of patches will merge some code for qemu and qemu-img, and add following interfaces for qemu: 1) qmp: query-images, show image info for a block device Example: -> { "execute": "query-images" } <- { "return":[ { "device":"ide0-hd0", "image":{ "filename":"disks/test1.img", "format":"qcow2", "virtual-size":2048000, "snapshots":[ { "id": "1", "name": "snapshot1", "vm-state-size": 0, "date-sec": 10000200, "date-nsec": 12, "vm-clock-sec": 206, "vm-clock-nsec": 30 } ] } } ] } 2) qmp: query-snapshots, show avaiable vm snapshot info which can be used in loadvm. Example: -> { "execute": "query-snapshots" } <- { "return":[ { "id": "1", "name": "snapshot1", "vm-state-size": 0, "date-sec": 10000200, "date-nsec": 12, "vm-clock-sec": 206, "vm-clock-nsec": 30 } ] } 3) hmp: info images, show what got in qmp query-images in monitor These patches follows the rule that use qmp to retieve information, hmp layer just do 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 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(). V7: ==Address Eric's comments==: 6/14: discard of static function bdrv_get_filename(). 8/14: better doc and comments, trailing '.' is removed. 11/14: QMP API change: removed parameter *device, it only returns VM snapshot now. Block device's internal snapshot info can be accessed by query-images. 12/14: related caller code change for query-snapshots. Seperate internal static function for VM snapshot info. 14/14: HMP API change: added support of query internal snapshots of one image in the backing file chain of a block device. use query-images instead of query-snapshots. Seperate internal static mirror function for block snapshot info. v8: General change: discard bdrv_can_read_snapshot() for that return value can tip error. add block/snapshot.c and block/qapi.c and function are moved there. Patches 17-20 are for clean and moved to tail. Address Markus's comments: 3/20: function was moved to block/snapshot.c instead of block.c. 7/20: better commit message. Remove comments for the return value of bdrv_snapshot_list(), remove period suffix in error message, better error message, remove the filter callback of it. remove comments for *bs must be open. It return negative value for error check. 8/20: add a flag parameter to filter out inconsistent vm snapshots instead of a call back function. 9/20: function reorganized to return negative error value, and qmp object will be got only on success. 10/20: better documents and remove suffix period. 11/20: better documents and remove suffix period, explain optional member in qmp-commands.hx. Address Stefan's comments: 6/20: add prefix 'bdrv_' to the moved functions. 7/20: remove the filter call back function. remove bdrv_can_reand_snapshot() call in qemu-img. It return negative value for error check. 8/20: add a flag parameter to filter out inconsistent vm snapshots instead of a call back function. 9/20: small trivial static function was removed. Address Eric's comments: 6/20: add prefix 'bdrv_' to the moved functions. Added message in commit about the patch's purpose. Other: 14/20 - 16/20: new interface info image which show all image info including internal snapshots for each device, share the dump code with qemu-img. 18/20: new clean up patch for block/snapshot.c. 19/20: new clean up patch for block/qapi.c. Wenchao Xia (20): 1 build: add block/snapshot.c 2 build: add block/qapi.c 3 block: move bdrv_snapshot_find() to block/snapshot.c 4 block: distinguish id and name in bdrv_find_snapshot() 5 qemu-img: remove unused parameter in collect_image_info() 6 block: move collect_snapshots() and collect_image_info() to block/qapi.c 7 block: add snapshot info query function bdrv_query_snapshot_info_list() 8 block: add filter for vm snapshot in bdrv_query_snapshot_info_list() 9 block: add image info query function bdrv_query_image_info() 10 qmp: add interface query-snapshots 11 qmp: add interface query-images 12 hmp: add function hmp_info_snapshots() 13 hmp: switch snapshot info function to qmp based one 14 block: move dump_human_image_info() to block/qapi.c 15 block: dump to buffer for bdrv_image_info_dump() 16 hmp: add command info images 17 block: return bool for bdrv_can_snapshot() 18 block: move snapshot related functions to block/snapshot.c 19 block: move bdrv_snapshot_dump() to block/qapi.c 20 block: rename bdrv_query_info() to bdrv_query_block_info() block.c | 142 +--------------- block/Makefile.objs | 1 + block/qapi.c | 416 +++++++++++++++++++++++++++++++++++++++++++++ block/snapshot.c | 181 ++++++++++++++++++++ hmp.c | 80 +++++++++ hmp.h | 2 + include/block/block.h | 26 +--- include/block/block_int.h | 1 + include/block/qapi.h | 17 ++ include/block/snapshot.h | 31 ++++ monitor.c | 9 +- qapi-schema.json | 47 +++++ qemu-img.c | 162 +----------------- qmp-commands.hx | 141 +++++++++++++++ savevm.c | 95 +---------- 15 files changed, 943 insertions(+), 408 deletions(-) create mode 100644 block/qapi.c create mode 100644 block/snapshot.c create mode 100644 include/block/qapi.h create mode 100644 include/block/snapshot.h