diff options
author | Kevin Wolf <kwolf@redhat.com> | 2018-04-19 17:30:16 +0200 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2018-05-23 14:30:50 +0200 |
commit | 4ad351819b974d724e926fd23cdd66bec3c9768e (patch) | |
tree | 308f62a669a00a138090cb33e329f0232fdd5baf /include | |
parent | 139a9f020d49e9f863e0d46fd3d0b440dfb3b9d7 (diff) |
job: Move single job finalisation to Job
This moves the finalisation of a single job from BlockJob to Job.
Some part of this code depends on job transactions, and job transactions
call this code, we introduce some temporary calls from Job functions to
BlockJob ones. This will be fixed once transactions move to Job, too.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/block/blockjob.h | 9 | ||||
-rw-r--r-- | include/block/blockjob_int.h | 36 | ||||
-rw-r--r-- | include/qemu/job.h | 53 |
3 files changed, 52 insertions, 46 deletions
diff --git a/include/block/blockjob.h b/include/block/blockjob.h index aef06295f6..3f405d1fa7 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -76,9 +76,6 @@ typedef struct BlockJob { /** Rate limiting data structure for implementing @speed. */ RateLimit limit; - /** The completion function that will be called when the job completes. */ - BlockCompletionFunc *cb; - /** Block other operations when block job is running */ Error *blocker; @@ -94,12 +91,6 @@ typedef struct BlockJob { /** BlockDriverStates that are involved in this block job */ GSList *nodes; - /** The opaque value that is passed to the completion function. */ - void *opaque; - - /** ret code passed to block_job_completed. */ - int ret; - BlockJobTxn *txn; QLIST_ENTRY(BlockJob) txn_list; } BlockJob; diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h index 88639f7efc..bf2b762808 100644 --- a/include/block/blockjob_int.h +++ b/include/block/blockjob_int.h @@ -54,34 +54,6 @@ struct BlockJobDriver { */ int (*prepare)(BlockJob *job); - /** - * If the callback is not NULL, it will be invoked when all the jobs - * belonging to the same transaction complete; or upon this job's - * completion if it is not in a transaction. Skipped if NULL. - * - * All jobs will complete with a call to either .commit() or .abort() but - * never both. - */ - void (*commit)(BlockJob *job); - - /** - * If the callback is not NULL, it will be invoked when any job in the - * same transaction fails; or upon this job's failure (due to error or - * cancellation) if it is not in a transaction. Skipped if NULL. - * - * All jobs will complete with a call to either .commit() or .abort() but - * never both. - */ - void (*abort)(BlockJob *job); - - /** - * If the callback is not NULL, it will be invoked after a call to either - * .commit() or .abort(). Regardless of which callback is invoked after - * completion, .clean() will always be called, even if the job does not - * belong to a transaction group. - */ - void (*clean)(BlockJob *job); - /* * If the callback is not NULL, it will be invoked before the job is * resumed in a new AioContext. This is the place to move any resources @@ -156,14 +128,6 @@ void block_job_yield(BlockJob *job); int64_t block_job_ratelimit_get_delay(BlockJob *job, uint64_t n); /** - * block_job_early_fail: - * @bs: The block device. - * - * The block job could not be started, free it. - */ -void block_job_early_fail(BlockJob *job); - -/** * block_job_completed: * @job: The job being completed. * @ret: The status code. diff --git a/include/qemu/job.h b/include/qemu/job.h index 14d93778f3..3e817beee9 100644 --- a/include/qemu/job.h +++ b/include/qemu/job.h @@ -29,6 +29,7 @@ #include "qapi/qapi-types-block-core.h" #include "qemu/queue.h" #include "qemu/coroutine.h" +#include "block/aio.h" typedef struct JobDriver JobDriver; @@ -105,6 +106,15 @@ typedef struct Job { /** True if this job should automatically dismiss itself */ bool auto_dismiss; + /** ret code passed to block_job_completed. */ + int ret; + + /** The completion function that will be called when the job completes. */ + BlockCompletionFunc *cb; + + /** The opaque value that is passed to the completion function. */ + void *opaque; + /** Notifiers called when a cancelled job is finalised */ NotifierList on_finalize_cancelled; @@ -151,6 +161,35 @@ struct JobDriver { */ void (*user_resume)(Job *job); + /** + * If the callback is not NULL, it will be invoked when all the jobs + * belonging to the same transaction complete; or upon this job's + * completion if it is not in a transaction. Skipped if NULL. + * + * All jobs will complete with a call to either .commit() or .abort() but + * never both. + */ + void (*commit)(Job *job); + + /** + * If the callback is not NULL, it will be invoked when any job in the + * same transaction fails; or upon this job's failure (due to error or + * cancellation) if it is not in a transaction. Skipped if NULL. + * + * All jobs will complete with a call to either .commit() or .abort() but + * never both. + */ + void (*abort)(Job *job); + + /** + * If the callback is not NULL, it will be invoked after a call to either + * .commit() or .abort(). Regardless of which callback is invoked after + * completion, .clean() will always be called, even if the job does not + * belong to a transaction group. + */ + void (*clean)(Job *job); + + /** Called when the job is freed */ void (*free)(Job *job); }; @@ -174,10 +213,12 @@ typedef enum JobCreateFlags { * @driver: The class object for the newly-created job. * @ctx: The AioContext to run the job coroutine in. * @flags: Creation flags for the job. See @JobCreateFlags. + * @cb: Completion function for the job. + * @opaque: Opaque pointer value passed to @cb. * @errp: Error object. */ void *job_create(const char *job_id, const JobDriver *driver, AioContext *ctx, - int flags, Error **errp); + int flags, BlockCompletionFunc *cb, void *opaque, Error **errp); /** * Add a reference to Job refcnt, it will be decreased with job_unref, and then @@ -300,6 +341,10 @@ Job *job_get(const char *id); */ int job_apply_verb(Job *job, JobVerb verb, Error **errp); +/** The @job could not be started, free it. */ +void job_early_fail(Job *job); + + typedef void JobDeferToMainLoopFn(Job *job, void *opaque); /** @@ -322,5 +367,11 @@ void job_state_transition(Job *job, JobStatus s1); void coroutine_fn job_do_yield(Job *job, uint64_t ns); bool job_should_pause(Job *job); bool job_started(Job *job); +void job_do_dismiss(Job *job); +int job_finalize_single(Job *job); +void job_update_rc(Job *job); + +typedef struct BlockJob BlockJob; +void block_job_txn_del_job(BlockJob *job); #endif |