* [Qemu-devel] [PATCH 1/2] scsi-disk: fix double completion of failing passthrough requests
2018-10-13 9:53 [Qemu-devel] [PATCH 0/2] scsi-disk: fix bugs in rerror/werror Paolo Bonzini
@ 2018-10-13 9:53 ` Paolo Bonzini
2018-10-13 9:53 ` [Qemu-devel] [PATCH 2/2] scsi-disk: fix rerror/werror=ignore Paolo Bonzini
1 sibling, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2018-10-13 9:53 UTC (permalink / raw)
To: qemu-devel; +Cc: famz
If a command fails with a sense that scsi_sense_buf_to_errno converts to
ECANCELED/EAGAIN/ENOTCONN or with a unit attention, scsi_req_complete is
called twice. This caused a crash.
Reported-by: Wangguang <wang.guangA@h3c.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/scsi/scsi-disk.c | 24 +++++++++++-------------
1 file changed, 11 insertions(+), 13 deletions(-)
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index c43163c..4074d7c 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -441,9 +441,18 @@ static bool scsi_handle_rw_error(SCSIDiskReq *r, int error, bool acct_failed)
}
switch (error) {
case 0:
- /* The command has run, no need to fake sense. */
+ /* A passthrough command has run and has produced sense data; check
+ * whether the error has to be handled by the guest or should rather
+ * pause the host.
+ */
assert(r->status && *r->status);
- scsi_req_complete(&r->req, *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;
+ }
break;
case ENOMEDIUM:
scsi_check_condition(r, SENSE_CODE(NO_MEDIUM));
@@ -462,17 +471,6 @@ static bool 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) {
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH 2/2] scsi-disk: fix rerror/werror=ignore
2018-10-13 9:53 [Qemu-devel] [PATCH 0/2] scsi-disk: fix bugs in rerror/werror Paolo Bonzini
2018-10-13 9:53 ` [Qemu-devel] [PATCH 1/2] scsi-disk: fix double completion of failing passthrough requests Paolo Bonzini
@ 2018-10-13 9:53 ` Paolo Bonzini
2018-11-18 15:26 ` Richard W.M. Jones
1 sibling, 1 reply; 4+ messages in thread
From: Paolo Bonzini @ 2018-10-13 9:53 UTC (permalink / raw)
To: qemu-devel; +Cc: famz
rerror=ignore was returning true from scsi_handle_rw_error but the callers were not
calling scsi_req_complete when rerror=ignore returns true (this is the correct thing
to do when true is returned after executing a passthrough command). Fix this by
calling it in scsi_handle_rw_error.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/scsi/scsi-disk.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index 4074d7c..e2c5408 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -473,10 +473,15 @@ static bool scsi_handle_rw_error(SCSIDiskReq *r, int error, bool acct_failed)
}
blk_error_action(s->qdev.conf.blk, action, is_read, error);
+ if (action == BLOCK_ERROR_ACTION_IGNORE) {
+ scsi_req_complete(&r->req, 0);
+ return true;
+ }
+
if (action == BLOCK_ERROR_ACTION_STOP) {
scsi_req_retry(&r->req);
}
- return action != BLOCK_ERROR_ACTION_IGNORE;
+ return false;
}
static void scsi_write_complete_noio(SCSIDiskReq *r, int ret)
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread