diff options
author | Kevin Wolf <kwolf@redhat.com> | 2018-04-23 16:06:26 +0200 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2018-05-23 14:30:51 +0200 |
commit | 7eaa8fb57da96301f4a8ce176ad503f80efc7cc0 (patch) | |
tree | 2450798efd3aa3104933bceeb7d44dfe1d8edf51 /include | |
parent | 62c9e4162a7bc26a1389e50d17d3b2637028bbc3 (diff) |
job: Move transactions to Job
This moves the logic that implements job transactions from BlockJob to
Job.
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 | 54 | ||||
-rw-r--r-- | include/block/blockjob_int.h | 10 | ||||
-rw-r--r-- | include/qemu/job.h | 71 |
3 files changed, 62 insertions, 73 deletions
diff --git a/include/block/blockjob.h b/include/block/blockjob.h index 44df025bd0..09e6bb42bf 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -33,7 +33,6 @@ #define BLOCK_JOB_SLICE_TIME 100000000ULL /* ns */ typedef struct BlockJobDriver BlockJobDriver; -typedef struct JobTxn JobTxn; /** * BlockJob: @@ -84,8 +83,6 @@ typedef struct BlockJob { /** BlockDriverStates that are involved in this block job */ GSList *nodes; - - JobTxn *txn; } BlockJob; /** @@ -153,22 +150,6 @@ void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp); void block_job_cancel(BlockJob *job, bool force); /** - * block_job_finalize: - * @job: The job to fully commit and finish. - * @errp: Error object. - * - * For jobs that have finished their work and are pending - * awaiting explicit acknowledgement to commit their work, - * This will commit that work. - * - * FIXME: Make the below statement universally true: - * For jobs that support the manual workflow mode, all graph - * changes that occur as a result will occur after this command - * and before a successful reply. - */ -void block_job_finalize(BlockJob *job, Error **errp); - -/** * block_job_dismiss: * @job: The job to be dismissed. * @errp: Error object. @@ -260,41 +241,6 @@ int block_job_complete_sync(BlockJob *job, Error **errp); void block_job_iostatus_reset(BlockJob *job); /** - * block_job_txn_new: - * - * Allocate and return a new block job transaction. Jobs can be added to the - * transaction using block_job_txn_add_job(). - * - * The transaction is automatically freed when the last job completes or is - * cancelled. - * - * All jobs in the transaction either complete successfully or fail/cancel as a - * group. Jobs wait for each other before completing. Cancelling one job - * cancels all jobs in the transaction. - */ -JobTxn *block_job_txn_new(void); - -/** - * block_job_txn_unref: - * - * Release a reference that was previously acquired with block_job_txn_add_job - * or block_job_txn_new. If it's the last reference to the object, it will be - * freed. - */ -void block_job_txn_unref(JobTxn *txn); - -/** - * block_job_txn_add_job: - * @txn: The transaction (may be NULL) - * @job: Job to add to the transaction - * - * Add @job to the transaction. The @job must not already be in a transaction. - * The caller must call either block_job_txn_unref() or block_job_completed() - * to release the reference that is automatically grabbed here. - */ -void block_job_txn_add_job(JobTxn *txn, BlockJob *job); - -/** * block_job_is_internal: * @job: The job to determine if it is user-visible or not. * diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h index ce66a9b51c..29a28020ac 100644 --- a/include/block/blockjob_int.h +++ b/include/block/blockjob_int.h @@ -38,16 +38,6 @@ struct BlockJobDriver { /** Generic JobDriver callbacks and settings */ JobDriver job_driver; - /** - * If the callback is not NULL, prepare 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. - * - * This callback will not be invoked if the job has already failed. - * If it fails, abort and then clean will be called. - */ - int (*prepare)(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 diff --git a/include/qemu/job.h b/include/qemu/job.h index d4aa7fa981..39d74abdec 100644 --- a/include/qemu/job.h +++ b/include/qemu/job.h @@ -32,6 +32,8 @@ #include "block/aio.h" typedef struct JobDriver JobDriver; +typedef struct JobTxn JobTxn; + /** * Long-running operation. @@ -133,6 +135,9 @@ typedef struct Job { /** Element of the list of jobs */ QLIST_ENTRY(Job) job_list; + /** Transaction this job is part of */ + JobTxn *txn; + /** Element of the list of jobs in a job transaction */ QLIST_ENTRY(Job) txn_list; } Job; @@ -184,6 +189,16 @@ struct JobDriver { void (*drain)(Job *job); /** + * If the callback is not NULL, prepare 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. + * + * This callback will not be invoked if the job has already failed. + * If it fails, abort and then clean will be called. + */ + int (*prepare)(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. @@ -227,20 +242,52 @@ typedef enum JobCreateFlags { JOB_MANUAL_DISMISS = 0x04, } JobCreateFlags; +/** + * Allocate and return a new job transaction. Jobs can be added to the + * transaction using job_txn_add_job(). + * + * The transaction is automatically freed when the last job completes or is + * cancelled. + * + * All jobs in the transaction either complete successfully or fail/cancel as a + * group. Jobs wait for each other before completing. Cancelling one job + * cancels all jobs in the transaction. + */ +JobTxn *job_txn_new(void); + +/** + * Release a reference that was previously acquired with job_txn_add_job or + * job_txn_new. If it's the last reference to the object, it will be freed. + */ +void job_txn_unref(JobTxn *txn); + +/** + * @txn: The transaction (may be NULL) + * @job: Job to add to the transaction + * + * Add @job to the transaction. The @job must not already be in a transaction. + * The caller must call either job_txn_unref() or block_job_completed() to + * release the reference that is automatically grabbed here. + * + * If @txn is NULL, the function does nothing. + */ +void job_txn_add_job(JobTxn *txn, Job *job); /** * Create a new long-running job and return it. * * @job_id: The id of the newly-created job, or %NULL for internal jobs * @driver: The class object for the newly-created job. + * @txn: The transaction this job belongs to, if any. %NULL otherwise. * @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, BlockCompletionFunc *cb, void *opaque, Error **errp); +void *job_create(const char *job_id, const JobDriver *driver, JobTxn *txn, + AioContext *ctx, int flags, BlockCompletionFunc *cb, + void *opaque, Error **errp); /** * Add a reference to Job refcnt, it will be decreased with job_unref, and then @@ -260,9 +307,6 @@ void job_event_cancelled(Job *job); /** To be called when a successfully completed job is finalised. */ void job_event_completed(Job *job); -/** To be called when the job transitions to PENDING */ -void job_event_pending(Job *job); - /** * Conditionally enter the job coroutine if the job is ready to run, not * already busy and fn() returns true. fn() is called while under the job_lock @@ -375,6 +419,16 @@ void job_early_fail(Job *job); /** Asynchronously complete the specified @job. */ void job_complete(Job *job, Error **errp);; +/** + * For a @job that has finished its work and is pending awaiting explicit + * acknowledgement to commit its work, this will commit that work. + * + * FIXME: Make the below statement universally true: + * For jobs that support the manual workflow mode, all graph changes that occur + * as a result will occur after this command and before a successful reply. + */ +void job_finalize(Job *job, Error **errp); + typedef void JobDeferToMainLoopFn(Job *job, void *opaque); /** @@ -407,10 +461,9 @@ 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); +void job_cancel_async(Job *job, bool force); +void job_completed_txn_abort(Job *job); +void job_completed_txn_success(Job *job); #endif |