From nobody Thu Nov 6 08:26:56 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 1539781245369553.6813356636727; Wed, 17 Oct 2018 06:00:45 -0700 (PDT) Received: from localhost ([::1]:36521 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClRM-0006ZC-7w for importer@patchew.org; Wed, 17 Oct 2018 09:00:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52329) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClPL-0005I8-6o for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gClPH-0006YC-3m for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:38 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:34308) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gClPG-0004yO-D9; Wed, 17 Oct 2018 08:58:34 -0400 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gClOe-0000lO-H9; Wed, 17 Oct 2018 14:57:57 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gClOM-0005kX-8a; Wed, 17 Oct 2018 15:57:38 +0300 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=aeJQCs3etXRwJZUw+0rnMgKW2ZWKM7PVVWfmn2JsHBw=; b=J0qYzxprf/JKTPH2/dR8gtIczaAkv0eEwT8ULrxzs/ojnN8fWbAYsvo6dk7gmud/P8JH+HzjZrmFTg+BxlrfJM6zZOT19S3praeZxT3bY2K4R90Tpf7DU21+iudc/ivzu9JX4n1FSYpoY+ZfSis8fHWap3uFylybpOZ25rfOYh7kjul+cMFZc8z5tOV6Of4ffh7H5tMT/YD5j/u07Vff5kaB1YpB4gSttOxTCE1TRXkPKH7sfp1MqFk1Cnj1xS1h7btTaaRX8pYlYDzlmOtAGpCx/Yav63vnHefMGhMIaiUl8kT2B6TsLaZmKo/4Dd2X6tzhW/F9lu3nSlc+KOh82A==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 17 Oct 2018 15:57:17 +0300 Message-Id: <5b203ceb35b456503115cb2a4ab2941b2fdc2a6a.1539780785.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: 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 v2 01/14] 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 Reviewed-by: Max Reitz --- 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 7710b399a3..47d5fe2f91 100644 --- a/block.c +++ b/block.c @@ -2942,12 +2942,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