Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / kernel / vserver / sysctl.c
1 /*
2  *  kernel/vserver/sysctl.c
3  *
4  *  Virtual Context Support
5  *
6  *  Copyright (C) 2004-2005  Herbert Pƶtzl
7  *
8  *  V0.01  basic structure
9  *
10  */
11
12 #include <linux/errno.h>
13 #include <linux/module.h>
14 #include <linux/types.h>
15 #include <linux/ctype.h>
16 #include <linux/sysctl.h>
17 #include <linux/parser.h>
18 #include <linux/fs.h>
19
20 #include <asm/uaccess.h>
21 #include <asm/unistd.h>
22
23
24 #define CTL_VSERVER     4242    /* unused? */
25
26 enum {
27         CTL_DEBUG_ERROR = 0,
28         CTL_DEBUG_SWITCH = 1,
29         CTL_DEBUG_XID,
30         CTL_DEBUG_NID,
31         CTL_DEBUG_NET,
32         CTL_DEBUG_LIMIT,
33         CTL_DEBUG_CRES,
34         CTL_DEBUG_DLIM,
35         CTL_DEBUG_CVIRT,
36         CTL_DEBUG_MISC,
37 };
38
39
40 unsigned int vx_debug_switch = 0;
41 unsigned int vx_debug_xid = 0;
42 unsigned int vx_debug_nid = 0;
43 unsigned int vx_debug_net = 0;
44 unsigned int vx_debug_limit = 0;
45 unsigned int vx_debug_cres = 0;
46 unsigned int vx_debug_dlim = 0;
47 unsigned int vx_debug_cvirt = 0;
48 unsigned int vx_debug_misc = 0;
49
50
51 static struct ctl_table_header *vserver_table_header;
52 static ctl_table vserver_table[];
53
54
55 void vserver_register_sysctl(void)
56 {
57         if (!vserver_table_header) {
58                 vserver_table_header = register_sysctl_table(vserver_table, 1);
59         }
60
61 }
62
63 void vserver_unregister_sysctl(void)
64 {
65         if (vserver_table_header) {
66                 unregister_sysctl_table(vserver_table_header);
67                 vserver_table_header = NULL;
68         }
69 }
70
71
72 static int proc_dodebug(ctl_table *table, int write,
73         struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
74 {
75         char            tmpbuf[20], *p, c;
76         unsigned int    value;
77         size_t          left, len;
78
79         if ((*ppos && !write) || !*lenp) {
80                 *lenp = 0;
81                 return 0;
82         }
83
84         left = *lenp;
85
86         if (write) {
87                 if (!access_ok(VERIFY_READ, buffer, left))
88                         return -EFAULT;
89                 p = (char *) buffer;
90                 while (left && __get_user(c, p) >= 0 && isspace(c))
91                         left--, p++;
92                 if (!left)
93                         goto done;
94
95                 if (left > sizeof(tmpbuf) - 1)
96                         return -EINVAL;
97                 if (copy_from_user(tmpbuf, p, left))
98                         return -EFAULT;
99                 tmpbuf[left] = '\0';
100
101                 for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
102                         value = 10 * value + (*p - '0');
103                 if (*p && !isspace(*p))
104                         return -EINVAL;
105                 while (left && isspace(*p))
106                         left--, p++;
107                 *(unsigned int *) table->data = value;
108         } else {
109                 if (!access_ok(VERIFY_WRITE, buffer, left))
110                         return -EFAULT;
111                 len = sprintf(tmpbuf, "%d", *(unsigned int *) table->data);
112                 if (len > left)
113                         len = left;
114                 if (__copy_to_user(buffer, tmpbuf, len))
115                         return -EFAULT;
116                 if ((left -= len) > 0) {
117                         if (put_user('\n', (char *)buffer + len))
118                                 return -EFAULT;
119                         left--;
120                 }
121         }
122
123 done:
124         *lenp -= left;
125         *ppos += *lenp;
126         return 0;
127 }
128
129
130
131 static ctl_table debug_table[] = {
132         {
133                 .ctl_name       = CTL_DEBUG_SWITCH,
134                 .procname       = "debug_switch",
135                 .data           = &vx_debug_switch,
136                 .maxlen         = sizeof(int),
137                 .mode           = 0644,
138                 .proc_handler   = &proc_dodebug
139         },
140         {
141                 .ctl_name       = CTL_DEBUG_XID,
142                 .procname       = "debug_xid",
143                 .data           = &vx_debug_xid,
144                 .maxlen         = sizeof(int),
145                 .mode           = 0644,
146                 .proc_handler   = &proc_dodebug
147         },
148         {
149                 .ctl_name       = CTL_DEBUG_NID,
150                 .procname       = "debug_nid",
151                 .data           = &vx_debug_nid,
152                 .maxlen         = sizeof(int),
153                 .mode           = 0644,
154                 .proc_handler   = &proc_dodebug
155         },
156         {
157                 .ctl_name       = CTL_DEBUG_NET,
158                 .procname       = "debug_net",
159                 .data           = &vx_debug_net,
160                 .maxlen         = sizeof(int),
161                 .mode           = 0644,
162                 .proc_handler   = &proc_dodebug
163         },
164         {
165                 .ctl_name       = CTL_DEBUG_LIMIT,
166                 .procname       = "debug_limit",
167                 .data           = &vx_debug_limit,
168                 .maxlen         = sizeof(int),
169                 .mode           = 0644,
170                 .proc_handler   = &proc_dodebug
171         },
172         {
173                 .ctl_name       = CTL_DEBUG_CRES,
174                 .procname       = "debug_cres",
175                 .data           = &vx_debug_cres,
176                 .maxlen         = sizeof(int),
177                 .mode           = 0644,
178                 .proc_handler   = &proc_dodebug
179         },
180         {
181                 .ctl_name       = CTL_DEBUG_DLIM,
182                 .procname       = "debug_dlim",
183                 .data           = &vx_debug_dlim,
184                 .maxlen         = sizeof(int),
185                 .mode           = 0644,
186                 .proc_handler   = &proc_dodebug
187         },
188         {
189                 .ctl_name       = CTL_DEBUG_CVIRT,
190                 .procname       = "debug_cvirt",
191                 .data           = &vx_debug_cvirt,
192                 .maxlen         = sizeof(int),
193                 .mode           = 0644,
194                 .proc_handler   = &proc_dodebug
195         },
196         {
197                 .ctl_name       = CTL_DEBUG_MISC,
198                 .procname       = "debug_misc",
199                 .data           = &vx_debug_misc,
200                 .maxlen         = sizeof(int),
201                 .mode           = 0644,
202                 .proc_handler   = &proc_dodebug
203         },
204         { .ctl_name = 0 }
205 };
206
207 static ctl_table vserver_table[] = {
208         {
209                 .ctl_name       = CTL_VSERVER,
210                 .procname       = "vserver",
211                 .mode           = 0555,
212                 .child          = debug_table
213         },
214         { .ctl_name = 0 }
215 };
216
217
218 EXPORT_SYMBOL_GPL(vx_debug_switch);
219 EXPORT_SYMBOL_GPL(vx_debug_xid);
220 EXPORT_SYMBOL_GPL(vx_debug_nid);
221 EXPORT_SYMBOL_GPL(vx_debug_net);
222 EXPORT_SYMBOL_GPL(vx_debug_limit);
223 EXPORT_SYMBOL_GPL(vx_debug_cres);
224 EXPORT_SYMBOL_GPL(vx_debug_dlim);
225 EXPORT_SYMBOL_GPL(vx_debug_cvirt);
226 EXPORT_SYMBOL_GPL(vx_debug_misc);
227