diff mbox series

[04/14] block: Use bdrv_reopen_set_read_only() in commit_start/complete()

Message ID 57d02fc28b31eebda8ee6d751587c5f25ebf5af0.1537367701.git.berto@igalia.com
State New
Headers show
Series Don't pass flags to bdrv_reopen_queue() | expand

Commit Message

Alberto Garcia Sept. 19, 2018, 2:47 p.m. UTC
This patch replaces the bdrv_reopen() calls that set and remove the
BDRV_O_RDWR flag with the new bdrv_reopen_set_read_only() function.

Signed-off-by: Alberto Garcia <berto@igalia.com>
---
 block/commit.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

Comments

Max Reitz Oct. 8, 2018, 1:11 a.m. UTC | #1
On 19.09.18 16:47, Alberto Garcia wrote:
> This patch replaces the bdrv_reopen() calls that set and remove the
> BDRV_O_RDWR flag with the new bdrv_reopen_set_read_only() function.
> 
> Signed-off-by: Alberto Garcia <berto@igalia.com>
> ---
>  block/commit.c | 16 ++++++----------
>  1 file changed, 6 insertions(+), 10 deletions(-)

Will need a rebase on 22dffcbec62ba918db690ed44beba4bd4e970bb9, but that
looks like a rather simple job, so:

Reviewed-by: Max Reitz <mreitz@redhat.com>
diff mbox series

Patch

diff --git a/block/commit.c b/block/commit.c
index eb414579bd..fcadcab33a 100644
--- a/block/commit.c
+++ b/block/commit.c
@@ -37,7 +37,7 @@  typedef struct CommitBlockJob {
     BlockBackend *top;
     BlockBackend *base;
     BlockdevOnError on_error;
-    int base_flags;
+    bool base_read_only;
     char *backing_file_str;
 } CommitBlockJob;
 
@@ -105,8 +105,8 @@  static void commit_complete(Job *job, void *opaque)
     /* restore base open flags here if appropriate (e.g., change the base back
      * to r/o). These reopens do not need to be atomic, since we won't abort
      * even on failure here */
-    if (s->base_flags != bdrv_get_flags(base)) {
-        bdrv_reopen(base, s->base_flags, NULL);
+    if (s->base_read_only) {
+        bdrv_reopen_set_read_only(base, true, NULL);
     }
     g_free(s->backing_file_str);
     blk_unref(s->top);
@@ -265,7 +265,6 @@  void commit_start(const char *job_id, BlockDriverState *bs,
                   const char *filter_node_name, Error **errp)
 {
     CommitBlockJob *s;
-    int orig_base_flags;
     BlockDriverState *iter;
     BlockDriverState *commit_top_bs = NULL;
     Error *local_err = NULL;
@@ -284,11 +283,9 @@  void commit_start(const char *job_id, BlockDriverState *bs,
     }
 
     /* convert base to r/w, if necessary */
-    orig_base_flags = bdrv_get_flags(base);
-    if (!(orig_base_flags & BDRV_O_RDWR)) {
-        bdrv_reopen(base, orig_base_flags | BDRV_O_RDWR, &local_err);
-        if (local_err != NULL) {
-            error_propagate(errp, local_err);
+    s->base_read_only = bdrv_is_read_only(base);
+    if (s->base_read_only) {
+        if (bdrv_reopen_set_read_only(base, false, errp) != 0) {
             goto fail;
         }
     }
@@ -363,7 +360,6 @@  void commit_start(const char *job_id, BlockDriverState *bs,
         goto fail;
     }
 
-    s->base_flags = orig_base_flags;
     s->backing_file_str = g_strdup(backing_file_str);
     s->on_error = on_error;