From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Hannes Reinecke <hare@suse.de>
Subject: [PULL 04/29] scsi: make io_timeout configurable
Date: Fri, 26 Feb 2021 09:05:01 +0100 [thread overview]
Message-ID: <20210226080526.651705-5-pbonzini@redhat.com> (raw)
In-Reply-To: <20210226080526.651705-1-pbonzini@redhat.com>
From: Hannes Reinecke <hare@suse.de>
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 <hare@suse.de>
Message-Id: <20201116183114.55703-3-hare@suse.de>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/scsi/scsi-disk.c | 6 ++++--
hw/scsi/scsi-generic.c | 17 +++++++++++------
include/hw/scsi/scsi.h | 4 +++-
3 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index ed52fcd49f..c4016d1cfc 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -2624,7 +2624,7 @@ static int get_device_type(SCSIDiskState *s)
cmd[4] = sizeof(buf);
ret = scsi_SG_IO_FROM_DEV(s->qdev.conf.blk, cmd, sizeof(cmd),
- buf, sizeof(buf));
+ buf, sizeof(buf), s->qdev.io_timeout);
if (ret < 0) {
return -1;
}
@@ -2785,7 +2785,7 @@ static BlockAIOCB *scsi_block_do_sgio(SCSIBlockReq *req,
/* The rest is as in scsi-generic.c. */
io_header->mx_sb_len = sizeof(r->req.sense);
io_header->sbp = r->req.sense;
- io_header->timeout = UINT_MAX;
+ io_header->timeout = s->qdev.io_timeout * 1000;
io_header->usr_ptr = r;
io_header->flags |= SG_FLAG_DIRECT_IO;
@@ -3103,6 +3103,8 @@ static Property scsi_block_properties[] = {
DEFAULT_MAX_IO_SIZE),
DEFINE_PROP_INT32("scsi_version", SCSIDiskState, qdev.default_scsi_version,
-1),
+ DEFINE_PROP_UINT32("io_timeout", SCSIDiskState, qdev.io_timeout,
+ DEFAULT_IO_TIMEOUT),
DEFINE_PROP_END_OF_LIST(),
};
diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c
index ab220141f5..3dd3ccd097 100644
--- a/hw/scsi/scsi-generic.c
+++ b/hw/scsi/scsi-generic.c
@@ -115,6 +115,8 @@ static int execute_command(BlockBackend *blk,
SCSIGenericReq *r, int direction,
BlockCompletionFunc *complete)
{
+ SCSIDevice *s = r->req.dev;
+
r->io_header.interface_id = 'S';
r->io_header.dxfer_direction = direction;
r->io_header.dxferp = r->buf;
@@ -123,7 +125,7 @@ static int execute_command(BlockBackend *blk,
r->io_header.cmd_len = r->req.cmd.len;
r->io_header.mx_sb_len = sizeof(r->req.sense);
r->io_header.sbp = r->req.sense;
- r->io_header.timeout = MAX_UINT;
+ r->io_header.timeout = s->io_timeout * 1000;
r->io_header.usr_ptr = r;
r->io_header.flags |= SG_FLAG_DIRECT_IO;
@@ -506,7 +508,7 @@ static int read_naa_id(const uint8_t *p, uint64_t *p_wwn)
}
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)
{
sg_io_hdr_t io_header;
uint8_t sensebuf[8];
@@ -521,7 +523,7 @@ int scsi_SG_IO_FROM_DEV(BlockBackend *blk, uint8_t *cmd, uint8_t cmd_size,
io_header.cmd_len = cmd_size;
io_header.mx_sb_len = sizeof(sensebuf);
io_header.sbp = sensebuf;
- io_header.timeout = 6000; /* XXX */
+ io_header.timeout = timeout * 1000;
ret = blk_ioctl(blk, SG_IO, &io_header);
if (ret < 0 || io_header.driver_status || io_header.host_status) {
@@ -551,7 +553,7 @@ static void scsi_generic_set_vpd_bl_emulation(SCSIDevice *s)
cmd[4] = sizeof(buf);
ret = scsi_SG_IO_FROM_DEV(s->conf.blk, cmd, sizeof(cmd),
- buf, sizeof(buf));
+ buf, sizeof(buf), s->io_timeout);
if (ret < 0) {
/*
* Do not assume anything if we can't retrieve the
@@ -587,7 +589,7 @@ static void scsi_generic_read_device_identification(SCSIDevice *s)
cmd[4] = sizeof(buf);
ret = scsi_SG_IO_FROM_DEV(s->conf.blk, cmd, sizeof(cmd),
- buf, sizeof(buf));
+ buf, sizeof(buf), s->io_timeout);
if (ret < 0) {
return;
}
@@ -638,7 +640,7 @@ static int get_stream_blocksize(BlockBackend *blk)
cmd[0] = MODE_SENSE;
cmd[4] = sizeof(buf);
- ret = scsi_SG_IO_FROM_DEV(blk, cmd, sizeof(cmd), buf, sizeof(buf));
+ ret = scsi_SG_IO_FROM_DEV(blk, cmd, sizeof(cmd), buf, sizeof(buf), 6);
if (ret < 0) {
return -1;
}
@@ -728,6 +730,7 @@ static void scsi_generic_realize(SCSIDevice *s, Error **errp)
/* Only used by scsi-block, but initialize it nevertheless to be clean. */
s->default_scsi_version = -1;
+ s->io_timeout = DEFAULT_IO_TIMEOUT;
scsi_generic_read_device_inquiry(s);
}
@@ -751,6 +754,8 @@ static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag, uint32_t lun,
static Property scsi_generic_properties[] = {
DEFINE_PROP_DRIVE("drive", SCSIDevice, conf.blk),
DEFINE_PROP_BOOL("share-rw", SCSIDevice, conf.share_rw, false),
+ DEFINE_PROP_UINT32("io_timeout", SCSIDevice, io_timeout,
+ DEFAULT_IO_TIMEOUT),
DEFINE_PROP_END_OF_LIST(),
};
diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h
index 09fa5c9d2a..a8ef59c0f4 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);
--
2.29.2
next prev parent reply other threads:[~2021-02-26 8:12 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-26 8:04 [PULL 00/29] Misc patches for 2021-02-25 Paolo Bonzini
2021-02-26 8:04 ` [PULL 01/29] hvf: Sign the code after installation Paolo Bonzini
2021-02-26 8:04 ` [PULL 02/29] configure: fix --enable-fuzzing linker failures Paolo Bonzini
2021-02-26 8:05 ` [PULL 03/29] multiprocess: move feature to meson_options.txt Paolo Bonzini
2021-02-26 8:05 ` Paolo Bonzini [this message]
2021-02-26 8:05 ` [PULL 05/29] scsi: add tracing for SG_IO commands Paolo Bonzini
2021-02-26 8:05 ` [PULL 06/29] scsi: allow user to set werror as report Paolo Bonzini
2021-02-26 8:05 ` [PULL 07/29] virtio-scsi: don't process IO on fenced dataplane Paolo Bonzini
2021-02-26 8:05 ` [PULL 08/29] scsi-disk: move scsi_handle_rw_error earlier Paolo Bonzini
2021-02-26 8:05 ` [PULL 09/29] scsi-disk: do not complete requests early for rerror/werror=ignore Paolo Bonzini
2021-02-26 8:05 ` [PULL 10/29] scsi: introduce scsi_sense_from_errno() Paolo Bonzini
2021-02-26 8:05 ` [PULL 11/29] scsi-disk: pass SCSI status to scsi_handle_rw_error Paolo Bonzini
2021-02-26 8:05 ` [PULL 12/29] scsi-disk: pass guest recoverable errors through even for rerror=stop Paolo Bonzini
2021-02-26 8:05 ` [PULL 13/29] scsi: drop 'result' argument from command_complete callback Paolo Bonzini
2021-02-26 8:05 ` [PULL 14/29] char: don't fail when client is not connected Paolo Bonzini
2021-02-26 8:05 ` [PULL 15/29] gdbstub: use preferred boolean option syntax Paolo Bonzini
2021-02-26 8:05 ` [PULL 16/29] qemu-options: update to show preferred boolean syntax for -chardev Paolo Bonzini
2021-02-26 8:05 ` [PULL 17/29] qemu-options: update to show preferred boolean syntax for -spice Paolo Bonzini
2021-02-26 8:05 ` [PULL 18/29] qemu-options: update to show preferred boolean syntax for -netdev Paolo Bonzini
2021-02-26 8:05 ` [PULL 19/29] qemu-options: update to show preferred boolean syntax for -incoming Paolo Bonzini
2021-02-26 8:05 ` [PULL 20/29] qemu-options: update to show preferred boolean syntax for -vnc Paolo Bonzini
2021-02-26 8:05 ` [PULL 21/29] docs: update to show preferred boolean syntax for -chardev Paolo Bonzini
2021-02-26 8:05 ` [PULL 22/29] docs: update to show preferred boolean syntax for -vnc Paolo Bonzini
2021-02-26 8:05 ` [PULL 23/29] docs: update to show preferred boolean syntax for -cpu Paolo Bonzini
2021-02-26 8:05 ` [PULL 24/29] target/i386: " Paolo Bonzini
2021-02-26 8:05 ` [PULL 25/29] qom/object.c: Fix typo Paolo Bonzini
2021-02-26 8:05 ` [PULL 26/29] target/i386: Add bus lock debug exception support Paolo Bonzini
2021-02-26 8:05 ` [PULL 27/29] vl: deprecate -writeconfig Paolo Bonzini
2021-03-01 8:00 ` Markus Armbruster
2021-03-01 10:09 ` Paolo Bonzini
2021-03-01 13:26 ` Markus Armbruster
2021-03-01 13:45 ` Paolo Bonzini
2021-03-01 14:54 ` Markus Armbruster
2021-03-01 15:05 ` Paolo Bonzini
2021-03-01 16:03 ` About '-readconfig' [Was: Re: [PULL 27/29] vl: deprecate -writeconfig] Kashyap Chamarthy
2021-03-01 16:24 ` Paolo Bonzini
2021-03-02 15:36 ` Kashyap Chamarthy
2021-02-26 8:05 ` [PULL 28/29] chardev: do not use short form boolean options in non-QemuOpts character device descriptions Paolo Bonzini
2021-02-26 8:05 ` [PULL 29/29] tcg/i386: rdpmc: fix the the condtions Paolo Bonzini
2021-02-26 8:51 ` [PULL 00/29] Misc patches for 2021-02-25 no-reply
2021-03-03 16:54 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210226080526.651705-5-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=hare@suse.de \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).