All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alberto Garcia <berto@igalia.com>
To: qemu-devel@nongnu.org
Cc: Alberto Garcia <berto@igalia.com>,
	qemu-block@nongnu.org, Kevin Wolf <kwolf@redhat.com>,
	Max Reitz <mreitz@redhat.com>
Subject: [Qemu-devel] [PATCH v4 10/15] qemu-io: Put flag changes in the options QDict in reopen_f()
Date: Wed,  7 Nov 2018 14:59:45 +0200	[thread overview]
Message-ID: <9f849af9a99edbe97e449843bb8c20f6aab8f6fe.1541595424.git.berto@igalia.com> (raw)
In-Reply-To: <cover.1541595424.git.berto@igalia.com>
In-Reply-To: <cover.1541595424.git.berto@igalia.com>

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 <berto@igalia.com>
---
 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 5363482213..c9ae09d574 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("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_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 af6b3e1dd4..14e6b3b972 100755
--- a/tests/qemu-iotests/133
+++ b/tests/qemu-iotests/133
@@ -92,6 +92,15 @@ echo
 IMGOPTSSYNTAX=false $QEMU_IO -f null-co -c 'reopen' -c 'info' \
     "json:{'driver': 'null-co', 'size': 65536}"
 
+echo
+echo "=== Check that mixing -c/-r/-w and their corresponding 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 f4a85aeb63..48a9d087f0 100644
--- a/tests/qemu-iotests/133.out
+++ b/tests/qemu-iotests/133.out
@@ -24,4 +24,12 @@ Cannot change the option 'driver'
 
 format name: null-co
 format name: null-co
+
+=== Check that mixing -c/-r/-w and their corresponding options is forbidden ===
+
+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
-- 
2.11.0

  parent reply	other threads:[~2018-11-07 13:01 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-07 12:59 [Qemu-devel] [PATCH v4 00/15] Don't pass flags to bdrv_reopen_queue() Alberto Garcia
2018-11-07 12:59 ` [Qemu-devel] [PATCH v4 01/15] block: Add bdrv_reopen_set_read_only() Alberto Garcia
2018-11-07 12:59 ` [Qemu-devel] [PATCH v4 02/15] block: Use bdrv_reopen_set_read_only() in bdrv_backing_update_filename() Alberto Garcia
2018-11-07 12:59 ` [Qemu-devel] [PATCH v4 03/15] block: Use bdrv_reopen_set_read_only() in commit_start/complete() Alberto Garcia
2018-11-07 12:59 ` [Qemu-devel] [PATCH v4 04/15] block: Use bdrv_reopen_set_read_only() in bdrv_commit() Alberto Garcia
2018-11-07 12:59 ` [Qemu-devel] [PATCH v4 05/15] block: Use bdrv_reopen_set_read_only() in stream_start/complete() Alberto Garcia
2018-11-07 12:59 ` [Qemu-devel] [PATCH v4 06/15] block: Use bdrv_reopen_set_read_only() in qmp_change_backing_file() Alberto Garcia
2018-11-07 12:59 ` [Qemu-devel] [PATCH v4 07/15] block: Use bdrv_reopen_set_read_only() in external_snapshot_commit() Alberto Garcia
2018-11-07 12:59 ` [Qemu-devel] [PATCH v4 08/15] block: Use bdrv_reopen_set_read_only() in the mirror driver Alberto Garcia
2018-11-07 12:59 ` [Qemu-devel] [PATCH v4 09/15] block: Drop bdrv_reopen() Alberto Garcia
2018-11-07 12:59 ` Alberto Garcia [this message]
2018-11-11 20:28   ` [Qemu-devel] [PATCH v4 10/15] qemu-io: Put flag changes in the options QDict in reopen_f() Max Reitz
2018-11-07 12:59 ` [Qemu-devel] [PATCH v4 11/15] block: Clean up reopen_backing_file() in block/replication.c Alberto Garcia
2018-11-11 20:31   ` Max Reitz
2018-11-07 12:59 ` [Qemu-devel] [PATCH v4 12/15] block: Remove flags parameter from bdrv_reopen_queue() Alberto Garcia
2018-11-07 12:59 ` [Qemu-devel] [PATCH v4 13/15] block: Stop passing flags to bdrv_reopen_queue_child() Alberto Garcia
2018-11-11 20:47   ` Max Reitz
2018-11-07 12:59 ` [Qemu-devel] [PATCH v4 14/15] block: Remove assertions from update_flags_from_options() Alberto Garcia
2018-11-11 21:01   ` Max Reitz
2018-11-12 10:26     ` Alberto Garcia
2018-11-12 15:20       ` Max Reitz
2018-11-12 10:36     ` Alberto Garcia
2018-11-07 12:59 ` [Qemu-devel] [PATCH v4 15/15] block: Assert that flags are up-to-date in bdrv_reopen_prepare() Alberto Garcia
2018-11-11 21:06   ` Max Reitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9f849af9a99edbe97e449843bb8c20f6aab8f6fe.1541595424.git.berto@igalia.com \
    --to=berto@igalia.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.