xref: /linux/net/sunrpc/sysctl.c (revision 99b5aa3c10c7cff1e97239fda93649222fc12d25)
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/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>
21 
22 /*
23  * Declare the debug flags here
24  */
25 unsigned int	rpc_debug;
26 unsigned int	nfs_debug;
27 unsigned int	nfsd_debug;
28 unsigned int	nlm_debug;
29 
30 #ifdef RPC_DEBUG
31 
32 static struct ctl_table_header *sunrpc_table_header;
33 static ctl_table		sunrpc_table[];
34 
35 void
36 rpc_register_sysctl(void)
37 {
38 	if (!sunrpc_table_header) {
39 		sunrpc_table_header = register_sysctl_table(sunrpc_table, 1);
40 #ifdef CONFIG_PROC_FS
41 		if (sunrpc_table[0].de)
42 			sunrpc_table[0].de->owner = THIS_MODULE;
43 #endif
44 	}
45 
46 }
47 
48 void
49 rpc_unregister_sysctl(void)
50 {
51 	if (sunrpc_table_header) {
52 		unregister_sysctl_table(sunrpc_table_header);
53 		sunrpc_table_header = NULL;
54 	}
55 }
56 
57 static int
58 proc_dodebug(ctl_table *table, int write, struct file *file,
59 				void __user *buffer, size_t *lenp, loff_t *ppos)
60 {
61 	char		tmpbuf[20], c, *s;
62 	char __user *p;
63 	unsigned int	value;
64 	size_t		left, len;
65 
66 	if ((*ppos && !write) || !*lenp) {
67 		*lenp = 0;
68 		return 0;
69 	}
70 
71 	left = *lenp;
72 
73 	if (write) {
74 		if (!access_ok(VERIFY_READ, buffer, left))
75 			return -EFAULT;
76 		p = buffer;
77 		while (left && __get_user(c, p) >= 0 && isspace(c))
78 			left--, p++;
79 		if (!left)
80 			goto done;
81 
82 		if (left > sizeof(tmpbuf) - 1)
83 			return -EINVAL;
84 		if (copy_from_user(tmpbuf, p, left))
85 			return -EFAULT;
86 		tmpbuf[left] = '\0';
87 
88 		for (s = tmpbuf, value = 0; '0' <= *s && *s <= '9'; s++, left--)
89 			value = 10 * value + (*s - '0');
90 		if (*s && !isspace(*s))
91 			return -EINVAL;
92 		while (left && isspace(*s))
93 			left--, s++;
94 		*(unsigned int *) table->data = value;
95 		/* Display the RPC tasks on writing to rpc_debug */
96 		if (table->ctl_name == CTL_RPCDEBUG) {
97 			rpc_show_tasks();
98 		}
99 	} 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 
114 done:
115 	*lenp -= left;
116 	*ppos += *lenp;
117 	return 0;
118 }
119 
120 
121 static ctl_table debug_table[] = {
122 	{
123 		.ctl_name	= CTL_RPCDEBUG,
124 		.procname	= "rpc_debug",
125 		.data		= &rpc_debug,
126 		.maxlen		= sizeof(int),
127 		.mode		= 0644,
128 		.proc_handler	= &proc_dodebug
129 	},
130 	{
131 		.ctl_name	= CTL_NFSDEBUG,
132 		.procname	= "nfs_debug",
133 		.data		= &nfs_debug,
134 		.maxlen		= sizeof(int),
135 		.mode		= 0644,
136 		.proc_handler	= &proc_dodebug
137 	},
138 	{
139 		.ctl_name	= CTL_NFSDDEBUG,
140 		.procname	= "nfsd_debug",
141 		.data		= &nfsd_debug,
142 		.maxlen		= sizeof(int),
143 		.mode		= 0644,
144 		.proc_handler	= &proc_dodebug
145 	},
146 	{
147 		.ctl_name	= CTL_NLMDEBUG,
148 		.procname	= "nlm_debug",
149 		.data		= &nlm_debug,
150 		.maxlen		= sizeof(int),
151 		.mode		= 0644,
152 		.proc_handler	= &proc_dodebug
153 	},
154 	{ .ctl_name = 0 }
155 };
156 
157 static ctl_table sunrpc_table[] = {
158 	{
159 		.ctl_name	= CTL_SUNRPC,
160 		.procname	= "sunrpc",
161 		.mode		= 0555,
162 		.child		= debug_table
163 	},
164 	{ .ctl_name = 0 }
165 };
166 
167 #endif
168