From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49259) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Whz55-0002bY-Ox for qemu-devel@nongnu.org; Wed, 07 May 2014 06:28:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Whz4v-0005eO-Ea for qemu-devel@nongnu.org; Wed, 07 May 2014 06:28:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:29578) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Whz4v-0005e6-6U for qemu-devel@nongnu.org; Wed, 07 May 2014 06:27:57 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s47ARuoh030472 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 7 May 2014 06:27:56 -0400 From: Stefan Hajnoczi Date: Wed, 7 May 2014 12:27:19 +0200 Message-Id: <1399458461-3997-4-git-send-email-stefanha@redhat.com> In-Reply-To: <1399458461-3997-1-git-send-email-stefanha@redhat.com> References: <1399458461-3997-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PATCH v2 03/25] block: acquire AioContext in bdrv_drain_all() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Stefan Hajnoczi Modify bdrv_drain_all() to take into account that BlockDriverState instances may be running in different AioContexts. This patch changes the implementation of bdrv_drain_all() while preserving the semantics. Previously kicking throttled requests and checking for pending requests were done across all BlockDriverState instances in sequence. Now we process each BlockDriverState in turn, making sure to acquire and release its AioContext. This prevents race conditions between the thread executing bdrv_drain_all() and the thread running the AioContext. Signed-off-by: Stefan Hajnoczi --- block.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/block.c b/block.c index 2a72409..8cb84b3 100644 --- a/block.c +++ b/block.c @@ -1806,17 +1806,6 @@ static bool bdrv_requests_pending(BlockDriverState *bs) return false; } -static bool bdrv_requests_pending_all(void) -{ - BlockDriverState *bs; - QTAILQ_FOREACH(bs, &bdrv_states, device_list) { - if (bdrv_requests_pending(bs)) { - return true; - } - } - return false; -} - /* * Wait for pending requests to complete across all BlockDriverStates * @@ -1836,12 +1825,20 @@ void bdrv_drain_all(void) BlockDriverState *bs; while (busy) { + busy = false; + QTAILQ_FOREACH(bs, &bdrv_states, device_list) { + AioContext *aio_context = bdrv_get_aio_context(bs); + bool bs_busy; + + aio_context_acquire(aio_context); bdrv_start_throttled_reqs(bs); - } + bs_busy = bdrv_requests_pending(bs); + bs_busy |= aio_poll(aio_context, bs_busy); + aio_context_release(aio_context); - busy = bdrv_requests_pending_all(); - busy |= aio_poll(qemu_get_aio_context(), busy); + busy |= bs_busy; + } } } -- 1.9.0