yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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