Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > media > main-src > by-pkgid > aadbe78a25743146bb784eee19f007c5 > files > 161

kvm-83-164.el5_5.9.src.rpm

From 82a377e801c2a862cb1a9ca04a97083b945d120d Mon Sep 17 00:00:00 2001
From: Mark McLoughlin <markmc@redhat.com>
Date: Wed, 3 Jun 2009 09:52:49 +0100
Subject: [PATCH 07/10] Prevent CD-ROM media eject while device is locked

https://bugzilla.redhat.com/503029

Section 10.8.25 ("START/STOP UNIT Command") of SFF-8020i states that
if the device is locked we should refuse to eject if the device is
locked.

ASC_MEDIA_REMOVAL_PREVENTED is the appropriate return in this case.

In order to stop itself from ejecting the media it is running from,
Fedora's installer (anaconda) requires the CDROMEJECT ioctl() to fail
if the drive has been previously locked.

This fixes anaconda installs crashing/hanging at the end when qemu
allows anaconda to pull the rug out from under itself.

Patch submitted upstream here:

  http://lists.gnu.org/archive/html/qemu-devel/2009-05/msg01324.html

Still awaiting upstream review and acceptance.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
Message-Id: <1244019169.5001.11.camel@blaa>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
RH-Upstream-status: submitted(qemu-devel)
Acked-by: Dor Laor <dlaor@redhat.com>
Acked-by: Glauber Costa <glommer@redhat.com>
Acked-by: Kevin Wolf <kwolf@redhat.com>
Bugzilla: 504237
---
 qemu/block.c  |    9 ++++++++-
 qemu/block.h  |    2 +-
 qemu/hw/ide.c |   26 ++++++++++++++++++--------
 3 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/qemu/block.c b/qemu/block.c
index 078065d..5fbd797 100644
--- a/qemu/block.c
+++ b/qemu/block.c
@@ -1612,11 +1612,15 @@ int bdrv_media_changed(BlockDriverState *bs)
 /**
  * If eject_flag is TRUE, eject the media. Otherwise, close the tray
  */
-void bdrv_eject(BlockDriverState *bs, int eject_flag)
+int bdrv_eject(BlockDriverState *bs, int eject_flag)
 {
     BlockDriver *drv = bs->drv;
     int ret;
 
+    if (bs->locked) {
+        return -EBUSY;
+    }
+
     if (!drv || !drv->bdrv_eject) {
         ret = -ENOTSUP;
     } else {
@@ -1625,7 +1629,10 @@ void bdrv_eject(BlockDriverState *bs, int eject_flag)
     if (ret == -ENOTSUP) {
         if (eject_flag)
             bdrv_close(bs);
+        ret = 0;
     }
+
+    return ret;
 }
 
 int bdrv_is_locked(BlockDriverState *bs)
diff --git a/qemu/block.h b/qemu/block.h
index 4983bc2..867c463 100644
--- a/qemu/block.h
+++ b/qemu/block.h
@@ -129,7 +129,7 @@ int bdrv_is_inserted(BlockDriverState *bs);
 int bdrv_media_changed(BlockDriverState *bs);
 int bdrv_is_locked(BlockDriverState *bs);
 void bdrv_set_locked(BlockDriverState *bs, int locked);
-void bdrv_eject(BlockDriverState *bs, int eject_flag);
+int bdrv_eject(BlockDriverState *bs, int eject_flag);
 void bdrv_set_change_cb(BlockDriverState *bs,
                         void (*change_cb)(void *opaque), void *opaque);
 void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size);
diff --git a/qemu/hw/ide.c b/qemu/hw/ide.c
index ba4cce5..6e56b4c 100644
--- a/qemu/hw/ide.c
+++ b/qemu/hw/ide.c
@@ -358,6 +358,7 @@
 #define ASC_INCOMPATIBLE_FORMAT              0x30
 #define ASC_MEDIUM_NOT_PRESENT               0x3a
 #define ASC_SAVING_PARAMETERS_NOT_SUPPORTED  0x39
+#define ASC_MEDIA_REMOVAL_PREVENTED          0x53
 
 #define CFA_NO_ERROR            0x00
 #define CFA_MISC_ERROR          0x09
@@ -1772,18 +1773,27 @@ static void ide_atapi_cmd(IDEState *s)
         break;
     case GPCMD_START_STOP_UNIT:
         {
-            int start, eject;
+            int start, eject, err = 0;
             start = packet[4] & 1;
             eject = (packet[4] >> 1) & 1;
 
-            if (eject && !start) {
-                /* eject the disk */
-                bdrv_eject(s->bs, 1);
-            } else if (eject && start) {
-                /* close the tray */
-                bdrv_eject(s->bs, 0);
+            if (eject) {
+                err = bdrv_eject(s->bs, !start);
+            }
+
+            switch (err) {
+            case 0:
+                ide_atapi_cmd_ok(s);
+                break;
+            case -EBUSY:
+                ide_atapi_cmd_error(s, SENSE_NOT_READY,
+                                    ASC_MEDIA_REMOVAL_PREVENTED);
+                break;
+            default:
+                ide_atapi_cmd_error(s, SENSE_NOT_READY,
+                                    ASC_MEDIUM_NOT_PRESENT);
+                break;
             }
-            ide_atapi_cmd_ok(s);
         }
         break;
     case GPCMD_MECHANISM_STATUS:
-- 
1.6.3.rc4.29.g8146