From patchwork Mon Apr 4 13:43:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 605876 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ozlabs.org (Postfix) with ESMTPS id 3qdtZS1TJPz9s9Y for ; Mon, 4 Apr 2016 23:46:56 +1000 (AEST) Received: from localhost ([::1]:58741 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1an4qE-0004zG-D1 for incoming@patchwork.ozlabs.org; Mon, 04 Apr 2016 09:46:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58298) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1an4og-0001zG-Uu for qemu-devel@nongnu.org; Mon, 04 Apr 2016 09:45:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1an4oe-0000AG-Af 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 1an4oe-0008Qw-4b; Mon, 04 Apr 2016 09:45:16 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2CSAwCybgJX/5tjdVtdHYMagVCnFQEBAQEBBQGBEQGQZoIPAQ2BcoYNAoEzOBQBAQEBAQEBZSeEQgEBBCdSED8SPBsZiCsBvQcBAQgghViCRYdYhQoFh2+GTolEjgiJOoVVRI5WHgEBQoIEGYFNaYZpBIE5AQEB X-IPAS-Result: A2CSAwCybgJX/5tjdVtdHYMagVCnFQEBAQEBBQGBEQGQZoIPAQ2BcoYNAoEzOBQBAQEBAQEBZSeEQgEBBCdSED8SPBsZiCsBvQcBAQgghViCRYdYhQoFh2+GTolEjgiJOoVVRI5WHgEBQoIEGYFNaYZpBIE5AQEB X-IronPort-AV: E=Sophos;i="5.24,440,1454972400"; d="scan'208";a="39334338" 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 1an4o1-00050y-0U; Mon, 04 Apr 2016 15:44:37 +0200 Received: from berto by perseus.local with local (Exim 4.87) (envelope-from ) id 1an4nj-0003vM-1P; Mon, 04 Apr 2016 16:44:19 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Mon, 4 Apr 2016 16:43:54 +0300 Message-Id: <41bbdd98675b93ff0d4b4e745d942cfd5c16aa1f.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 04/11] block: use the block job list in bdrv_close() 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 bdrv_close_all() cancels all block jobs by iterating over all BlockDriverStates. This patch simplifies the code by iterating directly over the block jobs using block_job_next(). Signed-off-by: Alberto Garcia --- block.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/block.c b/block.c index d36eb75..48638c9 100644 --- a/block.c +++ b/block.c @@ -2182,8 +2182,7 @@ static void bdrv_close(BlockDriverState *bs) void bdrv_close_all(void) { - BlockDriverState *bs; - AioContext *aio_context; + BlockJob *job; /* Drop references from requests still in flight, such as canceled block * jobs whose AIO context has not been polled yet */ @@ -2193,23 +2192,11 @@ void bdrv_close_all(void) blockdev_close_all_bdrv_states(); /* Cancel all block jobs */ - while (!QTAILQ_EMPTY(&all_bdrv_states)) { - QTAILQ_FOREACH(bs, &all_bdrv_states, bs_list) { - aio_context = bdrv_get_aio_context(bs); - - aio_context_acquire(aio_context); - if (bs->job) { - block_job_cancel_sync(bs->job); - aio_context_release(aio_context); - break; - } - aio_context_release(aio_context); - } - - /* All the remaining BlockDriverStates are referenced directly or - * indirectly from block jobs, so there needs to be at least one BDS - * directly used by a block job */ - assert(bs); + while ((job = block_job_next(NULL))) { + AioContext *aio_context = bdrv_get_aio_context(job->bs); + aio_context_acquire(aio_context); + block_job_cancel_sync(job); + aio_context_release(aio_context); } }