From nobody Wed Nov 5 18:21:32 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; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1536669712790577.1554428992525; Tue, 11 Sep 2018 05:41:52 -0700 (PDT) Received: from localhost ([::1]:57484 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fzhzL-0002Pf-2m for importer@patchew.org; Tue, 11 Sep 2018 08:41:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57278) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fzhxC-0000iN-Po for qemu-devel@nongnu.org; Tue, 11 Sep 2018 08:39:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fzhrc-0006V8-4i for qemu-devel@nongnu.org; Tue, 11 Sep 2018 08:33:57 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:33226) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fzhrY-0005nK-Lr; Tue, 11 Sep 2018 08:33:49 -0400 Received: from 91-158-71-53.elisa-laajakaista.fi ([91.158.71.53] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1fzhqw-0001HW-U9; Tue, 11 Sep 2018 14:33:11 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1fzhqj-00069N-Rs; Tue, 11 Sep 2018 15:32:57 +0300 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Message-Id:Date:Subject:Cc:To:From; bh=R5SZQyE8fyirtxycHk1pDAo4ENRSjGGBjNM0Got0eEE=; b=YkK94K8j+I3vfdzzp8mNPVjZellJVbVJisBhZ7CsxH0UBrHfGwHrJg6/9q9fuWPs/sbpIaz53PRr3JBgOmZjn6S1Kg/xCoInZx+Sv6iL46IekWezgfP5He6RJGm+6iKYo73FkvbF8xzXigNjWC3iEGW1VzWVPeaKeCDBpVEQ21XGjzA1eDJo1DC3PKgrU6R6EZ2BO5oIeOv/11JScPvZ66ALx0krN5qxtIKecrShTAZqS8DSttxyIe/koJZ4hwzlYag8wwb19YzWunJLe/qSRmi3xSTAUpEJ4nQ6AId0vJZLGIlQLExgGL6gzIh2sT3u9ydP87UrnRGX+RAONGeSMQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Tue, 11 Sep 2018 15:32:56 +0300 Message-Id: <20180911123256.23601-1-berto@igalia.com> X-Mailer: git-send-email 2.11.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH] block: Don't call update_flags_from_options() if the options are wrong 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 , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" If qemu_opts_absorb_qdict() fails and we carry on and call update_flags_from_options() then that can result on a failed assertion: $ qemu-io -c 'reopen -o read-only=3Dfoo' hd.qcow2 block.c:1101: update_flags_from_options: Assertion `qemu_opt_find(opts, = BDRV_OPT_CACHE_DIRECT)' failed. Aborted This only happens in bdrv_reopen_queue_child(). Although this function doesn't return errors, we can simply keep the wrong options in the reopen queue and later bdrv_reopen_prepare() will fail. Signed-off-by: Alberto Garcia --- block.c | 11 +++++++++-- tests/qemu-iotests/133 | 6 ++++++ tests/qemu-iotests/133.out | 4 ++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index 0dbb1fcc7b..739d9073a6 100644 --- a/block.c +++ b/block.c @@ -2931,12 +2931,19 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Bl= ockReopenQueue *bs_queue, if (parent_options) { QemuOpts *opts; QDict *options_copy; + Error *local_err =3D NULL; assert(!flags); role->inherit_options(&flags, options, parent_flags, parent_option= s); options_copy =3D qdict_clone_shallow(options); opts =3D qemu_opts_create(&bdrv_runtime_opts, NULL, 0, &error_abor= t); - qemu_opts_absorb_qdict(opts, options_copy, NULL); - update_flags_from_options(&flags, opts); + qemu_opts_absorb_qdict(opts, options_copy, &local_err); + /* Don't call update_flags_from_options() if the options are wrong. + * bdrv_reopen_prepare() will later return an error. */ + if (!local_err) { + update_flags_from_options(&flags, opts); + } else { + error_free(local_err); + } qemu_opts_del(opts); qobject_unref(options_copy); } diff --git a/tests/qemu-iotests/133 b/tests/qemu-iotests/133 index af6b3e1dd4..b9f17c996f 100755 --- a/tests/qemu-iotests/133 +++ b/tests/qemu-iotests/133 @@ -92,6 +92,12 @@ echo IMGOPTSSYNTAX=3Dfalse $QEMU_IO -f null-co -c 'reopen' -c 'info' \ "json:{'driver': 'null-co', 'size': 65536}" =20 +echo +echo "=3D=3D=3D Check that invalid options are handled correctly =3D=3D=3D" +echo + +$QEMU_IO -c 'reopen -o read-only=3Dfoo' $TEST_IMG + # success, all done echo "*** done" rm -f $seq.full diff --git a/tests/qemu-iotests/133.out b/tests/qemu-iotests/133.out index f4a85aeb63..570f623b6b 100644 --- a/tests/qemu-iotests/133.out +++ b/tests/qemu-iotests/133.out @@ -24,4 +24,8 @@ Cannot change the option 'driver' =20 format name: null-co format name: null-co + +=3D=3D=3D Check that invalid options are handled correctly =3D=3D=3D + +Parameter 'read-only' expects 'on' or 'off' *** done --=20 2.11.0