[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 10/50] scsi: Introduce scsi_sense_buf_to_errno
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 10/50] scsi: Introduce scsi_sense_buf_to_errno |
Date: |
Tue, 19 Sep 2017 14:28:59 +0200 |
From: Fam Zheng <address@hidden>
This recognizes the "fixed" and "descriptor" format sense data, extracts
the sense key/asc/ascq fields then converts them to an errno.
Signed-off-by: Fam Zheng <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
include/scsi/scsi.h | 1 +
util/scsi.c | 30 ++++++++++++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
index f894ace..fe33038 100644
--- a/include/scsi/scsi.h
+++ b/include/scsi/scsi.h
@@ -15,5 +15,6 @@
#define QEMU_SCSI_H
int scsi_sense_to_errno(int key, int asc, int ascq);
+int scsi_sense_buf_to_errno(const uint8_t *sense, size_t sense_size);
#endif
diff --git a/util/scsi.c b/util/scsi.c
index 472eb5b..472293d 100644
--- a/util/scsi.c
+++ b/util/scsi.c
@@ -58,3 +58,33 @@ int scsi_sense_to_errno(int key, int asc, int ascq)
return EIO;
}
}
+
+int scsi_sense_buf_to_errno(const uint8_t *sense, size_t sense_size)
+{
+ int key, asc, ascq;
+ if (sense_size < 1) {
+ return EIO;
+ }
+ switch (sense[0]) {
+ case 0x70: /* Fixed format sense data. */
+ if (sense_size < 14) {
+ return EIO;
+ }
+ key = sense[2] & 0xF;
+ asc = sense[12];
+ ascq = sense[13];
+ break;
+ case 0x72: /* Descriptor format sense data. */
+ if (sense_size < 4) {
+ return EIO;
+ }
+ key = sense[1] & 0xF;
+ asc = sense[2];
+ ascq = sense[3];
+ break;
+ default:
+ return EIO;
+ break;
+ }
+ return scsi_sense_to_errno(key, asc, ascq);
+}
--
1.8.3.1
- [Qemu-devel] [PULL 02/50] target/i386: set rip_offset for further SSE instructions, (continued)
- [Qemu-devel] [PULL 02/50] target/i386: set rip_offset for further SSE instructions, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 05/50] target/i386: fix phminposuw in-place operation, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 04/50] target/i386: fix pcmpxstrx substring search, Paolo Bonzini, 2017/09/19
- [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 <=
- [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, 2017/09/19
- [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