Skip to contentSkip to conversation

block: Fix eject -f for locked devices

RFC PATCH In review Markus Armbruster 3 participants 4 messages Feb 18, 2011 – Apr 15, 2011

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 block: Fix eject -f for locked devices

Quoted 1 line

From 8cd4978c9be6ff2bcc414bb1c1b258b96b9a74c1 Mon Sep 17 00:00:00 2001

From: Markus Armbruster <[email protected]>
Date: Fri, 18 Feb 2011 15:54:02 +0100

After forcefully ejecting media locked by the guest, you can't ever again insert new media.

Example:

(qemu) info block
hda: type=hd removable=0 file=test.img ro=0 drv=raw encrypted=0
cd: type=cdrom removable=1 locked=1 file=x.iso ro=0 drv=raw encrypted=0 (qemu) eject cd
Device 'cd' is locked
(qemu) eject -f cd
(qemu) info block
hda: type=hd removable=0 file=test.img ro=0 drv=raw encrypted=0
cd: type=cdrom removable=1 locked=1 [not inserted]
(qemu) change cd x.iso
Device 'cd' is locked

---
I'm not entirely sure this is the appropriate fix, and that's why there's RFC in the subject.

Both IDE and SCSI devices expose their drive's BlockDriverState member locked to the guest via mode sense.

What does real hardware do when I force-eject media (typically by rummaging in that little hole with a paperclip)? Does it actively notify the OS? Does mode sense change?

A possible alternative fix is to make do_change_block() ignore bdrv_is_locked() when inserting media into an empty drive.

 block.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
block.c +1 -0
index b476479..295cf7b 100644
@@ -682,6 +682,7 @@ void bdrv_close(BlockDriverState *bs)
         }
 
         /* call the change callback */
+        bs->locked = 0;
         bs->media_changed = 1;
         if (bs->change_cb)
             bs->change_cb(bs->change_opaque, CHANGE_MEDIA);
Signature · 1 line
1.7.2.3
#1 lore raw
Quoted 26 lines · Markus Armbruster

From 8cd4978c9be6ff2bcc414bb1c1b258b96b9a74c1 Mon Sep 17 00:00:00 2001
From: Markus Armbruster <[email protected]>
Date: Fri, 18 Feb 2011 15:54:02 +0100

After forcefully ejecting media locked by the guest, you can't ever again insert new media.

Example:

   (qemu) info block
   hda: type=hd removable=0 file=test.img ro=0 drv=raw encrypted=0
   cd: type=cdrom removable=1 locked=1 file=x.iso ro=0 drv=raw encrypted=0 (qemu) eject cd
   Device 'cd' is locked
   (qemu) eject -f cd
   (qemu) info block
   hda: type=hd removable=0 file=test.img ro=0 drv=raw encrypted=0
   cd: type=cdrom removable=1 locked=1 [not inserted]
   (qemu) change cd x.iso
   Device 'cd' is locked

---
I'm not entirely sure this is the appropriate fix, and that's why there's RFC in the subject.

Quoted 6 lines

Both IDE and SCSI devices expose their drive's BlockDriverState member locked to the guest via mode sense.

What does real hardware do when I force-eject media (typically by rummaging in that little hole with a paperclip)?  Does it actively notify the OS?  Does mode sense change?

No idea, but IIRC the drive is still usable after that, so locking the drive does not look correct.

Quoted 2 lines

A possible alternative fix is to make do_change_block() ignore bdrv_is_locked() when inserting media into an empty drive.

Then the meaning of locked would change, maybe eject_disabled would then describe the state better.

#2 lore raw

Sorry for my slow reply.

Quoted 27 lines · Blue Swirl
Quoted 26 lines · Markus Armbruster

From 8cd4978c9be6ff2bcc414bb1c1b258b96b9a74c1 Mon Sep 17 00:00:00 2001
From: Markus Armbruster <[email protected]>
Date: Fri, 18 Feb 2011 15:54:02 +0100

After forcefully ejecting media locked by the guest, you can't ever again insert new media.

Example:

   (qemu) info block
   hda: type=hd removable=0 file=test.img ro=0 drv=raw encrypted=0
   cd: type=cdrom removable=1 locked=1 file=x.iso ro=0 drv=raw encrypted=0 (qemu) eject cd
   Device 'cd' is locked
   (qemu) eject -f cd
   (qemu) info block
   hda: type=hd removable=0 file=test.img ro=0 drv=raw encrypted=0
   cd: type=cdrom removable=1 locked=1 [not inserted]
   (qemu) change cd x.iso
   Device 'cd' is locked

---
I'm not entirely sure this is the appropriate fix, and that's why there's RFC in the subject.

Quoted 8 lines
Quoted 6 lines

Both IDE and SCSI devices expose their drive's BlockDriverState member locked to the guest via mode sense.

What does real hardware do when I force-eject media (typically by rummaging in that little hole with a paperclip)?  Does it actively notify the OS?  Does mode sense change?

No idea, but IIRC the drive is still usable after that,

That's what I'd expect. If the OS recovers from losing the media, the drive should be fine.

Quoted 2 lines

so locking the
drive does not look correct.

I'm not sure I get you here.

Quoted 5 lines
Quoted 2 lines

A possible alternative fix is to make do_change_block() ignore bdrv_is_locked() when inserting media into an empty drive.

Then the meaning of locked would change, maybe eject_disabled would then describe the state better.

I like the current meaning of BlockDriverState member locked just fine, it nicely mirrors the SCSI / ATAPI mode sense page bit.

I'm worried about unwanted side effects of my change. For instance, what about this code in do_snapshot_blkdev():

    flags = bs->open_flags;
    bdrv_close(bs);
    ret = bdrv_open(bs, filename, flags, drv);

I'm afraid my change would make it screw up bs->locked. Jes?

#3 lore raw
In reply to Markus Armbruster
Quoted 26 lines · Markus Armbruster

From 8cd4978c9be6ff2bcc414bb1c1b258b96b9a74c1 Mon Sep 17 00:00:00 2001
From: Markus Armbruster <[email protected]>
Date: Fri, 18 Feb 2011 15:54:02 +0100

After forcefully ejecting media locked by the guest, you can't ever again insert new media.

Example:

(qemu) info block
hda: type=hd removable=0 file=test.img ro=0 drv=raw encrypted=0
cd: type=cdrom removable=1 locked=1 file=x.iso ro=0 drv=raw encrypted=0 (qemu) eject cd
Device 'cd' is locked
(qemu) eject -f cd
(qemu) info block
hda: type=hd removable=0 file=test.img ro=0 drv=raw encrypted=0
cd: type=cdrom removable=1 locked=1 [not inserted]
(qemu) change cd x.iso
Device 'cd' is locked

---
I'm not entirely sure this is the appropriate fix, and that's why there's RFC in the subject.

Quoted 6 lines

Both IDE and SCSI devices expose their drive's BlockDriverState member locked to the guest via mode sense.

What does real hardware do when I force-eject media (typically by rummaging in that little hole with a paperclip)? Does it actively notify the OS? Does mode sense change?

I think this should happen. Calling the 'change_cb' with a new CHANGE_EJECT parameter can notify the guest of the medium going from READY to NO_MEDIUM.

The guest can then probe for the status of the tray.

However, I currently don't know if devices are supposed to send such events to OSes, and how, if they are supposed to. We currently approximate this using ide_set_irq() for the cdrom case in cdrom_change_cb().

This patch looks sensible, though.

Quoted 11 lines

A possible alternative fix is to make do_change_block() ignore bdrv_is_locked() when inserting media into an empty drive.

 block.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
block.c +0 -0
index b476479..295cf7b 100644

block.c void bdrv_close(BlockDriverState *bs) · line 688

Quoted 7 lines
block.c +1 -0
@@ -682,6 +682,7 @@ void bdrv_close(BlockDriverState *bs)
         }
 
         /* call the change callback */
+        bs->locked = 0;
         bs->media_changed = 1;
         if (bs->change_cb)
             bs->change_cb(bs->change_opaque, CHANGE_MEDIA);

Amit