qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] windows cdrom cache flush
@ 2008-11-04 15:00 Stefano Stabellini
  2008-11-11 20:58 ` Anthony Liguori
  2008-12-03 15:53 ` Ian Jackson
  0 siblings, 2 replies; 4+ messages in thread
From: Stefano Stabellini @ 2008-11-04 15:00 UTC (permalink / raw)
  To: qemu-devel

Windows only flushes its cache of a CDROM if it gets a
SENSE_UNIT_ATTENTION CHECK_CONDITION response to a REQUEST_SENSE
command.
Make sure it does so after we change the CD.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: Steven Smith <steven.smith@citrix.com>

---

diff --git a/hw/ide.c b/hw/ide.c
index 33e8b39..836f23b 100644
--- a/hw/ide.c
+++ b/hw/ide.c
@@ -351,6 +351,7 @@
 #define ASC_ILLEGAL_OPCODE                   0x20
 #define ASC_LOGICAL_BLOCK_OOR                0x21
 #define ASC_INV_FIELD_IN_CMD_PACKET          0x24
+#define ASC_MEDIUM_MAY_HAVE_CHANGED          0x28
 #define ASC_INCOMPATIBLE_FORMAT              0x30
 #define ASC_MEDIUM_NOT_PRESENT               0x3a
 #define ASC_SAVING_PARAMETERS_NOT_SUPPORTED  0x39
@@ -1106,6 +1107,17 @@ static void ide_atapi_cmd_error(IDEState *s, int sense_key, int asc)
     ide_set_irq(s);
 }
 
+static void ide_atapi_cmd_check_status(IDEState *s)
+{
+#ifdef DEBUG_IDE_ATAPI
+    printf("atapi_cmd_check_status\n");
+#endif
+    s->error = MC_ERR | (SENSE_UNIT_ATTENTION << 4);
+    s->status = ERR_STAT;
+    s->nsector = 0;
+    ide_set_irq(s);
+}
+
 static inline void cpu_to_ube16(uint8_t *buf, int val)
 {
     buf[0] = val >> 8;
@@ -1528,6 +1540,14 @@ static void ide_atapi_cmd(IDEState *s)
         printf("\n");
     }
 #endif
+    /* 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;
+    }
     switch(s->io_buffer[0]) {
     case GPCMD_TEST_UNIT_READY:
         if (bdrv_is_inserted(s->bs)) {
@@ -1623,6 +1643,8 @@ static void ide_atapi_cmd(IDEState *s)
         buf[2] = s->sense_key;
         buf[7] = 10;
         buf[12] = s->asc;
+	if (s->sense_key == SENSE_UNIT_ATTENTION)
+	    s->sense_key = SENSE_NONE;
         ide_atapi_cmd_reply(s, 18, max_len);
         break;
     case GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL:
@@ -1974,9 +1996,13 @@ static void cdrom_change_cb(void *opaque)
     IDEState *s = opaque;
     uint64_t nb_sectors;
 
-    /* XXX: send interrupt too */
     bdrv_get_geometry(s->bs, &nb_sectors);
     s->nb_sectors = nb_sectors;
+
+    s->sense_key = SENSE_UNIT_ATTENTION;
+    s->asc = ASC_MEDIUM_MAY_HAVE_CHANGED;
+
+    ide_set_irq(s);
 }
 
 static void ide_cmd_lba48_transform(IDEState *s, int lba48)

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] windows cdrom cache flush
  2008-11-04 15:00 [Qemu-devel] [PATCH] windows cdrom cache flush Stefano Stabellini
@ 2008-11-11 20:58 ` Anthony Liguori
  2008-11-12 11:18   ` Stefano Stabellini
  2008-12-03 15:53 ` Ian Jackson
  1 sibling, 1 reply; 4+ messages in thread
From: Anthony Liguori @ 2008-11-11 20:58 UTC (permalink / raw)
  To: qemu-devel

Stefano Stabellini wrote:
> Windows only flushes its cache of a CDROM if it gets a
> SENSE_UNIT_ATTENTION CHECK_CONDITION response to a REQUEST_SENSE
> command.
> Make sure it does so after we change the CD.
>
> Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> Signed-off-by: Steven Smith <steven.smith@citrix.com>
>
> ---
>   

Applied, but you had some tab damage.  svn sucks sufficiently that it 
was easier for me to fix than to undo the patch, so I just fixed it up 
myself.  In the future, please try to avoid this.

Regards,

Anthony Liguori

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] windows cdrom cache flush
  2008-11-11 20:58 ` Anthony Liguori
@ 2008-11-12 11:18   ` Stefano Stabellini
  0 siblings, 0 replies; 4+ messages in thread
From: Stefano Stabellini @ 2008-11-12 11:18 UTC (permalink / raw)
  To: qemu-devel

Anthony Liguori wrote:

> Applied, but you had some tab damage.  svn sucks sufficiently that it
> was easier for me to fix than to undo the patch, so I just fixed it up
> myself.  In the future, please try to avoid this.
> 


Thanks, sorry about the tabs.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] windows cdrom cache flush
  2008-11-04 15:00 [Qemu-devel] [PATCH] windows cdrom cache flush Stefano Stabellini
  2008-11-11 20:58 ` Anthony Liguori
@ 2008-12-03 15:53 ` Ian Jackson
  1 sibling, 0 replies; 4+ messages in thread
From: Ian Jackson @ 2008-12-03 15:53 UTC (permalink / raw)
  To: qemu-devel

Stefano Stabellini writes ("[Qemu-devel] [PATCH] windows cdrom cache flush"):
> Windows only flushes its cache of a CDROM if it gets a
> SENSE_UNIT_ATTENTION CHECK_CONDITION response to a REQUEST_SENSE
> command.
> Make sure it does so after we change the CD.

Should I cherry pick this into qemu-xen 3.3 ?  (I haven't checked
whether we already have it, and of course it'll come into xen-unstable
next time I merge.)

Ian.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-12-03 15:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-04 15:00 [Qemu-devel] [PATCH] windows cdrom cache flush Stefano Stabellini
2008-11-11 20:58 ` Anthony Liguori
2008-11-12 11:18   ` Stefano Stabellini
2008-12-03 15:53 ` Ian Jackson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).