* [Qemu-devel] [PATCH v3 0/3] scsi-block: Support werror/rerror
@ 2017-08-18 14:15 Fam Zheng
2017-08-18 14:15 ` [Qemu-devel] [PATCH v3 1/3] scsi: Refactor scsi sense interpreting code Fam Zheng
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Fam Zheng @ 2017-08-18 14:15 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini
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
--
2.13.4
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Qemu-devel] [PATCH v3 1/3] scsi: Refactor scsi sense interpreting code
2017-08-18 14:15 [Qemu-devel] [PATCH v3 0/3] scsi-block: Support werror/rerror Fam Zheng
@ 2017-08-18 14:15 ` Fam Zheng
2017-08-18 14:15 ` [Qemu-devel] [PATCH v3 2/3] scsi: Enhance scsi_sense_to_errno Fam Zheng
` (2 subsequent siblings)
3 siblings, 0 replies; 9+ messages in thread
From: Fam Zheng @ 2017-08-18 14:15 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini
So that it can be reused outside of iscsi.c.
Also update MAINTAINERS to include the new files in SCSI section.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
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
diff --git a/MAINTAINERS b/MAINTAINERS
index ccee28b12d..2a4e5036ae 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -969,7 +969,9 @@ SCSI
M: Paolo Bonzini <pbonzini@redhat.com>
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
diff --git a/block/iscsi.c b/block/iscsi.c
index d557c99668..4bed63cd6d 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -40,6 +40,7 @@
#include "qmp-commands.h"
#include "qapi/qmp/qstring.h"
#include "crypto/secret.h"
+#include "scsi/scsi.h"
#include <iscsi/iscsi.h>
#include <iscsi/scsi-lowlevel.h>
@@ -209,47 +210,9 @@ static inline unsigned exp_random(double mean)
static int iscsi_translate_sense(struct scsi_sense *sense)
{
- int ret;
-
- switch (sense->key) {
- case SCSI_SENSE_NOT_READY:
- return -EBUSY;
- case SCSI_SENSE_DATA_PROTECTION:
- return -EACCES;
- case SCSI_SENSE_COMMAND_ABORTED:
- return -ECANCELED;
- case SCSI_SENSE_ILLEGAL_REQUEST:
- /* Parse ASCQ */
- break;
- default:
- return -EIO;
- }
- switch (sense->ascq) {
- case SCSI_SENSE_ASCQ_PARAMETER_LIST_LENGTH_ERROR:
- case SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE:
- case SCSI_SENSE_ASCQ_INVALID_FIELD_IN_CDB:
- case SCSI_SENSE_ASCQ_INVALID_FIELD_IN_PARAMETER_LIST:
- ret = -EINVAL;
- break;
- case SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE:
- ret = -ENOSPC;
- break;
- case SCSI_SENSE_ASCQ_LOGICAL_UNIT_NOT_SUPPORTED:
- ret = -ENOTSUP;
- break;
- case SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT:
- case SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED:
- case SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN:
- ret = -ENOMEDIUM;
- break;
- case SCSI_SENSE_ASCQ_WRITE_PROTECTED:
- ret = -EACCES;
- break;
- default:
- ret = -EIO;
- break;
- }
- return ret;
+ return - scsi_sense_to_errno(sense->key,
+ (sense->ascq & 0xFF00) >> 8,
+ sense->ascq & 0xFF);
}
/* Called (via iscsi_service) with QemuMutex held. */
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
new file mode 100644
index 0000000000..f894ace4bf
--- /dev/null
+++ b/include/scsi/scsi.h
@@ -0,0 +1,19 @@
+/*
+ * SCSI helpers
+ *
+ * Copyright 2017 Red Hat, Inc.
+ *
+ * Authors:
+ * Fam Zheng <famz@redhat.com>
+ *
+ * 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
diff --git a/util/Makefile.objs b/util/Makefile.objs
index 50a55ecc75..c9e6c493d3 100644
--- a/util/Makefile.objs
+++ b/util/Makefile.objs
@@ -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
diff --git a/util/scsi.c b/util/scsi.c
new file mode 100644
index 0000000000..92ca436cd0
--- /dev/null
+++ b/util/scsi.c
@@ -0,0 +1,52 @@
+/*
+ * SCSI helpers
+ *
+ * Copyright 2017 Red Hat, Inc.
+ *
+ * Authors:
+ * Fam Zheng <famz@redhat.com>
+ *
+ * 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.
+ */
+
+#include "qemu/osdep.h"
+#include "scsi/scsi.h"
+
+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 0x05: /* SCSI_SENSE_ILLEGAL_REQUEST */
+ /* Parse ASCQ */
+ break;
+ default:
+ return EIO;
+ }
+ switch ((asc << 8) | ascq) {
+ case 0x1a00: /* SCSI_SENSE_ASCQ_PARAMETER_LIST_LENGTH_ERROR */
+ case 0x2000: /* SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE */
+ case 0x2400: /* SCSI_SENSE_ASCQ_INVALID_FIELD_IN_CDB */
+ case 0x2600: /* SCSI_SENSE_ASCQ_INVALID_FIELD_IN_PARAMETER_LIST */
+ return EINVAL;
+ case 0x2100: /* SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE */
+ return ENOSPC;
+ case 0x2500: /* SCSI_SENSE_ASCQ_LOGICAL_UNIT_NOT_SUPPORTED */
+ return ENOTSUP;
+ case 0x3a00: /* SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT */
+ case 0x3a01: /* SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED */
+ case 0x3a02: /* SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN */
+ return ENOMEDIUM;
+ case 0x2700: /* SCSI_SENSE_ASCQ_WRITE_PROTECTED */
+ return EACCES;
+ default:
+ return EIO;
+ }
+}
--
2.13.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [Qemu-devel] [PATCH v3 2/3] scsi: Enhance scsi_sense_to_errno
2017-08-18 14:15 [Qemu-devel] [PATCH v3 0/3] scsi-block: Support werror/rerror Fam Zheng
2017-08-18 14:15 ` [Qemu-devel] [PATCH v3 1/3] scsi: Refactor scsi sense interpreting code Fam Zheng
@ 2017-08-18 14:15 ` Fam Zheng
2017-08-18 14:36 ` Paolo Bonzini
2017-08-18 14:15 ` [Qemu-devel] [PATCH v3 3/3] scsi-block: Support rerror/werror Fam Zheng
2017-08-18 14:39 ` [Qemu-devel] [PATCH v3 0/3] scsi-block: Support werror/rerror no-reply
3 siblings, 1 reply; 9+ messages in thread
From: Fam Zheng @ 2017-08-18 14:15 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini
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:
@@ -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;
--
2.13.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [Qemu-devel] [PATCH v3 3/3] scsi-block: Support rerror/werror
2017-08-18 14:15 [Qemu-devel] [PATCH v3 0/3] scsi-block: Support werror/rerror Fam Zheng
2017-08-18 14:15 ` [Qemu-devel] [PATCH v3 1/3] scsi: Refactor scsi sense interpreting code Fam Zheng
2017-08-18 14:15 ` [Qemu-devel] [PATCH v3 2/3] scsi: Enhance scsi_sense_to_errno Fam Zheng
@ 2017-08-18 14:15 ` Fam Zheng
2017-08-18 14:38 ` Paolo Bonzini
2017-08-18 14:39 ` [Qemu-devel] [PATCH v3 0/3] scsi-block: Support werror/rerror no-reply
3 siblings, 1 reply; 9+ messages in thread
From: Fam Zheng @ 2017-08-18 14:15 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini
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 <famz@redhat.com>
---
hw/scsi/scsi-disk.c | 54 +++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 40 insertions(+), 14 deletions(-)
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index 5f1e5e8070..ec7dbe4a2d 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -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 SCSIDiskState
bool 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(),
};
--
2.13.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH v3 2/3] scsi: Enhance scsi_sense_to_errno
2017-08-18 14:15 ` [Qemu-devel] [PATCH v3 2/3] scsi: Enhance scsi_sense_to_errno Fam Zheng
@ 2017-08-18 14:36 ` Paolo Bonzini
2017-08-21 11:11 ` Fam Zheng
0 siblings, 1 reply; 9+ messages in thread
From: Paolo Bonzini @ 2017-08-18 14:36 UTC (permalink / raw)
To: Fam Zheng, qemu-devel
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;
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH v3 3/3] scsi-block: Support rerror/werror
2017-08-18 14:15 ` [Qemu-devel] [PATCH v3 3/3] scsi-block: Support rerror/werror Fam Zheng
@ 2017-08-18 14:38 ` Paolo Bonzini
0 siblings, 0 replies; 9+ messages in thread
From: Paolo Bonzini @ 2017-08-18 14:38 UTC (permalink / raw)
To: Fam Zheng, qemu-devel
On 18/08/2017 16:15, Fam Zheng wrote:
> 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 <famz@redhat.com>
> ---
> hw/scsi/scsi-disk.c | 54 +++++++++++++++++++++++++++++++++++++++--------------
> 1 file changed, 40 insertions(+), 14 deletions(-)
>
> diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
> index 5f1e5e8070..ec7dbe4a2d 100644
> --- a/hw/scsi/scsi-disk.c
> +++ b/hw/scsi/scsi-disk.c
> @@ -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 SCSIDiskState
> bool 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;
> + }
Maybe this switch statement should also be a function in util/iscsi.c
(scsi_sense_buf_to_errno)?
> +
> + if (error == ECANCELED) {
... || error == EAGAIN || error == ENOTCONN || error == 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(),
> };
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH v3 0/3] scsi-block: Support werror/rerror
2017-08-18 14:15 [Qemu-devel] [PATCH v3 0/3] scsi-block: Support werror/rerror Fam Zheng
` (2 preceding siblings ...)
2017-08-18 14:15 ` [Qemu-devel] [PATCH v3 3/3] scsi-block: Support rerror/werror Fam Zheng
@ 2017-08-18 14:39 ` no-reply
3 siblings, 0 replies; 9+ messages in thread
From: no-reply @ 2017-08-18 14:39 UTC (permalink / raw)
To: famz; +Cc: qemu-devel, pbonzini
Hi,
This series seems to have some coding style problems. See output below for
more information:
Type: series
Message-id: 20170818141512.15205-1-famz@redhat.com
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/1503065708-28277-1-git-send-email-mark.cave-ayland@ilande.co.uk -> patchew/1503065708-28277-1-git-send-email-mark.cave-ayland@ilande.co.uk
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 patchew-devel@freelists.org
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH v3 2/3] scsi: Enhance scsi_sense_to_errno
2017-08-18 14:36 ` Paolo Bonzini
@ 2017-08-21 11:11 ` Fam Zheng
2017-08-21 11:30 ` Paolo Bonzini
0 siblings, 1 reply; 9+ messages in thread
From: Fam Zheng @ 2017-08-21 11:11 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: qemu-devel
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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH v3 2/3] scsi: Enhance scsi_sense_to_errno
2017-08-21 11:11 ` Fam Zheng
@ 2017-08-21 11:30 ` Paolo Bonzini
0 siblings, 0 replies; 9+ messages in thread
From: Paolo Bonzini @ 2017-08-21 11:30 UTC (permalink / raw)
To: Fam Zheng; +Cc: qemu-devel
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
>
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2017-08-21 11:30 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-18 14:15 [Qemu-devel] [PATCH v3 0/3] scsi-block: Support werror/rerror Fam Zheng
2017-08-18 14:15 ` [Qemu-devel] [PATCH v3 1/3] scsi: Refactor scsi sense interpreting code Fam Zheng
2017-08-18 14:15 ` [Qemu-devel] [PATCH v3 2/3] scsi: Enhance scsi_sense_to_errno Fam Zheng
2017-08-18 14:36 ` Paolo Bonzini
2017-08-21 11:11 ` Fam Zheng
2017-08-21 11:30 ` Paolo Bonzini
2017-08-18 14:15 ` [Qemu-devel] [PATCH v3 3/3] scsi-block: Support rerror/werror Fam Zheng
2017-08-18 14:38 ` Paolo Bonzini
2017-08-18 14:39 ` [Qemu-devel] [PATCH v3 0/3] scsi-block: Support werror/rerror no-reply
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).