From patchwork Wed Jun 22 12:25:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 9192651 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7855F6075A for ; Wed, 22 Jun 2016 12:35:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 69199283E9 for ; Wed, 22 Jun 2016 12:35:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5DB82283FD; Wed, 22 Jun 2016 12:35:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D6367283E9 for ; Wed, 22 Jun 2016 12:35:52 +0000 (UTC) Received: from localhost ([::1]:57955 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFhNo-0005do-0E for patchwork-qemu-devel@patchwork.kernel.org; Wed, 22 Jun 2016 08:35:52 -0400 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 Received: from smtp3.mundo-r.com ([212.51.32.191]:10832 helo=smtp4.mundo-r.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFhE8-0001w7-1y; Wed, 22 Jun 2016 08:25:52 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2CqAgCmgmpX/5tjdVtUCh6DIIFTpVgBAQEBAQEFAYEPAZExgg+BeoYXAoEsOBQBAQEBAQEBZSeETQIEJ1IQPxI8GxmINAHDCgEBCCeFX4JHhmZ0hQ8FjmiKFY4tiUaFXUiPNB42g3NrinEBAQE X-IPAS-Result: A2CqAgCmgmpX/5tjdVtUCh6DIIFTpVgBAQEBAQEFAYEPAZExgg+BeoYXAoEsOBQBAQEBAQEBZSeETQIEJ1IQPxI8GxmINAHDCgEBCCeFX4JHhmZ0hQ8FjmiKFY4tiUaFXUiPNB42g3NrinEBAQE X-IronPort-AV: E=Sophos;i="5.26,509,1459807200"; d="scan'208";a="76201812" Received: from fanzine.igalia.com ([91.117.99.155]) by smtp4.mundo-r.com with ESMTP; 22 Jun 2016 14:25:48 +0200 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim) id 1bFhE4-0004kU-6E; Wed, 22 Jun 2016 14:25:48 +0200 Received: from berto by perseus.local with local (Exim 4.87) (envelope-from ) id 1bFhDo-0007FK-Cw; Wed, 22 Jun 2016 15:25:32 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 22 Jun 2016 15:25:00 +0300 Message-Id: <0cd54b0b40980c66e798b19d98daa90987defe45.1466598035.git.berto@igalia.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 212.51.32.191 Subject: [Qemu-devel] [PATCH v2 03/15] blockjob: Add block_job_get() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Jeff Cody , Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Kevin Wolf --- 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