]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
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 | ||
1da177e4 LT |
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 | ||
7c0f6ba6 | 17 | #include <linux/uaccess.h> |
1da177e4 LT |
18 | #include <linux/sunrpc/types.h> |
19 | #include <linux/sunrpc/sched.h> | |
20 | #include <linux/sunrpc/stats.h> | |
dc9a16e4 | 21 | #include <linux/sunrpc/svc_xprt.h> |
1da177e4 | 22 | |
70abc49b SK |
23 | #include "netns.h" |
24 | ||
1da177e4 LT |
25 | /* |
26 | * Declare the debug flags here | |
27 | */ | |
28 | unsigned int rpc_debug; | |
e8914c65 | 29 | EXPORT_SYMBOL_GPL(rpc_debug); |
a6eaf8bd | 30 | |
1da177e4 | 31 | unsigned int nfs_debug; |
e8914c65 | 32 | EXPORT_SYMBOL_GPL(nfs_debug); |
a6eaf8bd | 33 | |
1da177e4 | 34 | unsigned int nfsd_debug; |
e8914c65 | 35 | EXPORT_SYMBOL_GPL(nfsd_debug); |
a6eaf8bd | 36 | |
1da177e4 | 37 | unsigned int nlm_debug; |
e8914c65 | 38 | EXPORT_SYMBOL_GPL(nlm_debug); |
1da177e4 | 39 | |
f895b252 | 40 | #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) |
1da177e4 LT |
41 | |
42 | static struct ctl_table_header *sunrpc_table_header; | |
fe2c6338 | 43 | static struct ctl_table sunrpc_table[]; |
1da177e4 LT |
44 | |
45 | void | |
46 | rpc_register_sysctl(void) | |
47 | { | |
2b1bec5f | 48 | if (!sunrpc_table_header) |
0b4d4147 | 49 | sunrpc_table_header = register_sysctl_table(sunrpc_table); |
1da177e4 LT |
50 | } |
51 | ||
52 | void | |
53 | rpc_unregister_sysctl(void) | |
54 | { | |
55 | if (sunrpc_table_header) { | |
56 | unregister_sysctl_table(sunrpc_table_header); | |
57 | sunrpc_table_header = NULL; | |
58 | } | |
59 | } | |
60 | ||
fe2c6338 | 61 | static int proc_do_xprt(struct ctl_table *table, int write, |
dc9a16e4 TT |
62 | void __user *buffer, size_t *lenp, loff_t *ppos) |
63 | { | |
64 | char tmpbuf[256]; | |
27df6f25 CG |
65 | size_t len; |
66 | ||
dc9a16e4 TT |
67 | if ((*ppos && !write) || !*lenp) { |
68 | *lenp = 0; | |
69 | return 0; | |
70 | } | |
27df6f25 CG |
71 | len = svc_print_xprts(tmpbuf, sizeof(tmpbuf)); |
72 | return simple_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len); | |
dc9a16e4 TT |
73 | } |
74 | ||
1da177e4 | 75 | static int |
fe2c6338 | 76 | proc_dodebug(struct ctl_table *table, int write, |
1da177e4 LT |
77 | void __user *buffer, size_t *lenp, loff_t *ppos) |
78 | { | |
941c3ff3 | 79 | char tmpbuf[20], c, *s = NULL; |
1da177e4 LT |
80 | char __user *p; |
81 | unsigned int value; | |
82 | size_t left, len; | |
83 | ||
84 | if ((*ppos && !write) || !*lenp) { | |
85 | *lenp = 0; | |
86 | return 0; | |
87 | } | |
88 | ||
89 | left = *lenp; | |
90 | ||
91 | if (write) { | |
92 | if (!access_ok(VERIFY_READ, buffer, left)) | |
93 | return -EFAULT; | |
94 | p = buffer; | |
95 | while (left && __get_user(c, p) >= 0 && isspace(c)) | |
96 | left--, p++; | |
97 | if (!left) | |
98 | goto done; | |
99 | ||
100 | if (left > sizeof(tmpbuf) - 1) | |
101 | return -EINVAL; | |
102 | if (copy_from_user(tmpbuf, p, left)) | |
103 | return -EFAULT; | |
104 | tmpbuf[left] = '\0'; | |
105 | ||
941c3ff3 KM |
106 | value = simple_strtol(tmpbuf, &s, 0); |
107 | if (s) { | |
108 | left -= (s - tmpbuf); | |
109 | if (left && !isspace(*s)) | |
110 | return -EINVAL; | |
111 | while (left && isspace(*s)) | |
112 | left--, s++; | |
113 | } else | |
114 | left = 0; | |
1da177e4 LT |
115 | *(unsigned int *) table->data = value; |
116 | /* Display the RPC tasks on writing to rpc_debug */ | |
bc2a3f86 | 117 | if (strcmp(table->procname, "rpc_debug") == 0) |
70abc49b | 118 | rpc_show_tasks(&init_net); |
1da177e4 | 119 | } else { |
941c3ff3 | 120 | len = sprintf(tmpbuf, "0x%04x", *(unsigned int *) table->data); |
1da177e4 LT |
121 | if (len > left) |
122 | len = left; | |
941c3ff3 | 123 | if (copy_to_user(buffer, tmpbuf, len)) |
1da177e4 LT |
124 | return -EFAULT; |
125 | if ((left -= len) > 0) { | |
126 | if (put_user('\n', (char __user *)buffer + len)) | |
127 | return -EFAULT; | |
128 | left--; | |
129 | } | |
130 | } | |
131 | ||
132 | done: | |
133 | *lenp -= left; | |
134 | *ppos += *lenp; | |
135 | return 0; | |
136 | } | |
137 | ||
a246b010 | 138 | |
fe2c6338 | 139 | static struct ctl_table debug_table[] = { |
1da177e4 | 140 | { |
1da177e4 LT |
141 | .procname = "rpc_debug", |
142 | .data = &rpc_debug, | |
143 | .maxlen = sizeof(int), | |
144 | .mode = 0644, | |
6d456111 | 145 | .proc_handler = proc_dodebug |
cca5172a | 146 | }, |
1da177e4 | 147 | { |
1da177e4 LT |
148 | .procname = "nfs_debug", |
149 | .data = &nfs_debug, | |
150 | .maxlen = sizeof(int), | |
151 | .mode = 0644, | |
6d456111 | 152 | .proc_handler = proc_dodebug |
cca5172a | 153 | }, |
1da177e4 | 154 | { |
1da177e4 LT |
155 | .procname = "nfsd_debug", |
156 | .data = &nfsd_debug, | |
157 | .maxlen = sizeof(int), | |
158 | .mode = 0644, | |
6d456111 | 159 | .proc_handler = proc_dodebug |
cca5172a | 160 | }, |
1da177e4 | 161 | { |
1da177e4 LT |
162 | .procname = "nlm_debug", |
163 | .data = &nlm_debug, | |
164 | .maxlen = sizeof(int), | |
165 | .mode = 0644, | |
6d456111 | 166 | .proc_handler = proc_dodebug |
cca5172a | 167 | }, |
dc9a16e4 TT |
168 | { |
169 | .procname = "transports", | |
170 | .maxlen = 256, | |
171 | .mode = 0444, | |
6d456111 | 172 | .proc_handler = proc_do_xprt, |
dc9a16e4 | 173 | }, |
f8572d8f | 174 | { } |
1da177e4 LT |
175 | }; |
176 | ||
fe2c6338 | 177 | static struct ctl_table sunrpc_table[] = { |
1da177e4 | 178 | { |
1da177e4 LT |
179 | .procname = "sunrpc", |
180 | .mode = 0555, | |
181 | .child = debug_table | |
182 | }, | |
f8572d8f | 183 | { } |
1da177e4 LT |
184 | }; |
185 | ||
186 | #endif |