From: Luis Chamberlain <mcgrof@kernel.org>
To: akpm@linux-foundation.org, keescook@chromium.org,
yzaikin@google.com, nixiaoming@huawei.com, ebiederm@xmission.com,
steve@sk2.org, gregkh@linuxfoundation.org, rafael@kernel.org,
tytso@mit.edu, viro@zeniv.linux.org.uk, pmladek@suse.com,
senozhatsky@chromium.org, rostedt@goodmis.org,
john.ogness@linutronix.de, dgilbert@interlog.com,
jejb@linux.ibm.com, martin.petersen@oracle.com,
mcgrof@bombadil.infradead.org, mcgrof@kernel.org,
linux-scsi@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 6/8] scsi/sg: move sg-big-buff sysctl to scsi/sg.c
Date: Wed, 24 Nov 2021 15:14:33 -0800 [thread overview]
Message-ID: <20211124231435.1445213-7-mcgrof@kernel.org> (raw)
In-Reply-To: <20211124231435.1445213-1-mcgrof@kernel.org>
From: Xiaoming Ni <nixiaoming@huawei.com>
The 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.
Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
[mcgrof: commit log update]
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
drivers/scsi/sg.c | 35 ++++++++++++++++++++++++++++++++++-
include/scsi/sg.h | 4 ----
kernel/sysctl.c | 12 ------------
3 files changed, 34 insertions(+), 17 deletions(-)
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 141099ab9092..32129bb16521 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -77,7 +77,7 @@ static int sg_proc_init(void);
#define SG_DEFAULT_TIMEOUT mult_frac(SG_DEFAULT_TIMEOUT_USER, HZ, USER_HZ)
-int sg_big_buff = SG_DEF_RESERVED_SIZE;
+static int sg_big_buff = SG_DEF_RESERVED_SIZE;
/* N.B. This variable is readable and writeable via
/proc/scsi/sg/def_reserved_size . Each time sg_open() is called a buffer
of this size (or less if there is not enough memory) will be reserved
@@ -1634,6 +1634,37 @@ MODULE_PARM_DESC(scatter_elem_sz, "scatter gather element "
MODULE_PARM_DESC(def_reserved_size, "size of buffer reserved for each fd");
MODULE_PARM_DESC(allow_dio, "allow direct I/O (default: 0 (disallow))");
+#ifdef CONFIG_SYSCTL
+#include <linux/sysctl.h>
+
+static struct ctl_table sg_sysctls[] = {
+ {
+ .procname = "sg-big-buff",
+ .data = &sg_big_buff,
+ .maxlen = sizeof(int),
+ .mode = 0444,
+ .proc_handler = proc_dointvec,
+ },
+ {}
+};
+
+static struct ctl_table_header *hdr;
+static void register_sg_sysctls(void)
+{
+ if (!hdr)
+ hdr = register_sysctl("kernel", sg_sysctls);
+}
+
+static void unregister_sg_sysctls(void)
+{
+ if (hdr)
+ unregister_sysctl_table(hdr);
+}
+#else
+#define register_sg_sysctls() do { } while (0)
+#define unregister_sg_sysctls() do { } while (0)
+#endif /* CONFIG_SYSCTL */
+
static int __init
init_sg(void)
{
@@ -1666,6 +1697,7 @@ init_sg(void)
return 0;
}
class_destroy(sg_sysfs_class);
+ register_sg_sysctls();
err_out:
unregister_chrdev_region(MKDEV(SCSI_GENERIC_MAJOR, 0), SG_MAX_DEVS);
return rc;
@@ -1674,6 +1706,7 @@ init_sg(void)
static void __exit
exit_sg(void)
{
+ unregister_sg_sysctls();
#ifdef CONFIG_SCSI_PROC_FS
remove_proc_subtree("scsi/sg", NULL);
#endif /* CONFIG_SCSI_PROC_FS */
diff --git a/include/scsi/sg.h b/include/scsi/sg.h
index 843cefb8efce..068e35d36557 100644
--- a/include/scsi/sg.h
+++ b/include/scsi/sg.h
@@ -29,10 +29,6 @@
* For utility and test programs see: http://sg.danny.cz/sg/sg3_utils.html
*/
-#ifdef __KERNEL__
-extern int sg_big_buff; /* for sysctl */
-#endif
-
typedef struct sg_iovec /* same structure as used by readv() Linux system */
{ /* call. It defines one scatter-gather element. */
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 02ef27804601..a4bda4a11ea8 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -94,9 +94,6 @@
#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
#include <linux/lockdep.h>
#endif
-#ifdef CONFIG_CHR_DEV_SG
-#include <scsi/sg.h>
-#endif
#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
#include <linux/stackleak.h>
#endif
@@ -2089,15 +2086,6 @@ static struct ctl_table kern_table[] = {
.proc_handler = proc_dostring,
},
#endif
-#ifdef CONFIG_CHR_DEV_SG
- {
- .procname = "sg-big-buff",
- .data = &sg_big_buff,
- .maxlen = sizeof (int),
- .mode = 0444,
- .proc_handler = proc_dointvec,
- },
-#endif
#ifdef CONFIG_BSD_PROCESS_ACCT
{
.procname = "acct",
--
2.33.0
next prev parent reply other threads:[~2021-11-24 23:15 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-24 23:14 [PATCH v2 0/8] sysctl: 3rd set of kernel/sysctl cleanups Luis Chamberlain
2021-11-24 23:14 ` [PATCH v2 1/8] firmware_loader: move firmware sysctl to its own files Luis Chamberlain
2021-11-24 23:14 ` [PATCH v2 2/8] random: move the random sysctl declarations to its own file Luis Chamberlain
2021-11-24 23:14 ` [PATCH v2 3/8] sysctl: add helper to register a sysctl mount point Luis Chamberlain
2021-11-24 23:14 ` [PATCH v2 4/8] fs: move binfmt_misc sysctl to its own file Luis Chamberlain
2021-11-24 23:14 ` [PATCH v2 5/8] printk: move printk sysctl to printk/sysctl.c Luis Chamberlain
2021-11-26 12:51 ` Petr Mladek
2021-11-29 20:48 ` Luis Chamberlain
2021-11-24 23:14 ` Luis Chamberlain [this message]
2021-11-24 23:14 ` [PATCH v2 7/8] stackleak: move stack_erasing sysctl to stackleak.c Luis Chamberlain
2021-11-24 23:14 ` [PATCH v2 8/8] sysctl: share unsigned long const values Luis Chamberlain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211124231435.1445213-7-mcgrof@kernel.org \
--to=mcgrof@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=dgilbert@interlog.com \
--cc=ebiederm@xmission.com \
--cc=gregkh@linuxfoundation.org \
--cc=jejb@linux.ibm.com \
--cc=john.ogness@linutronix.de \
--cc=keescook@chromium.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=mcgrof@bombadil.infradead.org \
--cc=nixiaoming@huawei.com \
--cc=pmladek@suse.com \
--cc=rafael@kernel.org \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
--cc=steve@sk2.org \
--cc=tytso@mit.edu \
--cc=viro@zeniv.linux.org.uk \
--cc=yzaikin@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).