From patchwork Thu Apr 16 15:12:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 461798 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 9E78A1402E1 for ; Fri, 17 Apr 2015 01:16:00 +1000 (AEST) Received: from localhost ([::1]:37317 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YilWI-0001c4-Hh for incoming@patchwork.ozlabs.org; Thu, 16 Apr 2015 11:15:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36173) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YilTw-0006Qj-0G for qemu-devel@nongnu.org; Thu, 16 Apr 2015 11:13:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YilTr-0004z4-6E for qemu-devel@nongnu.org; Thu, 16 Apr 2015 11:13:31 -0400 Received: from smtp3.mundo-r.com ([212.51.32.191]:40680 helo=smtp4.mundo-r.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YilTq-0004yE-VJ; Thu, 16 Apr 2015 11:13:27 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqcFAA3RL1VbdWOb/2dsb2JhbABcgwyBLrQjAQEEBQF7mC8CgURMAQEBAQEBfoQhAQEEJ1IQPxI8GxmILgHIMAEBCCKGEIoXB4QtBYYohQeQAJR7IoFFPhyBU2yCQwEBAQ X-IPAS-Result: AqcFAA3RL1VbdWOb/2dsb2JhbABcgwyBLrQjAQEEBQF7mC8CgURMAQEBAQEBfoQhAQEEJ1IQPxI8GxmILgHIMAEBCCKGEIoXB4QtBYYohQeQAJR7IoFFPhyBU2yCQwEBAQ X-IronPort-AV: E=Sophos;i="5.11,588,1422918000"; d="scan'208";a="341793875" Received: from fanzine.igalia.com ([91.117.99.155]) by smtp4.mundo-r.com with ESMTP; 16 Apr 2015 17:13:22 +0200 Received: from dsl-hkibrasgw4-50df50-128.dhcp.inet.fi ([80.223.80.128] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim) id 1YilTi-0001NG-1d; Thu, 16 Apr 2015 17:13:18 +0200 Received: from berto by perseus.local with local (Exim 4.84) (envelope-from ) id 1YilTU-0003ov-7k; Thu, 16 Apr 2015 18:13:04 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 16 Apr 2015 18:12:51 +0300 Message-Id: X-Mailer: git-send-email 2.1.4 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 1/8] 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 everytime one is created or destroyed. This also updates qmp_query_block_jobs() to use this new list. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Reviewed-by: Eric Blake --- blockdev.c | 19 ++++++++----------- blockjob.c | 13 +++++++++++++ include/block/blockjob.h | 14 ++++++++++++++ 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/blockdev.c b/blockdev.c index 30dc9d2..567d5e3 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2901,21 +2901,18 @@ fail: BlockJobInfoList *qmp_query_block_jobs(Error **errp) { BlockJobInfoList *head = NULL, **p_next = &head; - BlockDriverState *bs; + BlockJob *job; - for (bs = bdrv_next(NULL); bs; bs = bdrv_next(bs)) { - AioContext *aio_context = bdrv_get_aio_context(bs); + for (job = block_job_next(NULL); job; job = block_job_next(job)) { + BlockJobInfoList *elem = g_new0(BlockJobInfoList, 1); + AioContext *aio_context = bdrv_get_aio_context(job->bs); aio_context_acquire(aio_context); - - if (bs->job) { - BlockJobInfoList *elem = g_new0(BlockJobInfoList, 1); - elem->value = block_job_query(bs->job); - *p_next = elem; - p_next = &elem->next; - } - + elem->value = block_job_query(job); aio_context_release(aio_context); + + *p_next = elem; + p_next = &elem->next; } return head; diff --git a/blockjob.c b/blockjob.c index ba2255d..562362b 100644 --- a/blockjob.c +++ b/blockjob.c @@ -35,6 +35,16 @@ #include "qemu/timer.h" #include "qapi-event.h" +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) @@ -73,6 +83,8 @@ void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs, return NULL; } } + + QLIST_INSERT_HEAD(&block_jobs, job, job_list); return job; } @@ -85,6 +97,7 @@ void block_job_completed(BlockJob *job, int ret) bs->job = NULL; bdrv_op_unblock_all(bs, job->blocker); error_free(job->blocker); + QLIST_REMOVE(job, job_list); g_free(job); } diff --git a/include/block/blockjob.h b/include/block/blockjob.h index b6d4ebb..636204b 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -96,6 +96,9 @@ struct BlockJob { */ bool ready; + /** 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; @@ -119,6 +122,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