aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin K. Petersen <martin.petersen@oracle.com>2017-09-27 21:35:12 -0400
committerMartin K. Petersen <martin.petersen@oracle.com>2017-10-02 22:16:18 -0400
commit28a0bc4120d38a394499382ba21d6965a67a3703 (patch)
treed9cae3be601b655420b9c765841e310d102a51d8
parentd0b7a9095c0730b92a0a2eecaba2e6b77ed87339 (diff)
scsi: sd: Implement blacklist option for WRITE SAME w/ UNMAP
SBC-4 states: "A MAXIMUM UNMAP LBA COUNT field set to a non-zero value indicates the maximum number of LBAs that may be unmapped by an UNMAP command" "A MAXIMUM WRITE SAME LENGTH field set to a non-zero value indicates the maximum number of contiguous logical blocks that the device server allows to be unmapped or written in a single WRITE SAME command." Despite the spec being clear on the topic, some devices incorrectly expect WRITE SAME commands with the UNMAP bit set to be limited to the value reported in MAXIMUM UNMAP LBA COUNT in the Block Limits VPD. Implement a blacklist option that can be used to accommodate devices with this behavior. Cc: <stable@vger.kernel.org> Reported-by: Bill Kuzeja <William.Kuzeja@stratus.com> Reported-by: Ewan D. Milne <emilne@redhat.com> Reviewed-by: Ewan D. Milne <emilne@redhat.com> Tested-by: Laurence Oberman <loberman@redhat.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
-rw-r--r--drivers/scsi/scsi_scan.c3
-rw-r--r--drivers/scsi/sd.c16
-rw-r--r--include/scsi/scsi_device.h1
-rw-r--r--include/scsi/scsi_devinfo.h1
4 files changed, 17 insertions, 4 deletions
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index e7818afeda2b..15590a063ad9 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -956,6 +956,9 @@ static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result,
956 if (*bflags & BLIST_NO_DIF) 956 if (*bflags & BLIST_NO_DIF)
957 sdev->no_dif = 1; 957 sdev->no_dif = 1;
958 958
959 if (*bflags & BLIST_UNMAP_LIMIT_WS)
960 sdev->unmap_limit_for_ws = 1;
961
959 sdev->eh_timeout = SCSI_DEFAULT_EH_TIMEOUT; 962 sdev->eh_timeout = SCSI_DEFAULT_EH_TIMEOUT;
960 963
961 if (*bflags & BLIST_TRY_VPD_PAGES) 964 if (*bflags & BLIST_TRY_VPD_PAGES)
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index fb9f8b5f4673..3d26a729825c 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -715,13 +715,21 @@ static void sd_config_discard(struct scsi_disk *sdkp, unsigned int mode)
715 break; 715 break;
716 716
717 case SD_LBP_WS16: 717 case SD_LBP_WS16:
718 max_blocks = min_not_zero(sdkp->max_ws_blocks, 718 if (sdkp->device->unmap_limit_for_ws)
719 (u32)SD_MAX_WS16_BLOCKS); 719 max_blocks = sdkp->max_unmap_blocks;
720 else
721 max_blocks = sdkp->max_ws_blocks;
722
723 max_blocks = min_not_zero(max_blocks, (u32)SD_MAX_WS16_BLOCKS);
720 break; 724 break;
721 725
722 case SD_LBP_WS10: 726 case SD_LBP_WS10:
723 max_blocks = min_not_zero(sdkp->max_ws_blocks, 727 if (sdkp->device->unmap_limit_for_ws)
724 (u32)SD_MAX_WS10_BLOCKS); 728 max_blocks = sdkp->max_unmap_blocks;
729 else
730 max_blocks = sdkp->max_ws_blocks;
731
732 max_blocks = min_not_zero(max_blocks, (u32)SD_MAX_WS10_BLOCKS);
725 break; 733 break;
726 734
727 case SD_LBP_ZERO: 735 case SD_LBP_ZERO:
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index 82e93ee94708..67c5a9f223f7 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -192,6 +192,7 @@ struct scsi_device {
192 unsigned no_dif:1; /* T10 PI (DIF) should be disabled */ 192 unsigned no_dif:1; /* T10 PI (DIF) should be disabled */
193 unsigned broken_fua:1; /* Don't set FUA bit */ 193 unsigned broken_fua:1; /* Don't set FUA bit */
194 unsigned lun_in_cdb:1; /* Store LUN bits in CDB[1] */ 194 unsigned lun_in_cdb:1; /* Store LUN bits in CDB[1] */
195 unsigned unmap_limit_for_ws:1; /* Use the UNMAP limit for WRITE SAME */
195 196
196 atomic_t disk_events_disable_depth; /* disable depth for disk events */ 197 atomic_t disk_events_disable_depth; /* disable depth for disk events */
197 198
diff --git a/include/scsi/scsi_devinfo.h b/include/scsi/scsi_devinfo.h
index 9592570e092a..36b03013d629 100644
--- a/include/scsi/scsi_devinfo.h
+++ b/include/scsi/scsi_devinfo.h
@@ -29,5 +29,6 @@
29#define BLIST_TRY_VPD_PAGES 0x10000000 /* Attempt to read VPD pages */ 29#define BLIST_TRY_VPD_PAGES 0x10000000 /* Attempt to read VPD pages */
30#define BLIST_NO_RSOC 0x20000000 /* don't try to issue RSOC */ 30#define BLIST_NO_RSOC 0x20000000 /* don't try to issue RSOC */
31#define BLIST_MAX_1024 0x40000000 /* maximum 1024 sector cdb length */ 31#define BLIST_MAX_1024 0x40000000 /* maximum 1024 sector cdb length */
32#define BLIST_UNMAP_LIMIT_WS 0x80000000 /* Use UNMAP limit for WRITE SAME */
32 33
33#endif 34#endif