2 * kernel/vserver/sysctl.c
4 * Virtual Context Support
6 * Copyright (C) 2004-2007 Herbert Pƶtzl
8 * V0.01 basic structure
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>
20 #include <asm/uaccess.h>
21 #include <asm/unistd.h>
24 #define CTL_VSERVER 4242 /* unused? */
42 unsigned int vx_debug_switch = 0;
43 unsigned int vx_debug_xid = 0;
44 unsigned int vx_debug_nid = 0;
45 unsigned int vx_debug_tag = 0;
46 unsigned int vx_debug_net = 0;
47 unsigned int vx_debug_limit = 0;
48 unsigned int vx_debug_cres = 0;
49 unsigned int vx_debug_dlim = 0;
50 unsigned int vx_debug_quota = 0;
51 unsigned int vx_debug_cvirt = 0;
52 unsigned int vx_debug_misc = 0;
55 static struct ctl_table_header *vserver_table_header;
56 static ctl_table vserver_table[];
59 void vserver_register_sysctl(void)
61 if (!vserver_table_header) {
62 vserver_table_header = register_sysctl_table(vserver_table, 1);
67 void vserver_unregister_sysctl(void)
69 if (vserver_table_header) {
70 unregister_sysctl_table(vserver_table_header);
71 vserver_table_header = NULL;
76 static int proc_dodebug(ctl_table *table, int write,
77 struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
79 char tmpbuf[20], *p, c;
83 if ((*ppos && !write) || !*lenp) {
91 if (!access_ok(VERIFY_READ, buffer, left))
94 while (left && __get_user(c, p) >= 0 && isspace(c))
99 if (left > sizeof(tmpbuf) - 1)
101 if (copy_from_user(tmpbuf, p, left))
105 for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
106 value = 10 * value + (*p - '0');
107 if (*p && !isspace(*p))
109 while (left && isspace(*p))
111 *(unsigned int *) table->data = value;
113 if (!access_ok(VERIFY_WRITE, buffer, left))
115 len = sprintf(tmpbuf, "%d", *(unsigned int *) table->data);
118 if (__copy_to_user(buffer, tmpbuf, len))
120 if ((left -= len) > 0) {
121 if (put_user('\n', (char *)buffer + len))
134 #define CTL_ENTRY(ctl, name) \
138 .data = &vx_##name, \
139 .maxlen = sizeof(int), \
141 .proc_handler = &proc_dodebug \
144 static ctl_table debug_table[] = {
145 CTL_ENTRY (CTL_DEBUG_SWITCH, debug_switch),
146 CTL_ENTRY (CTL_DEBUG_XID, debug_xid),
147 CTL_ENTRY (CTL_DEBUG_NID, debug_nid),
148 CTL_ENTRY (CTL_DEBUG_TAG, debug_tag),
149 CTL_ENTRY (CTL_DEBUG_NET, debug_net),
150 CTL_ENTRY (CTL_DEBUG_LIMIT, debug_limit),
151 CTL_ENTRY (CTL_DEBUG_CRES, debug_cres),
152 CTL_ENTRY (CTL_DEBUG_DLIM, debug_dlim),
153 CTL_ENTRY (CTL_DEBUG_QUOTA, debug_quota),
154 CTL_ENTRY (CTL_DEBUG_CVIRT, debug_cvirt),
155 CTL_ENTRY (CTL_DEBUG_MISC, debug_misc),
159 static ctl_table vserver_table[] = {
161 .ctl_name = CTL_VSERVER,
162 .procname = "vserver",
170 static match_table_t tokens = {
171 { CTL_DEBUG_SWITCH, "switch=%x" },
172 { CTL_DEBUG_XID, "xid=%x" },
173 { CTL_DEBUG_NID, "nid=%x" },
174 { CTL_DEBUG_TAG, "tag=%x" },
175 { CTL_DEBUG_NET, "net=%x" },
176 { CTL_DEBUG_LIMIT, "limit=%x" },
177 { CTL_DEBUG_CRES, "cres=%x" },
178 { CTL_DEBUG_DLIM, "dlim=%x" },
179 { CTL_DEBUG_QUOTA, "quota=%x" },
180 { CTL_DEBUG_CVIRT, "cvirt=%x" },
181 { CTL_DEBUG_MISC, "misc=%x" },
182 { CTL_DEBUG_ERROR, NULL }
185 #define HANDLE_CASE(id, name, val) \
186 case CTL_DEBUG_ ## id: \
187 vx_debug_ ## name = val; \
188 printk("vs_debug_" #name "=0x%x\n", val); \
192 static int __init vs_debug_setup(char *str)
197 printk("vs_debug_setup(%s)\n", str);
198 while ((p = strsep(&str, ",")) != NULL) {
199 substring_t args[MAX_OPT_ARGS];
205 token = match_token(p, tokens, args);
206 value = (token>0)?simple_strtoul(args[0].from, NULL, 0):0;
209 HANDLE_CASE(SWITCH, switch, value);
210 HANDLE_CASE(XID, xid, value);
211 HANDLE_CASE(NID, nid, value);
212 HANDLE_CASE(TAG, tag, value);
213 HANDLE_CASE(NET, net, value);
214 HANDLE_CASE(LIMIT, limit, value);
215 HANDLE_CASE(CRES, cres, value);
216 HANDLE_CASE(DLIM, dlim, value);
217 HANDLE_CASE(QUOTA, quota, value);
218 HANDLE_CASE(CVIRT, cvirt, value);
219 HANDLE_CASE(MISC, misc, value);
228 __setup("vsdebug=", vs_debug_setup);
232 EXPORT_SYMBOL_GPL(vx_debug_switch);
233 EXPORT_SYMBOL_GPL(vx_debug_xid);
234 EXPORT_SYMBOL_GPL(vx_debug_nid);
235 EXPORT_SYMBOL_GPL(vx_debug_net);
236 EXPORT_SYMBOL_GPL(vx_debug_limit);
237 EXPORT_SYMBOL_GPL(vx_debug_cres);
238 EXPORT_SYMBOL_GPL(vx_debug_dlim);
239 EXPORT_SYMBOL_GPL(vx_debug_quota);
240 EXPORT_SYMBOL_GPL(vx_debug_cvirt);
241 EXPORT_SYMBOL_GPL(vx_debug_misc);