yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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