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