|
Paolo Bonzini |
0fb2b2 |
From: Fam Zheng <famz@redhat.com>
|
|
Paolo Bonzini |
0fb2b2 |
Date: Mon, 21 Aug 2017 22:10:07 +0800
|
|
|
59eb7a |
Subject: [PATCH] scsi: Introduce scsi_sense_buf_to_errno
|
|
Paolo Bonzini |
0fb2b2 |
|
|
Paolo Bonzini |
0fb2b2 |
This recognizes the "fixed" and "descriptor" format sense data, extracts
|
|
Paolo Bonzini |
0fb2b2 |
the sense key/asc/ascq fields then converts them to an errno.
|
|
Paolo Bonzini |
0fb2b2 |
|
|
Paolo Bonzini |
0fb2b2 |
Signed-off-by: Fam Zheng <famz@redhat.com>
|
|
Paolo Bonzini |
0fb2b2 |
Message-Id: <20170821141008.19383-4-famz@redhat.com>
|
|
Paolo Bonzini |
0fb2b2 |
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
Paolo Bonzini |
0fb2b2 |
---
|
|
Paolo Bonzini |
0fb2b2 |
include/scsi/scsi.h | 1 +
|
|
Paolo Bonzini |
0fb2b2 |
util/scsi.c | 30 ++++++++++++++++++++++++++++++
|
|
Paolo Bonzini |
0fb2b2 |
2 files changed, 31 insertions(+)
|
|
Paolo Bonzini |
0fb2b2 |
|
|
Paolo Bonzini |
0fb2b2 |
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
|
|
Paolo Bonzini |
0fb2b2 |
index f894ace4bf..fe330385d8 100644
|
|
Paolo Bonzini |
0fb2b2 |
--- a/include/scsi/scsi.h
|
|
Paolo Bonzini |
0fb2b2 |
+++ b/include/scsi/scsi.h
|
|
Paolo Bonzini |
0fb2b2 |
@@ -15,5 +15,6 @@
|
|
Paolo Bonzini |
0fb2b2 |
#define QEMU_SCSI_H
|
|
Paolo Bonzini |
0fb2b2 |
|
|
Paolo Bonzini |
0fb2b2 |
int scsi_sense_to_errno(int key, int asc, int ascq);
|
|
Paolo Bonzini |
0fb2b2 |
+int scsi_sense_buf_to_errno(const uint8_t *sense, size_t sense_size);
|
|
Paolo Bonzini |
0fb2b2 |
|
|
Paolo Bonzini |
0fb2b2 |
#endif
|
|
Paolo Bonzini |
0fb2b2 |
diff --git a/util/scsi.c b/util/scsi.c
|
|
Paolo Bonzini |
0fb2b2 |
index 472eb5bea5..472293d59b 100644
|
|
Paolo Bonzini |
0fb2b2 |
--- a/util/scsi.c
|
|
Paolo Bonzini |
0fb2b2 |
+++ b/util/scsi.c
|
|
Paolo Bonzini |
0fb2b2 |
@@ -58,3 +58,33 @@ int scsi_sense_to_errno(int key, int asc, int ascq)
|
|
Paolo Bonzini |
0fb2b2 |
return EIO;
|
|
Paolo Bonzini |
0fb2b2 |
}
|
|
Paolo Bonzini |
0fb2b2 |
}
|
|
Paolo Bonzini |
0fb2b2 |
+
|
|
Paolo Bonzini |
0fb2b2 |
+int scsi_sense_buf_to_errno(const uint8_t *sense, size_t sense_size)
|
|
Paolo Bonzini |
0fb2b2 |
+{
|
|
Paolo Bonzini |
0fb2b2 |
+ int key, asc, ascq;
|
|
Paolo Bonzini |
0fb2b2 |
+ if (sense_size < 1) {
|
|
Paolo Bonzini |
0fb2b2 |
+ return EIO;
|
|
Paolo Bonzini |
0fb2b2 |
+ }
|
|
Paolo Bonzini |
0fb2b2 |
+ switch (sense[0]) {
|
|
Paolo Bonzini |
0fb2b2 |
+ case 0x70: /* Fixed format sense data. */
|
|
Paolo Bonzini |
0fb2b2 |
+ if (sense_size < 14) {
|
|
Paolo Bonzini |
0fb2b2 |
+ return EIO;
|
|
Paolo Bonzini |
0fb2b2 |
+ }
|
|
Paolo Bonzini |
0fb2b2 |
+ key = sense[2] & 0xF;
|
|
Paolo Bonzini |
0fb2b2 |
+ asc = sense[12];
|
|
Paolo Bonzini |
0fb2b2 |
+ ascq = sense[13];
|
|
Paolo Bonzini |
0fb2b2 |
+ break;
|
|
Paolo Bonzini |
0fb2b2 |
+ case 0x72: /* Descriptor format sense data. */
|
|
Paolo Bonzini |
0fb2b2 |
+ if (sense_size < 4) {
|
|
Paolo Bonzini |
0fb2b2 |
+ return EIO;
|
|
Paolo Bonzini |
0fb2b2 |
+ }
|
|
Paolo Bonzini |
0fb2b2 |
+ key = sense[1] & 0xF;
|
|
Paolo Bonzini |
0fb2b2 |
+ asc = sense[2];
|
|
Paolo Bonzini |
0fb2b2 |
+ ascq = sense[3];
|
|
Paolo Bonzini |
0fb2b2 |
+ break;
|
|
Paolo Bonzini |
0fb2b2 |
+ default:
|
|
Paolo Bonzini |
0fb2b2 |
+ return EIO;
|
|
Paolo Bonzini |
0fb2b2 |
+ break;
|
|
Paolo Bonzini |
0fb2b2 |
+ }
|
|
Paolo Bonzini |
0fb2b2 |
+ return scsi_sense_to_errno(key, asc, ascq);
|
|
Paolo Bonzini |
0fb2b2 |
+}
|