From nobody Thu Nov 6 08:27:00 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 1539781818012793.8985449422408; Wed, 17 Oct 2018 06:10:18 -0700 (PDT) Received: from localhost ([::1]:36590 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClaZ-0005uh-7x for importer@patchew.org; Wed, 17 Oct 2018 09:10:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52339) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClPL-0005IF-7j 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 1gClPG-0006Vg-Qo for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:39 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:34317) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gClPG-0004zL-Co; 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 1gClOf-0000lY-TL; Wed, 17 Oct 2018 14:57:58 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gClOM-0005l2-HV; 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=TyOmc1EJNdTIYj6mt1Zu90Nv1TLZ7Igu33rACBsT2BQ=; b=KeNZonNGJOsiECwwWsBrg4rd67Hyy7g1WmbFjctOsh2sodHRBi083ZW/6NkftIPrwQ9p0Q0M73EfQjNB5bmIzYoFhuRfEB0yr4RKDfMThdbCw/gx9wz/+VhJe088NJTouCx2xrNyxd8SgbJQBhUxt6M7x3xVmgZjZKBDtD1ZeoNh2TbB/M5f3QIfV+X0bbnnGKRVEpkAA+6aElITn/1zeSrFIQEbWq+ocmKFHLU2i/8wd/8djkwTKH40d5TbB/cgW/rLN6gKGT/9FM6t7WAJhCv3jtyxGfEsPxfyorbR/QE758slQJh+Rftfm78pbgXpJo6F9DE6kdRObwiy8HXFqA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 17 Oct 2018 15:57:27 +0300 Message-Id: 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 11/14] qemu-io: Put flag changes in the options QDict in reopen_f() 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" When reopen_f() puts a block device in the reopen queue, some of the new options are passed using a QDict, but others ("read-only" and the cache options) are passed as flags. This patch puts those flags in the QDict. This way the flags parameter becomes redundant and we'll be able to get rid of it in a subsequent patch. Signed-off-by: Alberto Garcia --- qemu-io-cmds.c | 27 ++++++++++++++++++++++++++- tests/qemu-iotests/133 | 9 +++++++++ tests/qemu-iotests/133.out | 8 ++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index db0b3ee5ef..b49a816cc8 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -10,6 +10,7 @@ =20 #include "qemu/osdep.h" #include "qapi/error.h" +#include "qapi/qmp/qdict.h" #include "qemu-io.h" #include "sysemu/block-backend.h" #include "block/block.h" @@ -1978,6 +1979,7 @@ static int reopen_f(BlockBackend *blk, int argc, char= **argv) int flags =3D bs->open_flags; bool writethrough =3D !blk_enable_write_cache(blk); bool has_rw_option =3D false; + bool has_cache_option =3D false; =20 BlockReopenQueue *brq; Error *local_err =3D NULL; @@ -1989,6 +1991,7 @@ static int reopen_f(BlockBackend *blk, int argc, char= **argv) error_report("Invalid cache option: %s", optarg); return -EINVAL; } + has_cache_option =3D true; break; case 'o': if (!qemu_opts_parse_noisily(&reopen_opts, optarg, 0)) { @@ -2046,9 +2049,31 @@ static int reopen_f(BlockBackend *blk, int argc, cha= r **argv) } =20 qopts =3D qemu_opts_find(&reopen_opts, NULL); - opts =3D qopts ? qemu_opts_to_qdict(qopts, NULL) : NULL; + opts =3D qopts ? qemu_opts_to_qdict(qopts, NULL) : qdict_new(); qemu_opts_reset(&reopen_opts); =20 + if (qdict_haskey(opts, BDRV_OPT_READ_ONLY)) { + if (has_rw_option) { + error_report("Cannot set both -r/-w and '" BDRV_OPT_READ_ONLY = "'"); + qobject_unref(opts); + return -EINVAL; + } + } else { + qdict_put_bool(opts, BDRV_OPT_READ_ONLY, !(flags & BDRV_O_RDWR)); + } + + if (qdict_haskey(opts, BDRV_OPT_CACHE_DIRECT) || + qdict_haskey(opts, BDRV_OPT_CACHE_NO_FLUSH)) { + if (has_cache_option) { + error_report("Cannot set both -c and the cache options"); + qobject_unref(opts); + return -EINVAL; + } + } else { + qdict_put_bool(opts, BDRV_OPT_CACHE_DIRECT, flags & BDRV_O_NOCACHE= ); + qdict_put_bool(opts, BDRV_OPT_CACHE_NO_FLUSH, flags & BDRV_O_NO_FL= USH); + } + bdrv_subtree_drained_begin(bs); brq =3D bdrv_reopen_queue(NULL, bs, opts, flags); bdrv_reopen_multiple(bdrv_get_aio_context(bs), brq, &local_err); diff --git a/tests/qemu-iotests/133 b/tests/qemu-iotests/133 index b9f17c996f..3cbe72c42b 100755 --- a/tests/qemu-iotests/133 +++ b/tests/qemu-iotests/133 @@ -98,6 +98,15 @@ echo =20 $QEMU_IO -c 'reopen -o read-only=3Dfoo' $TEST_IMG =20 +echo +echo "=3D=3D=3D Check that mixing -c/-r/-w and their corresponding options= is forbidden =3D=3D=3D" +echo + +$QEMU_IO -c 'reopen -r -o read-only=3Don' $TEST_IMG +$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 # success, all done echo "*** done" rm -f $seq.full diff --git a/tests/qemu-iotests/133.out b/tests/qemu-iotests/133.out index 570f623b6b..aa8cf19f9e 100644 --- a/tests/qemu-iotests/133.out +++ b/tests/qemu-iotests/133.out @@ -28,4 +28,12 @@ format name: null-co =3D=3D=3D Check that invalid options are handled correctly =3D=3D=3D =20 Parameter 'read-only' expects 'on' or 'off' + +=3D=3D=3D Check that mixing -c/-r/-w and their corresponding options is fo= rbidden =3D=3D=3D + +Cannot set both -r/-w and 'read-only' +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 *** done --=20 2.11.0