diff mbox series

[4/8] sg: expand request states

Message ID 20181019062456.4690-5-dgilbert@interlog.com (mailing list archive)
State Changes Requested
Headers show
Series sg: major cleanup, remove max_queue limit | expand

Commit Message

Douglas Gilbert Oct. 19, 2018, 6:24 a.m. UTC
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 <dgilbert@interlog.com>
---

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(+)

Comments

Johannes Thumshirn Oct. 19, 2018, 8:27 a.m. UTC | #1
Looks good (but the ifdefs are creepy),
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Bart Van Assche Oct. 19, 2018, 3:13 p.m. UTC | #2
On Fri, 2018-10-19 at 02:24 -0400, Douglas Gilbert wrote: 
> +/* 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 */

Please introduce an enumeration type instead of #defining these constants to
allow the compiler to verify assignments to sg_request::rq_state.

Thanks,

Bart.
diff mbox series

Patch

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 */