Received: from eggs.gnu.org ([208.118.235.92]:58784) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tm3Gc-0000nS-Ig for qemu-devel@nongnu.org; Fri, 21 Dec 2012 09:08:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tm3GW-0007xo-5s for qemu-devel@nongnu.org; Fri, 21 Dec 2012 09:08:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39934) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tm3GV-0007xa-VC for qemu-devel@nongnu.org; Fri, 21 Dec 2012 09:07:56 -0500 From: Markus Armbruster References: <1355912230-25132-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1355912230-25132-4-git-send-email-xiawenc@linux.vnet.ibm.com> Date: Fri, 21 Dec 2012 15:07:51 +0100 In-Reply-To: <1355912230-25132-4-git-send-email-xiawenc@linux.vnet.ibm.com> (Wenchao Xia's message of "Wed, 19 Dec 2012 18:17:10 +0800") Message-ID: <87mwx733d4.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH 3/3] HMP: show internal snapshots on a single device List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Wenchao Xia Cc: kwolf@redhat.com, aliguori@us.ibm.com, stefanha@gmail.com, qemu-devel@nongnu.org, lcapitulino@redhat.com, pbonzini@redhat.com Wenchao Xia writes: > 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 ; > + } Rest of the function is is essentially code copied from do_info_snapshots_vm(). Could it be factored out? > + > + 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. */ I'm not sure I get this comment. We usually capitalize TODO for easy grepping. > + 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,