Blame SOURCES/kvm-jobs-change-start-callback-to-run-callback.patch

383d26
From 751387e28f5006dd063010ff0b0912ff9b44c2fe Mon Sep 17 00:00:00 2001
383d26
From: John Snow <jsnow@redhat.com>
383d26
Date: Mon, 10 Sep 2018 18:17:39 +0200
383d26
Subject: [PATCH 01/25] jobs: change start callback to run callback
383d26
383d26
RH-Author: John Snow <jsnow@redhat.com>
383d26
Message-id: <20180910181803.11781-2-jsnow@redhat.com>
383d26
Patchwork-id: 82102
383d26
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 01/25] jobs: change start callback to run callback
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
Presently we codify the entry point for a job as the "start" callback,
383d26
but a more apt name would be "run" to clarify the idea that when this
383d26
function returns we consider the job to have "finished," except for
383d26
any cleanup which occurs in separate callbacks later.
383d26
383d26
As part of this clarification, change the signature to include an error
383d26
object and a return code. The error ptr is not yet used, and the return
383d26
code while captured, will be overwritten by actions in the job_completed
383d26
function.
383d26
383d26
Signed-off-by: John Snow <jsnow@redhat.com>
383d26
Reviewed-by: Max Reitz <mreitz@redhat.com>
383d26
Message-id: 20180830015734.19765-2-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 f67432a2019caf05b57a146bf45c1024a5cb608e)
383d26
Signed-off-by: John Snow <jsnow@redhat.com>
383d26
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
---
383d26
 block/backup.c            |  7 ++++---
383d26
 block/commit.c            |  7 ++++---
383d26
 block/create.c            |  8 +++++---
383d26
 block/mirror.c            | 10 ++++++----
383d26
 block/stream.c            |  7 ++++---
383d26
 include/qemu/job.h        |  2 +-
383d26
 job.c                     |  6 +++---
383d26
 tests/test-bdrv-drain.c   |  7 ++++---
383d26
 tests/test-blockjob-txn.c | 16 ++++++++--------
383d26
 tests/test-blockjob.c     |  7 ++++---
383d26
 10 files changed, 43 insertions(+), 34 deletions(-)
383d26
383d26
diff --git a/block/backup.c b/block/backup.c
383d26
index 4ba1a6a..a142518 100644
383d26
--- a/block/backup.c
383d26
+++ b/block/backup.c
383d26
@@ -480,9 +480,9 @@ static void backup_incremental_init_copy_bitmap(BackupBlockJob *job)
383d26
     bdrv_dirty_iter_free(dbi);
383d26
 }
383d26
 
383d26
-static void coroutine_fn backup_run(void *opaque)
383d26
+static int coroutine_fn backup_run(Job *opaque_job, Error **errp)
383d26
 {
383d26
-    BackupBlockJob *job = opaque;
383d26
+    BackupBlockJob *job = container_of(opaque_job, BackupBlockJob, common.job);
383d26
     BackupCompleteData *data;
383d26
     BlockDriverState *bs = blk_bs(job->common.blk);
383d26
     int64_t offset, nb_clusters;
383d26
@@ -587,6 +587,7 @@ static void coroutine_fn backup_run(void *opaque)
383d26
     data = g_malloc(sizeof(*data));
383d26
     data->ret = ret;
383d26
     job_defer_to_main_loop(&job->common.job, backup_complete, data);
383d26
+    return ret;
383d26
 }
383d26
 
