public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi: sd: Keep the discard mode stable
@ 2024-06-14 16:03 Li Feng
  2024-06-17  6:17 ` Christoph Hellwig
  2024-06-17 16:26 ` Benjamin Block
  0 siblings, 2 replies; 10+ messages in thread
From: Li Feng @ 2024-06-14 16:03 UTC (permalink / raw)
  To: James E.J. Bottomley, open list, open list:SCSI SUBSYSTEM,
	Martin K. Petersen

There is a scenario where a large number of discard commands
are issued when the iscsi initiator connects to the target
and then performs a session rescan operation. There is a time
window, most of the commands are in UNMAP mode, and some
discard commands become WRITE SAME with UNMAP.

The discard mode has been negotiated during the SCSI probe. If
the mode is temporarily changed from UNMAP to WRITE SAME with
UNMAP, IO ERROR may occur because the target may not implement
WRITE SAME with UNMAP. Keep the discard mode stable to fix this
issue.

Signed-off-by: Li Feng <fengli@smartx.com>
---
 drivers/scsi/sd.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index f6c822c9cbd2..0165dc70a99b 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -2598,7 +2598,12 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp,
 		if (buffer[14] & 0x40) /* LBPRZ */
 			sdkp->lbprz = 1;
 
-		sd_config_discard(sdkp, SD_LBP_WS16);
+		/*
+		 * When the discard mode has been set to UNMAP, it should not be set to
+		 * WRITE SAME with UNMAP.
+		 */
+		if (!sdkp->max_unmap_blocks)
+			sd_config_discard(sdkp, SD_LBP_WS16);
 	}
 
 	sdkp->capacity = lba + 1;
-- 
2.45.2


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

end of thread, other threads:[~2024-06-19  7:02 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-14 16:03 [PATCH] scsi: sd: Keep the discard mode stable Li Feng
2024-06-17  6:17 ` Christoph Hellwig
2024-06-17  9:03   ` Li Feng
2024-06-18  6:41     ` Christoph Hellwig
2024-06-19  6:56       ` Li Feng
2024-06-19  7:02         ` Christoph Hellwig
2024-06-17 16:26 ` Benjamin Block
2024-06-18  3:06   ` Li Feng
2024-06-18  8:47     ` Benjamin Block
2024-06-19  6:58       ` Li Feng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox