From patchwork Fri Oct 14 13:08:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 9376817 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 70AC16022E for ; Fri, 14 Oct 2016 13:16:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62BE82A691 for ; Fri, 14 Oct 2016 13:16:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5787A2A698; Fri, 14 Oct 2016 13:16:30 +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 C18BC2A691 for ; Fri, 14 Oct 2016 13:16:29 +0000 (UTC) Received: from localhost ([::1]:47246 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bv2Lc-0003Uu-Rg for patchwork-qemu-devel@patchwork.kernel.org; Fri, 14 Oct 2016 09:16:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49149) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bv2FO-0006gj-1b 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-0007CY-58 for qemu-devel@nongnu.org; Fri, 14 Oct 2016 09:10:01 -0400 Received: from smtp3.mundo-r.com ([212.51.32.191]:33004 helo=smtp4.mundo-r.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bv2FK-00073X-TT; Fri, 14 Oct 2016 09:09:59 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2BIAgCE2ABY/5tjdVtcg2wBAQEBAR2BU6MSAQEBAQEBBQGBFwGPe4Ixgg+CCIYiAoIOOBQBAgEBAQEBAQFeJ4RiAgQnUhA/EjwbGYhWAcMFAQEIKIVyglCGZ3yFEwWPM4pTkACJaYYMSZAvHjZEBgiEbG+GBoIvAQEB X-IPAS-Result: A2BIAgCE2ABY/5tjdVtcg2wBAQEBAR2BU6MSAQEBAQEBBQGBFwGPe4Ixgg+CCIYiAoIOOBQBAgEBAQEBAQFeJ4RiAgQnUhA/EjwbGYhWAcMFAQEIKIVyglCGZ3yFEwWPM4pTkACJaYYMSZAvHjZEBgiEbG+GBoIvAQEB X-IronPort-AV: E=Sophos;i="5.31,493,1473112800"; d="scan'208";a="118727409" 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-0004Qr-1S; Fri, 14 Oct 2016 15:08:58 +0200 Received: from berto by perseus.local with local (Exim 4.87) (envelope-from ) id 1bv2E1-0006kF-Q1; Fri, 14 Oct 2016 16:08:37 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 14 Oct 2016 16:08:14 +0300 Message-Id: <48f12427ab83c20fd27aa451e5a941201581742c.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 02/19] block: Pause all jobs during bdrv_reopen_multiple() 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 When a BlockDriverState is about to be reopened it can trigger certain operations that need to write to disk. During this process a different block job can be woken up. If that block job completes and also needs to call bdrv_reopen() it can happen that it needs to do it on the same BlockDriverState that is still in the process of being reopened. This can have fatal consequences, like in this example: 1) Block job A starts and sleeps after a while. 2) Block job B starts and tries to reopen node1 (a qcow2 file). 3) Reopening node1 means flushing and replacing its qcow2 cache. 4) While the qcow2 cache is being flushed, job A wakes up. 5) Job A completes and reopens node1, replacing its cache. 6) Job B resumes, but the cache that was being flushed no longer exists. This patch splits the bdrv_drain_all() call to keep all block jobs paused during bdrv_reopen_multiple(), so that step 4 can never happen and the operation is safe. Note that this scenario can only happen if both bdrv_reopen() calls are made by block jobs on the same backing chain. Otherwise there's no chance that the same BlockDriverState appears in both reopen queues. Signed-off-by: Alberto Garcia Reviewed-by: Paolo Bonzini --- block.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index 7f3e7bc..adbecd0 100644 --- a/block.c +++ b/block.c @@ -2090,7 +2090,7 @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp) assert(bs_queue != NULL); - bdrv_drain_all(); + bdrv_drain_all_begin(); QSIMPLEQ_FOREACH(bs_entry, bs_queue, entry) { if (bdrv_reopen_prepare(&bs_entry->state, bs_queue, &local_err)) { @@ -2120,6 +2120,9 @@ cleanup: g_free(bs_entry); } g_free(bs_queue); + + bdrv_drain_all_end(); + return ret; }