1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
#include <linux/module.h>
#include <linux/sysctl.h>
#include <linux/slab.h>
#include <litmus/color.h>
extern int color_sysctl_add_pages_data; /* litmus/color.c */
static int zero = 0;
static int one = 1;
#define NR_PAGES_INDEX 1 /* location of nr_pages in the table below */
static struct ctl_table color_table[] =
{
{
.procname = "add_pages",
.data = &color_sysctl_add_pages_data,
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = color_add_pages_handler,
.extra1 = &zero,
.extra2 = &one,
},
{
.procname = "nr_pages",
.mode = 0444,
.proc_handler = color_nr_pages_handler,
.data = NULL, /* dynamically later */
.maxlen = 0, /* also set later */
},
{ }
};
static struct ctl_table litmus_table[] =
{
{
.procname = "color",
.mode = 0555,
.child = color_table,
},
{ }
};
static struct ctl_table litmus_dir_table[] = {
{
.procname = "litmus",
.mode = 0555,
.child = litmus_table,
},
{ }
};
extern unsigned long nr_colors; /* litmus/color.c */
/* must be called AFTER nr_colors is set */
static int __init init_sysctl_nr_colors(void)
{
int ret = 0, maxlen = ONE_COLOR_LEN * nr_colors;
color_table[NR_PAGES_INDEX].data = kmalloc(maxlen, GFP_KERNEL);
if (!color_table[NR_PAGES_INDEX].data) {
printk(KERN_WARNING "Could not allocate nr_pages buffer.\n");
ret = -ENOMEM;
goto out;
}
color_table[NR_PAGES_INDEX].maxlen = maxlen;
out:
return ret;
}
static struct ctl_table_header *litmus_sysctls;
static int __init litmus_sysctl_init(void)
{
int ret = 0;
litmus_sysctls = register_sysctl_table(litmus_dir_table);
if (!litmus_sysctls) {
printk(KERN_WARNING "Could not register LITMUS^RT sysctl.\n");
ret = -EFAULT;
goto out;
}
ret = init_sysctl_nr_colors();
out:
return ret;
}
module_init(litmus_sysctl_init);
|