]> git.proxmox.com Git - mirror_qemu.git/commitdiff
blockjob: Add block_job_get()
authorAlberto Garcia <berto@igalia.com>
Tue, 5 Jul 2016 14:28:54 +0000 (17:28 +0300)
committerKevin Wolf <kwolf@redhat.com>
Wed, 13 Jul 2016 11:26:02 +0000 (13:26 +0200)
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>
blockjob.c
include/block/blockjob.h

index ce0e27c124b5d70cd5a5de8f6e7cc1a230c70202..ca2291b5c56ababe1149edfef3572e249404c220 100644 (file)
@@ -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.
index 97b86f109f3a777df6f1a68060a5ff01a5258968..934bf1ce2d50ae7d31aeb367be4a799867b0f484 100644 (file)
@@ -211,6 +211,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.