From: Mike Christie <michael.christie@oracle.com>
To: kbusch@kernel.org, axboe@fb.com, hch@lst.de, sagi@grimberg.me,
martin.petersen@oracle.com, jejb@linux.ibm.com,
linux-scsi@vger.kernel.org, linux-nvme@lists.infradead.org,
linux-block@vger.kernel.org
Cc: Mike Christie <michael.christie@oracle.com>
Subject: [PATCH 2/3] scsi: Convert SCSI errors to PR_STS errors
Date: Tue, 8 Nov 2022 21:11:05 -0600 [thread overview]
Message-ID: <20221109031106.201324-3-michael.christie@oracle.com> (raw)
In-Reply-To: <20221109031106.201324-1-michael.christie@oracle.com>
This converts the SCSI errors we commonly see during PR handling to PT_STS
errors, so pr_ops callers can handle scsi and nvme errors without knowing
the device types.
Signed-off-by: Mike Christie <michael.christie@oracle.com>
---
drivers/scsi/sd.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 42 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index eb76ba055021..667477d1e4b7 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1701,6 +1701,44 @@ static char sd_pr_type(enum pr_type type)
}
};
+static enum pr_status sd_scsi_to_block_pr_err(struct scsi_sense_hdr *sshdr,
+ int result)
+{
+ enum pr_status sts = PR_STS_IOERR;
+
+ switch host_byte(result) {
+ case DID_TRANSPORT_MARGINAL:
+ case DID_TRANSPORT_DISRUPTED:
+ case DID_BUS_BUSY:
+ sts = PR_STS_RETRY_PATH_FAILURE;
+ goto done;
+ case DID_NO_CONNECT:
+ sts = PR_STS_PATH_FAILED;
+ goto done;
+ case DID_TRANSPORT_FAILFAST:
+ sts = PR_STS_PATH_FAST_FAILED;
+ goto done;
+ }
+
+ switch (__get_status_byte(result)) {
+ case SAM_STAT_RESERVATION_CONFLICT:
+ sts = PR_STS_RESERVATION_CONFLICT;
+ goto done;
+ case SAM_STAT_CHECK_CONDITION:
+ if (!scsi_sense_valid(sshdr))
+ goto done;
+
+ if (sshdr->sense_key == ILLEGAL_REQUEST &&
+ (sshdr->asc == 0x26 || sshdr->asc == 0x24)) {
+ sts = PR_STS_OP_INVALID;
+ goto done;
+ }
+ }
+
+done:
+ return sts;
+}
+
static int sd_pr_command(struct block_device *bdev, u8 sa,
u64 key, u64 sa_key, u8 type, u8 flags)
{
@@ -1729,7 +1767,10 @@ static int sd_pr_command(struct block_device *bdev, u8 sa,
scsi_print_sense_hdr(sdev, NULL, &sshdr);
}
- return result;
+ if (result <= 0)
+ return result;
+
+ return sd_scsi_to_block_pr_err(&sshdr, result);
}
static int sd_pr_register(struct block_device *bdev, u64 old_key, u64 new_key,
--
2.25.1
next prev parent reply other threads:[~2022-11-09 3:13 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-09 3:11 [PATCH 0/3] block/scsi/nvme: Add error codes for PR ops Mike Christie
2022-11-09 3:11 ` [PATCH 1/3] block: Add error codes for common PR failures Mike Christie
2022-11-09 6:52 ` Christoph Hellwig
2022-11-09 3:11 ` Mike Christie [this message]
2022-11-09 6:52 ` [PATCH 2/3] scsi: Convert SCSI errors to PR_STS errors Christoph Hellwig
2022-11-10 18:59 ` kernel test robot
2022-11-10 19:29 ` kernel test robot
2022-11-09 3:11 ` [PATCH 3/3] nvme: Convert NVMe errors to PT_STS errors Mike Christie
2022-11-09 6:53 ` Christoph Hellwig
2022-11-09 17:20 ` Mike Christie
2022-11-15 9:14 ` Christoph Hellwig
2022-11-15 16:56 ` Mike Christie
2022-11-09 8:28 ` Chao Leng
2022-11-09 17:35 ` Mike Christie
2022-11-10 0:58 ` Chao Leng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221109031106.201324-3-michael.christie@oracle.com \
--to=michael.christie@oracle.com \
--cc=axboe@fb.com \
--cc=hch@lst.de \
--cc=jejb@linux.ibm.com \
--cc=kbusch@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=sagi@grimberg.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox