blob: 3aad6ef1850452adb533c8bb1691f38224ea0428 [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,
Christoph Hellwig32927392020-04-24 08:43:38 +020063 void *buffer, size_t *lenp, loff_t *ppos)
Tom Tuckerdc9a16e2007-12-30 21:08:31 -060064{
65 char tmpbuf[256];
Dan Carpenterae297502020-11-06 15:50:39 -050066 ssize_t len;
Cyrill Gorcunov27df6f22008-08-31 19:25:49 +040067
Dan Carpenterd435c052020-11-06 15:39:50 -050068 if (write || *ppos) {
Tom Tuckerdc9a16e2007-12-30 21:08:31 -060069 *lenp = 0;
70 return 0;
71 }
Cyrill Gorcunov27df6f22008-08-31 19:25:49 +040072 len = svc_print_xprts(tmpbuf, sizeof(tmpbuf));
Dan Carpenterae297502020-11-06 15:50:39 -050073 len = memory_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len);
Artur Molchanovc09f56b2020-10-12 01:00:45 +030074
Dan Carpenterae297502020-11-06 15:50:39 -050075 if (len < 0) {
Artur Molchanovc09f56b2020-10-12 01:00:45 +030076 *lenp = 0;
77 return -EINVAL;
78 }
Dan Carpenterae297502020-11-06 15:50:39 -050079 *lenp = len;
Artur Molchanovc09f56b2020-10-12 01:00:45 +030080 return 0;
Tom Tuckerdc9a16e2007-12-30 21:08:31 -060081}
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083static int
Christoph Hellwig32927392020-04-24 08:43:38 +020084proc_dodebug(struct ctl_table *table, int write, void *buffer, size_t *lenp,
85 loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
Christoph Hellwig32927392020-04-24 08:43:38 +020087 char tmpbuf[20], *s = NULL;
88 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 unsigned int value;
90 size_t left, len;
91
92 if ((*ppos && !write) || !*lenp) {
93 *lenp = 0;
94 return 0;
95 }
96
97 left = *lenp;
98
99 if (write) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 p = buffer;
Christoph Hellwig32927392020-04-24 08:43:38 +0200101 while (left && isspace(*p)) {
102 left--;
103 p++;
104 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 if (!left)
106 goto done;
107
108 if (left > sizeof(tmpbuf) - 1)
109 return -EINVAL;
Christoph Hellwig32927392020-04-24 08:43:38 +0200110 memcpy(tmpbuf, p, left);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 tmpbuf[left] = '\0';
112
Kinglong Mee941c3ff2015-09-12 09:37:18 +0800113 value = simple_strtol(tmpbuf, &s, 0);
114 if (s) {
115 left -= (s - tmpbuf);
116 if (left && !isspace(*s))
117 return -EINVAL;
Joe Perchesca65a282020-08-24 21:56:25 -0700118 while (left && isspace(*s)) {
119 left--;
120 s++;
121 }
Kinglong Mee941c3ff2015-09-12 09:37:18 +0800122 } else
123 left = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 *(unsigned int *) table->data = value;
125 /* Display the RPC tasks on writing to rpc_debug */
J. Bruce Fieldsbc2a3f82007-10-29 14:37:18 -0700126 if (strcmp(table->procname, "rpc_debug") == 0)
Stanislav Kinsbursky70abc492012-01-12 22:07:51 +0400127 rpc_show_tasks(&init_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 } else {
Kinglong Mee941c3ff2015-09-12 09:37:18 +0800129 len = sprintf(tmpbuf, "0x%04x", *(unsigned int *) table->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 if (len > left)
131 len = left;
Christoph Hellwig32927392020-04-24 08:43:38 +0200132 memcpy(buffer, tmpbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 if ((left -= len) > 0) {
Christoph Hellwig32927392020-04-24 08:43:38 +0200134 *((char *)buffer + len) = '\n';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 left--;
136 }
137 }
138
139done:
140 *lenp -= left;
141 *ppos += *lenp;
142 return 0;
143}
144
Chuck Levera246b012005-08-11 16:25:23 -0400145
Joe Perchesfe2c6332013-06-11 23:04:25 -0700146static struct ctl_table debug_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 .procname = "rpc_debug",
149 .data = &rpc_debug,
150 .maxlen = sizeof(int),
151 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800152 .proc_handler = proc_dodebug
YOSHIFUJI Hideakicca51722007-02-09 15:38:13 -0800153 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 .procname = "nfs_debug",
156 .data = &nfs_debug,
157 .maxlen = sizeof(int),
158 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800159 .proc_handler = proc_dodebug
YOSHIFUJI Hideakicca51722007-02-09 15:38:13 -0800160 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 .procname = "nfsd_debug",
163 .data = &nfsd_debug,
164 .maxlen = sizeof(int),
165 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800166 .proc_handler = proc_dodebug
YOSHIFUJI Hideakicca51722007-02-09 15:38:13 -0800167 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 .procname = "nlm_debug",
170 .data = &nlm_debug,
171 .maxlen = sizeof(int),
172 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800173 .proc_handler = proc_dodebug
YOSHIFUJI Hideakicca51722007-02-09 15:38:13 -0800174 },
Tom Tuckerdc9a16e2007-12-30 21:08:31 -0600175 {
176 .procname = "transports",
177 .maxlen = 256,
178 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800179 .proc_handler = proc_do_xprt,
Tom Tuckerdc9a16e2007-12-30 21:08:31 -0600180 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800181 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182};
183
Joe Perchesfe2c6332013-06-11 23:04:25 -0700184static struct ctl_table sunrpc_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 .procname = "sunrpc",
187 .mode = 0555,
188 .child = debug_table
189 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800190 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191};
192
193#endif