]> git.proxmox.com Git - mirror_qemu.git/commitdiff
scsi: Improve scsi_sense_to_errno
authorFam Zheng <famz@redhat.com>
Mon, 21 Aug 2017 14:10:06 +0000 (22:10 +0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 19 Sep 2017 12:09:11 +0000 (14:09 +0200)
Tweak the errno mapping to return more accurate/appropriate values.

Signed-off-by: Fam Zheng <famz@redhat.com>
Message-Id: <20170821141008.19383-3-famz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
util/scsi.c

index a6710799fc05cdc2222eec7dafe0b67e79c739c0..472eb5bea50a41db521d67a81f43d334b92bc094 100644 (file)
 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 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:
@@ -37,6 +40,7 @@ int scsi_sense_to_errno(int key, int asc, int ascq)
     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;
@@ -46,6 +50,10 @@ int scsi_sense_to_errno(int key, int asc, int ascq)
         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;
     }