summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlberto Garcia <berto@igalia.com>2016-07-05 17:28:54 +0300
committerKevin Wolf <kwolf@redhat.com>2016-07-13 13:26:02 +0200
commitffb1f10cd1118393627e1bd2dad0a68152d2e539 (patch)
tree6bc5ce3d7c06bb0f80324b0b696050e908c8093c
parent9df229c3caf6559a37c8760ef6e1485e66bbae41 (diff)
downloadqemu-ffb1f10cd1118393627e1bd2dad0a68152d2e539.tar.gz
blockjob: Add block_job_get()
Currently the way to look for a specific block job is to iterate the list manually using block_job_next(). Since we want to be able to identify a job primarily by its ID it makes sense to have a function that does just that. Signed-off-by: Alberto Garcia <berto@igalia.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
-rw-r--r--blockjob.c13
-rw-r--r--include/block/blockjob.h10
2 files changed, 23 insertions, 0 deletions
diff --git a/blockjob.c b/blockjob.c
index ce0e27c124..ca2291b5c5 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -60,6 +60,19 @@ BlockJob *block_job_next(BlockJob *job)
return QLIST_NEXT(job, job_list);
}
+BlockJob *block_job_get(const char *id)
+{
+ BlockJob *job;
+
+ QLIST_FOREACH(job, &block_jobs, job_list) {
+ if (!strcmp(id, job->id)) {
+ return job;
+ }
+ }
+
+ return NULL;
+}
+
/* Normally the job runs in its BlockBackend's AioContext. The exception is
* block_job_defer_to_main_loop() where it runs in the QEMU main loop. Code
* that supports both cases uses this helper function.
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
index 97b86f109f..934bf1ce2d 100644
--- a/include/block/blockjob.h
+++ b/include/block/blockjob.h
@@ -212,6 +212,16 @@ struct BlockJob {
BlockJob *block_job_next(BlockJob *job);
/**
+ * block_job_get:
+ * @id: The id of the block job.
+ *
+ * Get the block job identified by @id (which must not be %NULL).
+ *
+ * Returns the requested job, or %NULL if it doesn't exist.
+ */
+BlockJob *block_job_get(const char *id);
+
+/**
* block_job_create:
* @job_type: The class object for the newly-created job.
* @bs: The block