|
|
4a2fec |
From 4f71eecd159d2ab9e66e1f6115a0490676f76e8e Mon Sep 17 00:00:00 2001
|
|
|
4a2fec |
From: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
4a2fec |
Date: Sat, 2 Dec 2017 12:19:40 +0100
|
|
|
4a2fec |
Subject: [PATCH 14/36] scsi: Refactor scsi sense interpreting code
|
|
|
4a2fec |
|
|
|
4a2fec |
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
4a2fec |
Message-id: <20171202121953.13317-5-pbonzini@redhat.com>
|
|
|
4a2fec |
Patchwork-id: 78073
|
|
|
4a2fec |
O-Subject: [RHEL7.4 qemu-kvm-rhev PATCH 04/17] scsi: Refactor scsi sense interpreting code
|
|
|
4a2fec |
Bugzilla: 1464908
|
|
|
4a2fec |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
4a2fec |
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
|
|
4a2fec |
RH-Acked-by: John Snow <jsnow@redhat.com>
|
|
|
4a2fec |
|
|
|
4a2fec |
From: Fam Zheng <famz@redhat.com>
|
|
|
4a2fec |
|
|
|
4a2fec |
So that it can be reused outside of iscsi.c.
|
|
|
4a2fec |
|
|
|
4a2fec |
Also update MAINTAINERS to include the new files in SCSI section.
|
|
|
4a2fec |
|
|
|
4a2fec |
Signed-off-by: Fam Zheng <famz@redhat.com>
|
|
|
4a2fec |
Message-Id: <20170821141008.19383-2-famz@redhat.com>
|
|
|
4a2fec |
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
4a2fec |
(cherry picked from commit 2875135807771a0d07ba1c878c20b757ed7adffb)
|
|
|
4a2fec |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
4a2fec |
---
|
|
|
4a2fec |
MAINTAINERS | 2 ++
|
|
|
4a2fec |
block/iscsi.c | 45 ++++-----------------------------------------
|
|
|
4a2fec |
include/scsi/scsi.h | 19 +++++++++++++++++++
|
|
|
4a2fec |
util/Makefile.objs | 1 +
|
|
|
4a2fec |
util/scsi.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
4a2fec |
5 files changed, 78 insertions(+), 41 deletions(-)
|
|
|
4a2fec |
create mode 100644 include/scsi/scsi.h
|
|
|
4a2fec |
create mode 100644 util/scsi.c
|
|
|
4a2fec |
|
|
|
4a2fec |
diff --git a/MAINTAINERS b/MAINTAINERS
|
|
|
4a2fec |
index ccee28b..2a4e503 100644
|
|
|
4a2fec |
--- a/MAINTAINERS
|
|
|
4a2fec |
+++ b/MAINTAINERS
|
|
|
4a2fec |
@@ -969,7 +969,9 @@ SCSI
|
|
|
4a2fec |
M: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
4a2fec |
S: Supported
|
|
|
4a2fec |
F: include/hw/scsi/*
|
|
|
4a2fec |
+F: include/scsi/*
|
|
|
4a2fec |
F: hw/scsi/*
|
|
|
4a2fec |
+F: util/scsi*
|
|
|
4a2fec |
F: tests/virtio-scsi-test.c
|
|
|
4a2fec |
T: git git://github.com/bonzini/qemu.git scsi-next
|
|
|
4a2fec |
|
|
|
4a2fec |
diff --git a/block/iscsi.c b/block/iscsi.c
|
|
|
4a2fec |
index d557c99..4bed63c 100644
|
|
|
4a2fec |
--- a/block/iscsi.c
|
|
|
4a2fec |
+++ b/block/iscsi.c
|
|
|
4a2fec |
@@ -40,6 +40,7 @@
|
|
|
4a2fec |
#include "qmp-commands.h"
|
|
|
4a2fec |
#include "qapi/qmp/qstring.h"
|
|
|
4a2fec |
#include "crypto/secret.h"
|
|
|
4a2fec |
+#include "scsi/scsi.h"
|
|
|
4a2fec |
|
|
|
4a2fec |
#include <iscsi/iscsi.h>
|
|
|
4a2fec |
#include <iscsi/scsi-lowlevel.h>
|
|
|
4a2fec |
@@ -209,47 +210,9 @@ static inline unsigned exp_random(double mean)
|
|
|
4a2fec |
|
|
|
4a2fec |
static int iscsi_translate_sense(struct scsi_sense *sense)
|
|
|
4a2fec |
{
|
|
|
4a2fec |
- int ret;
|
|
|
4a2fec |
-
|
|
|
4a2fec |
- switch (sense->key) {
|
|
|
4a2fec |
- case SCSI_SENSE_NOT_READY:
|
|
|
4a2fec |
- return -EBUSY;
|
|
|
4a2fec |
- case SCSI_SENSE_DATA_PROTECTION:
|
|
|
4a2fec |
- return -EACCES;
|
|
|
4a2fec |
- case SCSI_SENSE_COMMAND_ABORTED:
|
|
|
4a2fec |
- return -ECANCELED;
|
|
|
4a2fec |
- case SCSI_SENSE_ILLEGAL_REQUEST:
|
|
|
4a2fec |
- /* Parse ASCQ */
|
|
|
4a2fec |
- break;
|
|
|
4a2fec |
- default:
|
|
|
4a2fec |
- return -EIO;
|
|
|
4a2fec |
- }
|
|
|
4a2fec |
- switch (sense->ascq) {
|
|
|
4a2fec |
- case SCSI_SENSE_ASCQ_PARAMETER_LIST_LENGTH_ERROR:
|
|
|
4a2fec |
- case SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE:
|
|
|
4a2fec |
- case SCSI_SENSE_ASCQ_INVALID_FIELD_IN_CDB:
|
|
|
4a2fec |
- case SCSI_SENSE_ASCQ_INVALID_FIELD_IN_PARAMETER_LIST:
|
|
|
4a2fec |
- ret = -EINVAL;
|
|
|
4a2fec |
- break;
|
|
|
4a2fec |
- case SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE:
|
|
|
4a2fec |
- ret = -ENOSPC;
|
|
|
4a2fec |
- break;
|
|
|
4a2fec |
- case SCSI_SENSE_ASCQ_LOGICAL_UNIT_NOT_SUPPORTED:
|
|
|
4a2fec |
- ret = -ENOTSUP;
|
|
|
4a2fec |
- break;
|
|
|
4a2fec |
- case SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT:
|
|
|
4a2fec |
- case SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED:
|
|
|
4a2fec |
- case SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN:
|
|
|
4a2fec |
- ret = -ENOMEDIUM;
|
|
|
4a2fec |
- break;
|
|
|
4a2fec |
- case SCSI_SENSE_ASCQ_WRITE_PROTECTED:
|
|
|
4a2fec |
- ret = -EACCES;
|
|
|
4a2fec |
- break;
|
|
|
4a2fec |
- default:
|
|
|
4a2fec |
- ret = -EIO;
|
|
|
4a2fec |
- break;
|
|
|
4a2fec |
- }
|
|
|
4a2fec |
- return ret;
|
|
|
4a2fec |
+ return - scsi_sense_to_errno(sense->key,
|
|
|
4a2fec |
+ (sense->ascq & 0xFF00) >> 8,
|
|
|
4a2fec |
+ sense->ascq & 0xFF);
|
|
|
4a2fec |
}
|
|
|
4a2fec |
|
|
|
4a2fec |
/* Called (via iscsi_service) with QemuMutex held. */
|
|
|
4a2fec |
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
|
|
|
4a2fec |
new file mode 100644
|
|
|
4a2fec |
index 0000000..f894ace
|
|
|
4a2fec |
--- /dev/null
|
|
|
4a2fec |
+++ b/include/scsi/scsi.h
|
|
|
4a2fec |
@@ -0,0 +1,19 @@
|
|
|
4a2fec |
+/*
|
|
|
4a2fec |
+ * SCSI helpers
|
|
|
4a2fec |
+ *
|
|
|
4a2fec |
+ * Copyright 2017 Red Hat, Inc.
|
|
|
4a2fec |
+ *
|
|
|
4a2fec |
+ * Authors:
|
|
|
4a2fec |
+ * Fam Zheng <famz@redhat.com>
|
|
|
4a2fec |
+ *
|
|
|
4a2fec |
+ * This program is free software; you can redistribute it and/or modify it
|
|
|
4a2fec |
+ * under the terms of the GNU General Public License as published by the Free
|
|
|
4a2fec |
+ * Software Foundation; either version 2 of the License, or (at your option)
|
|
|
4a2fec |
+ * any later version.
|
|
|
4a2fec |
+ */
|
|
|
4a2fec |
+#ifndef QEMU_SCSI_H
|
|
|
4a2fec |
+#define QEMU_SCSI_H
|
|
|
4a2fec |
+
|
|
|
4a2fec |
+int scsi_sense_to_errno(int key, int asc, int ascq);
|
|
|
4a2fec |
+
|
|
|
4a2fec |
+#endif
|
|
|
4a2fec |
diff --git a/util/Makefile.objs b/util/Makefile.objs
|
|
|
4a2fec |
index 50a55ec..c9e6c49 100644
|
|
|
4a2fec |
--- a/util/Makefile.objs
|
|
|
4a2fec |
+++ b/util/Makefile.objs
|
|
|
4a2fec |
@@ -45,3 +45,4 @@ util-obj-y += qht.o
|
|
|
4a2fec |
util-obj-y += range.o
|
|
|
4a2fec |
util-obj-y += stats64.o
|
|
|
4a2fec |
util-obj-y += systemd.o
|
|
|
4a2fec |
+util-obj-y += scsi.o
|
|
|
4a2fec |
diff --git a/util/scsi.c b/util/scsi.c
|
|
|
4a2fec |
new file mode 100644
|
|
|
4a2fec |
index 0000000..a671079
|
|
|
4a2fec |
--- /dev/null
|
|
|
4a2fec |
+++ b/util/scsi.c
|
|
|
4a2fec |
@@ -0,0 +1,52 @@
|
|
|
4a2fec |
+/*
|
|
|
4a2fec |
+ * SCSI helpers
|
|
|
4a2fec |
+ *
|
|
|
4a2fec |
+ * Copyright 2017 Red Hat, Inc.
|
|
|
4a2fec |
+ *
|
|
|
4a2fec |
+ * Authors:
|
|
|
4a2fec |
+ * Fam Zheng <famz@redhat.com>
|
|
|
4a2fec |
+ *
|
|
|
4a2fec |
+ * This program is free software; you can redistribute it and/or modify it
|
|
|
4a2fec |
+ * under the terms of the GNU General Public License as published by the Free
|
|
|
4a2fec |
+ * Software Foundation; either version 2 of the License, or (at your option)
|
|
|
4a2fec |
+ * any later version.
|
|
|
4a2fec |
+ */
|
|
|
4a2fec |
+
|
|
|
4a2fec |
+#include "qemu/osdep.h"
|
|
|
4a2fec |
+#include "scsi/scsi.h"
|
|
|
4a2fec |
+
|
|
|
4a2fec |
+int scsi_sense_to_errno(int key, int asc, int ascq)
|
|
|
4a2fec |
+{
|
|
|
4a2fec |
+ switch (key) {
|
|
|
4a2fec |
+ case 0x02: /* NOT READY */
|
|
|
4a2fec |
+ return EBUSY;
|
|
|
4a2fec |
+ case 0x07: /* DATA PROTECTION */
|
|
|
4a2fec |
+ return EACCES;
|
|
|
4a2fec |
+ case 0x0b: /* COMMAND ABORTED */
|
|
|
4a2fec |
+ return ECANCELED;
|
|
|
4a2fec |
+ case 0x05: /* ILLEGAL REQUEST */
|
|
|
4a2fec |
+ /* Parse ASCQ */
|
|
|
4a2fec |
+ break;
|
|
|
4a2fec |
+ default:
|
|
|
4a2fec |
+ return EIO;
|
|
|
4a2fec |
+ }
|
|
|
4a2fec |
+ switch ((asc << 8) | ascq) {
|
|
|
4a2fec |
+ case 0x1a00: /* PARAMETER LIST LENGTH ERROR */
|
|
|
4a2fec |
+ case 0x2000: /* INVALID OPERATION CODE */
|
|
|
4a2fec |
+ case 0x2400: /* INVALID FIELD IN CDB */
|
|
|
4a2fec |
+ case 0x2600: /* INVALID FIELD IN PARAMETER LIST */
|
|
|
4a2fec |
+ return EINVAL;
|
|
|
4a2fec |
+ case 0x2100: /* LBA OUT OF RANGE */
|
|
|
4a2fec |
+ return ENOSPC;
|
|
|
4a2fec |
+ case 0x2500: /* LOGICAL UNIT NOT SUPPORTED */
|
|
|
4a2fec |
+ return ENOTSUP;
|
|
|
4a2fec |
+ case 0x3a00: /* MEDIUM NOT PRESENT */
|
|
|
4a2fec |
+ case 0x3a01: /* MEDIUM NOT PRESENT TRAY CLOSED */
|
|
|
4a2fec |
+ case 0x3a02: /* MEDIUM NOT PRESENT TRAY OPEN */
|
|
|
4a2fec |
+ return ENOMEDIUM;
|
|
|
4a2fec |
+ case 0x2700: /* WRITE PROTECTED */
|
|
|
4a2fec |
+ return EACCES;
|
|
|
4a2fec |
+ default:
|
|
|
4a2fec |
+ return EIO;
|
|
|
4a2fec |
+ }
|
|
|
4a2fec |
+}
|
|
|
4a2fec |
--
|
|
|
4a2fec |
1.8.3.1
|
|
|
4a2fec |
|