From nobody Wed Apr 16 08:02:02 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528727713188485.01682983786486; Mon, 11 Jun 2018 07:35:13 -0700 (PDT) Received: from localhost ([::1]:49186 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNua-0002Sj-D0 for importer@patchew.org; Mon, 11 Jun 2018 10:35:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52905) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNmF-0004OP-KY for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNmC-0001eA-B8 for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:35 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55638 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNm7-0001be-Pf; Mon, 11 Jun 2018 10:26:27 -0400 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 mx1.redhat.com (Postfix) with ESMTPS id 62B6340BC04D; Mon, 11 Jun 2018 14:26:27 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DB67E2028672; Mon, 11 Jun 2018 14:26:26 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:25:49 +0200 Message-Id: <20180611142611.6609-8-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 11 Jun 2018 14:26:27 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 11 Jun 2018 14:26:27 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 07/29] qemu-img: Add print_amend_option_help() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The more generic print_block_option_help() function is not really suitable for qemu-img amend, for a couple of reasons: (1) We do not need to append the protocol-level options, as amendment happens only on one node and does not descend downwards to its children. (2) print_block_option_help() says those options are "supported". For option amendment, we do not really know that. So this new function explicitly says that those options are the creation options, and not all of them may be supported. (3) If the driver does not support option amendment, we should not print anything (except for an error message that amendment is not supported). Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=3D1537956 Signed-off-by: Max Reitz Reviewed-by: John Snow Reviewed-by: Eric Blake Message-id: 20180509210023.20283-5-mreitz@redhat.com Signed-off-by: Max Reitz --- qemu-img.c | 30 ++++++++++++++++++++++++-- tests/qemu-iotests/082.out | 44 +++++++++++++++++++++++--------------- 2 files changed, 55 insertions(+), 19 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 52008c5647..07935cb232 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3658,6 +3658,32 @@ static void amend_status_cb(BlockDriverState *bs, qemu_progress_print(100.f * offset / total_work_size, 0); } =20 +static int print_amend_option_help(const char *format) +{ + BlockDriver *drv; + + /* Find driver and parse its options */ + drv =3D bdrv_find_format(format); + if (!drv) { + error_report("Unknown file format '%s'", format); + return 1; + } + + if (!drv->bdrv_amend_options) { + error_report("Format driver '%s' does not support option amendment= ", + format); + return 1; + } + + /* Every driver supporting amendment must have create_opts */ + assert(drv->create_opts); + + printf("Creation options for '%s':\n", format); + qemu_opts_print_help(drv->create_opts); + printf("\nNote that not all of these options may be amendable.\n"); + return 0; +} + static int img_amend(int argc, char **argv) { Error *err =3D NULL; @@ -3757,7 +3783,7 @@ static int img_amend(int argc, char **argv) if (fmt && has_help_option(options)) { /* If a format is explicitly specified (and possibly no filename is * given), print option help here */ - ret =3D print_block_option_help(filename, fmt); + ret =3D print_amend_option_help(fmt); goto out; } =20 @@ -3786,7 +3812,7 @@ static int img_amend(int argc, char **argv) =20 if (has_help_option(options)) { /* If the format was auto-detected, print option help here */ - ret =3D print_block_option_help(filename, fmt); + ret =3D print_amend_option_help(fmt); goto out; } =20 diff --git a/tests/qemu-iotests/082.out b/tests/qemu-iotests/082.out index 1527fbe1b7..4e52dce8d6 100644 --- a/tests/qemu-iotests/082.out +++ b/tests/qemu-iotests/082.out @@ -546,7 +546,7 @@ cluster_size: 65536 =3D=3D=3D amend: help for -o =3D=3D=3D =20 Testing: amend -f qcow2 -o help TEST_DIR/t.qcow2 -Supported options: +Creation options for 'qcow2': size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image @@ -564,10 +564,11 @@ cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates refcount_bits Width of a reference count entry in bits -nocow Turn off copy-on-write (valid only on btrfs) + +Note that not all of these options may be amendable. =20 Testing: amend -f qcow2 -o ? TEST_DIR/t.qcow2 -Supported options: +Creation options for 'qcow2': size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image @@ -585,10 +586,11 @@ cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates refcount_bits Width of a reference count entry in bits -nocow Turn off copy-on-write (valid only on btrfs) + +Note that not all of these options may be amendable. =20 Testing: amend -f qcow2 -o cluster_size=3D4k,help TEST_DIR/t.qcow2 -Supported options: +Creation options for 'qcow2': size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image @@ -606,10 +608,11 @@ cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates refcount_bits Width of a reference count entry in bits -nocow Turn off copy-on-write (valid only on btrfs) + +Note that not all of these options may be amendable. =20 Testing: amend -f qcow2 -o cluster_size=3D4k,? TEST_DIR/t.qcow2 -Supported options: +Creation options for 'qcow2': size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image @@ -627,10 +630,11 @@ cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates refcount_bits Width of a reference count entry in bits -nocow Turn off copy-on-write (valid only on btrfs) + +Note that not all of these options may be amendable. =20 Testing: amend -f qcow2 -o help,cluster_size=3D4k TEST_DIR/t.qcow2 -Supported options: +Creation options for 'qcow2': size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image @@ -648,10 +652,11 @@ cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates refcount_bits Width of a reference count entry in bits -nocow Turn off copy-on-write (valid only on btrfs) + +Note that not all of these options may be amendable. =20 Testing: amend -f qcow2 -o ?,cluster_size=3D4k TEST_DIR/t.qcow2 -Supported options: +Creation options for 'qcow2': size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image @@ -669,10 +674,11 @@ cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates refcount_bits Width of a reference count entry in bits -nocow Turn off copy-on-write (valid only on btrfs) + +Note that not all of these options may be amendable. =20 Testing: amend -f qcow2 -o cluster_size=3D4k -o help TEST_DIR/t.qcow2 -Supported options: +Creation options for 'qcow2': size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image @@ -690,10 +696,11 @@ cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates refcount_bits Width of a reference count entry in bits -nocow Turn off copy-on-write (valid only on btrfs) + +Note that not all of these options may be amendable. =20 Testing: amend -f qcow2 -o cluster_size=3D4k -o ? TEST_DIR/t.qcow2 -Supported options: +Creation options for 'qcow2': size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image @@ -711,7 +718,8 @@ cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates refcount_bits Width of a reference count entry in bits -nocow Turn off copy-on-write (valid only on btrfs) + +Note that not all of these options may be amendable. =20 Testing: amend -f qcow2 -o backing_file=3DTEST_DIR/t.qcow2,,help TEST_DIR/= t.qcow2 =20 @@ -731,7 +739,7 @@ Testing: amend -f qcow2 -o backing_file=3DTEST_DIR/t.qc= ow2 -o ,, -o help TEST_DIR/ qemu-img: Invalid option list: ,, =20 Testing: amend -f qcow2 -o help -Supported options: +Creation options for 'qcow2': size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image @@ -750,6 +758,8 @@ preallocation Preallocation mode (allowed values: of= f, metadata, falloc, full lazy_refcounts Postpone refcount updates refcount_bits Width of a reference count entry in bits =20 +Note that not all of these options may be amendable. + Testing: convert -o help Supported options: size Virtual disk size --=20 2.17.1