From patchwork Sat Oct 20 22:21:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Douglas Gilbert X-Patchwork-Id: 10650639 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 CC77C90 for ; Sat, 20 Oct 2018 22:22:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCF7028696 for ; Sat, 20 Oct 2018 22:22:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B1572286BA; Sat, 20 Oct 2018 22:22:16 +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 0C65F28696 for ; Sat, 20 Oct 2018 22:22:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726627AbeJUGeN (ORCPT ); Sun, 21 Oct 2018 02:34:13 -0400 Received: from smtp.infotech.no ([82.134.31.41]:57371 "EHLO smtp.infotech.no" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726630AbeJUGeM (ORCPT ); Sun, 21 Oct 2018 02:34:12 -0400 Received: from localhost (localhost [127.0.0.1]) by smtp.infotech.no (Postfix) with ESMTP id C28BE2041AC; Sun, 21 Oct 2018 00:22:12 +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 xiSmdp9ILSKY; Sun, 21 Oct 2018 00:22:11 +0200 (CEST) Received: from xtwo70.bingwo.ca (65.194.6.51.dyn.plus.net [51.6.194.65]) by smtp.infotech.no (Postfix) with ESMTPA id 776FE20423B; Sun, 21 Oct 2018 00:22: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 v2 4/8] sg: expand request states Date: Sat, 20 Oct 2018 23:21:57 +0100 Message-Id: <20181020222201.25135-5-dgilbert@interlog.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181020222201.25135-1-dgilbert@interlog.com> References: <20181020222201.25135-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 sg_rq_state enumerations for tracking the lifetime of a sg_request. 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 --- The '#if 0's are temporary and removed in a later patch. They allow the following large and complex patch (5 of 8) to be a bit shorter and still compile. drivers/scsi/sg.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 94e13a1d21a5..a76395f16fb1 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -75,6 +75,24 @@ static int sg_proc_init(void); */ #define SG_MAX_CDB_SIZE 252 +/* Following enum contains the states of sg_request::rq_state */ +enum sg_rq_state { + SG_RQ_INACTIVE = 0, /* request not in use (e.g. on fl) */ + SG_RQ_INFLIGHT, /* SCSI request issued, no response yet */ + SG_RQ_AWAIT_READ, /* response received, awaiting read */ + SG_RQ_DONE_READ, /* read is ongoing or done */ + SG_RQ_BUSY, /* 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 +968,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 +1246,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 +1516,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 +2444,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 +2627,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 +2732,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 */