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 11/15] block: Clean up reopen_backing_file() in block/replication.c
Date: Wed,  7 Nov 2018 14:59:46 +0200	[thread overview]
Message-ID: <37b20c1e4ca5ef29ec7fbba2fa62dbf7acc292a5.1541595424.git.berto@igalia.com> (raw)
In-Reply-To: <cover.1541595424.git.berto@igalia.com>
In-Reply-To: <cover.1541595424.git.berto@igalia.com>

This function is used to put the hidden and secondary disks in
read-write mode before launching the backup job, and back in read-only
mode afterwards.

This patch does the following changes:

  - Use an options QDict with the "read-only" option instead of
    passing the changes as flags only.

  - Simplify the code (it was unnecessarily complicated and verbose).

  - Fix a bug due to which the secondary disk was not being put back
    in read-only mode when writable=false (because in this case
    orig_secondary_flags always had the BDRV_O_RDWR flag set).

  - Stop clearing the BDRV_O_INACTIVE flag.

The flags parameter to bdrv_reopen_queue() becomes redundant and we'll
be able to get rid of it in a subsequent patch.

Signed-off-by: Alberto Garcia <berto@igalia.com>
---
 block/replication.c | 45 +++++++++++++++++++++------------------------
 1 file changed, 21 insertions(+), 24 deletions(-)

diff --git a/block/replication.c b/block/replication.c
index 6349d6958e..481a225924 100644
--- a/block/replication.c
+++ b/block/replication.c
@@ -20,6 +20,7 @@
 #include "block/block_backup.h"
 #include "sysemu/block-backend.h"
 #include "qapi/error.h"
+#include "qapi/qmp/qdict.h"
 #include "replication.h"
 
 typedef enum {
@@ -39,8 +40,8 @@ typedef struct BDRVReplicationState {
     char *top_id;
     ReplicationState *rs;
     Error *blocker;
-    int orig_hidden_flags;
-    int orig_secondary_flags;
+    bool orig_hidden_read_only;
+    bool orig_secondary_read_only;
     int error;
 } BDRVReplicationState;
 
@@ -371,44 +372,40 @@ static void secondary_do_checkpoint(BDRVReplicationState *s, Error **errp)
     }
 }
 
+/* This function is supposed to be called twice:
+ * first with writable = true, then with writable = false.
+ * The first call puts s->hidden_disk and s->secondary_disk in
+ * r/w mode, and the second puts them back in their original state.
+ */
 static void reopen_backing_file(BlockDriverState *bs, bool writable,
                                 Error **errp)
 {
     BDRVReplicationState *s = bs->opaque;
     BlockReopenQueue *reopen_queue = NULL;
-    int orig_hidden_flags, orig_secondary_flags;
-    int new_hidden_flags, new_secondary_flags;
     Error *local_err = NULL;
 
     if (writable) {
-        orig_hidden_flags = s->orig_hidden_flags =
-                                bdrv_get_flags(s->hidden_disk->bs);
-        new_hidden_flags = (orig_hidden_flags | BDRV_O_RDWR) &
-                                                    ~BDRV_O_INACTIVE;
-        orig_secondary_flags = s->orig_secondary_flags =
-                                bdrv_get_flags(s->secondary_disk->bs);
-        new_secondary_flags = (orig_secondary_flags | BDRV_O_RDWR) &
-                                                     ~BDRV_O_INACTIVE;
-    } else {
-        orig_hidden_flags = (s->orig_hidden_flags | BDRV_O_RDWR) &
-                                                    ~BDRV_O_INACTIVE;
-        new_hidden_flags = s->orig_hidden_flags;
-        orig_secondary_flags = (s->orig_secondary_flags | BDRV_O_RDWR) &
-                                                    ~BDRV_O_INACTIVE;
-        new_secondary_flags = s->orig_secondary_flags;
+        s->orig_hidden_read_only = bdrv_is_read_only(s->hidden_disk->bs);
+        s->orig_secondary_read_only = bdrv_is_read_only(s->secondary_disk->bs);
     }
 
     bdrv_subtree_drained_begin(s->hidden_disk->bs);
     bdrv_subtree_drained_begin(s->secondary_disk->bs);
 
-    if (orig_hidden_flags != new_hidden_flags) {
-        reopen_queue = bdrv_reopen_queue(reopen_queue, s->hidden_disk->bs, NULL,
-                                         new_hidden_flags);
+    if (s->orig_hidden_read_only) {
+        int flags = bdrv_get_flags(s->hidden_disk->bs);
+        QDict *opts = qdict_new();
+        qdict_put_bool(opts, BDRV_OPT_READ_ONLY, !writable);
+        reopen_queue = bdrv_reopen_queue(reopen_queue, s->hidden_disk->bs,
+                                         opts, flags);
     }
 
-    if (!(orig_secondary_flags & BDRV_O_RDWR)) {
+    if (s->orig_secondary_read_only) {
+        int flags = bdrv_get_flags(s->secondary_disk->bs);
+        QDict *opts = qdict_new();
+        qdict_put_bool(opts, BDRV_OPT_READ_ONLY, !writable);
         reopen_queue = bdrv_reopen_queue(reopen_queue, s->secondary_disk->bs,
-                                         NULL, new_secondary_flags);
+                                         opts, flags);
     }
 
     if (reopen_queue) {
-- 
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 ` [Qemu-devel] [PATCH v4 10/15] qemu-io: Put flag changes in the options QDict in reopen_f() Alberto Garcia
2018-11-11 20:28   ` Max Reitz
2018-11-07 12:59 ` Alberto Garcia [this message]
2018-11-11 20:31   ` [Qemu-devel] [PATCH v4 11/15] block: Clean up reopen_backing_file() in block/replication.c 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=37b20c1e4ca5ef29ec7fbba2fa62dbf7acc292a5.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.