mirror of https://github.com/torvalds/linux.git
Summary
* Move kern_table members out of kernel/sysctl.c Moved a subset (tracing, panic, signal, stack_tracer and sparc) out of the kern_table array. The goal is for kern_table to only have sysctl elements. All this increases modularity by placing the ctl_tables closer to where they are used while reducing the chances of merge conflicts in kernel/sysctl.c. * Fixed sysctl unit test panic by relocating it to selftests * Testing These have been in linux-next from rc2, so they have had more than a month worth of testing. -----BEGIN PGP SIGNATURE----- iQGzBAABCgAdFiEErkcJVyXmMSXOyyeQupfNUreWQU8FAmgwLsAACgkQupfNUreW QU9ghwv/VKZW+IXEvSjc8OiwntWkL7e5ddHY6O2Vf44MzhBefLTXmfx2HfkEA0Xw RaOQ28Hf/zQL83RqHHnXqI7JdGWQJUm8bCPwk4H3DCaF8qOfPVvblVYmfNL2auSY oyRRpRzZuY5EtKcrNjiHFHL2WIC8KvPVwS748oHY1eZY7kn1fcs8DDnNO4iuWop+ uJeDxu87wkRCFXF3DIM+MAHRvxSa8GHtZvb9EjAl/EHMbAyVSz3uTb7FdQDdnE09 s7P30EC03RHtgi3sd2Ku04dJsHLz7VErvpToxSH2KFlcdpJuWuCSCTT8XaD8kII8 kYYCxNpmPOf4LzEy/J2vVZB0PSHrHvuQCH7iGy+8wOPk9GHTOMkKMMXVmeGnAsef AiosPYroxXp/nBFcuNs6/1LKpsdpFr2F6u6oMgbzLaW1Xe/oc+6oynuOgeVj9LuM FrSxSwaVvpdwHYHujYPQAAWIgKRzITiEXnCgtSyohFquKb+7E8ZspwjOqYH2xWMQ WwABNRqY =45X2 -----END PGP SIGNATURE----- Merge tag 'sysctl-6.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/sysctl/sysctl Pull sysctl updates from Joel Granados: - Move kern_table members out of kernel/sysctl.c Moved a subset (tracing, panic, signal, stack_tracer and sparc) out of the kern_table array. The goal is for kern_table to only have sysctl elements. All this increases modularity by placing the ctl_tables closer to where they are used while reducing the chances of merge conflicts in kernel/sysctl.c. - Fixed sysctl unit test panic by relocating it to selftests * tag 'sysctl-6.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/sysctl/sysctl: sysctl: Close test ctl_headers with a for loop sysctl: call sysctl tests with a for loop sysctl: Add 0012 to test the u8 range check sysctl: move u8 register test to lib/test_sysctl.c sparc: mv sparc sysctls into their own file under arch/sparc/kernel stack_tracer: move sysctl registration to kernel/trace/trace_stack.c tracing: Move trace sysctls into trace.c signal: Move signal ctl tables into signal.c panic: Move panic ctl tables into panic.c
This commit is contained in:
commit
f1975e4765
|
|
@ -35,6 +35,7 @@ obj-y += process.o
|
|||
obj-y += signal_$(BITS).o
|
||||
obj-y += sigutil_$(BITS).o
|
||||
obj-$(CONFIG_SPARC32) += ioport.o
|
||||
obj-y += setup.o
|
||||
obj-y += setup_$(BITS).o
|
||||
obj-y += idprom.o
|
||||
obj-y += sys_sparc_$(BITS).o
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
#include <asm/setup.h>
|
||||
#include <linux/sysctl.h>
|
||||
|
||||
static const struct ctl_table sparc_sysctl_table[] = {
|
||||
{
|
||||
.procname = "reboot-cmd",
|
||||
.data = reboot_command,
|
||||
.maxlen = 256,
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dostring,
|
||||
},
|
||||
{
|
||||
.procname = "stop-a",
|
||||
.data = &stop_a_enabled,
|
||||
.maxlen = sizeof(int),
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dointvec,
|
||||
},
|
||||
{
|
||||
.procname = "scons-poweroff",
|
||||
.data = &scons_pwroff,
|
||||
.maxlen = sizeof(int),
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dointvec,
|
||||
},
|
||||
#ifdef CONFIG_SPARC64
|
||||
{
|
||||
.procname = "tsb-ratio",
|
||||
.data = &sysctl_tsb_ratio,
|
||||
.maxlen = sizeof(int),
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dointvec,
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
static int __init init_sparc_sysctls(void)
|
||||
{
|
||||
register_sysctl_init("kernel", sparc_sysctl_table);
|
||||
return 0;
|
||||
}
|
||||
|
||||
arch_initcall(init_sparc_sysctls);
|
||||
|
|
@ -569,8 +569,6 @@ static inline void arch_ftrace_set_direct_caller(struct ftrace_regs *fregs,
|
|||
|
||||
#ifdef CONFIG_STACK_TRACER
|
||||
|
||||
extern int stack_tracer_enabled;
|
||||
|
||||
int stack_trace_sysctl(const struct ctl_table *table, int write, void *buffer,
|
||||
size_t *lenp, loff_t *ppos);
|
||||
|
||||
|
|
@ -1298,16 +1296,9 @@ static inline void unpause_graph_tracing(void) { }
|
|||
#ifdef CONFIG_TRACING
|
||||
enum ftrace_dump_mode;
|
||||
|
||||
#define MAX_TRACER_SIZE 100
|
||||
extern char ftrace_dump_on_oops[];
|
||||
extern int ftrace_dump_on_oops_enabled(void);
|
||||
extern int tracepoint_printk;
|
||||
|
||||
extern void disable_trace_on_warning(void);
|
||||
extern int __disable_trace_on_warning;
|
||||
|
||||
int tracepoint_printk_sysctl(const struct ctl_table *table, int write,
|
||||
void *buffer, size_t *lenp, loff_t *ppos);
|
||||
|
||||
#else /* CONFIG_TRACING */
|
||||
static inline void disable_trace_on_warning(void) { }
|
||||
|
|
|
|||
|
|
@ -96,6 +96,36 @@ static const struct ctl_table kern_panic_table[] = {
|
|||
.extra2 = SYSCTL_ONE,
|
||||
},
|
||||
#endif
|
||||
{
|
||||
.procname = "panic",
|
||||
.data = &panic_timeout,
|
||||
.maxlen = sizeof(int),
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dointvec,
|
||||
},
|
||||
{
|
||||
.procname = "panic_on_oops",
|
||||
.data = &panic_on_oops,
|
||||
.maxlen = sizeof(int),
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dointvec,
|
||||
},
|
||||
{
|
||||
.procname = "panic_print",
|
||||
.data = &panic_print,
|
||||
.maxlen = sizeof(unsigned long),
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_doulongvec_minmax,
|
||||
},
|
||||
{
|
||||
.procname = "panic_on_warn",
|
||||
.data = &panic_on_warn,
|
||||
.maxlen = sizeof(int),
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dointvec_minmax,
|
||||
.extra1 = SYSCTL_ZERO,
|
||||
.extra2 = SYSCTL_ONE,
|
||||
},
|
||||
{
|
||||
.procname = "warn_limit",
|
||||
.data = &warn_limit,
|
||||
|
|
|
|||
|
|
@ -4981,9 +4981,20 @@ static const struct ctl_table signal_debug_table[] = {
|
|||
#endif
|
||||
};
|
||||
|
||||
static const struct ctl_table signal_table[] = {
|
||||
{
|
||||
.procname = "print-fatal-signals",
|
||||
.data = &print_fatal_signals,
|
||||
.maxlen = sizeof(int),
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dointvec,
|
||||
},
|
||||
};
|
||||
|
||||
static int __init init_signal_sysctls(void)
|
||||
{
|
||||
register_sysctl_init("debug", signal_debug_table);
|
||||
register_sysctl_init("kernel", signal_table);
|
||||
return 0;
|
||||
}
|
||||
early_initcall(init_signal_sysctls);
|
||||
|
|
|
|||
|
|
@ -367,54 +367,6 @@ static void sysctl_test_api_dointvec_write_single_greater_int_max(
|
|||
KUNIT_EXPECT_EQ(test, 0, *((int *)table.data));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test that registering an invalid extra value is not allowed.
|
||||
*/
|
||||
static void sysctl_test_register_sysctl_sz_invalid_extra_value(
|
||||
struct kunit *test)
|
||||
{
|
||||
unsigned char data = 0;
|
||||
const struct ctl_table table_foo[] = {
|
||||
{
|
||||
.procname = "foo",
|
||||
.data = &data,
|
||||
.maxlen = sizeof(u8),
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dou8vec_minmax,
|
||||
.extra1 = SYSCTL_FOUR,
|
||||
.extra2 = SYSCTL_ONE_THOUSAND,
|
||||
},
|
||||
};
|
||||
|
||||
const struct ctl_table table_bar[] = {
|
||||
{
|
||||
.procname = "bar",
|
||||
.data = &data,
|
||||
.maxlen = sizeof(u8),
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dou8vec_minmax,
|
||||
.extra1 = SYSCTL_NEG_ONE,
|
||||
.extra2 = SYSCTL_ONE_HUNDRED,
|
||||
},
|
||||
};
|
||||
|
||||
const struct ctl_table table_qux[] = {
|
||||
{
|
||||
.procname = "qux",
|
||||
.data = &data,
|
||||
.maxlen = sizeof(u8),
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dou8vec_minmax,
|
||||
.extra1 = SYSCTL_ZERO,
|
||||
.extra2 = SYSCTL_TWO_HUNDRED,
|
||||
},
|
||||
};
|
||||
|
||||
KUNIT_EXPECT_NULL(test, register_sysctl("foo", table_foo));
|
||||
KUNIT_EXPECT_NULL(test, register_sysctl("foo", table_bar));
|
||||
KUNIT_EXPECT_NOT_NULL(test, register_sysctl("foo", table_qux));
|
||||
}
|
||||
|
||||
static struct kunit_case sysctl_test_cases[] = {
|
||||
KUNIT_CASE(sysctl_test_api_dointvec_null_tbl_data),
|
||||
KUNIT_CASE(sysctl_test_api_dointvec_table_maxlen_unset),
|
||||
|
|
@ -426,7 +378,6 @@ static struct kunit_case sysctl_test_cases[] = {
|
|||
KUNIT_CASE(sysctl_test_dointvec_write_happy_single_negative),
|
||||
KUNIT_CASE(sysctl_test_api_dointvec_write_single_less_int_min),
|
||||
KUNIT_CASE(sysctl_test_api_dointvec_write_single_greater_int_max),
|
||||
KUNIT_CASE(sysctl_test_register_sysctl_sz_invalid_extra_value),
|
||||
{}
|
||||
};
|
||||
|
||||
|
|
|
|||
108
kernel/sysctl.c
108
kernel/sysctl.c
|
|
@ -22,8 +22,6 @@
|
|||
#include <linux/module.h>
|
||||
#include <linux/sysctl.h>
|
||||
#include <linux/bitmap.h>
|
||||
#include <linux/signal.h>
|
||||
#include <linux/panic.h>
|
||||
#include <linux/printk.h>
|
||||
#include <linux/proc_fs.h>
|
||||
#include <linux/security.h>
|
||||
|
|
@ -46,7 +44,6 @@
|
|||
#include <linux/nfs_fs.h>
|
||||
#include <linux/acpi.h>
|
||||
#include <linux/reboot.h>
|
||||
#include <linux/ftrace.h>
|
||||
#include <linux/kmod.h>
|
||||
#include <linux/capability.h>
|
||||
#include <linux/binfmts.h>
|
||||
|
|
@ -61,12 +58,8 @@
|
|||
|
||||
#ifdef CONFIG_X86
|
||||
#include <asm/nmi.h>
|
||||
#include <asm/stacktrace.h>
|
||||
#include <asm/io.h>
|
||||
#endif
|
||||
#ifdef CONFIG_SPARC
|
||||
#include <asm/setup.h>
|
||||
#endif
|
||||
#ifdef CONFIG_RT_MUTEXES
|
||||
#include <linux/rtmutex.h>
|
||||
#endif
|
||||
|
|
@ -1588,13 +1581,6 @@ int proc_do_static_key(const struct ctl_table *table, int write,
|
|||
}
|
||||
|
||||
static const struct ctl_table kern_table[] = {
|
||||
{
|
||||
.procname = "panic",
|
||||
.data = &panic_timeout,
|
||||
.maxlen = sizeof(int),
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dointvec,
|
||||
},
|
||||
#ifdef CONFIG_PROC_SYSCTL
|
||||
{
|
||||
.procname = "tainted",
|
||||
|
|
@ -1611,45 +1597,6 @@ static const struct ctl_table kern_table[] = {
|
|||
.extra1 = SYSCTL_NEG_ONE,
|
||||
.extra2 = SYSCTL_ONE,
|
||||
},
|
||||
#endif
|
||||
{
|
||||
.procname = "print-fatal-signals",
|
||||
.data = &print_fatal_signals,
|
||||
.maxlen = sizeof(int),
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dointvec,
|
||||
},
|
||||
#ifdef CONFIG_SPARC
|
||||
{
|
||||
.procname = "reboot-cmd",
|
||||
.data = reboot_command,
|
||||
.maxlen = 256,
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dostring,
|
||||
},
|
||||
{
|
||||
.procname = "stop-a",
|
||||
.data = &stop_a_enabled,
|
||||
.maxlen = sizeof (int),
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dointvec,
|
||||
},
|
||||
{
|
||||
.procname = "scons-poweroff",
|
||||
.data = &scons_pwroff,
|
||||
.maxlen = sizeof (int),
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dointvec,
|
||||
},
|
||||
#endif
|
||||
#ifdef CONFIG_SPARC64
|
||||
{
|
||||
.procname = "tsb-ratio",
|
||||
.data = &sysctl_tsb_ratio,
|
||||
.maxlen = sizeof (int),
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dointvec,
|
||||
},
|
||||
#endif
|
||||
#ifdef CONFIG_PARISC
|
||||
{
|
||||
|
|
@ -1669,38 +1616,6 @@ static const struct ctl_table kern_table[] = {
|
|||
.proc_handler = proc_dointvec,
|
||||
},
|
||||
#endif
|
||||
#ifdef CONFIG_STACK_TRACER
|
||||
{
|
||||
.procname = "stack_tracer_enabled",
|
||||
.data = &stack_tracer_enabled,
|
||||
.maxlen = sizeof(int),
|
||||
.mode = 0644,
|
||||
.proc_handler = stack_trace_sysctl,
|
||||
},
|
||||
#endif
|
||||
#ifdef CONFIG_TRACING
|
||||
{
|
||||
.procname = "ftrace_dump_on_oops",
|
||||
.data = &ftrace_dump_on_oops,
|
||||
.maxlen = MAX_TRACER_SIZE,
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dostring,
|
||||
},
|
||||
{
|
||||
.procname = "traceoff_on_warning",
|
||||
.data = &__disable_trace_on_warning,
|
||||
.maxlen = sizeof(__disable_trace_on_warning),
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dointvec,
|
||||
},
|
||||
{
|
||||
.procname = "tracepoint_printk",
|
||||
.data = &tracepoint_printk,
|
||||
.maxlen = sizeof(tracepoint_printk),
|
||||
.mode = 0644,
|
||||
.proc_handler = tracepoint_printk_sysctl,
|
||||
},
|
||||
#endif
|
||||
#ifdef CONFIG_MODULES
|
||||
{
|
||||
.procname = "modprobe",
|
||||
|
|
@ -1772,20 +1687,6 @@ static const struct ctl_table kern_table[] = {
|
|||
.extra1 = SYSCTL_ZERO,
|
||||
.extra2 = SYSCTL_MAXOLDUID,
|
||||
},
|
||||
{
|
||||
.procname = "panic_on_oops",
|
||||
.data = &panic_on_oops,
|
||||
.maxlen = sizeof(int),
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dointvec,
|
||||
},
|
||||
{
|
||||
.procname = "panic_print",
|
||||
.data = &panic_print,
|
||||
.maxlen = sizeof(unsigned long),
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_doulongvec_minmax,
|
||||
},
|
||||
{
|
||||
.procname = "ngroups_max",
|
||||
.data = (void *)&ngroups_max,
|
||||
|
|
@ -1837,15 +1738,6 @@ static const struct ctl_table kern_table[] = {
|
|||
.proc_handler = proc_dointvec,
|
||||
},
|
||||
#endif
|
||||
{
|
||||
.procname = "panic_on_warn",
|
||||
.data = &panic_on_warn,
|
||||
.maxlen = sizeof(int),
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dointvec_minmax,
|
||||
.extra1 = SYSCTL_ZERO,
|
||||
.extra2 = SYSCTL_ONE,
|
||||
},
|
||||
#ifdef CONFIG_TREE_RCU
|
||||
{
|
||||
.procname = "panic_on_rcu_stall",
|
||||
|
|
|
|||
|
|
@ -120,6 +120,7 @@ static int tracing_disabled = 1;
|
|||
|
||||
cpumask_var_t __read_mostly tracing_buffer_mask;
|
||||
|
||||
#define MAX_TRACER_SIZE 100
|
||||
/*
|
||||
* ftrace_dump_on_oops - variable to dump ftrace buffer on oops
|
||||
*
|
||||
|
|
@ -142,7 +143,40 @@ cpumask_var_t __read_mostly tracing_buffer_mask;
|
|||
char ftrace_dump_on_oops[MAX_TRACER_SIZE] = "0";
|
||||
|
||||
/* When set, tracing will stop when a WARN*() is hit */
|
||||
int __disable_trace_on_warning;
|
||||
static int __disable_trace_on_warning;
|
||||
|
||||
int tracepoint_printk_sysctl(const struct ctl_table *table, int write,
|
||||
void *buffer, size_t *lenp, loff_t *ppos);
|
||||
static const struct ctl_table trace_sysctl_table[] = {
|
||||
{
|
||||
.procname = "ftrace_dump_on_oops",
|
||||
.data = &ftrace_dump_on_oops,
|
||||
.maxlen = MAX_TRACER_SIZE,
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dostring,
|
||||
},
|
||||
{
|
||||
.procname = "traceoff_on_warning",
|
||||
.data = &__disable_trace_on_warning,
|
||||
.maxlen = sizeof(__disable_trace_on_warning),
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dointvec,
|
||||
},
|
||||
{
|
||||
.procname = "tracepoint_printk",
|
||||
.data = &tracepoint_printk,
|
||||
.maxlen = sizeof(tracepoint_printk),
|
||||
.mode = 0644,
|
||||
.proc_handler = tracepoint_printk_sysctl,
|
||||
},
|
||||
};
|
||||
|
||||
static int __init init_trace_sysctls(void)
|
||||
{
|
||||
register_sysctl_init("kernel", trace_sysctl_table);
|
||||
return 0;
|
||||
}
|
||||
subsys_initcall(init_trace_sysctls);
|
||||
|
||||
#ifdef CONFIG_TRACE_EVAL_MAP_FILE
|
||||
/* Map of enums to their values, for "eval_map" file */
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ static arch_spinlock_t stack_trace_max_lock =
|
|||
DEFINE_PER_CPU(int, disable_stack_tracer);
|
||||
static DEFINE_MUTEX(stack_sysctl_mutex);
|
||||
|
||||
int stack_tracer_enabled;
|
||||
static int stack_tracer_enabled;
|
||||
|
||||
static void print_max_stack(void)
|
||||
{
|
||||
|
|
@ -578,3 +578,23 @@ static __init int stack_trace_init(void)
|
|||
}
|
||||
|
||||
device_initcall(stack_trace_init);
|
||||
|
||||
|
||||
static const struct ctl_table trace_stack_sysctl_table[] = {
|
||||
{
|
||||
.procname = "stack_tracer_enabled",
|
||||
.data = &stack_tracer_enabled,
|
||||
.maxlen = sizeof(int),
|
||||
.mode = 0644,
|
||||
.proc_handler = stack_trace_sysctl,
|
||||
},
|
||||
};
|
||||
|
||||
static int __init init_trace_stack_sysctls(void)
|
||||
{
|
||||
register_sysctl_init("kernel", trace_stack_sysctl_table);
|
||||
return 0;
|
||||
}
|
||||
subsys_initcall(init_trace_stack_sysctls);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -30,15 +30,17 @@ static int i_zero;
|
|||
static int i_one_hundred = 100;
|
||||
static int match_int_ok = 1;
|
||||
|
||||
enum {
|
||||
TEST_H_SETUP_NODE,
|
||||
TEST_H_MNT,
|
||||
TEST_H_MNTERROR,
|
||||
TEST_H_EMPTY_ADD,
|
||||
TEST_H_EMPTY,
|
||||
TEST_H_U8,
|
||||
TEST_H_SIZE /* Always at the end */
|
||||
};
|
||||
|
||||
static struct {
|
||||
struct ctl_table_header *test_h_setup_node;
|
||||
struct ctl_table_header *test_h_mnt;
|
||||
struct ctl_table_header *test_h_mnterror;
|
||||
struct ctl_table_header *empty_add;
|
||||
struct ctl_table_header *empty;
|
||||
} sysctl_test_headers;
|
||||
|
||||
static struct ctl_table_header *ctl_headers[TEST_H_SIZE] = {};
|
||||
struct test_sysctl_data {
|
||||
int int_0001;
|
||||
int int_0002;
|
||||
|
|
@ -167,8 +169,8 @@ static int test_sysctl_setup_node_tests(void)
|
|||
test_data.bitmap_0001 = kzalloc(SYSCTL_TEST_BITMAP_SIZE/8, GFP_KERNEL);
|
||||
if (!test_data.bitmap_0001)
|
||||
return -ENOMEM;
|
||||
sysctl_test_headers.test_h_setup_node = register_sysctl("debug/test_sysctl", test_table);
|
||||
if (!sysctl_test_headers.test_h_setup_node) {
|
||||
ctl_headers[TEST_H_SETUP_NODE] = register_sysctl("debug/test_sysctl", test_table);
|
||||
if (!ctl_headers[TEST_H_SETUP_NODE]) {
|
||||
kfree(test_data.bitmap_0001);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
|
@ -202,12 +204,12 @@ static int test_sysctl_run_unregister_nested(void)
|
|||
|
||||
static int test_sysctl_run_register_mount_point(void)
|
||||
{
|
||||
sysctl_test_headers.test_h_mnt
|
||||
ctl_headers[TEST_H_MNT]
|
||||
= register_sysctl_mount_point("debug/test_sysctl/mnt");
|
||||
if (!sysctl_test_headers.test_h_mnt)
|
||||
if (!ctl_headers[TEST_H_MNT])
|
||||
return -ENOMEM;
|
||||
|
||||
sysctl_test_headers.test_h_mnterror
|
||||
ctl_headers[TEST_H_MNTERROR]
|
||||
= register_sysctl("debug/test_sysctl/mnt/mnt_error",
|
||||
test_table_unregister);
|
||||
/*
|
||||
|
|
@ -225,15 +227,74 @@ static const struct ctl_table test_table_empty[] = { };
|
|||
static int test_sysctl_run_register_empty(void)
|
||||
{
|
||||
/* Tets that an empty dir can be created */
|
||||
sysctl_test_headers.empty_add
|
||||
ctl_headers[TEST_H_EMPTY_ADD]
|
||||
= register_sysctl("debug/test_sysctl/empty_add", test_table_empty);
|
||||
if (!sysctl_test_headers.empty_add)
|
||||
if (!ctl_headers[TEST_H_EMPTY_ADD])
|
||||
return -ENOMEM;
|
||||
|
||||
/* Test that register on top of an empty dir works */
|
||||
sysctl_test_headers.empty
|
||||
ctl_headers[TEST_H_EMPTY]
|
||||
= register_sysctl("debug/test_sysctl/empty_add/empty", test_table_empty);
|
||||
if (!sysctl_test_headers.empty)
|
||||
if (!ctl_headers[TEST_H_EMPTY])
|
||||
return -ENOMEM;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct ctl_table table_u8_over[] = {
|
||||
{
|
||||
.procname = "u8_over",
|
||||
.data = &test_data.uint_0001,
|
||||
.maxlen = sizeof(u8),
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dou8vec_minmax,
|
||||
.extra1 = SYSCTL_FOUR,
|
||||
.extra2 = SYSCTL_ONE_THOUSAND,
|
||||
},
|
||||
};
|
||||
|
||||
static const struct ctl_table table_u8_under[] = {
|
||||
{
|
||||
.procname = "u8_under",
|
||||
.data = &test_data.uint_0001,
|
||||
.maxlen = sizeof(u8),
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dou8vec_minmax,
|
||||
.extra1 = SYSCTL_NEG_ONE,
|
||||
.extra2 = SYSCTL_ONE_HUNDRED,
|
||||
},
|
||||
};
|
||||
|
||||
static const struct ctl_table table_u8_valid[] = {
|
||||
{
|
||||
.procname = "u8_valid",
|
||||
.data = &test_data.uint_0001,
|
||||
.maxlen = sizeof(u8),
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dou8vec_minmax,
|
||||
.extra1 = SYSCTL_ZERO,
|
||||
.extra2 = SYSCTL_TWO_HUNDRED,
|
||||
},
|
||||
};
|
||||
|
||||
static int test_sysctl_register_u8_extra(void)
|
||||
{
|
||||
/* should fail because it's over */
|
||||
ctl_headers[TEST_H_U8]
|
||||
= register_sysctl("debug/test_sysctl", table_u8_over);
|
||||
if (ctl_headers[TEST_H_U8])
|
||||
return -ENOMEM;
|
||||
|
||||
/* should fail because it's under */
|
||||
ctl_headers[TEST_H_U8]
|
||||
= register_sysctl("debug/test_sysctl", table_u8_under);
|
||||
if (ctl_headers[TEST_H_U8])
|
||||
return -ENOMEM;
|
||||
|
||||
/* should not fail because it's valid */
|
||||
ctl_headers[TEST_H_U8]
|
||||
= register_sysctl("debug/test_sysctl", table_u8_valid);
|
||||
if (!ctl_headers[TEST_H_U8])
|
||||
return -ENOMEM;
|
||||
|
||||
return 0;
|
||||
|
|
@ -241,23 +302,19 @@ static int test_sysctl_run_register_empty(void)
|
|||
|
||||
static int __init test_sysctl_init(void)
|
||||
{
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
err = test_sysctl_setup_node_tests();
|
||||
if (err)
|
||||
goto out;
|
||||
int (*func_array[])(void) = {
|
||||
test_sysctl_setup_node_tests,
|
||||
test_sysctl_run_unregister_nested,
|
||||
test_sysctl_run_register_mount_point,
|
||||
test_sysctl_run_register_empty,
|
||||
test_sysctl_register_u8_extra
|
||||
};
|
||||
|
||||
err = test_sysctl_run_unregister_nested();
|
||||
if (err)
|
||||
goto out;
|
||||
for (int i = 0; !err && i < ARRAY_SIZE(func_array); i++)
|
||||
err = func_array[i]();
|
||||
|
||||
err = test_sysctl_run_register_mount_point();
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
err = test_sysctl_run_register_empty();
|
||||
|
||||
out:
|
||||
return err;
|
||||
}
|
||||
module_init(test_sysctl_init);
|
||||
|
|
@ -265,16 +322,10 @@ module_init(test_sysctl_init);
|
|||
static void __exit test_sysctl_exit(void)
|
||||
{
|
||||
kfree(test_data.bitmap_0001);
|
||||
if (sysctl_test_headers.test_h_setup_node)
|
||||
unregister_sysctl_table(sysctl_test_headers.test_h_setup_node);
|
||||
if (sysctl_test_headers.test_h_mnt)
|
||||
unregister_sysctl_table(sysctl_test_headers.test_h_mnt);
|
||||
if (sysctl_test_headers.test_h_mnterror)
|
||||
unregister_sysctl_table(sysctl_test_headers.test_h_mnterror);
|
||||
if (sysctl_test_headers.empty)
|
||||
unregister_sysctl_table(sysctl_test_headers.empty);
|
||||
if (sysctl_test_headers.empty_add)
|
||||
unregister_sysctl_table(sysctl_test_headers.empty_add);
|
||||
for (int i = 0; i < TEST_H_SIZE; i++) {
|
||||
if (ctl_headers[i])
|
||||
unregister_sysctl_table(ctl_headers[i]);
|
||||
}
|
||||
}
|
||||
|
||||
module_exit(test_sysctl_exit);
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ ALL_TESTS="$ALL_TESTS 0008:1:1:match_int:1"
|
|||
ALL_TESTS="$ALL_TESTS 0009:1:1:unregister_error:0"
|
||||
ALL_TESTS="$ALL_TESTS 0010:1:1:mnt/mnt_error:0"
|
||||
ALL_TESTS="$ALL_TESTS 0011:1:1:empty_add:0"
|
||||
ALL_TESTS="$ALL_TESTS 0012:1:1:u8_valid:0"
|
||||
|
||||
function allow_user_defaults()
|
||||
{
|
||||
|
|
@ -851,6 +852,34 @@ sysctl_test_0011()
|
|||
return 0
|
||||
}
|
||||
|
||||
sysctl_test_0012()
|
||||
{
|
||||
TARGET="${SYSCTL}/$(get_test_target 0012)"
|
||||
echo -n "Testing u8 range check in sysctl table check in ${TARGET} ... "
|
||||
if [ ! -f ${TARGET} ]; then
|
||||
echo -e "FAIL\nCould not create ${TARGET}" >&2
|
||||
rc=1
|
||||
test_rc
|
||||
fi
|
||||
|
||||
local u8over_msg=$(dmesg | grep "u8_over range value" | wc -l)
|
||||
if [ ! ${u8over_msg} -eq 1 ]; then
|
||||
echo -e "FAIL\nu8 overflow not detected" >&2
|
||||
rc=1
|
||||
test_rc
|
||||
fi
|
||||
|
||||
local u8under_msg=$(dmesg | grep "u8_under range value" | wc -l)
|
||||
if [ ! ${u8under_msg} -eq 1 ]; then
|
||||
echo -e "FAIL\nu8 underflow not detected" >&2
|
||||
rc=1
|
||||
test_rc
|
||||
fi
|
||||
|
||||
echo "OK"
|
||||
return 0
|
||||
}
|
||||
|
||||
list_tests()
|
||||
{
|
||||
echo "Test ID list:"
|
||||
|
|
@ -870,6 +899,7 @@ list_tests()
|
|||
echo "0009 x $(get_test_count 0009) - tests sysct unregister"
|
||||
echo "0010 x $(get_test_count 0010) - tests sysct mount point"
|
||||
echo "0011 x $(get_test_count 0011) - tests empty directories"
|
||||
echo "0012 x $(get_test_count 0012) - tests range check for u8 proc_handler"
|
||||
}
|
||||
|
||||
usage()
|
||||
|
|
|
|||
Loading…
Reference in New Issue