Skip to contentSkip to conversation

scsi: add a new flag to set whether SCSI disks support WRITE_SAME_16 by default

PATCH In review AlexChen 3 participants 6 messages Feb 1, 2020 – Feb 26, 2020 1 message not in the archive SCSI

lore
Share & tools
lore

AlexChen

author
#1 lore raw

PATCH v2 1/1 scsi: add a new flag to set whether SCSI disks support WRITE_SAME_16 by default

In reply to a message not in the archive

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 support, and only WRITE_SAME_16 is supported, not WRITE_SAME_10. Therefore, we need to provide a new flag for these storage devices. When initializing these devices, we will no longer query for support for WRITE_SAME_16 in the sd_read_write_same(), but set these SCSI disks to support WRITE_SAME_16 by default. In that way, we can add 'vendor:product:flag' to the module parameter 'dev_flags' for these storage devices.

---
 drivers/scsi/sd.c           | 4 +++-
 include/scsi/scsi_devinfo.h | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)
drivers/scsi/sd.c +3 -1
index 4f7e7b607..a208ba5b5 100644
@@ -68,6 +68,7 @@
 #include <scsi/scsi_host.h>
 #include <scsi/scsi_ioctl.h>
 #include <scsi/scsicam.h>
+#include <scsi/scsi_devinfo.h>
 
 #include "sd.h"
 #include "scsi_priv.h"
@@ -3014,7 +3015,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 ||
+			sdev->sdev_bflags & BLIST_SUPPORT_WS16)
 		sdkp->ws16 = 1;
 
 	if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, WRITE_SAME) == 1)
include/scsi/scsi_devinfo.h +3 -1
index 3fdb322d4..da70d4795 100644
@@ -67,8 +67,10 @@
 #define BLIST_RETRY_ITF		((__force blist_flags_t)(1ULL << 32))
 /* Always retry ABORTED_COMMAND with ASC 0xc1 */
 #define BLIST_RETRY_ASC_C1	((__force blist_flags_t)(1ULL << 33))
+/* support for write_same_16, no need to query */
+#define BLIST_SUPPORT_WS16      ((__force blist_flags_t)(1ULL << 34))
 
-#define __BLIST_LAST_USED BLIST_RETRY_ASC_C1
+#define __BLIST_LAST_USED BLIST_SUPPORT_WS16
 
 #define __BLIST_HIGH_UNUSED (~(__BLIST_LAST_USED | \
 			       (__force blist_flags_t) \
Signature · 1 line
2.19.1
#2 lore raw

Hi Alex,

Quoted 4 lines

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.

Your proposed code change is fine and to the point. However, I'd like to understand why you are adding a workaround to the kernel instead of fixing the affected device?

Implementing support for either WRITE SAME(10) or REPORT SUPPORTED OPERATION CODES is easy. And the latter in particular is beneficial for discovering several other SCSI protocol features. It's a good command to support in general.

Also, we generally don't add features to the kernel without any users. So if you add a blacklist flag, I would expect to see a set of device strings to be added to scsi_devinfo.c.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
author
#3 lore raw

Hi Martin,

Thanks for your reply.

Quoted 5 lines
Quoted 4 lines

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.

Quoted 9 lines

Your proposed code change is fine and to the point. However, I'd like to understand why you are adding a workaround to the kernel instead of fixing the affected device?

Implementing support for either WRITE SAME(10) or REPORT SUPPORTED OPERATION CODES is easy. And the latter in particular is beneficial for discovering several other SCSI protocol features. It's a good command to support in general.

From a maintenance perspective, I think the old storage device which does not support WRITE SAME query interface can be easily supported by adding a workaround to the kernel, instead of waiting for the storage device to implement the query interface.

Quoted 3 lines

Also, we generally don't add features to the kernel without any users. So if you add a blacklist flag, I would expect to see a set of device strings to be added to scsi_devinfo.c.

Through my test, I found that HUAWEI's storage devices do not provide queries for WRITE_SAME_16 support.
If the lists of such devices is written into the kernel code, will it be incomplete and difficult to maintain? On the other hand, It would be more flexible if we provided the module parameter 'dev_flags' to set.

Thanks
Alex

author
#4 lore raw

Hi Martin,

Are there any other opinions about this patch? If so, I can make corresponding modifications.

Thanks
Alex

Quoted 37 lines · AlexChen

Hi Martin,

Thanks for your reply.

Quoted 9 lines
Quoted 4 lines

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.

Your proposed code change is fine and to the point. However, I'd like to understand why you are adding a workaround to the kernel instead of fixing the affected device?

Quoted 7 lines

Implementing support for either WRITE SAME(10) or REPORT SUPPORTED OPERATION CODES is easy. And the latter in particular is beneficial for discovering several other SCSI protocol features. It's a good command to support in general.

From a maintenance perspective, I think the old storage device which does

not support WRITE SAME query interface can be easily supported by adding a workaround to the kernel, instead of waiting for the storage device to implement the query interface.

Quoted 3 lines

Also, we generally don't add features to the kernel without any users. So if you add a blacklist flag, I would expect to see a set of device strings to be added to scsi_devinfo.c.

Through my test, I found that HUAWEI's storage devices do not provide queries for WRITE_SAME_16 support.
If the lists of such devices is written into the kernel code, will it be incomplete and difficult to maintain? On the other hand, It would be more flexible if we provided the module parameter 'dev_flags' to set.

Thanks
Alex

#5 lore raw
In reply to AlexChen
Quoted 11 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.

Quoted 8 lines

Currently, some storage devices do not provide queries for WRITE_SAME_16 support, and only WRITE_SAME_16 is supported, not WRITE_SAME_10. Therefore, we need to provide a new flag for these storage devices. When initializing these devices, we will no longer query for support for WRITE_SAME_16 in the sd_read_write_same(), but set these SCSI disks to support WRITE_SAME_16 by default. In that way, we can add 'vendor:product:flag' to the module parameter 'dev_flags' for these storage devices.

Please send this along with the patch that actually sets the flag somewhere..

author
#6 lore raw

Hi Christoph,

Thanks for your reply.

Quoted 21 lines · Christoph Hellwig
Quoted 11 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.

Quoted 8 lines

Currently, some storage devices do not provide queries for WRITE_SAME_16 support, and only WRITE_SAME_16 is supported, not WRITE_SAME_10. Therefore, we need to provide a new flag for these storage devices. When initializing these devices, we will no longer query for support for WRITE_SAME_16 in the sd_read_write_same(), but set these SCSI disks to support WRITE_SAME_16 by default. In that way, we can add 'vendor:product:flag' to the module parameter 'dev_flags' for these storage devices.

Quoted 3 lines

Please send this along with the patch that actually sets the flag somewhere..

If we want Huawei storage device to support WRITE_SAME_16 by default, we can add module parameter dev_flags='HUAWEI::‭17179869184‬' to the kernel command line parameters.
Do you mean I need to add these to this patch description?

Thanks
Alex