All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sd: Limit WRITE SAME / WRITE SAME(16) w/UNMAP length for certain devices
@ 2017-09-19 16:14 Ewan D. Milne
  2017-09-19 17:32 ` Kuzeja, William
  2017-09-26  1:46 ` Martin K. Petersen
  0 siblings, 2 replies; 13+ messages in thread
From: Ewan D. Milne @ 2017-09-19 16:14 UTC (permalink / raw)
  To: linux-scsi

From: "Ewan D. Milne" <emilne@redhat.com>

Some devices do not support a WRITE SAME / WRITE SAME(16) with the UNMAP
bit set up to the length specified in the MAXIMUM WRITE SAME LENGTH field
in the block limits VPD page (or, the field is zero, indicating there is
no limit).  Limit the length by the MAXIMUM UNMAP LBA COUNT value.
Otherwise the command might be rejected.

Signed-off-by: Ewan D. Milne <emilne@redhat.com>
---
 drivers/scsi/sd.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 6549e5c..fa07ac2 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -693,6 +693,7 @@ static void sd_config_discard(struct scsi_disk *sdkp, unsigned int mode)
 	struct request_queue *q = sdkp->disk->queue;
 	unsigned int logical_block_size = sdkp->device->sector_size;
 	unsigned int max_blocks = 0;
+	u32 max_ws_blocks = sdkp->max_ws_blocks;
 
 	q->limits.discard_alignment =
 		sdkp->unmap_alignment * logical_block_size;
@@ -701,6 +702,13 @@ static void sd_config_discard(struct scsi_disk *sdkp, unsigned int mode)
 		    sdkp->unmap_granularity * logical_block_size);
 	sdkp->provisioning_mode = mode;
 
+	/*
+	 * Some devices limit WRITE SAME / WRITE SAME(16) w/UNMAP
+	 * by MAXIMUM UNMAP LBA COUNT instead of MAXIMUM WRITE SAME LENGTH.
+	 * Use the smaller of the two values to avoid ILLEGAL REQUEST errors.
+	 */
+	max_ws_blocks = min_not_zero(max_ws_blocks, sdkp->max_unmap_blocks);
+
 	switch (mode) {
 
 	case SD_LBP_FULL:
@@ -715,17 +723,17 @@ static void sd_config_discard(struct scsi_disk *sdkp, unsigned int mode)
 		break;
 
 	case SD_LBP_WS16:
-		max_blocks = min_not_zero(sdkp->max_ws_blocks,
+		max_blocks = min_not_zero(max_ws_blocks,
 					  (u32)SD_MAX_WS16_BLOCKS);
 		break;
 
 	case SD_LBP_WS10:
-		max_blocks = min_not_zero(sdkp->max_ws_blocks,
+		max_blocks = min_not_zero(max_ws_blocks,
 					  (u32)SD_MAX_WS10_BLOCKS);
 		break;
 
 	case SD_LBP_ZERO:
-		max_blocks = min_not_zero(sdkp->max_ws_blocks,
+		max_blocks = min_not_zero(max_ws_blocks,
 					  (u32)SD_MAX_WS10_BLOCKS);
 		break;
 	}
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2017-10-17 14:43 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-19 16:14 [PATCH] sd: Limit WRITE SAME / WRITE SAME(16) w/UNMAP length for certain devices Ewan D. Milne
2017-09-19 17:32 ` Kuzeja, William
2017-09-26  1:46 ` Martin K. Petersen
2017-09-27 16:27   ` Ewan D. Milne
2017-09-27 16:42     ` Knight, Frederick
2017-09-28  1:34     ` Martin K. Petersen
2017-09-28  1:35     ` [PATCH] scsi: sd: Implement blacklist option for WRITE SAME w/ UNMAP Martin K. Petersen
2017-09-28 15:46       ` Ewan D. Milne
2017-09-29 10:02       ` Laurence Oberman
2017-09-29 13:21         ` Martin K. Petersen
2017-09-29 14:01           ` Laurence Oberman
2017-10-17 14:26             ` Laurence Oberman
2017-10-17 14:43               ` Laurence Oberman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.