From patchwork Fri Oct 19 06:24:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Douglas Gilbert X-Patchwork-Id: 10648747 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DE67514E2 for ; Fri, 19 Oct 2018 06:25:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CFF0428ABF for ; Fri, 19 Oct 2018 06:25:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C4C4A28AC8; Fri, 19 Oct 2018 06:25:11 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6101928ABF for ; Fri, 19 Oct 2018 06:25:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727008AbeJSO3s (ORCPT ); Fri, 19 Oct 2018 10:29:48 -0400 Received: from smtp.infotech.no ([82.134.31.41]:47409 "EHLO smtp.infotech.no" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726584AbeJSO3s (ORCPT ); Fri, 19 Oct 2018 10:29:48 -0400 Received: from localhost (localhost [127.0.0.1]) by smtp.infotech.no (Postfix) with ESMTP id 83B892041AF; Fri, 19 Oct 2018 08:25:08 +0200 (CEST) X-Virus-Scanned: by amavisd-new-2.6.6 (20110518) (Debian) at infotech.no Received: from smtp.infotech.no ([127.0.0.1]) by localhost (smtp.infotech.no [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uatMCS0Ew4lN; Fri, 19 Oct 2018 08:25:07 +0200 (CEST) Received: from xtwo70.bingwo.ca (host-45-58-195-233.dyn.295.ca [45.58.195.233]) by smtp.infotech.no (Postfix) with ESMTPA id 55550204255; Fri, 19 Oct 2018 08:25:05 +0200 (CEST) From: Douglas Gilbert To: linux-scsi@vger.kernel.org Cc: martin.petersen@oracle.com, tonyb@cybernetics.com, hare@suse.de, bart.vanassche@wdc.com Subject: [PATCH 4/8] sg: expand request states Date: Fri, 19 Oct 2018 02:24:52 -0400 Message-Id: <20181019062456.4690-5-dgilbert@interlog.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181019062456.4690-1-dgilbert@interlog.com> References: <20181019062456.4690-1-dgilbert@interlog.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce the new rq_state defines. SG_RQ_DATA_THRESHOLD is a default value that if the data length of a request exceeds then, after that request is completed, the data buffer will be freed up as the sg_request object is placed on the free list. SG_TOT_FD_THRESHOLD is a default, per file descriptor value that the sum of outstanding command data lengths is not allowed to exceed. Signed-off-by: Douglas Gilbert Reviewed-by: Johannes Thumshirn --- The '#if 0's are temporary and removed in a later patch. They allow the following large and complex patch to be a bit shorter and still compile. drivers/scsi/sg.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 71623685abfe..c77701c0b939 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -75,6 +75,22 @@ static int sg_proc_init(void); */ #define SG_MAX_CDB_SIZE 252 +/* Following defines are states of sg_request::rq_state */ +#define SG_RQ_INACTIVE 0 /* request not in use (e.g. on fl) */ +#define SG_RQ_INFLIGHT 1 /* SCSI request issued, no response yet */ +#define SG_RQ_AWAIT_READ 2 /* response received, awaiting read */ +#define SG_RQ_DONE_READ 3 /* read is ongoing or done */ +#define SG_RQ_BUSY 4 /* example: reserve request changing size */ + +/* free up requests larger than this dlen size after use */ +#define SG_RQ_DATA_THRESHOLD (128 * 1024) + +/* If sum_of(dlen) of a fd exceeds this, write() will yield E2BIG */ +#define SG_TOT_FD_THRESHOLD (16 * 1024 * 1024) + +#define SG_TIME_UNIT_MS 0 /* milliseconds */ +#define SG_TIME_UNIT_NS 1 /* nanoseconds */ +#define SG_DEF_TIME_UNIT SG_TIME_UNIT_MS #define SG_DEFAULT_TIMEOUT mult_frac(SG_DEFAULT_TIMEOUT_USER, HZ, USER_HZ) int sg_big_buff = SG_DEF_RESERVED_SIZE; @@ -950,6 +966,7 @@ sg_fill_request_table(struct sg_fd *sfp, struct sg_req_info *rinfo) } } +#if 0 /* temporary to shorten big patch */ static long sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg) { @@ -1227,6 +1244,7 @@ sg_compat_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg) return -ENOIOCTLCMD; } #endif +#endif /* temporary to shorten big patch */ static __poll_t sg_poll(struct file *filp, poll_table * wait) @@ -1496,10 +1514,12 @@ static const struct file_operations sg_fops = { .read = sg_read, .write = sg_write, .poll = sg_poll, +#if 0 /* temporary to shorten big patch */ .unlocked_ioctl = sg_ioctl, #ifdef CONFIG_COMPAT .compat_ioctl = sg_compat_ioctl, #endif +#endif /* temporary to shorten big patch */ .open = sg_open, .mmap = sg_mmap, .release = sg_release, @@ -2422,12 +2442,16 @@ static const struct seq_operations devstrs_seq_ops = { .show = sg_proc_seq_show_devstrs, }; +#if 0 /* temporary to shorten big patch */ static int sg_proc_seq_show_debug(struct seq_file *s, void *v); +#endif /* temporary to shorten big patch */ static const struct seq_operations debug_seq_ops = { .start = dev_seq_start, .next = dev_seq_next, .stop = dev_seq_stop, +#if 0 /* temporary to shorten big patch */ .show = sg_proc_seq_show_debug, +#endif /* temporary to shorten big patch */ }; static int @@ -2601,6 +2625,8 @@ sg_proc_seq_show_devstrs(struct seq_file *s, void *v) return 0; } +#if 0 /* temporary to shorten big patch */ + /* must be called while holding sg_index_lock */ static void sg_proc_debug_helper(struct seq_file *s, struct sg_device *sdp) @@ -2704,6 +2730,7 @@ sg_proc_seq_show_debug(struct seq_file *s, void *v) read_unlock_irqrestore(&sg_index_lock, iflags); return 0; } +#endif /* temporary to shorten big patch */ #endif /* CONFIG_SCSI_PROC_FS */