vserver 1.9.5.x5
[linux-2.6.git] / kernel / vserver / sysctl.c
1 /*
2  *  linux/kernel/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/config.h>
13 #include <linux/errno.h>
14 #include <linux/module.h>
15 #include <linux/types.h>
16 #include <linux/ctype.h>
17 #include <linux/sysctl.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_SWITCH = 1,
28         CTL_DEBUG_XID,
29         CTL_DEBUG_NID,
30         CTL_DEBUG_NET,
31         CTL_DEBUG_LIMIT,
32         CTL_DEBUG_DLIM,
33         CTL_DEBUG_CVIRT,
34 };
35
36
37 unsigned int vx_debug_switch = 0;
38 unsigned int vx_debug_xid = 0;
39 unsigned int vx_debug_nid = 0;
40 unsigned int vx_debug_net = 0;
41 unsigned int vx_debug_limit = 0;
42 unsigned int vx_debug_dlim = 0;
43 unsigned int vx_debug_cvirt = 0;
44
45
46 static struct ctl_table_header *vserver_table_header;
47 static ctl_table vserver_table[];
48
49
50 void vserver_register_sysctl(void)
51 {
52         if (!vserver_table_header) {
53                 vserver_table_header = register_sysctl_table(vserver_table, 1);
54         }
55
56 }
57
58 void vserver_unregister_sysctl(void)
59 {
60         if (vserver_table_header) {
61                 unregister_sysctl_table(vserver_table_header);
62                 vserver_table_header = NULL;
63         }
64 }
65
66
67 static int proc_dodebug(ctl_table *table, int write,
68         struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
69 {
70         char            tmpbuf[20], *p, c;
71         unsigned int    value;
72         size_t          left, len;
73
74         if ((*ppos && !write) || !*lenp) {
75                 *lenp = 0;
76                 return 0;
77         }
78
79         left = *lenp;
80
81         if (write) {
82                 if (!access_ok(VERIFY_READ, buffer, left))
83                         return -EFAULT;
84                 p = (char *) buffer;
85                 while (left && __get_user(c, p) >= 0 && isspace(c))
86                         left--, p++;
87                 if (!left)
88                         goto done;
89
90                 if (left > sizeof(tmpbuf) - 1)
91                         return -EINVAL;
92                 if (copy_from_user(tmpbuf, p, left))
93                         return -EFAULT;
94                 tmpbuf[left] = '\0';
95
96                 for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
97                         value = 10 * value + (*p - '0');
98                 if (*p && !isspace(*p))
99                         return -EINVAL;
100                 while (left && isspace(*p))
101                         left--, p++;
102                 *(unsigned int *) table->data = value;
103         } else {
104                 if (!access_ok(VERIFY_WRITE, buffer, left))
105                         return -EFAULT;
106                 len = sprintf(tmpbuf, "%d", *(unsigned int *) table->data);
107                 if (len > left)
108                         len = left;
109                 if (__copy_to_user(buffer, tmpbuf, len))
110                         return -EFAULT;
111                 if ((left -= len) > 0) {
112                         if (put_user('\n', (char *)buffer + len))
113                                 return -EFAULT;
114                         left--;
115                 }
116         }
117
118 done:
119         *lenp -= left;
120         *ppos += *lenp;
121         return 0;
122 }
123
124
125
126 static ctl_table debug_table[] = {
127         {
128                 .ctl_name       = CTL_DEBUG_SWITCH,
129                 .procname       = "debug_switch",
130                 .data           = &vx_debug_switch,
131                 .maxlen         = sizeof(int),
132                 .mode           = 0644,
133                 .proc_handler   = &proc_dodebug
134         },
135         {
136                 .ctl_name       = CTL_DEBUG_XID,
137                 .procname       = "debug_xid",
138                 .data           = &vx_debug_xid,
139                 .maxlen         = sizeof(int),
140                 .mode           = 0644,
141                 .proc_handler   = &proc_dodebug
142         },
143         {
144                 .ctl_name       = CTL_DEBUG_NID,
145                 .procname       = "debug_nid",
146                 .data           = &vx_debug_nid,
147                 .maxlen         = sizeof(int),
148                 .mode           = 0644,
149                 .proc_handler   = &proc_dodebug
150         },
151         {
152                 .ctl_name       = CTL_DEBUG_NET,
153                 .procname       = "debug_net",
154                 .data           = &vx_debug_net,
155                 .maxlen         = sizeof(int),
156                 .mode           = 0644,
157                 .proc_handler   = &proc_dodebug
158         },
159         {
160                 .ctl_name       = CTL_DEBUG_LIMIT,
161                 .procname       = "debug_limit",
162                 .data           = &vx_debug_limit,
163                 .maxlen         = sizeof(int),
164                 .mode           = 0644,
165                 .proc_handler   = &proc_dodebug
166         },
167         {
168                 .ctl_name       = CTL_DEBUG_DLIM,
169                 .procname       = "debug_dlim",
170                 .data           = &vx_debug_dlim,
171                 .maxlen         = sizeof(int),
172                 .mode           = 0644,
173                 .proc_handler   = &proc_dodebug
174         },
175         {
176                 .ctl_name       = CTL_DEBUG_CVIRT,
177                 .procname       = "debug_cvirt",
178                 .data           = &vx_debug_cvirt,
179                 .maxlen         = sizeof(int),
180                 .mode           = 0644,
181                 .proc_handler   = &proc_dodebug
182         },
183         { .ctl_name = 0 }
184 };
185
186 static ctl_table vserver_table[] = {
187         {
188                 .ctl_name       = CTL_VSERVER,
189                 .procname       = "vserver",
190                 .mode           = 0555,
191                 .child          = debug_table
192         },
193         { .ctl_name = 0 }
194 };
195
196
197 EXPORT_SYMBOL_GPL(vx_debug_switch);
198 EXPORT_SYMBOL_GPL(vx_debug_xid);
199 EXPORT_SYMBOL_GPL(vx_debug_nid);
200 EXPORT_SYMBOL_GPL(vx_debug_net);
201 EXPORT_SYMBOL_GPL(vx_debug_limit);
202 EXPORT_SYMBOL_GPL(vx_debug_dlim);
203 EXPORT_SYMBOL_GPL(vx_debug_cvirt);
204