Skip to contentSkip to conversation

scsi discard fix

PATCH Applied Li Feng 3 participants 8 messages Jul 18, 2024 – Aug 3, 2024 SCSI

lore
Share & tools
lore

Li Feng

author
#0 lore raw

v3 cover scsi discard fix

Hi Jens,

These two patches have been reviewed but have not been merged into linux-next. Can they be merged into 6.11?

Thanks,

v3:
- rebased to the latest linux-next branch;
- put the separate patch2 in this patchset;
- add reviewed-by tag.

v2:
- rewrite the patch.

Haoqian He (1):
scsi: sd: remove some redundant initialization code

Li Feng (1):
scsi: sd: Keep the discard mode stable

 drivers/scsi/sd.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
Signature · 1 line
2.45.2
author
#1 lore raw

PATCH v3 1/2 scsi: sd: Keep the discard mode stable

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.

---
 drivers/scsi/sd.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/scsi/sd.c +2 -4
index 8bb3a3611851..c180427e2c98 100644
@@ -2711,8 +2711,6 @@ 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, lim, SD_LBP_WS16);
 	}
 
 	sdkp->capacity = lba + 1;
@@ -3365,8 +3363,6 @@ static void sd_read_block_limits(struct scsi_disk *sdkp,
 			sdkp->unmap_alignment =
 				get_unaligned_be32(&vpd->data[32]) & ~(1 << 31);
 
-		sd_config_discard(sdkp, lim, sd_discard_mode(sdkp));
-
 config_atomic:
 		sdkp->max_atomic = get_unaligned_be32(&vpd->data[44]);
 		sdkp->atomic_alignment = get_unaligned_be32(&vpd->data[48]);
@@ -3756,6 +3752,8 @@ static int sd_revalidate_disk(struct gendisk *disk)
 			sd_read_cpr(sdkp);
 		}
 
+		sd_config_discard(sdkp, &lim, sd_discard_mode(sdkp));
+
 		sd_print_capacity(sdkp, old_capacity);
 
 		sd_read_write_protect_flag(sdkp, buffer);
Signature · 1 line
2.45.2
author
#2 lore raw

PATCH v3 2/2 scsi: sd: remove some redundant initialization code

In reply to Li Feng

From: Haoqian He <[email protected]>

Since the memory allocated by kzalloc for sdkp has been initialized to 0, the code that initializes some sdkp fields to 0 is no longer needed.

---
 drivers/scsi/sd.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/scsi/sd.c +0 -7
index c180427e2c98..3921b8fd71d1 100644
@@ -3953,7 +3953,6 @@ static int sd_probe(struct device *dev)
 	sdkp->disk = gd;
 	sdkp->index = index;
 	sdkp->max_retries = SD_MAX_RETRIES;
-	atomic_set(&sdkp->openers, 0);
 	atomic_set(&sdkp->device->ioerr_cnt, 0);
 
 	if (!sdp->request_queue->rq_timeout) {
@@ -3986,13 +3985,7 @@ static int sd_probe(struct device *dev)
 
 	/* defaults, until the device tells us otherwise */
 	sdp->sector_size = 512;
-	sdkp->capacity = 0;
 	sdkp->media_present = 1;
-	sdkp->write_prot = 0;
-	sdkp->cache_override = 0;
-	sdkp->WCE = 0;
-	sdkp->RCD = 0;
-	sdkp->ATO = 0;
 	sdkp->first_scan = 1;
 	sdkp->max_medium_access_timeouts = SD_MAX_MEDIUM_TIMEOUTS;
 
Signature · 1 line
2.45.2
#3 lore raw
In reply to Li Feng
Quoted 4 lines · Li Feng

Hi Jens,

These two patches have been reviewed but have not been merged into linux-next. Can they be merged into 6.11?

They can, but is there some dependency that means they should go through the block tree? Would seem more logical that Martin picked them up.

Signature · 1 line
Jens Axboe
#4 lore raw

Jens,

Quoted 3 lines

They can, but is there some dependency that means they should go through the block tree? Would seem more logical that Martin picked them up.

I'll get to them. Busy with a couple of hardware-related regressions right now.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#5 lore raw
Quoted 9 lines · Martin K. Petersen

Jens,

Quoted 3 lines

They can, but is there some dependency that means they should go through the block tree? Would seem more logical that Martin picked them up.

I'll get to them. Busy with a couple of hardware-related regressions right now.

All good, just wanted to ensure they weren't waiting on me, as the cover letter seemed to indicate.

Thanks!

Signature · 1 line
Jens Axboe
author
#6 lore raw

Hi Jens and Martin,

Thank you.
I was worried that you were too busy and forgot about these two patches.

Quoted 22 lines

2024年7月23日 08:37,Jens Axboe <[email protected]> 写道:

Quoted 9 lines · Martin K. Petersen

Jens,

Quoted 3 lines

They can, but is there some dependency that means they should go through the block tree? Would seem more logical that Martin picked them up.

I'll get to them. Busy with a couple of hardware-related regressions right now.

All good, just wanted to ensure they weren't waiting on me, as the cover letter seemed to indicate.

Thanks!

Signature · 1 line
Jens Axboe
#7 lore raw
In reply to Li Feng
Quoted 11 lines · Li Feng

These two patches have been reviewed but have not been merged into linux-next. Can they be merged into 6.11?

Thanks,

v3:
- rebased to the latest linux-next branch;
- put the separate patch2 in this patchset;
- add reviewed-by tag.

[...]

Applied to 6.11/scsi-fixes, thanks!

[1/2] scsi: sd: Keep the discard mode stable

      https://git.kernel.org/mkp/scsi/c/f874d7210d88
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering