Skip to content

Commit 0f11328

Browse files
mikechristiemartinkpetersen
authored andcommitted
scsi: sd: Have midlayer retry read_capacity_10() errors
This has read_capacity_10() have the SCSI midlayer retry errors instead of driving them itself. There are 2 behavior changes with this patch: 1. There is one behavior change where we no longer retry when scsi_execute_cmd() returns < 0, but we should be ok. We don't need to retry for failures like the queue being removed, and for the case where there are no tags/reqs since the block layer waits/retries for us. For possible memory allocation failures from blk_rq_map_kern() we use GFP_NOIO, so retrying will probably not help. 2. For the specific UAs we checked for and retried, we would get READ_CAPACITY_RETRIES_ON_RESET retries plus whatever retries were left from the main loop's retries. Each UA now gets READ_CAPACITY_RETRIES_ON_RESET retries, and the other errors get up to 3 retries. This is most likely ok, because READ_CAPACITY_RETRIES_ON_RESET is already 10 and is not based on anything specific like a spec or device, so the extra 3 we got from the main loop was probably just an accident and is not going to help. Signed-off-by: Mike Christie <michael.christie@oracle.com> Link: https://lore.kernel.org/r/20240123002220.129141-16-michael.christie@oracle.com Acked-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent eea6ef3 commit 0f11328

File tree

1 file changed

+39
-23
lines changed

1 file changed

+39
-23
lines changed

drivers/scsi/sd.c

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2588,42 +2588,58 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp,
25882588
static int read_capacity_10(struct scsi_disk *sdkp, struct scsi_device *sdp,
25892589
unsigned char *buffer)
25902590
{
2591-
unsigned char cmd[16];
2591+
static const u8 cmd[10] = { READ_CAPACITY };
25922592
struct scsi_sense_hdr sshdr;
2593+
struct scsi_failure failure_defs[] = {
2594+
/* Do not retry Medium Not Present */
2595+
{
2596+
.sense = UNIT_ATTENTION,
2597+
.asc = 0x3A,
2598+
.result = SAM_STAT_CHECK_CONDITION,
2599+
},
2600+
{
2601+
.sense = NOT_READY,
2602+
.asc = 0x3A,
2603+
.result = SAM_STAT_CHECK_CONDITION,
2604+
},
2605+
/* Device reset might occur several times so retry a lot */
2606+
{
2607+
.sense = UNIT_ATTENTION,
2608+
.asc = 0x29,
2609+
.allowed = READ_CAPACITY_RETRIES_ON_RESET,
2610+
.result = SAM_STAT_CHECK_CONDITION,
2611+
},
2612+
/* Any other error not listed above retry 3 times */
2613+
{
2614+
.result = SCMD_FAILURE_RESULT_ANY,
2615+
.allowed = 3,
2616+
},
2617+
{}
2618+
};
2619+
struct scsi_failures failures = {
2620+
.failure_definitions = failure_defs,
2621+
};
25932622
const struct scsi_exec_args exec_args = {
25942623
.sshdr = &sshdr,
2624+
.failures = &failures,
25952625
};
25962626
int sense_valid = 0;
25972627
int the_result;
2598-
int retries = 3, reset_retries = READ_CAPACITY_RETRIES_ON_RESET;
25992628
sector_t lba;
26002629
unsigned sector_size;
26012630

2602-
do {
2603-
cmd[0] = READ_CAPACITY;
2604-
memset(&cmd[1], 0, 9);
2605-
memset(buffer, 0, 8);
2631+
memset(buffer, 0, 8);
26062632

2607-
the_result = scsi_execute_cmd(sdp, cmd, REQ_OP_DRV_IN, buffer,
2608-
8, SD_TIMEOUT, sdkp->max_retries,
2609-
&exec_args);
2633+
the_result = scsi_execute_cmd(sdp, cmd, REQ_OP_DRV_IN, buffer,
2634+
8, SD_TIMEOUT, sdkp->max_retries,
2635+
&exec_args);
2636+
2637+
if (the_result > 0) {
2638+
sense_valid = scsi_sense_valid(&sshdr);
26102639

26112640
if (media_not_present(sdkp, &sshdr))
26122641
return -ENODEV;
2613-
2614-
if (the_result > 0) {
2615-
sense_valid = scsi_sense_valid(&sshdr);
2616-
if (sense_valid &&
2617-
sshdr.sense_key == UNIT_ATTENTION &&
2618-
sshdr.asc == 0x29 && sshdr.ascq == 0x00)
2619-
/* Device reset might occur several times,
2620-
* give it one more chance */
2621-
if (--reset_retries > 0)
2622-
continue;
2623-
}
2624-
retries--;
2625-
2626-
} while (the_result && retries);
2642+
}
26272643

26282644
if (the_result) {
26292645
sd_print_result(sdkp, "Read Capacity(10) failed", the_result);

0 commit comments

Comments
 (0)