yeahuh / rpms / qemu-kvm

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