diff options
author | Alberto Garcia <berto@igalia.com> | 2016-04-04 16:43:51 +0300 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2016-05-25 19:04:21 +0200 |
commit | a7112795c14d99b81600f8809fda5ce18b430830 (patch) | |
tree | f422a21a2d8ccafde4d68b61a11b17842208d13d /blockjob.c | |
parent | d004bd52aacbe9bf43c38fa6cb20a6f241ac64be (diff) |
block: keep a list of block jobs
The current way to obtain the list of existing block jobs is to
iterate over all root nodes and check which ones own a job.
Since we want to be able to support block jobs in other nodes as well,
this patch keeps a list of jobs that is updated every time one is
created or destroyed.
Signed-off-by: Alberto Garcia <berto@igalia.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'blockjob.c')
-rw-r--r-- | blockjob.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/blockjob.c b/blockjob.c index 5b840a7df6..0f1bc77b1d 100644 --- a/blockjob.c +++ b/blockjob.c @@ -50,6 +50,16 @@ struct BlockJobTxn { int refcnt; }; +static QLIST_HEAD(, BlockJob) block_jobs = QLIST_HEAD_INITIALIZER(block_jobs); + +BlockJob *block_job_next(BlockJob *job) +{ + if (!job) { + return QLIST_FIRST(&block_jobs); + } + return QLIST_NEXT(job, job_list); +} + void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs, int64_t speed, BlockCompletionFunc *cb, void *opaque, Error **errp) @@ -76,6 +86,8 @@ void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs, job->refcnt = 1; bs->job = job; + QLIST_INSERT_HEAD(&block_jobs, job, job_list); + /* Only set speed when necessary to avoid NotSupported error */ if (speed != 0) { Error *local_err = NULL; @@ -103,6 +115,7 @@ void block_job_unref(BlockJob *job) bdrv_unref(job->bs); error_free(job->blocker); g_free(job->id); + QLIST_REMOVE(job, job_list); g_free(job); } } |