From nobody Mon Feb 9 01:51:44 2026 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 1542031827645697.6668094673128; Mon, 12 Nov 2018 06:10:27 -0800 (PST) Received: from localhost ([::1]:48819 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gMCv3-0002Wi-Tc for importer@patchew.org; Mon, 12 Nov 2018 09:10:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57860) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gMCmo-0000nK-LF for qemu-devel@nongnu.org; Mon, 12 Nov 2018 09:01:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gMCmg-0001cJ-JB for qemu-devel@nongnu.org; Mon, 12 Nov 2018 09:01:52 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:57651) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gMCmf-0001Et-6X; Mon, 12 Nov 2018 09:01:45 -0500 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 1gMCm8-00073y-VE; Mon, 12 Nov 2018 15:01:13 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gMClq-0007Cy-J6; Mon, 12 Nov 2018 16:00:54 +0200 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=yZlbXJb30F0HcNgJq5dzqWNew/6m7QHdE278g8UKEy0=; b=dDowColhtpSSEusr+LaFgoTuiejE4oJKm0MS/A+QQjiq+k/HBxj4jPSQvgjoOThIm1GZPFrGKnbdh2bfA7lP9Pbl7uP4B5shk2zgWS18Odw3pqsg2cEtKjJ7N/1eCro2Sn60tfL/A7zVAfFVfkXzaiisZ9B3zg6Be/PAC2YlyArUX1ya51FSAH1cn1gHnPZFQQWrP2L6K2RLSR5dvakAc/HUxPu6+t0QyRtjDB3GvcTG5mpE80xcrIb9GfXF9qL15UenZu9MQ8BDjbWtMABHIdDlSeci/+OeHCkklG8HHAsX5DG/gCMtYyoCLawOnKaPH0ZiHp4lc8ovRGhfqa07Rw==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Mon, 12 Nov 2018 16:00:46 +0200 Message-Id: <45483ddb0e71df083616ff0b2a1f39c4e853925b.1542031058.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 v5 14/16] block: Remove assertions from update_flags_from_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 , 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) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This function takes four options (cache.direct, cache.no-flush, read-only and auto-read-only) from a QemuOpts object and updates the flags accordingly. If any of those options is not set (because it was missing from the original QDict or because it had an invalid value) then the function aborts with a failed assertion: $ qemu-io -c 'reopen -o read-only=3Dfoo' hd.qcow2 block.c:1126: update_flags_from_options: Assertion `qemu_opt_find(opts, = BDRV_OPT_CACHE_DIRECT)' failed. Aborted This assertion is unnecessary, and it forces any caller of bdrv_reopen() to pass all the aforementioned four options. This may have made sense in order to remove ambiguity when bdrv_reopen() was taking both flags and options, but that's not the case anymore. It's also unnecessary if we want to validate the option values, because bdrv_reopen_prepare() already takes care of that, as we can see if we remove the assertions: $ qemu-io -c 'reopen -o read-only=3Dfoo' hd.qcow2 Parameter 'read-only' expects 'on' or 'off' Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block.c | 4 ---- tests/qemu-iotests/133 | 9 +++++++++ tests/qemu-iotests/133.out | 7 +++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/block.c b/block.c index 8bc808d6f3..68f1e3b45e 100644 --- a/block.c +++ b/block.c @@ -1139,24 +1139,20 @@ static void update_flags_from_options(int *flags, Q= emuOpts *opts) { *flags &=3D ~BDRV_O_CACHE_MASK; =20 - assert(qemu_opt_find(opts, BDRV_OPT_CACHE_NO_FLUSH)); if (qemu_opt_get_bool_del(opts, BDRV_OPT_CACHE_NO_FLUSH, false)) { *flags |=3D BDRV_O_NO_FLUSH; } =20 - assert(qemu_opt_find(opts, BDRV_OPT_CACHE_DIRECT)); if (qemu_opt_get_bool_del(opts, BDRV_OPT_CACHE_DIRECT, false)) { *flags |=3D BDRV_O_NOCACHE; } =20 *flags &=3D ~BDRV_O_RDWR; =20 - assert(qemu_opt_find(opts, BDRV_OPT_READ_ONLY)); if (!qemu_opt_get_bool_del(opts, BDRV_OPT_READ_ONLY, false)) { *flags |=3D BDRV_O_RDWR; } =20 - assert(qemu_opt_find(opts, BDRV_OPT_AUTO_READ_ONLY)); if (qemu_opt_get_bool_del(opts, BDRV_OPT_AUTO_READ_ONLY, false)) { *flags |=3D BDRV_O_AUTO_RDONLY; } diff --git a/tests/qemu-iotests/133 b/tests/qemu-iotests/133 index 14e6b3b972..243b1eba50 100755 --- a/tests/qemu-iotests/133 +++ b/tests/qemu-iotests/133 @@ -101,6 +101,15 @@ $QEMU_IO -c 'reopen -w -o read-only=3Don' $TEST_IMG $QEMU_IO -c 'reopen -c none -o cache.direct=3Don' $TEST_IMG $QEMU_IO -c 'reopen -c writeback -o cache.direct=3Don' $TEST_IMG $QEMU_IO -c 'reopen -c directsync -o cache.no-flush=3Don' $TEST_IMG + +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 +$QEMU_IO -c 'reopen -o cache.no-flush=3Dbar' $TEST_IMG +$QEMU_IO -c 'reopen -o cache.direct=3Dbaz' $TEST_IMG +$QEMU_IO -c 'reopen -o auto-read-only=3Dqux' $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 48a9d087f0..414c7fa27f 100644 --- a/tests/qemu-iotests/133.out +++ b/tests/qemu-iotests/133.out @@ -32,4 +32,11 @@ Cannot set both -r/-w and 'read-only' Cannot set both -c and the cache options Cannot set both -c and the cache options Cannot set both -c and the cache options + +=3D=3D=3D Check that invalid options are handled correctly =3D=3D=3D + +Parameter 'read-only' expects 'on' or 'off' +Parameter 'cache.no-flush' expects 'on' or 'off' +Parameter 'cache.direct' expects 'on' or 'off' +Parameter 'auto-read-only' expects 'on' or 'off' *** done --=20 2.11.0