Blame SOURCES/kvm-block-mirror-conservative-mirror_exit-refactor.patch

357786
From f27835b1c21b80477e828ed82c5afd764e6f90ca Mon Sep 17 00:00:00 2001
357786
From: John Snow <jsnow@redhat.com>
357786
Date: Mon, 10 Sep 2018 18:17:53 +0200
357786
Subject: [PATCH 15/25] block/mirror: conservative mirror_exit refactor
357786
357786
RH-Author: John Snow <jsnow@redhat.com>
357786
Message-id: <20180910181803.11781-16-jsnow@redhat.com>
357786
Patchwork-id: 82105
357786
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 15/25] block/mirror: conservative mirror_exit refactor
357786
Bugzilla: 1626061
357786
RH-Acked-by: Max Reitz <mreitz@redhat.com>
357786
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
357786
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
357786
357786
For purposes of minimum code movement, refactor the mirror_exit
357786
callback to use the post-finalization callbacks in a trivial way.
357786
357786
Signed-off-by: John Snow <jsnow@redhat.com>
357786
Message-id: 20180906130225.5118-7-jsnow@redhat.com
357786
Reviewed-by: Jeff Cody <jcody@redhat.com>
357786
Reviewed-by: Max Reitz <mreitz@redhat.com>
357786
[mreitz: Added comment for the mirror_exit() function]
357786
Signed-off-by: Max Reitz <mreitz@redhat.com>
357786
(cherry picked from commit 9fd426955da4239af7690c92b387fff0502aca84)
357786
Signed-off-by: John Snow <jsnow@redhat.com>
357786
357786
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
357786
357786
Conflicts:
357786
    block/mirror.c: context conflict on job properties
357786
---
357786
 block/mirror.c | 44 +++++++++++++++++++++++++++++++++-----------
357786
 1 file changed, 33 insertions(+), 11 deletions(-)
357786
357786
diff --git a/block/mirror.c b/block/mirror.c
357786
index 1945000..313e6e9 100644
357786
--- a/block/mirror.c
357786
+++ b/block/mirror.c
357786
@@ -71,6 +71,7 @@ typedef struct MirrorBlockJob {
357786
     int target_cluster_size;
357786
     int max_iov;
357786
     bool initial_zeroing_ongoing;
357786
+    bool prepared;
357786
 } MirrorBlockJob;
357786
 
357786
 typedef struct MirrorOp {
357786
@@ -480,7 +481,12 @@ static void mirror_wait_for_all_io(MirrorBlockJob *s)
357786
     }
357786
 }
357786
 
357786
-static void mirror_exit(Job *job)
357786
+/**
357786
+ * mirror_exit_common: handle both abort() and prepare() cases.
357786
+ * for .prepare, returns 0 on success and -errno on failure.
357786
+ * for .abort cases, denoted by abort = true, MUST return 0.
357786
+ */
357786
+static int mirror_exit_common(Job *job)
357786
 {
357786
     MirrorBlockJob *s = container_of(job, MirrorBlockJob, common.job);
357786
     BlockJob *bjob = &s->common;
357786
@@ -489,7 +495,13 @@ static void mirror_exit(Job *job)
357786
     BlockDriverState *target_bs = blk_bs(s->target);
357786
     BlockDriverState *mirror_top_bs = s->mirror_top_bs;
357786
     Error *local_err = NULL;
357786
-    int ret = job->ret;
357786
+    bool abort = job->ret < 0;
357786
+    int ret = 0;
357786
+
357786
+    if (s->prepared) {
357786
+        return 0;
357786
+    }
357786
+    s->prepared = true;
357786
 
357786
     bdrv_release_dirty_bitmap(src, s->dirty_bitmap);
357786
 
357786
@@ -514,7 +526,7 @@ static void mirror_exit(Job *job)
357786
      * required before it could become a backing file of target_bs. */
357786
     bdrv_child_try_set_perm(mirror_top_bs->backing, 0, BLK_PERM_ALL,
357786
                             &error_abort);
357786
-    if (ret == 0 && s->backing_mode == MIRROR_SOURCE_BACKING_CHAIN) {
357786
+    if (!abort && s->backing_mode == MIRROR_SOURCE_BACKING_CHAIN) {
357786
         BlockDriverState *backing = s->is_none_mode ? src : s->base;
357786
         if (backing_bs(target_bs) != backing) {
357786
             bdrv_set_backing_hd(target_bs, backing, &local_err);
357786
@@ -530,11 +542,8 @@ static void mirror_exit(Job *job)
357786
         aio_context_acquire(replace_aio_context);
357786
     }
357786
 
357786
-    if (s->should_complete && ret == 0) {
357786
-        BlockDriverState *to_replace = src;
357786
-        if (s->to_replace) {
357786
-            to_replace = s->to_replace;
357786
-        }
357786
+    if (s->should_complete && !abort) {
357786
+        BlockDriverState *to_replace = s->to_replace ?: src;
357786
 
357786
         if (bdrv_get_flags(target_bs) != bdrv_get_flags(to_replace)) {
357786
             bdrv_reopen(target_bs, bdrv_get_flags(to_replace), NULL);
357786
@@ -581,7 +590,18 @@ static void mirror_exit(Job *job)
357786
     bdrv_unref(mirror_top_bs);
357786
     bdrv_unref(src);
357786
 
357786
-    job->ret = ret;
357786
+    return ret;
357786
+}
357786
+
357786
+static int mirror_prepare(Job *job)
357786
+{
357786
+    return mirror_exit_common(job);
357786
+}
357786
+
357786
+static void mirror_abort(Job *job)
357786
+{
357786
+    int ret = mirror_exit_common(job);
357786
+    assert(ret == 0);
357786
 }
357786
 
357786
 static void mirror_throttle(MirrorBlockJob *s)
357786
@@ -986,7 +1006,8 @@ static const BlockJobDriver mirror_job_driver = {
357786
         .user_resume            = block_job_user_resume,
357786
         .drain                  = block_job_drain,
357786
         .run                    = mirror_run,
357786
-        .exit                   = mirror_exit,
357786
+        .prepare                = mirror_prepare,
357786
+        .abort                  = mirror_abort,
357786
         .pause                  = mirror_pause,
357786
         .complete               = mirror_complete,
357786
     },
357786
@@ -1002,7 +1023,8 @@ static const BlockJobDriver commit_active_job_driver = {
357786
         .user_resume            = block_job_user_resume,
357786
         .drain                  = block_job_drain,
357786
         .run                    = mirror_run,
357786
-        .exit                   = mirror_exit,
357786
+        .prepare                = mirror_prepare,
357786
+        .abort                  = mirror_abort,
357786
         .pause                  = mirror_pause,
357786
         .complete               = mirror_complete,
357786
     },
357786
-- 
357786
1.8.3.1
357786