From patchwork Fri May 12 10:20:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 9723879 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6B9DD600CB for ; Fri, 12 May 2017 10:26:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60239287F3 for ; Fri, 12 May 2017 10:26:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 53A712880D; Fri, 12 May 2017 10:26:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DA412287F3 for ; Fri, 12 May 2017 10:25:59 +0000 (UTC) Received: from localhost ([::1]:52533 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d97ln-0008Qo-0h for patchwork-qemu-devel@patchwork.kernel.org; Fri, 12 May 2017 06:25:59 -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 X-Virus-Scanned: by amavisd-new at test-mx.suse.de 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) 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 = &s->parent_obj; + VirtIODevice *vdev = VIRTIO_DEVICE(s); SCSIDevice *d; int rc; @@ -560,6 +561,21 @@ static int virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, VirtIOSCSIReq *req) virtio_scsi_get_lun(req->req.cmd.lun), req->req.cmd.cdb, req); + if (virtio_vdev_has_feature(vdev, VIRTIO_SCSI_F_TIMEOUT)) { + int timeout = (int)req->req.cmd.crn; + + if (timeout < 60) { + /* Timeouts below 60 are in seconds */ + req->sreq->timeout = timeout * 1000; + } else if (timeout == 255) { + /* 255 is infinite timeout */ + req->sreq->timeout = UINT_MAX; + } else { + /* Otherwise the timeout is in minutes */ + req->sreq->timeout = timeout * 1000 * 60; + } + } + if (req->sreq->cmd.mode != SCSI_XFER_NONE && (req->sreq->cmd.mode != req->mode || req->sreq->cmd.xfer > req->qsgl.size)) { diff --git a/include/standard-headers/linux/virtio_scsi.h b/include/standard-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 /* Response codes */ #define VIRTIO_SCSI_S_OK 0