After a media change, the only commands allowed from the guest were
REQUEST_SENSE and INQUIRY.  The guest may also issue
GET_EVENT_STATUS_NOTIFICATION and TEST_UNIT_READY commands to get media
changed notification.  Enable those commands.

After this, the HSM violation messages from Linux guests aren't seen.

Signed-off-by: Amit Shah <amit.s...@redhat.com>
---
 hw/ide/core.c |   28 +++++++++++++++++++++-------
 1 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index 89e212b..362a258 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -625,6 +625,14 @@ void ide_atapi_cmd_ok(IDEState *s)
     ide_set_irq(s->bus);
 }
 
+static void ide_atapi_cmd_ua(IDEState *s)
+{
+    s->sense_key = SENSE_UNIT_ATTENTION;
+    s->asc = ASC_MEDIUM_MAY_HAVE_CHANGED;
+    ide_atapi_cmd_ok(s);
+    s->sense_key = SENSE_NONE;
+}
+
 void ide_atapi_cmd_error(IDEState *s, int sense_key, int asc)
 {
 #ifdef DEBUG_IDE_ATAPI
@@ -1243,20 +1251,26 @@ static void ide_atapi_cmd(IDEState *s)
     /* If there's a UNIT_ATTENTION condition pending, only
        REQUEST_SENSE and INQUIRY commands are allowed to complete. */
     if (s->sense_key == SENSE_UNIT_ATTENTION &&
-       s->io_buffer[0] != GPCMD_REQUEST_SENSE &&
-       s->io_buffer[0] != GPCMD_INQUIRY) {
-       ide_atapi_cmd_check_status(s);
-       return;
+        s->io_buffer[0] != GPCMD_REQUEST_SENSE &&
+        s->io_buffer[0] != GPCMD_INQUIRY &&
+        s->io_buffer[0] != GPCMD_GET_EVENT_STATUS_NOTIFICATION &&
+        s->io_buffer[0] != GPCMD_TEST_UNIT_READY) {
+        ide_atapi_cmd_check_status(s);
+        return;
     }
     switch(s->io_buffer[0]) {
     case GPCMD_TEST_UNIT_READY:
-        if (bdrv_is_inserted(s->bs) && !s->cdrom_changed) {
-            ide_atapi_cmd_ok(s);
+        if (bdrv_is_inserted(s->bs)) {
+            if (!s->cdrom_changed) {
+                ide_atapi_cmd_ok(s);
+            } else {
+                ide_atapi_cmd_ua(s);
+            }
         } else {
-            s->cdrom_changed = 0;
             ide_atapi_cmd_error(s, SENSE_NOT_READY,
                                 ASC_MEDIUM_NOT_PRESENT);
         }
+        s->cdrom_changed = 0;
         break;
     case GPCMD_MODE_SENSE_6:
     case GPCMD_MODE_SENSE_10:
-- 
1.7.4


Reply via email to