aboutsummaryrefslogtreecommitdiff
path: root/include/qemu/job.h
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2018-04-13 18:50:05 +0200
committerKevin Wolf <kwolf@redhat.com>2018-05-23 14:30:49 +0200
commit80fa2c756b3241f24015a7503a01f7999d4a942d (patch)
treedb1b410af62162feb7d8b69651a9d671cf4cc030 /include/qemu/job.h
parenta50c2ab858fe613fb805e53b4f6b970ab936706d (diff)
downloadqemu-80fa2c756b3241f24015a7503a01f7999d4a942d.zip
qemu-80fa2c756b3241f24015a7503a01f7999d4a942d.tar.gz
qemu-80fa2c756b3241f24015a7503a01f7999d4a942d.tar.bz2
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/qemu/job.h')
-rw-r--r--include/qemu/job.h19
1 files changed, 17 insertions, 2 deletions
diff --git a/include/qemu/job.h b/include/qemu/job.h
index 0b78778..0751e2a 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);