From nobody Fri May 3 06:44:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524329829111550.0630718623447; Sat, 21 Apr 2018 09:57:09 -0700 (PDT) Received: from localhost ([::1]:57940 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9vom-000169-G3 for importer@patchew.org; Sat, 21 Apr 2018 12:56:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45150) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9vma-0007sz-IR for qemu-devel@nongnu.org; Sat, 21 Apr 2018 12:54:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f9vmZ-0003A3-S1 for qemu-devel@nongnu.org; Sat, 21 Apr 2018 12:54:40 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44232 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 1f9vmT-000371-R7; Sat, 21 Apr 2018 12:54:33 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0B4F1406C780; Sat, 21 Apr 2018 16:54:32 +0000 (UTC) Received: from localhost (ovpn-204-54.brq.redhat.com [10.40.204.54]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A21AB1C705; Sat, 21 Apr 2018 16:54:31 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Sat, 21 Apr 2018 18:54:17 +0200 Message-Id: <20180421165423.30759-2-mreitz@redhat.com> In-Reply-To: <20180421165423.30759-1-mreitz@redhat.com> References: <20180421165423.30759-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sat, 21 Apr 2018 16:54:32 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sat, 21 Apr 2018 16:54:32 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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] [PATCH 1/7] qemu-img: Amendment support implies create_opts 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 , 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" Instead of checking whether a driver has a non-NULL create_opts we should check whether it supports image amendment in the first place. If it does, it must have create_opts. On the other hand, if it does not have create_opts (so it does not support amendment either), the error message "does not support any options" is a bit useless. Stating clearly that the driver has no amendment support whatsoever is probably better. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- qemu-img.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 855fa52514..f60b22769e 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3709,13 +3709,16 @@ static int img_amend(int argc, char **argv) goto out; } =20 - if (!bs->drv->create_opts) { - error_report("Format driver '%s' does not support any options to a= mend", + if (!bs->drv->bdrv_amend_options) { + error_report("Format driver '%s' does not support option amendment= ", fmt); ret =3D -1; goto out; } =20 + /* Every driver supporting amendment must have create_opts */ + assert(bs->drv->create_opts); + create_opts =3D qemu_opts_append(create_opts, bs->drv->create_opts); opts =3D qemu_opts_create(create_opts, NULL, 0, &error_abort); qemu_opts_do_parse(opts, options, NULL, &err); --=20 2.14.3 From nobody Fri May 3 06:44:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.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 1524329829213832.8588021928458; Sat, 21 Apr 2018 09:57:09 -0700 (PDT) Received: from localhost ([::1]:57942 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9vov-0001Bi-Qz for importer@patchew.org; Sat, 21 Apr 2018 12:57:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45230) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9vmd-0007we-Nn for qemu-devel@nongnu.org; Sat, 21 Apr 2018 12:54:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f9vmb-0003B7-DR for qemu-devel@nongnu.org; Sat, 21 Apr 2018 12:54:43 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34242 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 1f9vmU-00037W-OX; Sat, 21 Apr 2018 12:54:34 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3D99DEC004; Sat, 21 Apr 2018 16:54:34 +0000 (UTC) Received: from localhost (ovpn-204-54.brq.redhat.com [10.40.204.54]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8E3E71C705; Sat, 21 Apr 2018 16:54:33 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Sat, 21 Apr 2018 18:54:18 +0200 Message-Id: <20180421165423.30759-3-mreitz@redhat.com> In-Reply-To: <20180421165423.30759-1-mreitz@redhat.com> References: <20180421165423.30759-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Sat, 21 Apr 2018 16:54:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Sat, 21 Apr 2018 16:54:34 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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] [PATCH 2/7] block: Add Error parameter to bdrv_amend_options 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 , 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" Looking at the qcow2 code that is riddled with error_report() calls, this is really how it should have been from the start. Signed-off-by: Max Reitz --- include/block/block.h | 3 +- include/block/block_int.h | 3 +- block.c | 8 ++++-- block/qcow2.c | 72 ++++++++++++++++++++++++++++++------------= ---- qemu-img.c | 4 +-- tests/qemu-iotests/060.out | 4 +-- tests/qemu-iotests/061.out | 7 ----- tests/qemu-iotests/080.out | 4 +-- tests/qemu-iotests/112.out | 3 -- 9 files changed, 64 insertions(+), 44 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index cdec3639a3..ba9cfec384 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -336,7 +336,8 @@ int bdrv_check(BlockDriverState *bs, BdrvCheckResult *r= es, BdrvCheckMode fix); typedef void BlockDriverAmendStatusCB(BlockDriverState *bs, int64_t offset, int64_t total_work_size, void *opaqu= e); int bdrv_amend_options(BlockDriverState *bs_new, QemuOpts *opts, - BlockDriverAmendStatusCB *status_cb, void *cb_opaqu= e); + BlockDriverAmendStatusCB *status_cb, void *cb_opaqu= e, + Error **errp); =20 /* external snapshots */ bool bdrv_recurse_is_first_non_filter(BlockDriverState *bs, diff --git a/include/block/block_int.h b/include/block/block_int.h index c4dd1d4bb8..d913ed1ea1 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -324,7 +324,8 @@ struct BlockDriver { =20 int (*bdrv_amend_options)(BlockDriverState *bs, QemuOpts *opts, BlockDriverAmendStatusCB *status_cb, - void *cb_opaque); + void *cb_opaque, + Error **errp); =20 void (*bdrv_debug_event)(BlockDriverState *bs, BlkdebugEvent event); =20 diff --git a/block.c b/block.c index a2caadf0a0..fefe1109eb 100644 --- a/block.c +++ b/block.c @@ -4996,15 +4996,19 @@ void bdrv_remove_aio_context_notifier(BlockDriverSt= ate *bs, } =20 int bdrv_amend_options(BlockDriverState *bs, QemuOpts *opts, - BlockDriverAmendStatusCB *status_cb, void *cb_opaqu= e) + BlockDriverAmendStatusCB *status_cb, void *cb_opaqu= e, + Error **errp) { if (!bs->drv) { + error_setg(errp, "Node is ejected"); return -ENOMEDIUM; } if (!bs->drv->bdrv_amend_options) { + error_setg(errp, "Block driver '%s' does not support option amendm= ent", + bs->drv->format_name); return -ENOTSUP; } - return bs->drv->bdrv_amend_options(bs, opts, status_cb, cb_opaque); + return bs->drv->bdrv_amend_options(bs, opts, status_cb, cb_opaque, err= p); } =20 /* This function will be called by the bdrv_recurse_is_first_non_filter me= thod diff --git a/block/qcow2.c b/block/qcow2.c index 091088e09e..eb86ba0a2a 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -4049,7 +4049,8 @@ static int qcow2_load_vmstate(BlockDriverState *bs, Q= EMUIOVector *qiov, * have to be removed. */ static int qcow2_downgrade(BlockDriverState *bs, int target_version, - BlockDriverAmendStatusCB *status_cb, void *cb_o= paque) + BlockDriverAmendStatusCB *status_cb, void *cb_o= paque, + Error **errp) { BDRVQcow2State *s =3D bs->opaque; int current_version =3D s->qcow_version; @@ -4058,13 +4059,17 @@ static int qcow2_downgrade(BlockDriverState *bs, in= t target_version, if (target_version =3D=3D current_version) { return 0; } else if (target_version > current_version) { + error_setg(errp, "Cannot downgrade an image from version %i to %i", + current_version, target_version); return -EINVAL; } else if (target_version !=3D 2) { + error_setg(errp, "Cannot downgrade an image to version %i (only " + "target version 2 is supported)", target_version); return -EINVAL; } =20 if (s->refcount_order !=3D 4) { - error_report("compat=3D0.10 requires refcount_bits=3D16"); + error_setg(errp, "compat=3D0.10 requires refcount_bits=3D16"); return -ENOTSUP; } =20 @@ -4072,6 +4077,8 @@ static int qcow2_downgrade(BlockDriverState *bs, int = target_version, if (s->incompatible_features & QCOW2_INCOMPAT_DIRTY) { ret =3D qcow2_mark_clean(bs); if (ret < 0) { + error_setg(errp, "Failed to make the image clean: %s", + strerror(-ret)); return ret; } } @@ -4081,6 +4088,8 @@ static int qcow2_downgrade(BlockDriverState *bs, int = target_version, * best thing to do anyway */ =20 if (s->incompatible_features) { + error_setg(errp, "Cannot downgrade an image with incompatible feat= ures " + "%#" PRIx64 " set", s->incompatible_features); return -ENOTSUP; } =20 @@ -4094,6 +4103,8 @@ static int qcow2_downgrade(BlockDriverState *bs, int = target_version, =20 ret =3D qcow2_expand_zero_clusters(bs, status_cb, cb_opaque); if (ret < 0) { + error_setg(errp, "Failed to turn zero into data clusters: %s", + strerror(-ret)); return ret; } =20 @@ -4101,6 +4112,8 @@ static int qcow2_downgrade(BlockDriverState *bs, int = target_version, ret =3D qcow2_update_header(bs); if (ret < 0) { s->qcow_version =3D current_version; + error_setg(errp, "Failed to update the image header: %s", + strerror(-ret)); return ret; } return 0; @@ -4178,7 +4191,8 @@ static void qcow2_amend_helper_cb(BlockDriverState *b= s, =20 static int qcow2_amend_options(BlockDriverState *bs, QemuOpts *opts, BlockDriverAmendStatusCB *status_cb, - void *cb_opaque) + void *cb_opaque, + Error **errp) { BDRVQcow2State *s =3D bs->opaque; int old_version =3D s->qcow_version, new_version =3D old_version; @@ -4190,7 +4204,6 @@ static int qcow2_amend_options(BlockDriverState *bs, = QemuOpts *opts, bool encrypt; int encformat; int refcount_bits =3D s->refcount_bits; - Error *local_err =3D NULL; int ret; QemuOptDesc *desc =3D opts->list->desc; Qcow2AmendHelperCBInfo helper_cb_info; @@ -4211,11 +4224,11 @@ static int qcow2_amend_options(BlockDriverState *bs= , QemuOpts *opts, } else if (!strcmp(compat, "1.1")) { new_version =3D 3; } else { - error_report("Unknown compatibility level %s", compat); + error_setg(errp, "Unknown compatibility level %s", compat); return -EINVAL; } } else if (!strcmp(desc->name, BLOCK_OPT_PREALLOC)) { - error_report("Cannot change preallocation mode"); + error_setg(errp, "Cannot change preallocation mode"); return -ENOTSUP; } else if (!strcmp(desc->name, BLOCK_OPT_SIZE)) { new_size =3D qemu_opt_get_size(opts, BLOCK_OPT_SIZE, 0); @@ -4228,7 +4241,8 @@ static int qcow2_amend_options(BlockDriverState *bs, = QemuOpts *opts, !!s->crypto); =20 if (encrypt !=3D !!s->crypto) { - error_report("Changing the encryption flag is not supporte= d"); + error_setg(errp, + "Changing the encryption flag is not supported"= ); return -ENOTSUP; } } else if (!strcmp(desc->name, BLOCK_OPT_ENCRYPT_FORMAT)) { @@ -4236,17 +4250,19 @@ static int qcow2_amend_options(BlockDriverState *bs= , QemuOpts *opts, qemu_opt_get(opts, BLOCK_OPT_ENCRYPT_FORMAT)); =20 if (encformat !=3D s->crypt_method_header) { - error_report("Changing the encryption format is not suppor= ted"); + error_setg(errp, + "Changing the encryption format is not supporte= d"); return -ENOTSUP; } } else if (g_str_has_prefix(desc->name, "encrypt.")) { - error_report("Changing the encryption parameters is not suppor= ted"); + error_setg(errp, + "Changing the encryption parameters is not supporte= d"); return -ENOTSUP; } else if (!strcmp(desc->name, BLOCK_OPT_CLUSTER_SIZE)) { cluster_size =3D qemu_opt_get_size(opts, BLOCK_OPT_CLUSTER_SIZ= E, cluster_size); if (cluster_size !=3D s->cluster_size) { - error_report("Changing the cluster size is not supported"); + error_setg(errp, "Changing the cluster size is not support= ed"); return -ENOTSUP; } } else if (!strcmp(desc->name, BLOCK_OPT_LAZY_REFCOUNTS)) { @@ -4259,8 +4275,8 @@ static int qcow2_amend_options(BlockDriverState *bs, = QemuOpts *opts, if (refcount_bits <=3D 0 || refcount_bits > 64 || !is_power_of_2(refcount_bits)) { - error_report("Refcount width must be a power of two and ma= y " - "not exceed 64 bits"); + error_setg(errp, "Refcount width must be a power of two an= d " + "may not exceed 64 bits"); return -EINVAL; } } else { @@ -4285,6 +4301,8 @@ static int qcow2_amend_options(BlockDriverState *bs, = QemuOpts *opts, ret =3D qcow2_update_header(bs); if (ret < 0) { s->qcow_version =3D old_version; + error_setg(errp, "Failed to update the image header: %s", + strerror(-ret)); return ret; } } @@ -4293,18 +4311,17 @@ static int qcow2_amend_options(BlockDriverState *bs= , QemuOpts *opts, int refcount_order =3D ctz32(refcount_bits); =20 if (new_version < 3 && refcount_bits !=3D 16) { - error_report("Different refcount widths than 16 bits require " - "compatibility level 1.1 or above (use compat=3D1= .1 or " - "greater)"); + error_setg(errp, "Different refcount widths than 16 bits requi= re " + "compatibility level 1.1 or above (use compat=3D1.1= or " + "greater)"); return -EINVAL; } =20 helper_cb_info.current_operation =3D QCOW2_CHANGING_REFCOUNT_ORDER; ret =3D qcow2_change_refcount_order(bs, refcount_order, &qcow2_amend_helper_cb, - &helper_cb_info, &local_err); + &helper_cb_info, errp); if (ret < 0) { - error_report_err(local_err); return ret; } } @@ -4314,6 +4331,8 @@ static int qcow2_amend_options(BlockDriverState *bs, = QemuOpts *opts, backing_file ?: s->image_backing_file, backing_format ?: s->image_backing_format); if (ret < 0) { + error_setg(errp, "Failed to change the backing file: %s", + strerror(-ret)); return ret; } } @@ -4321,14 +4340,17 @@ static int qcow2_amend_options(BlockDriverState *bs= , QemuOpts *opts, if (s->use_lazy_refcounts !=3D lazy_refcounts) { if (lazy_refcounts) { if (new_version < 3) { - error_report("Lazy refcounts only supported with compatibi= lity " - "level 1.1 and above (use compat=3D1.1 or gre= ater)"); + error_setg(errp, "Lazy refcounts only supported with " + "compatibility level 1.1 and above (use compat= =3D1.1 " + "or greater)"); return -EINVAL; } s->compatible_features |=3D QCOW2_COMPAT_LAZY_REFCOUNTS; ret =3D qcow2_update_header(bs); if (ret < 0) { s->compatible_features &=3D ~QCOW2_COMPAT_LAZY_REFCOUNTS; + error_setg(errp, "Failed to update the image header: %s", + strerror(-ret)); return ret; } s->use_lazy_refcounts =3D true; @@ -4336,6 +4358,8 @@ static int qcow2_amend_options(BlockDriverState *bs, = QemuOpts *opts, /* make image clean first */ ret =3D qcow2_mark_clean(bs); if (ret < 0) { + error_setg(errp, "Failed to make the image clean: %s", + strerror(-ret)); return ret; } /* now disallow lazy refcounts */ @@ -4343,6 +4367,8 @@ static int qcow2_amend_options(BlockDriverState *bs, = QemuOpts *opts, ret =3D qcow2_update_header(bs); if (ret < 0) { s->compatible_features |=3D QCOW2_COMPAT_LAZY_REFCOUNTS; + error_setg(errp, "Failed to update the image header: %s", + strerror(-ret)); return ret; } s->use_lazy_refcounts =3D false; @@ -4351,17 +4377,15 @@ static int qcow2_amend_options(BlockDriverState *bs= , QemuOpts *opts, =20 if (new_size) { BlockBackend *blk =3D blk_new(BLK_PERM_RESIZE, BLK_PERM_ALL); - ret =3D blk_insert_bs(blk, bs, &local_err); + ret =3D blk_insert_bs(blk, bs, errp); if (ret < 0) { - error_report_err(local_err); blk_unref(blk); return ret; } =20 - ret =3D blk_truncate(blk, new_size, PREALLOC_MODE_OFF, &local_err); + ret =3D blk_truncate(blk, new_size, PREALLOC_MODE_OFF, errp); blk_unref(blk); if (ret < 0) { - error_report_err(local_err); return ret; } } @@ -4370,7 +4394,7 @@ static int qcow2_amend_options(BlockDriverState *bs, = QemuOpts *opts, if (new_version < old_version) { helper_cb_info.current_operation =3D QCOW2_DOWNGRADING; ret =3D qcow2_downgrade(bs, new_version, &qcow2_amend_helper_cb, - &helper_cb_info); + &helper_cb_info, errp); if (ret < 0) { return ret; } diff --git a/qemu-img.c b/qemu-img.c index f60b22769e..375fe852e0 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3730,10 +3730,10 @@ static int img_amend(int argc, char **argv) =20 /* In case the driver does not call amend_status_cb() */ qemu_progress_print(0.f, 0); - ret =3D bdrv_amend_options(bs, opts, &amend_status_cb, NULL); + ret =3D bdrv_amend_options(bs, opts, &amend_status_cb, NULL, &err); qemu_progress_print(100.f, 0); if (ret < 0) { - error_report("Error while amending options: %s", strerror(-ret)); + error_report_err(err); goto out; } =20 diff --git a/tests/qemu-iotests/060.out b/tests/qemu-iotests/060.out index 25d5c3938b..5f4264cff6 100644 --- a/tests/qemu-iotests/060.out +++ b/tests/qemu-iotests/060.out @@ -129,7 +129,7 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D671= 08864 wrote 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qcow2: Marking image as corrupt: L2 table offset 0x42a00 unaligned (L1 ind= ex: 0); further corruption events will be suppressed -qemu-img: Error while amending options: Input/output error +qemu-img: Failed to turn zero into data clusters: Input/output error =20 =3D=3D=3D Testing unaligned L2 entry =3D=3D=3D =20 @@ -145,7 +145,7 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D671= 08864 wrote 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qcow2: Marking image as corrupt: Cluster allocation offset 0x52a00 unalign= ed (L2 offset: 0x40000, L2 index: 0); further corruption events will be sup= pressed -qemu-img: Error while amending options: Input/output error +qemu-img: Failed to turn zero into data clusters: Input/output error =20 =3D=3D=3D Testing unaligned reftable entry =3D=3D=3D =20 diff --git a/tests/qemu-iotests/061.out b/tests/qemu-iotests/061.out index e857ef9a7d..183f7dd690 100644 --- a/tests/qemu-iotests/061.out +++ b/tests/qemu-iotests/061.out @@ -358,18 +358,12 @@ No errors were found on the image. =20 Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 qemu-img: Lazy refcounts only supported with compatibility level 1.1 and a= bove (use compat=3D1.1 or greater) -qemu-img: Error while amending options: Invalid argument qemu-img: Lazy refcounts only supported with compatibility level 1.1 and a= bove (use compat=3D1.1 or greater) -qemu-img: Error while amending options: Invalid argument qemu-img: Unknown compatibility level 0.42 -qemu-img: Error while amending options: Invalid argument qemu-img: Invalid parameter 'foo' qemu-img: Changing the cluster size is not supported -qemu-img: Error while amending options: Operation not supported qemu-img: Changing the encryption flag is not supported -qemu-img: Error while amending options: Operation not supported qemu-img: Cannot change preallocation mode -qemu-img: Error while amending options: Operation not supported =20 =3D=3D=3D Testing correct handling of unset value =3D=3D=3D =20 @@ -377,7 +371,6 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D671= 08864 Should work: Should not work: qemu-img: Changing the cluster size is not supported -qemu-img: Error while amending options: Operation not supported =20 =3D=3D=3D Testing zero expansion on inactive clusters =3D=3D=3D =20 diff --git a/tests/qemu-iotests/080.out b/tests/qemu-iotests/080.out index 4e0f7f7b92..281c7e0d1d 100644 --- a/tests/qemu-iotests/080.out +++ b/tests/qemu-iotests/080.out @@ -65,7 +65,7 @@ wrote 512/512 bytes at offset 0 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qemu-img: Failed to load snapshot: Snapshot L1 table offset invalid qemu-img: Snapshot L1 table offset invalid -qemu-img: Error while amending options: Invalid argument +qemu-img: Failed to turn zero into data clusters: Invalid argument Failed to flush the refcount block cache: Invalid argument write failed: Invalid argument qemu-img: Snapshot L1 table offset invalid @@ -88,7 +88,7 @@ wrote 512/512 bytes at offset 0 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qemu-img: Failed to load snapshot: Snapshot L1 table too large qemu-img: Snapshot L1 table too large -qemu-img: Error while amending options: File too large +qemu-img: Failed to turn zero into data clusters: File too large Failed to flush the refcount block cache: File too large write failed: File too large qemu-img: Snapshot L1 table too large diff --git a/tests/qemu-iotests/112.out b/tests/qemu-iotests/112.out index 86f041075d..a23aa1be75 100644 --- a/tests/qemu-iotests/112.out +++ b/tests/qemu-iotests/112.out @@ -99,13 +99,11 @@ refcount bits: 64 =3D=3D=3D Amend to compat=3D0.10 =3D=3D=3D =20 qemu-img: compat=3D0.10 requires refcount_bits=3D16 -qemu-img: Error while amending options: Operation not supported refcount bits: 64 No errors were found on the image. refcount bits: 16 refcount bits: 16 qemu-img: Different refcount widths than 16 bits require compatibility lev= el 1.1 or above (use compat=3D1.1 or greater) -qemu-img: Error while amending options: Invalid argument refcount bits: 16 =20 =3D=3D=3D Amend with snapshot =3D=3D=3D @@ -113,7 +111,6 @@ refcount bits: 16 wrote 16777216/16777216 bytes at offset 0 16 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qemu-img: Cannot decrease refcount entry width to 1 bits: Cluster at offse= t 0x50000 has a refcount of 2 -qemu-img: Error while amending options: Invalid argument No errors were found on the image. refcount bits: 16 No errors were found on the image. --=20 2.14.3 From nobody Fri May 3 06:44:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 15243298291110.7182712081095133; Sat, 21 Apr 2018 09:57:09 -0700 (PDT) Received: from localhost ([::1]:57941 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9vor-000172-Te for importer@patchew.org; Sat, 21 Apr 2018 12:57:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45154) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9vma-0007t5-L6 for qemu-devel@nongnu.org; Sat, 21 Apr 2018 12:54:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f9vmZ-0003AA-UI for qemu-devel@nongnu.org; Sat, 21 Apr 2018 12:54:40 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44236 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 1f9vmW-00038I-Lg; Sat, 21 Apr 2018 12:54:36 -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 27397406C780; Sat, 21 Apr 2018 16:54:36 +0000 (UTC) Received: from localhost (ovpn-204-54.brq.redhat.com [10.40.204.54]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C0E142166BAD; Sat, 21 Apr 2018 16:54:35 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Sat, 21 Apr 2018 18:54:19 +0200 Message-Id: <20180421165423.30759-4-mreitz@redhat.com> In-Reply-To: <20180421165423.30759-1-mreitz@redhat.com> References: <20180421165423.30759-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.5]); Sat, 21 Apr 2018 16:54:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sat, 21 Apr 2018 16:54:36 +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] [PATCH 3/7] qemu-option: Pull out "Supported options" print 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 , 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" It really is up to the caller to decide what this list of options means. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- qemu-img.c | 1 + util/qemu-option.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/qemu-img.c b/qemu-img.c index 375fe852e0..6dd8e95bb2 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -261,6 +261,7 @@ static int print_block_option_help(const char *filename= , const char *fmt) create_opts =3D qemu_opts_append(create_opts, proto_drv->create_op= ts); } =20 + printf("Supported options:\n"); qemu_opts_print_help(create_opts); qemu_opts_free(create_opts); return 0; diff --git a/util/qemu-option.c b/util/qemu-option.c index d0756fda58..95e6cf4e49 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -218,7 +218,6 @@ void qemu_opts_print_help(QemuOptsList *list) =20 assert(list); desc =3D list->desc; - printf("Supported options:\n"); while (desc && desc->name) { printf("%-16s %s\n", desc->name, desc->help ? desc->help : "No description available"); --=20 2.14.3 From nobody Fri May 3 06:44:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.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 1524330006299509.66733092078675; Sat, 21 Apr 2018 10:00:06 -0700 (PDT) Received: from localhost ([::1]:57957 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9vrp-0003pq-Az for importer@patchew.org; Sat, 21 Apr 2018 13:00:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45244) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9vme-0007xD-8F for qemu-devel@nongnu.org; Sat, 21 Apr 2018 12:54:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f9vmc-0003Bx-F1 for qemu-devel@nongnu.org; Sat, 21 Apr 2018 12:54:44 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:58340 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 1f9vmY-000391-Uv; Sat, 21 Apr 2018 12:54:39 -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 79B40410FBB4; Sat, 21 Apr 2018 16:54:38 +0000 (UTC) Received: from localhost (ovpn-204-54.brq.redhat.com [10.40.204.54]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D17212166BAD; Sat, 21 Apr 2018 16:54:37 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Sat, 21 Apr 2018 18:54:20 +0200 Message-Id: <20180421165423.30759-5-mreitz@redhat.com> In-Reply-To: <20180421165423.30759-1-mreitz@redhat.com> References: <20180421165423.30759-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]); Sat, 21 Apr 2018 16:54:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Sat, 21 Apr 2018 16:54:38 +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] [PATCH 4/7] 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 , 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: Eric Blake --- 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 6dd8e95bb2..45e243cc80 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3578,6 +3578,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; @@ -3677,7 +3703,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 @@ -3706,7 +3732,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.14.3 From nobody Fri May 3 06:44:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.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 1524329838125709.3795217787439; Sat, 21 Apr 2018 09:57:18 -0700 (PDT) Received: from localhost ([::1]:57943 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9vp5-0001If-7r for importer@patchew.org; Sat, 21 Apr 2018 12:57:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45245) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9vme-0007xE-8U for qemu-devel@nongnu.org; Sat, 21 Apr 2018 12:54:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f9vmd-0003CL-D4 for qemu-devel@nongnu.org; Sat, 21 Apr 2018 12:54:44 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:43144 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 1f9vmb-0003At-B7; Sat, 21 Apr 2018 12:54:41 -0400 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 mx1.redhat.com (Postfix) with ESMTPS id D810A4023335; Sat, 21 Apr 2018 16:54:40 +0000 (UTC) Received: from localhost (ovpn-204-54.brq.redhat.com [10.40.204.54]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7EC5610B00AD; Sat, 21 Apr 2018 16:54:40 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Sat, 21 Apr 2018 18:54:21 +0200 Message-Id: <20180421165423.30759-6-mreitz@redhat.com> In-Reply-To: <20180421165423.30759-1-mreitz@redhat.com> References: <20180421165423.30759-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Sat, 21 Apr 2018 16:54:40 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Sat, 21 Apr 2018 16:54:40 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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] [PATCH 5/7] qemu-img: Recognize no creation support in -o 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 , 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 only users of print_block_option_help() are qemu-img create and qemu-img convert for the output image, so this function is always used for image creation (it used to be used for amendment also, but that is no longer the case). So if image creation is not supported by either the format or the protocol, there is no need to print any option description, because the user cannot create an image like this anyway. This also fixes an assertion failure: $ qemu-img create -f bochs -o help Supported options: qemu-img: util/qemu-option.c:219: qemu_opts_print_help: Assertion `list' failed. [1] 24831 abort (core dumped) qemu-img create -f bochs -o help Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- qemu-img.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/qemu-img.c b/qemu-img.c index 45e243cc80..29efd80c35 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -250,6 +250,11 @@ static int print_block_option_help(const char *filenam= e, const char *fmt) return 1; } =20 + if (!drv->create_opts) { + error_report("Format driver '%s' does not support image creation",= fmt); + return 1; + } + create_opts =3D qemu_opts_append(create_opts, drv->create_opts); if (filename) { proto_drv =3D bdrv_find_protocol(filename, true, &local_err); @@ -258,6 +263,11 @@ static int print_block_option_help(const char *filenam= e, const char *fmt) qemu_opts_free(create_opts); return 1; } + if (!proto_drv->create_opts) { + error_report("Protocal driver '%s' does not support image crea= tion", + proto_drv->format_name); + return 1; + } create_opts =3D qemu_opts_append(create_opts, proto_drv->create_op= ts); } =20 --=20 2.14.3 From nobody Fri May 3 06:44:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.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 1524330010883220.8914498419855; Sat, 21 Apr 2018 10:00:10 -0700 (PDT) Received: from localhost ([::1]:57960 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9vrt-0003uK-U7 for importer@patchew.org; Sat, 21 Apr 2018 13:00:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45306) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9vmk-000873-Am for qemu-devel@nongnu.org; Sat, 21 Apr 2018 12:54:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f9vmj-0003GP-59 for qemu-devel@nongnu.org; Sat, 21 Apr 2018 12:54:50 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41564 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 1f9vmd-0003CI-KV; Sat, 21 Apr 2018 12:54:43 -0400 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 mx1.redhat.com (Postfix) with ESMTPS id 2771B8185321; Sat, 21 Apr 2018 16:54:43 +0000 (UTC) Received: from localhost (ovpn-204-54.brq.redhat.com [10.40.204.54]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B06E3202699C; Sat, 21 Apr 2018 16:54:42 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Sat, 21 Apr 2018 18:54:22 +0200 Message-Id: <20180421165423.30759-7-mreitz@redhat.com> In-Reply-To: <20180421165423.30759-1-mreitz@redhat.com> References: <20180421165423.30759-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Sat, 21 Apr 2018 16:54:43 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Sat, 21 Apr 2018 16:54:43 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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] [PATCH 6/7] iotests: Test help option for unsupporting formats 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 , 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" This adds test cases to 082 for qemu-img create/convert/amend "-o help" on formats that do not support creation or amendment, respectively. Signed-off-by: Max Reitz Reviewed-by: Eric Blake Reviewed-by: John Snow --- tests/qemu-iotests/082 | 9 +++++++++ tests/qemu-iotests/082.out | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/tests/qemu-iotests/082 b/tests/qemu-iotests/082 index d5c83d45ed..a872f771a6 100755 --- a/tests/qemu-iotests/082 +++ b/tests/qemu-iotests/082 @@ -97,6 +97,9 @@ run_qemu_img create -f $IMGFMT -o backing_file=3D"$TEST_I= MG" -o ,, -o help "$TEST_ run_qemu_img create -f $IMGFMT -o help run_qemu_img create -o help =20 +# Try help option for a format that does not support creation +run_qemu_img create -f bochs -o help + echo echo =3D=3D=3D convert: Options specified more than once =3D=3D=3D =20 @@ -151,6 +154,9 @@ run_qemu_img convert -O $IMGFMT -o backing_file=3D"$TES= T_IMG" -o ,, -o help "$TEST run_qemu_img convert -O $IMGFMT -o help run_qemu_img convert -o help =20 +# Try help option for a format that does not support creation +run_qemu_img convert -O bochs -o help + echo echo =3D=3D=3D amend: Options specified more than once =3D=3D=3D =20 @@ -201,6 +207,9 @@ run_qemu_img amend -f $IMGFMT -o backing_file=3D"$TEST_= IMG" -o ,, -o help "$TEST_I run_qemu_img amend -f $IMGFMT -o help run_qemu_img convert -o help =20 +# Try help option for a format that does not support amendment +run_qemu_img amend -f bochs -o help + # success, all done echo "*** done" rm -f $seq.full diff --git a/tests/qemu-iotests/082.out b/tests/qemu-iotests/082.out index 4e52dce8d6..60ef87c276 100644 --- a/tests/qemu-iotests/082.out +++ b/tests/qemu-iotests/082.out @@ -249,6 +249,9 @@ Testing: create -o help Supported options: size Virtual disk size =20 +Testing: create -f bochs -o help +qemu-img: Format driver 'bochs' does not support image creation + =3D=3D=3D convert: Options specified more than once =3D=3D=3D =20 Testing: create -f qcow2 TEST_DIR/t.qcow2 128M @@ -502,6 +505,9 @@ Testing: convert -o help Supported options: size Virtual disk size =20 +Testing: convert -O bochs -o help +qemu-img: Format driver 'bochs' does not support image creation + =3D=3D=3D amend: Options specified more than once =3D=3D=3D =20 Testing: amend -f foo -f qcow2 -o lazy_refcounts=3Don TEST_DIR/t.qcow2 @@ -763,4 +769,7 @@ Note that not all of these options may be amendable. Testing: convert -o help Supported options: size Virtual disk size + +Testing: amend -f bochs -o help +qemu-img: Format driver 'bochs' does not support option amendment *** done --=20 2.14.3 From nobody Fri May 3 06:44:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.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 1524330007750665.4367681912822; Sat, 21 Apr 2018 10:00:07 -0700 (PDT) Received: from localhost ([::1]:57958 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9vrq-0003r1-Kd for importer@patchew.org; Sat, 21 Apr 2018 13:00:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45321) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9vml-00088m-IN for qemu-devel@nongnu.org; Sat, 21 Apr 2018 12:54:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f9vmk-0003Gn-E4 for qemu-devel@nongnu.org; Sat, 21 Apr 2018 12:54:51 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45428 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 1f9vmf-0003E7-Og; Sat, 21 Apr 2018 12:54:45 -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 4FA747C6B0; Sat, 21 Apr 2018 16:54:45 +0000 (UTC) Received: from localhost (ovpn-204-54.brq.redhat.com [10.40.204.54]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ED99C2166BAD; Sat, 21 Apr 2018 16:54:44 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Sat, 21 Apr 2018 18:54:23 +0200 Message-Id: <20180421165423.30759-8-mreitz@redhat.com> In-Reply-To: <20180421165423.30759-1-mreitz@redhat.com> References: <20180421165423.30759-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.2]); Sat, 21 Apr 2018 16:54:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Sat, 21 Apr 2018 16:54:45 +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] [PATCH 7/7] iotests: Rework 113 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 , 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" This test case has been broken since 398e6ad014df261d (roughly half a year). qemu-img amend requires its output image to be R/W, so it opens it as such; the node is then turned into an read-only node automatically which is now accompanied by a warning, however. This warning has not been part of the reference output. For one thing, this warning shows that we cannot keep the test case as it is. We would need a format that has no create_opts but that does have write support -- we do not have such a format, though. Another thing is that qemu now actually checks whether an image format supports amendment instead of whether it has create_opts (since the former always implies the latter). So we can now use any format that does not support amendment (even if it supports creation) and thus test the same code path. The reason nobody has noticed the breakage until now of course is the fact that nobody runs the iotests for nbd+bochs. There actually was never any reason to set the protocol to "nbd" but because that was technically correct; functionally it made no difference. So that is the first thing we are going to change: Make the protocol "file" instead so that people might actually notice breakage here. Secondly, now that bochs no longer works for the amend test case, we have to change the format there anyway. Set let us just bend the truth a bit, declare this test a raw test. In fact, that does not even concern the bochs test cases, other than the output now reading 'bochs' instead of 'IMGFMT'. So with this test now being a raw test, we can rework the amend test case to use raw instead. Signed-off-by: Max Reitz Tested-by: John Snow --- tests/qemu-iotests/113 | 19 +++++++++---------- tests/qemu-iotests/113.out | 7 ++++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/qemu-iotests/113 b/tests/qemu-iotests/113 index 19b68b2727..4e09810905 100755 --- a/tests/qemu-iotests/113 +++ b/tests/qemu-iotests/113 @@ -38,16 +38,17 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 . ./common.rc . ./common.filter =20 -# We can only test one format here because we need its sample file -_supported_fmt bochs -_supported_proto nbd +# Some of these test cases use bochs, but others do use raw, so this +# is only half a lie. +_supported_fmt raw +_supported_proto file _supported_os Linux =20 echo echo '=3D=3D=3D Unsupported image creation in qemu-img create =3D=3D=3D' echo =20 -$QEMU_IMG create -f $IMGFMT nbd://example.com 2>&1 64M | _filter_imgfmt +$QEMU_IMG create -f bochs nbd://example.com 2>&1 64M =20 echo echo '=3D=3D=3D Unsupported image creation in qemu-img convert =3D=3D=3D' @@ -56,17 +57,15 @@ echo # We could use any input image format here, but this is a bochs test, so j= ust # use the bochs image _use_sample_img empty.bochs.bz2 -$QEMU_IMG convert -f $IMGFMT -O $IMGFMT "$TEST_IMG" nbd://example.com 2>&1= \ - | _filter_imgfmt +$QEMU_IMG convert -f bochs -O bochs "$TEST_IMG" nbd://example.com =20 echo echo '=3D=3D=3D Unsupported format in qemu-img amend =3D=3D=3D' echo =20 -# The protocol does not matter here -_use_sample_img empty.bochs.bz2 -$QEMU_IMG amend -f $IMGFMT -o foo=3Dbar "$TEST_IMG" 2>&1 | _filter_imgfmt - +TEST_IMG=3D"$TEST_DIR/t.$IMGFMT" +_make_test_img 1M +$QEMU_IMG amend -f $IMGFMT -o size=3D2M "$TEST_IMG" 2>&1 | _filter_imgfmt =20 # success, all done echo diff --git a/tests/qemu-iotests/113.out b/tests/qemu-iotests/113.out index 00bdfd6887..3557e2bbf0 100644 --- a/tests/qemu-iotests/113.out +++ b/tests/qemu-iotests/113.out @@ -2,14 +2,15 @@ QA output created by 113 =20 =3D=3D=3D Unsupported image creation in qemu-img create =3D=3D=3D =20 -qemu-img: nbd://example.com: Format driver 'IMGFMT' does not support image= creation +qemu-img: nbd://example.com: Format driver 'bochs' does not support image = creation =20 =3D=3D=3D Unsupported image creation in qemu-img convert =3D=3D=3D =20 -qemu-img: Format driver 'IMGFMT' does not support image creation +qemu-img: Format driver 'bochs' does not support image creation =20 =3D=3D=3D Unsupported format in qemu-img amend =3D=3D=3D =20 -qemu-img: Format driver 'IMGFMT' does not support any options to amend +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +qemu-img: Format driver 'IMGFMT' does not support option amendment =20 *** done --=20 2.14.3