All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 07/23] block: Forbid trying to change unsupported options during reopen
Date: Mon,  1 Oct 2018 19:18:45 +0200	[thread overview]
Message-ID: <20181001171901.11004-8-kwolf@redhat.com> (raw)
In-Reply-To: <20181001171901.11004-1-kwolf@redhat.com>

From: Alberto Garcia <berto@igalia.com>

The bdrv_reopen_prepare() function checks all options passed to each
BlockDriverState (in the reopen_state->options QDict) and makes all
necessary preparations to apply the option changes requested by the
user.

Options are removed from the QDict as they are processed, so at the
end of bdrv_reopen_prepare() only the options that can't be changed
are left. Then a loop goes over all remaining options and verifies
that the old and new values are identical, returning an error if
they're not.

The problem is that at the moment there are options that are removed
from the QDict although they can't be changed. The consequence of this
is any modification to any of those options is silently ignored:

   (qemu) qemu-io virtio0 "reopen -o discard=on"

This happens when all options from bdrv_runtime_opts are removed
from the QDict but then only a few of them are processed. Since
it's especially important that "node-name" and "driver" are not
changed, the code puts them back into the QDict so they are checked
at the end of the function. Instead of putting only those two options
back into the QDict, this patch puts all unprocessed options using
qemu_opts_to_qdict().

update_flags_from_options() also needs to be modified to prevent
BDRV_OPT_CACHE_NO_FLUSH, BDRV_OPT_CACHE_DIRECT and BDRV_OPT_READ_ONLY
from going back to the QDict.

Signed-off-by: Alberto Garcia <berto@igalia.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/block.c b/block.c
index ff1aded4b8..e36ae3e8d1 100644
--- a/block.c
+++ b/block.c
@@ -1094,19 +1094,19 @@ static void update_flags_from_options(int *flags, QemuOpts *opts)
     *flags &= ~BDRV_O_CACHE_MASK;
 
     assert(qemu_opt_find(opts, BDRV_OPT_CACHE_NO_FLUSH));
-    if (qemu_opt_get_bool(opts, BDRV_OPT_CACHE_NO_FLUSH, false)) {
+    if (qemu_opt_get_bool_del(opts, BDRV_OPT_CACHE_NO_FLUSH, false)) {
         *flags |= BDRV_O_NO_FLUSH;
     }
 
     assert(qemu_opt_find(opts, BDRV_OPT_CACHE_DIRECT));
-    if (qemu_opt_get_bool(opts, BDRV_OPT_CACHE_DIRECT, false)) {
+    if (qemu_opt_get_bool_del(opts, BDRV_OPT_CACHE_DIRECT, false)) {
         *flags |= BDRV_O_NOCACHE;
     }
 
     *flags &= ~BDRV_O_RDWR;
 
     assert(qemu_opt_find(opts, BDRV_OPT_READ_ONLY));
-    if (!qemu_opt_get_bool(opts, BDRV_OPT_READ_ONLY, false)) {
+    if (!qemu_opt_get_bool_del(opts, BDRV_OPT_READ_ONLY, false)) {
         *flags |= BDRV_O_RDWR;
     }
 
@@ -3156,7 +3156,6 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue,
     BlockDriver *drv;
     QemuOpts *opts;
     QDict *orig_reopen_opts;
-    const char *value;
     bool read_only;
 
     assert(reopen_state != NULL);
@@ -3179,17 +3178,10 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue,
 
     update_flags_from_options(&reopen_state->flags, opts);
 
-    /* node-name and driver must be unchanged. Put them back into the QDict, so
-     * that they are checked at the end of this function. */
-    value = qemu_opt_get(opts, "node-name");
-    if (value) {
-        qdict_put_str(reopen_state->options, "node-name", value);
-    }
-
-    value = qemu_opt_get(opts, "driver");
-    if (value) {
-        qdict_put_str(reopen_state->options, "driver", value);
-    }
+    /* All other options (including node-name and driver) must be unchanged.
+     * Put them back into the QDict, so that they are checked at the end
+     * of this function. */
+    qemu_opts_to_qdict(opts, reopen_state->options);
 
     /* If we are to stay read-only, do not allow permission change
      * to r/w. Attempting to set to r/w may fail if either BDRV_O_ALLOW_RDWR is
-- 
2.13.6

  parent reply	other threads:[~2018-10-01 17:19 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-01 17:18 [Qemu-devel] [PULL 00/23] Block layer patches Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 01/23] file-posix: Include filename in locking error message Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 02/23] qemu-io: Fix writethrough check in reopen Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 03/23] file-posix: x-check-cache-dropped should default to false on reopen Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 04/23] block: Remove child references from bs->{options, explicit_options} Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 05/23] block: Don't look for child references in append_open_options() Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 06/23] block: Allow child references on reopen Kevin Wolf
2018-10-01 17:18 ` Kevin Wolf [this message]
2018-10-01 17:18 ` [Qemu-devel] [PULL 08/23] file-posix: Forbid trying to change unsupported options during reopen Kevin Wolf
2018-10-05 12:55   ` Peter Maydell
2018-10-05 13:10     ` Kevin Wolf
2018-10-05 13:40     ` [Qemu-devel] [Qemu-block] " Alberto Garcia
2018-10-05 13:41       ` Alberto Garcia
2018-10-05 13:47       ` Peter Maydell
2018-10-01 17:18 ` [Qemu-devel] [PULL 09/23] block: Allow changing 'discard' on reopen Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 10/23] block: Allow changing 'detect-zeroes' " Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 11/23] qcow2: Options' documentation fixes Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 12/23] include: Add a lookup table of sizes Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 13/23] qcow2: Make sizes more humanly readable Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 14/23] qcow2: Avoid duplication in setting the refcount cache size Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 15/23] qcow2: Assign the L2 cache relatively to the image size Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 16/23] qcow2: Increase the default upper limit on the L2 cache size Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 17/23] qcow2: Resize the cache upon image resizing Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 18/23] qcow2: Set the default cache-clean-interval to 10 minutes Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 19/23] qcow2: Explicit number replaced by a constant Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 20/23] block-backend: Set werror/rerror defaults in blk_new() Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 21/23] qcow2: Fix cache-clean-interval documentation Kevin Wolf
2018-10-01 17:19 ` [Qemu-devel] [PULL 22/23] test-replication: Lock AioContext around blk_unref() Kevin Wolf
2018-10-01 17:19 ` [Qemu-devel] [PULL 23/23] tests/test-bdrv-drain: Fix too late qemu_event_reset() Kevin Wolf
2018-10-02  8:06 ` [Qemu-devel] [PULL 00/23] Block layer patches Peter Maydell
2018-10-03 15:46   ` Peter Maydell

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=20181001171901.11004-8-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=peter.maydell@linaro.org \
    --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.