yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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