From patchwork Wed Dec 19 10:17:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 207306 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 B58B42C0094 for ; Wed, 19 Dec 2012 21:22:35 +1100 (EST) Received: from localhost ([::1]:41363 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TlGnJ-0006Ki-SG for incoming@patchwork.ozlabs.org; Wed, 19 Dec 2012 05:22:33 -0500 Received: from eggs.gnu.org ([208.118.235.92]:41473) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TlGn9-0006Iz-EO for qemu-devel@nongnu.org; Wed, 19 Dec 2012 05:22:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TlGn8-0001Ci-2R for qemu-devel@nongnu.org; Wed, 19 Dec 2012 05:22:23 -0500 Received: from e23smtp05.au.ibm.com ([202.81.31.147]:47058) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TlGn7-0001CK-Fr for qemu-devel@nongnu.org; Wed, 19 Dec 2012 05:22:22 -0500 Received: from /spool/local by e23smtp05.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 19 Dec 2012 20:19:29 +1000 Received: from d23dlp02.au.ibm.com (202.81.31.213) by e23smtp05.au.ibm.com (202.81.31.211) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 19 Dec 2012 20:19:28 +1000 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [9.190.234.120]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id 738152BB004A for ; Wed, 19 Dec 2012 21:22:13 +1100 (EST) Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id qBJAB8uW66519170 for ; Wed, 19 Dec 2012 21:11:08 +1100 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id qBJAMCis009676 for ; Wed, 19 Dec 2012 21:22:13 +1100 Received: from RedHat62GAWSWenchao ([9.77.178.138]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id qBJAHLkI003655; Wed, 19 Dec 2012 21:22:00 +1100 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Wed, 19 Dec 2012 18:17:10 +0800 Message-Id: <1355912230-25132-4-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1355912230-25132-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1355912230-25132-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12121910-1396-0000-0000-00000251D5A6 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.147 Cc: kwolf@redhat.com, aliguori@us.ibm.com, stefanha@gmail.com, armbru@redhat.com, lcapitulino@redhat.com, pbonzini@redhat.com, Wenchao Xia Subject: [Qemu-devel] [PATCH 3/3] HMP: show internal snapshots on a single 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 add an option to show snapshots on a single block device, so some snapshot do not exist on other block device could be shown. Signed-off-by: Wenchao Xia --- monitor.c | 6 +++--- savevm.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/monitor.c b/monitor.c index ce0e74d..b019618 100644 --- a/monitor.c +++ b/monitor.c @@ -2613,9 +2613,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 fa32171..438eb24 100644 --- a/savevm.c +++ b/savevm.c @@ -2358,7 +2358,7 @@ void do_delvm(Monitor *mon, const QDict *qdict) } } -void do_info_snapshots(Monitor *mon, const QDict *qdict) +static void do_info_snapshots_vm(Monitor *mon) { BlockDriverState *bs, *bs1; QEMUSnapshotInfo *sn_tab, *sn, s, *sn_info = &s; @@ -2422,6 +2422,59 @@ void do_info_snapshots(Monitor *mon, const QDict *qdict) } +static void do_info_snapshots_blk(Monitor *mon, const char *device) +{ + BlockDriverState *bs; + QEMUSnapshotInfo *sn_tab, *sn; + int nb_sns, i; + char buf[256]; + + /* 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 ; + } + + nb_sns = bdrv_snapshot_list(bs, &sn_tab); + if (nb_sns < 0) { + monitor_printf(mon, "Device %s bdrv_snapshot_list: error %d\n", + device, nb_sns); + return; + } + + if (nb_sns == 0) { + monitor_printf(mon, "There is no snapshot available.\n"); + return; + } + + monitor_printf(mon, "Device %s:\n", device); + monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL)); + for (i = 0; i < nb_sns; i++) { + sn = &sn_tab[i]; + monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf, sizeof(buf), sn)); + } + g_free(sn_tab); + return; +} + +void do_info_snapshots(Monitor *mon, const QDict *qdict) +{ + /* Todo, there should be a layer rebuild qdict before enter this func. */ + 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) { qemu_ram_set_idstr(memory_region_get_ram_addr(mr) & TARGET_PAGE_MASK,