scsi-block: Support werror/rerror
Subsystems (2)
v3 cover scsi-block: Support werror/rerror
v3: Enhance and reuse iscsi sense data translation. [Paolo]
First refactor and enhance the code in iscsi for sense data translation, then modify error handing of scsi-block and expose the qdev properties.
Fam Zheng (3):
scsi: Refactor scsi sense interpreting code
scsi: Enhance scsi_sense_to_errno
scsi-block: Support rerror/werror
MAINTAINERS | 2 ++ block/iscsi.c | 45 ++++---------------------------------------- hw/scsi/scsi-disk.c | 54 +++++++++++++++++++++++++++++++++++++++-------------- include/scsi/scsi.h | 19 +++++++++++++++++++ util/Makefile.objs | 1 + util/scsi.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 117 insertions(+), 55 deletions(-) create mode 100644 include/scsi/scsi.h create mode 100644 util/scsi.c
Signature · 1 line
2.13.4
PATCH v3 1/3 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.
--- MAINTAINERS | 2 ++ block/iscsi.c | 45 ++++----------------------------------------- include/scsi/scsi.h | 19 +++++++++++++++++++ util/Makefile.objs | 1 + util/scsi.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 78 insertions(+), 41 deletions(-) create mode 100644 include/scsi/scsi.h create mode 100644 util/scsi.c
MAINTAINERS +2 -0
@@ -969,7 +969,9 @@ SCSI M: Paolo Bonzini <[email protected]> S: Supported F: include/hw/scsi/* +F: include/scsi/* F: hw/scsi/* +F: util/scsi* F: tests/virtio-scsi-test.c T: git git://github.com/bonzini/qemu.git scsi-next
block/iscsi.c +4 -41
57 lines not on this page · raw message
include/scsi/scsi.h new file +19 -0
@@ -0,0 +1,19 @@ +/* +* SCSI helpers +* +* Copyright 2017 Red Hat, Inc. +* +* Authors: +* Fam Zheng <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the Free +* Software Foundation; either version 2 of the License, or (at your option) +* any later version. +*/ +#ifndef QEMU_SCSI_H +#define QEMU_SCSI_H + +int scsi_sense_to_errno (int key,int asc,int ascq); + +#endif
util/Makefile.objs +1 -0
@@ -45,3 +45,4 @@ util-obj-y += qht.o util-obj-y += range.o util-obj-y += stats64.o util-obj-y += systemd.o +util-obj-y += scsi.o
util/scsi.c new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
2.13.4
PATCH v3 2/3 scsi: Enhance scsi_sense_to_errno
In reply to Fam ZhengTwo changes:
1) Look at asc/ascq for NOT_READY and DATA_PROTECT;
2) Translate SPACE_ALLOC_FAILED as ENOSPC;
--- util/scsi.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
util/scsi.c +3 -4
@@ -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 ;
Signature · 1 line
2.13.4
Re: [Qemu-devel] [PATCH v3 2/3] scsi: Enhance scsi_sense_to_errno
Quoted 20 lines · Fam Zheng
Two changes:
1) Look at asc/ascq for
NOT_READYandDATA_PROTECT;
2) TranslateSPACE_ALLOC_FAILEDas ENOSPC;Signed-off-by Fam Zheng <[email protected]>--- util/scsi.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)util/scsi.c +0
-2@@ -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 ;
util/scsi.c line 28
Quoted 10 lines
util/scsi.c +2
-2-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
Quoted 9 lines
util/scsi.c +1
-0@@ -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 ;
Re: [Qemu-devel] [PATCH v3 2/3] scsi: Enhance scsi_sense_to_errno
Quoted 26 lines · Paolo Bonzini
Quoted 25 lines · Fam Zheng
Two changes:
1) Look at asc/ascq for
NOT_READYandDATA_PROTECT;
2) TranslateSPACE_ALLOC_FAILEDas ENOSPC;Signed-off-by Fam Zheng <[email protected]>--- util/scsi.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)util/scsi.c +1
-4@@ -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 */
Quoted 8 lines
util/scsi.c line 28
Quoted 5 lines
util/scsi.c +1
-0case 0x05 :/* SCSI_SENSE_ILLEGAL_REQUEST */ +case 0x07 :/* SCSI_SENSE_DATA_PROTECTION */ /* Parse ASCQ */ break ;default :
UNIT_ATTENTIONshould also be passed down to the guest without stopping the VM. Maybe map it to EAGAIN?
Or just 0?
Quoted 5 lines
Looking at what Linux does:
-
RECOVERED_ERRORshould just return 0
Quoted 8 lines
-
0x0401is "unit in the process of becoming ready", and it should also be EAGAIN-
0x0402is "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, seescsi_eh_try_stuin Linux'sdrivers/scsi/scsi_error.c).
These makes sense to me.
Fam
Re: [Qemu-devel] [PATCH v3 2/3] scsi: Enhance scsi_sense_to_errno
Quoted 36 lines · Fam Zheng
Quoted 26 lines · Paolo Bonzini
Quoted 25 lines · Fam Zheng
Two changes:
1) Look at asc/ascq for
NOT_READYandDATA_PROTECT;
2) TranslateSPACE_ALLOC_FAILEDas ENOSPC;Signed-off-by Fam Zheng <[email protected]>--- util/scsi.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)util/scsi.c +1
-4@@ -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 */ Quoted 8 lines
util/scsi.c line 28
Quoted 5 lines
util/scsi.c +1
-0case 0x05 :/* SCSI_SENSE_ILLEGAL_REQUEST */ +case 0x07 :/* SCSI_SENSE_DATA_PROTECTION */ /* Parse ASCQ */ break ;default :
UNIT_ATTENTIONshould also be passed down to the guest without stopping the VM. Maybe map it to EAGAIN?
Quoted 1 line
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
Quoted 18 lines
Quoted 5 lines
Looking at what Linux does:
-
RECOVERED_ERRORshould just return 0Quoted 8 lines
-
0x0401is "unit in the process of becoming ready", and it should also be EAGAIN-
0x0402is "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, seescsi_eh_try_stuin Linux'sdrivers/scsi/scsi_error.c).These makes sense to me.
Fam
PATCH v3 3/3 scsi-block: Support rerror/werror
In reply to Fam ZhengThis makes the werror/rerror options available on the scsi-block device, to allow user specify error handling policy similar to scsi-hd.
--- hw/scsi/scsi-disk.c | 54 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 14 deletions(-)
hw/scsi/scsi-disk.c +40 -14
@@ -39,6 +39,7 @@ do { printf("scsi-disk: " fmt , ## __VA_ARGS__); } while (0)#include "hw/block/block.h" #include "sysemu/dma.h" #include "qemu/cutils.h" +#include "scsi/scsi.h" #ifdef __linux#include <scsi/sg.h>
@@ -106,7 +107,7 @@ typedef struct SCSIDiskStatebool tray_locked; } SCSIDiskState; -static int scsi_handle_rw_error (SCSIDiskReq *r,int error,bool acct_failed); +static bool scsi_handle_rw_error (SCSIDiskReq *r,int error,bool acct_failed);static void scsi_free_request (SCSIRequest *req) {
@@ -184,19 +185,10 @@ static bool scsi_disk_req_check_error(SCSIDiskReq *r, int ret, bool acct_failed)return true; } -if (ret <0 ) { +if (ret <0 || (r->status && *r->status)) {return scsi_handle_rw_error (r, -ret, acct_failed); } -if (r->status && *r->status) { -if (acct_failed) { -SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, r->req.dev); -block_acct_failed (blk_get_stats (s->qdev.conf.blk), &r->acct); - } -scsi_req_complete (&r->req, *r->status); -return true; - } -return false; }
@@ -422,13 +414,13 @@ static void scsi_read_data(SCSIRequest *req) }/* -* scsi_handle_rw_error has two return values. 0 means that the error -* must be ignored, 1 means that the error has been processed and the +* scsi_handle_rw_error has two return values. False means that the error +* must be ignored, true means that the error has been processed and the * caller should not do anything else for this request. Note that * scsi_handle_rw_error always manages its reference counts, independent * of the return value. */ -static int scsi_handle_rw_error (SCSIDiskReq *r,int error,bool acct_failed) +static bool scsi_handle_rw_error (SCSIDiskReq *r,int error,bool acct_failed) {bool is_read = (r->req.cmd.mode ==SCSI_XFER_FROM_DEV );SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, r->req.dev);
@@ -440,6 +432,11 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error, bool acct_failed)block_acct_failed (blk_get_stats (s->qdev.conf.blk), &r->acct); }switch (error) { +case 0 : +/* The command has run, no need to fake sense. */ +assert (r->status && *r->status); +scsi_req_complete (&r->req, *r->status); +break ;case ENOMEDIUM :scsi_check_condition (r,SENSE_CODE (NO_MEDIUM ));break ;
@@ -457,6 +454,34 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error, bool acct_failed)break ; } } +if (!error) { +int key, asc, ascq; +assert (r->status && *r->status); +switch (r->req.sense[0 ]) { +case 0x70 :/* Fixed format sense data. */ + key = r->req.sense[2 ] &0xF ; + asc = r->req.sense[12 ]; + ascq = r->req.sense[13 ]; + error =scsi_sense_to_errno (key, asc, ascq); +break ; +case 0x72 :/* Descriptor format sense data. */ + key = r->req.sense[1 ] &0xF ; + asc = r->req.sense[2 ]; + ascq = r->req.sense[3 ]; + error =scsi_sense_to_errno (key, asc, ascq); +break ; +default : + error =EIO ; +break ; + } + +if (error ==ECANCELED ) { +/* Command aborted shouldn't stop the VM. */ +scsi_req_complete (&r->req, *r->status); +return true; + } + } +blk_error_action (s->qdev.conf.blk, action, is_read, error);if (action ==BLOCK_ERROR_ACTION_STOP ) {scsi_req_retry (&r->req);
@@ -2972,6 +2997,7 @@ static const TypeInfo scsi_cd_info = {#ifdef __linux__static Property scsi_block_properties[] = { +DEFINE_BLOCK_ERROR_PROPERTIES (SCSIDiskState, qdev.conf), \DEFINE_PROP_DRIVE ("drive" , SCSIDiskState, qdev.conf.blk),DEFINE_PROP_END_OF_LIST (), };
Signature · 1 line
2.13.4
Re: [Qemu-devel] [PATCH v3 3/3] scsi-block: Support rerror/werror
Quoted 93 lines · Fam Zheng
This makes the werror/rerror options available on the scsi-block device, to allow user specify error handling policy similar to scsi-hd.
Signed-off-by Fam Zheng <[email protected]>--- hw/scsi/scsi-disk.c | 54 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 14 deletions(-)hw/scsi/scsi-disk.c +21
-14@@ -39,6 +39,7 @@ do { printf("scsi-disk: " fmt , ## __VA_ARGS__); } while (0)#include "hw/block/block.h" #include "sysemu/dma.h" #include "qemu/cutils.h" +#include "scsi/scsi.h" #ifdef __linux#include <scsi/sg.h> @@ -106,7 +107,7 @@ typedef struct SCSIDiskStatebool tray_locked; } SCSIDiskState; -static int scsi_handle_rw_error (SCSIDiskReq *r,int error,bool acct_failed); +static bool scsi_handle_rw_error (SCSIDiskReq *r,int error,bool acct_failed);static void scsi_free_request (SCSIRequest *req) {@@ -184,19 +185,10 @@ static bool scsi_disk_req_check_error(SCSIDiskReq *r, int ret, bool acct_failed)return true; } -if (ret <0 ) { +if (ret <0 || (r->status && *r->status)) {return scsi_handle_rw_error (r, -ret, acct_failed); } -if (r->status && *r->status) { -if (acct_failed) { -SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, r->req.dev); -block_acct_failed (blk_get_stats (s->qdev.conf.blk), &r->acct); - } -scsi_req_complete (&r->req, *r->status); -return true; - } -return false; }@@ -422,13 +414,13 @@ static void scsi_read_data(SCSIRequest *req) }/* -* scsi_handle_rw_error has two return values. 0 means that the error -* must be ignored, 1 means that the error has been processed and the +* scsi_handle_rw_error has two return values. False means that the error +* must be ignored, true means that the error has been processed and the * caller should not do anything else for this request. Note that * scsi_handle_rw_error always manages its reference counts, independent * of the return value. */ -static int scsi_handle_rw_error (SCSIDiskReq *r,int error,bool acct_failed) +static bool scsi_handle_rw_error (SCSIDiskReq *r,int error,bool acct_failed) {bool is_read = (r->req.cmd.mode ==SCSI_XFER_FROM_DEV );SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, r->req.dev);@@ -440,6 +432,11 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error, bool acct_failed)block_acct_failed (blk_get_stats (s->qdev.conf.blk), &r->acct); }switch (error) { +case 0 : +/* The command has run, no need to fake sense. */ +assert (r->status && *r->status); +scsi_req_complete (&r->req, *r->status); +break ;case ENOMEDIUM :scsi_check_condition (r,SENSE_CODE (NO_MEDIUM ));break ;@@ -457,6 +454,34 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error, bool acct_failed)break ; } } +if (!error) { +int key, asc, ascq; +assert (r->status && *r->status); +switch (r->req.sense[0 ]) { +case 0x70 :/* Fixed format sense data. */ + key = r->req.sense[2 ] &0xF ; + asc = r->req.sense[12 ]; + ascq = r->req.sense[13 ]; + error =scsi_sense_to_errno (key, asc, ascq); +break ;
hw/scsi/scsi-disk.c static int scsi_handle_rw_error(SCSIDiskReq *r, int error, bool acct_failed) · line 476
Quoted 10 lines
hw/scsi/scsi-disk.c +10
-0+case 0x72 :/* Descriptor format sense data. */ + key = r->req.sense[1 ] &0xF ; + asc = r->req.sense[2 ]; + ascq = r->req.sense[3 ]; + error =scsi_sense_to_errno (key, asc, ascq); +break ; +default : + error =EIO ; +break ; + }
Maybe this switch statement should also be a function in util/iscsi.c (scsi_sense_buf_to_errno)?
hw/scsi/scsi-disk.c static int scsi_handle_rw_error(SCSIDiskReq *r, int error, bool acct_failed) · line 478
Quoted 2 lines
hw/scsi/scsi-disk.c +2
-0+ +if (error ==ECANCELED ) {
... || error == EAGAIN || error == ENOTCONN || error == 0
?
Quoted 18 lines
hw/scsi/scsi-disk.c +7
-0+/* Command aborted shouldn't stop the VM. */ +scsi_req_complete (&r->req, *r->status); +return true; + } + } +blk_error_action (s->qdev.conf.blk, action, is_read, error);if (action ==BLOCK_ERROR_ACTION_STOP ) {scsi_req_retry (&r->req);@@ -2972,6 +2997,7 @@ static const TypeInfo scsi_cd_info = {#ifdef __linux__static Property scsi_block_properties[] = { +DEFINE_BLOCK_ERROR_PROPERTIES (SCSIDiskState, qdev.conf), \DEFINE_PROP_DRIVE ("drive" , SCSIDiskState, qdev.conf.blk),DEFINE_PROP_END_OF_LIST (), };
This series seems to have some coding style problems. See output below for more information:
Hi,
This series seems to have some coding style problems. See output below for more information:
Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH v3 0/3] scsi-block: Support werror/rerror
=== TEST SCRIPT BEGIN ===
#!/bin/bash
BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0
git config --local diff.renamelimit 0
git config --local diff.renames True
commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))done
exit $failed
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'5097d927de scsi-block: Support rerror/werror d2c536a47c scsi: Enhance scsi_sense_to_errno 17642e9a8e scsi: Refactor scsi sense interpreting code
=== OUTPUT BEGIN ===
Checking PATCH 1/3: scsi: Refactor scsi sense interpreting code...
ERROR: space prohibited after that '-' (ctx:WxW)
#84: FILE: block/iscsi.c:213:
+ return - scsi_sense_to_errno(sense->key,
^
ERROR: return of an errno should typically be -ve (return -EBUSY) #151: FILE: util/scsi.c:22:
+ return EBUSY;
ERROR: return of an errno should typically be -ve (return -EACCES) #153: FILE: util/scsi.c:24:
+ return EACCES;
ERROR: return of an errno should typically be -ve (return -ECANCELED) #155: FILE: util/scsi.c:26:
+ return ECANCELED;
ERROR: return of an errno should typically be -ve (return -EIO) #160: FILE: util/scsi.c:31:
+ return EIO;
ERROR: return of an errno should typically be -ve (return -EINVAL) #167: FILE: util/scsi.c:38:
+ return EINVAL;
ERROR: return of an errno should typically be -ve (return -ENOSPC) #169: FILE: util/scsi.c:40:
+ return ENOSPC;
ERROR: return of an errno should typically be -ve (return -ENOTSUP) #171: FILE: util/scsi.c:42:
+ return ENOTSUP;
ERROR: return of an errno should typically be -ve (return -ENOMEDIUM) #175: FILE: util/scsi.c:46:
+ return ENOMEDIUM;
ERROR: return of an errno should typically be -ve (return -EACCES) #177: FILE: util/scsi.c:48:
+ return EACCES;
ERROR: return of an errno should typically be -ve (return -EIO) #179: FILE: util/scsi.c:50:
+ return EIO;
total: 11 errors, 0 warnings, 141 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 2/3: scsi: Enhance scsi_sense_to_errno... Checking PATCH 3/3: scsi-block: Support rerror/werror... === OUTPUT END ===
Test command exited with code: 1
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]