Skip to content

Commit 1830532

Browse files
mikechristiemartinkpetersen
authored andcommitted
scsi: sd: Have midlayer retry sd_sync_cache() errors
This has sd_sync_cache() have the SCSI midlayer retry errors instead of driving them itself. 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 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. Signed-off-by: Mike Christie <michael.christie@oracle.com> Link: https://lore.kernel.org/r/20240123002220.129141-10-michael.christie@oracle.com Acked-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 5dbf104 commit 1830532

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

drivers/scsi/sd.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,36 +1645,35 @@ static unsigned int sd_check_events(struct gendisk *disk, unsigned int clearing)
16451645

16461646
static int sd_sync_cache(struct scsi_disk *sdkp)
16471647
{
1648-
int retries, res;
1648+
int res;
16491649
struct scsi_device *sdp = sdkp->device;
16501650
const int timeout = sdp->request_queue->rq_timeout
16511651
* SD_FLUSH_TIMEOUT_MULTIPLIER;
1652+
/* Leave the rest of the command zero to indicate flush everything. */
1653+
const unsigned char cmd[16] = { sdp->use_16_for_sync ?
1654+
SYNCHRONIZE_CACHE_16 : SYNCHRONIZE_CACHE };
16521655
struct scsi_sense_hdr sshdr;
1656+
struct scsi_failure failure_defs[] = {
1657+
{
1658+
.allowed = 3,
1659+
.result = SCMD_FAILURE_RESULT_ANY,
1660+
},
1661+
{}
1662+
};
1663+
struct scsi_failures failures = {
1664+
.failure_definitions = failure_defs,
1665+
};
16531666
const struct scsi_exec_args exec_args = {
16541667
.req_flags = BLK_MQ_REQ_PM,
16551668
.sshdr = &sshdr,
1669+
.failures = &failures,
16561670
};
16571671

16581672
if (!scsi_device_online(sdp))
16591673
return -ENODEV;
16601674

1661-
for (retries = 3; retries > 0; --retries) {
1662-
unsigned char cmd[16] = { 0 };
1663-
1664-
if (sdp->use_16_for_sync)
1665-
cmd[0] = SYNCHRONIZE_CACHE_16;
1666-
else
1667-
cmd[0] = SYNCHRONIZE_CACHE;
1668-
/*
1669-
* Leave the rest of the command zero to indicate
1670-
* flush everything.
1671-
*/
1672-
res = scsi_execute_cmd(sdp, cmd, REQ_OP_DRV_IN, NULL, 0,
1673-
timeout, sdkp->max_retries, &exec_args);
1674-
if (res == 0)
1675-
break;
1676-
}
1677-
1675+
res = scsi_execute_cmd(sdp, cmd, REQ_OP_DRV_IN, NULL, 0, timeout,
1676+
sdkp->max_retries, &exec_args);
16781677
if (res) {
16791678
sd_print_result(sdkp, "Synchronize Cache(10) failed", res);
16801679

0 commit comments

Comments
 (0)