From patchwork Thu Jun 9 08:20:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 9166453 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 CB7A16048F for ; Thu, 9 Jun 2016 08:29:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B22CA27248 for ; Thu, 9 Jun 2016 08:29:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A530628326; Thu, 9 Jun 2016 08:29:56 +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 3F51127248 for ; Thu, 9 Jun 2016 08:29:56 +0000 (UTC) Received: from localhost ([::1]:33060 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAvLe-0004UL-MU for patchwork-qemu-devel@patchwork.kernel.org; Thu, 09 Jun 2016 04:29:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60003) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAvD8-0004be-4J for qemu-devel@nongnu.org; Thu, 09 Jun 2016 04:21:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bAvD0-0004en-3G for qemu-devel@nongnu.org; Thu, 09 Jun 2016 04:21:05 -0400 Received: from smtp3.mundo-r.com ([212.51.32.191]:26734 helo=smtp4.mundo-r.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAvCz-0004eV-S1; Thu, 09 Jun 2016 04:20:58 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2DDCgBDJllX/5tjdVtUCh0BgyCBU6ZEAQEBAQEBBQGBDwGRJYQJhhMCgT87EQEBAQEBAQFlJ4RGAgQnUhA/EjwbGYgzAb4LATCFX4JHhmZ0hQ4FjlqJeI4miUSFW0aPHTQgggccgU5riggBAQE X-IPAS-Result: A2DDCgBDJllX/5tjdVtUCh0BgyCBU6ZEAQEBAQEBBQGBDwGRJYQJhhMCgT87EQEBAQEBAQFlJ4RGAgQnUhA/EjwbGYgzAb4LATCFX4JHhmZ0hQ4FjlqJeI4miUSFW0aPHTQgggccgU5riggBAQE X-IronPort-AV: E=Sophos;i="5.26,443,1459807200"; d="scan'208";a="71068671" Received: from fanzine.igalia.com ([91.117.99.155]) by smtp4.mundo-r.com with ESMTP; 09 Jun 2016 10:20:53 +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 1bAvCv-0007zC-3S; Thu, 09 Jun 2016 10:20:53 +0200 Received: from berto by perseus.local with local (Exim 4.87) (envelope-from ) id 1bAvCf-00051U-B6; Thu, 09 Jun 2016 11:20:37 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 9 Jun 2016 11:20:08 +0300 Message-Id: <3d3617592f14762be20abff8d4a3937e79b133dc.1465459496.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 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 --- blockjob.c | 13 +++++++++++++ include/block/blockjob.h | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/blockjob.c b/blockjob.c index 4d42987..a4a1caf 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; +} + void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs, int64_t speed, BlockCompletionFunc *cb, void *opaque, Error **errp) diff --git a/include/block/blockjob.h b/include/block/blockjob.h index 1533006..46d2af2 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -191,6 +191,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