diff options
author | Kevin Wolf <kwolf@redhat.com> | 2018-04-13 18:50:05 +0200 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2018-05-23 14:30:49 +0200 |
commit | 80fa2c756b3241f24015a7503a01f7999d4a942d (patch) | |
tree | db1b410af62162feb7d8b69651a9d671cf4cc030 /include | |
parent | a50c2ab858fe613fb805e53b4f6b970ab936706d (diff) |
job: Add reference counting
This moves reference counting from BlockJob to Job.
In order to keep calling the BlockJob cleanup code when the job is
deleted via job_unref(), introduce a new JobDriver.free callback. Every
block job must use block_job_free() for this callback, this is asserted
in block_job_create().
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/block/blockjob.h | 21 | ||||
-rw-r--r-- | include/block/blockjob_int.h | 7 | ||||
-rw-r--r-- | include/qemu/job.h | 19 |
3 files changed, 24 insertions, 23 deletions
diff --git a/include/block/blockjob.h b/include/block/blockjob.h index 01cdee6d15..087e7820f5 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -132,9 +132,6 @@ typedef struct BlockJob { /** The opaque value that is passed to the completion function. */ void *opaque; - /** Reference count of the block job */ - int refcnt; - /** True when job has reported completion by calling block_job_completed. */ bool completed; @@ -400,24 +397,6 @@ void block_job_iostatus_reset(BlockJob *job); BlockJobTxn *block_job_txn_new(void); /** - * block_job_ref: - * - * Add a reference to BlockJob refcnt, it will be decreased with - * block_job_unref, and then be freed if it comes to be the last - * reference. - */ -void block_job_ref(BlockJob *job); - -/** - * block_job_unref: - * - * Release a reference that was previously acquired with block_job_ref - * or block_job_create. If it's the last reference to the object, it will be - * freed. - */ -void block_job_unref(BlockJob *job); - -/** * block_job_txn_unref: * * Release a reference that was previously acquired with block_job_txn_add_job diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h index 1e62d6dd30..6f0fe3c48d 100644 --- a/include/block/blockjob_int.h +++ b/include/block/blockjob_int.h @@ -144,6 +144,13 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver, BlockCompletionFunc *cb, void *opaque, Error **errp); /** + * block_job_free: + * Callback to be used for JobDriver.free in all block jobs. Frees block job + * specific resources in @job. + */ +void block_job_free(Job *job); + +/** * block_job_sleep_ns: * @job: The job that calls the function. * @ns: How many nanoseconds to stop for. diff --git a/include/qemu/job.h b/include/qemu/job.h index 0b78778b9e..0751e2afab 100644 --- a/include/qemu/job.h +++ b/include/qemu/job.h @@ -41,6 +41,9 @@ typedef struct Job { /** The type of this job. */ const JobDriver *driver; + /** Reference count of the block job */ + int refcnt; + /** Current state; See @JobStatus for details. */ JobStatus status; @@ -57,6 +60,9 @@ struct JobDriver { /** Enum describing the operation */ JobType job_type; + + /** Called when the job is freed */ + void (*free)(Job *job); }; @@ -69,8 +75,17 @@ struct JobDriver { */ void *job_create(const char *job_id, const JobDriver *driver, Error **errp); -/** Frees the @job object. */ -void job_delete(Job *job); +/** + * Add a reference to Job refcnt, it will be decreased with job_unref, and then + * be freed if it comes to be the last reference. + */ +void job_ref(Job *job); + +/** + * Release a reference that was previously acquired with job_ref() or + * job_create(). If it's the last reference to the object, it will be freed. + */ +void job_unref(Job *job); /** Returns the JobType of a given Job. */ JobType job_type(const Job *job); |