From patchwork Fri Jan 20 07:23:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 717513 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3v4Xph0f94z9sdm for ; Fri, 20 Jan 2017 18:46:52 +1100 (AEDT) Received: from localhost ([::1]:52995 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cUTuL-0007nM-Cv for incoming@patchwork.ozlabs.org; Fri, 20 Jan 2017 02:46:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43595) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cUTYs-0006qK-5J for qemu-devel@nongnu.org; Fri, 20 Jan 2017 02:24:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cUTYr-0000WK-8Z for qemu-devel@nongnu.org; Fri, 20 Jan 2017 02:24:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51374) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cUTYp-0000U0-DA; Fri, 20 Jan 2017 02:24:35 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 94EF880F6B; Fri, 20 Jan 2017 07:24:35 +0000 (UTC) Received: from lemon.redhat.com (ovpn-8-18.pek2.redhat.com [10.72.8.18]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v0K7NDQw013112; Fri, 20 Jan 2017 02:24:31 -0500 From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 20 Jan 2017 15:23:09 +0800 Message-Id: <20170120072310.8009-16-famz@redhat.com> In-Reply-To: <20170120072310.8009-1-famz@redhat.com> References: <20170120072310.8009-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 20 Jan 2017 07:24:35 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v11 15/16] qcow2: Force "no other writer" lock on bs->file 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 , qemu-block@nongnu.org, rjones@redhat.com, Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Writing to the same qcow2 file from two QEMU processes at the same time will never work correctly, so disable it even when the caller specifies BDRV_O_RDWR. Other formats are less vulnerable because they don't have internal snapshots thus qemu-img is less often misused to create live snapshot. Signed-off-by: Fam Zheng --- block/qcow2.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/block/qcow2.c b/block/qcow2.c index 96fb8a8..879361a 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1177,6 +1177,17 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags, } } + if ((flags & BDRV_O_SHARE_RW) && (flags & BDRV_O_RDWR)) { + /* Shared write is never a good idea for qcow2, override it. + * XXX: Use permission propagation and masking mechanism in op blockers + * API once it's there. */ + ret = bdrv_reopen(bs->file->bs, flags & ~BDRV_O_SHARE_RW, &local_err); + if (ret) { + error_propagate(errp, local_err); + goto fail; + } + } + #ifdef DEBUG_ALLOC { BdrvCheckResult result = {0};