[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 33/55] ide/atapi: Avoid physical/virtual tray state
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PATCH 33/55] ide/atapi: Avoid physical/virtual tray state mismatch |
Date: |
Wed, 20 Jul 2011 18:24:07 +0200 |
When ide-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 <address@hidden>
---
hw/ide/core.c | 4 ++++
hw/ide/qdev.c | 18 ++++++++++++++++++
2 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 35beb93..1c84b68 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1845,6 +1845,10 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs,
IDEDriveKind kind,
ide_reset(s);
bdrv_set_removable(bs, s->drive_kind == IDE_CD);
+ if (s->drive_kind == IDE_CD) {
+ bdrv_lock_medium(bs, s->tray_locked);
+ bdrv_eject(bs, s->tray_open);
+ }
return 0;
}
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index 97ccbe8..50188a9 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -178,6 +178,12 @@ static int ide_cd_initfn(IDEDevice *dev)
return ide_dev_initfn(dev, IDE_CD);
}
+static int ide_cd_exitfn(IDEDevice *dev)
+{
+ bdrv_lock_medium(dev->conf.bs, 0);
+ return 0;
+}
+
static int ide_drive_initfn(IDEDevice *dev)
{
DriveInfo *dinfo = drive_get_by_blockdev(dev->conf.bs);
@@ -185,6 +191,16 @@ static int ide_drive_initfn(IDEDevice *dev)
return ide_dev_initfn(dev, dinfo->media_cd ? IDE_CD : IDE_HD);
}
+static int ide_drive_exitfn(IDEDevice *dev)
+{
+ DriveInfo *dinfo = drive_get_by_blockdev(dev->conf.bs);
+
+ if (dinfo->media_cd) {
+ return ide_cd_exitfn(dev);
+ }
+ return 0;
+}
+
#define DEFINE_IDE_DEV_PROPERTIES() \
DEFINE_PROP_UINT32("unit", IDEDrive, dev.unit, -1), \
DEFINE_BLOCK_PROPERTIES(IDEDrive, dev.conf), \
@@ -208,6 +224,7 @@ static IDEDeviceInfo ide_dev_info[] = {
.qdev.desc = "virtual IDE CD-ROM",
.qdev.size = sizeof(IDEDrive),
.init = ide_cd_initfn,
+ .exit = ide_cd_exitfn,
.qdev.props = (Property[]) {
DEFINE_IDE_DEV_PROPERTIES(),
DEFINE_PROP_END_OF_LIST(),
@@ -218,6 +235,7 @@ static IDEDeviceInfo ide_dev_info[] = {
.qdev.desc = "virtual IDE disk or CD-ROM (legacy)",
.qdev.size = sizeof(IDEDrive),
.init = ide_drive_initfn,
+ .exit = ide_drive_exitfn,
.qdev.props = (Property[]) {
DEFINE_IDE_DEV_PROPERTIES(),
DEFINE_PROP_END_OF_LIST(),
--
1.7.2.3
[Qemu-devel] [PATCH 24/55] ide/atapi: Track tray locked state, Markus Armbruster, 2011/07/20