peterdelevoryas / rpms / qemu

Forked from rpms/qemu 2 years ago
Clone

Blame 1005-scsi-Improve-scsi_sense_to_errno.patch

Paolo Bonzini 0fb2b2
From a7dc92dac7cedb3ba6b6d724c7579f05399e2f2e Mon Sep 17 00:00:00 2001
Paolo Bonzini 0fb2b2
From: Fam Zheng <famz@redhat.com>
Paolo Bonzini 0fb2b2
Date: Mon, 21 Aug 2017 22:10:06 +0800
Paolo Bonzini 0fb2b2
Subject: [PATCH 05/15] scsi: Improve scsi_sense_to_errno
Paolo Bonzini 0fb2b2
Paolo Bonzini 0fb2b2
Tweak the errno mapping to return more accurate/appropriate values.
Paolo Bonzini 0fb2b2
Paolo Bonzini 0fb2b2
Signed-off-by: Fam Zheng <famz@redhat.com>
Paolo Bonzini 0fb2b2
Message-Id: <20170821141008.19383-3-famz@redhat.com>
Paolo Bonzini 0fb2b2
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Paolo Bonzini 0fb2b2
---
Paolo Bonzini 0fb2b2
 util/scsi.c | 16 ++++++++++++----
Paolo Bonzini 0fb2b2
 1 file changed, 12 insertions(+), 4 deletions(-)
Paolo Bonzini 0fb2b2
Paolo Bonzini 0fb2b2
diff --git a/util/scsi.c b/util/scsi.c
Paolo Bonzini 0fb2b2
index a6710799fc..472eb5bea5 100644
Paolo Bonzini 0fb2b2
--- a/util/scsi.c
Paolo Bonzini 0fb2b2
+++ b/util/scsi.c
Paolo Bonzini 0fb2b2
@@ -18,13 +18,16 @@
Paolo Bonzini 0fb2b2
 int scsi_sense_to_errno(int key, int asc, int ascq)
Paolo Bonzini 0fb2b2
 {
Paolo Bonzini 0fb2b2
     switch (key) {
Paolo Bonzini 0fb2b2
-    case 0x02: /* NOT READY */
Paolo Bonzini 0fb2b2
-        return EBUSY;
Paolo Bonzini 0fb2b2
-    case 0x07: /* DATA PROTECTION */
Paolo Bonzini 0fb2b2
-        return EACCES;
Paolo Bonzini 0fb2b2
+    case 0x00: /* NO SENSE */
Paolo Bonzini 0fb2b2
+    case 0x01: /* RECOVERED ERROR */
Paolo Bonzini 0fb2b2
+    case 0x06: /* UNIT ATTENTION */
Paolo Bonzini 0fb2b2
+        /* These sense keys are not errors */
Paolo Bonzini 0fb2b2
+        return 0;
Paolo Bonzini 0fb2b2
     case 0x0b: /* COMMAND ABORTED */
Paolo Bonzini 0fb2b2
         return ECANCELED;
Paolo Bonzini 0fb2b2
+    case 0x02: /* NOT READY */
Paolo Bonzini 0fb2b2
     case 0x05: /* ILLEGAL REQUEST */
Paolo Bonzini 0fb2b2
+    case 0x07: /* DATA PROTECTION */
Paolo Bonzini 0fb2b2
         /* Parse ASCQ */
Paolo Bonzini 0fb2b2
         break;
Paolo Bonzini 0fb2b2
     default:
Paolo Bonzini 0fb2b2
@@ -37,6 +40,7 @@ int scsi_sense_to_errno(int key, int asc, int ascq)
Paolo Bonzini 0fb2b2
     case 0x2600: /* INVALID FIELD IN PARAMETER LIST */
Paolo Bonzini 0fb2b2
         return EINVAL;
Paolo Bonzini 0fb2b2
     case 0x2100: /* LBA OUT OF RANGE */
Paolo Bonzini 0fb2b2
+    case 0x2707: /* SPACE ALLOC FAILED */
Paolo Bonzini 0fb2b2
         return ENOSPC;
Paolo Bonzini 0fb2b2
     case 0x2500: /* LOGICAL UNIT NOT SUPPORTED */
Paolo Bonzini 0fb2b2
         return ENOTSUP;
Paolo Bonzini 0fb2b2
@@ -46,6 +50,10 @@ int scsi_sense_to_errno(int key, int asc, int ascq)
Paolo Bonzini 0fb2b2
         return ENOMEDIUM;
Paolo Bonzini 0fb2b2
     case 0x2700: /* WRITE PROTECTED */
Paolo Bonzini 0fb2b2
         return EACCES;
Paolo Bonzini 0fb2b2
+    case 0x0401: /* NOT READY, IN PROGRESS OF BECOMING READY */
Paolo Bonzini 0fb2b2
+        return EAGAIN;
Paolo Bonzini 0fb2b2
+    case 0x0402: /* NOT READY, INITIALIZING COMMAND REQUIRED */
Paolo Bonzini 0fb2b2
+        return ENOTCONN;
Paolo Bonzini 0fb2b2
     default:
Paolo Bonzini 0fb2b2
         return EIO;
Paolo Bonzini 0fb2b2
     }
Paolo Bonzini 0fb2b2
-- 
Paolo Bonzini 0fb2b2
2.13.5
Paolo Bonzini 0fb2b2