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

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