From patchwork Thu Mar 28 16:25:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 1068416 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=igalia.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.b="RjJ4w67N"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44VVcs6SZjz9sSV for ; Fri, 29 Mar 2019 03:26:52 +1100 (AEDT) Received: from localhost ([127.0.0.1]:39040 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9Xrb-0001bs-Ug for incoming@patchwork.ozlabs.org; Thu, 28 Mar 2019 12:26:47 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50191) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9Xqk-0001bY-Dr for qemu-devel@nongnu.org; Thu, 28 Mar 2019 12:25:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9Xqi-0004NR-Mr for qemu-devel@nongnu.org; Thu, 28 Mar 2019 12:25:54 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:33981) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h9Xqh-0004Mt-Oe; Thu, 28 Mar 2019 12:25:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=nkWk4JE2tlYtImsap3v9W3cWOko+4zNJcUdfmlS1j68=; b=RjJ4w67NDtm4/zKyyVAgJmirsVzk5xgdbQuEksYtRmFLLVQHm6ylaLdQ3uwYaBTqwKJiYkbDazJ6/eHHw795qz6KpbyrTIG5v4Ev2GMN1MeicQ8SsQyOr9IMa6HS7Sz2t0/qtg/REkUZkcLwJb3I3azwre37/C0XyZ+KG4Ma1BeZJHvwP/uq4xoujaJSdIcvlXCy8Ty86Dj2e4OrrrcJaa8Og0lCrxFp7Y+IdlSypI91wKT4cKaCpUcGHiMykbi9wVp7MoiD4sueTq2d14l9RT8qAtA//asVzyuMWxgdRxJbnN75bhCTn/6BZOFNCMEGvP9nlSUwC4Y3unw9W1VwWg==; Received: from 87-100-202-60.bb.dnainternet.fi ([87.100.202.60] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1h9Xqf-0007VK-QY; Thu, 28 Mar 2019 17:25:49 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1h9XqR-0003Y0-Bk; Thu, 28 Mar 2019 18:25:35 +0200 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 28 Mar 2019 18:25:10 +0200 Message-Id: <9ddb290573f04bdcf98985e569001efb5d19a9de.1553789986.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH for-4.0 v2 2/3] block: freeze the backing chain earlier in stream_start() 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 , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Andrey Shinkevich Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Commit 6585493369819a48d34a86d57ec6b97cb5cd9bc0 added code to freeze the backing chain from 'top' to 'base' for the duration of the block-stream job. The problem is that the freezing happens too late in stream_start(): during the bdrv_reopen_set_read_only() call earlier in that function another job can jump in and remove the base image. If that happens we have an invalid chain and QEMU crashes. This patch puts the bdrv_freeze_backing_chain() call at the beginning of the function. Signed-off-by: Alberto Garcia Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/stream.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/block/stream.c b/block/stream.c index 6253c86fae..bfaebb861a 100644 --- a/block/stream.c +++ b/block/stream.c @@ -238,11 +238,16 @@ void stream_start(const char *job_id, BlockDriverState *bs, BlockDriverState *iter; bool bs_read_only; + if (bdrv_freeze_backing_chain(bs, base, errp) < 0) { + return; + } + /* Make sure that the image is opened in read-write mode */ bs_read_only = bdrv_is_read_only(bs); if (bs_read_only) { if (bdrv_reopen_set_read_only(bs, false, errp) != 0) { - return; + bs_read_only = false; + goto fail; } } @@ -269,11 +274,6 @@ void stream_start(const char *job_id, BlockDriverState *bs, &error_abort); } - if (bdrv_freeze_backing_chain(bs, base, errp) < 0) { - job_early_fail(&s->common.job); - goto fail; - } - s->base = base; s->backing_file_str = g_strdup(backing_file_str); s->bs_read_only = bs_read_only; @@ -288,4 +288,5 @@ fail: if (bs_read_only) { bdrv_reopen_set_read_only(bs, true, NULL); } + bdrv_unfreeze_backing_chain(bs, base); }