Skip to contentSkip to conversation

scsi: sd: provide a new module parameter to set whether SCSI disks support WRITE_SAME_16 by default

PATCH Superseded AlexChen 3 participants 4 messages Jan 19, 2020 – Jan 21, 2020 SCSI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

AlexChen

author
#0 lore raw

PATCH 1/1 scsi: sd: provide a new module parameter to set whether SCSI disks support WRITE_SAME_16 by default

When the SCSI device is initialized, check whether it supports WRITE_SAME_16 or WRITE_SAME_10 in the sd_read_write_same(). If the back-end storage device does not support queries, it will not set sdkp->ws16 as 1.

When the WRITE_SAME io is issued through the blkdev_issue_write_same(), the WRITE_SAME type is set to WRITE_SAME_10 by default in the sd_setup_write_same_cmnd() since of "sdkp->ws16=0". If the storage device does not support WRITE_SAME_10, then the SCSI device is set to not support WRITE_SAME.

Currently, some storage devices do not provide queries for WRITE_SAME_16/WRITE_SAME_10 support, but they do support WRITE_SAME_16 and do not support WRITE_SAME_10. So in order for these devices to use WRITE_SAME, we need a new module parameter to set whether SCSI disks support WRITE_SAME_16 by default.

---
 drivers/scsi/sd.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/scsi/sd.c +5 -1
index 4f7e7b607..ff368701d 100644
@@ -104,6 +104,9 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_ZBC);
 #define SD_MINORS	0
 #endif
 
+static int sd_default_support_ws16;
+module_param(sd_default_support_ws16, int, 0644);
+
 static void sd_config_discard(struct scsi_disk *, unsigned int);
 static void sd_config_write_same(struct scsi_disk *);
 static int  sd_revalidate_disk(struct gendisk *);
@@ -3014,7 +3017,8 @@ static void sd_read_write_same(struct scsi_disk *sdkp, unsigned char *buffer)
 			sdev->no_write_same = 1;
 	}
 
-	if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, WRITE_SAME_16) == 1)
+	if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, WRITE_SAME_16) == 1 ||
+			sd_default_support_ws16)
 		sdkp->ws16 = 1;
 
 	if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, WRITE_SAME) == 1)

-- 2.19.1

#1 lore raw
Quoted 37 lines · AlexChen

When the SCSI device is initialized, check whether it supports WRITE_SAME_16 or WRITE_SAME_10 in the sd_read_write_same(). If the back-end storage device does not support queries, it will not set sdkp->ws16 as 1.

When the WRITE_SAME io is issued through the blkdev_issue_write_same(), the WRITE_SAME type is set to WRITE_SAME_10 by default in the sd_setup_write_same_cmnd() since of "sdkp->ws16=0". If the storage device does not support WRITE_SAME_10, then the SCSI device is set to not support WRITE_SAME.

Currently, some storage devices do not provide queries for WRITE_SAME_16/WRITE_SAME_10 support, but they do support WRITE_SAME_16 and do not support WRITE_SAME_10. So in order for these devices to use WRITE_SAME, we need a new module parameter to set whether SCSI disks support WRITE_SAME_16 by default.

---
 drivers/scsi/sd.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/scsi/sd.c +3 -0
index 4f7e7b607..ff368701d 100644
@@ -104,6 +104,9 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_ZBC);
 #define SD_MINORS	0
 #endif
 
+static int sd_default_support_ws16;
+module_param(sd_default_support_ws16, int, 0644);
+
 static void sd_config_discard(struct scsi_disk *, unsigned int);
 static void sd_config_write_same(struct scsi_disk *);
 static int  sd_revalidate_disk(struct gendisk *);

drivers/scsi/sd.c static void sd_read_write_same(struct scsi_disk *sdkp, unsigned char *buffer) · line 3024

Quoted 9 lines
drivers/scsi/sd.c +2 -1
@@ -3014,7 +3017,8 @@ static void sd_read_write_same(struct scsi_disk *sdkp, unsigned char *buffer)
 			sdev->no_write_same = 1;
 	}
 
