ata: libata-eh: Retry non-NCQ commands when their sense data asks for it
Niklas Cassel
maintainerPATCH 1/1 ata: libata-eh: Retry non-NCQ commands when their sense data asks for it
When a failed command has valid sense data, ata_eh_analyze_tf() asks scsi_check_sense() whether the command should be retried, and sets ATA_QCFLAG_RETRY if it should. ata_eh_link_autopsy() then clears AC_ERR_DEV and AC_ERR_OTHER from qc->err_mask, relying on that decision.
For an NCQ command, qc->err_mask still has AC_ERR_NCQ, so ata_eh_finish() honors ATA_QCFLAG_RETRY. For a non-NCQ command, whose sense data comes from REQUEST SENSE DATA EXT, qc->err_mask is now zero, and ata_eh_finish() completes the command with scmd->retries set to scmd->allowed, without looking at ATA_QCFLAG_RETRY. Such a command is thus never retried, even when its sense data asks for a retry, e.g. a transient error reported as ABORTED COMMAND.
Make ata_eh_finish() honor ATA_QCFLAG_RETRY for commands with valid sense data. ata_eh_qc_retry() cannot be used for this: as qc->err_mask is zero, it increments scmd->allowed, so every retry would allow one more, and a persistent error would be retried forever. Instead, complete the command without touching scmd->allowed or scmd->retries, so that the SCSI midlayer retries it at most scmd->allowed times, like any other failed command.
---
Tested in QEMU: blkdebug fails a non-NCQ (PATA) read with EIO, and the disk reports ABORTED COMMAND sense data. Before this patch, the read was not retried (1 attempt); after it, a transient error is retried and the read succeeds, and a persistent error is retried 5 times. NCQ commands, and errors without sense data, were already retried and are unchanged.
--- drivers/ata/libata-eh.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/ata/libata-eh.c +14 -2
@@ -4080,8 +4080,20 @@ void ata_eh_finish(struct ata_port *ap)ata_eh_qc_complete (qc); } }else { -if (qc->flags &ATA_QCFLAG_SENSE_VALID || - qc->flags &ATA_QCFLAG_EH_SUCCESS_CMD ) { +if (qc->flags &ATA_QCFLAG_SENSE_VALID && + qc->flags &ATA_QCFLAG_RETRY ) { +/* +* The sense data asks for a retry, see +* ata_eh_analyze_tf(). ata_eh_link_autopsy() +* cleared qc->err_mask, so ata_eh_qc_retry() +* would increment scmd->allowed. Leave +* scmd->allowed alone, so that upper layer +* only retries the command if it has not +* already been retried too many times. +*/ +__ata_eh_qc_complete (qc); + }else if (qc->flags &ATA_QCFLAG_SENSE_VALID || + qc->flags &ATA_QCFLAG_EH_SUCCESS_CMD ) {ata_eh_qc_complete (qc); }else {/* feed zero TF to sense generation */
Signature · 1 line
2.56.0
Quoted 21 lines · Niklas Cassel
When a failed command has valid sense data,
ata_eh_analyze_tf()asksscsi_check_sense()whether the command should be retried, and setsATA_QCFLAG_RETRYif it should.ata_eh_link_autopsy()then clearsAC_ERR_DEVandAC_ERR_OTHERfromqc->err_mask, relying on that decision.For an NCQ command,
qc->err_maskstill hasAC_ERR_NCQ, soata_eh_finish()honorsATA_QCFLAG_RETRY. For a non-NCQ command, whose sense data comes from REQUEST SENSE DATA EXT,qc->err_maskis now zero, andata_eh_finish()completes the command withscmd->retriesset toscmd->allowed, without looking atATA_QCFLAG_RETRY. Such a command is thus never retried, even when its sense data asks for a retry, e.g. a transient error reported as ABORTED COMMAND.Make
ata_eh_finish()honorATA_QCFLAG_RETRYfor commands with valid sense data.ata_eh_qc_retry()cannot be used for this: asqc->err_maskis zero, it incrementsscmd->allowed, so every retry would allow one more, and a persistent error would be retried forever. Instead, complete the command without touchingscmd->allowedorscmd->retries, so that the SCSI midlayer retries it at mostscmd->allowedtimes, like any other failed command.
Quoted 2 lines
Fixes 3852e3738266 ("libata: evaluate SCSI sense code")Signed-off-by Niklas Cassel <[email protected]>
Thanks,
Igor
Quoted 13 lines · Niklas Cassel
When a failed command has valid sense data,
ata_eh_analyze_tf()asksscsi_check_sense()whether the command should be retried, and setsATA_QCFLAG_RETRYif it should.ata_eh_link_autopsy()then clearsAC_ERR_DEVandAC_ERR_OTHERfromqc->err_mask, relying on that decision.For an NCQ command,
qc->err_maskstill hasAC_ERR_NCQ, soata_eh_finish()honorsATA_QCFLAG_RETRY. For a non-NCQ command, whose sense data comes from REQUEST SENSE DATA EXT,qc->err_maskis now zero, andata_eh_finish()completes the command withscmd->retriesset toscmd->allowed, without looking atATA_QCFLAG_RETRY. Such a command is thus never retried, even when its sense data asks for a retry, e.g. a transient error reported as ABORTED COMMAND.
Quoted 1 line
[...]
Applied to libata/linux.git (for-7.4-fixes), thanks!
[1/1] ata: libata-eh: Retry non-NCQ commands when their sense data asks for it
https://git.kernel.org/libata/linux/c/597be410
Kind regards,
Niklas