ide/atapi scsi-disk: Make monitor eject -f, then change work
authorMarkus Armbruster <armbru@redhat.com>
Tue, 6 Sep 2011 16:59:00 +0000 (18:59 +0200)
committerKevin Wolf <kwolf@redhat.com>
Mon, 12 Sep 2011 13:17:22 +0000 (15:17 +0200)
change fails while the tray is locked by the guest.  eject -f forces
it open and removes any media.  Unfortunately, the tray closes again
instantly.  Since the lock remains as it is, there is no way to insert
another medium unless the guest voluntarily unlocks.

Fix by leaving the tray open after monitor eject.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
blockdev.c
hw/ide/core.c
hw/scsi-disk.c

index 154cc8456ec518596e98f13a0d179d8919536ce9..0827bf77438a7d245b1f308c52ef809f9535c2ca 100644 (file)
@@ -635,7 +635,8 @@ static int eject_device(Monitor *mon, BlockDriverState *bs, int force)
         qerror_report(QERR_DEVICE_NOT_REMOVABLE, bdrv_get_device_name(bs));
         return -1;
     }
-    if (!force && bdrv_dev_is_medium_locked(bs)) {
+    if (!force && !bdrv_dev_is_tray_open(bs)
+        && bdrv_dev_is_medium_locked(bs)) {
         qerror_report(QERR_DEVICE_LOCKED, bdrv_get_device_name(bs));
         return -1;
     }
index 5def25c53d0bf174c762c982a4c6a586484f4b03..9297b9e657341ae1da06b6f624a6759357781ddf 100644 (file)
@@ -789,6 +789,7 @@ static void ide_cd_change_cb(void *opaque, bool load)
     IDEState *s = opaque;
     uint64_t nb_sectors;
 
+    s->tray_open = !load;
     bdrv_get_geometry(s->bs, &nb_sectors);
     s->nb_sectors = nb_sectors;
 
index f5f1d826888de60ad22cef339f5f91ffca95bbfe..4a60820b18c14941a442b1aa48bdbeffd0fef1ba 100644 (file)
@@ -1175,6 +1175,7 @@ static void scsi_destroy(SCSIDevice *dev)
 
 static void scsi_cd_change_media_cb(void *opaque, bool load)
 {
+    ((SCSIDiskState *)opaque)->tray_open = !load;
 }
 
 static bool scsi_cd_is_tray_open(void *opaque)