aboutsummaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorFam Zheng <famz@redhat.com>2017-08-21 22:10:05 +0800
committerPaolo Bonzini <pbonzini@redhat.com>2017-09-19 14:09:11 +0200
commit2875135807771a0d07ba1c878c20b757ed7adffb (patch)
treec3ab331ddaadd8f5e9b2ed8beaaf1bbec9c5c0ef /block
parentb07fbce6349c7b84642e7ed56c7a1ac3c1caca61 (diff)
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 'block')
-rw-r--r--block/iscsi.c45
1 files changed, 4 insertions, 41 deletions
diff --git a/block/iscsi.c b/block/iscsi.c
index 8b47d30dcc..1e8ae5a8cf 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -40,6 +40,7 @@
#include "qmp-commands.h"
#include "qapi/qmp/qstring.h"
#include "crypto/secret.h"
+#include "scsi/scsi.h"
#include <iscsi/iscsi.h>
#include <iscsi/scsi-lowlevel.h>
@@ -209,47 +210,9 @@ static inline unsigned exp_random(double mean)
static int iscsi_translate_sense(struct scsi_sense *sense)
{
- int ret;
-
- switch (sense->key) {
- case SCSI_SENSE_NOT_READY:
- return -EBUSY;
- case SCSI_SENSE_DATA_PROTECTION:
- return -EACCES;
- case SCSI_SENSE_COMMAND_ABORTED:
- return -ECANCELED;
- case SCSI_SENSE_ILLEGAL_REQUEST:
- /* Parse ASCQ */
- break;
- default:
- return -EIO;
- }
- switch (sense->ascq) {
- case SCSI_SENSE_ASCQ_PARAMETER_LIST_LENGTH_ERROR:
- case SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE:
- case SCSI_SENSE_ASCQ_INVALID_FIELD_IN_CDB:
- case SCSI_SENSE_ASCQ_INVALID_FIELD_IN_PARAMETER_LIST:
- ret = -EINVAL;
- break;
- case SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE:
- ret = -ENOSPC;
- break;
- case SCSI_SENSE_ASCQ_LOGICAL_UNIT_NOT_SUPPORTED:
- ret = -ENOTSUP;
- break;
- case SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT:
- case SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED:
- case SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN:
- ret = -ENOMEDIUM;
- break;
- case SCSI_SENSE_ASCQ_WRITE_PROTECTED:
- ret = -EACCES;
- break;
- default:
- ret = -EIO;
- break;
- }
- return ret;
+ return - scsi_sense_to_errno(sense->key,
+ (sense->ascq & 0xFF00) >> 8,
+ sense->ascq & 0xFF);
}
/* Called (via iscsi_service) with QemuMutex held. */