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