diff options
author | John Snow <jsnow@redhat.com> | 2018-08-29 21:57:26 -0400 |
---|---|---|
committer | Max Reitz <mreitz@redhat.com> | 2018-08-31 16:28:33 +0200 |
commit | f67432a2019caf05b57a146bf45c1024a5cb608e (patch) | |
tree | 8fac71ab094f84d2fe97941428fe69f3a3195844 /block | |
parent | 7b43db3cd08f722d743c443ac3713195875d0301 (diff) |
jobs: change start callback to run callback
Presently we codify the entry point for a job as the "start" callback,
but a more apt name would be "run" to clarify the idea that when this
function returns we consider the job to have "finished," except for
any cleanup which occurs in separate callbacks later.
As part of this clarification, change the signature to include an error
object and a return code. The error ptr is not yet used, and the return
code while captured, will be overwritten by actions in the job_completed
function.
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-id: 20180830015734.19765-2-jsnow@redhat.com
Reviewed-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'block')
-rw-r--r-- | block/backup.c | 7 | ||||
-rw-r--r-- | block/commit.c | 7 | ||||
-rw-r--r-- | block/create.c | 8 | ||||
-rw-r--r-- | block/mirror.c | 10 | ||||
-rw-r--r-- | block/stream.c | 7 |
5 files changed, 23 insertions, 16 deletions
diff --git a/block/backup.c b/block/backup.c index 8630d32926..5d47781840 100644 --- a/block/backup.c +++ b/block/backup.c @@ -480,9 +480,9 @@ static void backup_incremental_init_copy_bitmap(BackupBlockJob *job) bdrv_dirty_iter_free(dbi); } -static void coroutine_fn backup_run(void *opaque) +static int coroutine_fn backup_run(Job *opaque_job, Error **errp) { - BackupBlockJob *job = opaque; + BackupBlockJob *job = container_of(opaque_job, BackupBlockJob, common.job); BackupCompleteData *data; BlockDriverState *bs = blk_bs(job->common.blk); int64_t offset, nb_clusters; @@ -587,6 +587,7 @@ static void coroutine_fn backup_run(void *opaque) data = g_malloc(sizeof(*data)); data->ret = ret; job_defer_to_main_loop(&job->common.job, backup_complete, data); + return ret; } static const BlockJobDriver backup_job_driver = { @@ -596,7 +597,7 @@ static const BlockJobDriver backup_job_driver = { .free = block_job_free, .user_resume = block_job_user_resume, .drain = block_job_drain, - .start = backup_run, + .run = backup_run, .commit = backup_commit, .abort = backup_abort, .clean = backup_clean, diff --git a/block/commit.c b/block/commit.c index eb414579bd..a0ea86ff64 100644 --- a/block/commit.c +++ b/block/commit.c @@ -134,9 +134,9 @@ static void commit_complete(Job *job, void *opaque) bdrv_unref(top); } -static void coroutine_fn commit_run(void *opaque) +static int coroutine_fn commit_run(Job *job, Error **errp) { - CommitBlockJob *s = opaque; + CommitBlockJob *s = container_of(job, CommitBlockJob, common.job); CommitCompleteData *data; int64_t offset; uint64_t delay_ns = 0; @@ -213,6 +213,7 @@ out: data = g_malloc(sizeof(*data)); data->ret = ret; job_defer_to_main_loop(&s->common.job, commit_complete, data); + return ret; } static const BlockJobDriver commit_job_driver = { @@ -222,7 +223,7 @@ static const BlockJobDriver commit_job_driver = { .free = block_job_free, .user_resume = block_job_user_resume, .drain = block_job_drain, - .start = commit_run, + .run = commit_run, }, }; diff --git a/block/create.c b/block/create.c index 915cd41bcc..04733c3618 100644 --- a/block/create.c +++ b/block/create.c @@ -45,9 +45,9 @@ static void blockdev_create_complete(Job *job, void *opaque) job_completed(job, s->ret, s->err); } -static void coroutine_fn blockdev_create_run(void *opaque) +static int coroutine_fn blockdev_create_run(Job *job, Error **errp) { - BlockdevCreateJob *s = opaque; + BlockdevCreateJob *s = container_of(job, BlockdevCreateJob, common); job_progress_set_remaining(&s->common, 1); s->ret = s->drv->bdrv_co_create(s->opts, &s->err); @@ -55,12 +55,14 @@ static void coroutine_fn blockdev_create_run(void *opaque) qapi_free_BlockdevCreateOptions(s->opts); job_defer_to_main_loop(&s->common, blockdev_create_complete, NULL); + + return s->ret; } static const JobDriver blockdev_create_job_driver = { .instance_size = sizeof(BlockdevCreateJob), .job_type = JOB_TYPE_CREATE, - .start = blockdev_create_run, + .run = blockdev_create_run, }; void qmp_blockdev_create(const char *job_id, BlockdevCreateOptions *options, diff --git a/block/mirror.c b/block/mirror.c index 6cc10df5c9..691763db41 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -812,9 +812,9 @@ static int mirror_flush(MirrorBlockJob *s) return ret; } -static void coroutine_fn mirror_run(void *opaque) +static int coroutine_fn mirror_run(Job *job, Error **errp) { - MirrorBlockJob *s = opaque; + MirrorBlockJob *s = container_of(job, MirrorBlockJob, common.job); MirrorExitData *data; BlockDriverState *bs = s->mirror_top_bs->backing->bs; BlockDriverState *target_bs = blk_bs(s->target); @@ -1041,7 +1041,9 @@ immediate_exit: if (need_drain) { bdrv_drained_begin(bs); } + job_defer_to_main_loop(&s->common.job, mirror_exit, data); + return ret; } static void mirror_complete(Job *job, Error **errp) @@ -1138,7 +1140,7 @@ static const BlockJobDriver mirror_job_driver = { .free = block_job_free, .user_resume = block_job_user_resume, .drain = block_job_drain, - .start = mirror_run, + .run = mirror_run, .pause = mirror_pause, .complete = mirror_complete, }, @@ -1154,7 +1156,7 @@ static const BlockJobDriver commit_active_job_driver = { .free = block_job_free, .user_resume = block_job_user_resume, .drain = block_job_drain, - .start = mirror_run, + .run = mirror_run, .pause = mirror_pause, .complete = mirror_complete, }, diff --git a/block/stream.c b/block/stream.c index 9264b68a1e..b4b987df7e 100644 --- a/block/stream.c +++ b/block/stream.c @@ -97,9 +97,9 @@ out: g_free(data); } -static void coroutine_fn stream_run(void *opaque) +static int coroutine_fn stream_run(Job *job, Error **errp) { - StreamBlockJob *s = opaque; + StreamBlockJob *s = container_of(job, StreamBlockJob, common.job); StreamCompleteData *data; BlockBackend *blk = s->common.blk; BlockDriverState *bs = blk_bs(blk); @@ -206,6 +206,7 @@ out: data = g_malloc(sizeof(*data)); data->ret = ret; job_defer_to_main_loop(&s->common.job, stream_complete, data); + return ret; } static const BlockJobDriver stream_job_driver = { @@ -213,7 +214,7 @@ static const BlockJobDriver stream_job_driver = { .instance_size = sizeof(StreamBlockJob), .job_type = JOB_TYPE_STREAM, .free = block_job_free, - .start = stream_run, + .run = stream_run, .user_resume = block_job_user_resume, .drain = block_job_drain, }, |