383d26
 static const BlockJobDriver backup_job_driver = {
383d26
@@ -596,7 +597,7 @@ static const BlockJobDriver backup_job_driver = {
383d26
         .free                   = block_job_free,
383d26
         .user_resume            = block_job_user_resume,
383d26
         .drain                  = block_job_drain,
383d26
-        .start                  = backup_run,
383d26
+        .run                    = backup_run,
383d26
         .commit                 = backup_commit,
383d26
         .abort                  = backup_abort,
383d26
         .clean                  = backup_clean,
383d26
diff --git a/block/commit.c b/block/commit.c
383d26
index e1814d9..905a1c5 100644
383d26
--- a/block/commit.c
383d26
+++ b/block/commit.c
383d26
@@ -134,9 +134,9 @@ static void commit_complete(Job *job, void *opaque)
383d26
     bdrv_unref(top);
383d26
 }
383d26
 
383d26
-static void coroutine_fn commit_run(void *opaque)
383d26
+static int coroutine_fn commit_run(Job *job, Error **errp)
383d26
 {
383d26
-    CommitBlockJob *s = opaque;
383d26
+    CommitBlockJob *s = container_of(job, CommitBlockJob, common.job);
383d26
     CommitCompleteData *data;
383d26
     int64_t offset;
383d26
     uint64_t delay_ns = 0;
383d26
@@ -213,6 +213,7 @@ out:
383d26
     data = g_malloc(sizeof(*data));
383d26
     data->ret = ret;
383d26
     job_defer_to_main_loop(&s->common.job, commit_complete, data);
383d26
+    return ret;
383d26
 }
383d26
 
383d26
 static const BlockJobDriver commit_job_driver = {
383d26
@@ -222,7 +223,7 @@ static const BlockJobDriver commit_job_driver = {
383d26
         .free          = block_job_free,
383d26
         .user_resume   = block_job_user_resume,
383d26
         .drain         = block_job_drain,
383d26
-        .start         = commit_run,
383d26
+        .run           = commit_run,
383d26
     },
383d26
 };
383d26
 
383d26
diff --git a/block/create.c b/block/create.c
383d26
index 915cd41..04733c3 100644
383d26
--- a/block/create.c
383d26
+++ b/block/create.c
383d26
@@ -45,9 +45,9 @@ static void blockdev_create_complete(Job *job, void *opaque)
383d26
     job_completed(job, s->ret, s->err);
383d26
 }
383d26
 
383d26
-static void coroutine_fn blockdev_create_run(void *opaque)
383d26
+static int coroutine_fn blockdev_create_run(Job *job, Error **errp)
383d26
 {
383d26
-    BlockdevCreateJob *s = opaque;
383d26
+    BlockdevCreateJob *s = container_of(job, BlockdevCreateJob, common);
383d26
 
383d26
     job_progress_set_remaining(&s->common, 1);
383d26
     s->ret = s->drv->bdrv_co_create(s->opts, &s->err);
383d26
@@ -55,12 +55,14 @@ static void coroutine_fn blockdev_create_run(void *opaque)
383d26
 
383d26
     qapi_free_BlockdevCreateOptions(s->opts);
383d26
     job_defer_to_main_loop(&s->common, blockdev_create_complete, NULL);
383d26
+
383d26
+    return s->ret;
383d26
 }
383d26
 
383d26
 static const JobDriver blockdev_create_job_driver = {
383d26
     .instance_size = sizeof(BlockdevCreateJob),
383d26
     .job_type      = JOB_TYPE_CREATE,
383d26
-    .start         = blockdev_create_run,
383d26
+    .run           = blockdev_create_run,
383d26
 };
383d26
 
383d26
 void qmp_blockdev_create(const char *job_id, BlockdevCreateOptions *options,
383d26
diff --git a/block/mirror.c b/block/mirror.c
383d26
index 65cf43d..03b326d 100644
383d26
--- a/block/mirror.c
383d26
+++ b/block/mirror.c
383d26
@@ -683,9 +683,9 @@ static int mirror_flush(MirrorBlockJob *s)
383d26
     return ret;
383d26
 }
383d26
 
383d26
-static void coroutine_fn mirror_run(void *opaque)
383d26
+static int coroutine_fn mirror_run(Job *job, Error **errp)
383d26
 {
383d26
-    MirrorBlockJob *s = opaque;
383d26
+    MirrorBlockJob *s = container_of(job, MirrorBlockJob, common.job);
383d26
     MirrorExitData *data;
383d26
     BlockDriverState *bs = s->source;
383d26
     BlockDriverState *target_bs = blk_bs(s->target);
383d26
@@ -902,7 +902,9 @@ immediate_exit:
383d26
     if (need_drain) {
383d26
         bdrv_drained_begin(bs);
383d26
     }
383d26
+
383d26
     job_defer_to_main_loop(&s->common.job, mirror_exit, data);
383d26
+    return ret;
383d26
 }
383d26
 
383d26
 static void mirror_complete(Job *job, Error **errp)
383d26
@@ -993,7 +995,7 @@ static const BlockJobDriver mirror_job_driver = {
383d26
         .free                   = block_job_free,
383d26
         .user_resume            = block_job_user_resume,
383d26
         .drain                  = block_job_drain,
383d26
-        .start                  = mirror_run,
383d26
+        .run                    = mirror_run,
383d26
         .pause                  = mirror_pause,
383d26
         .complete               = mirror_complete,
383d26
     },
