From patchwork Thu Mar 7 06:07:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 225741 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 789472C0371 for ; Thu, 7 Mar 2013 17:17:06 +1100 (EST) Received: from localhost ([::1]:59669 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UDU8W-000267-KM for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2013 01:17:04 -0500 Received: from eggs.gnu.org ([208.118.235.92]:51252) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UDU28-000865-NL for qemu-devel@nongnu.org; Thu, 07 Mar 2013 01:10:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UDU27-0004dZ-81 for qemu-devel@nongnu.org; Thu, 07 Mar 2013 01:10:28 -0500 Received: from e28smtp03.in.ibm.com ([122.248.162.3]:36968) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UDU26-0004dM-Mb for qemu-devel@nongnu.org; Thu, 07 Mar 2013 01:10:27 -0500 Received: from /spool/local by e28smtp03.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 7 Mar 2013 11:37:34 +0530 Received: from d28dlp01.in.ibm.com (9.184.220.126) by e28smtp03.in.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 7 Mar 2013 11:37:32 +0530 Received: from d28relay04.in.ibm.com (d28relay04.in.ibm.com [9.184.220.61]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id 232D1E004A for ; Thu, 7 Mar 2013 11:41:36 +0530 (IST) Received: from d28av03.in.ibm.com (d28av03.in.ibm.com [9.184.220.65]) by d28relay04.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r276AEW230539986 for ; Thu, 7 Mar 2013 11:40:15 +0530 Received: from d28av03.in.ibm.com (loopback [127.0.0.1]) by d28av03.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r276AD54031865 for ; Thu, 7 Mar 2013 17:10:15 +1100 Received: from RH63Wenchao (wenchaox.cn.ibm.com [9.115.122.208]) by d28av03.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r2767TJt021188; Thu, 7 Mar 2013 17:10:12 +1100 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2013 14:07:19 +0800 Message-Id: <1362636445-7188-15-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1362636445-7188-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1362636445-7188-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13030706-3864-0000-0000-0000072242E6 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.3 Cc: kwolf@redhat.com, aliguori@us.ibm.com, capitulino@redhat.com, stefanha@gmail.com, armbru@redhat.com, pbonzini@redhat.com, Wenchao Xia Subject: [Qemu-devel] [PATCH V8 14/20] block: move dump_human_image_info() to block/qapi.c 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 is needed later in hmp command, it is also renamed to for bdrv_image_info_dump(). Signed-off-by: Wenchao Xia --- block/qapi.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ include/block/qapi.h | 1 + qemu-img.c | 69 +------------------------------------------------- 3 files changed, 69 insertions(+), 68 deletions(-) diff --git a/block/qapi.c b/block/qapi.c index a67d380..aef1397 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -285,3 +285,70 @@ DeviceImageInfoList *qmp_query_images(bool has_device, qapi_free_DeviceImageInfoList(head); return NULL; } + +void bdrv_image_info_dump(ImageInfo *info) +{ + char size_buf[128], dsize_buf[128]; + if (!info->has_actual_size) { + snprintf(dsize_buf, sizeof(dsize_buf), "unavailable"); + } else { + get_human_readable_size(dsize_buf, sizeof(dsize_buf), + info->actual_size); + } + get_human_readable_size(size_buf, sizeof(size_buf), info->virtual_size); + printf("image: %s\n" + "file format: %s\n" + "virtual size: %s (%" PRId64 " bytes)\n" + "disk size: %s\n", + info->filename, info->format, size_buf, + info->virtual_size, + dsize_buf); + + if (info->has_encrypted && info->encrypted) { + printf("encrypted: yes\n"); + } + + if (info->has_cluster_size) { + printf("cluster_size: %" PRId64 "\n", info->cluster_size); + } + + if (info->has_dirty_flag && info->dirty_flag) { + printf("cleanly shut down: no\n"); + } + + if (info->has_backing_filename) { + printf("backing file: %s", info->backing_filename); + if (info->has_full_backing_filename) { + printf(" (actual path: %s)", info->full_backing_filename); + } + putchar('\n'); + if (info->has_backing_filename_format) { + printf("backing file format: %s\n", info->backing_filename_format); + } + } + + if (info->has_snapshots) { + SnapshotInfoList *elem; + char buf[256]; + + printf("Snapshot list:\n"); + printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL)); + + /* Ideally bdrv_snapshot_dump() would operate on SnapshotInfoList but + * we convert to the block layer's native QEMUSnapshotInfo for now. + */ + for (elem = info->snapshots; 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); + printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), &sn)); + } + } +} diff --git a/include/block/qapi.h b/include/block/qapi.h index 675df0c..76b9e3f 100644 --- a/include/block/qapi.h +++ b/include/block/qapi.h @@ -11,4 +11,5 @@ int bdrv_query_snapshot_info_list(BlockDriverState *bs, int bdrv_query_image_info(BlockDriverState *bs, ImageInfo **p_info, Error **errp); +void bdrv_image_info_dump(ImageInfo *info); #endif diff --git a/qemu-img.c b/qemu-img.c index 59d900a..e1d6bac 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1606,73 +1606,6 @@ static void dump_json_image_info(ImageInfo *info) QDECREF(str); } -static void dump_human_image_info(ImageInfo *info) -{ - char size_buf[128], dsize_buf[128]; - if (!info->has_actual_size) { - snprintf(dsize_buf, sizeof(dsize_buf), "unavailable"); - } else { - get_human_readable_size(dsize_buf, sizeof(dsize_buf), - info->actual_size); - } - get_human_readable_size(size_buf, sizeof(size_buf), info->virtual_size); - printf("image: %s\n" - "file format: %s\n" - "virtual size: %s (%" PRId64 " bytes)\n" - "disk size: %s\n", - info->filename, info->format, size_buf, - info->virtual_size, - dsize_buf); - - if (info->has_encrypted && info->encrypted) { - printf("encrypted: yes\n"); - } - - if (info->has_cluster_size) { - printf("cluster_size: %" PRId64 "\n", info->cluster_size); - } - - if (info->has_dirty_flag && info->dirty_flag) { - printf("cleanly shut down: no\n"); - } - - if (info->has_backing_filename) { - printf("backing file: %s", info->backing_filename); - if (info->has_full_backing_filename) { - printf(" (actual path: %s)", info->full_backing_filename); - } - putchar('\n'); - if (info->has_backing_filename_format) { - printf("backing file format: %s\n", info->backing_filename_format); - } - } - - if (info->has_snapshots) { - SnapshotInfoList *elem; - char buf[256]; - - printf("Snapshot list:\n"); - printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL)); - - /* Ideally bdrv_snapshot_dump() would operate on SnapshotInfoList but - * we convert to the block layer's native QEMUSnapshotInfo for now. - */ - for (elem = info->snapshots; 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); - printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), &sn)); - } - } -} - static void dump_human_image_info_list(ImageInfoList *list) { ImageInfoList *elem; @@ -1684,7 +1617,7 @@ static void dump_human_image_info_list(ImageInfoList *list) } delim = true; - dump_human_image_info(elem->value); + bdrv_image_info_dump(elem->value); } }