From patchwork Mon Mar 11 11:23:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 226534 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 A05452C02A2 for ; Mon, 11 Mar 2013 22:31:14 +1100 (EST) Received: from localhost ([::1]:44400 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UF0wh-0006IQ-Nd for incoming@patchwork.ozlabs.org; Mon, 11 Mar 2013 07:31:11 -0400 Received: from eggs.gnu.org ([208.118.235.92]:52923) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UF0ra-0006yA-B4 for qemu-devel@nongnu.org; Mon, 11 Mar 2013 07:25:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UF0rX-0001bP-8d for qemu-devel@nongnu.org; Mon, 11 Mar 2013 07:25:54 -0400 Received: from e28smtp01.in.ibm.com ([122.248.162.1]:35054) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UF0rV-0001ag-Vj for qemu-devel@nongnu.org; Mon, 11 Mar 2013 07:25:51 -0400 Received: from /spool/local by e28smtp01.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 11 Mar 2013 16:52:23 +0530 Received: from d28dlp02.in.ibm.com (9.184.220.127) by e28smtp01.in.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 11 Mar 2013 16:52:21 +0530 Received: from d28relay01.in.ibm.com (d28relay01.in.ibm.com [9.184.220.58]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id CE40C3940023 for ; Mon, 11 Mar 2013 16:55:45 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay01.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2BBPf3o24248506 for ; Mon, 11 Mar 2013 16:55:41 +0530 Received: from d28av02.in.ibm.com (loopback [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2BBPiAA026436 for ; Mon, 11 Mar 2013 22:25:44 +1100 Received: from RH63Wenchao (wenchaox.cn.ibm.com [9.115.122.175] (may be forged)) by d28av02.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r2BBNRVG015564; Mon, 11 Mar 2013 22:25:42 +1100 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Mon, 11 Mar 2013 19:23:14 +0800 Message-Id: <1363000996-13221-13-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1363000996-13221-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363000996-13221-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13031111-4790-0000-0000-00000748F017 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.1 Cc: kwolf@redhat.com, stefanha@gmail.com, armbru@redhat.com, lcapitulino@redhat.com, pbonzini@redhat.com, Wenchao Xia Subject: [Qemu-devel] [PATCH V9 12/14] 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 bdrv_image_info_dump(). Signed-off-by: Wenchao Xia Reviewed-by: Eric Blake --- 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 0cbbb8c..1eb3de1 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -284,3 +284,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 7ff1f98..cc55bda 100644 --- a/include/block/qapi.h +++ b/include/block/qapi.h @@ -24,4 +24,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); } }