scsi-block: Support werror/rerror
Subsystems (2)
v4 cover scsi-block: Support werror/rerror
v4: Handle more sense keys/ascqs. [Paolo]
Add scsi_sense_buf_to_errno to util/scsi.c. [Paolo] Shorten the comment notes on SCSI constants.
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 (4):
scsi: Refactor scsi sense interpreting code
scsi: Improve scsi_sense_to_errno
scsi: Introduce scsi_sense_buf_to_errno
scsi-block: Support rerror/werror
MAINTAINERS | 2 ++ block/iscsi.c | 45 +++------------------------ hw/scsi/scsi-disk.c | 38 +++++++++++++--------- include/scsi/scsi.h | 20 ++++++++++++ util/Makefile.objs | 1 + util/scsi.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 141 insertions(+), 55 deletions(-) create mode 100644 include/scsi/scsi.h create mode 100644 util/scsi.c
Signature · 1 line
2.13.5
PATCH v4 1/4 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.5
Re: [Qemu-devel] [PATCH v4 1/4] scsi: Refactor scsi sense interpreting code
Quoted 4 lines · Fam Zheng
So that it can be reused outside of
iscsi.c.Also update
MAINTAINERSto include the new files in SCSI section.
Quoted 8 lines
Signed-off-by Fam Zheng <[email protected]>--- 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(-)
I've now introduced a more comprehensive scsi/utils.c. No need to do anything, I'll pick your file when I rebase the multipath patches I've just sent.
Paolo
PATCH v4 2/4 scsi: Improve scsi_sense_to_errno
In reply to Fam ZhengTweak the errno mapping to return more accurate/appropriate values.
--- util/scsi.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
util/scsi.c +12 -4
@@ -18,13 +18,16 @@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 ; }
Signature · 1 line
2.13.5
PATCH v4 3/4 scsi: Introduce scsi_sense_buf_to_errno
In reply to Fam ZhengThis recognizes the "fixed" and "descriptor" format sense data, extracts the sense key/asc/ascq fields then converts them to an errno.
--- include/scsi/scsi.h | 1 + util/scsi.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+)
include/scsi/scsi.h +1 -0
@@ -15,5 +15,6 @@#define QEMU_SCSI_H int scsi_sense_to_errno (int key,int asc,int ascq); +int scsi_sense_buf_to_errno (const uint8_t *sense,size_t sense_size);#endif
util/scsi.c +30 -0
@@ -58,3 +58,33 @@ int scsi_sense_to_errno(int key, int asc, int ascq)return EIO ; } } + +int scsi_sense_buf_to_errno (const uint8_t *sense,size_t sense_size) +{ +int key, asc, ascq; +if (sense_size <1 ) { +return EIO ; + } +switch (sense[0 ]) { +case 0x70 :/* Fixed format sense data. */ +if (sense_size <14 ) { +return EIO ; + } + key = sense[2 ] &0xF ; + asc = sense[12 ]; + ascq = sense[13 ]; +break ; +case 0x72 :/* Descriptor format sense data. */ +if (sense_size <4 ) { +return EIO ; + } + key = sense[1 ] &0xF ; + asc = sense[2 ]; + ascq = sense[3 ]; +break ; +default : +return EIO ; +break ; + } +return scsi_sense_to_errno (key, asc, ascq); +}
Signature · 1 line
2.13.5
PATCH v4 4/4 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 | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-)
hw/scsi/scsi-disk.c +24 -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,18 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error, bool acct_failed)break ; } } +if (!error) { +assert (r->status && *r->status); + error =scsi_sense_buf_to_errno (r->req.sense,sizeof (r->req.sense)); + +if (error ==ECANCELED || error ==EAGAIN || error ==ENOTCONN || + error ==0 ) { +/* These errors are handled by guest. */ +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 +2981,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.5
----- Original Message -----
Quoted 12 lines
From: "Fam Zheng" <[email protected]>
To: [email protected]
Cc: "Paolo Bonzini" <[email protected]>
Sent: Monday, August 21, 2017 4:10:04 PM
Subject: [PATCH v4 0/4] scsi-block: Support werror/rerrorv4: Handle more sense keys/ascqs. [Paolo]
Addscsi_sense_buf_to_errnotoutil/scsi.c. [Paolo] Shorten the comment notes on SCSI constants.v3: Enhance and reuse iscsi sense data translation. [Paolo]
Quoted 8 lines
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 (4):
scsi: Refactor scsi sense interpreting code
scsi: Improvescsi_sense_to_errno
scsi: Introducescsi_sense_buf_to_errno
scsi-block: Support rerror/werror
Looks good, thanks!
Paolo
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 v4 0/4] 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 Switched to a new branch 'test'2c3500c6c6 scsi-block: Support rerror/werror 05189062ee scsi: Introduce scsi_sense_buf_to_errno 71fe29752d scsi: Improve scsi_sense_to_errno e0bc108941 scsi: Refactor scsi sense interpreting code
=== OUTPUT BEGIN ===
Checking PATCH 1/4: 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/4: scsi: Improve scsi_sense_to_errno...
ERROR: return of an errno should typically be -ve (return -EAGAIN) #49: FILE: util/scsi.c:54:
+ return EAGAIN;
ERROR: return of an errno should typically be -ve (return -ENOTCONN) #51: FILE: util/scsi.c:56:
+ return ENOTCONN;
total: 2 errors, 0 warnings, 37 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 3/4: scsi: Introduce scsi_sense_buf_to_errno...
ERROR: return of an errno should typically be -ve (return -EIO) #36: FILE: util/scsi.c:66:
+ return EIO;
ERROR: return of an errno should typically be -ve (return -EIO) #41: FILE: util/scsi.c:71:
+ return EIO;
ERROR: return of an errno should typically be -ve (return -EIO) #49: FILE: util/scsi.c:79:
+ return EIO;
ERROR: return of an errno should typically be -ve (return -EIO) #56: FILE: util/scsi.c:86:
+ return EIO;
total: 4 errors, 0 warnings, 39 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 4/4: 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]