From patchwork Fri Jul 1 15:52:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 9210111 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 E53EC60752 for ; Fri, 1 Jul 2016 15:57:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D7A432853D for ; Fri, 1 Jul 2016 15:57:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC2F52867A; Fri, 1 Jul 2016 15:57:29 +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 645CC2853D for ; Fri, 1 Jul 2016 15:57:29 +0000 (UTC) Received: from localhost ([::1]:34120 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJ0oq-0006Gb-Kd for patchwork-qemu-devel@patchwork.kernel.org; Fri, 01 Jul 2016 11:57:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35865) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJ0kq-0000RW-GD for qemu-devel@nongnu.org; Fri, 01 Jul 2016 11:53:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bJ0kl-0004nU-P7 for qemu-devel@nongnu.org; Fri, 01 Jul 2016 11:53:20 -0400 Received: from smtp3.mundo-r.com ([212.51.32.191]:8370 helo=smtp4.mundo-r.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJ0kl-0004bv-Gh; Fri, 01 Jul 2016 11:53:15 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2D9AQAhkXZX/5tjdVtTCh0BgyCBUo0qlzoGBQGBEJFBgg+Be4YYAoEwOBQBAQEBAQEBZSeETQIEJ1IQPxI8GxmINAHEQgEBCCeFYIJHhmZ0hQ8FjnGKH45EiUuFX0iPQR42g3NriHQBAQE X-IPAS-Result: A2D9AQAhkXZX/5tjdVtTCh0BgyCBUo0qlzoGBQGBEJFBgg+Be4YYAoEwOBQBAQEBAQEBZSeETQIEJ1IQPxI8GxmINAHEQgEBCCeFYIJHhmZ0hQ8FjnGKH45EiUuFX0iPQR42g3NriHQBAQE X-IronPort-AV: E=Sophos;i="5.26,557,1459807200"; d="scan'208";a="146521269" Received: from fanzine.igalia.com ([91.117.99.155]) by smtp4.mundo-r.com with ESMTP; 01 Jul 2016 17:52:29 +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 1bJ0k1-0003iB-4Q; Fri, 01 Jul 2016 17:52:29 +0200 Received: from berto by perseus.local with local (Exim 4.87) (envelope-from ) id 1bJ0jl-0005PH-5Y; Fri, 01 Jul 2016 18:52:13 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 1 Jul 2016 18:52:01 +0300 Message-Id: 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 v3 03/11] 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 , John Snow 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 ce0e27c..ca2291b 100644 --- a/blockjob.c +++ b/blockjob.c @@ -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. diff --git a/include/block/blockjob.h b/include/block/blockjob.h index 5181514..0fe1540 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -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. * @bs: The block