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

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