Re: [Qemu-devel] [PATCH 35/55] scsi-disk: Avoid physical/virtual tray state mismatch

2011-07-26 Thread Christoph Hellwig
On Wed, Jul 20, 2011 at 06:24:09PM +0200, 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.

Looks good,

Reviewed-by: Christoph Hellwig 




[Qemu-devel] [PATCH 35/55] scsi-disk: Avoid physical/virtual tray state mismatch

2011-07-20 Thread Markus Armbruster
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 
---
 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 b9de4df..553d8c6 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1270,6 +1270,9 @@ static void scsi_destroy(SCSIDevice *dev)
 SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
 
 scsi_device_purge_requests(&s->qdev);
+if (s->drive_kind == SCSI_CD) {
+bdrv_lock_medium(s->qdev.conf.bs, 0);
+}
 blockdev_mark_auto_del(s->qdev.conf.bs);
 }
 
@@ -1332,6 +1335,10 @@ static int scsi_initfn(SCSIDevice *dev, SCSIDriveKind 
kind)
 s->qdev.type = TYPE_DISK;
 qemu_add_vm_change_state_handler(scsi_dma_restart_cb, s);
 bdrv_set_removable(s->bs, kind == SCSI_CD);
+if (kind == SCSI_CD) {
+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;
 }
-- 
1.7.2.3