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>
This commit is contained in:
parent
d004bd52aa
commit
a7112795c1
13
blockjob.c
13
blockjob.c
@ -50,6 +50,16 @@ struct BlockJobTxn {
|
|||||||
int refcnt;
|
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,
|
void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs,
|
||||||
int64_t speed, BlockCompletionFunc *cb,
|
int64_t speed, BlockCompletionFunc *cb,
|
||||||
void *opaque, Error **errp)
|
void *opaque, Error **errp)
|
||||||
@ -76,6 +86,8 @@ void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs,
|
|||||||
job->refcnt = 1;
|
job->refcnt = 1;
|
||||||
bs->job = job;
|
bs->job = job;
|
||||||
|
|
||||||
|
QLIST_INSERT_HEAD(&block_jobs, job, job_list);
|
||||||
|
|
||||||
/* Only set speed when necessary to avoid NotSupported error */
|
/* Only set speed when necessary to avoid NotSupported error */
|
||||||
if (speed != 0) {
|
if (speed != 0) {
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
@ -103,6 +115,7 @@ void block_job_unref(BlockJob *job)
|
|||||||
bdrv_unref(job->bs);
|
bdrv_unref(job->bs);
|
||||||
error_free(job->blocker);
|
error_free(job->blocker);
|
||||||
g_free(job->id);
|
g_free(job->id);
|
||||||
|
QLIST_REMOVE(job, job_list);
|
||||||
g_free(job);
|
g_free(job);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,6 +135,9 @@ struct BlockJob {
|
|||||||
*/
|
*/
|
||||||
bool deferred_to_main_loop;
|
bool deferred_to_main_loop;
|
||||||
|
|
||||||
|
/** Element of the list of block jobs */
|
||||||
|
QLIST_ENTRY(BlockJob) job_list;
|
||||||
|
|
||||||
/** Status that is published by the query-block-jobs QMP API */
|
/** Status that is published by the query-block-jobs QMP API */
|
||||||
BlockDeviceIoStatus iostatus;
|
BlockDeviceIoStatus iostatus;
|
||||||
|
|
||||||
@ -172,6 +175,17 @@ struct BlockJob {
|
|||||||
QLIST_ENTRY(BlockJob) txn_list;
|
QLIST_ENTRY(BlockJob) txn_list;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* block_job_next:
|
||||||
|
* @job: A block job, or %NULL.
|
||||||
|
*
|
||||||
|
* Get the next element from the list of block jobs after @job, or the
|
||||||
|
* first one if @job is %NULL.
|
||||||
|
*
|
||||||
|
* Returns the requested job, or %NULL if there are no more jobs left.
|
||||||
|
*/
|
||||||
|
BlockJob *block_job_next(BlockJob *job);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* block_job_create:
|
* block_job_create:
|
||||||
* @job_type: The class object for the newly-created job.
|
* @job_type: The class object for the newly-created job.
|
||||||
|
Loading…
Reference in New Issue
Block a user