diff mbox

[v3,2/3] scsi: Enhance scsi_sense_to_errno

Message ID 20170818141512.15205-3-famz@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Fam Zheng Aug. 18, 2017, 2:15 p.m. UTC
Two changes:

1) Look at asc/ascq for NOT_READY and DATA_PROTECT;
2) Translate SPACE_ALLOC_FAILED as ENOSPC;

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 util/scsi.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Comments

Paolo Bonzini Aug. 18, 2017, 2:36 p.m. UTC | #1
On 18/08/2017 16:15, Fam Zheng wrote:
> Two changes:
> 
> 1) Look at asc/ascq for NOT_READY and DATA_PROTECT;
> 2) Translate SPACE_ALLOC_FAILED as ENOSPC;
> 
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  util/scsi.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/util/scsi.c b/util/scsi.c
> index 92ca436cd0..d42ce33449 100644
> --- a/util/scsi.c
> +++ b/util/scsi.c
> @@ -18,13 +18,11 @@
>  int scsi_sense_to_errno(int key, int asc, int ascq)
>  {
>      switch (key) {
> -    case 0x02: /* SCSI_SENSE_NOT_READY */
> -        return EBUSY;
> -    case 0x07: /* SCSI_SENSE_DATA_PROTECTION */
> -        return EACCES;
>      case 0x0b: /* SCSI_SENSE_COMMAND_ABORTED */
>          return ECANCELED;
> +    case 0x02: /* SCSI_SENSE_NOT_READY */
>      case 0x05: /* SCSI_SENSE_ILLEGAL_REQUEST */
> +    case 0x07: /* SCSI_SENSE_DATA_PROTECTION */
>          /* Parse ASCQ */
>          break;
>      default:

UNIT_ATTENTION should also be passed down to the guest without stopping
the VM.  Maybe map it to EAGAIN?

Looking at what Linux does:

- RECOVERED_ERROR should just return 0

- 0x0401 is "unit in the process of becoming ready", and it should also
be EAGAIN

- 0x0402 is "initializing command required", and probably can be fixed
by the guest by scsi-block but not by iscsi so it should be its own
errno, maybe ENOTCONN?  (iscsi might try sending START STOP UNIT
followed by a bunch of TEST UNIT READYs, see scsi_eh_try_stu in Linux's
drivers/scsi/scsi_error.c).

Paolo

> @@ -37,6 +35,7 @@ int scsi_sense_to_errno(int key, int asc, int ascq)
>      case 0x2600: /* SCSI_SENSE_ASCQ_INVALID_FIELD_IN_PARAMETER_LIST */
>          return EINVAL;
>      case 0x2100: /* SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE */
> +    case 0x2707: /* SCSI_SENSE_ASCQ_SPACE_ALLOC_FAILED */
>          return ENOSPC;
>      case 0x2500: /* SCSI_SENSE_ASCQ_LOGICAL_UNIT_NOT_SUPPORTED */
>          return ENOTSUP;
>
Fam Zheng Aug. 21, 2017, 11:11 a.m. UTC | #2
On Fri, 08/18 16:36, Paolo Bonzini wrote:
> On 18/08/2017 16:15, Fam Zheng wrote:
> > Two changes:
> > 
> > 1) Look at asc/ascq for NOT_READY and DATA_PROTECT;
> > 2) Translate SPACE_ALLOC_FAILED as ENOSPC;
> > 
> > Signed-off-by: Fam Zheng <famz@redhat.com>
> > ---
> >  util/scsi.c | 7 +++----
> >  1 file changed, 3 insertions(+), 4 deletions(-)
> > 
> > diff --git a/util/scsi.c b/util/scsi.c
> > index 92ca436cd0..d42ce33449 100644
> > --- a/util/scsi.c
> > +++ b/util/scsi.c
> > @@ -18,13 +18,11 @@
> >  int scsi_sense_to_errno(int key, int asc, int ascq)
> >  {
> >      switch (key) {
> > -    case 0x02: /* SCSI_SENSE_NOT_READY */
> > -        return EBUSY;
> > -    case 0x07: /* SCSI_SENSE_DATA_PROTECTION */
> > -        return EACCES;
> >      case 0x0b: /* SCSI_SENSE_COMMAND_ABORTED */
> >          return ECANCELED;
> > +    case 0x02: /* SCSI_SENSE_NOT_READY */
> >      case 0x05: /* SCSI_SENSE_ILLEGAL_REQUEST */
> > +    case 0x07: /* SCSI_SENSE_DATA_PROTECTION */
> >          /* Parse ASCQ */
> >          break;
> >      default:
> 
> UNIT_ATTENTION should also be passed down to the guest without stopping
> the VM.  Maybe map it to EAGAIN?

Or just 0?

> 
> Looking at what Linux does:
> 
> - RECOVERED_ERROR should just return 0
> 
> - 0x0401 is "unit in the process of becoming ready", and it should also
> be EAGAIN
> 
> - 0x0402 is "initializing command required", and probably can be fixed
> by the guest by scsi-block but not by iscsi so it should be its own
> errno, maybe ENOTCONN?  (iscsi might try sending START STOP UNIT
> followed by a bunch of TEST UNIT READYs, see scsi_eh_try_stu in Linux's
> drivers/scsi/scsi_error.c).

These makes sense to me.

Fam
Paolo Bonzini Aug. 21, 2017, 11:30 a.m. UTC | #3
On 21/08/2017 13:11, Fam Zheng wrote:
> On Fri, 08/18 16:36, Paolo Bonzini wrote:
>> On 18/08/2017 16:15, Fam Zheng wrote:
>>> Two changes:
>>>
>>> 1) Look at asc/ascq for NOT_READY and DATA_PROTECT;
>>> 2) Translate SPACE_ALLOC_FAILED as ENOSPC;
>>>
>>> Signed-off-by: Fam Zheng <famz@redhat.com>
>>> ---
>>>  util/scsi.c | 7 +++----
>>>  1 file changed, 3 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/util/scsi.c b/util/scsi.c
>>> index 92ca436cd0..d42ce33449 100644
>>> --- a/util/scsi.c
>>> +++ b/util/scsi.c
>>> @@ -18,13 +18,11 @@
>>>  int scsi_sense_to_errno(int key, int asc, int ascq)
>>>  {
>>>      switch (key) {
>>> -    case 0x02: /* SCSI_SENSE_NOT_READY */
>>> -        return EBUSY;
>>> -    case 0x07: /* SCSI_SENSE_DATA_PROTECTION */
>>> -        return EACCES;
>>>      case 0x0b: /* SCSI_SENSE_COMMAND_ABORTED */
>>>          return ECANCELED;
>>> +    case 0x02: /* SCSI_SENSE_NOT_READY */
>>>      case 0x05: /* SCSI_SENSE_ILLEGAL_REQUEST */
>>> +    case 0x07: /* SCSI_SENSE_DATA_PROTECTION */
>>>          /* Parse ASCQ */
>>>          break;
>>>      default:
>>
>> UNIT_ATTENTION should also be passed down to the guest without stopping
>> the VM.  Maybe map it to EAGAIN?
> 
> Or just 0?

That works too, it depends on how you define 0.  1h is defined as
informational only and can be dropped, 0x0401 or UNIT_ATTENTION
definitely cannot.

Paolo

>>
>> Looking at what Linux does:
>>
>> - RECOVERED_ERROR should just return 0
>>
>> - 0x0401 is "unit in the process of becoming ready", and it should also
>> be EAGAIN
>>
>> - 0x0402 is "initializing command required", and probably can be fixed
>> by the guest by scsi-block but not by iscsi so it should be its own
>> errno, maybe ENOTCONN?  (iscsi might try sending START STOP UNIT
>> followed by a bunch of TEST UNIT READYs, see scsi_eh_try_stu in Linux's
>> drivers/scsi/scsi_error.c).
> 
> These makes sense to me.
> 
> Fam
>
diff mbox

Patch

diff --git a/util/scsi.c b/util/scsi.c
index 92ca436cd0..d42ce33449 100644
--- a/util/scsi.c
+++ b/util/scsi.c
@@ -18,13 +18,11 @@ 
 int scsi_sense_to_errno(int key, int asc, int ascq)
 {
     switch (key) {
-    case 0x02: /* SCSI_SENSE_NOT_READY */
-        return EBUSY;
-    case 0x07: /* SCSI_SENSE_DATA_PROTECTION */
-        return EACCES;
     case 0x0b: /* SCSI_SENSE_COMMAND_ABORTED */
         return ECANCELED;
+    case 0x02: /* SCSI_SENSE_NOT_READY */
     case 0x05: /* SCSI_SENSE_ILLEGAL_REQUEST */
+    case 0x07: /* SCSI_SENSE_DATA_PROTECTION */
         /* Parse ASCQ */
         break;
     default:
@@ -37,6 +35,7 @@  int scsi_sense_to_errno(int key, int asc, int ascq)
     case 0x2600: /* SCSI_SENSE_ASCQ_INVALID_FIELD_IN_PARAMETER_LIST */
         return EINVAL;
     case 0x2100: /* SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE */
+    case 0x2707: /* SCSI_SENSE_ASCQ_SPACE_ALLOC_FAILED */
         return ENOSPC;
     case 0x2500: /* SCSI_SENSE_ASCQ_LOGICAL_UNIT_NOT_SUPPORTED */
         return ENOTSUP;