qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] scsi-disk: Inquiry with allocation length of CDB < 36
@ 2009-10-26 13:36 Artyom Tarasenko
  2009-10-27 18:03 ` Anthony Liguori
  0 siblings, 1 reply; 4+ messages in thread
From: Artyom Tarasenko @ 2009-10-26 13:36 UTC (permalink / raw)
  To: qemu-devel, Blue Swirl

[-- Attachment #1: Type: text/plain, Size: 2149 bytes --]

According to SCSI-2 specification,
http://ldkelley.com/SCSI2/SCSI2/SCSI2/SCSI2-08.html#8.2.5 ,
"if the allocation length of the command descriptor block (CDB) is too
small to transfer
all of the parameters, the additional length shall not be adjusted to
reflect the truncation."
The 36 mandatory bytes of response are written to outbuf, and then
only the length requested
in CDB is transferred.

Signed-off-by: Artyom Tarasenko <atar4qemu@gmail.com>
---
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 2a9268a..1a7487e 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -5,6 +5,12 @@
  * Based on code by Fabrice Bellard
  *
  * Written by Paul Brook
+ * Modifications:
+ *  2009-Oct-26 Artyom Tarasenko : implemented stamdard inquiry for the case
+ *                                 when the allocation length of CDB is smaller
+ *                                 than 36.
+ *  2009-Oct-13 Artyom Tarasenko : implemented the block descriptor in the
+ *                                 MODE SENSE response.
  *
  * This code is licenced under the LGPL.
  *
@@ -576,11 +582,6 @@ static int32_t scsi_send_command(SCSIDevice *d,
uint32_t tag,
                      "is less than 5\n", len);
                 goto fail;
             }
-
-            if (len < 36) {
-                BADF("Error: Inquiry (STANDARD) buffer size %d "
-                     "is less than 36 (TODO: only 5 required)\n", len);
-            }
         }

         if(len > SCSI_MAX_INQUIRY_LEN)
@@ -604,7 +605,13 @@ static int32_t scsi_send_command(SCSIDevice *d,
uint32_t tag,
            Some later commands are also implemented. */
        outbuf[2] = 3;
        outbuf[3] = 2; /* Format 2 */
-       outbuf[4] = len - 5; /* Additional Length = (Len - 1) - 4 */
+       if (len > 36) {
+           outbuf[4] = len - 5; /* Additional Length = (Len - 1) - 4 */
+       } else {
+              /* If the allocation length of CDB is too small, the
additional length
+                 is not adjusted */
+           outbuf[4] = 36 - 5;
+       }
         /* Sync data transfer and TCQ.  */
         outbuf[7] = 0x10 | (r->bus->tcq ? 0x02 : 0);
        r->iov.iov_len = len;

[-- Attachment #2: 0001-scsi-disk-short-inquiry.patch --]
[-- Type: text/plain, Size: 1703 bytes --]

Signed-off-by: Artyom Tarasenko <atar4qemu@gmail.com>
---
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 2a9268a..1a7487e 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -5,6 +5,12 @@
  * Based on code by Fabrice Bellard
  *
  * Written by Paul Brook
+ * Modifications:
+ *  2009-Oct-26 Artyom Tarasenko : implemented stamdard inquiry for the case
+ *                                 when the allocation length of CDB is smaller
+ *                                 than 36.
+ *  2009-Oct-13 Artyom Tarasenko : implemented the block descriptor in the 
+ *                                 MODE SENSE response.
  *
  * This code is licenced under the LGPL.
  *
@@ -576,11 +582,6 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag,
                      "is less than 5\n", len);
                 goto fail;
             }
-
-            if (len < 36) {
-                BADF("Error: Inquiry (STANDARD) buffer size %d "
-                     "is less than 36 (TODO: only 5 required)\n", len);
-            }
         }
 
         if(len > SCSI_MAX_INQUIRY_LEN)
@@ -604,7 +605,13 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag,
            Some later commands are also implemented. */
 	outbuf[2] = 3;
 	outbuf[3] = 2; /* Format 2 */
-	outbuf[4] = len - 5; /* Additional Length = (Len - 1) - 4 */
+	if (len > 36) {
+	    outbuf[4] = len - 5; /* Additional Length = (Len - 1) - 4 */
+	} else {
+              /* If the allocation length of CDB is too small, the additional length
+                 is not adjusted */  
+	    outbuf[4] = 36 - 5;
+	}
         /* Sync data transfer and TCQ.  */
         outbuf[7] = 0x10 | (r->bus->tcq ? 0x02 : 0);
 	r->iov.iov_len = len;

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

end of thread, other threads:[~2009-10-28 11:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-26 13:36 [Qemu-devel] [PATCH] scsi-disk: Inquiry with allocation length of CDB < 36 Artyom Tarasenko
2009-10-27 18:03 ` Anthony Liguori
2009-10-27 18:09   ` Artyom Tarasenko
2009-10-28 11:31     ` Artyom Tarasenko

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).