From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49998) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFhEF-0003Zq-9n for qemu-devel@nongnu.org; Wed, 22 Jun 2016 08:26:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bFhE8-0001wW-9Y for qemu-devel@nongnu.org; Wed, 22 Jun 2016 08:25:59 -0400 From: Alberto Garcia Date: Wed, 22 Jun 2016 15:25:00 +0300 Message-Id: <0cd54b0b40980c66e798b19d98daa90987defe45.1466598035.git.berto@igalia.com> In-Reply-To: References: In-Reply-To: References: Subject: [Qemu-devel] [PATCH v2 03/15] blockjob: Add block_job_get() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Max Reitz , Eric Blake , Kevin Wolf , Jeff Cody , Alberto Garcia 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 Reviewed-by: Max Reitz --- blockjob.c | 13 +++++++++++++ include/block/blockjob.h | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/blockjob.c b/blockjob.c index 8bcb5ea..51c6402 100644 --- a/blockjob.c +++ b/blockjob.c @@ -61,6 +61,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 856486a..9f28230 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -218,6 +218,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 -- 2.8.1