Merge master.kernel.org:/pub/scm/linux/kernel/git/airlied/drm-2.6
[linux-2.6] / net / sunrpc / sysctl.c
1 /*
2  * linux/net/sunrpc/sysctl.c
3  *
4  * Sysctl interface to sunrpc module.
5  *
6  * I would prefer to register the sunrpc table below sys/net, but that's
7  * impossible at the moment.
8  */
9
10 #include <linux/config.h>
11 #include <linux/types.h>
12 #include <linux/linkage.h>
13 #include <linux/ctype.h>
14 #include <linux/fs.h>
15 #include <linux/sysctl.h>
16 #include <linux/module.h>
17
18 #include <asm/uaccess.h>
19 #include <linux/sunrpc/types.h>
20 #include <linux/sunrpc/sched.h>
21 #include <linux/sunrpc/stats.h>
22 #include <linux/sunrpc/xprt.h>
23
24 /*
25  * Declare the debug flags here
26  */
27 unsigned int    rpc_debug;
28 unsigned int    nfs_debug;
29 unsigned int    nfsd_debug;
30 unsigned int    nlm_debug;
31
32 #ifdef RPC_DEBUG
33
34 static struct ctl_table_header *sunrpc_table_header;
35 static ctl_table                sunrpc_table[];
36
37 void
38 rpc_register_sysctl(void)
39 {
40         if (!sunrpc_table_header) {
41                 sunrpc_table_header = register_sysctl_table(sunrpc_table, 1);
42 #ifdef CONFIG_PROC_FS
43                 if (sunrpc_table[0].de)
44                         sunrpc_table[0].de->owner = THIS_MODULE;
45 #endif
46         }
47                         
48 }
49
50 void
51 rpc_unregister_sysctl(void)
52 {
53         if (sunrpc_table_header) {
54                 unregister_sysctl_table(sunrpc_table_header);
55                 sunrpc_table_header = NULL;
56         }
57 }
58
59 static int
60 proc_dodebug(ctl_table *table, int write, struct file *file,
61                                 void __user *buffer, size_t *lenp, loff_t *ppos)
62 {
63         char            tmpbuf[20], c, *s;
64         char __user *p;
65         unsigned int    value;
66         size_t          left, len;
67
68         if ((*ppos && !write) || !*lenp) {
69                 *lenp = 0;
70                 return 0;
71         }
72
73         left = *lenp;
74
75         if (write) {
76                 if (!access_ok(VERIFY_READ, buffer, left))
77                         return -EFAULT;
78                 p = buffer;
79                 while (left && __get_user(c, p) >= 0 && isspace(c))
80                         left--, p++;
81                 if (!left)
82                         goto done;
83
84                 if (left > sizeof(tmpbuf) - 1)
85                         return -EINVAL;
86                 if (copy_from_user(tmpbuf, p, left))
87                         return -EFAULT;
88                 tmpbuf[left] = '\0';
89
90                 for (s = tmpbuf, value = 0; '0' <= *s && *s <= '9'; s++, left--)
91                         value = 10 * value + (*s - '0');
92                 if (*s && !isspace(*s))
93                         return -EINVAL;
94                 while (left && isspace(*s))
95                         left--, s++;
96                 *(unsigned int *) table->data = value;
97                 /* Display the RPC tasks on writing to rpc_debug */
98                 if (table->ctl_name == CTL_RPCDEBUG) {
99                         rpc_show_tasks();
100                 }
101         } else {
102                 if (!access_ok(VERIFY_WRITE, buffer, left))
103                         return -EFAULT;
104                 len = sprintf(tmpbuf, "%d", *(unsigned int *) table->data);
105                 if (len > left)
106                         len = left;
107                 if (__copy_to_user(buffer, tmpbuf, len))
108                         return -EFAULT;
109                 if ((left -= len) > 0) {
110                         if (put_user('\n', (char __user *)buffer + len))
111                                 return -EFAULT;
112                         left--;
113                 }
114         }
115
116 done:
117         *lenp -= left;
118         *ppos += *lenp;
119         return 0;
120 }
121
122 unsigned int xprt_udp_slot_table_entries = RPC_DEF_SLOT_TABLE;
123 unsigned int xprt_tcp_slot_table_entries = RPC_DEF_SLOT_TABLE;
124 unsigned int xprt_min_resvport = RPC_DEF_MIN_RESVPORT;
125 EXPORT_SYMBOL(xprt_min_resvport);
126 unsigned int xprt_max_resvport = RPC_DEF_MAX_RESVPORT;
127 EXPORT_SYMBOL(xprt_max_resvport);
128
129
130 static unsigned int min_slot_table_size = RPC_MIN_SLOT_TABLE;
131 static unsigned int max_slot_table_size = RPC_MAX_SLOT_TABLE;
132 static unsigned int xprt_min_resvport_limit = RPC_MIN_RESVPORT;
133 static unsigned int xprt_max_resvport_limit = RPC_MAX_RESVPORT;
134
135 static ctl_table debug_table[] = {
136         {
137                 .ctl_name       = CTL_RPCDEBUG,
138                 .procname       = "rpc_debug",
139                 .data           = &rpc_debug,
140                 .maxlen         = sizeof(int),
141                 .mode           = 0644,
142                 .proc_handler   = &proc_dodebug
143         }, 
144         {
145                 .ctl_name       = CTL_NFSDEBUG,
146                 .procname       = "nfs_debug",
147                 .data           = &nfs_debug,
148                 .maxlen         = sizeof(int),
149                 .mode           = 0644,
150                 .proc_handler   = &proc_dodebug
151         }, 
152         {
153                 .ctl_name       = CTL_NFSDDEBUG,
154                 .procname       = "nfsd_debug",
155                 .data           = &nfsd_debug,
156                 .maxlen         = sizeof(int),
157                 .mode           = 0644,
158                 .proc_handler   = &proc_dodebug
159         }, 
160         {
161                 .ctl_name       = CTL_NLMDEBUG,
162                 .procname       = "nlm_debug",
163                 .data           = &nlm_debug,
164                 .maxlen         = sizeof(int),
165                 .mode           = 0644,
166                 .proc_handler   = &proc_dodebug
167         }, 
168         {
169                 .ctl_name       = CTL_SLOTTABLE_UDP,
170                 .procname       = "udp_slot_table_entries",
171                 .data           = &xprt_udp_slot_table_entries,
172                 .maxlen         = sizeof(unsigned int),
173                 .mode           = 0644,
174                 .proc_handler   = &proc_dointvec_minmax,
175                 .strategy       = &sysctl_intvec,
176                 .extra1         = &min_slot_table_size,
177                 .extra2         = &max_slot_table_size
178         },
179         {
180                 .ctl_name       = CTL_SLOTTABLE_TCP,
181                 .procname       = "tcp_slot_table_entries",
182                 .data           = &xprt_tcp_slot_table_entries,
183                 .maxlen         = sizeof(unsigned int),
184                 .mode           = 0644,
185                 .proc_handler   = &proc_dointvec_minmax,
186                 .strategy       = &sysctl_intvec,
187                 .extra1         = &min_slot_table_size,
188                 .extra2         = &max_slot_table_size
189         },
190         {
191                 .ctl_name       = CTL_MIN_RESVPORT,
192                 .procname       = "min_resvport",
193                 .data           = &xprt_min_resvport,
194                 .maxlen         = sizeof(unsigned int),
195                 .mode           = 0644,
196                 .proc_handler   = &proc_dointvec_minmax,
197                 .strategy       = &sysctl_intvec,
198                 .extra1         = &xprt_min_resvport_limit,
199                 .extra2         = &xprt_max_resvport_limit
200         },
201         {
202                 .ctl_name       = CTL_MAX_RESVPORT,
203                 .procname       = "max_resvport",
204                 .data           = &xprt_max_resvport,
205                 .maxlen         = sizeof(unsigned int),
206                 .mode           = 0644,
207                 .proc_handler   = &proc_dointvec_minmax,
208                 .strategy       = &sysctl_intvec,
209                 .extra1         = &xprt_min_resvport_limit,
210                 .extra2         = &xprt_max_resvport_limit
211         },
212         { .ctl_name = 0 }
213 };
214
215 static ctl_table sunrpc_table[] = {
216         {
217                 .ctl_name       = CTL_SUNRPC,
218                 .procname       = "sunrpc",
219                 .mode           = 0555,
220                 .child          = debug_table
221         },
222         { .ctl_name = 0 }
223 };
224
225 #endif