Skip to contentSkip to conversation

scsi-disk: Inquiry with allocation length of CDB < 36

PATCH In review Artyom Tarasenko 2 participants 4 messages Oct 26, 2009 – Oct 28, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi-disk: Inquiry with allocation length of CDB < 36

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.

---

hw/scsi-disk.c +6 -0
index 2a9268a..1a7487e 100644
@@ -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;

---

hw/scsi-disk.c +13 -6
index 2a9268a..1a7487e 100644
@@ -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;
#1 lore raw
Quoted 10 lines · Artyom Tarasenko

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.

Quoted 2 lines

This patch is whitespace damaged.

Regards,

Anthony Liguori

#2 lore raw

2009/10/27 Anthony Liguori <[email protected]>:

Quoted 12 lines
Quoted 11 lines · Artyom Tarasenko

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.

Quoted 4 lines
Quoted 2 lines

This patch is whitespace damaged.

Also the attached one? I tried to keep the original identation: used tabs where the tabs originally were.

#3 lore raw

2009/10/27 Artyom Tarasenko <[email protected]>:

Quoted 13 lines

2009/10/27 Anthony Liguori <[email protected]>:

Quoted 12 lines
Quoted 11 lines · Artyom Tarasenko

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.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

This patch is whitespace damaged.

Also the attached one? I tried to keep the original indentation: used tabs where the tabs originally were.

What is actually the indentation policy for patches? Should they be conform with CODING_STYLE even if the original code isn't? If they are conform the code may look badly indented with any tab settings, including the ones from the original author. If they keep author's indentation, the code still may look badly indented with the CODING_STYLE tab settings.

Should patches for badly indented code explicitly require indentation-only patches which shall be applied before?