Blame SOURCES/kvm-block-stream-refactor-stream-to-use-job-callbacks.patch

357786
From eca4127792a09e2bf10fdabc5780a2294a2d07da Mon Sep 17 00:00:00 2001
357786
From: John Snow <jsnow@redhat.com>
357786
Date: Mon, 10 Sep 2018 18:17:54 +0200
357786
Subject: [PATCH 16/25] block/stream: refactor stream to use job callbacks
357786
357786
RH-Author: John Snow <jsnow@redhat.com>
357786
Message-id: <20180910181803.11781-17-jsnow@redhat.com>
357786
Patchwork-id: 82093
357786
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 16/25] block/stream: refactor stream to use job callbacks
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
Signed-off-by: John Snow <jsnow@redhat.com>
357786
Reviewed-by: Max Reitz <mreitz@redhat.com>
357786
Message-id: 20180906130225.5118-8-jsnow@redhat.com
357786
Reviewed-by: Jeff Cody <jcody@redhat.com>
357786
Signed-off-by: Max Reitz <mreitz@redhat.com>
357786
(cherry picked from commit 98ebc93c760372630ab181efbc2302f3b6919cd8)
357786
Signed-off-by: John Snow <jsnow@redhat.com>
357786
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
357786
---
357786
 block/stream.c | 23 +++++++++++++++--------
357786
 1 file changed, 15 insertions(+), 8 deletions(-)
357786
357786
diff --git a/block/stream.c b/block/stream.c
357786
index 700eb23..81a7ec8 100644
357786
--- a/block/stream.c
357786
+++ b/block/stream.c
357786
@@ -54,16 +54,16 @@ static int coroutine_fn stream_populate(BlockBackend *blk,
357786
     return blk_co_preadv(blk, offset, qiov.size, &qiov, BDRV_REQ_COPY_ON_READ);
357786
 }
357786
 
357786
-static void stream_exit(Job *job)
357786
+static int stream_prepare(Job *job)
357786
 {
357786
     StreamBlockJob *s = container_of(job, StreamBlockJob, common.job);
357786
     BlockJob *bjob = &s->common;
357786
     BlockDriverState *bs = blk_bs(bjob->blk);
357786
     BlockDriverState *base = s->base;
357786
     Error *local_err = NULL;
357786
-    int ret = job->ret;
357786
+    int ret = 0;
357786
 
357786
-    if (!job_is_cancelled(job) && bs->backing && ret == 0) {
357786
+    if (bs->backing) {
357786
         const char *base_id = NULL, *base_fmt = NULL;
357786
         if (base) {
357786
             base_id = s->backing_file_str;
357786
@@ -75,12 +75,19 @@ static void stream_exit(Job *job)
357786
         bdrv_set_backing_hd(bs, base, &local_err);
357786
         if (local_err) {
357786
             error_report_err(local_err);
357786
-            ret = -EPERM;
357786
-            goto out;
357786
+            return -EPERM;
357786
         }
357786
     }
357786
 
357786
-out:
357786
+    return ret;
357786
+}
357786
+
357786
+static void stream_clean(Job *job)
357786
+{
357786
+    StreamBlockJob *s = container_of(job, StreamBlockJob, common.job);
357786
+    BlockJob *bjob = &s->common;
357786
+    BlockDriverState *bs = blk_bs(bjob->blk);
357786
+
357786
     /* Reopen the image back in read-only mode if necessary */
357786
     if (s->bs_flags != bdrv_get_flags(bs)) {
357786
         /* Give up write permissions before making it read-only */
357786
@@ -89,7 +96,6 @@ out:
357786
     }
357786
 
357786
     g_free(s->backing_file_str);
357786
-    job->ret = ret;
357786
 }
357786
 
357786
 static int coroutine_fn stream_run(Job *job, Error **errp)
357786
@@ -206,7 +212,8 @@ static const BlockJobDriver stream_job_driver = {
357786
         .job_type      = JOB_TYPE_STREAM,
357786
         .free          = block_job_free,
357786
         .run           = stream_run,
357786
-        .exit          = stream_exit,
357786
+        .prepare       = stream_prepare,
357786
+        .clean         = stream_clean,
357786
         .user_resume   = block_job_user_resume,
357786
         .drain         = block_job_drain,
357786
     },
357786
-- 
357786
1.8.3.1
357786