From patchwork Wed Jan 9 05:12:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 210625 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BA1E22C00DB for ; Wed, 9 Jan 2013 16:51:48 +1100 (EST) Received: from localhost ([::1]:51714 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsoZn-0000cz-1K for incoming@patchwork.ozlabs.org; Wed, 09 Jan 2013 00:51:47 -0500 Received: from eggs.gnu.org ([208.118.235.92]:55421) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tso0L-0007j7-Nl for qemu-devel@nongnu.org; Wed, 09 Jan 2013 00:15:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tso0K-0000Dz-2g for qemu-devel@nongnu.org; Wed, 09 Jan 2013 00:15:09 -0500 Received: from e28smtp08.in.ibm.com ([122.248.162.8]:35774) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tso0J-0000CB-FJ for qemu-devel@nongnu.org; Wed, 09 Jan 2013 00:15:08 -0500 Received: from /spool/local by e28smtp08.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 9 Jan 2013 10:43:27 +0530 Received: from d28dlp01.in.ibm.com (9.184.220.126) by e28smtp08.in.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 9 Jan 2013 10:43:24 +0530 Received: from d28relay03.in.ibm.com (d28relay03.in.ibm.com [9.184.220.60]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id 58495E004B for ; Wed, 9 Jan 2013 10:45:15 +0530 (IST) Received: from d28av04.in.ibm.com (d28av04.in.ibm.com [9.184.220.66]) by d28relay03.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r095ExHE45875324 for ; Wed, 9 Jan 2013 10:44:59 +0530 Received: from d28av04.in.ibm.com (loopback [127.0.0.1]) by d28av04.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r095F1Z3021696 for ; Wed, 9 Jan 2013 16:15:02 +1100 Received: from RH63Wenchao ([9.77.181.189]) by d28av04.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r095Ch6F014023; Wed, 9 Jan 2013 16:14:58 +1100 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Wed, 9 Jan 2013 13:12:30 +0800 Message-Id: <1357708350-9917-12-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1357708350-9917-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1357708350-9917-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13010905-2000-0000-0000-00000A875F4F X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.8 Cc: aliguori@us.ibm.com, phrdina@redhat.com, stefanha@gmail.com, armbru@redhat.com, lcapitulino@redhat.com, pbonzini@redhat.com, Wenchao Xia Subject: [Qemu-devel] [PATCH V2 11/11] hmp: show snapshot on single block device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch use block layer API to qmp snapshot info on a block device, then use the same code dumping vm snapshot info, to print in monitor. Note: This patch need previous hmp extention patch which enable info sub command take qdict * as paramter. v2: free SnapshotInfoList after usage. Signed-off-by: Wenchao Xia --- monitor.c | 6 +++--- savevm.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/monitor.c b/monitor.c index e1bcaa2..3dfdd4d 100644 --- a/monitor.c +++ b/monitor.c @@ -2580,9 +2580,9 @@ static mon_cmd_t info_cmds[] = { }, { .name = "snapshots", - .args_type = "", - .params = "", - .help = "show the currently saved VM snapshots", + .args_type = "device:B?", + .params = "[device]", + .help = "show snapshots of whole vm or a single device", .mhandler.info = do_info_snapshots, }, { diff --git a/savevm.c b/savevm.c index cabdcb6..cd474e9 100644 --- a/savevm.c +++ b/savevm.c @@ -2354,9 +2354,50 @@ static void do_info_snapshots_vm(Monitor *mon) return; } +static void do_info_snapshots_blk(Monitor *mon, const char *device) +{ + Error *err = NULL; + SnapshotInfoList *list; + BlockDriverState *bs; + + /* find the target bs */ + bs = bdrv_find(device); + if (!bs) { + monitor_printf(mon, "Device '%s' not found.\n", device); + return ; + } + + if (!bdrv_can_snapshot(bs)) { + monitor_printf(mon, "Device '%s' can't have snapshot.\n", device); + return ; + } + + list = bdrv_query_snapshot_infolist(bs, NULL, NULL, &err); + if (error_is_set(&err)) { + hmp_handle_error(mon, &err); + return; + } + + if (list == NULL) { + monitor_printf(mon, "There is no snapshot available.\n"); + return; + } + + monitor_printf(mon, "Device '%s':\n", device); + monitor_dump_snapshotinfolist(mon, list); + qapi_free_SnapshotInfoList(list); + return; +} + void do_info_snapshots(Monitor *mon, const QDict *qdict) { - do_info_snapshots_vm(mon); + const char *device = qdict_get_try_str(qdict, "device"); + if (!device) { + do_info_snapshots_vm(mon); + } else { + do_info_snapshots_blk(mon, device); + } + return; } void vmstate_register_ram(MemoryRegion *mr, DeviceState *dev)