[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 15/50] scsi: introduce sg_io_sense_from_errno
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 15/50] scsi: introduce sg_io_sense_from_errno |
Date: |
Tue, 19 Sep 2017 14:29:04 +0200 |
Move more knowledge of SG_IO out of hw/scsi/scsi-generic.c, for
reusability.
Reviewed-by: Stefan Hajnoczi <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
hw/scsi/scsi-generic.c | 40 +++++++---------------------------------
include/scsi/utils.h | 3 +++
scsi/utils.c | 35 +++++++++++++++++++++++++++++++++++
3 files changed, 45 insertions(+), 33 deletions(-)
diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c
index 7a8f500..04c687e 100644
--- a/hw/scsi/scsi-generic.c
+++ b/hw/scsi/scsi-generic.c
@@ -81,6 +81,7 @@ static void scsi_free_request(SCSIRequest *req)
static void scsi_command_complete_noio(SCSIGenericReq *r, int ret)
{
int status;
+ SCSISense sense;
assert(r->req.aiocb == NULL);
@@ -88,42 +89,15 @@ static void scsi_command_complete_noio(SCSIGenericReq *r,
int ret)
scsi_req_cancel_complete(&r->req);
goto done;
}
- if (r->io_header.driver_status & SG_ERR_DRIVER_SENSE) {
- r->req.sense_len = r->io_header.sb_len_wr;
- }
-
- if (ret != 0) {
- switch (ret) {
- case -EDOM:
- status = TASK_SET_FULL;
- break;
- case -ENOMEM:
- status = CHECK_CONDITION;
- scsi_req_build_sense(&r->req, SENSE_CODE(TARGET_FAILURE));
- break;
- default:
- status = CHECK_CONDITION;
- scsi_req_build_sense(&r->req, SENSE_CODE(IO_ERROR));
- break;
- }
- } else {
- if (r->io_header.host_status == SG_ERR_DID_NO_CONNECT ||
- r->io_header.host_status == SG_ERR_DID_BUS_BUSY ||
- r->io_header.host_status == SG_ERR_DID_TIME_OUT ||
- (r->io_header.driver_status & SG_ERR_DRIVER_TIMEOUT)) {
- status = BUSY;
- BADF("Driver Timeout\n");
- } else if (r->io_header.host_status) {
- status = CHECK_CONDITION;
- scsi_req_build_sense(&r->req, SENSE_CODE(I_T_NEXUS_LOSS));
- } else if (r->io_header.status) {
- status = r->io_header.status;
- } else if (r->io_header.driver_status & SG_ERR_DRIVER_SENSE) {
- status = CHECK_CONDITION;
+ status = sg_io_sense_from_errno(-ret, &r->io_header, &sense);
+ if (status == CHECK_CONDITION) {
+ if (r->io_header.driver_status & SG_ERR_DRIVER_SENSE) {
+ r->req.sense_len = r->io_header.sb_len_wr;
} else {
- status = GOOD;
+ scsi_req_build_sense(&r->req, sense);
}
}
+
DPRINTF("Command complete 0x%p tag=0x%x status=%d\n",
r, r->req.tag, status);
diff --git a/include/scsi/utils.h b/include/scsi/utils.h
index b49392d..d301b31 100644
--- a/include/scsi/utils.h
+++ b/include/scsi/utils.h
@@ -116,6 +116,9 @@ int scsi_cdb_length(uint8_t *buf);
#define SG_ERR_DID_TIME_OUT 0x03
#define SG_ERR_DRIVER_SENSE 0x08
+
+int sg_io_sense_from_errno(int errno_value, struct sg_io_hdr *io_hdr,
+ SCSISense *sense);
#endif
#endif
diff --git a/scsi/utils.c b/scsi/utils.c
index 89d9167..6ee9f40 100644
--- a/scsi/utils.c
+++ b/scsi/utils.c
@@ -501,3 +501,38 @@ const char *scsi_command_name(uint8_t cmd)
}
return names[cmd];
}
+
+#ifdef CONFIG_LINUX
+int sg_io_sense_from_errno(int errno_value, struct sg_io_hdr *io_hdr,
+ SCSISense *sense)
+{
+ if (errno_value != 0) {
+ switch (errno_value) {
+ case EDOM:
+ return TASK_SET_FULL;
+ case ENOMEM:
+ *sense = SENSE_CODE(TARGET_FAILURE);
+ return CHECK_CONDITION;
+ default:
+ *sense = SENSE_CODE(IO_ERROR);
+ return CHECK_CONDITION;
+ }
+ } else {
+ if (io_hdr->host_status == SG_ERR_DID_NO_CONNECT ||
+ io_hdr->host_status == SG_ERR_DID_BUS_BUSY ||
+ io_hdr->host_status == SG_ERR_DID_TIME_OUT ||
+ (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) {
+ return CHECK_CONDITION;
+ } else {
+ return GOOD;
+ }
+ }
+}
+#endif
--
1.8.3.1
- [Qemu-devel] [PULL 03/50] target/i386: fix packusdw in-place operation, (continued)
- [Qemu-devel] [PULL 03/50] target/i386: fix packusdw in-place operation, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 01/50] target/i386: fix pmovsx/pmovzx in-place operations, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 06/50] virtio-scsi: Add virtqueue_size parameter allowing virtqueue size to be set., Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 09/50] scsi: Improve scsi_sense_to_errno, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 08/50] scsi: Refactor scsi sense interpreting code, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 11/50] scsi-block: Support rerror/werror, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 14/50] scsi: introduce scsi_build_sense, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 10/50] scsi: Introduce scsi_sense_buf_to_errno, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 07/50] scsi-bus: correct responses for INQUIRY and REQUEST SENSE, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 12/50] scsi: rename scsi_build_sense to scsi_convert_sense, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 15/50] scsi: introduce sg_io_sense_from_errno,
Paolo Bonzini <=
- [Qemu-devel] [PULL 16/50] scsi: move block/scsi.h to include/scsi/constants.h, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 20/50] i386/kvm: introduce tsc_is_stable_and_known(), Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 17/50] MAINTAINERS: update mail address for NVDIMM, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 18/50] i386/kvm: use a switch statement for MSR detection, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 19/50] i386/kvm: set tsc_khz before configuring Hyper-V CPUID, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 29/50] kvm: we never have overlapping slots in kvm_set_phys_mem(), Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 30/50] kvm: kvm_log_start/stop are only called with known sections, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 28/50] kvm: use start + size for memory ranges, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 21/50] i386/kvm: advertise Hyper-V frequency MSRs, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 22/50] MAINTAINERS: update email, add missing test entry for megasas, Paolo Bonzini, 2017/09/19