From patchwork Sat Dec 29 08:45:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 208627 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 1E3E62C00DC for ; Sat, 29 Dec 2012 19:49:27 +1100 (EST) Received: from localhost ([::1]:60958 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tos6f-0007xI-Bc for incoming@patchwork.ozlabs.org; Sat, 29 Dec 2012 03:49:25 -0500 Received: from eggs.gnu.org ([208.118.235.92]:59169) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tos5s-00069s-IG for qemu-devel@nongnu.org; Sat, 29 Dec 2012 03:48:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tos5r-0005SH-D4 for qemu-devel@nongnu.org; Sat, 29 Dec 2012 03:48:36 -0500 Received: from e28smtp07.in.ibm.com ([122.248.162.7]:58854) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tos5q-0005S6-Oq for qemu-devel@nongnu.org; Sat, 29 Dec 2012 03:48:35 -0500 Received: from /spool/local by e28smtp07.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sat, 29 Dec 2012 14:17:34 +0530 Received: from d28dlp02.in.ibm.com (9.184.220.127) by e28smtp07.in.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sat, 29 Dec 2012 14:17:31 +0530 Received: from d28relay01.in.ibm.com (d28relay01.in.ibm.com [9.184.220.58]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id ED7A4394004C for ; Sat, 29 Dec 2012 14:18:29 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay01.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id qBT8mSEO40894608 for ; Sat, 29 Dec 2012 14:18:28 +0530 Received: from d28av02.in.ibm.com (loopback [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id qBT8mT8K022579 for ; Sat, 29 Dec 2012 19:48:29 +1100 Received: from RedHat62GAWSWenchao ([9.125.29.43]) by d28av02.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id qBT8jCUn014358; Sat, 29 Dec 2012 19:48:26 +1100 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Sat, 29 Dec 2012 16:45:25 +0800 Message-Id: <1356770725-4804-12-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1356770725-4804-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1356770725-4804-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12122908-8878-0000-0000-000005544C04 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.7 Cc: kwolf@redhat.com, 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 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. Signed-off-by: Wenchao Xia --- monitor.c | 6 +++--- savevm.c | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 44 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 5f29316..413328a 100644 --- a/savevm.c +++ b/savevm.c @@ -2391,9 +2391,49 @@ 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); + 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)