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

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