* [Qemu-devel] [PATCH for-4.1 0/2] fdc: Fix inserting read-only media in empty drive @ 2019-07-30 14:57 Kevin Wolf 2019-07-30 14:57 ` [Qemu-devel] [PATCH for-4.1 1/2] " Kevin Wolf 2019-07-30 14:57 ` [Qemu-devel] [PATCH for-4.1 2/2] iotests/118: Test inserting a read-only medium Kevin Wolf 0 siblings, 2 replies; 7+ messages in thread From: Kevin Wolf @ 2019-07-30 14:57 UTC (permalink / raw) To: qemu-block; +Cc: kwolf, philmd, qemu-devel, armbru, mreitz, jsnow Kevin Wolf (2): fdc: Fix inserting read-only media in empty drive iotests/118: Test inserting a read-only medium hw/block/fdc.c | 11 ++++++++--- tests/qemu-iotests/118 | 6 +++++- tests/qemu-iotests/118.out | 4 ++-- 3 files changed, 15 insertions(+), 6 deletions(-) -- 2.20.1 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Qemu-devel] [PATCH for-4.1 1/2] fdc: Fix inserting read-only media in empty drive 2019-07-30 14:57 [Qemu-devel] [PATCH for-4.1 0/2] fdc: Fix inserting read-only media in empty drive Kevin Wolf @ 2019-07-30 14:57 ` Kevin Wolf 2019-07-30 15:17 ` Max Reitz 2019-07-30 15:24 ` John Snow 2019-07-30 14:57 ` [Qemu-devel] [PATCH for-4.1 2/2] iotests/118: Test inserting a read-only medium Kevin Wolf 1 sibling, 2 replies; 7+ messages in thread From: Kevin Wolf @ 2019-07-30 14:57 UTC (permalink / raw) To: qemu-block; +Cc: kwolf, philmd, qemu-devel, armbru, mreitz, jsnow 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 <kwolf@redhat.com> --- 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; } -- 2.20.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH for-4.1 1/2] fdc: Fix inserting read-only media in empty drive 2019-07-30 14:57 ` [Qemu-devel] [PATCH for-4.1 1/2] " Kevin Wolf @ 2019-07-30 15:17 ` Max Reitz 2019-07-30 15:24 ` John Snow 1 sibling, 0 replies; 7+ messages in thread From: Max Reitz @ 2019-07-30 15:17 UTC (permalink / raw) To: Kevin Wolf, qemu-block; +Cc: jsnow, philmd, armbru, qemu-devel [-- Attachment #1.1: Type: text/plain, Size: 1056 bytes --] On 30.07.19 16:57, Kevin Wolf wrote: > 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. ...and once the drive is loaded with anything, fd_change_cb() calls blkconf_apply_backend_option() again with the updated RO state. Looks correct. > Signed-off-by: Kevin Wolf <kwolf@redhat.com> > --- > hw/block/fdc.c | 11 ++++++++--- > 1 file changed, 8 insertions(+), 3 deletions(-) Reviewed-by: Max Reitz <mreitz@redhat.com> [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH for-4.1 1/2] fdc: Fix inserting read-only media in empty drive 2019-07-30 14:57 ` [Qemu-devel] [PATCH for-4.1 1/2] " Kevin Wolf 2019-07-30 15:17 ` Max Reitz @ 2019-07-30 15:24 ` John Snow 1 sibling, 0 replies; 7+ messages in thread From: John Snow @ 2019-07-30 15:24 UTC (permalink / raw) To: Kevin Wolf, qemu-block; +Cc: mreitz, philmd, qemu-devel, armbru On 7/30/19 10:57 AM, Kevin Wolf wrote: > 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 <kwolf@redhat.com> > --- > 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; > } > > Smells correct. Reviewed-by: John Snow <jsnow@redhat.com> ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Qemu-devel] [PATCH for-4.1 2/2] iotests/118: Test inserting a read-only medium 2019-07-30 14:57 [Qemu-devel] [PATCH for-4.1 0/2] fdc: Fix inserting read-only media in empty drive Kevin Wolf 2019-07-30 14:57 ` [Qemu-devel] [PATCH for-4.1 1/2] " Kevin Wolf @ 2019-07-30 14:57 ` Kevin Wolf 2019-07-30 15:24 ` Max Reitz 2019-07-30 15:25 ` John Snow 1 sibling, 2 replies; 7+ messages in thread From: Kevin Wolf @ 2019-07-30 14:57 UTC (permalink / raw) To: qemu-block; +Cc: kwolf, philmd, qemu-devel, armbru, mreitz, jsnow Signed-off-by: Kevin Wolf <kwolf@redhat.com> --- 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 -- 2.20.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH for-4.1 2/2] iotests/118: Test inserting a read-only medium 2019-07-30 14:57 ` [Qemu-devel] [PATCH for-4.1 2/2] iotests/118: Test inserting a read-only medium Kevin Wolf @ 2019-07-30 15:24 ` Max Reitz 2019-07-30 15:25 ` John Snow 1 sibling, 0 replies; 7+ messages in thread From: Max Reitz @ 2019-07-30 15:24 UTC (permalink / raw) To: Kevin Wolf, qemu-block; +Cc: jsnow, philmd, armbru, qemu-devel [-- Attachment #1.1: Type: text/plain, Size: 573 bytes --] On 30.07.19 16:57, Kevin Wolf wrote: > Signed-off-by: Kevin Wolf <kwolf@redhat.com> > --- > tests/qemu-iotests/118 | 6 +++++- > tests/qemu-iotests/118.out | 4 ++-- > 2 files changed, 7 insertions(+), 3 deletions(-) Personally, I wouldn’t mind a self.assert_qmp(result, 'return[0]/inserted/ro', read_only_node) at the end of test_cycle(), but oh well: Reviewed-by: Max Reitz <mreitz@redhat.com> (We’d also want it in other places, e.g. test_tray_open_change() should check that it’s always False for floppy disks, and True for CDs.) [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH for-4.1 2/2] iotests/118: Test inserting a read-only medium 2019-07-30 14:57 ` [Qemu-devel] [PATCH for-4.1 2/2] iotests/118: Test inserting a read-only medium Kevin Wolf 2019-07-30 15:24 ` Max Reitz @ 2019-07-30 15:25 ` John Snow 1 sibling, 0 replies; 7+ messages in thread From: John Snow @ 2019-07-30 15:25 UTC (permalink / raw) To: Kevin Wolf, qemu-block; +Cc: qemu-devel, philmd, armbru, mreitz On 7/30/19 10:57 AM, Kevin Wolf wrote: > Signed-off-by: Kevin Wolf <kwolf@redhat.com> > --- > 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 > Reviewed-by: John Snow <jsnow@redhat.com> ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-07-30 15:27 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2019-07-30 14:57 [Qemu-devel] [PATCH for-4.1 0/2] fdc: Fix inserting read-only media in empty drive Kevin Wolf 2019-07-30 14:57 ` [Qemu-devel] [PATCH for-4.1 1/2] " Kevin Wolf 2019-07-30 15:17 ` Max Reitz 2019-07-30 15:24 ` John Snow 2019-07-30 14:57 ` [Qemu-devel] [PATCH for-4.1 2/2] iotests/118: Test inserting a read-only medium Kevin Wolf 2019-07-30 15:24 ` Max Reitz 2019-07-30 15:25 ` John Snow
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).