Skip to content

Commit f874d72

Browse files
Li Fengmartinkpetersen
authored andcommitted
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, an I/O 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> Link: https://lore.kernel.org/r/20240718080751.313102-2-fengli@smartx.com Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent ffed586 commit f874d72

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

drivers/scsi/sd.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2711,8 +2711,6 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp,
27112711

27122712
if (buffer[14] & 0x40) /* LBPRZ */
27132713
sdkp->lbprz = 1;
2714-
2715-
sd_config_discard(sdkp, lim, SD_LBP_WS16);
27162714
}
27172715

27182716
sdkp->capacity = lba + 1;
@@ -3365,8 +3363,6 @@ static void sd_read_block_limits(struct scsi_disk *sdkp,
33653363
sdkp->unmap_alignment =
33663364
get_unaligned_be32(&vpd->data[32]) & ~(1 << 31);
33673365

3368-
sd_config_discard(sdkp, lim, sd_discard_mode(sdkp));
3369-
33703366
config_atomic:
33713367
sdkp->max_atomic = get_unaligned_be32(&vpd->data[44]);
33723368
sdkp->atomic_alignment = get_unaligned_be32(&vpd->data[48]);
@@ -3755,6 +3751,8 @@ static int sd_revalidate_disk(struct gendisk *disk)
37553751
sd_zbc_read_zones(sdkp, &lim, buffer);
37563752
}
37573753

3754+
sd_config_discard(sdkp, &lim, sd_discard_mode(sdkp));
3755+
37583756
sd_print_capacity(sdkp, old_capacity);
37593757

37603758
sd_read_write_protect_flag(sdkp, buffer);

0 commit comments

Comments
 (0)