yeahuh / rpms / qemu-kvm

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