From patchwork Thu Jan 17 07:40:08 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 213161 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 A1FCB2C0091 for ; Thu, 17 Jan 2013 19:18:30 +1100 (EST) Received: from localhost ([::1]:37259 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tvk82-0006k9-LZ for incoming@patchwork.ozlabs.org; Thu, 17 Jan 2013 02:43:14 -0500 Received: from eggs.gnu.org ([208.118.235.92]:58074) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tvk7e-0006AN-HS for qemu-devel@nongnu.org; Thu, 17 Jan 2013 02:42:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tvk7d-00020X-Fg for qemu-devel@nongnu.org; Thu, 17 Jan 2013 02:42:50 -0500 Received: from e23smtp04.au.ibm.com ([202.81.31.146]:57118) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tvk7c-000208-Iz for qemu-devel@nongnu.org; Thu, 17 Jan 2013 02:42:49 -0500 Received: from /spool/local by e23smtp04.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 17 Jan 2013 17:35:02 +1000 Received: from d23dlp03.au.ibm.com (202.81.31.214) by e23smtp04.au.ibm.com (202.81.31.210) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 17 Jan 2013 17:35:01 +1000 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [9.190.235.21]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id 37591357804D for ; Thu, 17 Jan 2013 18:42:44 +1100 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r0H7gh4W63897766 for ; Thu, 17 Jan 2013 18:42:43 +1100 Received: from d23av01.au.ibm.com (loopback [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r0H7gh1g012562 for ; Thu, 17 Jan 2013 18:42:44 +1100 Received: from RH63Wenchao (wenchaox.cn.ibm.com [9.115.122.253]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r0H7e021007864; Thu, 17 Jan 2013 18:42:41 +1100 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Thu, 17 Jan 2013 15:40:08 +0800 Message-Id: <1358408410-22187-12-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1358408410-22187-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1358408410-22187-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13011707-9264-0000-0000-00000302EC92 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.146 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 V4 11/13] hmp: add function hmp_info_snapshots() 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 function will simply call qmp interface qmp_query_snapshots() added in last commit and then dump information in monitor console. Now snapshot info retrieving code in qemu and qemu-img are merged by calling same block layer function, and then they just translate the qmp object to strings in stdout or monitor console. Note: This patch need previous hmp extention patch which enable info sub command take qdict * as paramter. Signed-off-by: Wenchao Xia --- hmp.c | 42 ++++++++++++++++++++++++++++++++++++++++++ hmp.h | 1 + 2 files changed, 43 insertions(+), 0 deletions(-) diff --git a/hmp.c b/hmp.c index c7b6ba0..1e8f9eb 100644 --- a/hmp.c +++ b/hmp.c @@ -629,6 +629,48 @@ void hmp_info_block_jobs(Monitor *mon, const QDict *qdict) } } +/* assume list is valid */ +static void monitor_dump_snapshotinfolist(Monitor *mon, SnapshotInfoList *list) +{ + SnapshotInfoList *elem; + char buf[256]; + + monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL)); + + for (elem = list; elem; elem = elem->next) { + QEMUSnapshotInfo sn = { + .vm_state_size = elem->value->vm_state_size, + .date_sec = elem->value->date_sec, + .date_nsec = elem->value->date_nsec, + .vm_clock_nsec = elem->value->vm_clock_sec * 1000000000ULL + + elem->value->vm_clock_nsec, + }; + pstrcpy(sn.id_str, sizeof(sn.id_str), elem->value->id); + pstrcpy(sn.name, sizeof(sn.name), elem->value->name); + monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf, sizeof(buf), &sn)); + } +} + +void hmp_info_snapshots(Monitor *mon, const QDict *qdict) +{ + Error *err = NULL; + SnapshotInfoList *list; + + list = qmp_query_snapshots(false, NULL, &err); + if (error_is_set(&err)) { + hmp_handle_error(mon, &err); + return; + } + + if (list == NULL) { + monitor_printf(mon, "There is no suitable snapshot available\n"); + return; + } + + monitor_dump_snapshotinfolist(mon, list); + qapi_free_SnapshotInfoList(list); +} + void hmp_quit(Monitor *mon, const QDict *qdict) { monitor_suspend(mon); diff --git a/hmp.h b/hmp.h index 44be683..b020a7b 100644 --- a/hmp.h +++ b/hmp.h @@ -36,6 +36,7 @@ void hmp_info_spice(Monitor *mon, const QDict *qdict); void hmp_info_balloon(Monitor *mon, const QDict *qdict); void hmp_info_pci(Monitor *mon, const QDict *qdict); void hmp_info_block_jobs(Monitor *mon, const QDict *qdict); +void hmp_info_snapshots(Monitor *mon, const QDict *qdict); void hmp_quit(Monitor *mon, const QDict *qdict); void hmp_stop(Monitor *mon, const QDict *qdict); void hmp_system_reset(Monitor *mon, const QDict *qdict);