383d26
@@ -1008,7 +1010,7 @@ static const BlockJobDriver commit_active_job_driver = {
383d26
         .free                   = block_job_free,
383d26
         .user_resume            = block_job_user_resume,
383d26
         .drain                  = block_job_drain,
383d26
-        .start                  = mirror_run,
383d26
+        .run                    = mirror_run,
383d26
         .pause                  = mirror_pause,
383d26
         .complete               = mirror_complete,
383d26
     },
383d26
diff --git a/block/stream.c b/block/stream.c
383d26
index 9264b68..b4b987d 100644
383d26
--- a/block/stream.c
383d26
+++ b/block/stream.c
383d26
@@ -97,9 +97,9 @@ out:
383d26
     g_free(data);
383d26
 }
383d26
 
383d26
-static void coroutine_fn stream_run(void *opaque)
383d26
+static int coroutine_fn stream_run(Job *job, Error **errp)
383d26
 {
383d26
-    StreamBlockJob *s = opaque;
383d26
+    StreamBlockJob *s = container_of(job, StreamBlockJob, common.job);
383d26
     StreamCompleteData *data;
383d26
     BlockBackend *blk = s->common.blk;
383d26
     BlockDriverState *bs = blk_bs(blk);
383d26
@@ -206,6 +206,7 @@ out:
383d26
     data = g_malloc(sizeof(*data));
383d26
     data->ret = ret;
383d26
     job_defer_to_main_loop(&s->common.job, stream_complete, data);
383d26
+    return ret;
383d26
 }
383d26
 
