From nobody Thu May 2 05:07:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496141478460468.77833177521495; Tue, 30 May 2017 03:51:18 -0700 (PDT) Received: from localhost ([::1]:52872 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFek9-0006A3-4o for importer@patchew.org; Tue, 30 May 2017 06:51:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33889) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFeiE-0004o0-0u for qemu-devel@nongnu.org; Tue, 30 May 2017 06:49:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFeiC-0005IV-V3 for qemu-devel@nongnu.org; Tue, 30 May 2017 06:49:18 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:11975 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 1dFeiC-0005I7-KJ for qemu-devel@nongnu.org; Tue, 30 May 2017 06:49:16 -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 v4UAmvVX029109; 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:54 +0300 Message-Id: <20170530104857.70083-2-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 1/4] block: add bdrv_get_format_alloc_stat format interface 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The function should collect statistics, about allocted/unallocated by top-level format driver space (in its .file) and allocation status (allocated/hole/after eof) of corresponding areas in this .file. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block.c | 16 ++++++++++++++++ include/block/block.h | 3 +++ include/block/block_int.h | 2 ++ qapi/block-core.json | 26 ++++++++++++++++++++++++++ 4 files changed, 47 insertions(+) diff --git a/block.c b/block.c index 50ba264143..7d720ae0c2 100644 --- a/block.c +++ b/block.c @@ -3407,6 +3407,22 @@ int64_t bdrv_get_allocated_file_size(BlockDriverStat= e *bs) } =20 /** + * Collect format allocation info. See BlockFormatAllocInfo definition in + * qapi/block-core.json. + */ +int bdrv_get_format_alloc_stat(BlockDriverState *bs, BlockFormatAllocInfo = *bfai) +{ + BlockDriver *drv =3D bs->drv; + if (!drv) { + return -ENOMEDIUM; + } + if (drv->bdrv_get_format_alloc_stat) { + return drv->bdrv_get_format_alloc_stat(bs, bfai); + } + return -ENOTSUP; +} + +/** * Return number of sectors on success, -errno on error. */ int64_t bdrv_nb_sectors(BlockDriverState *bs) diff --git a/include/block/block.h b/include/block/block.h index 9b355e92d8..646376a772 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -335,6 +335,9 @@ typedef enum { =20 int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode f= ix); =20 +int bdrv_get_format_alloc_stat(BlockDriverState *bs, + BlockFormatAllocInfo *bfai); + /* The units of offset and total_work_size may be chosen arbitrarily by the * block driver; total_work_size may change during the course of the amend= ment * operation */ diff --git a/include/block/block_int.h b/include/block/block_int.h index 8d3724cce6..458c715e99 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -208,6 +208,8 @@ struct BlockDriver { int64_t (*bdrv_getlength)(BlockDriverState *bs); bool has_variable_length; int64_t (*bdrv_get_allocated_file_size)(BlockDriverState *bs); + int (*bdrv_get_format_alloc_stat)(BlockDriverState *bs, + BlockFormatAllocInfo *bfai); =20 int coroutine_fn (*bdrv_co_pwritev_compressed)(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov); diff --git a/qapi/block-core.json b/qapi/block-core.json index ea0b3e8b13..365070b3eb 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -139,6 +139,32 @@ '*format-specific': 'ImageInfoSpecific' } } =20 ## +# @BlockFormatAllocInfo: +# +# Information about allocations, including metadata. All fields are in byt= es. +# +# @alloc_alloc: allocated by format driver and allocated in underlying file +# +# @alloc_hole: allocated by format driver but actually is a hole in +# underlying file +# +# @alloc_overhead: allocated by format driver after end of underlying file +# +# @hole_alloc: not allocated by format driver but allocated in underlying = file +# +# @hole_hole: not allocated by format driver hole in underlying file +# +# Since: 2.10 +# +## +{ 'struct': 'BlockFormatAllocInfo', + 'data': {'alloc_alloc': 'uint64', + 'alloc_hole': 'uint64', + 'alloc_overhead': 'uint64', + 'hole_alloc': 'uint64', + 'hole_hole': 'uint64' } } + +## # @ImageCheck: # # Information about a QEMU image file check --=20 2.11.1 From nobody Thu May 2 05:07:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496141466298710.0386079135214; Tue, 30 May 2017 03:51:06 -0700 (PDT) Received: from localhost ([::1]:52871 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFejx-0005yX-0L for importer@patchew.org; Tue, 30 May 2017 06:51:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33858) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFei7-0004i9-W2 for qemu-devel@nongnu.org; Tue, 30 May 2017 06:49:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFei6-0005C2-Vg for qemu-devel@nongnu.org; Tue, 30 May 2017 06:49:12 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:13980 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-0005Ao-Fg 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 v4UAmvVY029109; 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:55 +0300 Message-Id: <20170530104857.70083-3-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 2/4] qcow2: add .bdrv_get_format_alloc_stat 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Realize .bdrv_get_format_alloc_stat interface. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2-refcount.c | 144 +++++++++++++++++++++++++++++++++++++++++++++= ++++ block/qcow2.c | 2 + block/qcow2.h | 2 + 3 files changed, 148 insertions(+) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 7c06061aae..2010dfa048 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -2931,3 +2931,147 @@ done: qemu_vfree(new_refblock); return ret; } + +typedef struct FormatAllocStatCo { + BlockDriverState *bs; + BlockFormatAllocInfo *bfai; + int64_t ret; +} FormatAllocStatCo; + +static void coroutine_fn qcow2_get_format_alloc_stat_entry(void *opaque) +{ + int ret =3D 0; + FormatAllocStatCo *nbco =3D opaque; + BlockDriverState *bs =3D nbco->bs; + BDRVQcow2State *s =3D bs->opaque; + BlockFormatAllocInfo *bfai =3D nbco->bfai; + int64_t cluster, file_sectors, sector; + int refcount_block_offset; + uint32_t i; + bool allocated =3D false, f_allocated =3D false; + int dif, num =3D 0, f_num =3D 0; + + memset(bfai, 0, sizeof(*bfai)); + + file_sectors =3D bdrv_nb_sectors(bs->file->bs); + if (file_sectors < 0) { + nbco->ret =3D file_sectors; + return; + } + + qemu_co_mutex_lock(&s->lock); + + for (sector =3D 0; sector < file_sectors; sector +=3D dif) { + if (f_num =3D=3D 0) { + ret =3D bdrv_is_allocated_above(bs->file->bs, NULL, sector, + file_sectors - sector, &f_num); + if (ret < 0) { + goto fail; + } + f_allocated =3D ret; + } + + if (num =3D=3D 0) { + uint64_t refcount; + assert(((sector << BDRV_SECTOR_BITS) & (s->cluster_size - 1)) = =3D=3D 0); + ret =3D qcow2_get_refcount( + bs, (sector << BDRV_SECTOR_BITS) >> s->cluster_bits, &refc= ount); + if (ret < 0) { + goto fail; + } + allocated =3D refcount > 0; + num =3D s->cluster_size >> BDRV_SECTOR_BITS; + } + + dif =3D MIN(f_num, MIN(num, file_sectors - sector)); + if (allocated) { + if (f_allocated) { + bfai->alloc_alloc +=3D dif; + } else { + bfai->alloc_hole +=3D dif; + } + } else { + if (f_allocated) { + bfai->hole_alloc +=3D dif; + } else { + bfai->hole_hole +=3D dif; + } + } + f_num -=3D dif; + num -=3D dif; + } + + assert(f_num =3D=3D 0); + + if (allocated) { + bfai->alloc_overhead +=3D num; + } + + cluster =3D size_to_clusters(s, sector << BDRV_SECTOR_BITS); + refcount_block_offset =3D cluster & (s->refcount_block_size - 1); + for (i =3D cluster >> s->refcount_block_bits; + i <=3D s->max_refcount_table_index; i++) + { + int j; + + if (!(s->refcount_table[i] & REFT_OFFSET_MASK)) { + refcount_block_offset =3D 0; + continue; + } + + for (j =3D refcount_block_offset; j < s->refcount_block_size; j++)= { + uint64_t refcount; + cluster =3D (i << s->refcount_block_bits) + j; + + ret =3D qcow2_get_refcount(bs, cluster, &refcount); + if (ret < 0) { + goto fail; + } + if (refcount > 0) { + bfai->alloc_overhead++; + } + } + + refcount_block_offset =3D 0; + } + + qemu_co_mutex_unlock(&s->lock); + + bfai->alloc_alloc =3D bfai->alloc_alloc << BDRV_SECTOR_BITS; + bfai->alloc_hole =3D bfai->alloc_hole << BDRV_SECTOR_BITS; + bfai->alloc_overhead =3D bfai->alloc_overhead << BDRV_SECTOR_BITS; + + bfai->hole_alloc =3D bfai->hole_alloc << BDRV_SECTOR_BITS; + bfai->hole_hole =3D bfai->hole_hole << BDRV_SECTOR_BITS; + + nbco->ret =3D 0; + return; + +fail: + nbco->ret =3D ret; + qemu_co_mutex_unlock(&s->lock); +} + +/* qcow2_get_format_alloc_stat() + * Fills @bfai struct. In case of failure @bfai content is unpredicted. + */ +int qcow2_get_format_alloc_stat(BlockDriverState *bs, + BlockFormatAllocInfo *bfai) +{ + FormatAllocStatCo nbco =3D { + .bs =3D bs, + .bfai =3D bfai, + .ret =3D -EINPROGRESS + }; + + if (qemu_in_coroutine()) { + qcow2_get_format_alloc_stat_entry(&nbco); + } else { + Coroutine *co =3D + qemu_coroutine_create(qcow2_get_format_alloc_stat_entry, &nbco= ); + qemu_coroutine_enter(co); + BDRV_POLL_WHILE(bs, nbco.ret =3D=3D -EINPROGRESS); + } + + return nbco.ret; +} diff --git a/block/qcow2.c b/block/qcow2.c index a8d61f0981..0e26b548fd 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3469,6 +3469,8 @@ BlockDriver bdrv_qcow2 =3D { =20 .bdrv_detach_aio_context =3D qcow2_detach_aio_context, .bdrv_attach_aio_context =3D qcow2_attach_aio_context, + + .bdrv_get_format_alloc_stat =3D qcow2_get_format_alloc_stat, }; =20 static void bdrv_qcow2_init(void) diff --git a/block/qcow2.h b/block/qcow2.h index 1801dc30dc..16d31a8624 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -598,4 +598,6 @@ int qcow2_cache_get_empty(BlockDriverState *bs, Qcow2Ca= che *c, uint64_t offset, void **table); void qcow2_cache_put(BlockDriverState *bs, Qcow2Cache *c, void **table); =20 +int qcow2_get_format_alloc_stat(BlockDriverState *bs, + BlockFormatAllocInfo *bfai); #endif --=20 2.11.1 From nobody Thu May 2 05:07:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496141580150892.738800792927; Tue, 30 May 2017 03:53:00 -0700 (PDT) Received: from localhost ([::1]:52878 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFelm-0007ZK-Kd for importer@patchew.org; Tue, 30 May 2017 06:52:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33852) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFei7-0004ht-Ld 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-0005Bs-Q6 for qemu-devel@nongnu.org; Tue, 30 May 2017 06:49:11 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:18301 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-0005Aq-G0 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 v4UAmvVZ029109; 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:56 +0300 Message-Id: <20170530104857.70083-4-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 3/4] qemu-img check: add format allocation 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy --- qapi/block-core.json | 6 +++++- qemu-img.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 365070b3eb..3357b61811 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -203,6 +203,9 @@ # field is present if the driver for the image format # supports it # +# @format-alloc-info: Format-allocation information, see +# BlockFormatAllocInfo description. (Since: 2.10) +# # Since: 1.4 # ## @@ -211,7 +214,8 @@ '*image-end-offset': 'int', '*corruptions': 'int', '*leaks': 'i= nt', '*corruptions-fixed': 'int', '*leaks-fixed': 'int', '*total-clusters': 'int', '*allocated-clusters': 'int', - '*fragmented-clusters': 'int', '*compressed-clusters': 'int' } } + '*fragmented-clusters': 'int', '*compressed-clusters': 'int', + '*format-alloc-info': 'BlockFormatAllocInfo' } } =20 ## # @MapEntry: diff --git a/qemu-img.c b/qemu-img.c index b506839ef0..55f8c1776c 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -560,6 +560,29 @@ static void dump_json_image_check(ImageCheck *check, b= ool quiet) QDECREF(str); } =20 +static void dump_human_format_alloc_info(BlockFormatAllocInfo *bfai, bool = quiet) +{ + char *alloc_alloc =3D size_to_str(bfai->alloc_alloc); + char *alloc_hole =3D size_to_str(bfai->alloc_hole); + char *alloc_overhead =3D size_to_str(bfai->alloc_overhead); + char *hole_alloc =3D size_to_str(bfai->hole_alloc); + char *hole_hole =3D size_to_str(bfai->hole_hole); + + 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); + + g_free(alloc_alloc); + g_free(alloc_hole); + g_free(alloc_overhead); + g_free(hole_alloc); + g_free(hole_hole); +} + static void dump_human_image_check(ImageCheck *check, bool quiet) { if (!(check->corruptions || check->leaks || check->check_errors)) { @@ -601,6 +624,10 @@ static void dump_human_image_check(ImageCheck *check, = bool quiet) qprintf(quiet, "Image end offset: %" PRId64 "\n", check->image_end_offset= ); } + + if (check->has_format_alloc_info) { + dump_human_format_alloc_info(check->format_alloc_info, quiet); + } } =20 static int collect_image_check(BlockDriverState *bs, @@ -611,6 +638,7 @@ static int collect_image_check(BlockDriverState *bs, { int ret; BdrvCheckResult result; + BlockFormatAllocInfo *bfai =3D g_new0(BlockFormatAllocInfo, 1); =20 ret =3D bdrv_check(bs, &result, fix); if (ret < 0) { @@ -639,6 +667,14 @@ static int collect_image_check(BlockDriverState *bs, check->compressed_clusters =3D result.bfi.compressed_clusters; check->has_compressed_clusters =3D result.bfi.compressed_clusters != =3D 0; =20 + ret =3D bdrv_get_format_alloc_stat(bs, bfai); + if (ret < 0) { + qapi_free_BlockFormatAllocInfo(bfai); + } else { + check->has_format_alloc_info =3D true; + check->format_alloc_info =3D bfai; + } + return 0; } =20 --=20 2.11.1 From nobody Thu May 2 05:07:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496141457188373.14583100631205; Tue, 30 May 2017 03:50:57 -0700 (PDT) Received: from localhost ([::1]:52869 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFejn-0005uO-92 for importer@patchew.org; Tue, 30 May 2017 06:50:55 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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, bo= ol quiet) QDECREF(str); } =20 -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 =3D size_to_str(bfai->alloc_alloc); char *alloc_hole =3D size_to_str(bfai->alloc_hole); @@ -568,13 +569,28 @@ static void dump_human_format_alloc_info(BlockFormatA= llocInfo *bfai, bool quiet) char *hole_alloc =3D size_to_str(bfai->hole_alloc); char *hole_hole =3D size_to_str(bfai->hole_hole); =20 + const char *format =3D bdrv_get_format_name(bs); + const char *f_format =3D + bs->file ? bdrv_get_format_name(bs->file->bs) : "file"; + int format_len, cw; + + if (format =3D=3D NULL) { + format =3D "format"; + } + if (f_format =3D=3D NULL) { + f_format =3D "file"; + } + format_len =3D strlen(format); + cw =3D 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); =20 g_free(alloc_alloc); g_free(alloc_hole); @@ -583,7 +599,8 @@ static void dump_human_format_alloc_info(BlockFormatAll= ocInfo *bfai, bool quiet) g_free(hole_hole); } =20 -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, b= ool quiet) } =20 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); } } =20 @@ -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); --=20 2.11.1