Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi/sg: move sg-big-buff sysctl to scsi/sg.c

kernel/sysctl.c is a kitchen sink where everyone leaves their dirty
dishes, this makes it very difficult to maintain.

To help with this maintenance let's start by moving sysctls to places
where they actually belong. The proc sysctl maintainers do not want to
know what sysctl knobs you wish to add for your own piece of code, we
just care about the core logic.

So move the sg-big-buff sysctl from kernel/sysctl.c to drivers/scsi/sg.c
and use register_sysctl() to register the sysctl interface.

[mcgrof@kernel.org: commit log update]

Link: https://lkml.kernel.org/r/20211124231435.1445213-7-mcgrof@kernel.org
Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Amir Goldstein <amir73il@gmail.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Antti Palosaari <crope@iki.fi>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Benjamin LaHaise <bcrl@kvack.org>
Cc: Clemens Ladisch <clemens@ladisch.de>
Cc: David Airlie <airlied@linux.ie>
Cc: Douglas Gilbert <dgilbert@interlog.com>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Iurii Zaikin <yzaikin@google.com>
Cc: James E.J. Bottomley <jejb@linux.ibm.com>
Cc: Jani Nikula <jani.nikula@intel.com>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: John Ogness <john.ogness@linutronix.de>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Joseph Qi <joseph.qi@linux.alibaba.com>
Cc: Julia Lawall <julia.lawall@inria.fr>
Cc: Kees Cook <keescook@chromium.org>
Cc: Lukas Middendorf <kernel@tuxforce.de>
Cc: Mark Fasheh <mark@fasheh.com>
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Cc: Paul Turner <pjt@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Phillip Potter <phil@philpotter.co.uk>
Cc: Qing Wang <wangqing@vivo.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Sebastian Reichel <sre@kernel.org>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Stephen Kitt <steve@sk2.org>
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Xiaoming Ni and committed by
Linus Torvalds
26d1c80f faaa357a

+34 -17
+34 -1
drivers/scsi/sg.c
··· 77 77 78 78 #define SG_DEFAULT_TIMEOUT mult_frac(SG_DEFAULT_TIMEOUT_USER, HZ, USER_HZ) 79 79 80 - int sg_big_buff = SG_DEF_RESERVED_SIZE; 80 + static int sg_big_buff = SG_DEF_RESERVED_SIZE; 81 81 /* N.B. This variable is readable and writeable via 82 82 /proc/scsi/sg/def_reserved_size . Each time sg_open() is called a buffer 83 83 of this size (or less if there is not enough memory) will be reserved ··· 1634 1634 MODULE_PARM_DESC(def_reserved_size, "size of buffer reserved for each fd"); 1635 1635 MODULE_PARM_DESC(allow_dio, "allow direct I/O (default: 0 (disallow))"); 1636 1636 1637 + #ifdef CONFIG_SYSCTL 1638 + #include <linux/sysctl.h> 1639 + 1640 + static struct ctl_table sg_sysctls[] = { 1641 + { 1642 + .procname = "sg-big-buff", 1643 + .data = &sg_big_buff, 1644 + .maxlen = sizeof(int), 1645 + .mode = 0444, 1646 + .proc_handler = proc_dointvec, 1647 + }, 1648 + {} 1649 + }; 1650 + 1651 + static struct ctl_table_header *hdr; 1652 + static void register_sg_sysctls(void) 1653 + { 1654 + if (!hdr) 1655 + hdr = register_sysctl("kernel", sg_sysctls); 1656 + } 1657 + 1658 + static void unregister_sg_sysctls(void) 1659 + { 1660 + if (hdr) 1661 + unregister_sysctl_table(hdr); 1662 + } 1663 + #else 1664 + #define register_sg_sysctls() do { } while (0) 1665 + #define unregister_sg_sysctls() do { } while (0) 1666 + #endif /* CONFIG_SYSCTL */ 1667 + 1637 1668 static int __init 1638 1669 init_sg(void) 1639 1670 { ··· 1697 1666 return 0; 1698 1667 } 1699 1668 class_destroy(sg_sysfs_class); 1669 + register_sg_sysctls(); 1700 1670 err_out: 1701 1671 unregister_chrdev_region(MKDEV(SCSI_GENERIC_MAJOR, 0), SG_MAX_DEVS); 1702 1672 return rc; ··· 1706 1674 static void __exit 1707 1675 exit_sg(void) 1708 1676 { 1677 + unregister_sg_sysctls(); 1709 1678 #ifdef CONFIG_SCSI_PROC_FS 1710 1679 remove_proc_subtree("scsi/sg", NULL); 1711 1680 #endif /* CONFIG_SCSI_PROC_FS */
-4
include/scsi/sg.h
··· 29 29 * For utility and test programs see: http://sg.danny.cz/sg/sg3_utils.html 30 30 */ 31 31 32 - #ifdef __KERNEL__ 33 - extern int sg_big_buff; /* for sysctl */ 34 - #endif 35 - 36 32 37 33 typedef struct sg_iovec /* same structure as used by readv() Linux system */ 38 34 { /* call. It defines one scatter-gather element. */
-12
kernel/sysctl.c
··· 95 95 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT) 96 96 #include <linux/lockdep.h> 97 97 #endif 98 - #ifdef CONFIG_CHR_DEV_SG 99 - #include <scsi/sg.h> 100 - #endif 101 98 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE 102 99 #include <linux/stackleak.h> 103 100 #endif ··· 2085 2088 .maxlen = UEVENT_HELPER_PATH_LEN, 2086 2089 .mode = 0644, 2087 2090 .proc_handler = proc_dostring, 2088 - }, 2089 - #endif 2090 - #ifdef CONFIG_CHR_DEV_SG 2091 - { 2092 - .procname = "sg-big-buff", 2093 - .data = &sg_big_buff, 2094 - .maxlen = sizeof (int), 2095 - .mode = 0444, 2096 - .proc_handler = proc_dointvec, 2097 2091 }, 2098 2092 #endif 2099 2093 #ifdef CONFIG_BSD_PROCESS_ACCT