yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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