From c9b6609b69facad0cc5425d4fa7934c33d7f2e91 Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Mon, 16 Nov 2020 19:31:13 +0100 Subject: scsi: make io_timeout configurable The current code sets an infinite timeout on SG_IO requests, causing the guest to stall if the host experiences a frame loss. This patch adds an 'io_timeout' parameter for SCSIDevice to make the SG_IO timeout configurable, and also shortens the default timeout to 30 seconds to avoid infinite stalls. Signed-off-by: Hannes Reinecke Message-Id: <20201116183114.55703-3-hare@suse.de> Signed-off-by: Paolo Bonzini --- include/hw/scsi/scsi.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h index 09fa5c9..a8ef59c 100644 --- a/include/hw/scsi/scsi.h +++ b/include/hw/scsi/scsi.h @@ -18,6 +18,7 @@ typedef struct SCSIReqOps SCSIReqOps; #define SCSI_SENSE_BUF_SIZE_OLD 96 #define SCSI_SENSE_BUF_SIZE 252 +#define DEFAULT_IO_TIMEOUT 30 struct SCSIRequest { SCSIBus *bus; @@ -84,6 +85,7 @@ struct SCSIDevice uint64_t port_wwn; int scsi_version; int default_scsi_version; + uint32_t io_timeout; bool needs_vpd_bl_emulation; bool hba_supports_iothread; }; @@ -188,7 +190,7 @@ void scsi_device_unit_attention_reported(SCSIDevice *dev); void scsi_generic_read_device_inquiry(SCSIDevice *dev); int scsi_device_get_sense(SCSIDevice *dev, uint8_t *buf, int len, bool fixed); int scsi_SG_IO_FROM_DEV(BlockBackend *blk, uint8_t *cmd, uint8_t cmd_size, - uint8_t *buf, uint8_t buf_size); + uint8_t *buf, uint8_t buf_size, uint32_t timeout); SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int target, int lun); SCSIDevice *scsi_device_get(SCSIBus *bus, int channel, int target, int lun); -- cgit v1.1 From d7a84021db8eeddcd5d24ab591a1434763caff6c Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 24 Feb 2021 16:30:09 +0100 Subject: scsi: introduce scsi_sense_from_errno() The new function is an extension of the switch statement in scsi-disk.c which also includes the errno cases only found in sg_io_sense_from_errno. This allows us to consolidate the errno handling. Extracted from a patch by Hannes Reinecke . Signed-off-by: Paolo Bonzini --- include/scsi/utils.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/scsi/utils.h b/include/scsi/utils.h index 096489c..ff7c709 100644 --- a/include/scsi/utils.h +++ b/include/scsi/utils.h @@ -135,4 +135,6 @@ int sg_io_sense_from_errno(int errno_value, struct sg_io_hdr *io_hdr, SCSISense *sense); #endif +int scsi_sense_from_errno(int errno_value, SCSISense *sense); + #endif -- cgit v1.1 From 17ea26c2d80a695b4d3af9ae2eaa438095029773 Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Mon, 16 Nov 2020 19:40:36 +0100 Subject: scsi: drop 'result' argument from command_complete callback The command complete callback has a SCSIRequest as the first argument, and the status field of that structure is identical to the 'status' argument. So drop the argument from the callback. Signed-off-by: Hannes Reinecke Message-Id: <20201116184041.60465-3-hare@suse.de> Signed-off-by: Paolo Bonzini --- include/hw/scsi/esp.h | 2 +- include/hw/scsi/scsi.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/hw/scsi/esp.h b/include/hw/scsi/esp.h index 60cc304..d8a6263 100644 --- a/include/hw/scsi/esp.h +++ b/include/hw/scsi/esp.h @@ -151,7 +151,7 @@ struct SysBusESPState { void esp_dma_enable(ESPState *s, int irq, int level); void esp_request_cancelled(SCSIRequest *req); -void esp_command_complete(SCSIRequest *req, uint32_t status, size_t resid); +void esp_command_complete(SCSIRequest *req, size_t resid); void esp_transfer_data(SCSIRequest *req, uint32_t len); void esp_hard_reset(ESPState *s); uint64_t esp_reg_read(ESPState *s, uint32_t saddr); diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h index a8ef59c..5d992e6 100644 --- a/include/hw/scsi/scsi.h +++ b/include/hw/scsi/scsi.h @@ -123,7 +123,7 @@ struct SCSIBusInfo { int (*parse_cdb)(SCSIDevice *dev, SCSICommand *cmd, uint8_t *buf, void *hba_private); void (*transfer_data)(SCSIRequest *req, uint32_t arg); - void (*complete)(SCSIRequest *req, uint32_t arg, size_t resid); + void (*complete)(SCSIRequest *req, size_t resid); void (*cancel)(SCSIRequest *req); void (*change)(SCSIBus *bus, SCSIDevice *dev, SCSISense sense); QEMUSGList *(*get_sg_list)(SCSIRequest *req); -- cgit v1.1