From patchwork Wed Sep 19 14:47:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 10605995 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 98D9414BD for ; Wed, 19 Sep 2018 14:52:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 804D5283F9 for ; Wed, 19 Sep 2018 14:52:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 71ED9283B1; Wed, 19 Sep 2018 14:52:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F0E752C16E for ; Wed, 19 Sep 2018 14:52:58 +0000 (UTC) Received: from localhost ([::1]:45778 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2dqc-0003f8-6o for patchwork-qemu-devel@patchwork.kernel.org; Wed, 19 Sep 2018 10:52:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45348) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2dmG-0008E8-SB for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2dmF-0000Oi-7Y for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:28 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:56791) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g2dmE-0000MY-RF; Wed, 19 Sep 2018 10:48:27 -0400 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=jKyLDFCIyuMqTCHJHkLgJQTQh60/QMVJLm3BwrDIlfE=; b=PPsypCc8r1Ehr4y7RoB6XoSPqj+jm2QT+Gmvd6st2YsDNjEaRaKA3FXjnImPsyY4kek6fvTTVeB2D6Jmo3afI4/JeMrx8M4tkenq7n3LZfRASAP5RYu7hYLRnkSDvNR3pfAbILMKm+c5kgYyQhAHt27BueerVUm0jKO1PWCdIkC9ks+/8ebiovlQbAgG86kHrsdnihMSvPUZu8ZGKwWA/G4XnUuGRGYud7zs1gyeo6TQKp++r0kcE7V9T6dE0pY6wnb4NMaxqxbmvOJeT8YU4jLE9cLykpTMMAEuhO2jAl5TimwL8See0pQ1VMkADASy1FcBmFaxUE6R2QrYFFcbew==; 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 1g2dmD-0003dK-OB; Wed, 19 Sep 2018 16:48:25 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1g2dlt-0004Tw-VD; Wed, 19 Sep 2018 17:48:05 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 19 Sep 2018 17:47:49 +0300 Message-Id: <298f85a0b53dc90b1d6bea272c26983ab684619e.1537367701.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 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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..4ad5269abc 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -10,6 +10,7 @@ #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 = bs->open_flags; bool writethrough = !blk_enable_write_cache(blk); bool has_rw_option = false; + bool has_cache_option = false; BlockReopenQueue *brq; Error *local_err = 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 = 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, char **argv) } qopts = qemu_opts_find(&reopen_opts, NULL); - opts = qopts ? qemu_opts_to_qdict(qopts, NULL) : NULL; + opts = qopts ? qemu_opts_to_qdict(qopts, NULL) : qdict_new(); qemu_opts_reset(&reopen_opts); + if (qdict_haskey(opts, BDRV_OPT_READ_ONLY)) { + if (has_rw_option) { + error_report("Can't 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("Can't 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_FLUSH); + } + bdrv_subtree_drained_begin(bs); brq = 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..a58130c5b4 100755 --- a/tests/qemu-iotests/133 +++ b/tests/qemu-iotests/133 @@ -98,6 +98,15 @@ echo $QEMU_IO -c 'reopen -o read-only=foo' $TEST_IMG +echo +echo "=== Check that mixing -c/-r/-w and their equivalent options is forbidden ===" +echo + +$QEMU_IO -c 'reopen -r -o read-only=on' $TEST_IMG +$QEMU_IO -c 'reopen -w -o read-only=on' $TEST_IMG +$QEMU_IO -c 'reopen -c none -o cache.direct=on' $TEST_IMG +$QEMU_IO -c 'reopen -c writeback -o cache.direct=on' $TEST_IMG +$QEMU_IO -c 'reopen -c directsync -o cache.no-flush=on' $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..4d84401688 100644 --- a/tests/qemu-iotests/133.out +++ b/tests/qemu-iotests/133.out @@ -28,4 +28,12 @@ format name: null-co === Check that invalid options are handled correctly === Parameter 'read-only' expects 'on' or 'off' + +=== Check that mixing -c/-r/-w and their equivalent options is forbidden === + +Can't set both -r/-w and 'read-only' +Can't set both -r/-w and 'read-only' +Can't set both -c and the cache options +Can't set both -c and the cache options +Can't set both -c and the cache options *** done