From patchwork Tue Apr 2 11:47:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 232983 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 B789D2C0156 for ; Tue, 2 Apr 2013 22:56:22 +1100 (EST) Received: from localhost ([::1]:36936 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMzp6-0003Qw-H9 for incoming@patchwork.ozlabs.org; Tue, 02 Apr 2013 07:56:20 -0400 Received: from eggs.gnu.org ([208.118.235.92]:49627) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMzji-0003rw-Uh for qemu-devel@nongnu.org; Tue, 02 Apr 2013 07:50:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UMzjg-000483-Rl for qemu-devel@nongnu.org; Tue, 02 Apr 2013 07:50:46 -0400 Received: from e28smtp09.in.ibm.com ([122.248.162.9]:52519) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMzjf-00046Z-Sj for qemu-devel@nongnu.org; Tue, 02 Apr 2013 07:50:44 -0400 Received: from /spool/local by e28smtp09.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 2 Apr 2013 17:17:54 +0530 Received: from d28dlp01.in.ibm.com (9.184.220.126) by e28smtp09.in.ibm.com (192.168.1.139) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 2 Apr 2013 17:17:29 +0530 Received: from d28relay01.in.ibm.com (d28relay01.in.ibm.com [9.184.220.58]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id 70277E0055 for ; Tue, 2 Apr 2013 17:21:58 +0530 (IST) Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay01.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r32BoBGR64946414 for ; Tue, 2 Apr 2013 17:20:11 +0530 Received: from d28av01.in.ibm.com (loopback [127.0.0.1]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r32BoFAF004539 for ; Tue, 2 Apr 2013 11:50:16 GMT Received: from RH63Wenchao (wenchaox.cn.ibm.com [9.115.122.29]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r32BlY3F025943; Tue, 2 Apr 2013 11:50:14 GMT From: Wenchao Xia To: qemu-devel@nongnu.org Date: Tue, 2 Apr 2013 19:47:27 +0800 Message-Id: <1364903250-10429-15-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1364903250-10429-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1364903250-10429-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13040211-2674-0000-0000-000008718F0A X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.9 Cc: kwolf@redhat.com, stefanha@gmail.com, armbru@redhat.com, lcapitulino@redhat.com, pbonzini@redhat.com, Wenchao Xia Subject: [Qemu-devel] [PATCH V11 14/17] 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. To get snapshot info, Now qemu and qemu-img both call block layer function bdrv_query_snapshot_info_list() in their calling path, and then they just translate the qmp object got to strings in stdout or monitor console. Signed-off-by: Wenchao Xia --- hmp.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ hmp.h | 1 + 2 files changed, 49 insertions(+), 0 deletions(-) diff --git a/hmp.c b/hmp.c index dbe9b90..89e1aaf 100644 --- a/hmp.c +++ b/hmp.c @@ -22,6 +22,7 @@ #include "qemu/sockets.h" #include "monitor/monitor.h" #include "ui/console.h" +#include "block/qapi.h" static void hmp_handle_error(Monitor *mon, Error **errp) { @@ -653,6 +654,53 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict) qapi_free_TPMInfoList(info_list); } +/* assume list is valid */ +static void monitor_dump_snapshotinfolist(Monitor *mon, SnapshotInfoList *list) +{ + SnapshotInfoList *elem; + GString *buf = g_string_sized_new(1024); + + bdrv_snapshot_dump(buf, NULL); + g_string_append_printf(buf, "\n"); + + 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); + bdrv_snapshot_dump(buf, &sn); + g_string_append_printf(buf, "\n"); + } + + monitor_printf(mon, "%s", buf->str); + g_string_free(buf, true); +} + +void hmp_info_snapshots(Monitor *mon, const QDict *qdict) +{ + Error *err = NULL; + SnapshotInfoList *list; + + list = qmp_query_snapshots(&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 80e8b41..1172c47 100644 --- a/hmp.h +++ b/hmp.h @@ -37,6 +37,7 @@ 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_tpm(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);