Commit 5efa3c04 authored by Fam Zheng's avatar Fam Zheng Committed by Paolo Bonzini

scsi: Improve scsi_sense_to_errno

Tweak the errno mapping to return more accurate/appropriate values.
Signed-off-by: 's avatarFam Zheng <famz@redhat.com>
Message-Id: <20170821141008.19383-3-famz@redhat.com>
Signed-off-by: 's avatarPaolo Bonzini <pbonzini@redhat.com>
parent 28751358
...@@ -18,13 +18,16 @@ ...@@ -18,13 +18,16 @@
int scsi_sense_to_errno(int key, int asc, int ascq) int scsi_sense_to_errno(int key, int asc, int ascq)
{ {
switch (key) { switch (key) {
case 0x02: /* NOT READY */ case 0x00: /* NO SENSE */
return EBUSY; case 0x01: /* RECOVERED ERROR */
case 0x07: /* DATA PROTECTION */ case 0x06: /* UNIT ATTENTION */
return EACCES; /* These sense keys are not errors */
return 0;
case 0x0b: /* COMMAND ABORTED */ case 0x0b: /* COMMAND ABORTED */
return ECANCELED; return ECANCELED;
case 0x02: /* NOT READY */
case 0x05: /* ILLEGAL REQUEST */ case 0x05: /* ILLEGAL REQUEST */
case 0x07: /* DATA PROTECTION */
/* Parse ASCQ */ /* Parse ASCQ */
break; break;
default: default:
...@@ -37,6 +40,7 @@ int scsi_sense_to_errno(int key, int asc, int ascq) ...@@ -37,6 +40,7 @@ int scsi_sense_to_errno(int key, int asc, int ascq)
case 0x2600: /* INVALID FIELD IN PARAMETER LIST */ case 0x2600: /* INVALID FIELD IN PARAMETER LIST */
return EINVAL; return EINVAL;
case 0x2100: /* LBA OUT OF RANGE */ case 0x2100: /* LBA OUT OF RANGE */
case 0x2707: /* SPACE ALLOC FAILED */
return ENOSPC; return ENOSPC;
case 0x2500: /* LOGICAL UNIT NOT SUPPORTED */ case 0x2500: /* LOGICAL UNIT NOT SUPPORTED */
return ENOTSUP; return ENOTSUP;
...@@ -46,6 +50,10 @@ int scsi_sense_to_errno(int key, int asc, int ascq) ...@@ -46,6 +50,10 @@ int scsi_sense_to_errno(int key, int asc, int ascq)
return ENOMEDIUM; return ENOMEDIUM;
case 0x2700: /* WRITE PROTECTED */ case 0x2700: /* WRITE PROTECTED */
return EACCES; return EACCES;
case 0x0401: /* NOT READY, IN PROGRESS OF BECOMING READY */
return EAGAIN;
case 0x0402: /* NOT READY, INITIALIZING COMMAND REQUIRED */
return ENOTCONN;
default: default:
return EIO; return EIO;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment