Skip to contentSkip to conversation

scsi: sd: Fix cache_type_store()

PATCH Applied Ivan Mironov 2 participants 2 messages Dec 23, 2018 – Jan 4, 2019 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: sd: Fix cache_type_store()

Changing of caching mode via /sys/devices/.../scsi_disk/.../cache_type may fail if device responses to MODE SENSE command with DPOFUA flag set, and then checks this flag to be not set on MODE SELECT command.

When trying to change cache_type, write always fails:

	# echo "none" >cache_type
	bash: echo: write error: Invalid argument

And following appears in dmesg:

	[13007.865745] sd 1:0:1:0: [sda] Sense Key : Illegal Request [current]
	[13007.865753] sd 1:0:1:0: [sda] Add. Sense: Invalid field in parameter list
---
 drivers/scsi/sd.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/scsi/sd.c +15 -0
index bd0a5c694a97..698fe651fb1a 100644
@@ -206,6 +206,21 @@ cache_type_store(struct device *dev, struct device_attribute *attr,
 	sp = buffer_data[0] & 0x80 ? 1 : 0;
 	buffer_data[0] &= ~0x80;
 
+	/* From SBC-4 r15, 6.5.1 "Mode pages overview", description of
+	 * DEVICE-SPECIFIC PARAMETER field in the mode parameter header:
+	 *     ...
+	 *     The write protect (WP) bit for mode data sent with a MODE SELECT
+	 *     command shall be ignored by the device server.
+	 *     ...
+	 *     The DPOFUA bit is reserved for mode data sent with a MODE SELECT
+	 *     command.
+	 *     ...
+	 * All other bits are also reserved, and all reserved bits shall be set
+	 * to zero according to the same document. So, we can simply set this
+	 * field to zero for compatibility.
+	 */
+	data.device_specific = 0;
+
 	if (scsi_mode_select(sdp, 1, sp, 8, buffer_data, len, SD_TIMEOUT,
 			     SD_MAX_RETRIES, &data, &sshdr)) {
 		if (scsi_sense_valid(&sshdr))
Signature · 1 line
2.20.1
#1 lore raw

Ivan,

drivers/scsi/sd.c cache_type_store(struct device *dev, struct device_attribute *attr, · line 216

Quoted 5 lines
drivers/scsi/sd.c +5 -0
+	 *     The write protect (WP) bit for mode data sent with a MODE SELECT
+	 *     command shall be ignored by the device server.
+	 *     ...
+	 *     The DPOFUA bit is reserved for mode data sent with a MODE SELECT
+	 *     command.

Wonderfully consistent :(

Applied to 4.21/scsi-fixes. Thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering