|
Paolo Bonzini |
0fb2b2 |
From f35ef58b2bac932bbd379602fe23e7a190530075 Mon Sep 17 00:00:00 2001
|
|
Paolo Bonzini |
0fb2b2 |
From: Fam Zheng <famz@redhat.com>
|
|
Paolo Bonzini |
0fb2b2 |
Date: Mon, 21 Aug 2017 22:10:05 +0800
|
|
Paolo Bonzini |
0fb2b2 |
Subject: [PATCH 04/15] scsi: Refactor scsi sense interpreting code
|
|
Paolo Bonzini |
0fb2b2 |
|
|
Paolo Bonzini |
0fb2b2 |
So that it can be reused outside of iscsi.c.
|
|
Paolo Bonzini |
0fb2b2 |
|
|
Paolo Bonzini |
0fb2b2 |
Also update MAINTAINERS to include the new files in SCSI section.
|
|
Paolo Bonzini |
0fb2b2 |
|
|
Paolo Bonzini |
0fb2b2 |
Signed-off-by: Fam Zheng <famz@redhat.com>
|
|
Paolo Bonzini |
0fb2b2 |
Message-Id: <20170821141008.19383-2-famz@redhat.com>
|
|
Paolo Bonzini |
0fb2b2 |
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
Paolo Bonzini |
0fb2b2 |
---
|
|
Paolo Bonzini |
0fb2b2 |
MAINTAINERS | 2 ++
|
|
Paolo Bonzini |
0fb2b2 |
block/iscsi.c | 45 ++++-----------------------------------------
|
|
Paolo Bonzini |
0fb2b2 |
include/scsi/scsi.h | 19 +++++++++++++++++++
|
|
Paolo Bonzini |
0fb2b2 |
util/Makefile.objs | 1 +
|
|
Paolo Bonzini |
0fb2b2 |
util/scsi.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
Paolo Bonzini |
0fb2b2 |
5 files changed, 78 insertions(+), 41 deletions(-)
|
|
Paolo Bonzini |
0fb2b2 |
create mode 100644 include/scsi/scsi.h
|
|
Paolo Bonzini |
0fb2b2 |
create mode 100644 util/scsi.c
|
|
Paolo Bonzini |
0fb2b2 |
|
|
Paolo Bonzini |
0fb2b2 |
diff --git a/MAINTAINERS b/MAINTAINERS
|
|
Paolo Bonzini |
0fb2b2 |
index ccee28b12d..2a4e5036ae 100644
|
|
Paolo Bonzini |
0fb2b2 |
--- a/MAINTAINERS
|
|
Paolo Bonzini |
0fb2b2 |
+++ b/MAINTAINERS
|
|
Paolo Bonzini |
0fb2b2 |
@@ -969,7 +969,9 @@ SCSI
|
|
Paolo Bonzini |
0fb2b2 |
M: Paolo Bonzini <pbonzini@redhat.com>
|
|
Paolo Bonzini |
0fb2b2 |
S: Supported
|
|
Paolo Bonzini |
0fb2b2 |
F: include/hw/scsi/*
|
|
Paolo Bonzini |
0fb2b2 |
+F: include/scsi/*
|
|
Paolo Bonzini |
0fb2b2 |
F: hw/scsi/*
|
|
Paolo Bonzini |
0fb2b2 |
+F: util/scsi*
|
|
Paolo Bonzini |
0fb2b2 |
F: tests/virtio-scsi-test.c
|
|
Paolo Bonzini |
0fb2b2 |
T: git git://github.com/bonzini/qemu.git scsi-next
|
|
Paolo Bonzini |
0fb2b2 |
|
|
Paolo Bonzini |
0fb2b2 |
diff --git a/block/iscsi.c b/block/iscsi.c
|
|
Paolo Bonzini |
0fb2b2 |
index d557c99668..4bed63cd6d 100644
|
|
Paolo Bonzini |
0fb2b2 |
--- a/block/iscsi.c
|
|
Paolo Bonzini |
0fb2b2 |
+++ b/block/iscsi.c
|
|
Paolo Bonzini |
0fb2b2 |
@@ -40,6 +40,7 @@
|
|
Paolo Bonzini |
0fb2b2 |
#include "qmp-commands.h"
|
|
Paolo Bonzini |
0fb2b2 |
#include "qapi/qmp/qstring.h"
|
|
Paolo Bonzini |
0fb2b2 |
#include "crypto/secret.h"
|
|
Paolo Bonzini |
0fb2b2 |
+#include "scsi/scsi.h"
|
|
Paolo Bonzini |
0fb2b2 |
|
|
Paolo Bonzini |
0fb2b2 |
#include <iscsi/iscsi.h>
|
|
Paolo Bonzini |
0fb2b2 |
#include <iscsi/scsi-lowlevel.h>
|
|
Paolo Bonzini |
0fb2b2 |
@@ -209,47 +210,9 @@ static inline unsigned exp_random(double mean)
|
|
Paolo Bonzini |
0fb2b2 |
|
|
Paolo Bonzini |
0fb2b2 |
static int iscsi_translate_sense(struct scsi_sense *sense)
|
|
Paolo Bonzini |
0fb2b2 |
{
|
|
Paolo Bonzini |
0fb2b2 |
- int ret;
|
|
Paolo Bonzini |
0fb2b2 |
-
|
|
Paolo Bonzini |
0fb2b2 |
- switch (sense->key) {
|
|
Paolo Bonzini |
0fb2b2 |
- case SCSI_SENSE_NOT_READY:
|
|
Paolo Bonzini |
0fb2b2 |
- return -EBUSY;
|
|
Paolo Bonzini |
0fb2b2 |
- case SCSI_SENSE_DATA_PROTECTION:
|
|
Paolo Bonzini |
0fb2b2 |
- return -EACCES;
|
|
Paolo Bonzini |
0fb2b2 |
- case SCSI_SENSE_COMMAND_ABORTED:
|
|
Paolo Bonzini |
0fb2b2 |
- return -ECANCELED;
|
|
Paolo Bonzini |
0fb2b2 |
- case SCSI_SENSE_ILLEGAL_REQUEST:
|
|
Paolo Bonzini |
0fb2b2 |
- /* Parse ASCQ */
|
|
Paolo Bonzini |
0fb2b2 |
- break;
|
|
Paolo Bonzini |
0fb2b2 |
- default:
|
|
Paolo Bonzini |
0fb2b2 |
- return -EIO;
|
|
Paolo Bonzini |
0fb2b2 |
- }
|
|
Paolo Bonzini |
0fb2b2 |
- switch (sense->ascq) {
|
|
Paolo Bonzini |
0fb2b2 |
- case SCSI_SENSE_ASCQ_PARAMETER_LIST_LENGTH_ERROR:
|
|
Paolo Bonzini |
0fb2b2 |
- case SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE:
|
|
Paolo Bonzini |
0fb2b2 |
- case SCSI_SENSE_ASCQ_INVALID_FIELD_IN_CDB:
|
|
Paolo Bonzini |
0fb2b2 |
- case SCSI_SENSE_ASCQ_INVALID_FIELD_IN_PARAMETER_LIST:
|
|
Paolo Bonzini |
0fb2b2 |
- ret = -EINVAL;
|
|
Paolo Bonzini |
0fb2b2 |
- break;
|
|
Paolo Bonzini |
0fb2b2 |
- case SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE:
|
|
Paolo Bonzini |
0fb2b2 |
- ret = -ENOSPC;
|
|
Paolo Bonzini |
0fb2b2 |
- break;
|
|
Paolo Bonzini |
0fb2b2 |
- case SCSI_SENSE_ASCQ_LOGICAL_UNIT_NOT_SUPPORTED:
|
|
Paolo Bonzini |
0fb2b2 |
- ret = -ENOTSUP;
|
|
Paolo Bonzini |
0fb2b2 |
- break;
|
|
Paolo Bonzini |
0fb2b2 |
- case SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT:
|
|
Paolo Bonzini |
0fb2b2 |
- case SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED:
|
|
Paolo Bonzini |
0fb2b2 |
- case SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN:
|
|
Paolo Bonzini |
0fb2b2 |
- ret = -ENOMEDIUM;
|
|
Paolo Bonzini |
0fb2b2 |
- break;
|
|
Paolo Bonzini |
0fb2b2 |
- case SCSI_SENSE_ASCQ_WRITE_PROTECTED:
|
|
Paolo Bonzini |
0fb2b2 |
- ret = -EACCES;
|
|
Paolo Bonzini |
0fb2b2 |
- break;
|
|
Paolo Bonzini |
0fb2b2 |
- default:
|
|
Paolo Bonzini |
0fb2b2 |
- ret = -EIO;
|
|
Paolo Bonzini |
0fb2b2 |
- break;
|
|
Paolo Bonzini |
0fb2b2 |
- }
|
|
Paolo Bonzini |
0fb2b2 |
- return ret;
|
|
Paolo Bonzini |
0fb2b2 |
+ return - scsi_sense_to_errno(sense->key,
|
|
Paolo Bonzini |
0fb2b2 |
+ (sense->ascq & 0xFF00) >> 8,
|
|
Paolo Bonzini |
0fb2b2 |
+ sense->ascq & 0xFF);
|
|
Paolo Bonzini |
0fb2b2 |
}
|
|
Paolo Bonzini |
0fb2b2 |
|
|
Paolo Bonzini |
0fb2b2 |
/* Called (via iscsi_service) with QemuMutex held. */
|
|
Paolo Bonzini |
0fb2b2 |
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
|
|
Paolo Bonzini |
0fb2b2 |
new file mode 100644
|
|
Paolo Bonzini |
0fb2b2 |
index 0000000000..f894ace4bf
|
|
Paolo Bonzini |
0fb2b2 |
--- /dev/null
|
|
Paolo Bonzini |
0fb2b2 |
+++ b/include/scsi/scsi.h
|
|
Paolo Bonzini |
0fb2b2 |
@@ -0,0 +1,19 @@
|
|
Paolo Bonzini |
0fb2b2 |
+/*
|
|
Paolo Bonzini |
0fb2b2 |
+ * SCSI helpers
|
|
Paolo Bonzini |
0fb2b2 |
+ *
|
|
Paolo Bonzini |
0fb2b2 |
+ * Copyright 2017 Red Hat, Inc.
|
|
Paolo Bonzini |
0fb2b2 |
+ *
|
|
Paolo Bonzini |
0fb2b2 |
+ * Authors:
|
|
Paolo Bonzini |
0fb2b2 |
+ * Fam Zheng <famz@redhat.com>
|
|
Paolo Bonzini |
0fb2b2 |
+ *
|
|
Paolo Bonzini |
0fb2b2 |
+ * This program is free software; you can redistribute it and/or modify it
|
|
Paolo Bonzini |
0fb2b2 |
+ * under the terms of the GNU General Public License as published by the Free
|
|
Paolo Bonzini |
0fb2b2 |
+ * Software Foundation; either version 2 of the License, or (at your option)
|
|
Paolo Bonzini |
0fb2b2 |
+ * any later version.
|
|
Paolo Bonzini |
0fb2b2 |
+ */
|
|
Paolo Bonzini |
0fb2b2 |
+#ifndef QEMU_SCSI_H
|
|
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 |
+
|
|
Paolo Bonzini |
0fb2b2 |
+#endif
|
|
Paolo Bonzini |
0fb2b2 |
diff --git a/util/Makefile.objs b/util/Makefile.objs
|
|
Paolo Bonzini |
0fb2b2 |
index 50a55ecc75..c9e6c493d3 100644
|
|
Paolo Bonzini |
0fb2b2 |
--- a/util/Makefile.objs
|
|
Paolo Bonzini |
0fb2b2 |
+++ b/util/Makefile.objs
|
|
Paolo Bonzini |
0fb2b2 |
@@ -45,3 +45,4 @@ util-obj-y += qht.o
|
|
Paolo Bonzini |
0fb2b2 |
util-obj-y += range.o
|
|
Paolo Bonzini |
0fb2b2 |
util-obj-y += stats64.o
|
|
Paolo Bonzini |
0fb2b2 |
util-obj-y += systemd.o
|
|
Paolo Bonzini |
0fb2b2 |
+util-obj-y += scsi.o
|
|
Paolo Bonzini |
0fb2b2 |
diff --git a/util/scsi.c b/util/scsi.c
|
|
Paolo Bonzini |
0fb2b2 |
new file mode 100644
|
|
Paolo Bonzini |
0fb2b2 |
index 0000000000..a6710799fc
|
|
Paolo Bonzini |
0fb2b2 |
--- /dev/null
|
|
Paolo Bonzini |
0fb2b2 |
+++ b/util/scsi.c
|
|
Paolo Bonzini |
0fb2b2 |
@@ -0,0 +1,52 @@
|
|
Paolo Bonzini |
0fb2b2 |
+/*
|
|
Paolo Bonzini |
0fb2b2 |
+ * SCSI helpers
|
|
Paolo Bonzini |
0fb2b2 |
+ *
|
|
Paolo Bonzini |
0fb2b2 |
+ * Copyright 2017 Red Hat, Inc.
|
|
Paolo Bonzini |
0fb2b2 |
+ *
|
|
Paolo Bonzini |
0fb2b2 |
+ * Authors:
|
|
Paolo Bonzini |
0fb2b2 |
+ * Fam Zheng <famz@redhat.com>
|
|
Paolo Bonzini |
0fb2b2 |
+ *
|
|
Paolo Bonzini |
0fb2b2 |
+ * This program is free software; you can redistribute it and/or modify it
|
|
Paolo Bonzini |
0fb2b2 |
+ * under the terms of the GNU General Public License as published by the Free
|
|
Paolo Bonzini |
0fb2b2 |
+ * Software Foundation; either version 2 of the License, or (at your option)
|
|
Paolo Bonzini |
0fb2b2 |
+ * any later version.
|
|
Paolo Bonzini |
0fb2b2 |
+ */
|
|
Paolo Bonzini |
0fb2b2 |
+
|
|
Paolo Bonzini |
0fb2b2 |
+#include "qemu/osdep.h"
|
|
Paolo Bonzini |
0fb2b2 |
+#include "scsi/scsi.h"
|
|
Paolo Bonzini |
0fb2b2 |
+
|
|
Paolo Bonzini |
0fb2b2 |
+int scsi_sense_to_errno(int key, int asc, int ascq)
|
|
Paolo Bonzini |
0fb2b2 |
+{
|
|
Paolo Bonzini |
0fb2b2 |
+ switch (key) {
|
|
Paolo Bonzini |
0fb2b2 |
+ case 0x02: /* NOT READY */
|
|
Paolo Bonzini |
0fb2b2 |
+ return EBUSY;
|
|
Paolo Bonzini |
0fb2b2 |
+ case 0x07: /* DATA PROTECTION */
|
|
Paolo Bonzini |
0fb2b2 |
+ return EACCES;
|
|
Paolo Bonzini |
0fb2b2 |
+ case 0x0b: /* COMMAND ABORTED */
|
|
Paolo Bonzini |
0fb2b2 |
+ return ECANCELED;
|
|
Paolo Bonzini |
0fb2b2 |
+ case 0x05: /* ILLEGAL REQUEST */
|
|
Paolo Bonzini |
0fb2b2 |
+ /* Parse ASCQ */
|
|
Paolo Bonzini |
0fb2b2 |
+ break;
|
|
Paolo Bonzini |
0fb2b2 |
+ default:
|
|
Paolo Bonzini |
0fb2b2 |
+ return EIO;
|
|
Paolo Bonzini |
0fb2b2 |
+ }
|
|
Paolo Bonzini |
0fb2b2 |
+ switch ((asc << 8) | ascq) {
|
|
Paolo Bonzini |
0fb2b2 |
+ case 0x1a00: /* PARAMETER LIST LENGTH ERROR */
|
|
Paolo Bonzini |
0fb2b2 |
+ case 0x2000: /* INVALID OPERATION CODE */
|
|
Paolo Bonzini |
0fb2b2 |
+ case 0x2400: /* INVALID FIELD IN CDB */
|
|
Paolo Bonzini |
0fb2b2 |
+ case 0x2600: /* INVALID FIELD IN PARAMETER LIST */
|
|
Paolo Bonzini |
0fb2b2 |
+ return EINVAL;
|
|
Paolo Bonzini |
0fb2b2 |
+ case 0x2100: /* LBA OUT OF RANGE */
|
|
Paolo Bonzini |
0fb2b2 |
+ return ENOSPC;
|
|
Paolo Bonzini |
0fb2b2 |
+ case 0x2500: /* LOGICAL UNIT NOT SUPPORTED */
|
|
Paolo Bonzini |
0fb2b2 |
+ return ENOTSUP;
|
|
Paolo Bonzini |
0fb2b2 |
+ case 0x3a00: /* MEDIUM NOT PRESENT */
|
|
Paolo Bonzini |
0fb2b2 |
+ case 0x3a01: /* MEDIUM NOT PRESENT TRAY CLOSED */
|
|
Paolo Bonzini |
0fb2b2 |
+ case 0x3a02: /* MEDIUM NOT PRESENT TRAY OPEN */
|
|
Paolo Bonzini |
0fb2b2 |
+ return ENOMEDIUM;
|
|
Paolo Bonzini |
0fb2b2 |
+ case 0x2700: /* WRITE PROTECTED */
|
|
Paolo Bonzini |
0fb2b2 |
+ return EACCES;
|
|
Paolo Bonzini |
0fb2b2 |
+ default:
|
|
Paolo Bonzini |
0fb2b2 |
+ return EIO;
|
|
Paolo Bonzini |
0fb2b2 |
+ }
|
|
Paolo Bonzini |
0fb2b2 |
+}
|
|
Paolo Bonzini |
0fb2b2 |
--
|
|
Paolo Bonzini |
0fb2b2 |
2.13.5
|
|
Paolo Bonzini |
0fb2b2 |
|