From patchwork Mon Jun 20 16:26:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanna Czenczek X-Patchwork-Id: 12887938 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7846AC43334 for ; Mon, 20 Jun 2022 16:34:11 +0000 (UTC) Received: from localhost ([::1]:52102 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o3KLq-0000kQ-Gw for qemu-devel@archiver.kernel.org; Mon, 20 Jun 2022 12:34:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52328) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3KF6-0005Z4-M7 for qemu-devel@nongnu.org; Mon, 20 Jun 2022 12:27:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:57286) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3KF3-0005Ha-J5 for qemu-devel@nongnu.org; Mon, 20 Jun 2022 12:27:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655742429; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MWlcc6ezxc5Kcy79e9j072gIoSmFIRG7sdEY1Zg/wSo=; b=YCGX0SVST/3sa343EluojwRacTkQbguK9lg+S3ORm2WHL6jEz2aPLPN1bpiMkTGBpT35MC 4CNjbN2a/RF6YlewLqzk0INVg/GMUywvgiPEgclJB/KiWcZXO6GZQxQ1RLxJW117+OcMtw 7NThIIOxrFRQYEm1/OiAb4dXqvIIIxg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-97-0TkaNIwSNVqKyr6-9H2bdA-1; Mon, 20 Jun 2022 12:27:07 -0400 X-MC-Unique: 0TkaNIwSNVqKyr6-9H2bdA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5D910811E83; Mon, 20 Jun 2022 16:27:07 +0000 (UTC) Received: from localhost (unknown [10.39.193.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 09162112131B; Mon, 20 Jun 2022 16:27:06 +0000 (UTC) From: Hanna Reitz To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Reitz , Kevin Wolf , Eric Blake , Markus Armbruster Subject: [PATCH v2 01/12] block: Improve empty format-specific info dump Date: Mon, 20 Jun 2022 18:26:53 +0200 Message-Id: <20220620162704.80987-2-hreitz@redhat.com> In-Reply-To: <20220620162704.80987-1-hreitz@redhat.com> References: <20220620162704.80987-1-hreitz@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Received-SPF: pass client-ip=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" When a block driver supports obtaining format-specific information, but that object only contains optional fields, it is possible that none of them are present, so that dump_qobject() (called by bdrv_image_info_specific_dump()) will not print anything. The callers of bdrv_image_info_specific_dump() put a header above this information ("Format specific information:\n"), which will look strange when there is nothing below. Modify bdrv_image_info_specific_dump() to print this header instead of its callers, and only if there is indeed something to be printed. Signed-off-by: Hanna Reitz --- include/block/qapi.h | 3 ++- block/qapi.c | 41 +++++++++++++++++++++++++++++++++++++---- qemu-io-cmds.c | 4 ++-- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/include/block/qapi.h b/include/block/qapi.h index 22c7807c89..c09859ea78 100644 --- a/include/block/qapi.h +++ b/include/block/qapi.h @@ -40,6 +40,7 @@ void bdrv_query_image_info(BlockDriverState *bs, Error **errp); void bdrv_snapshot_dump(QEMUSnapshotInfo *sn); -void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec); +void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec, + const char *prefix); void bdrv_image_info_dump(ImageInfo *info); #endif diff --git a/block/qapi.c b/block/qapi.c index cf557e3aea..51202b470a 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -777,7 +777,35 @@ static void dump_qdict(int indentation, QDict *dict) } } -void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec) +/* + * Return whether dumping the given QObject with dump_qobject() would + * yield an empty dump, i.e. not print anything. + */ +static bool qobject_is_empty_dump(const QObject *obj) +{ + switch (qobject_type(obj)) { + case QTYPE_QNUM: + case QTYPE_QSTRING: + case QTYPE_QBOOL: + return false; + + case QTYPE_QDICT: + return qdict_size(qobject_to(QDict, obj)) == 0; + + case QTYPE_QLIST: + return qlist_empty(qobject_to(QList, obj)); + + default: + abort(); + } +} + +/** + * Dumps the given ImageInfoSpecific object in a human-readable form, + * prepending an optional prefix if the dump is not empty. + */ +void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec, + const char *prefix) { QObject *obj, *data; Visitor *v = qobject_output_visitor_new(&obj); @@ -785,7 +813,12 @@ void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec) visit_type_ImageInfoSpecific(v, NULL, &info_spec, &error_abort); visit_complete(v, &obj); data = qdict_get(qobject_to(QDict, obj), "data"); - dump_qobject(1, data); + if (!qobject_is_empty_dump(data)) { + if (prefix) { + qemu_printf("%s", prefix); + } + dump_qobject(1, data); + } qobject_unref(obj); visit_free(v); } @@ -866,7 +899,7 @@ void bdrv_image_info_dump(ImageInfo *info) } if (info->has_format_specific) { - qemu_printf("Format specific information:\n"); - bdrv_image_info_specific_dump(info->format_specific); + bdrv_image_info_specific_dump(info->format_specific, + "Format specific information:\n"); } } diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 2f0d8ac25a..084ec44d3b 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -1819,8 +1819,8 @@ static int info_f(BlockBackend *blk, int argc, char **argv) return -EIO; } if (spec_info) { - printf("Format specific information:\n"); - bdrv_image_info_specific_dump(spec_info); + bdrv_image_info_specific_dump(spec_info, + "Format specific information:\n"); qapi_free_ImageInfoSpecific(spec_info); } From patchwork Mon Jun 20 16:26:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanna Czenczek X-Patchwork-Id: 12887933 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 818AEC433EF for ; Mon, 20 Jun 2022 16:30:43 +0000 (UTC) Received: from localhost ([::1]:42974 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o3KIU-0002jx-I3 for qemu-devel@archiver.kernel.org; Mon, 20 Jun 2022 12:30:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52470) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3KF9-0005ek-5r for qemu-devel@nongnu.org; Mon, 20 Jun 2022 12:27:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:48308) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3KF5-0005Hw-TB for qemu-devel@nongnu.org; Mon, 20 Jun 2022 12:27:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655742430; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9I6OjyTmx9o3Yi4Vwfplt31NAiJmb8LFOaJgJMJWUhg=; b=NC8GeVyweHVSxwz0okEuYGZW0MMw/XjmM0qL/dY0MBPeDewB8rcTI/cNH7ZQuIf4/8hTZc MRL4BloHuPQgiNSANq2DQo1+MeLd6Wkd3cRqwf2jVKqdi/D7LXIe+hoYvpr9WlZUFkkiA7 Lzq/UhUxyIYV7/Ssg5wjI14kM8Udysw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-17--rTSKz8FPeS4rEcyAIwy4g-1; Mon, 20 Jun 2022 12:27:09 -0400 X-MC-Unique: -rTSKz8FPeS4rEcyAIwy4g-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E672F801756; Mon, 20 Jun 2022 16:27:08 +0000 (UTC) Received: from localhost (unknown [10.39.193.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A37412166B26; Mon, 20 Jun 2022 16:27:08 +0000 (UTC) From: Hanna Reitz To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Reitz , Kevin Wolf , Eric Blake , Markus Armbruster Subject: [PATCH v2 02/12] block/file: Add file-specific image info Date: Mon, 20 Jun 2022 18:26:54 +0200 Message-Id: <20220620162704.80987-3-hreitz@redhat.com> In-Reply-To: <20220620162704.80987-1-hreitz@redhat.com> References: <20220620162704.80987-1-hreitz@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass client-ip=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add some (optional) information that the file driver can provide for image files, namely the extent size hint. Signed-off-by: Hanna Reitz Reviewed-by: Eric Blake --- qapi/block-core.json | 26 ++++++++++++++++++++++++-- block/file-posix.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 457df16638..40fb307e2d 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -139,16 +139,29 @@ '*encryption-format': 'RbdImageEncryptionFormat' } } +## +# @ImageInfoSpecificFile: +# +# @extent-size-hint: Extent size hint (if available) +# +# Since: 7.1 +## +{ 'struct': 'ImageInfoSpecificFile', + 'data': { + '*extent-size-hint': 'size' + } } + ## # @ImageInfoSpecificKind: # # @luks: Since 2.7 # @rbd: Since 6.1 +# @file: Since 7.1 # # Since: 1.7 ## { 'enum': 'ImageInfoSpecificKind', - 'data': [ 'qcow2', 'vmdk', 'luks', 'rbd' ] } + 'data': [ 'qcow2', 'vmdk', 'luks', 'rbd', 'file' ] } ## # @ImageInfoSpecificQCow2Wrapper: @@ -185,6 +198,14 @@ { 'struct': 'ImageInfoSpecificRbdWrapper', 'data': { 'data': 'ImageInfoSpecificRbd' } } +## +# @ImageInfoSpecificFileWrapper: +# +# Since: 7.1 +## +{ 'struct': 'ImageInfoSpecificFileWrapper', + 'data': { 'data': 'ImageInfoSpecificFile' } } + ## # @ImageInfoSpecific: # @@ -199,7 +220,8 @@ 'qcow2': 'ImageInfoSpecificQCow2Wrapper', 'vmdk': 'ImageInfoSpecificVmdkWrapper', 'luks': 'ImageInfoSpecificLUKSWrapper', - 'rbd': 'ImageInfoSpecificRbdWrapper' + 'rbd': 'ImageInfoSpecificRbdWrapper', + 'file': 'ImageInfoSpecificFileWrapper' } } ## diff --git a/block/file-posix.c b/block/file-posix.c index 48cd096624..74a649b409 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -3083,6 +3083,34 @@ static int raw_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) return 0; } +static ImageInfoSpecific *raw_get_specific_info(BlockDriverState *bs, + Error **errp) +{ + BDRVRawState *s = bs->opaque; + ImageInfoSpecificFile *file_info = g_new0(ImageInfoSpecificFile, 1); + ImageInfoSpecific *spec_info = g_new(ImageInfoSpecific, 1); + + *spec_info = (ImageInfoSpecific){ + .type = IMAGE_INFO_SPECIFIC_KIND_FILE, + .u.file.data = file_info, + }; + +#ifdef FS_IOC_FSGETXATTR + { + struct fsxattr attr; + int ret; + + ret = ioctl(s->fd, FS_IOC_FSGETXATTR, &attr); + if (!ret && attr.fsx_extsize != 0) { + file_info->has_extent_size_hint = true; + file_info->extent_size_hint = attr.fsx_extsize; + } + } +#endif + + return spec_info; +} + static BlockStatsSpecificFile get_blockstats_specific_file(BlockDriverState *bs) { BDRVRawState *s = bs->opaque; @@ -3316,6 +3344,7 @@ BlockDriver bdrv_file = { .bdrv_co_truncate = raw_co_truncate, .bdrv_getlength = raw_getlength, .bdrv_get_info = raw_get_info, + .bdrv_get_specific_info = raw_get_specific_info, .bdrv_get_allocated_file_size = raw_get_allocated_file_size, .bdrv_get_specific_stats = raw_get_specific_stats, @@ -3688,6 +3717,7 @@ static BlockDriver bdrv_host_device = { .bdrv_co_truncate = raw_co_truncate, .bdrv_getlength = raw_getlength, .bdrv_get_info = raw_get_info, + .bdrv_get_specific_info = raw_get_specific_info, .bdrv_get_allocated_file_size = raw_get_allocated_file_size, .bdrv_get_specific_stats = hdev_get_specific_stats, From patchwork Mon Jun 20 16:26:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanna Czenczek X-Patchwork-Id: 12887931 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 50A50C43334 for ; Mon, 20 Jun 2022 16:29:13 +0000 (UTC) Received: from localhost ([::1]:38938 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o3KH2-0008Ty-4y for qemu-devel@archiver.kernel.org; Mon, 20 Jun 2022 12:29:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52474) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3KF9-0005el-5P for qemu-devel@nongnu.org; Mon, 20 Jun 2022 12:27:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:46450) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3KF6-0005IL-Pl for qemu-devel@nongnu.org; Mon, 20 Jun 2022 12:27:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655742432; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6RsjjJd0xWLonB3st7VmcEoP3cHKpd4nP4y316E//KM=; b=QvA3+Z4o7CZnOq0fET0ivvC6GhRIw5qzmtLIa0Q5J974lcc1z3qhz0LlN+Hj5ZGC3DPUqm VXLNGfnbi5URukDhts7QS1mrnlfkafLNWZmjanOelKZ4/5rx1l2l380SoItKuhK0TrMct8 zQfAVU+oLYJAYxgoXYhEfZmAtD0AwQQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-121-gEHCzc_HNiWrGRzRXffiWA-1; Mon, 20 Jun 2022 12:27:10 -0400 X-MC-Unique: gEHCzc_HNiWrGRzRXffiWA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 826A6101E166; Mon, 20 Jun 2022 16:27:10 +0000 (UTC) Received: from localhost (unknown [10.39.193.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3D12B1121314; Mon, 20 Jun 2022 16:27:10 +0000 (UTC) From: Hanna Reitz To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Reitz , Kevin Wolf , Eric Blake , Markus Armbruster Subject: [PATCH v2 03/12] block/vmdk: Change extent info type Date: Mon, 20 Jun 2022 18:26:55 +0200 Message-Id: <20220620162704.80987-4-hreitz@redhat.com> In-Reply-To: <20220620162704.80987-1-hreitz@redhat.com> References: <20220620162704.80987-1-hreitz@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Received-SPF: pass client-ip=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" VMDK's implementation of .bdrv_get_specific_info() returns information about its extent files, ostensibly in the form of ImageInfo objects. However, it does not get this information through bdrv_query_image_info(), but fills only a select few fields with custom information that does not always match the fields' purposes. For example, @format, which is supposed to be a block driver name, is filled with the extent type, e.g. SPARSE or FLAT. In ImageInfo, @compressed shows whether the data that can be seen in the image is stored in compressed form or not. For example, a compressed qcow2 image will store compressed data in its data file, but when accessing the qcow2 node, you will see normal data. This is not how VMDK uses the @compressed field for its extent files: Instead, it signifies whether accessing the extent file will yield compressed data (which the VMDK driver then (de-)compresses). Create a new structure to represent the extent information. This allows us to clarify the fields' meanings, and it clearly shows that these are not complete ImageInfo objects. (That is, if a user wants an extent file's ImageInfo object, they will need to query it separately, and will not get it from ImageInfoSpecificVmdk.extents.) Note that this removes the last use of ['ImageInfo'] (i.e. an array of ImageInfo objects), so the QAPI generator will no longer generate ImageInfoList by default. However, we use it in qemu-img.c, so we need to create a dummy object to force the generate to create that type, similarly to DummyForceArrays in machine.json (introduced in commit 9f08c8ec73878122ad4b061ed334f0437afaaa32 ("qapi: Lazy creation of array types")). Signed-off-by: Hanna Reitz --- I'm not sure whether this is an incompatible change. I'm also not sure if it even matters whether it's an incompatible change (i.e. whether anyone cares). I believe we can get away without this change. I find it useful to make it clear that (A) this extent information is not what you would find in other ImageInfo objects (i.e., I consider this a fix for ImageInfoSpecificVmdk's @extents field), and (B) that the upcoming BlockGraphInfo type will not duplicate the extent nodes' ImageInfo information, because those are actual ImageInfo objects. We can probably replace this patch by clarifying all of this in documentation, but if possible I would prefer a syntactic clarification (as done here). --- qapi/block-core.json | 38 +++++++++++++++++++++++++++++++++++++- block/vmdk.c | 8 ++++---- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 40fb307e2d..e0c8f07932 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -124,7 +124,33 @@ 'create-type': 'str', 'cid': 'int', 'parent-cid': 'int', - 'extents': ['ImageInfo'] + 'extents': ['VmdkExtentInfo'] + } } + +## +# @VmdkExtentInfo: +# +# Information about a VMDK extent file +# +# @filename: Name of the extent file +# +# @format: Extent type (e.g. FLAT or SPARSE) +# +# @virtual-size: Number of bytes covered by this extent +# +# @cluster-size: Cluster size in bytes (for non-flat extents) +# +# @compressed: Whether this extent contains compressed data +# +# Since: 7.1 +## +{ 'struct': 'VmdkExtentInfo', + 'data': { + 'filename': 'str', + 'format': 'str', + 'virtual-size': 'int', + '*cluster-size': 'int', + '*compressed': 'bool' } } ## @@ -5638,3 +5664,13 @@ 'data': { 'device': 'str', '*id': 'str', '*name': 'str'}, 'returns': 'SnapshotInfo', 'allow-preconfig': true } + +## +# @DummyBlockCoreForceArrays: +# +# Not used by QMP; hack to let us use ImageInfoList internally +# +# Since: 7.1 +## +{ 'struct': 'DummyBlockCoreForceArrays', + 'data': { 'unused-image-info': ['ImageInfo'] } } diff --git a/block/vmdk.c b/block/vmdk.c index 38e5ab3806..35131a916e 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -2908,12 +2908,12 @@ static int vmdk_has_zero_init(BlockDriverState *bs) return 1; } -static ImageInfo *vmdk_get_extent_info(VmdkExtent *extent) +static VmdkExtentInfo *vmdk_get_extent_info(VmdkExtent *extent) { - ImageInfo *info = g_new0(ImageInfo, 1); + VmdkExtentInfo *info = g_new0(VmdkExtentInfo, 1); bdrv_refresh_filename(extent->file->bs); - *info = (ImageInfo){ + *info = (VmdkExtentInfo){ .filename = g_strdup(extent->file->bs->filename), .format = g_strdup(extent->type), .virtual_size = extent->sectors * BDRV_SECTOR_SIZE, @@ -2992,7 +2992,7 @@ static ImageInfoSpecific *vmdk_get_specific_info(BlockDriverState *bs, int i; BDRVVmdkState *s = bs->opaque; ImageInfoSpecific *spec_info = g_new0(ImageInfoSpecific, 1); - ImageInfoList **tail; + VmdkExtentInfoList **tail; *spec_info = (ImageInfoSpecific){ .type = IMAGE_INFO_SPECIFIC_KIND_VMDK, From patchwork Mon Jun 20 16:26:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanna Czenczek X-Patchwork-Id: 12887937 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 97DDBC433EF for ; Mon, 20 Jun 2022 16:34:06 +0000 (UTC) Received: from localhost ([::1]:51670 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o3KLl-0000T5-IY for qemu-devel@archiver.kernel.org; Mon, 20 Jun 2022 12:34:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52524) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3KFB-0005gC-Qu for qemu-devel@nongnu.org; Mon, 20 Jun 2022 12:27:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:47746) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3KF8-0005J9-TV for qemu-devel@nongnu.org; Mon, 20 Jun 2022 12:27:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655742434; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K451xAz8q8YJEBiSSJdcae6R7yHjJVWcLpflnIiwjlY=; b=b25dcbxcEPxb8Ejallgt/ceCLAe36Z0g7IuCZWIEuelHJ2Qry3XOKMR5Texrk7l25YYGRh UHpmWbbahAAWU6PPh7ryJBTHerws7MJVgIfLO1q1I+15809LQbhk7eDav+vSKuDMwWZJV7 xdnmpdAH6BVyklV1bF040pbMDCTgocA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-228-JaSCDt2gMf26IibSYlY0kA-1; Mon, 20 Jun 2022 12:27:12 -0400 X-MC-Unique: JaSCDt2gMf26IibSYlY0kA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 63112101E167; Mon, 20 Jun 2022 16:27:12 +0000 (UTC) Received: from localhost (unknown [10.39.193.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F05EA2026D64; Mon, 20 Jun 2022 16:27:11 +0000 (UTC) From: Hanna Reitz To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Reitz , Kevin Wolf , Eric Blake , Markus Armbruster Subject: [PATCH v2 04/12] block: Split BlockNodeInfo off of ImageInfo Date: Mon, 20 Jun 2022 18:26:56 +0200 Message-Id: <20220620162704.80987-5-hreitz@redhat.com> In-Reply-To: <20220620162704.80987-1-hreitz@redhat.com> References: <20220620162704.80987-1-hreitz@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 Received-SPF: pass client-ip=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" ImageInfo sometimes contains flat information, and sometimes it does not. Split off a BlockNodeInfo struct, which only contains information about a single node and has no link to the backing image. We do this so we can extend BlockNodeInfo to a BlockGraphInfo struct, which has links to all child nodes, not just the backing node. It would be strange to base BlockGraphInfo on ImageInfo, because then this extended struct would have two links to the backing node (one in BlockGraphInfo as one of all the child links, and one in ImageInfo). Furthermore, it is quite common to ignore the backing-image field altogether: bdrv_query_image_info() does not set it, and bdrv_image_info_dump() does not evaluate it. That signals that we should have different structs for describing a single node and one that has a link to the backing image. Still, bdrv_query_image_info() and bdrv_image_info_dump() are not changed too much in this patch. Follow-up patches will handle them. Signed-off-by: Hanna Reitz --- I hope this is not an incompatible change, but I'm not sure, I have to admit. --- qapi/block-core.json | 22 +++++++++--- include/block/qapi.h | 3 ++ block/qapi.c | 86 ++++++++++++++++++++++++++++++++------------ 3 files changed, 84 insertions(+), 27 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index e0c8f07932..8c06deacdf 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -251,7 +251,7 @@ } } ## -# @ImageInfo: +# @BlockNodeInfo: # # Information about a QEMU image file # @@ -279,22 +279,34 @@ # # @snapshots: list of VM snapshots # -# @backing-image: info of the backing image (since 1.6) -# # @format-specific: structure supplying additional format-specific # information (since 1.7) # # Since: 1.3 ## -{ 'struct': 'ImageInfo', +{ 'struct': 'BlockNodeInfo', 'data': {'filename': 'str', 'format': 'str', '*dirty-flag': 'bool', '*actual-size': 'int', 'virtual-size': 'int', '*cluster-size': 'int', '*encrypted': 'bool', '*compressed': 'bool', '*backing-filename': 'str', '*full-backing-filename': 'str', '*backing-filename-format': 'str', '*snapshots': ['SnapshotInfo'], - '*backing-image': 'ImageInfo', '*format-specific': 'ImageInfoSpecific' } } +## +# @ImageInfo: +# +# Information about a QEMU image file, and potentially its backing image +# +# @backing-image: info of the backing image +# +# Since: 7.1 +## +{ 'struct': 'ImageInfo', + 'base': 'BlockNodeInfo', + 'data': { + '*backing-image': 'ImageInfo' + } } + ## # @ImageCheck: # diff --git a/include/block/qapi.h b/include/block/qapi.h index c09859ea78..c7de4e3fa9 100644 --- a/include/block/qapi.h +++ b/include/block/qapi.h @@ -35,6 +35,9 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk, int bdrv_query_snapshot_info_list(BlockDriverState *bs, SnapshotInfoList **p_list, Error **errp); +void bdrv_query_block_node_info(BlockDriverState *bs, + BlockNodeInfo **p_info, + Error **errp); void bdrv_query_image_info(BlockDriverState *bs, ImageInfo **p_info, Error **errp); diff --git a/block/qapi.c b/block/qapi.c index 51202b470a..e5022b4481 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -241,30 +241,18 @@ int bdrv_query_snapshot_info_list(BlockDriverState *bs, } /** - * bdrv_query_image_info: - * @bs: block device to examine - * @p_info: location to store image information - * @errp: location to store error information - * - * Store "flat" image information in @p_info. - * - * "Flat" means it does *not* query backing image information, - * i.e. (*pinfo)->has_backing_image will be set to false and - * (*pinfo)->backing_image to NULL even when the image does in fact have - * a backing image. - * - * @p_info will be set only on success. On error, store error in @errp. + * Helper function for other query info functions. Store information about @bs + * in @info, setting @errp on error. */ -void bdrv_query_image_info(BlockDriverState *bs, - ImageInfo **p_info, - Error **errp) +static void bdrv_do_query_node_info(BlockDriverState *bs, + BlockNodeInfo *info, + Error **errp) { int64_t size; const char *backing_filename; BlockDriverInfo bdi; int ret; Error *err = NULL; - ImageInfo *info; aio_context_acquire(bdrv_get_aio_context(bs)); @@ -277,7 +265,6 @@ void bdrv_query_image_info(BlockDriverState *bs, bdrv_refresh_filename(bs); - info = g_new0(ImageInfo, 1); info->filename = g_strdup(bs->filename); info->format = g_strdup(bdrv_get_format_name(bs)); info->virtual_size = size; @@ -298,7 +285,6 @@ void bdrv_query_image_info(BlockDriverState *bs, info->format_specific = bdrv_get_specific_info(bs, &err); if (err) { error_propagate(errp, err); - qapi_free_ImageInfo(info); goto out; } info->has_format_specific = info->format_specific != NULL; @@ -339,16 +325,72 @@ void bdrv_query_image_info(BlockDriverState *bs, break; default: error_propagate(errp, err); - qapi_free_ImageInfo(info); goto out; } - *p_info = info; - out: aio_context_release(bdrv_get_aio_context(bs)); } +/** + * bdrv_query_block_node_info: + * @bs: block node to examine + * @p_info: location to store node information + * @errp: location to store error information + * + * Store image information about @bs in @p_info. + * + * @p_info will be set only on success. On error, store error in @errp. + */ +void bdrv_query_block_node_info(BlockDriverState *bs, + BlockNodeInfo **p_info, + Error **errp) +{ + BlockNodeInfo *info; + ERRP_GUARD(); + + info = g_new0(BlockNodeInfo, 1); + bdrv_do_query_node_info(bs, info, errp); + if (*errp) { + qapi_free_BlockNodeInfo(info); + return; + } + + *p_info = info; +} + +/** + * bdrv_query_image_info: + * @bs: block node to examine + * @p_info: location to store image information + * @errp: location to store error information + * + * Store "flat" image information in @p_info. + * + * "Flat" means it does *not* query backing image information, + * i.e. (*pinfo)->has_backing_image will be set to false and + * (*pinfo)->backing_image to NULL even when the image does in fact have + * a backing image. + * + * @p_info will be set only on success. On error, store error in @errp. + */ +void bdrv_query_image_info(BlockDriverState *bs, + ImageInfo **p_info, + Error **errp) +{ + ImageInfo *info; + ERRP_GUARD(); + + info = g_new0(ImageInfo, 1); + bdrv_do_query_node_info(bs, qapi_ImageInfo_base(info), errp); + if (*errp) { + qapi_free_ImageInfo(info); + return; + } + + *p_info = info; +} + /* @p_info will be set only on success. */ static void bdrv_query_info(BlockBackend *blk, BlockInfo **p_info, Error **errp) From patchwork Mon Jun 20 16:26:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanna Czenczek X-Patchwork-Id: 12887932 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 44671CCA479 for ; Mon, 20 Jun 2022 16:29:54 +0000 (UTC) Received: from localhost ([::1]:41370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o3KHh-0001fQ-BD for qemu-devel@archiver.kernel.org; Mon, 20 Jun 2022 12:29:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52610) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3KFH-0005ir-PN for qemu-devel@nongnu.org; Mon, 20 Jun 2022 12:27:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:44093) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3KFD-0005KL-PE for qemu-devel@nongnu.org; Mon, 20 Jun 2022 12:27:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655742437; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QBl8D55J3wkL4vzH5q+CBhlJZXBKayii7nNAPVHdt3o=; b=RhouIMERMo8hilLELLuaFo1X9wMrVcHcpTyFQ4l+ibBzDcnQ9nGQbNdQaVHZ+BtyGhr0lk FuyQK9M0ORQpp9zNhLqnx1HvDSRJ5xZ6jYFcd1SomO3Mmc5DpVQe8R2xxNlh2XU4vw7fws ngP5qwG9t1cJSuHGaxbIp7QS1YcGffs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-258-meNQnjIlP_SAzpjTFyidqA-1; Mon, 20 Jun 2022 12:27:14 -0400 X-MC-Unique: meNQnjIlP_SAzpjTFyidqA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2422585A580; Mon, 20 Jun 2022 16:27:14 +0000 (UTC) Received: from localhost (unknown [10.39.193.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B40D640466B2; Mon, 20 Jun 2022 16:27:13 +0000 (UTC) From: Hanna Reitz To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Reitz , Kevin Wolf , Eric Blake , Markus Armbruster Subject: [PATCH v2 05/12] qemu-img: Use BlockNodeInfo Date: Mon, 20 Jun 2022 18:26:57 +0200 Message-Id: <20220620162704.80987-6-hreitz@redhat.com> In-Reply-To: <20220620162704.80987-1-hreitz@redhat.com> References: <20220620162704.80987-1-hreitz@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 Received-SPF: pass client-ip=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" qemu-img info never uses ImageInfo's backing-image field, because it opens the backing chain one by one with BDRV_O_NO_BACKING, and prints all backing chain nodes' information consecutively. Use BlockNodeInfo to make it clear that we only print information about a single node, and that we are not using the backing-image field. Notably, bdrv_image_info_dump() does not evaluate the backing-image field, so we can easily make it take a BlockNodeInfo pointer (and consequentially rename it to bdrv_node_info_dump()). It makes more sense this way, because again, the interface now makes it syntactically clear that backing-image is ignored by this function. Signed-off-by: Hanna Reitz --- qapi/block-core.json | 4 +-- include/block/qapi.h | 2 +- block/monitor/block-hmp-cmds.c | 2 +- block/qapi.c | 2 +- qemu-img.c | 48 +++++++++++++++++----------------- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 8c06deacdf..d5d1c8ff15 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -5680,9 +5680,9 @@ ## # @DummyBlockCoreForceArrays: # -# Not used by QMP; hack to let us use ImageInfoList internally +# Not used by QMP; hack to let us use BlockNodeInfoList internally # # Since: 7.1 ## { 'struct': 'DummyBlockCoreForceArrays', - 'data': { 'unused-image-info': ['ImageInfo'] } } + 'data': { 'unused-block-node-info': ['BlockNodeInfo'] } } diff --git a/include/block/qapi.h b/include/block/qapi.h index c7de4e3fa9..22198dcd0c 100644 --- a/include/block/qapi.h +++ b/include/block/qapi.h @@ -45,5 +45,5 @@ void bdrv_query_image_info(BlockDriverState *bs, void bdrv_snapshot_dump(QEMUSnapshotInfo *sn); void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec, const char *prefix); -void bdrv_image_info_dump(ImageInfo *info); +void bdrv_node_info_dump(BlockNodeInfo *info); #endif diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index bfb3c043a0..d286f2d1c5 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -734,7 +734,7 @@ static void print_block_info(Monitor *mon, BlockInfo *info, monitor_printf(mon, "\nImages:\n"); image_info = inserted->image; while (1) { - bdrv_image_info_dump(image_info); + bdrv_node_info_dump(qapi_ImageInfo_base(image_info)); if (image_info->has_backing_image) { image_info = image_info->backing_image; } else { diff --git a/block/qapi.c b/block/qapi.c index e5022b4481..ad88bf9b38 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -865,7 +865,7 @@ void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec, visit_free(v); } -void bdrv_image_info_dump(ImageInfo *info) +void bdrv_node_info_dump(BlockNodeInfo *info) { char *size_buf, *dsize_buf; if (!info->has_actual_size) { diff --git a/qemu-img.c b/qemu-img.c index 4cf4d2423d..3b1f950c85 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2800,13 +2800,13 @@ static void dump_snapshots(BlockDriverState *bs) g_free(sn_tab); } -static void dump_json_image_info_list(ImageInfoList *list) +static void dump_json_block_node_info_list(BlockNodeInfoList *list) { GString *str; QObject *obj; Visitor *v = qobject_output_visitor_new(&obj); - visit_type_ImageInfoList(v, NULL, &list, &error_abort); + visit_type_BlockNodeInfoList(v, NULL, &list, &error_abort); visit_complete(v, &obj); str = qobject_to_json_pretty(obj, true); assert(str != NULL); @@ -2816,13 +2816,13 @@ static void dump_json_image_info_list(ImageInfoList *list) g_string_free(str, true); } -static void dump_json_image_info(ImageInfo *info) +static void dump_json_block_node_info(BlockNodeInfo *info) { GString *str; QObject *obj; Visitor *v = qobject_output_visitor_new(&obj); - visit_type_ImageInfo(v, NULL, &info, &error_abort); + visit_type_BlockNodeInfo(v, NULL, &info, &error_abort); visit_complete(v, &obj); str = qobject_to_json_pretty(obj, true); assert(str != NULL); @@ -2832,9 +2832,9 @@ static void dump_json_image_info(ImageInfo *info) g_string_free(str, true); } -static void dump_human_image_info_list(ImageInfoList *list) +static void dump_human_image_info_list(BlockNodeInfoList *list) { - ImageInfoList *elem; + BlockNodeInfoList *elem; bool delim = false; for (elem = list; elem; elem = elem->next) { @@ -2843,7 +2843,7 @@ static void dump_human_image_info_list(ImageInfoList *list) } delim = true; - bdrv_image_info_dump(elem->value); + bdrv_node_info_dump(elem->value); } } @@ -2853,24 +2853,24 @@ static gboolean str_equal_func(gconstpointer a, gconstpointer b) } /** - * Open an image file chain and return an ImageInfoList + * Open an image file chain and return an BlockNodeInfoList * * @filename: topmost image filename * @fmt: topmost image format (may be NULL to autodetect) * @chain: true - enumerate entire backing file chain * false - only topmost image file * - * Returns a list of ImageInfo objects or NULL if there was an error opening an - * image file. If there was an error a message will have been printed to - * stderr. + * Returns a list of BlockNodeInfo objects or NULL if there was an error + * opening an image file. If there was an error a message will have been + * printed to stderr. */ -static ImageInfoList *collect_image_info_list(bool image_opts, - const char *filename, - const char *fmt, - bool chain, bool force_share) +static BlockNodeInfoList *collect_image_info_list(bool image_opts, + const char *filename, + const char *fmt, + bool chain, bool force_share) { - ImageInfoList *head = NULL; - ImageInfoList **tail = &head; + BlockNodeInfoList *head = NULL; + BlockNodeInfoList **tail = &head; GHashTable *filenames; Error *err = NULL; @@ -2879,7 +2879,7 @@ static ImageInfoList *collect_image_info_list(bool image_opts, while (filename) { BlockBackend *blk; BlockDriverState *bs; - ImageInfo *info; + BlockNodeInfo *info; if (g_hash_table_lookup_extended(filenames, filename, NULL, NULL)) { error_report("Backing file '%s' creates an infinite loop.", @@ -2896,7 +2896,7 @@ static ImageInfoList *collect_image_info_list(bool image_opts, } bs = blk_bs(blk); - bdrv_query_image_info(bs, &info, &err); + bdrv_query_block_node_info(bs, &info, &err); if (err) { error_report_err(err); blk_unref(blk); @@ -2929,7 +2929,7 @@ static ImageInfoList *collect_image_info_list(bool image_opts, return head; err: - qapi_free_ImageInfoList(head); + qapi_free_BlockNodeInfoList(head); g_hash_table_destroy(filenames); return NULL; } @@ -2940,7 +2940,7 @@ static int img_info(int argc, char **argv) OutputFormat output_format = OFORMAT_HUMAN; bool chain = false; const char *filename, *fmt, *output; - ImageInfoList *list; + BlockNodeInfoList *list; bool image_opts = false; bool force_share = false; @@ -3019,14 +3019,14 @@ static int img_info(int argc, char **argv) break; case OFORMAT_JSON: if (chain) { - dump_json_image_info_list(list); + dump_json_block_node_info_list(list); } else { - dump_json_image_info(list->value); + dump_json_block_node_info(list->value); } break; } - qapi_free_ImageInfoList(list); + qapi_free_BlockNodeInfoList(list); return 0; } From patchwork Mon Jun 20 16:26:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanna Czenczek X-Patchwork-Id: 12887936 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 43B0EC43334 for ; Mon, 20 Jun 2022 16:33:30 +0000 (UTC) Received: from localhost ([::1]:49250 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o3KLB-0007GF-9u for qemu-devel@archiver.kernel.org; Mon, 20 Jun 2022 12:33:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52690) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3KFK-0005jx-7b for qemu-devel@nongnu.org; Mon, 20 Jun 2022 12:27:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:40154) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3KFH-0005Lb-HO for qemu-devel@nongnu.org; Mon, 20 Jun 2022 12:27:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655742442; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qnNcy7us2A1nC5/F++kD1Vlw6UlMQtk1NBGLuz6NJ8s=; b=Eab653Oe1Zdhvc1ZnLskntsYp0iys0tmrRmRz+rznVYa0yksTR9UtZ6OXy4AKVFDHSCgQR IcssTLH3vSr0isswxpHIw8gWGBUHaVb7+5qJxKWyTM4AwTVEvGBMJzICy8uW08pplr79hT EI5UrqQedhTV/UJmMSdnXu00OCVb9mI= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-120-n-bVl1TfNvqzXZw9poHLVw-1; Mon, 20 Jun 2022 12:27:16 -0400 X-MC-Unique: n-bVl1TfNvqzXZw9poHLVw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B67B31C00AC5; Mon, 20 Jun 2022 16:27:15 +0000 (UTC) Received: from localhost (unknown [10.39.193.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6FA802026D64; Mon, 20 Jun 2022 16:27:15 +0000 (UTC) From: Hanna Reitz To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Reitz , Kevin Wolf , Eric Blake , Markus Armbruster Subject: [PATCH v2 06/12] block/qapi: Let bdrv_query_image_info() recurse Date: Mon, 20 Jun 2022 18:26:58 +0200 Message-Id: <20220620162704.80987-7-hreitz@redhat.com> In-Reply-To: <20220620162704.80987-1-hreitz@redhat.com> References: <20220620162704.80987-1-hreitz@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 Received-SPF: pass client-ip=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" There is no real reason why bdrv_query_image_info() should generally not recurse. The ImageInfo struct has a pointer to the backing image, so it should generally be filled, unless the caller explicitly opts out. This moves the recursing code from bdrv_block_device_info() into bdrv_query_image_info(). Signed-off-by: Hanna Reitz --- include/block/qapi.h | 2 + block/qapi.c | 94 +++++++++++++++++++++++++++----------------- 2 files changed, 59 insertions(+), 37 deletions(-) diff --git a/include/block/qapi.h b/include/block/qapi.h index 22198dcd0c..2174bf8fa2 100644 --- a/include/block/qapi.h +++ b/include/block/qapi.h @@ -40,6 +40,8 @@ void bdrv_query_block_node_info(BlockDriverState *bs, Error **errp); void bdrv_query_image_info(BlockDriverState *bs, ImageInfo **p_info, + bool flat, + bool skip_implicit_filters, Error **errp); void bdrv_snapshot_dump(QEMUSnapshotInfo *sn); diff --git a/block/qapi.c b/block/qapi.c index ad88bf9b38..5d0a8d2ce3 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -47,8 +47,10 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk, Error **errp) { ImageInfo **p_image_info; + ImageInfo *backing_info; BlockDriverState *bs0, *backing; BlockDeviceInfo *info; + ERRP_GUARD(); if (!bs->drv) { error_setg(errp, "Block device %s is ejected", bs->node_name); @@ -149,38 +151,21 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk, bs0 = bs; p_image_info = &info->image; info->backing_file_depth = 0; - while (1) { - Error *local_err = NULL; - bdrv_query_image_info(bs0, p_image_info, &local_err); - if (local_err) { - error_propagate(errp, local_err); - qapi_free_BlockDeviceInfo(info); - return NULL; - } - - /* stop gathering data for flat output */ - if (flat) { - break; - } - if (bs0->drv && bdrv_filter_or_cow_child(bs0)) { - /* - * Put any filtered child here (for backwards compatibility to when - * we put bs0->backing here, which might be any filtered child). - */ - info->backing_file_depth++; - bs0 = bdrv_filter_or_cow_bs(bs0); - (*p_image_info)->has_backing_image = true; - p_image_info = &((*p_image_info)->backing_image); - } else { - break; - } + /* + * Skip automatically inserted nodes that the user isn't aware of for + * query-block (blk != NULL), but not for query-named-block-nodes + */ + bdrv_query_image_info(bs0, p_image_info, flat, blk != NULL, errp); + if (*errp) { + qapi_free_BlockDeviceInfo(info); + return NULL; + } - /* Skip automatically inserted nodes that the user isn't aware of for - * query-block (blk != NULL), but not for query-named-block-nodes */ - if (blk) { - bs0 = bdrv_skip_implicit_filters(bs0); - } + backing_info = info->image->backing_image; + while (backing_info) { + info->backing_file_depth++; + backing_info = backing_info->backing_image; } return info; @@ -363,19 +348,28 @@ void bdrv_query_block_node_info(BlockDriverState *bs, * bdrv_query_image_info: * @bs: block node to examine * @p_info: location to store image information + * @flat: skip backing node information + * @skip_implicit_filters: skip implicit filters in the backing chain * @errp: location to store error information * - * Store "flat" image information in @p_info. + * Store image information in @p_info, potentially recursively covering the + * backing chain. * - * "Flat" means it does *not* query backing image information, - * i.e. (*pinfo)->has_backing_image will be set to false and - * (*pinfo)->backing_image to NULL even when the image does in fact have - * a backing image. + * If @flat is true, do not query backing image information, i.e. + * (*p_info)->has_backing_image will be set to false and + * (*p_info)->backing_image to NULL even when the image does in fact have a + * backing image. + * + * If @skip_implicit_filters is true, implicit filter nodes in the backing chain + * will be skipped when querying backing image information. + * (@skip_implicit_filters is ignored when @flat is true.) * * @p_info will be set only on success. On error, store error in @errp. */ void bdrv_query_image_info(BlockDriverState *bs, ImageInfo **p_info, + bool flat, + bool skip_implicit_filters, Error **errp) { ImageInfo *info; @@ -384,11 +378,37 @@ void bdrv_query_image_info(BlockDriverState *bs, info = g_new0(ImageInfo, 1); bdrv_do_query_node_info(bs, qapi_ImageInfo_base(info), errp); if (*errp) { - qapi_free_ImageInfo(info); - return; + goto fail; + } + + if (!flat) { + BlockDriverState *backing; + + /* + * Use any filtered child here (for backwards compatibility to when + * we always took bs->backing, which might be any filtered child). + */ + backing = bdrv_filter_or_cow_bs(bs); + if (skip_implicit_filters) { + backing = bdrv_skip_implicit_filters(backing); + } + + if (backing) { + bdrv_query_image_info(backing, &info->backing_image, false, + skip_implicit_filters, errp); + if (*errp) { + goto fail; + } + info->has_backing_image = true; + } } *p_info = info; + return; + +fail: + assert(*errp); + qapi_free_ImageInfo(info); } /* @p_info will be set only on success. */ From patchwork Mon Jun 20 16:26:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanna Czenczek X-Patchwork-Id: 12887942 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 091CBC433EF for ; Mon, 20 Jun 2022 16:36:57 +0000 (UTC) Received: from localhost ([::1]:32900 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o3KOW-0006yI-1t for qemu-devel@archiver.kernel.org; Mon, 20 Jun 2022 12:36:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52672) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3KFJ-0005jm-J2 for qemu-devel@nongnu.org; Mon, 20 Jun 2022 12:27:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:34480) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3KFF-0005Ko-L8 for qemu-devel@nongnu.org; Mon, 20 Jun 2022 12:27:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655742439; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=azDHCkLZKgDRmP2fzg4kWG8pSOIHzq7N9h+EqjJrB+0=; b=Zfof5ZpllOv0AeuvDN5aFqY5yC74Du2JCszyDwYrSuzO6bpjVUsqREe9TVrGyWFikmChdN hrCKK+s0tQ19Zo0RwbQQQljJssqrGqCNxcbMOjjRGhRWlmX1UlcnyhTGDQA4DFvH6xJE5K 3VzMctH6Y/3mCHkF2JFpVmBpzxyA9BQ= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-512-fb5aJ-ykNcSMrHuHG0v4tw-1; Mon, 20 Jun 2022 12:27:17 -0400 X-MC-Unique: fb5aJ-ykNcSMrHuHG0v4tw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 700B03C30103; Mon, 20 Jun 2022 16:27:17 +0000 (UTC) Received: from localhost (unknown [10.39.193.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2BE981121314; Mon, 20 Jun 2022 16:27:17 +0000 (UTC) From: Hanna Reitz To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Reitz , Kevin Wolf , Eric Blake , Markus Armbruster Subject: [PATCH v2 07/12] block/qapi: Introduce BlockGraphInfo Date: Mon, 20 Jun 2022 18:26:59 +0200 Message-Id: <20220620162704.80987-8-hreitz@redhat.com> In-Reply-To: <20220620162704.80987-1-hreitz@redhat.com> References: <20220620162704.80987-1-hreitz@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Received-SPF: pass client-ip=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Introduce a new QAPI type BlockGraphInfo and an associated bdrv_query_block_graph_info() function that recursively gathers BlockNodeInfo objects through a block graph. A follow-up patch is going to make "qemu-img info" use this to print information about all nodes that are (usually implicitly) opened for a given image file. Signed-off-by: Hanna Reitz --- qapi/block-core.json | 35 ++++++++++++++++++++++++++++++++ include/block/qapi.h | 3 +++ block/qapi.c | 48 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) diff --git a/qapi/block-core.json b/qapi/block-core.json index d5d1c8ff15..b7e5708487 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -307,6 +307,41 @@ '*backing-image': 'ImageInfo' } } +## +# @BlockChildInfo: +# +# Information about all nodes in the block graph starting at some node, +# annotated with information about that node in relation to its parent. +# +# @name: Child name of the root node in the BlockGraphInfo struct, in its role +# as the child of some undescribed parent node +# +# @info: Block graph information starting at this node +# +# Since: 7.1 +## +{ 'struct': 'BlockChildInfo', + 'data': { + 'name': 'str', + 'info': 'BlockGraphInfo' + } } + +## +# @BlockGraphInfo: +# +# Information about all nodes in a block (sub)graph in the form of BlockNodeInfo +# data. +# The base BlockNodeInfo struct contains the information for the (sub)graph's +# root node. +# +# @children: Array of links to this node's child nodes' information +# +# Since: 7.1 +## +{ 'struct': 'BlockGraphInfo', + 'base': 'BlockNodeInfo', + 'data': { 'children': ['BlockChildInfo'] } } + ## # @ImageCheck: # diff --git a/include/block/qapi.h b/include/block/qapi.h index 2174bf8fa2..196436020e 100644 --- a/include/block/qapi.h +++ b/include/block/qapi.h @@ -43,6 +43,9 @@ void bdrv_query_image_info(BlockDriverState *bs, bool flat, bool skip_implicit_filters, Error **errp); +void bdrv_query_block_graph_info(BlockDriverState *bs, + BlockGraphInfo **p_info, + Error **errp); void bdrv_snapshot_dump(QEMUSnapshotInfo *sn); void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec, diff --git a/block/qapi.c b/block/qapi.c index 5d0a8d2ce3..f208c21ccf 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -411,6 +411,54 @@ fail: qapi_free_ImageInfo(info); } +/** + * bdrv_query_block_graph_info: + * @bs: root node to start from + * @p_info: location to store image information + * @errp: location to store error information + * + * Store image information about the graph starting from @bs in @p_info. + * + * @p_info will be set only on success. On error, store error in @errp. + */ +void bdrv_query_block_graph_info(BlockDriverState *bs, + BlockGraphInfo **p_info, + Error **errp) +{ + BlockGraphInfo *info; + BlockChildInfoList **children_list_tail; + BdrvChild *c; + ERRP_GUARD(); + + info = g_new0(BlockGraphInfo, 1); + bdrv_do_query_node_info(bs, qapi_BlockGraphInfo_base(info), errp); + if (*errp) { + goto fail; + } + + children_list_tail = &info->children; + + QLIST_FOREACH(c, &bs->children, next) { + BlockChildInfo *c_info; + + c_info = g_new0(BlockChildInfo, 1); + QAPI_LIST_APPEND(children_list_tail, c_info); + + c_info->name = g_strdup(c->name); + bdrv_query_block_graph_info(c->bs, &c_info->info, errp); + if (*errp) { + goto fail; + } + } + + *p_info = info; + return; + +fail: + assert(*errp != NULL); + qapi_free_BlockGraphInfo(info); +} + /* @p_info will be set only on success. */ static void bdrv_query_info(BlockBackend *blk, BlockInfo **p_info, Error **errp) From patchwork Mon Jun 20 16:27:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanna Czenczek X-Patchwork-Id: 12887941 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 84A18C433EF for ; Mon, 20 Jun 2022 16:36:33 +0000 (UTC) Received: from localhost ([::1]:59936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o3KO8-0006B6-L5 for qemu-devel@archiver.kernel.org; Mon, 20 Jun 2022 12:36:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52692) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3KFK-0005jy-8d for qemu-devel@nongnu.org; Mon, 20 Jun 2022 12:27:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52112) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3KFH-0005Li-Hf for qemu-devel@nongnu.org; Mon, 20 Jun 2022 12:27:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655742442; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EA7ONpO+2HIMdqqzStXL4UXUjmQpxaOF0OuP5bUaEhM=; b=fS9IidYJVF+wGHdPwwKDkmvDh/xH7CRlFdkEljzeaCzxk0l/NFp2D1ClnZDskKuccq+TXo dNOL3hyvJ6rv0bBA/iRQy1FivvU78pMOZYdqDx+Vb+eohwiZf9k0eTZo/2No7LUSYQazPk TVwgsNRNl231+7wwumoEzwp7tW3Dzr8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-142-hoQ9ENP1NN2TtW2e6kEMww-1; Mon, 20 Jun 2022 12:27:19 -0400 X-MC-Unique: hoQ9ENP1NN2TtW2e6kEMww-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2E829801756; Mon, 20 Jun 2022 16:27:19 +0000 (UTC) Received: from localhost (unknown [10.39.193.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BDA502166B26; Mon, 20 Jun 2022 16:27:18 +0000 (UTC) From: Hanna Reitz To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Reitz , Kevin Wolf , Eric Blake , Markus Armbruster Subject: [PATCH v2 08/12] block/qapi: Add indentation to bdrv_node_info_dump() Date: Mon, 20 Jun 2022 18:27:00 +0200 Message-Id: <20220620162704.80987-9-hreitz@redhat.com> In-Reply-To: <20220620162704.80987-1-hreitz@redhat.com> References: <20220620162704.80987-1-hreitz@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass client-ip=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" In order to let qemu-img info present a block graph, add a parameter to bdrv_node_info_dump() and bdrv_image_info_specific_dump() so that the information of nodes below the root level can be given an indentation. Signed-off-by: Hanna Reitz --- include/block/qapi.h | 5 ++-- block/monitor/block-hmp-cmds.c | 2 +- block/qapi.c | 47 +++++++++++++++++++--------------- qemu-img.c | 2 +- qemu-io-cmds.c | 3 ++- 5 files changed, 34 insertions(+), 25 deletions(-) diff --git a/include/block/qapi.h b/include/block/qapi.h index 196436020e..38855f2ae9 100644 --- a/include/block/qapi.h +++ b/include/block/qapi.h @@ -49,6 +49,7 @@ void bdrv_query_block_graph_info(BlockDriverState *bs, void bdrv_snapshot_dump(QEMUSnapshotInfo *sn); void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec, - const char *prefix); -void bdrv_node_info_dump(BlockNodeInfo *info); + const char *prefix, + int indentation); +void bdrv_node_info_dump(BlockNodeInfo *info, int indentation); #endif diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index d286f2d1c5..a63c25c208 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -734,7 +734,7 @@ static void print_block_info(Monitor *mon, BlockInfo *info, monitor_printf(mon, "\nImages:\n"); image_info = inserted->image; while (1) { - bdrv_node_info_dump(qapi_ImageInfo_base(image_info)); + bdrv_node_info_dump(qapi_ImageInfo_base(image_info), 0); if (image_info->has_backing_image) { image_info = image_info->backing_image; } else { diff --git a/block/qapi.c b/block/qapi.c index f208c21ccf..3e35603f0c 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -915,7 +915,8 @@ static bool qobject_is_empty_dump(const QObject *obj) * prepending an optional prefix if the dump is not empty. */ void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec, - const char *prefix) + const char *prefix, + int indentation) { QObject *obj, *data; Visitor *v = qobject_output_visitor_new(&obj); @@ -925,48 +926,51 @@ void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec, data = qdict_get(qobject_to(QDict, obj), "data"); if (!qobject_is_empty_dump(data)) { if (prefix) { - qemu_printf("%s", prefix); + qemu_printf("%*s%s", indentation * 4, "", prefix); } - dump_qobject(1, data); + dump_qobject(indentation + 1, data); } qobject_unref(obj); visit_free(v); } -void bdrv_node_info_dump(BlockNodeInfo *info) +void bdrv_node_info_dump(BlockNodeInfo *info, int indentation) { char *size_buf, *dsize_buf; + g_autofree char *ind_s = g_strdup_printf("%*s", indentation * 4, ""); + if (!info->has_actual_size) { dsize_buf = g_strdup("unavailable"); } else { dsize_buf = size_to_str(info->actual_size); } size_buf = size_to_str(info->virtual_size); - qemu_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); + qemu_printf("%simage: %s\n" + "%sfile format: %s\n" + "%svirtual size: %s (%" PRId64 " bytes)\n" + "%sdisk size: %s\n", + ind_s, info->filename, + ind_s, info->format, + ind_s, size_buf, info->virtual_size, + ind_s, dsize_buf); g_free(size_buf); g_free(dsize_buf); if (info->has_encrypted && info->encrypted) { - qemu_printf("encrypted: yes\n"); + qemu_printf("%sencrypted: yes\n", ind_s); } if (info->has_cluster_size) { - qemu_printf("cluster_size: %" PRId64 "\n", - info->cluster_size); + qemu_printf("%scluster_size: %" PRId64 "\n", + ind_s, info->cluster_size); } if (info->has_dirty_flag && info->dirty_flag) { - qemu_printf("cleanly shut down: no\n"); + qemu_printf("%scleanly shut down: no\n", ind_s); } if (info->has_backing_filename) { - qemu_printf("backing file: %s", info->backing_filename); + qemu_printf("%sbacking file: %s", ind_s, info->backing_filename); if (!info->has_full_backing_filename) { qemu_printf(" (cannot determine actual path)"); } else if (strcmp(info->backing_filename, @@ -975,15 +979,16 @@ void bdrv_node_info_dump(BlockNodeInfo *info) } qemu_printf("\n"); if (info->has_backing_filename_format) { - qemu_printf("backing file format: %s\n", - info->backing_filename_format); + qemu_printf("%sbacking file format: %s\n", + ind_s, info->backing_filename_format); } } if (info->has_snapshots) { SnapshotInfoList *elem; - qemu_printf("Snapshot list:\n"); + qemu_printf("%sSnapshot list:\n", ind_s); + qemu_printf("%s", ind_s); bdrv_snapshot_dump(NULL); qemu_printf("\n"); @@ -1003,6 +1008,7 @@ void bdrv_node_info_dump(BlockNodeInfo *info) pstrcpy(sn.id_str, sizeof(sn.id_str), elem->value->id); pstrcpy(sn.name, sizeof(sn.name), elem->value->name); + qemu_printf("%s", ind_s); bdrv_snapshot_dump(&sn); qemu_printf("\n"); } @@ -1010,6 +1016,7 @@ void bdrv_node_info_dump(BlockNodeInfo *info) if (info->has_format_specific) { bdrv_image_info_specific_dump(info->format_specific, - "Format specific information:\n"); + "Format specific information:\n", + indentation); } } diff --git a/qemu-img.c b/qemu-img.c index 3b1f950c85..f835ce6feb 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2843,7 +2843,7 @@ static void dump_human_image_info_list(BlockNodeInfoList *list) } delim = true; - bdrv_node_info_dump(elem->value); + bdrv_node_info_dump(elem->value, 0); } } diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 084ec44d3b..00f1f78cdd 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -1820,7 +1820,8 @@ static int info_f(BlockBackend *blk, int argc, char **argv) } if (spec_info) { bdrv_image_info_specific_dump(spec_info, - "Format specific information:\n"); + "Format specific information:\n", + 0); qapi_free_ImageInfoSpecific(spec_info); } From patchwork Mon Jun 20 16:27:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanna Czenczek X-Patchwork-Id: 12887940 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DC49CC433EF for ; Mon, 20 Jun 2022 16:36:02 +0000 (UTC) Received: from localhost ([::1]:57714 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o3KNe-0004cP-0H for qemu-devel@archiver.kernel.org; Mon, 20 Jun 2022 12:36:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52696) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3KFK-0005jz-Af for qemu-devel@nongnu.org; Mon, 20 Jun 2022 12:27:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:30683) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3KFH-0005Lf-IN for qemu-devel@nongnu.org; Mon, 20 Jun 2022 12:27:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655742442; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WWQw5X+b1I1YdynXUzAkZPJDrxQO+oK7ACqIgSgve7A=; b=dmIv4RBLu7m9L6L+HTQjuus6/3AlXk8kvRFm44t2bRxaqgkgdnJWexc4MMIgF5hlh9O296 HcBczcwI0SYR3qd/yeUc0UBfm7+IkITUeC6S24mtOmN39+g8oOU1Z/fbfF5BEBq85imNuB 5K8MtkV4Lx2PuIgPBf+1osL+ksHXyxU= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-264-rewff2JnNe-lzrkpoHaIfg-1; Mon, 20 Jun 2022 12:27:21 -0400 X-MC-Unique: rewff2JnNe-lzrkpoHaIfg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B4FE03817A65; Mon, 20 Jun 2022 16:27:20 +0000 (UTC) Received: from localhost (unknown [10.39.193.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 727502166B26; Mon, 20 Jun 2022 16:27:20 +0000 (UTC) From: Hanna Reitz To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Reitz , Kevin Wolf , Eric Blake , Markus Armbruster Subject: [PATCH v2 09/12] iotests: Filter child node information Date: Mon, 20 Jun 2022 18:27:01 +0200 Message-Id: <20220620162704.80987-10-hreitz@redhat.com> In-Reply-To: <20220620162704.80987-1-hreitz@redhat.com> References: <20220620162704.80987-1-hreitz@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass client-ip=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Before we let qemu-img info print child node information, have common.filter, common.rc, and iotests.py filter it from the test output so we get as few reference output changes as possible. Signed-off-by: Hanna Reitz --- tests/qemu-iotests/common.filter | 22 ++++++++++++++-------- tests/qemu-iotests/common.rc | 22 ++++++++++++++-------- tests/qemu-iotests/iotests.py | 18 +++++++++++++++--- 3 files changed, 43 insertions(+), 19 deletions(-) diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter index cc9f1a5891..6b32c7fbfa 100644 --- a/tests/qemu-iotests/common.filter +++ b/tests/qemu-iotests/common.filter @@ -223,6 +223,7 @@ _filter_img_info() discard=0 regex_json_spec_start='^ *"format-specific": \{' + regex_json_child_start='^ *"children": \[' gsed -e "s#$REMOTE_TEST_DIR#TEST_DIR#g" \ -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \ -e "s#$TEST_DIR#TEST_DIR#g" \ @@ -251,20 +252,25 @@ _filter_img_info() -e 's/\(compression type: \)\(zlib\|zstd\)/\1COMPRESSION_TYPE/' \ -e "s/uuid: [-a-f0-9]\\+/uuid: 00000000-0000-0000-0000-000000000000/" | \ while IFS='' read -r line; do - if [[ $format_specific == 1 ]]; then - discard=0 - elif [[ $line == "Format specific information:" ]]; then - discard=1 - elif [[ $line =~ $regex_json_spec_start ]]; then - discard=2 - regex_json_spec_end="^${line%%[^ ]*}\\},? *$" + if [[ $discard == 0 ]]; then + if [[ $format_specific == 0 && $line == "Format specific information:" ]]; then + discard=1 + elif [[ $line =~ "Child node '/" ]]; then + discard=1 + elif [[ $line =~ $regex_json_spec_start ]]; then + discard=2 + regex_json_end="^${line%%[^ ]*}\\},? *$" + elif [[ $line =~ $regex_json_child_start ]]; then + discard=2 + regex_json_end="^${line%%[^ ]*}\\],? *$" + fi fi if [[ $discard == 0 ]]; then echo "$line" elif [[ $discard == 1 && ! $line ]]; then echo discard=0 - elif [[ $discard == 2 && $line =~ $regex_json_spec_end ]]; then + elif [[ $discard == 2 && $line =~ $regex_json_end ]]; then discard=0 fi done diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc index 165b54a61e..0e1fa82ec6 100644 --- a/tests/qemu-iotests/common.rc +++ b/tests/qemu-iotests/common.rc @@ -711,6 +711,7 @@ _img_info() discard=0 regex_json_spec_start='^ *"format-specific": \{' + regex_json_child_start='^ *"children": \[' $QEMU_IMG info $QEMU_IMG_EXTRA_ARGS "$@" "$TEST_IMG" 2>&1 | \ sed -e "s#$REMOTE_TEST_DIR#TEST_DIR#g" \ -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \ @@ -721,20 +722,25 @@ _img_info() -e "/^disk size:/ D" \ -e "/actual-size/ D" | \ while IFS='' read -r line; do - if [[ $format_specific == 1 ]]; then - discard=0 - elif [[ $line == "Format specific information:" ]]; then - discard=1 - elif [[ $line =~ $regex_json_spec_start ]]; then - discard=2 - regex_json_spec_end="^${line%%[^ ]*}\\},? *$" + if [[ $discard == 0 ]]; then + if [[ $format_specific == 0 && $line == "Format specific information:" ]]; then + discard=1 + elif [[ $line =~ "Child node '/" ]]; then + discard=1 + elif [[ $format_specific == 0 && $line =~ $regex_json_spec_start ]]; then + discard=2 + regex_json_end="^${line%%[^ ]*}\\},? *$" + elif [[ $line =~ $regex_json_child_start ]]; then + discard=2 + regex_json_end="^${line%%[^ ]*}\\],? *$" + fi fi if [[ $discard == 0 ]]; then echo "$line" elif [[ $discard == 1 && ! $line ]]; then echo discard=0 - elif [[ $discard == 2 && $line =~ $regex_json_spec_end ]]; then + elif [[ $discard == 2 && $line =~ $regex_json_end ]]; then discard=0 fi done diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index da7d6637e1..94aeb3f3b2 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -329,7 +329,7 @@ def qemu_img_log(*args: str, check: bool = True def img_info_log(filename: str, filter_path: Optional[str] = None, use_image_opts: bool = False, extra_args: Sequence[str] = (), - check: bool = True, + check: bool = True, drop_child_info: bool = True, ) -> None: args = ['info'] if use_image_opts: @@ -342,7 +342,7 @@ def img_info_log(filename: str, filter_path: Optional[str] = None, output = qemu_img(*args, check=check).stdout if not filter_path: filter_path = filename - log(filter_img_info(output, filter_path)) + log(filter_img_info(output, filter_path, drop_child_info)) def qemu_io_wrap_args(args: Sequence[str]) -> List[str]: if '-f' in args or '--image-opts' in args: @@ -642,11 +642,23 @@ def _filter(_key, value): def filter_generated_node_ids(msg): return re.sub("#block[0-9]+", "NODE_NAME", msg) -def filter_img_info(output, filename): +def filter_img_info(output: str, filename: str, + drop_child_info: bool = True) -> str: lines = [] + drop_indented = False for line in output.split('\n'): if 'disk size' in line or 'actual-size' in line: continue + + # Drop child node info + if drop_indented: + if line.startswith(' '): + continue + drop_indented = False + if drop_child_info and "Child node '/" in line: + drop_indented = True + continue + line = line.replace(filename, 'TEST_IMG') line = filter_testfiles(line) line = line.replace(imgfmt, 'IMGFMT') From patchwork Mon Jun 20 16:27:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanna Czenczek X-Patchwork-Id: 12887943 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EC04EC433EF for ; Mon, 20 Jun 2022 16:39:38 +0000 (UTC) Received: from localhost ([::1]:38268 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o3KR7-0002G6-TL for qemu-devel@archiver.kernel.org; Mon, 20 Jun 2022 12:39:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52748) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3KFM-0005lZ-8J for qemu-devel@nongnu.org; Mon, 20 Jun 2022 12:27:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:48776) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3KFK-0005N3-HR for qemu-devel@nongnu.org; Mon, 20 Jun 2022 12:27:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655742446; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MAZeZkYpGCQOItsNFseIPRpqqRPm3vhYpjjCbxi4WWA=; b=OfxZZAkOvoZCSpb3/7XrJp+2n/gjQWr4fDAFvrglZYexWxEG/UF4sLIW/Z/JIxr3LcYdE6 BqyAOVaWcjubCNuE97LwoVNU8y8ZdyjGgKVz9LxWL9ClGIn1diR8+0afiv5EggdtlmNdIX T+nuoFSfxqY3uZnJhztbnlaLfay+ZKE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-388-vcmPXKziNfqiXTnnzxr8pg-1; Mon, 20 Jun 2022 12:27:22 -0400 X-MC-Unique: vcmPXKziNfqiXTnnzxr8pg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4CDE585A580; Mon, 20 Jun 2022 16:27:22 +0000 (UTC) Received: from localhost (unknown [10.39.193.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 098622166B26; Mon, 20 Jun 2022 16:27:21 +0000 (UTC) From: Hanna Reitz To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Reitz , Kevin Wolf , Eric Blake , Markus Armbruster Subject: [PATCH v2 10/12] iotests/106, 214, 308: Read only one size line Date: Mon, 20 Jun 2022 18:27:02 +0200 Message-Id: <20220620162704.80987-11-hreitz@redhat.com> In-Reply-To: <20220620162704.80987-1-hreitz@redhat.com> References: <20220620162704.80987-1-hreitz@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass client-ip=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" These tests read size information (sometimes disk size, sometimes virtual size) from qemu-img info's output. Once qemu-img starts printing info about child nodes, we are going to see multiple instances of that per image, but these tests are only interested in the first one, so use "head -n 1" to get it. Signed-off-by: Hanna Reitz --- tests/qemu-iotests/106 | 4 ++-- tests/qemu-iotests/214 | 6 ++++-- tests/qemu-iotests/308 | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/qemu-iotests/106 b/tests/qemu-iotests/106 index 9d6adb542d..ae0fc46691 100755 --- a/tests/qemu-iotests/106 +++ b/tests/qemu-iotests/106 @@ -66,7 +66,7 @@ for create_mode in off falloc full; do expected_size=$((expected_size + $GROWTH_SIZE)) fi - actual_size=$($QEMU_IMG info -f "$IMGFMT" "$TEST_IMG" | grep 'disk size') + actual_size=$($QEMU_IMG info -f "$IMGFMT" "$TEST_IMG" | grep 'disk size' | head -n 1) actual_size=$(echo "$actual_size" | sed -e 's/^[^0-9]*\([0-9]\+\).*$/\1/') # The actual size may exceed the expected size, depending on the file @@ -105,7 +105,7 @@ for growth_mode in falloc full; do _make_test_img -o "extent_size_hint=0" 2G $QEMU_IMG resize -f "$IMGFMT" --preallocation=$growth_mode "$TEST_IMG" +${GROWTH_SIZE}K - actual_size=$($QEMU_IMG info -f "$IMGFMT" "$TEST_IMG" | grep 'disk size') + actual_size=$($QEMU_IMG info -f "$IMGFMT" "$TEST_IMG" | grep 'disk size' | head -n 1) actual_size=$(echo "$actual_size" | sed -e 's/^[^0-9]*\([0-9]\+\).*$/\1/') if [ $actual_size -lt $GROWTH_SIZE ]; then diff --git a/tests/qemu-iotests/214 b/tests/qemu-iotests/214 index c66e246ba2..55ffcd7f44 100755 --- a/tests/qemu-iotests/214 +++ b/tests/qemu-iotests/214 @@ -102,7 +102,8 @@ let data_size="8 * $cluster_size" $QEMU_IO -c "write -P 0xaa 0 $data_size" "$TEST_IMG" \ 2>&1 | _filter_qemu_io | _filter_testdir sizeA=$($QEMU_IMG info --output=json "$TEST_IMG" | - sed -n '/"actual-size":/ s/[^0-9]//gp') + sed -n '/"actual-size":/ s/[^0-9]//gp' | + head -n 1) _make_test_img 2M -o cluster_size=$cluster_size echo "Write compressed data:" @@ -124,7 +125,8 @@ $QEMU_IO -c "write -P 0xcc $offset $data_size" "json:{\ _filter_qemu_io | _filter_testdir sizeB=$($QEMU_IMG info --output=json "$TEST_IMG" | - sed -n '/"actual-size":/ s/[^0-9]//gp') + sed -n '/"actual-size":/ s/[^0-9]//gp' | + head -n 1) if [ $sizeA -lt $sizeB ] then diff --git a/tests/qemu-iotests/308 b/tests/qemu-iotests/308 index bde4aac2fa..09275e9a10 100755 --- a/tests/qemu-iotests/308 +++ b/tests/qemu-iotests/308 @@ -217,12 +217,12 @@ echo echo '=== Remove export ===' # Double-check that $EXT_MP appears as a non-empty file (the raw image) -$QEMU_IMG info -f raw "$EXT_MP" | grep 'virtual size' +$QEMU_IMG info -f raw "$EXT_MP" | grep 'virtual size' | head -n 1 fuse_export_del 'export-mp' # See that the file appears empty again -$QEMU_IMG info -f raw "$EXT_MP" | grep 'virtual size' +$QEMU_IMG info -f raw "$EXT_MP" | grep 'virtual size' | head -n 1 echo echo '=== Writable export ===' From patchwork Mon Jun 20 16:27:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanna Czenczek X-Patchwork-Id: 12887944 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 49BB1C43334 for ; Mon, 20 Jun 2022 16:40:07 +0000 (UTC) Received: from localhost ([::1]:40714 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o3KRa-0003yu-Cv for qemu-devel@archiver.kernel.org; Mon, 20 Jun 2022 12:40:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52782) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3KFO-0005ni-07 for qemu-devel@nongnu.org; Mon, 20 Jun 2022 12:27:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:56973) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3KFM-0005Na-46 for qemu-devel@nongnu.org; Mon, 20 Jun 2022 12:27:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655742447; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QJ8Nuc3zkFJwQM3cTVy/o2w2yLOJqNRxWSNZG+R81Yo=; b=OyHcDg37/1mJvxNlEZitJEcgncKggp0lLfsUjxDgYuNhOYFITcntziE7M3UXWJYWMEN0oZ bX83+pYGSFSC/Z6Kmek00zsFUrjQ83YgD/tQGa/viXQK6nvX1tn4juESGDXslQAILpDKUm +uauXgRscV/dWZw1YN6KdpaZ/YoK5To= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-222-7C6cLFItPIOs5PhVMZ0zlQ-1; Mon, 20 Jun 2022 12:27:24 -0400 X-MC-Unique: 7C6cLFItPIOs5PhVMZ0zlQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 27CE4811E75; Mon, 20 Jun 2022 16:27:24 +0000 (UTC) Received: from localhost (unknown [10.39.193.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B678D2166B26; Mon, 20 Jun 2022 16:27:23 +0000 (UTC) From: Hanna Reitz To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Reitz , Kevin Wolf , Eric Blake , Markus Armbruster Subject: [PATCH v2 11/12] qemu-img: Let info print block graph Date: Mon, 20 Jun 2022 18:27:03 +0200 Message-Id: <20220620162704.80987-12-hreitz@redhat.com> In-Reply-To: <20220620162704.80987-1-hreitz@redhat.com> References: <20220620162704.80987-1-hreitz@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass client-ip=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" For every node in the backing chain, collect its BlockGraphInfo struct using bdrv_query_block_graph_info(). Print all nodes' information, indenting child nodes and labelling them with a path constructed from the child names leading to the node from the root (e.g. /file/file). Note that we open each image with BDRV_O_NO_BACKING, so its backing child is omitted from this graph, and thus presented in the previous manner: By simply concatenating all images' information, separated with blank lines. This affects two iotests: - 065: Here we try to get the format node's format specific information. The pre-patch code does so by taking all lines from "Format specific information:" until an empty line. This format specific information is no longer followed by an empty line, though, but by child node information, so limit the range by "Child node '/file':". - 302: Calls qemu_img() for qemu-img info directly, which does not filter the output, so the child node information ends up in the output. Signed-off-by: Hanna Reitz --- qapi/block-core.json | 4 +-- qemu-img.c | 69 ++++++++++++++++++++++++++------------ tests/qemu-iotests/065 | 2 +- tests/qemu-iotests/302.out | 5 +++ 4 files changed, 56 insertions(+), 24 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index b7e5708487..5597c783e7 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -5715,9 +5715,9 @@ ## # @DummyBlockCoreForceArrays: # -# Not used by QMP; hack to let us use BlockNodeInfoList internally +# Not used by QMP; hack to let us use BlockGraphInfoList internally # # Since: 7.1 ## { 'struct': 'DummyBlockCoreForceArrays', - 'data': { 'unused-block-node-info': ['BlockNodeInfo'] } } + 'data': { 'unused-block-graph-info': ['BlockGraphInfo'] } } diff --git a/qemu-img.c b/qemu-img.c index f835ce6feb..6da4064d57 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2800,13 +2800,13 @@ static void dump_snapshots(BlockDriverState *bs) g_free(sn_tab); } -static void dump_json_block_node_info_list(BlockNodeInfoList *list) +static void dump_json_block_graph_info_list(BlockGraphInfoList *list) { GString *str; QObject *obj; Visitor *v = qobject_output_visitor_new(&obj); - visit_type_BlockNodeInfoList(v, NULL, &list, &error_abort); + visit_type_BlockGraphInfoList(v, NULL, &list, &error_abort); visit_complete(v, &obj); str = qobject_to_json_pretty(obj, true); assert(str != NULL); @@ -2816,13 +2816,13 @@ static void dump_json_block_node_info_list(BlockNodeInfoList *list) g_string_free(str, true); } -static void dump_json_block_node_info(BlockNodeInfo *info) +static void dump_json_block_graph_info(BlockGraphInfo *info) { GString *str; QObject *obj; Visitor *v = qobject_output_visitor_new(&obj); - visit_type_BlockNodeInfo(v, NULL, &info, &error_abort); + visit_type_BlockGraphInfo(v, NULL, &info, &error_abort); visit_complete(v, &obj); str = qobject_to_json_pretty(obj, true); assert(str != NULL); @@ -2832,9 +2832,29 @@ static void dump_json_block_node_info(BlockNodeInfo *info) g_string_free(str, true); } -static void dump_human_image_info_list(BlockNodeInfoList *list) +static void dump_human_image_info(BlockGraphInfo *info, int indentation, + const char *path) { - BlockNodeInfoList *elem; + BlockChildInfoList *children_list; + + bdrv_node_info_dump(qapi_BlockGraphInfo_base(info), indentation); + + for (children_list = info->children; children_list; + children_list = children_list->next) + { + BlockChildInfo *child = children_list->value; + g_autofree char *child_path; + + printf("%*sChild node '%s%s':\n", + indentation * 4, "", path, child->name); + child_path = g_strdup_printf("%s%s/", path, child->name); + dump_human_image_info(child->info, indentation + 1, child_path); + } +} + +static void dump_human_image_info_list(BlockGraphInfoList *list) +{ + BlockGraphInfoList *elem; bool delim = false; for (elem = list; elem; elem = elem->next) { @@ -2843,7 +2863,7 @@ static void dump_human_image_info_list(BlockNodeInfoList *list) } delim = true; - bdrv_node_info_dump(elem->value, 0); + dump_human_image_info(elem->value, 0, "/"); } } @@ -2853,7 +2873,7 @@ static gboolean str_equal_func(gconstpointer a, gconstpointer b) } /** - * Open an image file chain and return an BlockNodeInfoList + * Open an image file chain and return an BlockGraphInfoList * * @filename: topmost image filename * @fmt: topmost image format (may be NULL to autodetect) @@ -2864,13 +2884,13 @@ static gboolean str_equal_func(gconstpointer a, gconstpointer b) * opening an image file. If there was an error a message will have been * printed to stderr. */ -static BlockNodeInfoList *collect_image_info_list(bool image_opts, - const char *filename, - const char *fmt, - bool chain, bool force_share) +static BlockGraphInfoList *collect_image_info_list(bool image_opts, + const char *filename, + const char *fmt, + bool chain, bool force_share) { - BlockNodeInfoList *head = NULL; - BlockNodeInfoList **tail = &head; + BlockGraphInfoList *head = NULL; + BlockGraphInfoList **tail = &head; GHashTable *filenames; Error *err = NULL; @@ -2879,7 +2899,7 @@ static BlockNodeInfoList *collect_image_info_list(bool image_opts, while (filename) { BlockBackend *blk; BlockDriverState *bs; - BlockNodeInfo *info; + BlockGraphInfo *info; if (g_hash_table_lookup_extended(filenames, filename, NULL, NULL)) { error_report("Backing file '%s' creates an infinite loop.", @@ -2896,7 +2916,14 @@ static BlockNodeInfoList *collect_image_info_list(bool image_opts, } bs = blk_bs(blk); - bdrv_query_block_node_info(bs, &info, &err); + /* + * Note that the returned BlockGraphInfo object will not have + * information about this image's backing node, because we have opened + * it with BDRV_O_NO_BACKING. Printing this object will therefore not + * duplicate the backing chain information that we obtain by walking + * the chain manually here. + */ + bdrv_query_block_graph_info(bs, &info, &err); if (err) { error_report_err(err); blk_unref(blk); @@ -2929,7 +2956,7 @@ static BlockNodeInfoList *collect_image_info_list(bool image_opts, return head; err: - qapi_free_BlockNodeInfoList(head); + qapi_free_BlockGraphInfoList(head); g_hash_table_destroy(filenames); return NULL; } @@ -2940,7 +2967,7 @@ static int img_info(int argc, char **argv) OutputFormat output_format = OFORMAT_HUMAN; bool chain = false; const char *filename, *fmt, *output; - BlockNodeInfoList *list; + BlockGraphInfoList *list; bool image_opts = false; bool force_share = false; @@ -3019,14 +3046,14 @@ static int img_info(int argc, char **argv) break; case OFORMAT_JSON: if (chain) { - dump_json_block_node_info_list(list); + dump_json_block_graph_info_list(list); } else { - dump_json_block_node_info(list->value); + dump_json_block_graph_info(list->value); } break; } - qapi_free_BlockNodeInfoList(list); + qapi_free_BlockGraphInfoList(list); return 0; } diff --git a/tests/qemu-iotests/065 b/tests/qemu-iotests/065 index b724c89c7c..b76701c71e 100755 --- a/tests/qemu-iotests/065 +++ b/tests/qemu-iotests/065 @@ -56,7 +56,7 @@ class TestQemuImgInfo(TestImageInfoSpecific): def test_human(self): data = qemu_img('info', '--output=human', test_img).stdout.split('\n') data = data[(data.index('Format specific information:') + 1) - :data.index('')] + :data.index("Child node '/file':")] for field in data: self.assertTrue(re.match('^ {4}[^ ]', field) is not None) data = [line.strip() for line in data] diff --git a/tests/qemu-iotests/302.out b/tests/qemu-iotests/302.out index 3e7c281b91..edfa1c4f05 100644 --- a/tests/qemu-iotests/302.out +++ b/tests/qemu-iotests/302.out @@ -4,6 +4,11 @@ image: nbd+unix:///exp?socket=SOCK_DIR/PID-nbd-sock file format: raw virtual size: 448 KiB (458752 bytes) disk size: unavailable +Child node '/file': + image: nbd+unix:///exp?socket=SOCK_DIR/PID-nbd-sock + file format: nbd + virtual size: 448 KiB (458752 bytes) + disk size: unavailable === Converted image info === image: TEST_IMG From patchwork Mon Jun 20 16:27:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanna Czenczek X-Patchwork-Id: 12887945 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BCDE9C43334 for ; Mon, 20 Jun 2022 16:41:08 +0000 (UTC) Received: from localhost ([::1]:43328 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o3KSZ-0005ov-Tp for qemu-devel@archiver.kernel.org; Mon, 20 Jun 2022 12:41:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52824) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3KFP-0005pZ-J8 for qemu-devel@nongnu.org; Mon, 20 Jun 2022 12:27:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:21174) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3KFN-0005O0-C3 for qemu-devel@nongnu.org; Mon, 20 Jun 2022 12:27:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655742448; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oX8yxx0QBnmbAYhzhtCxIgoNrNucW6Qfs9ClSyrsx00=; b=DxqcU2RVqvj56G/GwHAvPxphjk4mcm9vvX1NTAf0hPiXzVHI6fZjl/Q7MsnqpJkUjtpPfo 3ctAsiubmK4Tu6z4FzGPD1g8P+NFAQRuMnLRTQXafEpXsbmyoIB2/xDXNxvbO2n4JCdbfF 0JvcSYwoZrXggtdwgNTNRBX2nagWoAo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-491-qTv6pwhhP7SlzT9igizF2g-1; Mon, 20 Jun 2022 12:27:26 -0400 X-MC-Unique: qTv6pwhhP7SlzT9igizF2g-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CEAB480B70F; Mon, 20 Jun 2022 16:27:25 +0000 (UTC) Received: from localhost (unknown [10.39.193.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 692ED2166B26; Mon, 20 Jun 2022 16:27:25 +0000 (UTC) From: Hanna Reitz To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Reitz , Kevin Wolf , Eric Blake , Markus Armbruster Subject: [PATCH v2 12/12] qemu-img: Change info key names for protocol nodes Date: Mon, 20 Jun 2022 18:27:04 +0200 Message-Id: <20220620162704.80987-13-hreitz@redhat.com> In-Reply-To: <20220620162704.80987-1-hreitz@redhat.com> References: <20220620162704.80987-1-hreitz@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass client-ip=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Currently, when querying a qcow2 image, qemu-img info reports something like this: image: test.qcow2 file format: qcow2 virtual size: 64 MiB (67108864 bytes) disk size: 196 KiB cluster_size: 65536 Format specific information: compat: 1.1 compression type: zlib lazy refcounts: false refcount bits: 16 corrupt: false extended l2: false Child node '/file': image: test.qcow2 file format: file virtual size: 192 KiB (197120 bytes) disk size: 196 KiB Format specific information: extent size hint: 1048576 Notably, the way the keys are named is specific for image files: The filename is shown under "image", the BDS driver under "file format", and the BDS length under "virtual size". This does not make much sense for nodes that are not actually supposed to be guest images, like the /file child node shown above. Give bdrv_node_info_dump() a @protocol parameter that gives a hint that the respective node is probably just used for data storage and does not necessarily present the data for a VM guest disk. This renames the keys so that with this patch, the output becomes: image: test.qcow2 [...] Child node '/file': filename: test.qcow2 protocol type: file file length: 192 KiB (197120 bytes) disk size: 196 KiB Format specific information: extent size hint: 1048576 (Perhaps we should also rename "Format specific information", but I could not come up with anything better that will not become problematic if we guess wrong with the protocol "heuristic".) This change affects iotest 302, which has protocol node information in its reference output. Signed-off-by: Hanna Reitz --- This patch is completely optional and just based on personal preference. I just don't like e.g. how the child node is called an "image" when it's pretty much unusable as a guest image, or how "virtual size" is there twice but with different values. --- include/block/qapi.h | 2 +- block/monitor/block-hmp-cmds.c | 2 +- block/qapi.c | 39 ++++++++++++++++++++++++++++------ qemu-img.c | 3 ++- tests/qemu-iotests/302.out | 6 +++--- 5 files changed, 39 insertions(+), 13 deletions(-) diff --git a/include/block/qapi.h b/include/block/qapi.h index 38855f2ae9..26113da21a 100644 --- a/include/block/qapi.h +++ b/include/block/qapi.h @@ -51,5 +51,5 @@ void bdrv_snapshot_dump(QEMUSnapshotInfo *sn); void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec, const char *prefix, int indentation); -void bdrv_node_info_dump(BlockNodeInfo *info, int indentation); +void bdrv_node_info_dump(BlockNodeInfo *info, int indentation, bool protocol); #endif diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index a63c25c208..a8067846b2 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -734,7 +734,7 @@ static void print_block_info(Monitor *mon, BlockInfo *info, monitor_printf(mon, "\nImages:\n"); image_info = inserted->image; while (1) { - bdrv_node_info_dump(qapi_ImageInfo_base(image_info), 0); + bdrv_node_info_dump(qapi_ImageInfo_base(image_info), 0, false); if (image_info->has_backing_image) { image_info = image_info->backing_image; } else { diff --git a/block/qapi.c b/block/qapi.c index 3e35603f0c..56f398c500 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -934,24 +934,49 @@ void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec, visit_free(v); } -void bdrv_node_info_dump(BlockNodeInfo *info, int indentation) +/** + * Print the given @info object in human-readable form. Every field is indented + * using the given @indentation (four spaces per indentation level). + * + * When using this to print a whole block graph, @protocol can be set to true to + * signify that the given information is associated with a protocol node, i.e. + * just data storage for an image, such that the data it presents is not really + * a full VM disk. If so, several fields change name: For example, "virtual + * size" is printed as "file length". + * (Consider a qcow2 image, which is represented by a qcow2 node and a file + * node. Printing a "virtual size" for the file node does not make sense, + * because without the qcow2 node, it is not really a guest disk, so it does not + * have a "virtual size". Therefore, we call it "file length" instead.) + * + * @protocol is ignored when @indentation is 0, because we take that to mean + * that the associated node is the root node in the queried block graph, and + * thus is always to be interpreted as a standalone guest disk. + */ +void bdrv_node_info_dump(BlockNodeInfo *info, int indentation, bool protocol) { char *size_buf, *dsize_buf; g_autofree char *ind_s = g_strdup_printf("%*s", indentation * 4, ""); + if (indentation == 0) { + /* Top level, consider this a normal image */ + protocol = false; + } + if (!info->has_actual_size) { dsize_buf = g_strdup("unavailable"); } else { dsize_buf = size_to_str(info->actual_size); } size_buf = size_to_str(info->virtual_size); - qemu_printf("%simage: %s\n" - "%sfile format: %s\n" - "%svirtual size: %s (%" PRId64 " bytes)\n" + qemu_printf("%s%s: %s\n" + "%s%s: %s\n" + "%s%s: %s (%" PRId64 " bytes)\n" "%sdisk size: %s\n", - ind_s, info->filename, - ind_s, info->format, - ind_s, size_buf, info->virtual_size, + ind_s, protocol ? "filename" : "image", info->filename, + ind_s, protocol ? "protocol type" : "file format", + info->format, + ind_s, protocol ? "file length" : "virtual size", + size_buf, info->virtual_size, ind_s, dsize_buf); g_free(size_buf); g_free(dsize_buf); diff --git a/qemu-img.c b/qemu-img.c index 6da4064d57..17ccde5448 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2837,7 +2837,8 @@ static void dump_human_image_info(BlockGraphInfo *info, int indentation, { BlockChildInfoList *children_list; - bdrv_node_info_dump(qapi_BlockGraphInfo_base(info), indentation); + bdrv_node_info_dump(qapi_BlockGraphInfo_base(info), indentation, + info->children == NULL); for (children_list = info->children; children_list; children_list = children_list->next) diff --git a/tests/qemu-iotests/302.out b/tests/qemu-iotests/302.out index edfa1c4f05..7b5014cdd8 100644 --- a/tests/qemu-iotests/302.out +++ b/tests/qemu-iotests/302.out @@ -5,9 +5,9 @@ file format: raw virtual size: 448 KiB (458752 bytes) disk size: unavailable Child node '/file': - image: nbd+unix:///exp?socket=SOCK_DIR/PID-nbd-sock - file format: nbd - virtual size: 448 KiB (458752 bytes) + filename: nbd+unix:///exp?socket=SOCK_DIR/PID-nbd-sock + protocol type: nbd + file length: 448 KiB (458752 bytes) disk size: unavailable === Converted image info ===