From nobody Thu May 2 08:29:33 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1564500952; cv=none; d=zoho.com; s=zohoarc; b=BOT3TwLoGwRxeDenREwlCSYrWZga+suQyC2jjliQwHm5v6FJ/i9fUOozx12e2xeoUj6XwbgnC9oKK4S6dI2KYODiRBWxJK2Q9G5pAA6mHXtdM5YoRqE7/X9VhbRa21+U6869ftj1nEm8BMSDDxbbu5U6QBN2fLCILnjnjWsceBc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564500952; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=gECrUoc5zSye+3KEQ84d6B+9vU7LJDQk9QqWslNMB8c=; b=FaohNhzVsYKgs1UVe9YspG/fNGnQ46PxFYoWgPBZPC4sNFF/9D5xqw7jmIP4f56IQxm10+R83wFZWAY0c4AfHxpbQQvQN8YjViDqBa1m8qT/muu8PCpe0oE/0vFrCTrz0+eTlLXsm+2tJhFDt59hT6QWOC0rXnMZJjakQDxwlUY= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1564500952312316.36775333183687; Tue, 30 Jul 2019 08:35:52 -0700 (PDT) Received: from localhost ([::1]:34006 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsUAJ-0001Bo-BO for importer@patchew.org; Tue, 30 Jul 2019 11:35:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45173) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsU8L-0007j3-4M for qemu-devel@nongnu.org; Tue, 30 Jul 2019 11:33:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsU8J-0004ZP-T2 for qemu-devel@nongnu.org; Tue, 30 Jul 2019 11:33:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57234) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hsU8H-0004X3-PD; Tue, 30 Jul 2019 11:33:45 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0AC86308AA11; Tue, 30 Jul 2019 15:33:45 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-75.ams2.redhat.com [10.36.117.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id F0791608C1; Tue, 30 Jul 2019 15:33:43 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 30 Jul 2019 17:33:30 +0200 Message-Id: <20190730153331.24515-2-kwolf@redhat.com> In-Reply-To: <20190730153331.24515-1-kwolf@redhat.com> References: <20190730153331.24515-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 30 Jul 2019 15:33: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 1/2] fdc: Fix inserting read-only media in empty drive X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" In order to insert a read-only medium (i.e. a read-only block node) to the BlockBackend of a floppy drive, we must not have taken write permissions on that BlockBackend, or the operation will fail with the error message "Block node is read-only". The device already takes care to remove all permissions when the medium is ejected, but the state isn't correct if the drive is initially empty: It uses blk_is_read_only() to check whether write permissions should be taken, but this function returns false for empty BlockBackends in the common case. Fix floppy_drive_realize() to avoid taking write permissions if the drive is empty. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz Reviewed-by: John Snow --- hw/block/fdc.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/hw/block/fdc.c b/hw/block/fdc.c index 77af9979de..9b24cb9b85 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -514,6 +514,7 @@ static void floppy_drive_realize(DeviceState *qdev, Err= or **errp) FloppyDrive *dev =3D FLOPPY_DRIVE(qdev); FloppyBus *bus =3D FLOPPY_BUS(qdev->parent_bus); FDrive *drive; + bool read_only; int ret; =20 if (dev->unit =3D=3D -1) { @@ -542,6 +543,12 @@ static void floppy_drive_realize(DeviceState *qdev, Er= ror **errp) dev->conf.blk =3D blk_new(qemu_get_aio_context(), 0, BLK_PERM_ALL); ret =3D blk_attach_dev(dev->conf.blk, qdev); assert(ret =3D=3D 0); + + /* Don't take write permissions on an empty drive to allow attachi= ng a + * read-only node later */ + read_only =3D true; + } else { + read_only =3D !blk_bs(dev->conf.blk) || blk_is_read_only(dev->conf= .blk); } =20 blkconf_blocksizes(&dev->conf); @@ -559,9 +566,7 @@ static void floppy_drive_realize(DeviceState *qdev, Err= or **errp) dev->conf.rerror =3D BLOCKDEV_ON_ERROR_AUTO; dev->conf.werror =3D BLOCKDEV_ON_ERROR_AUTO; =20 - if (!blkconf_apply_backend_options(&dev->conf, - blk_is_read_only(dev->conf.blk), - false, errp)) { + if (!blkconf_apply_backend_options(&dev->conf, read_only, false, errp)= ) { return; } =20 --=20 2.20.1 From nobody Thu May 2 08:29:33 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1564500966; cv=none; d=zoho.com; s=zohoarc; b=av9FCFu7YSJ3yMG9rUjY9PKSm+VxlysylXpPsefoxdnQ4bS4UnMXFQAyr6IByjBbrb4IGnXUpvTXmbQJGp9yyaN4uDgX2gd0folefYFATRcuR/kzz7qq4ULdY1V+3LrlzuZgpSrg99XtoFI2D0kQvQHO38isTUKNd0Q9MYH7M78= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564500966; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=4g0EDjgACiiKbzg8CEON/ZFYR4WpBw5/mTxVHJTIrK0=; b=mbarpI8GCuhRJ80A2ru4uhDkBY9imxeDUFws+nWL7avSTSOQQFqgA3+SlaFjWPfXdyR7Mg3T+87tdq0MrOuquf3+s0zSx6cTzihxMnGOOA4oeYGdjmbGvM+mSGMNd66CUd1/WlNU02AImOwWR0gj0G2YpbmBi+CdCEVvLMtvVE8= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1564500966124550.6744826210676; Tue, 30 Jul 2019 08:36:06 -0700 (PDT) Received: from localhost ([::1]:34008 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsUAX-0001pH-5k for importer@patchew.org; Tue, 30 Jul 2019 11:36:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45188) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsU8M-0007kx-68 for qemu-devel@nongnu.org; Tue, 30 Jul 2019 11:33:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsU8L-0004au-7V for qemu-devel@nongnu.org; Tue, 30 Jul 2019 11:33:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57438) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hsU8J-0004YA-28; Tue, 30 Jul 2019 11:33:47 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 653FAC007359; Tue, 30 Jul 2019 15:33:46 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-75.ams2.redhat.com [10.36.117.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 580C7608C1; Tue, 30 Jul 2019 15:33:45 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 30 Jul 2019 17:33:31 +0200 Message-Id: <20190730153331.24515-3-kwolf@redhat.com> In-Reply-To: <20190730153331.24515-1-kwolf@redhat.com> References: <20190730153331.24515-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 30 Jul 2019 15:33:46 +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 2/2] iotests/118: Test inserting a read-only medium X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz Reviewed-by: John Snow --- tests/qemu-iotests/118 | 6 +++++- tests/qemu-iotests/118.out | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/qemu-iotests/118 b/tests/qemu-iotests/118 index 603e10e8a2..499c5f0901 100755 --- a/tests/qemu-iotests/118 +++ b/tests/qemu-iotests/118 @@ -207,10 +207,11 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass): self.assert_qmp(result, 'return[0]/tray_open', False) self.assert_qmp(result, 'return[0]/inserted/image/filename', new_i= mg) =20 - def test_cycle(self): + def test_cycle(self, read_only_node=3DFalse): result =3D self.vm.qmp('blockdev-add', node_name=3D'new', driver=3Diotests.imgfmt, + read_only=3Dread_only_node, file=3D{'filename': new_img, 'driver': 'file'}) self.assert_qmp(result, 'return', {}) @@ -257,6 +258,9 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass): self.assert_qmp(result, 'return[0]/tray_open', False) self.assert_qmp(result, 'return[0]/inserted/image/filename', new_i= mg) =20 + def test_cycle_read_only_media(self): + self.test_cycle(True) + def test_close_on_closed(self): result =3D self.vm.qmp('blockdev-close-tray', id=3Dself.device_nam= e) # Should be a no-op diff --git a/tests/qemu-iotests/118.out b/tests/qemu-iotests/118.out index 6a917130b6..4823c113d5 100644 --- a/tests/qemu-iotests/118.out +++ b/tests/qemu-iotests/118.out @@ -1,5 +1,5 @@ -........................................................... +............................................................... ---------------------------------------------------------------------- -Ran 59 tests +Ran 63 tests =20 OK --=20 2.20.1