On 08/03/2011 03:08 PM, Markus Armbruster wrote:
When scsi-cd is backed by a physical drive, we want the physical tray
match the virtual one.  To that end, we call bdrv_eject() on guest's
load/eject, and bdrv_lock_medium() on guest's prevent/allow removal.
But we don't set the initial state on device model init.  Fix that.
While there, also unlock on device model exit.

Signed-off-by: Markus Armbruster<arm...@redhat.com>
---
  hw/scsi-disk.c |    7 +++++++
  1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 19a1843..f223de6 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1205,6 +1205,9 @@ static void scsi_destroy(SCSIDevice *dev)
      SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);

      scsi_device_purge_requests(&s->qdev);
+    if (s->qdev.type == TYPE_ROM) {
+        bdrv_lock_medium(s->qdev.conf.bs, 0);
+    }
      blockdev_mark_auto_del(s->qdev.conf.bs);
  }

@@ -1265,6 +1268,10 @@ static int scsi_initfn(SCSIDevice *dev, uint8_t 
scsi_type)
      s->qdev.type = scsi_type;
      qemu_add_vm_change_state_handler(scsi_dma_restart_cb, s);
      bdrv_set_removable(s->bs, scsi_type == TYPE_ROM);
+    if (scsi_type == TYPE_ROM) {
+        bdrv_lock_medium(s->bs, s->tray_locked);
+        bdrv_eject(s->bs, s->tray_open);
+    }
      add_boot_device_path(s->qdev.conf.bootindex,&dev->qdev, ",0");
      return 0;
  }
We could go not into metaphysical arguments that we're exposing the host state to the guest here. But I guess that would be taking things too far :-)
Acked-by: Hannes Reinecke <h...@suse.de>

Cheers,

Hannes
--
Dr. Hannes Reinecke                   zSeries & Storage
h...@suse.de                          +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)

Reply via email to