blob: d75f17b56f0e17ee52b5703429ef5e1366da6475 [file] [log] [blame]
Thomas Gleixner457c8992019-05-19 13:08:55 +01001// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * linux/net/sunrpc/sysctl.c
4 *
5 * Sysctl interface to sunrpc module.
6 *
7 * I would prefer to register the sunrpc table below sys/net, but that's
8 * impossible at the moment.
9 */
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#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
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080018#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/sunrpc/types.h>
20#include <linux/sunrpc/sched.h>
21#include <linux/sunrpc/stats.h>
Tom Tuckerdc9a16e2007-12-30 21:08:31 -060022#include <linux/sunrpc/svc_xprt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Stanislav Kinsbursky70abc492012-01-12 22:07:51 +040024#include "netns.h"
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026/*
27 * Declare the debug flags here
28 */
29unsigned int rpc_debug;
Trond Myklebuste8914c62007-07-14 15:39:59 -040030EXPORT_SYMBOL_GPL(rpc_debug);
Trond Myklebusta6eaf8b2007-07-14 15:39:58 -040031
Linus Torvalds1da177e2005-04-16 15:20:36 -070032unsigned int nfs_debug;
Trond Myklebuste8914c62007-07-14 15:39:59 -040033EXPORT_SYMBOL_GPL(nfs_debug);
Trond Myklebusta6eaf8b2007-07-14 15:39:58 -040034
Linus Torvalds1da177e2005-04-16 15:20:36 -070035unsigned int nfsd_debug;
Trond Myklebuste8914c62007-07-14 15:39:59 -040036EXPORT_SYMBOL_GPL(nfsd_debug);
Trond Myklebusta6eaf8b2007-07-14 15:39:58 -040037
Linus Torvalds1da177e2005-04-16 15:20:36 -070038unsigned int nlm_debug;
Trond Myklebuste8914c62007-07-14 15:39:59 -040039EXPORT_SYMBOL_GPL(nlm_debug);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Jeff Laytonf895b252014-11-17 16:58:04 -050041#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43static struct ctl_table_header *sunrpc_table_header;
Joe Perchesfe2c6332013-06-11 23:04:25 -070044static struct ctl_table sunrpc_table[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46void
47rpc_register_sysctl(void)
48{
Eric W. Biederman2b1bec52007-02-14 00:33:24 -080049 if (!sunrpc_table_header)
Eric W. Biederman0b4d4142007-02-14 00:34:09 -080050 sunrpc_table_header = register_sysctl_table(sunrpc_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051}
52
53void
54rpc_unregister_sysctl(void)
55{
56 if (sunrpc_table_header) {
57 unregister_sysctl_table(sunrpc_table_header);
58 sunrpc_table_header = NULL;
59 }
60}
61
Joe Perchesfe2c6332013-06-11 23:04:25 -070062static int proc_do_xprt(struct ctl_table *table, int write,
Tom Tuckerdc9a16e2007-12-30 21:08:31 -060063 void __user *buffer, size_t *lenp, loff_t *ppos)
64{
65 char tmpbuf[256];
Cyrill Gorcunov27df6f22008-08-31 19:25:49 +040066 size_t len;
67
Tom Tuckerdc9a16e2007-12-30 21:08:31 -060068 if ((*ppos && !write) || !*lenp) {
69 *lenp = 0;
70 return 0;
71 }
Cyrill Gorcunov27df6f22008-08-31 19:25:49 +040072 len = svc_print_xprts(tmpbuf, sizeof(tmpbuf));
73 return simple_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len);
Tom Tuckerdc9a16e2007-12-30 21:08:31 -060074}
75
Linus Torvalds1da177e2005-04-16 15:20:36 -070076static int
Joe Perchesfe2c6332013-06-11 23:04:25 -070077proc_dodebug(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 void __user *buffer, size_t *lenp, loff_t *ppos)
79{
Kinglong Mee941c3ff2015-09-12 09:37:18 +080080 char tmpbuf[20], c, *s = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 char __user *p;
82 unsigned int value;
83 size_t left, len;
84
85 if ((*ppos && !write) || !*lenp) {
86 *lenp = 0;
87 return 0;
88 }
89
90 left = *lenp;
91
92 if (write) {
Linus Torvalds96d4f262019-01-03 18:57:57 -080093 if (!access_ok(buffer, left))
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 return -EFAULT;
95 p = buffer;
96 while (left && __get_user(c, p) >= 0 && isspace(c))
97 left--, p++;
98 if (!left)
99 goto done;
100
101 if (left > sizeof(tmpbuf) - 1)
102 return -EINVAL;
103 if (copy_from_user(tmpbuf, p, left))
104 return -EFAULT;
105 tmpbuf[left] = '\0';
106
Kinglong Mee941c3ff2015-09-12 09:37:18 +0800107 value = simple_strtol(tmpbuf, &s, 0);
108 if (s) {
109 left -= (s - tmpbuf);
110 if (left && !isspace(*s))
111 return -EINVAL;
112 while (left && isspace(*s))
113 left--, s++;
114 } else
115 left = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 *(unsigned int *) table->data = value;
117 /* Display the RPC tasks on writing to rpc_debug */
J. Bruce Fieldsbc2a3f82007-10-29 14:37:18 -0700118 if (strcmp(table->procname, "rpc_debug") == 0)
Stanislav Kinsbursky70abc492012-01-12 22:07:51 +0400119 rpc_show_tasks(&init_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 } else {
Kinglong Mee941c3ff2015-09-12 09:37:18 +0800121 len = sprintf(tmpbuf, "0x%04x", *(unsigned int *) table->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 if (len > left)
123 len = left;
Kinglong Mee941c3ff2015-09-12 09:37:18 +0800124 if (copy_to_user(buffer, tmpbuf, len))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 return -EFAULT;
126 if ((left -= len) > 0) {
127 if (put_user('\n', (char __user *)buffer + len))
128 return -EFAULT;
129 left--;
130 }
131 }
132
133done:
134 *lenp -= left;
135 *ppos += *lenp;
136 return 0;
137}
138
Chuck Levera246b012005-08-11 16:25:23 -0400139
Joe Perchesfe2c6332013-06-11 23:04:25 -0700140static struct ctl_table debug_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 .procname = "rpc_debug",
143 .data = &rpc_debug,
144 .maxlen = sizeof(int),
145 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800146 .proc_handler = proc_dodebug
YOSHIFUJI Hideakicca51722007-02-09 15:38:13 -0800147 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 .procname = "nfs_debug",
150 .data = &nfs_debug,
151 .maxlen = sizeof(int),
152 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800153 .proc_handler = proc_dodebug
YOSHIFUJI Hideakicca51722007-02-09 15:38:13 -0800154 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 .procname = "nfsd_debug",
157 .data = &nfsd_debug,
158 .maxlen = sizeof(int),
159 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800160 .proc_handler = proc_dodebug
YOSHIFUJI Hideakicca51722007-02-09 15:38:13 -0800161 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 .procname = "nlm_debug",
164 .data = &nlm_debug,
165 .maxlen = sizeof(int),
166 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800167 .proc_handler = proc_dodebug
YOSHIFUJI Hideakicca51722007-02-09 15:38:13 -0800168 },
Tom Tuckerdc9a16e2007-12-30 21:08:31 -0600169 {
170 .procname = "transports",
171 .maxlen = 256,
172 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800173 .proc_handler = proc_do_xprt,
Tom Tuckerdc9a16e2007-12-30 21:08:31 -0600174 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800175 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176};
177
Joe Perchesfe2c6332013-06-11 23:04:25 -0700178static struct ctl_table sunrpc_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 .procname = "sunrpc",
181 .mode = 0555,
182 .child = debug_table
183 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800184 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185};
186
187#endif