File 0164-scsi-disk-set-default-I-O-timeout-t.patch of Package qemu.26284
From: Hannes Reinecke <hare@suse.de>
Date: Tue, 10 Nov 2020 15:06:58 +0100
Subject: scsi-disk: set default I/O timeout to 30 seconds
References: bsc#1178049
To align with standard linux settings we should be setting the
default I/O timeout to 30 seconds, and add a lower bound of
5 seconds to avoid spurious I/O failures.
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Bruce Rogers <brogers@suse.com>
---
hw/scsi/scsi-disk.c | 4 +++-
hw/scsi/scsi-generic.c | 4 ++++
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index 25d007722975b4cd9b31fd331e8f..b0cdbc1b9f01c7b4280bfa8d0b98 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -45,7 +45,7 @@
#define DEFAULT_DISCARD_GRANULARITY (4 * KiB)
#define DEFAULT_MAX_UNMAP_SIZE (1 * GiB)
-#define DEFAULT_IO_TIMEOUT UINT_MAX /* Infinity */
+#define DEFAULT_IO_TIMEOUT 30000 /* 30 seconds */
#define DEFAULT_MAX_IO_SIZE INT_MAX /* 2 GB - 1 block */
#define TYPE_SCSI_DISK_BASE "scsi-disk-base"
@@ -2694,6 +2694,8 @@ static BlockAIOCB *scsi_block_do_sgio(SCSIBlockReq *req,
io_header->mx_sb_len = sizeof(r->req.sense);
io_header->sbp = r->req.sense;
io_header->timeout = s->qdev.io_timeout;
+ if (io_header->timeout < 5000)
+ io_header->timeout = 5000;
io_header->usr_ptr = r;
io_header->flags |= SG_FLAG_DIRECT_IO;
trace_scsi_disk_aio_sgio_command(r->req.tag, req->cdb[0], lba,
diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c
index 0a0f8e6094f0c8ec2c23f89c4a8b..d84f3d3e75a9b29b9cbe8c8cc021 100644
--- a/hw/scsi/scsi-generic.c
+++ b/hw/scsi/scsi-generic.c
@@ -122,6 +122,8 @@ static int execute_command(BlockBackend *blk,
r->io_header.mx_sb_len = sizeof(r->req.sense);
r->io_header.sbp = r->req.sense;
r->io_header.timeout = s->io_timeout;
+ if (r->io_header.timeout < 5000)
+ r->io_header.timeout = 5000;
r->io_header.usr_ptr = r;
r->io_header.flags |= SG_FLAG_DIRECT_IO;
@@ -516,6 +518,8 @@ int scsi_SG_IO_FROM_DEV(BlockBackend *blk, uint8_t *cmd, uint8_t cmd_size,
io_header.mx_sb_len = sizeof(sensebuf);
io_header.sbp = sensebuf;
io_header.timeout = timeout;
+ if (io_header.timeout < 5000)
+ io_header.timeout = 5000;
trace_scsi_generic_ioctl_sgio_command(cmd[0], io_header.timeout);
ret = blk_ioctl(blk, SG_IO, &io_header);