[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 14/23] scsi: Add mapping for generic SCSI_HOST status to sense cod
From: |
Paolo Bonzini |
Subject: |
[PULL 14/23] scsi: Add mapping for generic SCSI_HOST status to sense codes |
Date: |
Sat, 6 Mar 2021 11:54:10 +0100 |
From: Hannes Reinecke <hare@suse.de>
As we don't have a driver-specific mapping (yet) we should provide
for a detailed mapping from host_status to SCSI sense codes.
Signed-off-by: Hannes Reinecke <hare@suse.de>
Message-Id: <20201116184041.60465-6-hare@suse.de>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
include/scsi/utils.h | 1 +
scsi/utils.c | 65 +++++++++++++++++++++++++++++++++++++++-----
2 files changed, 59 insertions(+), 7 deletions(-)
diff --git a/include/scsi/utils.h b/include/scsi/utils.h
index ddb22b56df..9080d65e27 100644
--- a/include/scsi/utils.h
+++ b/include/scsi/utils.h
@@ -145,5 +145,6 @@ int sg_io_sense_from_errno(int errno_value, struct
sg_io_hdr *io_hdr,
#endif
int scsi_sense_from_errno(int errno_value, SCSISense *sense);
+int scsi_sense_from_host_status(uint8_t host_status, SCSISense *sense);
#endif
diff --git a/scsi/utils.c b/scsi/utils.c
index 4d994b6d56..28eb32746e 100644
--- a/scsi/utils.c
+++ b/scsi/utils.c
@@ -257,6 +257,21 @@ const struct SCSISense sense_code_LUN_COMM_FAILURE = {
.key = ABORTED_COMMAND, .asc = 0x08, .ascq = 0x00
};
+/* Command aborted, LUN does not respond to selection */
+const struct SCSISense sense_code_LUN_NOT_RESPONDING = {
+ .key = ABORTED_COMMAND, .asc = 0x05, .ascq = 0x00
+};
+
+/* Command aborted, Command Timeout during processing */
+const struct SCSISense sense_code_COMMAND_TIMEOUT = {
+ .key = ABORTED_COMMAND, .asc = 0x2e, .ascq = 0x02
+};
+
+/* Command aborted, Commands cleared by device server */
+const struct SCSISense sense_code_COMMAND_ABORTED = {
+ .key = ABORTED_COMMAND, .asc = 0x2f, .ascq = 0x02
+};
+
/* Medium Error, Unrecovered read error */
const struct SCSISense sense_code_READ_ERROR = {
.key = MEDIUM_ERROR, .asc = 0x11, .ascq = 0x00
@@ -605,6 +620,45 @@ int scsi_sense_from_errno(int errno_value, SCSISense
*sense)
}
}
+int scsi_sense_from_host_status(uint8_t host_status,
+ SCSISense *sense)
+{
+ switch (host_status) {
+ case SCSI_HOST_NO_LUN:
+ *sense = SENSE_CODE(LUN_NOT_RESPONDING);
+ return CHECK_CONDITION;
+ case SCSI_HOST_BUSY:
+ return BUSY;
+ case SCSI_HOST_TIME_OUT:
+ *sense = SENSE_CODE(COMMAND_TIMEOUT);
+ return CHECK_CONDITION;
+ case SCSI_HOST_BAD_RESPONSE:
+ *sense = SENSE_CODE(LUN_COMM_FAILURE);
+ return CHECK_CONDITION;
+ case SCSI_HOST_ABORTED:
+ *sense = SENSE_CODE(COMMAND_ABORTED);
+ return CHECK_CONDITION;
+ case SCSI_HOST_RESET:
+ *sense = SENSE_CODE(RESET);
+ return CHECK_CONDITION;
+ case SCSI_HOST_TRANSPORT_DISRUPTED:
+ *sense = SENSE_CODE(I_T_NEXUS_LOSS);
+ return CHECK_CONDITION;
+ case SCSI_HOST_TARGET_FAILURE:
+ *sense = SENSE_CODE(TARGET_FAILURE);
+ return CHECK_CONDITION;
+ case SCSI_HOST_RESERVATION_ERROR:
+ return RESERVATION_CONFLICT;
+ case SCSI_HOST_ALLOCATION_FAILURE:
+ *sense = SENSE_CODE(SPACE_ALLOC_FAILED);
+ return CHECK_CONDITION;
+ case SCSI_HOST_MEDIUM_ERROR:
+ *sense = SENSE_CODE(READ_ERROR);
+ return CHECK_CONDITION;
+ }
+ return GOOD;
+}
+
#ifdef CONFIG_LINUX
int sg_io_sense_from_errno(int errno_value, struct sg_io_hdr *io_hdr,
SCSISense *sense)
@@ -612,14 +666,11 @@ int sg_io_sense_from_errno(int errno_value, struct
sg_io_hdr *io_hdr,
if (errno_value != 0) {
return scsi_sense_from_errno(errno_value, sense);
} else {
- if (io_hdr->host_status == SCSI_HOST_NO_LUN ||
- io_hdr->host_status == SCSI_HOST_BUSY ||
- io_hdr->host_status == SCSI_HOST_TIME_OUT ||
- (io_hdr->driver_status & SG_ERR_DRIVER_TIMEOUT)) {
+ int status = scsi_sense_from_host_status(io_hdr->host_status, sense);
+ if (status) {
+ return status;
+ } else if (io_hdr->driver_status & SG_ERR_DRIVER_TIMEOUT) {
return BUSY;
- } else if (io_hdr->host_status) {
- *sense = SENSE_CODE(I_T_NEXUS_LOSS);
- return CHECK_CONDITION;
} else if (io_hdr->status) {
return io_hdr->status;
} else if (io_hdr->driver_status & SG_ERR_DRIVER_SENSE) {
--
2.29.2
- [PULL 10/23] elf_ops: correct loading of 32 bit PVH kernel, (continued)
- [PULL 10/23] elf_ops: correct loading of 32 bit PVH kernel, Paolo Bonzini, 2021/03/06
- [PULL 11/23] x86/pvh: extract only 4 bytes of start address for 32 bit kernels, Paolo Bonzini, 2021/03/06
- [PULL 13/23] scsi: Rename linux-specific SG_ERR codes to generic SCSI_HOST error codes, Paolo Bonzini, 2021/03/06
- [PULL 12/23] qemu-config: add error propagation to qemu_config_parse, Paolo Bonzini, 2021/03/06
- [PULL 15/23] scsi-generic: do not snoop the output of failed commands, Paolo Bonzini, 2021/03/06
- [PULL 16/23] scsi: inline sg_io_sense_from_errno() into the callers., Paolo Bonzini, 2021/03/06
- [PULL 20/23] meson: adjust timeouts for some slower tests, Paolo Bonzini, 2021/03/06
- [PULL 21/23] trace: fix "-trace file=...", Paolo Bonzini, 2021/03/06
- [PULL 22/23] trace: skip qemu_set_log_filename if no "-D" option was passed, Paolo Bonzini, 2021/03/06
- [PULL 08/23] accel: kvm: Add aligment assert for kvm_log_clear_one_slot, Paolo Bonzini, 2021/03/06
- [PULL 14/23] scsi: Add mapping for generic SCSI_HOST status to sense codes,
Paolo Bonzini <=
- [PULL 17/23] scsi: move host_status handling into SCSI drivers, Paolo Bonzini, 2021/03/06
- [PULL 18/23] qemu-option: do not suggest using the delay option, Paolo Bonzini, 2021/03/06
- [PULL 19/23] build-sys: invoke ninja with -d keepdepfile, Paolo Bonzini, 2021/03/06
- [PULL 23/23] meson: Stop if cfi is enabled with system slirp, Paolo Bonzini, 2021/03/06
- [PULL 09/23] lsilogic: Use PCIDevice::exit instead of DeviceState::unrealize, Paolo Bonzini, 2021/03/06
- Re: [PULL 00/23] Misc patches for 2021-03-06, no-reply, 2021/03/06
- Re: [PULL 00/23] Misc patches for 2021-03-06, Peter Maydell, 2021/03/08