@@ -119,7 +119,7 @@ static struct ctl_table fs_stat_sysctls[] = {
.data = &files_stat.max_files,
.maxlen = sizeof(files_stat.max_files),
.mode = 0644,
- .proc_handler = proc_doulongvec_minmax,
+ .proc_handler = proc_doulongvec_maxfiles_minmax,
.extra1 = SYSCTL_LONG_ZERO,
.extra2 = SYSCTL_LONG_MAX,
},
@@ -82,6 +82,8 @@ int proc_dointvec_userhz_jiffies(const struct ctl_table *, int, void *, size_t *
int proc_dointvec_ms_jiffies(const struct ctl_table *, int, void *, size_t *,
loff_t *);
int proc_doulongvec_minmax(const struct ctl_table *, int, void *, size_t *, loff_t *);
+int proc_doulongvec_maxfiles_minmax(const struct ctl_table *, int, void *,
+ size_t *, loff_t *);
int proc_doulongvec_ms_jiffies_minmax(const struct ctl_table *table, int, void *,
size_t *, loff_t *);
int proc_do_large_bitmap(const struct ctl_table *, int, void *, size_t *, loff_t *);
@@ -1122,6 +1122,23 @@ int proc_doulongvec_minmax(const struct ctl_table *table, int write,
return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
}
+/*
+ * Used for 'sysctl -w fs.file-max', ensuring its value will not be less
+ * than sysctl_nr_open.
+ */
+int proc_doulongvec_maxfiles_minmax(const struct ctl_table *table, int write,
+ void *buffer, size_t *lenp, loff_t *ppos)
+{
+ unsigned long *min = table->extra1;
+ unsigned long *max = table->extra2;
+ unsigned long nr_open = sysctl_nr_open;
+
+ if (write)
+ min = &nr_open;
+ return __do_proc_doulongvec_minmax(table->data, table, write,
+ buffer, lenp, ppos, 1l, 1l, min, max);
+}
+
/**
* proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
* @table: the sysctl table
Introduce proc_doulongvec_maxfiles_minmax(), ensure the value of files_stat.max_files is not less than sysctl_nr_open. Signed-off-by: Jinliang Zheng <alexjlzheng@tencent.com> --- fs/file_table.c | 2 +- include/linux/sysctl.h | 2 ++ kernel/sysctl.c | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-)