From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43820) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bvJOL-0002CX-3u for qemu-devel@nongnu.org; Sat, 15 Oct 2016 03:28:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bvJOI-0006S4-VR for qemu-devel@nongnu.org; Sat, 15 Oct 2016 03:28:23 -0400 Sender: Paolo Bonzini References: <48f12427ab83c20fd27aa451e5a941201581742c.1476450059.git.berto@igalia.com> From: Paolo Bonzini Message-ID: <67846f43-6d6f-56b7-8ccf-eb211ab00492@redhat.com> Date: Sat, 15 Oct 2016 09:28:12 +0200 MIME-Version: 1.0 In-Reply-To: <48f12427ab83c20fd27aa451e5a941201581742c.1476450059.git.berto@igalia.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v11 02/19] block: Pause all jobs during bdrv_reopen_multiple() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alberto Garcia , qemu-devel@nongnu.org Cc: Kevin Wolf , qemu-block@nongnu.org, Markus Armbruster , Max Reitz On 14/10/2016 15:08, Alberto Garcia wrote: > 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 > --- > 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; > } > > Reviewed-by: Paolo Bonzini