vserver 1.9.3
[linux-2.6.git] / kernel / vserver / sysctl.c
1 /*
2  *  linux/kernel/sysctl.c
3  *
4  *  Virtual Context Support
5  *
6  *  Copyright (C) 2004  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/vserver.h>
15 #include <linux/module.h>
16 #include <linux/types.h>
17 #include <linux/ctype.h>
18 #include <linux/sysctl.h>
19 #include <linux/fs.h>
20
21 #include <asm/uaccess.h>
22 #include <asm/unistd.h>
23
24
25 #define CTL_VSERVER     4242    /* unused? */
26
27 enum {
28         CTL_DEBUG_SWITCH = 1,
29         CTL_DEBUG_XID,
30         CTL_DEBUG_NID,
31         CTL_DEBUG_NET,
32         CTL_DEBUG_LIMIT,
33         CTL_DEBUG_DLIM,
34         CTL_DEBUG_CVIRT,
35 };
36
37
38 unsigned int vx_debug_switch = 0;
39 unsigned int vx_debug_xid = 0;
40 unsigned int vx_debug_nid = 0;
41 unsigned int vx_debug_net = 0;
42 unsigned int vx_debug_limit = 0;
43 unsigned int vx_debug_dlim = 0;
44 unsigned int vx_debug_cvirt = 0;
45
46
47 static struct ctl_table_header *vserver_table_header;
48 static ctl_table vserver_table[];
49
50
51 void vserver_register_sysctl(void)
52 {
53         if (!vserver_table_header) {
54                 vserver_table_header = register_sysctl_table(vserver_table, 1);
55 #ifdef CONFIG_PROC_FS
56 //              if (vserver_table[0].de)
57 //                      vserver_table[0].de->owner = THIS_MODULE;
58 #endif
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_DLIM,
174                 .procname       = "debug_dlim",
175                 .data           = &vx_debug_dlim,
176                 .maxlen         = sizeof(int),
177                 .mode           = 0644,
178                 .proc_handler   = &proc_dodebug
179         },
180         {
181                 .ctl_name       = CTL_DEBUG_CVIRT,
182                 .procname       = "debug_cvirt",
183                 .data           = &vx_debug_cvirt,
184                 .maxlen         = sizeof(int),
185                 .mode           = 0644,
186                 .proc_handler   = &proc_dodebug
187         },
188         { .ctl_name = 0 }
189 };
190
191 static ctl_table vserver_table[] = {
192         {
193                 .ctl_name       = CTL_VSERVER,
194                 .procname       = "vserver",
195                 .mode           = 0555,
196                 .child          = debug_table
197         },
198         { .ctl_name = 0 }
199 };
200
201
202 EXPORT_SYMBOL_GPL(vx_debug_switch);
203 EXPORT_SYMBOL_GPL(vx_debug_xid);
204 EXPORT_SYMBOL_GPL(vx_debug_nid);
205 EXPORT_SYMBOL_GPL(vx_debug_net);
206 EXPORT_SYMBOL_GPL(vx_debug_limit);
207 EXPORT_SYMBOL_GPL(vx_debug_dlim);
208 EXPORT_SYMBOL_GPL(vx_debug_cvirt);
209