From patchwork Tue Jul 30 15:33:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11066009 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7E934112C for ; Tue, 30 Jul 2019 15:35:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 66C4728396 for ; Tue, 30 Jul 2019 15:35:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B35F28451; Tue, 30 Jul 2019 15:35:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0381628429 for ; Tue, 30 Jul 2019 15:35:38 +0000 (UTC) Received: from localhost ([::1]:34006 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsUA6-0001Bo-9e for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Jul 2019 11:35:38 -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) 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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, Error **errp) FloppyDrive *dev = FLOPPY_DRIVE(qdev); FloppyBus *bus = FLOPPY_BUS(qdev->parent_bus); FDrive *drive; + bool read_only; int ret; if (dev->unit == -1) { @@ -542,6 +543,12 @@ static void floppy_drive_realize(DeviceState *qdev, Error **errp) dev->conf.blk = blk_new(qemu_get_aio_context(), 0, BLK_PERM_ALL); ret = blk_attach_dev(dev->conf.blk, qdev); assert(ret == 0); + + /* Don't take write permissions on an empty drive to allow attaching a + * read-only node later */ + read_only = true; + } else { + read_only = !blk_bs(dev->conf.blk) || blk_is_read_only(dev->conf.blk); } blkconf_blocksizes(&dev->conf); @@ -559,9 +566,7 @@ static void floppy_drive_realize(DeviceState *qdev, Error **errp) dev->conf.rerror = BLOCKDEV_ON_ERROR_AUTO; dev->conf.werror = BLOCKDEV_ON_ERROR_AUTO; - 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; } From patchwork Tue Jul 30 15:33:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11066011 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2399A13AC for ; Tue, 30 Jul 2019 15:35:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 12AA928396 for ; Tue, 30 Jul 2019 15:35:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 066B627CEA; Tue, 30 Jul 2019 15:35:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AB26E26CFF for ; Tue, 30 Jul 2019 15:35:51 +0000 (UTC) Received: from localhost ([::1]:34008 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsUAJ-0001pH-2R for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Jul 2019 11:35:51 -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) 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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_img) - def test_cycle(self): + def test_cycle(self, read_only_node=False): result = self.vm.qmp('blockdev-add', node_name='new', driver=iotests.imgfmt, + read_only=read_only_node, file={'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_img) + def test_cycle_read_only_media(self): + self.test_cycle(True) + def test_close_on_closed(self): result = self.vm.qmp('blockdev-close-tray', id=self.device_name) # 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 OK