cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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