383d26
 static const BlockJobDriver stream_job_driver = {
383d26
@@ -213,7 +214,7 @@ static const BlockJobDriver stream_job_driver = {
383d26
         .instance_size = sizeof(StreamBlockJob),
383d26
         .job_type      = JOB_TYPE_STREAM,
383d26
         .free          = block_job_free,
383d26
-        .start         = stream_run,
383d26
+        .run           = stream_run,
383d26
         .user_resume   = block_job_user_resume,
383d26
         .drain         = block_job_drain,
383d26
     },
383d26
diff --git a/include/qemu/job.h b/include/qemu/job.h
383d26
index 1d82053..e81cc34 100644
383d26
--- a/include/qemu/job.h
383d26
+++ b/include/qemu/job.h
383d26
@@ -169,7 +169,7 @@ struct JobDriver {
383d26
     JobType job_type;
383d26
 
383d26
     /** Mandatory: Entrypoint for the Coroutine. */
383d26
-    CoroutineEntry *start;
383d26
+    int coroutine_fn (*run)(Job *job, Error **errp);
383d26
 
383d26
     /**
383d26
      * If the callback is not NULL, it will be invoked when the job transitions
383d26
diff --git a/job.c b/job.c
383d26
index 95dc998..0d07700 100644
383d26
--- a/job.c
383d26
+++ b/job.c
383d26
@@ -539,16 +539,16 @@ static void coroutine_fn job_co_entry(void *opaque)
383d26
 {
383d26
     Job *job = opaque;
383d26
 
383d26
-    assert(job && job->driver && job->driver->start);
383d26
+    assert(job && job->driver && job->driver->run);
383d26
     job_pause_point(job);
383d26
-    job->driver->start(job);
383d26
+    job->ret = job->driver->run(job, NULL);
383d26
 }
383d26
 
383d26
 
383d26
 void job_start(Job *job)
383d26
 {
383d26
     assert(job && !job_started(job) && job->paused &&
383d26
-           job->driver && job->driver->start);
383d26
+           job->driver && job->driver->run);
383d26
     job->co = qemu_coroutine_create(job_co_entry, job);
383d26
     job->pause_count--;
383d26
     job->busy = true;
383d26
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
383d26
index a11c4cf..798445a 100644
383d26
--- a/tests/test-bdrv-drain.c
383d26
+++ b/tests/test-bdrv-drain.c
383d26
@@ -501,9 +501,9 @@ static void test_job_completed(Job *job, void *opaque)
383d26
     job_completed(job, 0, NULL);
383d26
 }
383d26
 
383d26
-static void coroutine_fn test_job_start(void *opaque)
383d26
+static int coroutine_fn test_job_run(Job *job, Error **errp)
383d26
 {
383d26
-    TestBlockJob *s = opaque;
383d26
+    TestBlockJob *s = container_of(job, TestBlockJob, common.job);
383d26
 
383d26
     job_transition_to_ready(&s->common.job);
383d26
     while (!s->should_complete) {
383d26
@@ -511,6 +511,7 @@ static void coroutine_fn test_job_start(void *opaque)
383d26
     }
383d26
 
383d26
     job_defer_to_main_loop(&s->common.job, test_job_completed, NULL);
383d26
+    return 0;
383d26
 }
383d26
 
383d26
 static void test_job_complete(Job *job, Error **errp)
383d26
@@ -525,7 +526,7 @@ BlockJobDriver test_job_driver = {
383d26
         .free           = block_job_free,
383d26
         .user_resume    = block_job_user_resume,
383d26
         .drain          = block_job_drain,
383d26
-        .start          = test_job_start,
383d26
+        .run            = test_job_run,
383d26
         .complete       = test_job_complete,
383d26
     },
383d26
 };
383d26
diff --git a/tests/test-blockjob-txn.c b/tests/test-blockjob-txn.c
383d26
index 58d9b87..3194924 100644
383d26
--- a/tests/test-blockjob-txn.c
383d26
+++ b/tests/test-blockjob-txn.c
383d26
@@ -38,25 +38,25 @@ static void test_block_job_complete(Job *job, void *opaque)
383d26
     bdrv_unref(bs);
383d26
 }
383d26
 
383d26
-static void coroutine_fn test_block_job_run(void *opaque)
383d26
+static int coroutine_fn test_block_job_run(Job *job, Error **errp)
383d26
 {
383d26
-    TestBlockJob *s = opaque;
383d26
-    BlockJob *job = &s->common;
383d26
+    TestBlockJob *s = container_of(job, TestBlockJob, common.job);
383d26
 
383d26
     while (s->iterations--) {
383d26
         if (s->use_timer) {
383d26
-            job_sleep_ns(&job->job, 0);
383d26
+            job_sleep_ns(job, 0);
383d26
         } else {
383d26
-            job_yield(&job->job);
383d26
+            job_yield(job);
383d26
         }
383d26
 
383d26
-        if (job_is_cancelled(&job->job)) {
383d26
+        if (job_is_cancelled(job)) {
383d26
             break;
383d26
         }
383d26
     }
383d26
 
383d26
-    job_defer_to_main_loop(&job->job, test_block_job_complete,
383d26
+    job_defer_to_main_loop(job, test_block_job_complete,
383d26
                            (void *)(intptr_t)s->rc);
383d26
+    return s->rc;
383d26
 }
383d26
 
383d26
 typedef struct {
383d26
@@ -80,7 +80,7 @@ static const BlockJobDriver test_block_job_driver = {
383d26
         .free          = block_job_free,
383d26
         .user_resume   = block_job_user_resume,
383d26
         .drain         = block_job_drain,
383d26
-        .start         = test_block_job_run,
383d26
+        .run           = test_block_job_run,
383d26
     },
383d26
 };
383d26
 
383d26
diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c
383d26
index cb42f06..b0462bf 100644
383d26
--- a/tests/test-blockjob.c
383d26
+++ b/tests/test-blockjob.c
383d26
@@ -176,9 +176,9 @@ static void cancel_job_complete(Job *job, Error **errp)
383d26
     s->should_complete = true;
383d26
 }
383d26
 
383d26
-static void coroutine_fn cancel_job_start(void *opaque)
383d26
+static int coroutine_fn cancel_job_run(Job *job, Error **errp)
383d26
 {
383d26
-    CancelJob *s = opaque;
383d26
+    CancelJob *s = container_of(job, CancelJob, common.job);
383d26
 
383d26
     while (!s->should_complete) {
383d26
         if (job_is_cancelled(&s->common.job)) {
383d26
@@ -194,6 +194,7 @@ static void coroutine_fn cancel_job_start(void *opaque)
383d26
 
383d26
  defer:
383d26
     job_defer_to_main_loop(&s->common.job, cancel_job_completed, s);
383d26
+    return 0;
383d26
 }
383d26
 
383d26
 static const BlockJobDriver test_cancel_driver = {
383d26
@@ -202,7 +203,7 @@ static const BlockJobDriver test_cancel_driver = {
383d26
         .free          = block_job_free,
383d26
         .user_resume   = block_job_user_resume,
383d26
         .drain         = block_job_drain,
383d26
-        .start         = cancel_job_start,
383d26
+        .run           = cancel_job_run,
383d26
         .complete      = cancel_job_complete,
383d26
     },
383d26
 };
383d26
-- 
383d26
1.8.3.1
383d26