From patchwork Fri Oct 14 13:08:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 9376791 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 A5FFC6022E for ; Fri, 14 Oct 2016 13:10:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9782F28F49 for ; Fri, 14 Oct 2016 13:10:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B92C2A58A; Fri, 14 Oct 2016 13:10:45 +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.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 1D6C328F49 for ; Fri, 14 Oct 2016 13:10:40 +0000 (UTC) Received: from localhost ([::1]:47211 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bv2Fz-0006jZ-3U for patchwork-qemu-devel@patchwork.kernel.org; Fri, 14 Oct 2016 09:10:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49150) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bv2FO-0006gk-1Z for qemu-devel@nongnu.org; Fri, 14 Oct 2016 09:10:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bv2FL-0007Ce-8E for qemu-devel@nongnu.org; Fri, 14 Oct 2016 09:10:01 -0400 Received: from smtp3.mundo-r.com ([212.51.32.191]:62335 helo=smtp4.mundo-r.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bv2FK-000746-R2; Fri, 14 Oct 2016 09:09:59 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2AsAgCE2ABY/5tjdVtcHAEFAQsBgz0BAQEBAR2BU400lV4BAQEBAQEFAYEXAZIsgg+CCIYiAoIOOBQBAgEBAQEBAQFeJ4RiAgQnUhA/EjwbGYhWAcMFAQEIKIVyglCHY4UTBY8zilOQAIlphgxJkC8eNkQGCIJ6HIFWb4g1AQEB X-IPAS-Result: A2AsAgCE2ABY/5tjdVtcHAEFAQsBgz0BAQEBAR2BU400lV4BAQEBAQEFAYEXAZIsgg+CCIYiAoIOOBQBAgEBAQEBAQFeJ4RiAgQnUhA/EjwbGYhWAcMFAQEIKIVyglCHY4UTBY8zilOQAIlphgxJkC8eNkQGCIJ6HIFWb4g1AQEB X-IronPort-AV: E=Sophos;i="5.31,493,1473112800"; d="scan'208";a="118727406" Received: from fanzine.igalia.com ([91.117.99.155]) by smtp4.mundo-r.com with ESMTP; 14 Oct 2016 15:08:59 +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 1bv2EM-0004Qs-1T; Fri, 14 Oct 2016 15:08:58 +0200 Received: from berto by perseus.local with local (Exim 4.87) (envelope-from ) id 1bv2E1-0006kD-P2; Fri, 14 Oct 2016 16:08:37 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 14 Oct 2016 16:08:13 +0300 Message-Id: <99a0ff7379a345ed60a6092866c9a42f667b37b5.1476450059.git.berto@igalia.com> X-Mailer: git-send-email 2.9.3 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 v11 01/19] block: Add bdrv_drain_all_{begin, end}() 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, Markus Armbruster , Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP bdrv_drain_all() doesn't allow the caller to do anything after all pending requests have been completed but before block jobs are resumed. This patch splits bdrv_drain_all() into _begin() and _end() for that purpose. It also adds aio_{disable,enable}_external() calls to disable external clients in the meantime. Signed-off-by: Alberto Garcia Reviewed-by: Paolo Bonzini --- block/io.c | 24 +++++++++++++++++++++--- include/block/block.h | 2 ++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/block/io.c b/block/io.c index b136c89..9418f8b 100644 --- a/block/io.c +++ b/block/io.c @@ -275,8 +275,11 @@ void bdrv_drain(BlockDriverState *bs) * * This function does not flush data to disk, use bdrv_flush_all() for that * after calling this function. + * + * This pauses all block jobs and disables external clients. It must + * be paired with bdrv_drain_all_end(). */ -void bdrv_drain_all(void) +void bdrv_drain_all_begin(void) { /* Always run first iteration so any pending completion BHs run */ bool busy = true; @@ -300,6 +303,7 @@ void bdrv_drain_all(void) bdrv_parent_drained_begin(bs); bdrv_io_unplugged_begin(bs); bdrv_drain_recurse(bs); + aio_disable_external(aio_context); aio_context_release(aio_context); if (!g_slist_find(aio_ctxs, aio_context)) { @@ -333,17 +337,25 @@ void bdrv_drain_all(void) } } + g_slist_free(aio_ctxs); +} + +void bdrv_drain_all_end(void) +{ + BlockDriverState *bs; + BdrvNextIterator it; + BlockJob *job = NULL; + for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) { AioContext *aio_context = bdrv_get_aio_context(bs); aio_context_acquire(aio_context); + aio_enable_external(aio_context); bdrv_io_unplugged_end(bs); bdrv_parent_drained_end(bs); aio_context_release(aio_context); } - g_slist_free(aio_ctxs); - job = NULL; while ((job = block_job_next(job))) { AioContext *aio_context = blk_get_aio_context(job->blk); @@ -353,6 +365,12 @@ void bdrv_drain_all(void) } } +void bdrv_drain_all(void) +{ + bdrv_drain_all_begin(); + bdrv_drain_all_end(); +} + /** * Remove an active request from the tracked requests list * diff --git a/include/block/block.h b/include/block/block.h index 107c603..301d713 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -338,6 +338,8 @@ int bdrv_flush_all(void); void bdrv_close_all(void); void bdrv_drain(BlockDriverState *bs); void coroutine_fn bdrv_co_drain(BlockDriverState *bs); +void bdrv_drain_all_begin(void); +void bdrv_drain_all_end(void); void bdrv_drain_all(void); int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int count);