diff options
author | Paolo Bonzini | 2017-08-22 07:08:27 +0200 |
---|---|---|
committer | Paolo Bonzini | 2017-09-19 14:09:11 +0200 |
commit | e5b5728cd330f533e02e483af8973ad7ffccce8b (patch) | |
tree | f47dcecd074391ef42adfeae7d8d4fda94c69bcf /util | |
parent | scsi: rename scsi_build_sense to scsi_convert_sense (diff) | |
download | qemu-e5b5728cd330f533e02e483af8973ad7ffccce8b.tar.gz qemu-e5b5728cd330f533e02e483af8973ad7ffccce8b.tar.xz qemu-e5b5728cd330f533e02e483af8973ad7ffccce8b.zip |
scsi: move non-emulation specific code to scsi/
util/scsi.c includes some SCSI code that is shared by block/iscsi.c and
hw/scsi, but the introduction of the persistent reservation helper
will add many more instances of this. There is also include/block/scsi.h,
which actually is not part of the core block layer.
The persistent reservation manager will also need a home. A scsi/
directory provides one for both the aforementioned shared code and
the PR manager code.
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
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 | 90 |
2 files changed, 0 insertions, 91 deletions
diff --git a/util/Makefile.objs b/util/Makefile.objs index c9e6c493d3..50a55ecc75 100644 --- a/util/Makefile.objs +++ b/util/Makefile.objs @@ -45,4 +45,3 @@ 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 deleted file mode 100644 index 472293d59b..0000000000 --- a/util/scsi.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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 0x00: /* NO SENSE */ - case 0x01: /* RECOVERED ERROR */ - case 0x06: /* UNIT ATTENTION */ - /* These sense keys are not errors */ - return 0; - case 0x0b: /* COMMAND ABORTED */ - return ECANCELED; - case 0x02: /* NOT READY */ - case 0x05: /* ILLEGAL REQUEST */ - case 0x07: /* DATA PROTECTION */ - /* 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 */ - case 0x2707: /* SPACE ALLOC FAILED */ - 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; - case 0x0401: /* NOT READY, IN PROGRESS OF BECOMING READY */ - return EAGAIN; - case 0x0402: /* NOT READY, INITIALIZING COMMAND REQUIRED */ - return ENOTCONN; - default: - 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); -} |