From nobody Fri Dec 19 13:25:48 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1688661104; cv=none; d=zohomail.com; s=zohoarc; b=IZqBcVTgCkQ9bBQca89bG4KpeIa4eRDq3Uk+aJXQmK133b3pov4t5S3EnQDexC9usItFEfTwXsooAkL078j/Dpnrteg7HdZoCWpb/HJJsfRH5j985sYRaJah0gOaOHLA4qbUZqf138y+N7zJF01XfSUYDIJj87sMClBnwzWJ7AM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688661104; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=taGmQcpJGvCN8CKZT3PFZE6n45d7qs8VK4ok7Rvhz9w=; b=YIBaTytFkuHcgBPvebxLQlieh0dmKepC01Yc8NIY4aMiABHU3IKvTmKk0KDiy6ftXQStJt6lb+fd80jRuBldyWebebaXImnPWsL4cbbzAh5jNkF3rABJvhGkwPdS5aWDyU16LQwlsjeON1OQTf4tCKZjqAuA754yVV3U5fUXU0M= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1688661103841790.6736203744091; Thu, 6 Jul 2023 09:31:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHRst-0008RE-VR; Thu, 06 Jul 2023 12:31:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qHRso-0008Q1-IU; Thu, 06 Jul 2023 12:31:06 -0400 Received: from relay.virtuozzo.com ([130.117.225.111]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qHRsg-0007Pv-22; Thu, 06 Jul 2023 12:30:59 -0400 Received: from [130.117.225.1] (helo=dev005.ch-qa.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1qHRrH-00D6CC-0r; Thu, 06 Jul 2023 18:30:47 +0200 To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com, fam@euphon.net, eblake@redhat.com, vsementsov@yandex-team.ru, andrey.drobyshev@virtuozzo.com, den@virtuozzo.com Subject: [PATCH v2 2/3] qemu-img: map: report compressed data blocks Date: Thu, 6 Jul 2023 19:30:46 +0300 Message-Id: <20230706163047.128999-3-andrey.drobyshev@virtuozzo.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230706163047.128999-1-andrey.drobyshev@virtuozzo.com> References: <20230706163047.128999-1-andrey.drobyshev@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=130.117.225.111; envelope-from=andrey.drobyshev@virtuozzo.com; helo=relay.virtuozzo.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Andrey Drobyshev From: Andrey Drobyshev via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1688661105501100003 Content-Type: text/plain; charset="utf-8" Right now "qemu-img map" reports compressed blocks as containing data but having no host offset. This is not very informative. Instead, let's add another boolean field named "compressed" in case JSON output mode is specified. This is achieved by utilizing new allocation status flag BDRV_BLOCK_COMPRESSED for bdrv_block_status(). Signed-off-by: Andrey Drobyshev Reviewed-by: Denis V. Lunev --- qapi/block-core.json | 7 +++++-- qemu-img.c | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 5dd5f7e4b0..b263d2cd30 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -409,6 +409,9 @@ # # @zero: whether the virtual blocks read as zeroes # +# @compressed: true indicates that data is stored compressed. Optional, +# only valid for the formats whith support compression +# # @depth: number of layers (0 =3D top image, 1 =3D top image's backing # file, ..., n - 1 =3D bottom image (where n is the number of images # in the chain)) before reaching one for which the range is @@ -426,8 +429,8 @@ ## { 'struct': 'MapEntry', 'data': {'start': 'int', 'length': 'int', 'data': 'bool', - 'zero': 'bool', 'depth': 'int', 'present': 'bool', - '*offset': 'int', '*filename': 'str' } } + 'zero': 'bool', '*compressed': 'bool', 'depth': 'int', + 'present': 'bool', '*offset': 'int', '*filename': 'str' } } =20 ## # @BlockdevCacheInfo: diff --git a/qemu-img.c b/qemu-img.c index 27f48051b0..9bb69f58f6 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3083,7 +3083,7 @@ static int img_info(int argc, char **argv) } =20 static int dump_map_entry(OutputFormat output_format, MapEntry *e, - MapEntry *next) + MapEntry *next, bool can_compress) { switch (output_format) { case OFORMAT_HUMAN: @@ -3112,6 +3112,9 @@ static int dump_map_entry(OutputFormat output_format,= MapEntry *e, e->present ? "true" : "false", e->zero ? "true" : "false", e->data ? "true" : "false"); + if (can_compress) { + printf(", \"compressed\": %s", e->compressed ? "true" : "false= "); + } if (e->has_offset) { printf(", \"offset\": %"PRId64"", e->offset); } @@ -3172,6 +3175,7 @@ static int get_block_status(BlockDriverState *bs, int= 64_t offset, .length =3D bytes, .data =3D !!(ret & BDRV_BLOCK_DATA), .zero =3D !!(ret & BDRV_BLOCK_ZERO), + .compressed =3D !!(ret & BDRV_BLOCK_COMPRESSED), .offset =3D map, .has_offset =3D has_offset, .depth =3D depth, @@ -3189,6 +3193,7 @@ static inline bool entry_mergeable(const MapEntry *cu= rr, const MapEntry *next) } if (curr->zero !=3D next->zero || curr->data !=3D next->data || + curr->compressed !=3D next->compressed || curr->depth !=3D next->depth || curr->present !=3D next->present || !curr->filename !=3D !next->filename || @@ -3218,6 +3223,7 @@ static int img_map(int argc, char **argv) bool force_share =3D false; int64_t start_offset =3D 0; int64_t max_length =3D -1; + bool can_compress =3D false; =20 fmt =3D NULL; output =3D NULL; @@ -3313,6 +3319,10 @@ static int img_map(int argc, char **argv) length =3D MIN(start_offset + max_length, length); } =20 + if (output_format =3D=3D OFORMAT_JSON) { + can_compress =3D block_driver_can_compress(bs->drv); + } + curr.start =3D start_offset; while (curr.start + curr.length < length) { int64_t offset =3D curr.start + curr.length; @@ -3330,7 +3340,7 @@ static int img_map(int argc, char **argv) } =20 if (curr.length > 0) { - ret =3D dump_map_entry(output_format, &curr, &next); + ret =3D dump_map_entry(output_format, &curr, &next, can_compre= ss); if (ret < 0) { goto out; } @@ -3338,7 +3348,7 @@ static int img_map(int argc, char **argv) curr =3D next; } =20 - ret =3D dump_map_entry(output_format, &curr, NULL); + ret =3D dump_map_entry(output_format, &curr, NULL, can_compress); if (output_format =3D=3D OFORMAT_JSON) { puts("]"); } --=20 2.39.3