scsi: core: Allow libata to complete successful commands via EH
authorNiklas Cassel <niklas.cassel@wdc.com>
Thu, 11 May 2023 01:13:37 +0000 (03:13 +0200)
committerMartin K. Petersen <martin.petersen@oracle.com>
Mon, 22 May 2023 21:05:18 +0000 (17:05 -0400)
In SCSI, we get the sense data as part of the completion, for ATA however,
we need to fetch the sense data as an extra step. For an aborted ATA
command the sense data is fetched via libata's ->eh_strategy_handler().

For Command Duration Limits policy 0xD:

  The device shall complete the command without error with the additional
  sense code set to DATA CURRENTLY UNAVAILABLE.

In order to handle this policy in libata, we intend to send a successful
command via SCSI EH, and let libata's ->eh_strategy_handler() fetch the
sense data for the good command. This is similar to how we handle an
aborted ATA command, just that we need to read the Successful NCQ Commands
log instead of the NCQ Command Error log.

When we get a SATA completion with successful commands, ATA_SENSE will be
set, indicating that some commands in the completion have sense data.

The sense_valid bitmask in the Sense Data for Successful NCQ Commands log
will inform exactly which commands that had sense data, which might be a
subset of all the commands that was completed in the same completion. (Yet
all will have ATA_SENSE set, since the status is per completion.)

The successful commands that have e.g. a "DATA CURRENTLY UNAVAILABLE" sense
data will have a SCSI ML byte set, so scsi_eh_flush_done_q() will not set
the scmd->result to DID_TIME_OUT for these commands. However, the
successful commands that did not have sense data, must not get their result
marked as DID_TIME_OUT by SCSI EH.

Add a new flag SCMD_FORCE_EH_SUCCESS, which tells SCSI EH to not mark a
command as DID_TIME_OUT, even if it has scmd->result == SAM_STAT_GOOD.

This will be used by libata in a subsequent commit.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com>
Link: https://lore.kernel.org/r/20230511011356.227789-5-nks@flawful.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/scsi_error.c
include/scsi/scsi_cmnd.h

index 3ec8bfd4090f9eaa7bee047e9664597152a19cbf..8b7d227bfe1c6799c53d6cf7178c2fb6873f394e 100644 (file)
@@ -2165,7 +2165,8 @@ void scsi_eh_flush_done_q(struct list_head *done_q)
                         * scsi_eh_get_sense), scmd->result is already
                         * set, do not set DID_TIME_OUT.
                         */
-                       if (!scmd->result)
+                       if (!scmd->result &&
+                           !(scmd->flags & SCMD_FORCE_EH_SUCCESS))
                                scmd->result |= (DID_TIME_OUT << 16);
                        SCSI_LOG_ERROR_RECOVERY(3,
                                scmd_printk(KERN_INFO, scmd,
index c2cb5f69635c6f5fbe6a930109c66f0f541aa01c..526def14e7fb755913b58be7ec97e5629941929f 100644 (file)
@@ -52,6 +52,11 @@ struct scsi_pointer {
 #define SCMD_TAGGED            (1 << 0)
 #define SCMD_INITIALIZED       (1 << 1)
 #define SCMD_LAST              (1 << 2)
+/*
+ * libata uses SCSI EH to fetch sense data for successful commands.
+ * SCSI EH should not overwrite scmd->result when SCMD_FORCE_EH_SUCCESS is set.
+ */
+#define SCMD_FORCE_EH_SUCCESS  (1 << 3)
 #define SCMD_FAIL_IF_RECOVERING        (1 << 4)
 /* flags preserved across unprep / reprep */
 #define SCMD_PRESERVED_FLAGS   (SCMD_INITIALIZED | SCMD_FAIL_IF_RECOVERING)