From nobody Thu Dec 18 17:55:12 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552416097300655.3865456386712; Tue, 12 Mar 2019 11:41:37 -0700 (PDT) Received: from localhost ([127.0.0.1]:57663 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3mLC-0003FP-R2 for importer@patchew.org; Tue, 12 Mar 2019 14:41:30 -0400 Received: from eggs.gnu.org ([209.51.188.92]:56506) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3lEq-0000yR-M9 for qemu-devel@nongnu.org; Tue, 12 Mar 2019 13:30:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h3lEo-00004t-Qr for qemu-devel@nongnu.org; Tue, 12 Mar 2019 13:30:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37806) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h3lEj-0008Pu-UI; Tue, 12 Mar 2019 13:30:46 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EFEA2308848F; Tue, 12 Mar 2019 17:30:44 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-52.ams2.redhat.com [10.36.117.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id DEEAC60BF7; Tue, 12 Mar 2019 17:30:43 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 12 Mar 2019 18:30:06 +0100 Message-Id: <20190312173025.3843-10-kwolf@redhat.com> In-Reply-To: <20190312173025.3843-1-kwolf@redhat.com> References: <20190312173025.3843-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Tue, 12 Mar 2019 17:30:45 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 09/28] file-posix: Fix bdrv_open_flags() for snapshot=on 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: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Using a different read-only setting for bs->open_flags than for the flags to the driver's open function is just inconsistent and a bad idea. After this patch, the temporary snapshot keeps being opened read-only if read-only=3Don,snapshot=3Don is passed. If we wanted to change this behaviour to make only the orginal image file read-only, but the temporary overlay read-write (as the comment in the removed code suggests), that change would have to be made in bdrv_temp_snapshot_options() (where the comment suggests otherwise). Addressing this inconsistency before introducing dynamic auto-read-only is important because otherwise we would immediately try to reopen the temporary overlay even though the file is already unlinked. Signed-off-by: Kevin Wolf --- block.c | 7 ------- tests/qemu-iotests/051 | 7 +++++++ tests/qemu-iotests/051.out | 9 +++++++++ tests/qemu-iotests/051.pc.out | 9 +++++++++ 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/block.c b/block.c index 9b9d25e843..33804cdcaa 100644 --- a/block.c +++ b/block.c @@ -1163,13 +1163,6 @@ static int bdrv_open_flags(BlockDriverState *bs, int= flags) */ open_flags &=3D ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING | BDRV_O_PROTOCO= L); =20 - /* - * Snapshots should be writable. - */ - if (flags & BDRV_O_TEMPORARY) { - open_flags |=3D BDRV_O_RDWR; - } - return open_flags; } =20 diff --git a/tests/qemu-iotests/051 b/tests/qemu-iotests/051 index 3b50c7f188..151b850a8b 100755 --- a/tests/qemu-iotests/051 +++ b/tests/qemu-iotests/051 @@ -356,6 +356,13 @@ $QEMU_IO -c "read -P 0x33 0 4k" "$TEST_IMG" | _filter_= qemu_io # Using snapshot=3Don with a non-existent TMPDIR TMPDIR=3D/nonexistent run_qemu -drive driver=3Dnull-co,snapshot=3Don =20 +# Using snapshot=3Don together with read-only=3Don +echo "info block" | + run_qemu -drive file=3D"$TEST_IMG",snapshot=3Don,read-only=3Don,if=3Dn= one,id=3D$device_id | + _filter_qemu_io | + sed -e 's#"/[^"]*/vl\.[A-Za-z]\{6\}"#SNAPSHOT_PATH#g' + + # success, all done echo "*** done" rm -f $seq.full diff --git a/tests/qemu-iotests/051.out b/tests/qemu-iotests/051.out index b900935fbc..9f1cf22608 100644 --- a/tests/qemu-iotests/051.out +++ b/tests/qemu-iotests/051.out @@ -458,4 +458,13 @@ read 4096/4096 bytes at offset 0 Testing: -drive driver=3Dnull-co,snapshot=3Don QEMU_PROG: -drive driver=3Dnull-co,snapshot=3Don: Could not get temporary = filename: No such file or directory =20 +Testing: -drive file=3DTEST_DIR/t.qcow2,snapshot=3Don,read-only=3Don,if=3D= none,id=3Ddrive0 +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +drive0 (NODE_NAME): json:{"backing": {"driver": "qcow2", "file": {"driver"= : "file", "filename": "TEST_DIR/t.qcow2"}}, "driver": "qcow2", "file": {"dr= iver": "file", "filename": SNAPSHOT_PATH}} (qcow2, read-only) + Removable device: not locked, tray closed + Cache mode: writeback, ignore flushes + Backing file: TEST_DIR/t.qcow2 (chain depth: 1) +(qemu) quit + *** done diff --git a/tests/qemu-iotests/051.pc.out b/tests/qemu-iotests/051.pc.out index 8c5c735dfd..c4743cc31c 100644 --- a/tests/qemu-iotests/051.pc.out +++ b/tests/qemu-iotests/051.pc.out @@ -530,4 +530,13 @@ read 4096/4096 bytes at offset 0 Testing: -drive driver=3Dnull-co,snapshot=3Don QEMU_PROG: -drive driver=3Dnull-co,snapshot=3Don: Could not get temporary = filename: No such file or directory =20 +Testing: -drive file=3DTEST_DIR/t.qcow2,snapshot=3Don,read-only=3Don,if=3D= none,id=3Ddrive0 +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +drive0 (NODE_NAME): json:{"backing": {"driver": "qcow2", "file": {"driver"= : "file", "filename": "TEST_DIR/t.qcow2"}}, "driver": "qcow2", "file": {"dr= iver": "file", "filename": SNAPSHOT_PATH}} (qcow2, read-only) + Removable device: not locked, tray closed + Cache mode: writeback, ignore flushes + Backing file: TEST_DIR/t.qcow2 (chain depth: 1) +(qemu) quit + *** done --=20 2.20.1