From patchwork Tue May 30 10:48:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 768545 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wcVjw709pz9ryr for ; Tue, 30 May 2017 20:49:56 +1000 (AEST) Received: from localhost ([::1]:52857 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFeio-0004kf-HV for incoming@patchwork.ozlabs.org; Tue, 30 May 2017 06:49:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33847) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFei7-0004hm-Ih for qemu-devel@nongnu.org; Tue, 30 May 2017 06:49:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFei6-0005Bh-Ll for qemu-devel@nongnu.org; Tue, 30 May 2017 06:49:11 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:6389 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFei6-0005Am-Ar for qemu-devel@nongnu.org; Tue, 30 May 2017 06:49:10 -0400 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v4UAmvVa029109; Tue, 30 May 2017 13:48:58 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 30 May 2017 13:48:57 +0300 Message-Id: <20170530104857.70083-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170530104857.70083-1-vsementsov@virtuozzo.com> References: <20170530104857.70083-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x [fuzzy] X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 4/4] qemu-img check: improve dump_human_format_alloc_info X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, armbru@redhat.com, mreitz@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Improve dump_human_format_alloc_info() by specifying format names. Signed-off-by: Vladimir Sementsov-Ogievskiy --- qemu-img.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 55f8c1776c..3c03690a4f 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -560,7 +560,8 @@ static void dump_json_image_check(ImageCheck *check, bool quiet) QDECREF(str); } -static void dump_human_format_alloc_info(BlockFormatAllocInfo *bfai, bool quiet) +static void dump_human_format_alloc_info(BlockDriverState *bs, + BlockFormatAllocInfo *bfai, bool quiet) { char *alloc_alloc = size_to_str(bfai->alloc_alloc); char *alloc_hole = size_to_str(bfai->alloc_hole); @@ -568,13 +569,28 @@ static void dump_human_format_alloc_info(BlockFormatAllocInfo *bfai, bool quiet) char *hole_alloc = size_to_str(bfai->hole_alloc); char *hole_hole = size_to_str(bfai->hole_hole); + const char *format = bdrv_get_format_name(bs); + const char *f_format = + bs->file ? bdrv_get_format_name(bs->file->bs) : "file"; + int format_len, cw; + + if (format == NULL) { + format = "format"; + } + if (f_format == NULL) { + f_format = "file"; + } + format_len = strlen(format); + cw = MAX(10, strlen(f_format) + 6); + qprintf(quiet, "Format allocation info (including metadata):\n" - " file-alloc file-hole after-eof\n" - "format-alloc %10s %10s %10s\n" - "format-hole %10s %10s\n", - alloc_alloc, alloc_hole, alloc_overhead, - hole_alloc, hole_hole); + "%*s %*s-alloc %*s-hole %*s\n" + "%s-alloc %*s %*s %*s\n" + "%s-hole %*s %*s\n", + format_len, "", cw - 6, f_format, cw - 5, f_format, cw, "after-eof", + format, cw, alloc_alloc, cw, alloc_hole, cw, alloc_overhead, + format, cw, hole_alloc, cw, hole_hole); g_free(alloc_alloc); g_free(alloc_hole); @@ -583,7 +599,8 @@ static void dump_human_format_alloc_info(BlockFormatAllocInfo *bfai, bool quiet) g_free(hole_hole); } -static void dump_human_image_check(ImageCheck *check, bool quiet) +static void dump_human_image_check(BlockDriverState *bs, ImageCheck *check, + bool quiet) { if (!(check->corruptions || check->leaks || check->check_errors)) { qprintf(quiet, "No errors were found on the image.\n"); @@ -626,7 +643,7 @@ static void dump_human_image_check(ImageCheck *check, bool quiet) } if (check->has_format_alloc_info) { - dump_human_format_alloc_info(check->format_alloc_info, quiet); + dump_human_format_alloc_info(bs, check->format_alloc_info, quiet); } } @@ -840,7 +857,7 @@ static int img_check(int argc, char **argv) if (!ret) { switch (output_format) { case OFORMAT_HUMAN: - dump_human_image_check(check, quiet); + dump_human_image_check(bs, check, quiet); break; case OFORMAT_JSON: dump_json_image_check(check, quiet);