ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / 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 *buffer, size_t *lenp)
62 {
63         char            tmpbuf[20], *p, c;
64         unsigned int    value;
65         size_t          left, len;
66
67         if ((file->f_pos && !write) || !*lenp) {
68                 *lenp = 0;
69                 return 0;
70         }
71
72         left = *lenp;
73
74         if (write) {
75                 if (!access_ok(VERIFY_READ, buffer, left))
76                         return -EFAULT;
77                 p = (char *) buffer;
78                 while (left && __get_user(c, p) >= 0 && isspace(c))
79                         left--, p++;
80                 if (!left)
81                         goto done;
82
83                 if (left > sizeof(tmpbuf) - 1)
84                         return -EINVAL;
85                 if (copy_from_user(tmpbuf, p, left))
86                         return -EFAULT;
87                 tmpbuf[left] = '\0';
88
89                 for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
90                         value = 10 * value + (*p - '0');
91                 if (*p && !isspace(*p))
92                         return -EINVAL;
93                 while (left && isspace(*p))
94                         left--, p++;
95                 *(unsigned int *) table->data = value;
96                 /* Display the RPC tasks on writing to rpc_debug */
97                 if (table->ctl_name == CTL_RPCDEBUG) {
98                         rpc_show_tasks();
99                 }
100         } else {
101                 if (!access_ok(VERIFY_WRITE, buffer, left))
102                         return -EFAULT;
103                 len = sprintf(tmpbuf, "%d", *(unsigned int *) table->data);
104                 if (len > left)
105                         len = left;
106                 if (__copy_to_user(buffer, tmpbuf, len))
107                         return -EFAULT;
108                 if ((left -= len) > 0) {
109                         if (put_user('\n', (char *)buffer + len))
110                                 return -EFAULT;
111                         left--;
112                 }
113         }
114
115 done:
116         *lenp -= left;
117         file->f_pos += *lenp;
118         return 0;
119 }
120
121 static unsigned int min_slot_table_size = RPC_MIN_SLOT_TABLE;
122 static unsigned int max_slot_table_size = RPC_MAX_SLOT_TABLE;
123
124 static ctl_table debug_table[] = {
125         {
126                 .ctl_name       = CTL_RPCDEBUG,
127                 .procname       = "rpc_debug",
128                 .data           = &rpc_debug,
129                 .maxlen         = sizeof(int),
130                 .mode           = 0644,
131                 .proc_handler   = &proc_dodebug
132         }, 
133         {
134                 .ctl_name       = CTL_NFSDEBUG,
135                 .procname       = "nfs_debug",
136                 .data           = &nfs_debug,
137                 .maxlen         = sizeof(int),
138                 .mode           = 0644,
139                 .proc_handler   = &proc_dodebug
140         }, 
141         {
142                 .ctl_name       = CTL_NFSDDEBUG,
143                 .procname       = "nfsd_debug",
144                 .data           = &nfsd_debug,
145                 .maxlen         = sizeof(int),
146                 .mode           = 0644,
147                 .proc_handler   = &proc_dodebug
148         }, 
149         {
150                 .ctl_name       = CTL_NLMDEBUG,
151                 .procname       = "nlm_debug",
152                 .data           = &nlm_debug,
153                 .maxlen         = sizeof(int),
154                 .mode           = 0644,
155                 .proc_handler   = &proc_dodebug
156         }, 
157         {
158                 .ctl_name       = CTL_SLOTTABLE_UDP,
159                 .procname       = "udp_slot_table_entries",
160                 .data           = &xprt_udp_slot_table_entries,
161                 .maxlen         = sizeof(unsigned int),
162                 .mode           = 0644,
163                 .proc_handler   = &proc_dointvec_minmax,
164                 .strategy       = &sysctl_intvec,
165                 .extra1         = &min_slot_table_size,
166                 .extra2         = &max_slot_table_size
167         },
168         {
169                 .ctl_name       = CTL_SLOTTABLE_TCP,
170                 .procname       = "tcp_slot_table_entries",
171                 .data           = &xprt_tcp_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         { .ctl_name = 0 }
180 };
181
182 static ctl_table sunrpc_table[] = {
183         {
184                 .ctl_name       = CTL_SUNRPC,
185                 .procname       = "sunrpc",
186                 .mode           = 0555,
187                 .child          = debug_table
188         },
189         { .ctl_name = 0 }
190 };
191
192 #endif