-	if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, WRITE_SAME_16) == 1)
+	if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, WRITE_SAME_16) == 1 ||
+			sd_default_support_ws16)
 		sdkp->ws16 = 1;
 
 	if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, WRITE_SAME) == 1)

Should this be fixed using the quirk mechanism instead of introducing a new kernel module parameter? Kernel module parameters apply to all SCSI disk devices irrespective of their vendor and model. The quirk mechanism can be used to introduce special behavior for certain disk models and types. See also the output of the following grep command:

$ git grep -nH '& BLIST'

Bart.

author
#2 lore raw
Quoted 54 lines · Bart Van Assche
Quoted 37 lines · AlexChen

When the SCSI device is initialized, check whether it supports WRITE_SAME_16 or WRITE_SAME_10 in the sd_read_write_same(). If the back-end storage device does not support queries, it will not set sdkp->ws16 as 1.

When the WRITE_SAME io is issued through the blkdev_issue_write_same(), the WRITE_SAME type is set to WRITE_SAME_10 by default in the sd_setup_write_same_cmnd() since of "sdkp->ws16=0". If the storage device does not support WRITE_SAME_10, then the SCSI device is set to not support WRITE_SAME.

Currently, some storage devices do not provide queries for WRITE_SAME_16/WRITE_SAME_10 support, but they do support WRITE_SAME_16 and do not support WRITE_SAME_10. So in order for these devices to use WRITE_SAME, we need a new module parameter to set whether SCSI disks support WRITE_SAME_16 by default.

---
 drivers/scsi/sd.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/scsi/sd.c +3 -0
index 4f7e7b607..ff368701d 100644
@@ -104,6 +104,9 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_ZBC);
 #define SD_MINORS	0
 #endif
 
+static int sd_default_support_ws16;
+module_param(sd_default_support_ws16, int, 0644);
+
 static void sd_config_discard(struct scsi_disk *, unsigned int);
 static void sd_config_write_same(struct scsi_disk *);
 static int  sd_revalidate_disk(struct gendisk *);

drivers/scsi/sd.c static void sd_read_write_same(struct scsi_disk *sdkp, unsigned char *buffer) · line 3024

Quoted 9 lines
drivers/scsi/sd.c +2 -1
@@ -3014,7 +3017,8 @@ static void sd_read_write_same(struct scsi_disk *sdkp, unsigned char *buffer)
 			sdev->no_write_same = 1;
 	}
 
-	if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, WRITE_SAME_16) == 1)
+	if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, WRITE_SAME_16) == 1 ||
+			sd_default_support_ws16)
 		sdkp->ws16 = 1;
 
 	if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, WRITE_SAME) == 1)

Should this be fixed using the quirk mechanism instead of introducing a new kernel module parameter? Kernel module parameters apply to all SCSI disk devices irrespective of their vendor and model. The quirk mechanism can be used to introduce special behavior for certain disk models and types. See also the output of the following grep command:

Quoted 4 lines
$ git grep -nH '& BLIST'

Bart.

Thanks for your reply.
I will try to fix the problem by the way you suggested above.

Thanks
Alex

Quoted 3 lines

.

#3 lore raw
In reply to Bart Van Assche

Bart,

Quoted 11 lines

drivers/scsi/sd.c static void sd_read_write_same(struct scsi_disk *sdkp, unsigned char *buffer) · line 3024

Quoted 5 lines
drivers/scsi/sd.c +2 -0
+	if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, WRITE_SAME_16) == 1 ||
+			sd_default_support_ws16)
 		sdkp->ws16 = 1;
 
 	if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, WRITE_SAME) == 1)

Should this be fixed using the quirk mechanism instead of introducing a new kernel module parameter? Kernel module parameters apply to all SCSI disk devices irrespective of their vendor and model. The quirk mechanism can be used to introduce special behavior for certain disk models and types.

Yes, this should definitely be a blacklist option. Although I'd obviously encourage the vendor to implement RSOC instead of working around this in the kernel.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering