yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
26ba25
From 1203019dd3f126849c6409db6a282342e7cf1280 Mon Sep 17 00:00:00 2001
26ba25
From: John Snow <jsnow@redhat.com>
26ba25
Date: Tue, 25 Sep 2018 22:34:10 +0100
26ba25
Subject: [PATCH 07/28] block/commit: utilize job_exit shim
26ba25
26ba25
RH-Author: John Snow <jsnow@redhat.com>
26ba25
Message-id: <20180925223431.24791-5-jsnow@redhat.com>
26ba25
Patchwork-id: 82265
26ba25
O-Subject: [RHEL8/rhel qemu-kvm PATCH 04/25] block/commit: 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 commit_complete into the implicit
26ba25
callback to job_exit, renaming commit_complete to commit_exit.
26ba25
26ba25
This conversion does change the timing of when job_completed is
26ba25
called to after the bdrv_replace_node and bdrv_unref calls, which
26ba25
could have implications for bjob->blk which will now be put down
26ba25
after this cleanup.
26ba25
26ba25
Kevin highlights that we did not take any permissions for that backend
26ba25
at job creation time, so it is safe to reorder these operations.
26ba25
26ba25
Signed-off-by: John Snow <jsnow@redhat.com>
26ba25
Reviewed-by: Max Reitz <mreitz@redhat.com>
26ba25
Message-id: 20180830015734.19765-5-jsnow@redhat.com
26ba25
Reviewed-by: Jeff Cody <jcody@redhat.com>
26ba25
Signed-off-by: Max Reitz <mreitz@redhat.com>
26ba25
(cherry picked from commit f369b48dc4095861223f9bc4329935599e03b1c5)
26ba25
Signed-off-by: John Snow <jsnow@redhat.com>
26ba25
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
26ba25
---
26ba25
 block/commit.c | 22 +++++-----------------
26ba25
 1 file changed, 5 insertions(+), 17 deletions(-)
26ba25
26ba25
diff --git a/block/commit.c b/block/commit.c
26ba25
index af7579d..25b3cb8 100644
26ba25
--- a/block/commit.c
26ba25
+++ b/block/commit.c
26ba25
@@ -68,19 +68,13 @@ static int coroutine_fn commit_populate(BlockBackend *bs, BlockBackend *base,
26ba25
     return 0;
26ba25
 }
26ba25
 
26ba25
-typedef struct {
26ba25
-    int ret;
26ba25
-} CommitCompleteData;
26ba25
-
26ba25
-static void commit_complete(Job *job, void *opaque)
26ba25
+static void commit_exit(Job *job)
26ba25
 {
26ba25
     CommitBlockJob *s = container_of(job, CommitBlockJob, common.job);
26ba25
     BlockJob *bjob = &s->common;
26ba25
-    CommitCompleteData *data = opaque;
26ba25
     BlockDriverState *top = blk_bs(s->top);
26ba25
     BlockDriverState *base = blk_bs(s->base);
26ba25
     BlockDriverState *commit_top_bs = s->commit_top_bs;
26ba25
-    int ret = data->ret;
26ba25
     bool remove_commit_top_bs = false;
26ba25
 
26ba25
     /* Make sure commit_top_bs and top stay around until bdrv_replace_node() */
26ba25
@@ -91,10 +85,10 @@ static void commit_complete(Job *job, void *opaque)
26ba25
      * the normal backing chain can be restored. */
26ba25
     blk_unref(s->base);
26ba25
 
26ba25
-    if (!job_is_cancelled(job) && ret == 0) {
26ba25
+    if (!job_is_cancelled(job) && job->ret == 0) {
26ba25
         /* success */
26ba25
-        ret = bdrv_drop_intermediate(s->commit_top_bs, base,
26ba25
-                                     s->backing_file_str);
26ba25
+        job->ret = bdrv_drop_intermediate(s->commit_top_bs, base,
26ba25
+                                          s->backing_file_str);
26ba25
     } else {
26ba25
         /* XXX Can (or should) we somehow keep 'consistent read' blocked even
26ba25
          * after the failed/cancelled commit job is gone? If we already wrote
26ba25
@@ -117,9 +111,6 @@ static void commit_complete(Job *job, void *opaque)
26ba25
      * bdrv_set_backing_hd() to fail. */
26ba25
     block_job_remove_all_bdrv(bjob);
26ba25
 
26ba25
-    job_completed(job, ret);
26ba25
-    g_free(data);
26ba25
-
26ba25
     /* If bdrv_drop_intermediate() didn't already do that, remove the commit
26ba25
      * filter driver from the backing chain. Do this as the final step so that
26ba25
      * the 'consistent read' permission can be granted.  */
26ba25
@@ -137,7 +128,6 @@ static void commit_complete(Job *job, void *opaque)
26ba25
 static int coroutine_fn commit_run(Job *job, Error **errp)
26ba25
 {
26ba25
     CommitBlockJob *s = container_of(job, CommitBlockJob, common.job);
26ba25
-    CommitCompleteData *data;
26ba25
     int64_t offset;
26ba25
     uint64_t delay_ns = 0;
26ba25
     int ret = 0;
26ba25
@@ -210,9 +200,6 @@ static int coroutine_fn commit_run(Job *job, Error **errp)
26ba25
 out:
26ba25
     qemu_vfree(buf);
26ba25
 
26ba25
-    data = g_malloc(sizeof(*data));
26ba25
-    data->ret = ret;
26ba25
-    job_defer_to_main_loop(&s->common.job, commit_complete, data);
26ba25
     return ret;
26ba25
 }
26ba25
 
26ba25
@@ -224,6 +211,7 @@ static const BlockJobDriver commit_job_driver = {
26ba25
         .user_resume   = block_job_user_resume,
26ba25
         .drain         = block_job_drain,
26ba25
         .run           = commit_run,
26ba25
+        .exit          = commit_exit,
26ba25
     },
26ba25
 };
26ba25
 
26ba25
-- 
26ba25
1.8.3.1
26ba25