Blame SOURCES/kvm-block-mirror-utilize-job_exit-shim.patch

357786
From a89c41261dee7c365995d9f5f98bcdb543e42775 Mon Sep 17 00:00:00 2001
357786
From: John Snow <jsnow@redhat.com>
357786
Date: Mon, 10 Sep 2018 18:17:43 +0200
357786
Subject: [PATCH 05/25] block/mirror: utilize job_exit shim
357786
357786
RH-Author: John Snow <jsnow@redhat.com>
357786
Message-id: <20180910181803.11781-6-jsnow@redhat.com>
357786
Patchwork-id: 82098
357786
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 05/25] block/mirror: utilize job_exit shim
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
Change the manual deferment to mirror_exit into the implicit
357786
callback to job_exit and the mirror_exit callback.
357786
357786
This does change the order of some bdrv_unref calls and job_completed,
357786
but thanks to the new context in which we call .exit, this is safe to
357786
defer the possible flushing of any nodes to the job_finalize_single
357786
cleanup stage.
357786
357786
Signed-off-by: John Snow <jsnow@redhat.com>
357786
Message-id: 20180830015734.19765-6-jsnow@redhat.com
357786
Reviewed-by: Max Reitz <mreitz@redhat.com>
357786
Reviewed-by: Jeff Cody <jcody@redhat.com>
357786
Signed-off-by: Max Reitz <mreitz@redhat.com>
357786
(cherry picked from commit 7b508f6b7a38a8d9729772fa6e525da883fb120b)
357786
Signed-off-by: John Snow <jsnow@redhat.com>
357786
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
357786
---
357786
 block/mirror.c | 30 +++++++++++-------------------
357786
 1 file changed, 11 insertions(+), 19 deletions(-)
357786
357786
diff --git a/block/mirror.c b/block/mirror.c
357786
index 459f944..0ab0822 100644
357786
--- a/block/mirror.c
357786
+++ b/block/mirror.c
357786
@@ -480,25 +480,21 @@ static void mirror_wait_for_all_io(MirrorBlockJob *s)
357786
     }
357786
 }
357786
 
357786
-typedef struct {
357786
-    int ret;
357786
-} MirrorExitData;
357786
-
357786
-static void mirror_exit(Job *job, void *opaque)
357786
+static void mirror_exit(Job *job)
357786
 {
357786
     MirrorBlockJob *s = container_of(job, MirrorBlockJob, common.job);
357786
     BlockJob *bjob = &s->common;
357786
-    MirrorExitData *data = opaque;
357786
     AioContext *replace_aio_context = NULL;
357786
     BlockDriverState *src = s->source;
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
 
357786
     bdrv_release_dirty_bitmap(src, s->dirty_bitmap);
357786
 
357786
-    /* Make sure that the source BDS doesn't go away before we called
357786
-     * job_completed(). */
357786
+    /* Make sure that the source BDS doesn't go away during bdrv_replace_node,
357786
+     * before we can call bdrv_drained_end */
357786
     bdrv_ref(src);
357786
     bdrv_ref(mirror_top_bs);
357786
     bdrv_ref(target_bs);
357786
@@ -524,7 +520,7 @@ static void mirror_exit(Job *job, void *opaque)
357786
             bdrv_set_backing_hd(target_bs, backing, &local_err);
357786
             if (local_err) {
357786
                 error_report_err(local_err);
357786
-                data->ret = -EPERM;
357786
+                ret = -EPERM;
357786
             }
357786
         }
357786
     }
357786
@@ -534,7 +530,7 @@ static void mirror_exit(Job *job, void *opaque)
357786
         aio_context_acquire(replace_aio_context);
357786
     }
357786
 
357786
-    if (s->should_complete && data->ret == 0) {
357786
+    if (s->should_complete && ret == 0) {
357786
         BlockDriverState *to_replace = src;
357786
         if (s->to_replace) {
357786
             to_replace = s->to_replace;
357786
@@ -551,7 +547,7 @@ static void mirror_exit(Job *job, void *opaque)
357786
         bdrv_drained_end(target_bs);
357786
         if (local_err) {
357786
             error_report_err(local_err);
357786
-            data->ret = -EPERM;
357786
+            ret = -EPERM;
357786
         }
357786
     }
357786
     if (s->to_replace) {
357786
@@ -581,12 +577,11 @@ static void mirror_exit(Job *job, void *opaque)
357786
     blk_set_perm(bjob->blk, 0, BLK_PERM_ALL, &error_abort);
357786
     blk_insert_bs(bjob->blk, mirror_top_bs, &error_abort);
357786
 
357786
-    job_completed(job, data->ret);
357786
-
357786
-    g_free(data);
357786
     bdrv_drained_end(src);
357786
     bdrv_unref(mirror_top_bs);
357786
     bdrv_unref(src);
357786
+
357786
+    job->ret = ret;
357786
 }
357786
 
357786
 static void mirror_throttle(MirrorBlockJob *s)
357786
@@ -686,7 +681,6 @@ static int mirror_flush(MirrorBlockJob *s)
357786
 static int coroutine_fn mirror_run(Job *job, Error **errp)
357786
 {
357786
     MirrorBlockJob *s = container_of(job, MirrorBlockJob, common.job);
357786
-    MirrorExitData *data;
357786
     BlockDriverState *bs = s->source;
357786
     BlockDriverState *target_bs = blk_bs(s->target);
357786
     bool need_drain = true;
357786
@@ -896,14 +890,10 @@ immediate_exit:
357786
     g_free(s->in_flight_bitmap);
357786
     bdrv_dirty_iter_free(s->dbi);
357786
 
357786
-    data = g_malloc(sizeof(*data));
357786
-    data->ret = ret;
357786
-
357786
     if (need_drain) {
357786
         bdrv_drained_begin(bs);
357786
     }
357786
 
357786
-    job_defer_to_main_loop(&s->common.job, mirror_exit, data);
357786
     return ret;
357786
 }
357786
 
357786
@@ -996,6 +986,7 @@ 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
         .pause                  = mirror_pause,
357786
         .complete               = mirror_complete,
357786
     },
357786
@@ -1011,6 +1002,7 @@ 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
         .pause                  = mirror_pause,
357786
         .complete               = mirror_complete,
357786
     },
357786
-- 
357786
1.8.3.1
357786