diff options
author | Fam Zheng | 2017-08-21 16:10:05 +0200 |
---|---|---|
committer | Paolo Bonzini | 2017-09-19 14:09:11 +0200 |
commit | 2875135807771a0d07ba1c878c20b757ed7adffb (patch) | |
tree | c3ab331ddaadd8f5e9b2ed8beaaf1bbec9c5c0ef /util | |
parent | scsi-bus: correct responses for INQUIRY and REQUEST SENSE (diff) | |
download | qemu-2875135807771a0d07ba1c878c20b757ed7adffb.tar.gz qemu-2875135807771a0d07ba1c878c20b757ed7adffb.tar.xz qemu-2875135807771a0d07ba1c878c20b757ed7adffb.zip |
scsi: Refactor scsi sense interpreting code
So that it can be reused outside of iscsi.c.
Also update MAINTAINERS to include the new files in SCSI section.
Signed-off-by: Fam Zheng <famz@redhat.com>
Message-Id: <20170821141008.19383-2-famz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'util')
-rw-r--r-- | util/Makefile.objs | 1 | ||||
-rw-r--r-- | util/scsi.c | 52 |
2 files changed, 53 insertions, 0 deletions
diff --git a/util/Makefile.objs b/util/Makefile.objs index 50a55ecc75..c9e6c493d3 100644 --- a/util/Makefile.objs +++ b/util/Makefile.objs @@ -45,3 +45,4 @@ util-obj-y += qht.o util-obj-y += range.o util-obj-y += stats64.o util-obj-y += systemd.o +util-obj-y += scsi.o diff --git a/util/scsi.c b/util/scsi.c new file mode 100644 index 0000000000..a6710799fc --- /dev/null +++ b/util/scsi.c @@ -0,0 +1,52 @@ +/* + * SCSI helpers + * + * Copyright 2017 Red Hat, Inc. + * + * Authors: + * Fam Zheng <famz@redhat.com> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + */ + +#include "qemu/osdep.h" +#include "scsi/scsi.h" + +int scsi_sense_to_errno(int key, int asc, int ascq) +{ + switch (key) { + case 0x02: /* NOT READY */ + return EBUSY; + case 0x07: /* DATA PROTECTION */ + return EACCES; + case 0x0b: /* COMMAND ABORTED */ + return ECANCELED; + case 0x05: /* ILLEGAL REQUEST */ + /* Parse ASCQ */ + break; + default: + return EIO; + } + switch ((asc << 8) | ascq) { + case 0x1a00: /* PARAMETER LIST LENGTH ERROR */ + case 0x2000: /* INVALID OPERATION CODE */ + case 0x2400: /* INVALID FIELD IN CDB */ + case 0x2600: /* INVALID FIELD IN PARAMETER LIST */ + return EINVAL; + case 0x2100: /* LBA OUT OF RANGE */ + return ENOSPC; + case 0x2500: /* LOGICAL UNIT NOT SUPPORTED */ + return ENOTSUP; + case 0x3a00: /* MEDIUM NOT PRESENT */ + case 0x3a01: /* MEDIUM NOT PRESENT TRAY CLOSED */ + case 0x3a02: /* MEDIUM NOT PRESENT TRAY OPEN */ + return ENOMEDIUM; + case 0x2700: /* WRITE PROTECTED */ + return EACCES; + default: + return EIO; + } +} |