Commit ffb1f10c authored by Alberto Garcia's avatar Alberto Garcia Committed by Kevin Wolf
Browse files

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: default avatarAlberto Garcia <berto@igalia.com>
Reviewed-by: default avatarMax Reitz <mreitz@redhat.com>
Reviewed-by: default avatarKevin Wolf <kwolf@redhat.com>
Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
parent 9df229c3
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -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.
+10 −0
Original line number Diff line number Diff line
@@ -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.