From patchwork Tue Feb 26 10:40:28 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 223195 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 B06282C0324 for ; Tue, 26 Feb 2013 21:44:43 +1100 (EST) Received: from localhost ([::1]:40094 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAI1Z-0006yq-RT for incoming@patchwork.ozlabs.org; Tue, 26 Feb 2013 05:44:41 -0500 Received: from eggs.gnu.org ([208.118.235.92]:55085) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAI0a-0005bY-9U for qemu-devel@nongnu.org; Tue, 26 Feb 2013 05:43:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UAI0Y-0003v4-Ti for qemu-devel@nongnu.org; Tue, 26 Feb 2013 05:43:40 -0500 Received: from e23smtp06.au.ibm.com ([202.81.31.148]:36178) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAI0Y-0003uX-6U for qemu-devel@nongnu.org; Tue, 26 Feb 2013 05:43:38 -0500 Received: from /spool/local by e23smtp06.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 26 Feb 2013 20:38:53 +1000 Received: from d23dlp02.au.ibm.com (202.81.31.213) by e23smtp06.au.ibm.com (202.81.31.212) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 26 Feb 2013 20:38:52 +1000 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [9.190.234.120]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id BC7C62BB0050 for ; Tue, 26 Feb 2013 21:43:34 +1100 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r1QAV72W6816120 for ; Tue, 26 Feb 2013 21:31:07 +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 r1QAhYXW016630 for ; Tue, 26 Feb 2013 21:43:34 +1100 Received: from RH63Wenchao (wenchaox.cn.ibm.com [9.115.122.152]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r1QAeKOJ012693; Tue, 26 Feb 2013 21:43:32 +1100 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Tue, 26 Feb 2013 18:40:28 +0800 Message-Id: <1361875228-15769-15-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1361875228-15769-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1361875228-15769-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13022610-7014-0000-0000-000002A40164 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.148 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 V7 14/14] hmp: show snapshots 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 added the support of showing internal snapshots on an image in the backing chain of a block device in hmp layer, by calling a qmp function. Signed-off-by: Wenchao Xia --- hmp.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- monitor.c | 6 ++-- 2 files changed, 83 insertions(+), 4 deletions(-) diff --git a/hmp.c b/hmp.c index 5e68b2f..ffa92ff 100644 --- a/hmp.c +++ b/hmp.c @@ -629,6 +629,73 @@ static void monitor_dump_snapshotinfolist(Monitor *mon, SnapshotInfoList *list) } } +/* Find the ImageInfo with correct image_name. If image_name = NULL, then + return the top one in the chain. */ +static ImageInfo *find_image_info(const DeviceImageInfoList *device_image_list, + const char *image_name) +{ + ImageInfo *image_info; + + /* return top one */ + if (!image_name) { + if (device_image_list->value->has_image) { + return device_image_list->value->image; + } else { + return NULL; + } + } + + /* search the chain */ + while (device_image_list) { + if (device_image_list->value->has_image) { + image_info = device_image_list->value->image; + if (!strcmp(image_info->filename, image_name)) { + return image_info; + } + } + device_image_list = device_image_list->next; + } + return NULL; +} + +static void hmp_info_snapshots_device(Monitor *mon, + const char *device_name, + const char *image_name) +{ + Error *err = NULL; + SnapshotInfoList *list; + + DeviceImageInfoList *device_image_list = qmp_query_images(true, + device_name, true, true, &err); + if (error_is_set(&err)) { + hmp_handle_error(mon, &err); + return; + } + if (!device_image_list) { + monitor_printf(mon, "Device '%s' can't get image info list.\n", + device_name); + return; + } + + ImageInfo *image_info = find_image_info(device_image_list, image_name); + if (image_info) { + if (image_info->has_snapshots) { + list = image_info->snapshots; + monitor_printf(mon, "Device '%s', Image name '%s':\n", + device_name, image_info->filename); + monitor_dump_snapshotinfolist(mon, list); + } else { + monitor_printf(mon, "Device '%s' have no valid " + "internal snapshot.\n", + device_name); + } + } else { + monitor_printf(mon, "Device '%s' have no correspond image now.\n", + device_name); + } + qapi_free_DeviceImageInfoList(device_image_list); +} + static void hmp_info_snapshots_vm(Monitor *mon) { Error *err = NULL; @@ -651,7 +718,19 @@ static void hmp_info_snapshots_vm(Monitor *mon) void hmp_info_snapshots(Monitor *mon, const QDict *qdict) { - hmp_info_snapshots_vm(mon); + const char *device_name = qdict_get_try_str(qdict, "device"); + const char *image_name = qdict_get_try_str(qdict, "image"); + + if (device_name) { + hmp_info_snapshots_device(mon, device_name, image_name); + } else { + if (image_name) { + monitor_printf(mon, "Parameter [image] is valid only when " + "device is specified.\n"); + return; + } + hmp_info_snapshots_vm(mon); + } } void hmp_quit(Monitor *mon, const QDict *qdict) diff --git a/monitor.c b/monitor.c index 5112375..1dca36f 100644 --- a/monitor.c +++ b/monitor.c @@ -2591,9 +2591,9 @@ static mon_cmd_t info_cmds[] = { }, { .name = "snapshots", - .args_type = "", - .params = "", - .help = "show the currently saved VM snapshots", + .args_type = "device:O?", + .params = "[device=str] [,image=str]", + .help = "show snapshots of whole vm or a single device", .mhandler.cmd = hmp_info_snapshots, }, {