gostor / gotgt

Simple Golang iSCSI Target framework
Apache License 2.0
261 stars 49 forks source link

MODE SENSE: ALLOCATION LENGTH shouldn't affect a size in response #80

Closed chessman closed 5 years ago

chessman commented 5 years ago

See SCSI Command Manual (2.2.6):

The allocation length is used to limit the maximum amount of variable length data (e.g., mode data, log data, diagnostic data) returned to an application client. If the information being transferred to the Data-In Buffer includes fields containing counts of the number of bytes in some or all of the data, then the contents of these fields shall not be altered to reflect the truncation, if any, that results from an insufficient ALLOCATION LENGTH value, unless this manual describes the Data-In Buffer format states otherwise.

Linux scsi driver sends the first request with len = 4 and the next request with a length known from a response: https://github.com/torvalds/linux/blob/master/drivers/scsi/sd.c#L2668-L2682

Before this PR linux couldn't read the Caching page:

[1186194.419206] sd 6:0:0:0: [sdc] 204800 512-byte logical blocks: (105 MB/100 MiB)
[1186194.419208] sd 6:0:0:0: [sdc] 4096-byte physical blocks
[1186194.419253] sd 6:0:0:0: [sdc] Write Protect is off
[1186194.419254] sd 6:0:0:0: [sdc] Mode Sense: 03 00 10 08
[1186194.419362] sd 6:0:0:0: [sdc] No Caching mode page found
[1186194.419364] sd 6:0:0:0: [sdc] Assuming drive cache: write through
[1186194.426756] sd 6:0:0:0: [sdc] Attached SCSI disk

After the PR caching modes are being read successfully:

[1186524.264557] sd 6:0:0:0: [sdc] 204800 512-byte logical blocks: (105 MB/100 MiB)
[1186524.264558] sd 6:0:0:0: [sdc] 4096-byte physical blocks
[1186524.264631] sd 6:0:0:0: [sdc] Write Protect is off
[1186524.264632] sd 6:0:0:0: [sdc] Mode Sense: 67 00 10 08
[1186524.264750] sd 6:0:0:0: [sdc] Write cache: enabled, read cache: enabled, supports DPO and FUA
[1186524.271044] sd 6:0:0:0: [sdc] Attached SCSI disk
carmark commented 5 years ago

LGTM