blob: c879732ae9d044c92b46fff834d04f9cba2a2125 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/types.h>
11#include <linux/linkage.h>
12#include <linux/ctype.h>
13#include <linux/fs.h>
14#include <linux/sysctl.h>
15#include <linux/module.h>
16
17#include <asm/uaccess.h>
18#include <linux/sunrpc/types.h>
19#include <linux/sunrpc/sched.h>
20#include <linux/sunrpc/stats.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22/*
23 * Declare the debug flags here
24 */
25unsigned int rpc_debug;
Trond Myklebusta6eaf8b2007-07-14 15:39:58 -040026EXPORT_SYMBOL(rpc_debug);
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028unsigned int nfs_debug;
Trond Myklebusta6eaf8b2007-07-14 15:39:58 -040029EXPORT_SYMBOL(nfs_debug);
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031unsigned int nfsd_debug;
Trond Myklebusta6eaf8b2007-07-14 15:39:58 -040032EXPORT_SYMBOL(nfsd_debug);
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034unsigned int nlm_debug;
Trond Myklebusta6eaf8b2007-07-14 15:39:58 -040035EXPORT_SYMBOL(nlm_debug);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37#ifdef RPC_DEBUG
38
39static struct ctl_table_header *sunrpc_table_header;
40static ctl_table sunrpc_table[];
41
42void
43rpc_register_sysctl(void)
44{
Eric W. Biederman2b1bec52007-02-14 00:33:24 -080045 if (!sunrpc_table_header)
Eric W. Biederman0b4d4142007-02-14 00:34:09 -080046 sunrpc_table_header = register_sysctl_table(sunrpc_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047}
48
49void
50rpc_unregister_sysctl(void)
51{
52 if (sunrpc_table_header) {
53 unregister_sysctl_table(sunrpc_table_header);
54 sunrpc_table_header = NULL;
55 }
56}
57
58static int
59proc_dodebug(ctl_table *table, int write, struct file *file,
60 void __user *buffer, size_t *lenp, loff_t *ppos)
61{
62 char tmpbuf[20], c, *s;
63 char __user *p;
64 unsigned int value;
65 size_t left, len;
66
67 if ((*ppos && !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 = 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 (s = tmpbuf, value = 0; '0' <= *s && *s <= '9'; s++, left--)
90 value = 10 * value + (*s - '0');
91 if (*s && !isspace(*s))
92 return -EINVAL;
93 while (left && isspace(*s))
94 left--, s++;
95 *(unsigned int *) table->data = value;
96 /* Display the RPC tasks on writing to rpc_debug */
J. Bruce Fieldsbc2a3f82007-10-29 14:37:18 -070097 if (strcmp(table->procname, "rpc_debug") == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 rpc_show_tasks();
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 } else {
100 if (!access_ok(VERIFY_WRITE, buffer, left))
101 return -EFAULT;
102 len = sprintf(tmpbuf, "%d", *(unsigned int *) table->data);
103 if (len > left)
104 len = left;
105 if (__copy_to_user(buffer, tmpbuf, len))
106 return -EFAULT;
107 if ((left -= len) > 0) {
108 if (put_user('\n', (char __user *)buffer + len))
109 return -EFAULT;
110 left--;
111 }
112 }
113
114done:
115 *lenp -= left;
116 *ppos += *lenp;
117 return 0;
118}
119
Chuck Levera246b012005-08-11 16:25:23 -0400120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121static ctl_table debug_table[] = {
122 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 .procname = "rpc_debug",
124 .data = &rpc_debug,
125 .maxlen = sizeof(int),
126 .mode = 0644,
127 .proc_handler = &proc_dodebug
YOSHIFUJI Hideakicca51722007-02-09 15:38:13 -0800128 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 .procname = "nfs_debug",
131 .data = &nfs_debug,
132 .maxlen = sizeof(int),
133 .mode = 0644,
134 .proc_handler = &proc_dodebug
YOSHIFUJI Hideakicca51722007-02-09 15:38:13 -0800135 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 .procname = "nfsd_debug",
138 .data = &nfsd_debug,
139 .maxlen = sizeof(int),
140 .mode = 0644,
141 .proc_handler = &proc_dodebug
YOSHIFUJI Hideakicca51722007-02-09 15:38:13 -0800142 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 .procname = "nlm_debug",
145 .data = &nlm_debug,
146 .maxlen = sizeof(int),
147 .mode = 0644,
148 .proc_handler = &proc_dodebug
YOSHIFUJI Hideakicca51722007-02-09 15:38:13 -0800149 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 { .ctl_name = 0 }
151};
152
153static ctl_table sunrpc_table[] = {
154 {
155 .ctl_name = CTL_SUNRPC,
156 .procname = "sunrpc",
157 .mode = 0555,
158 .child = debug_table
159 },
160 { .ctl_name = 0 }
161};
162
163#endif