Commit 204d5a24 authored by Luis Chamberlain's avatar Luis Chamberlain Committed by Linus Torvalds

fs: move fs stat sysctls to file_table.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.

We can create the sysctl dynamically on early init for fs stat to help
with this clutter.  This dusts off the fs stat syctls knobs and puts
them into where they are declared.

Link: https://lkml.kernel.org/r/20211129205548.605569-3-mcgrof@kernel.orgSigned-off-by: default avatarLuis Chamberlain <mcgrof@kernel.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Antti Palosaari <crope@iki.fi>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: Iurii Zaikin <yzaikin@google.com>
Cc: "J. Bruce Fields" <bfields@fieldses.org>
Cc: Jeff Layton <jlayton@kernel.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Lukas Middendorf <kernel@tuxforce.de>
Cc: Stephen Kitt <steve@sk2.org>
Cc: Xiaoming Ni <nixiaoming@huawei.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 1d67fe58
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
#include "internal.h" #include "internal.h"
/* sysctl tunables... */ /* sysctl tunables... */
struct files_stat_struct files_stat = { static struct files_stat_struct files_stat = {
.max_files = NR_FILE .max_files = NR_FILE
}; };
...@@ -75,22 +75,53 @@ unsigned long get_max_files(void) ...@@ -75,22 +75,53 @@ unsigned long get_max_files(void)
} }
EXPORT_SYMBOL_GPL(get_max_files); EXPORT_SYMBOL_GPL(get_max_files);
#if defined(CONFIG_SYSCTL) && defined(CONFIG_PROC_FS)
/* /*
* Handle nr_files sysctl * Handle nr_files sysctl
*/ */
#if defined(CONFIG_SYSCTL) && defined(CONFIG_PROC_FS) static int proc_nr_files(struct ctl_table *table, int write, void *buffer,
int proc_nr_files(struct ctl_table *table, int write, size_t *lenp, loff_t *ppos)
void *buffer, size_t *lenp, loff_t *ppos)
{ {
files_stat.nr_files = get_nr_files(); files_stat.nr_files = get_nr_files();
return proc_doulongvec_minmax(table, write, buffer, lenp, ppos); return proc_doulongvec_minmax(table, write, buffer, lenp, ppos);
} }
#else
int proc_nr_files(struct ctl_table *table, int write, static struct ctl_table fs_stat_sysctls[] = {
void *buffer, size_t *lenp, loff_t *ppos) {
.procname = "file-nr",
.data = &files_stat,
.maxlen = sizeof(files_stat),
.mode = 0444,
.proc_handler = proc_nr_files,
},
{
.procname = "file-max",
.data = &files_stat.max_files,
.maxlen = sizeof(files_stat.max_files),
.mode = 0644,
.proc_handler = proc_doulongvec_minmax,
.extra1 = SYSCTL_LONG_ZERO,
.extra2 = SYSCTL_LONG_MAX,
},
{
.procname = "nr_open",
.data = &sysctl_nr_open,
.maxlen = sizeof(unsigned int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
.extra1 = &sysctl_nr_open_min,
.extra2 = &sysctl_nr_open_max,
},
{ }
};
static int __init init_fs_stat_sysctls(void)
{ {
return -ENOSYS; register_sysctl_init("fs", fs_stat_sysctls);
return 0;
} }
fs_initcall(init_fs_stat_sysctls);
#endif #endif
static struct file *__alloc_file(int flags, const struct cred *cred) static struct file *__alloc_file(int flags, const struct cred *cred)
......
...@@ -79,7 +79,6 @@ extern void __init inode_init_early(void); ...@@ -79,7 +79,6 @@ extern void __init inode_init_early(void);
extern void __init files_init(void); extern void __init files_init(void);
extern void __init files_maxfiles_init(void); extern void __init files_maxfiles_init(void);
extern struct files_stat_struct files_stat;
extern unsigned long get_max_files(void); extern unsigned long get_max_files(void);
extern unsigned int sysctl_nr_open; extern unsigned int sysctl_nr_open;
extern int leases_enable, lease_break_time; extern int leases_enable, lease_break_time;
...@@ -3532,8 +3531,6 @@ ssize_t simple_attr_write(struct file *file, const char __user *buf, ...@@ -3532,8 +3531,6 @@ ssize_t simple_attr_write(struct file *file, const char __user *buf,
size_t len, loff_t *ppos); size_t len, loff_t *ppos);
struct ctl_table; struct ctl_table;
int proc_nr_files(struct ctl_table *table, int write,
void *buffer, size_t *lenp, loff_t *ppos);
int proc_nr_dentry(struct ctl_table *table, int write, int proc_nr_dentry(struct ctl_table *table, int write,
void *buffer, size_t *lenp, loff_t *ppos); void *buffer, size_t *lenp, loff_t *ppos);
int __init list_bdev_fs_names(char *buf, size_t size); int __init list_bdev_fs_names(char *buf, size_t size);
......
...@@ -2901,31 +2901,6 @@ static struct ctl_table vm_table[] = { ...@@ -2901,31 +2901,6 @@ static struct ctl_table vm_table[] = {
}; };
static struct ctl_table fs_table[] = { static struct ctl_table fs_table[] = {
{
.procname = "file-nr",
.data = &files_stat,
.maxlen = sizeof(files_stat),
.mode = 0444,
.proc_handler = proc_nr_files,
},
{
.procname = "file-max",
.data = &files_stat.max_files,
.maxlen = sizeof(files_stat.max_files),
.mode = 0644,
.proc_handler = proc_doulongvec_minmax,
.extra1 = SYSCTL_LONG_ZERO,
.extra2 = SYSCTL_LONG_MAX,
},
{
.procname = "nr_open",
.data = &sysctl_nr_open,
.maxlen = sizeof(unsigned int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
.extra1 = &sysctl_nr_open_min,
.extra2 = &sysctl_nr_open_max,
},
{ {
.procname = "dentry-state", .procname = "dentry-state",
.data = &dentry_stat, .data = &dentry_stat,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment