From patchwork Mon Apr 4 13:43:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 8741061 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E89939F36E for ; Mon, 4 Apr 2016 13:45:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4D0082024F for ; Mon, 4 Apr 2016 13:45:39 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 5BD36201CE for ; Mon, 4 Apr 2016 13:45:38 +0000 (UTC) Received: from localhost ([::1]:58727 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1an4oz-00024W-Gs for patchwork-qemu-devel@patchwork.kernel.org; Mon, 04 Apr 2016 09:45:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58301) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1an4og-0001zK-VM for qemu-devel@nongnu.org; Mon, 04 Apr 2016 09:45:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1an4od-0000A8-Od for qemu-devel@nongnu.org; Mon, 04 Apr 2016 09:45:18 -0400 Received: from smtp3.mundo-r.com ([212.51.32.191]:15153 helo=smtp4.mundo-r.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1an4od-0008Qw-HL; Mon, 04 Apr 2016 09:45:15 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2CSAwCybgJX/5tjdVtdgzeBUKcVAQEBAQEFAYERAZBmgg8BDYFyhg0CgTM4FAEBAQEBAQFlJ4RCAQEEJ1IQPxI8GxmIKwG9BwEBAQcghViCRYdYhQoFjj2JRI4IiTqFVY8aHgEBQoIEGYFNaYgmAQEB X-IPAS-Result: A2CSAwCybgJX/5tjdVtdgzeBUKcVAQEBAQEFAYERAZBmgg8BDYFyhg0CgTM4FAEBAQEBAQFlJ4RCAQEEJ1IQPxI8GxmIKwG9BwEBAQcghViCRYdYhQoFjj2JRI4IiTqFVY8aHgEBQoIEGYFNaYgmAQEB X-IronPort-AV: E=Sophos;i="5.24,440,1454972400"; d="scan'208";a="39334335" Received: from fanzine.igalia.com ([91.117.99.155]) by smtp4.mundo-r.com with ESMTP; 04 Apr 2016 15:44:37 +0200 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim) id 1an4o0-00050u-Vs; Mon, 04 Apr 2016 15:44:37 +0200 Received: from berto by perseus.local with local (Exim 4.87) (envelope-from ) id 1an4ni-0003vG-Uy; Mon, 04 Apr 2016 16:44:18 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Mon, 4 Apr 2016 16:43:51 +0300 Message-Id: <2c95dbf66898b364e5f3ef134af279fa7ce113c0.1459776815.git.berto@igalia.com> X-Mailer: git-send-email 2.8.0.rc3 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 Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v9 01/11] block: keep a list of block jobs X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The current way to obtain the list of existing block jobs is to iterate over all root nodes and check which ones own a job. Since we want to be able to support block jobs in other nodes as well, this patch keeps a list of jobs that is updated every time one is created or destroyed. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Reviewed-by: Kevin Wolf --- blockjob.c | 13 +++++++++++++ include/block/blockjob.h | 14 ++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/blockjob.c b/blockjob.c index 9fc37ca..3557048 100644 --- a/blockjob.c +++ b/blockjob.c @@ -50,6 +50,16 @@ struct BlockJobTxn { int refcnt; }; +static QLIST_HEAD(, BlockJob) block_jobs = QLIST_HEAD_INITIALIZER(block_jobs); + +BlockJob *block_job_next(BlockJob *job) +{ + if (!job) { + return QLIST_FIRST(&block_jobs); + } + return QLIST_NEXT(job, job_list); +} + void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs, int64_t speed, BlockCompletionFunc *cb, void *opaque, Error **errp) @@ -76,6 +86,8 @@ void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs, job->refcnt = 1; bs->job = job; + QLIST_INSERT_HEAD(&block_jobs, job, job_list); + /* Only set speed when necessary to avoid NotSupported error */ if (speed != 0) { Error *local_err = NULL; @@ -103,6 +115,7 @@ void block_job_unref(BlockJob *job) bdrv_unref(job->bs); error_free(job->blocker); g_free(job->id); + QLIST_REMOVE(job, job_list); g_free(job); } } diff --git a/include/block/blockjob.h b/include/block/blockjob.h index 8bedc49..5d665c1 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -135,6 +135,9 @@ struct BlockJob { */ bool deferred_to_main_loop; + /** Element of the list of block jobs */ + QLIST_ENTRY(BlockJob) job_list; + /** Status that is published by the query-block-jobs QMP API */ BlockDeviceIoStatus iostatus; @@ -173,6 +176,17 @@ struct BlockJob { }; /** + * block_job_next: + * @job: A block job, or %NULL. + * + * Get the next element from the list of block jobs after @job, or the + * first one if @job is %NULL. + * + * Returns the requested job, or %NULL if there are no more jobs left. + */ +BlockJob *block_job_next(BlockJob *job); + +/** * block_job_create: * @job_type: The class object for the newly-created job. * @bs: The block