diff mbox series

[2/2] scsi/utils: pass host_status = SCSI_HOST_ERROR to guest kernel

Message ID 20211210141615.2585-3-dongli.zhang@oracle.com (mailing list archive)
State New, archived
Headers show
Series scsi: to fix issue on passing host_status to the guest kernel | expand

Commit Message

Dongli Zhang Dec. 10, 2021, 2:16 p.m. UTC
For scsi_req_complete_failed() and when the req->bus->info->fail() is
implemented, the virtio-scsi passes SCSI_HOST_ERROR to the guest kernel as
VIRTIO_SCSI_S_FAILURE, while the pvscsi passes SCSI_HOST_ERROR to guest
kernel as BTSTAT_HASOFTWARE.

However, the scsi_req_complete_failed()->scsi_sense_from_host_status()
always returns GOOD for SCSI_HOST_ERROR, when the req->bus->info->fail() is
not implemented (e.g., megasas). As a result, the sense is not passed to
the guest kernel.

The SCSI_HOST_ERROR is reproduced on purpose by below QEMU command line:

-device megasas,id=vscsi0,bus=pci.0,addr=0x4 \
-drive file=/dev/sdc,format=raw,if=none,id=drive01 \
-device scsi-block,bus=vscsi0.0,channel=0,scsi-id=0,lun=0,drive=drive01 \

... and when we remove the /dev/sdc from the host with:

"echo 1 > /sys/block/sdc/device/delete"

This patch passes sense_code_IO_ERROR to the guest kernel for
host_status = SCSI_HOST_ERROR.

(This issue is detected by running a testing code from Rui Loura).

Cc: Joe Jin <joe.jin@oracle.com>
Cc: Adnan Misherfi <adnan.misherfi@oracle.com>
Cc: Rui Loura <rui.loura@oracle.com>
Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
---
 scsi/utils.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/scsi/utils.c b/scsi/utils.c
index 357b036671..086a1fea66 100644
--- a/scsi/utils.c
+++ b/scsi/utils.c
@@ -638,6 +638,9 @@  int scsi_sense_from_host_status(uint8_t host_status,
     case SCSI_HOST_ABORTED:
         *sense = SENSE_CODE(COMMAND_ABORTED);
         return CHECK_CONDITION;
+    case SCSI_HOST_ERROR:
+        *sense = SENSE_CODE(IO_ERROR);
+        return CHECK_CONDITION;
     case SCSI_HOST_RESET:
         *sense = SENSE_CODE(RESET);
         return CHECK_CONDITION;