From nobody Mon May 6 12:32:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1494584559926632.700683687141; Fri, 12 May 2017 03:22:39 -0700 (PDT) Received: from localhost ([::1]:52499 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d97iX-000645-LA for importer@patchew.org; Fri, 12 May 2017 06:22:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39609) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d97hB-00051m-2c for qemu-devel@nongnu.org; Fri, 12 May 2017 06:21:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d97h7-00064X-UP for qemu-devel@nongnu.org; Fri, 12 May 2017 06:21:13 -0400 Received: from mx2.suse.de ([195.135.220.15]:39442 helo=mx1.suse.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d97h7-0005z6-NY for qemu-devel@nongnu.org; Fri, 12 May 2017 06:21:09 -0400 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id A04ADACA6; Fri, 12 May 2017 10:21:05 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Hannes Reinecke To: Paolo Bonzini Date: Fri, 12 May 2017 12:20:54 +0200 Message-Id: <20170512102057.5855-2-hare@suse.de> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170512102057.5855-1-hare@suse.de> References: <20170512102057.5855-1-hare@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 195.135.220.15 Subject: [Qemu-devel] [PATCH 1/4] scsi: make default command timeout user-settable X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hannes Reinecke , qemu-devel@nongnu.org, Alexander Graf , Hannes Reinecke Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Per default any SCSI commands are sent with an infinite timeout, which essentially disables any command abort mechanism on the host and causes the guest to stall. This patch adds a new option 'timeout' for scsi-generic and scsi-disk which allows the user to set the timeout value to something sensible. Signed-off-by: Hannes Reinecke --- hw/scsi/scsi-disk.c | 4 +++- hw/scsi/scsi-generic.c | 5 ++++- include/hw/scsi/scsi.h | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index a53f058621..dd01ff7e06 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2679,7 +2679,7 @@ static BlockAIOCB *scsi_block_do_sgio(SCSIBlockReq *r= eq, /* The rest is as in scsi-generic.c. */ io_header->mx_sb_len =3D sizeof(r->req.sense); io_header->sbp =3D r->req.sense; - io_header->timeout =3D UINT_MAX; + io_header->timeout =3D s->qdev.timeout; io_header->usr_ptr =3D r; io_header->flags |=3D SG_FLAG_DIRECT_IO; =20 @@ -2898,6 +2898,8 @@ static Property scsi_hd_properties[] =3D { DEFAULT_MAX_UNMAP_SIZE), DEFINE_PROP_UINT64("max_io_size", SCSIDiskState, max_io_size, DEFAULT_MAX_IO_SIZE), + DEFINE_PROP_UINT32("timeout", SCSIDevice, timeout, + MAX_UINT), DEFINE_BLOCK_CHS_PROPERTIES(SCSIDiskState, qdev.conf), DEFINE_PROP_END_OF_LIST(), }; diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index a55ff87c22..fd02a0f4b2 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -157,6 +157,8 @@ static int execute_command(BlockBackend *blk, SCSIGenericReq *r, int direction, BlockCompletionFunc *complete) { + SCSIDevice *s =3D r->req.dev; + r->io_header.interface_id =3D 'S'; r->io_header.dxfer_direction =3D direction; r->io_header.dxferp =3D r->buf; @@ -165,7 +167,7 @@ static int execute_command(BlockBackend *blk, r->io_header.cmd_len =3D r->req.cmd.len; r->io_header.mx_sb_len =3D sizeof(r->req.sense); r->io_header.sbp =3D r->req.sense; - r->io_header.timeout =3D MAX_UINT; + r->io_header.timeout =3D s->timeout; r->io_header.usr_ptr =3D r; r->io_header.flags |=3D SG_FLAG_DIRECT_IO; =20 @@ -599,6 +601,7 @@ static SCSIRequest *scsi_new_request(SCSIDevice *d, uin= t32_t tag, uint32_t lun, =20 static Property scsi_generic_properties[] =3D { DEFINE_PROP_DRIVE("drive", SCSIDevice, conf.blk), + DEFINE_PROP_UINT32("timeout", SCSIDevice, timeout, MAX_UINT), DEFINE_PROP_END_OF_LIST(), }; =20 diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h index 6b85786dbf..a976e85cfa 100644 --- a/include/hw/scsi/scsi.h +++ b/include/hw/scsi/scsi.h @@ -110,6 +110,7 @@ struct SCSIDevice uint64_t max_lba; uint64_t wwn; uint64_t port_wwn; + uint32_t timeout; }; =20 extern const VMStateDescription vmstate_scsi_device; --=20 2.12.0 From nobody Mon May 6 12:32:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1494584683965451.99150232391617; Fri, 12 May 2017 03:24:43 -0700 (PDT) Received: from localhost ([::1]:52511 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d97kY-0007qp-DH for importer@patchew.org; Fri, 12 May 2017 06:24:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39612) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d97hB-00051o-3T for qemu-devel@nongnu.org; Fri, 12 May 2017 06:21:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d97h7-00064Z-Ug for qemu-devel@nongnu.org; Fri, 12 May 2017 06:21:13 -0400 Received: from mx2.suse.de ([195.135.220.15]:39443 helo=mx1.suse.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d97h7-0005z8-NZ for qemu-devel@nongnu.org; Fri, 12 May 2017 06:21:09 -0400 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 9C2D2AB9F; Fri, 12 May 2017 10:21:05 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Hannes Reinecke To: Paolo Bonzini Date: Fri, 12 May 2017 12:20:55 +0200 Message-Id: <20170512102057.5855-3-hare@suse.de> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170512102057.5855-1-hare@suse.de> References: <20170512102057.5855-1-hare@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 195.135.220.15 Subject: [Qemu-devel] [PATCH 2/4] scsi: use host default timeouts for SCSI commands X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hannes Reinecke , qemu-devel@nongnu.org, Alexander Graf , Hannes Reinecke Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Instead of disabling command aborts by setting the command timeout to infinity we should be setting it to '0' per default, allowing the host to fall back to its default values. Signed-off-by: Hannes Reinecke --- hw/scsi/scsi-disk.c | 3 +-- hw/scsi/scsi-generic.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index dd01ff7e06..4ac4c872fe 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2898,8 +2898,7 @@ static Property scsi_hd_properties[] =3D { DEFAULT_MAX_UNMAP_SIZE), DEFINE_PROP_UINT64("max_io_size", SCSIDiskState, max_io_size, DEFAULT_MAX_IO_SIZE), - DEFINE_PROP_UINT32("timeout", SCSIDevice, timeout, - MAX_UINT), + DEFINE_PROP_UINT32("timeout", SCSIDevice, timeout, 0), DEFINE_BLOCK_CHS_PROPERTIES(SCSIDiskState, qdev.conf), DEFINE_PROP_END_OF_LIST(), }; diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index fd02a0f4b2..998b6a4558 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -601,7 +601,7 @@ static SCSIRequest *scsi_new_request(SCSIDevice *d, uin= t32_t tag, uint32_t lun, =20 static Property scsi_generic_properties[] =3D { DEFINE_PROP_DRIVE("drive", SCSIDevice, conf.blk), - DEFINE_PROP_UINT32("timeout", SCSIDevice, timeout, MAX_UINT), + DEFINE_PROP_UINT32("timeout", SCSIDevice, timeout, 0), DEFINE_PROP_END_OF_LIST(), }; =20 --=20 2.12.0 From nobody Mon May 6 12:32:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1494584683199767.117401369409; Fri, 12 May 2017 03:24:43 -0700 (PDT) Received: from localhost ([::1]:52510 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d97kX-0007ou-30 for importer@patchew.org; Fri, 12 May 2017 06:24:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39606) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d97hB-00051i-1J for qemu-devel@nongnu.org; Fri, 12 May 2017 06:21:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d97h8-00064o-2E for qemu-devel@nongnu.org; Fri, 12 May 2017 06:21:13 -0400 Received: from mx2.suse.de ([195.135.220.15]:39441 helo=mx1.suse.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d97h7-0005z7-NW for qemu-devel@nongnu.org; Fri, 12 May 2017 06:21:09 -0400 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 9EDACAC9E; Fri, 12 May 2017 10:21:05 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Hannes Reinecke To: Paolo Bonzini Date: Fri, 12 May 2017 12:20:56 +0200 Message-Id: <20170512102057.5855-4-hare@suse.de> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170512102057.5855-1-hare@suse.de> References: <20170512102057.5855-1-hare@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 195.135.220.15 Subject: [Qemu-devel] [PATCH 3/4] scsi: per-request timeouts X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hannes Reinecke , qemu-devel@nongnu.org, Alexander Graf , Hannes Reinecke Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add a 'timeout' value per request to allow to specify individual per-request timeouts. Signed-off-by: Hannes Reinecke --- hw/scsi/scsi-bus.c | 1 + hw/scsi/scsi-disk.c | 15 +++++++++++---- hw/scsi/scsi-generic.c | 12 ++++++++---- include/hw/scsi/scsi.h | 1 + 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index f5574469c8..206000d873 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -690,6 +690,7 @@ SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, = uint32_t lun, =20 req->cmd =3D cmd; req->resid =3D req->cmd.xfer; + req->timeout =3D d->timeout; =20 switch (buf[0]) { case INQUIRY: diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 4ac4c872fe..6a6f091a9c 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2503,7 +2503,9 @@ static SCSIRequest *scsi_new_request(SCSIDevice *d, u= int32_t tag, uint32_t lun, printf("\n"); } #endif - + if (req) { + req->timeout =3D d->timeout; + } return req; } =20 @@ -2679,7 +2681,7 @@ static BlockAIOCB *scsi_block_do_sgio(SCSIBlockReq *r= eq, /* The rest is as in scsi-generic.c. */ io_header->mx_sb_len =3D sizeof(r->req.sense); io_header->sbp =3D r->req.sense; - io_header->timeout =3D s->qdev.timeout; + io_header->timeout =3D r->req.timeout; io_header->usr_ptr =3D r; io_header->flags |=3D SG_FLAG_DIRECT_IO; =20 @@ -2812,14 +2814,19 @@ static SCSIRequest *scsi_block_new_request(SCSIDevi= ce *d, uint32_t tag, void *hba_private) { SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, d); + struct SCSIRequest *req; =20 if (scsi_block_is_passthrough(s, buf)) { - return scsi_req_alloc(&scsi_generic_req_ops, &s->qdev, tag, lun, + req =3D scsi_req_alloc(&scsi_generic_req_ops, &s->qdev, tag, lun, hba_private); } else { - return scsi_req_alloc(&scsi_block_dma_reqops, &s->qdev, tag, lun, + req =3D scsi_req_alloc(&scsi_block_dma_reqops, &s->qdev, tag, lun, hba_private); } + if (req) { + req->timeout =3D d->timeout; + } + return req; } =20 static int scsi_block_parse_cdb(SCSIDevice *d, SCSICommand *cmd, diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index 998b6a4558..31c3a75bad 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -157,8 +157,6 @@ static int execute_command(BlockBackend *blk, SCSIGenericReq *r, int direction, BlockCompletionFunc *complete) { - SCSIDevice *s =3D r->req.dev; - r->io_header.interface_id =3D 'S'; r->io_header.dxfer_direction =3D direction; r->io_header.dxferp =3D r->buf; @@ -167,7 +165,7 @@ static int execute_command(BlockBackend *blk, r->io_header.cmd_len =3D r->req.cmd.len; r->io_header.mx_sb_len =3D sizeof(r->req.sense); r->io_header.sbp =3D r->req.sense; - r->io_header.timeout =3D s->timeout; + r->io_header.timeout =3D r->req.timeout; r->io_header.usr_ptr =3D r; r->io_header.flags |=3D SG_FLAG_DIRECT_IO; =20 @@ -596,7 +594,13 @@ const SCSIReqOps scsi_generic_req_ops =3D { static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag, uint32_t= lun, uint8_t *buf, void *hba_private) { - return scsi_req_alloc(&scsi_generic_req_ops, d, tag, lun, hba_private); + struct SCSIRequest *req; + + req =3D scsi_req_alloc(&scsi_generic_req_ops, d, tag, lun, hba_private= ); + if (req) { + req->timeout =3D d->timeout; + } + return req; } =20 static Property scsi_generic_properties[] =3D { diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h index a976e85cfa..6c51ddc3ef 100644 --- a/include/hw/scsi/scsi.h +++ b/include/hw/scsi/scsi.h @@ -51,6 +51,7 @@ struct SCSIRequest { uint32_t tag; uint32_t lun; uint32_t status; + uint32_t timeout; void *hba_private; size_t resid; SCSICommand cmd; --=20 2.12.0 From nobody Mon May 6 12:32:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1494584779006634.6226067866286; Fri, 12 May 2017 03:26:19 -0700 (PDT) Received: from localhost ([::1]:52542 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d97m5-0000bm-MO for importer@patchew.org; Fri, 12 May 2017 06:26:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39607) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d97hB-00051l-1k for qemu-devel@nongnu.org; Fri, 12 May 2017 06:21:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d97h7-00064O-U3 for qemu-devel@nongnu.org; Fri, 12 May 2017 06:21:13 -0400 Received: from mx2.suse.de ([195.135.220.15]:39439 helo=mx1.suse.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d97h7-0005z3-NS for qemu-devel@nongnu.org; Fri, 12 May 2017 06:21:09 -0400 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 9CF7BAC8C; Fri, 12 May 2017 10:21:05 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Hannes Reinecke To: Paolo Bonzini Date: Fri, 12 May 2017 12:20:57 +0200 Message-Id: <20170512102057.5855-5-hare@suse.de> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170512102057.5855-1-hare@suse.de> References: <20170512102057.5855-1-hare@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 195.135.220.15 Subject: [Qemu-devel] [PATCH 4/4] virtio: implement VIRTIO_SCSI_F_TIMEOUT feature X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hannes Reinecke , qemu-devel@nongnu.org, Alexander Graf , Hannes Reinecke Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Implement a handler for the VIRTIO_SCSI_F_TIMEOUT feature, which allows to pass in the assigned command timeout in seconds or minutes. This allows to specify a timeout up to 3 hours. Signed-off-by: Hannes Reinecke --- hw/scsi/virtio-scsi.c | 16 ++++++++++++++++ include/standard-headers/linux/virtio_scsi.h | 1 + 2 files changed, 17 insertions(+) diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 46a3e3f280..f1c2f7cb5b 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -534,6 +534,7 @@ static void virtio_scsi_fail_cmd_req(VirtIOSCSIReq *req) static int virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, VirtIOSCSIReq= *req) { VirtIOSCSICommon *vs =3D &s->parent_obj; + VirtIODevice *vdev =3D VIRTIO_DEVICE(s); SCSIDevice *d; int rc; =20 @@ -560,6 +561,21 @@ static int virtio_scsi_handle_cmd_req_prepare(VirtIOSC= SI *s, VirtIOSCSIReq *req) virtio_scsi_get_lun(req->req.cmd.lun), req->req.cmd.cdb, req); =20 + if (virtio_vdev_has_feature(vdev, VIRTIO_SCSI_F_TIMEOUT)) { + int timeout =3D (int)req->req.cmd.crn; + + if (timeout < 60) { + /* Timeouts below 60 are in seconds */ + req->sreq->timeout =3D timeout * 1000; + } else if (timeout =3D=3D 255) { + /* 255 is infinite timeout */ + req->sreq->timeout =3D UINT_MAX; + } else { + /* Otherwise the timeout is in minutes */ + req->sreq->timeout =3D timeout * 1000 * 60; + } + } + if (req->sreq->cmd.mode !=3D SCSI_XFER_NONE && (req->sreq->cmd.mode !=3D req->mode || req->sreq->cmd.xfer > req->qsgl.size)) { diff --git a/include/standard-headers/linux/virtio_scsi.h b/include/standar= d-headers/linux/virtio_scsi.h index ab66166b6a..b00e2b95ab 100644 --- a/include/standard-headers/linux/virtio_scsi.h +++ b/include/standard-headers/linux/virtio_scsi.h @@ -120,6 +120,7 @@ struct virtio_scsi_config { #define VIRTIO_SCSI_F_HOTPLUG 1 #define VIRTIO_SCSI_F_CHANGE 2 #define VIRTIO_SCSI_F_T10_PI 3 +#define VIRTIO_SCSI_F_TIMEOUT 4 =20 /* Response codes */ #define VIRTIO_SCSI_S_OK 0 --=20 2.12.0