Blame view

net/sunrpc/sysctl.c 3.47 KB
457c89965   Thomas Gleixner   treewide: Add SPD...
1
  // SPDX-License-Identifier: GPL-2.0-only
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
4
5
6
7
8
9
  /*
   * linux/net/sunrpc/sysctl.c
   *
   * Sysctl interface to sunrpc module.
   *
   * I would prefer to register the sunrpc table below sys/net, but that's
   * impossible at the moment.
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
10
11
12
13
14
15
  #include <linux/types.h>
  #include <linux/linkage.h>
  #include <linux/ctype.h>
  #include <linux/fs.h>
  #include <linux/sysctl.h>
  #include <linux/module.h>
7c0f6ba68   Linus Torvalds   Replace <asm/uacc...
16
  #include <linux/uaccess.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
17
18
19
  #include <linux/sunrpc/types.h>
  #include <linux/sunrpc/sched.h>
  #include <linux/sunrpc/stats.h>
dc9a16e49   Tom Tucker   svc: Add /proc/sy...
20
  #include <linux/sunrpc/svc_xprt.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21

70abc49b4   Stanislav Kinsbursky   SUNRPC: make SUNP...
22
  #include "netns.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
23
24
25
26
  /*
   * Declare the debug flags here
   */
  unsigned int	rpc_debug;
e8914c65f   Trond Myklebust   SUNRPC: Restrict ...
27
  EXPORT_SYMBOL_GPL(rpc_debug);
a6eaf8bdf   Trond Myklebust   SUNRPC: Move expo...
28

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
29
  unsigned int	nfs_debug;
e8914c65f   Trond Myklebust   SUNRPC: Restrict ...
30
  EXPORT_SYMBOL_GPL(nfs_debug);
a6eaf8bdf   Trond Myklebust   SUNRPC: Move expo...
31

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
32
  unsigned int	nfsd_debug;
e8914c65f   Trond Myklebust   SUNRPC: Restrict ...
33
  EXPORT_SYMBOL_GPL(nfsd_debug);
a6eaf8bdf   Trond Myklebust   SUNRPC: Move expo...
34

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35
  unsigned int	nlm_debug;
e8914c65f   Trond Myklebust   SUNRPC: Restrict ...
36
  EXPORT_SYMBOL_GPL(nlm_debug);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
37

f895b252d   Jeff Layton   sunrpc: eliminate...
38
  #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
39
40
  
  static struct ctl_table_header *sunrpc_table_header;
fe2c6338f   Joe Perches   net: Convert uses...
41
  static struct ctl_table sunrpc_table[];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
43
44
45
  
  void
  rpc_register_sysctl(void)
  {
2b1bec5f5   Eric W. Biederman   [PATCH] sysctl: s...
46
  	if (!sunrpc_table_header)
0b4d41471   Eric W. Biederman   [PATCH] sysctl: r...
47
  		sunrpc_table_header = register_sysctl_table(sunrpc_table);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
48
49
50
51
52
53
54
55
56
57
  }
  
  void
  rpc_unregister_sysctl(void)
  {
  	if (sunrpc_table_header) {
  		unregister_sysctl_table(sunrpc_table_header);
  		sunrpc_table_header = NULL;
  	}
  }
fe2c6338f   Joe Perches   net: Convert uses...
58
  static int proc_do_xprt(struct ctl_table *table, int write,
32927393d   Christoph Hellwig   sysctl: pass kern...
59
  			void *buffer, size_t *lenp, loff_t *ppos)
dc9a16e49   Tom Tucker   svc: Add /proc/sy...
60
61
  {
  	char tmpbuf[256];
ae2975046   Dan Carpenter   net/sunrpc: fix u...
62
  	ssize_t len;
27df6f25f   Cyrill Gorcunov   sunrpc: fix possi...
63

d435c05ab   Dan Carpenter   net/sunrpc: retur...
64
  	if (write || *ppos) {
dc9a16e49   Tom Tucker   svc: Add /proc/sy...
65
66
67
  		*lenp = 0;
  		return 0;
  	}
27df6f25f   Cyrill Gorcunov   sunrpc: fix possi...
68
  	len = svc_print_xprts(tmpbuf, sizeof(tmpbuf));
ae2975046   Dan Carpenter   net/sunrpc: fix u...
69
  	len = memory_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len);
c09f56b8f   Artur Molchanov   net/sunrpc: Fix r...
70

ae2975046   Dan Carpenter   net/sunrpc: fix u...
71
  	if (len < 0) {
c09f56b8f   Artur Molchanov   net/sunrpc: Fix r...
72
73
74
  		*lenp = 0;
  		return -EINVAL;
  	}
ae2975046   Dan Carpenter   net/sunrpc: fix u...
75
  	*lenp = len;
c09f56b8f   Artur Molchanov   net/sunrpc: Fix r...
76
  	return 0;
dc9a16e49   Tom Tucker   svc: Add /proc/sy...
77
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
78
  static int
32927393d   Christoph Hellwig   sysctl: pass kern...
79
80
  proc_dodebug(struct ctl_table *table, int write, void *buffer, size_t *lenp,
  	     loff_t *ppos)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
81
  {
32927393d   Christoph Hellwig   sysctl: pass kern...
82
83
  	char		tmpbuf[20], *s = NULL;
  	char *p;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
84
85
86
87
88
89
90
91
92
93
94
  	unsigned int	value;
  	size_t		left, len;
  
  	if ((*ppos && !write) || !*lenp) {
  		*lenp = 0;
  		return 0;
  	}
  
  	left = *lenp;
  
  	if (write) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
95
  		p = buffer;
32927393d   Christoph Hellwig   sysctl: pass kern...
96
97
98
99
  		while (left && isspace(*p)) {
  			left--;
  			p++;
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
100
101
102
103
104
  		if (!left)
  			goto done;
  
  		if (left > sizeof(tmpbuf) - 1)
  			return -EINVAL;
32927393d   Christoph Hellwig   sysctl: pass kern...
105
  		memcpy(tmpbuf, p, left);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
106
  		tmpbuf[left] = '\0';
941c3ff31   Kinglong Mee   Sunrpc: Supports ...
107
108
109
110
111
  		value = simple_strtol(tmpbuf, &s, 0);
  		if (s) {
  			left -= (s - tmpbuf);
  			if (left && !isspace(*s))
  				return -EINVAL;
ca65a280f   Joe Perches   sunrpc: Avoid com...
112
113
114
115
  			while (left && isspace(*s)) {
  				left--;
  				s++;
  			}
941c3ff31   Kinglong Mee   Sunrpc: Supports ...
116
117
  		} else
  			left = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
118
119
  		*(unsigned int *) table->data = value;
  		/* Display the RPC tasks on writing to rpc_debug */
bc2a3f86f   J. Bruce Fields   sunrpc: fix rpc d...
120
  		if (strcmp(table->procname, "rpc_debug") == 0)
70abc49b4   Stanislav Kinsbursky   SUNRPC: make SUNP...
121
  			rpc_show_tasks(&init_net);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
122
  	} else {
941c3ff31   Kinglong Mee   Sunrpc: Supports ...
123
  		len = sprintf(tmpbuf, "0x%04x", *(unsigned int *) table->data);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
124
125
  		if (len > left)
  			len = left;
32927393d   Christoph Hellwig   sysctl: pass kern...
126
  		memcpy(buffer, tmpbuf, len);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
127
  		if ((left -= len) > 0) {
32927393d   Christoph Hellwig   sysctl: pass kern...
128
129
  			*((char *)buffer + len) = '
  ';
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
130
131
132
133
134
135
136
137
138
  			left--;
  		}
  	}
  
  done:
  	*lenp -= left;
  	*ppos += *lenp;
  	return 0;
  }
a246b0105   Chuck Lever   [PATCH] RPC: intr...
139

fe2c6338f   Joe Perches   net: Convert uses...
140
  static struct ctl_table debug_table[] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
141
  	{
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
142
143
144
145
  		.procname	= "rpc_debug",
  		.data		= &rpc_debug,
  		.maxlen		= sizeof(int),
  		.mode		= 0644,
6d4561110   Eric W. Biederman   sysctl: Drop & in...
146
  		.proc_handler	= proc_dodebug
cca5172a7   YOSHIFUJI Hideaki   [NET] SUNRPC: Fix...
147
  	},
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
148
  	{
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
149
150
151
152
  		.procname	= "nfs_debug",
  		.data		= &nfs_debug,
  		.maxlen		= sizeof(int),
  		.mode		= 0644,
6d4561110   Eric W. Biederman   sysctl: Drop & in...
153
  		.proc_handler	= proc_dodebug
cca5172a7   YOSHIFUJI Hideaki   [NET] SUNRPC: Fix...
154
  	},
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
155
  	{
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
156
157
158
159
  		.procname	= "nfsd_debug",
  		.data		= &nfsd_debug,
  		.maxlen		= sizeof(int),
  		.mode		= 0644,
6d4561110   Eric W. Biederman   sysctl: Drop & in...
160
  		.proc_handler	= proc_dodebug
cca5172a7   YOSHIFUJI Hideaki   [NET] SUNRPC: Fix...
161
  	},
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
162
  	{
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
163
164
165
166
  		.procname	= "nlm_debug",
  		.data		= &nlm_debug,
  		.maxlen		= sizeof(int),
  		.mode		= 0644,
6d4561110   Eric W. Biederman   sysctl: Drop & in...
167
  		.proc_handler	= proc_dodebug
cca5172a7   YOSHIFUJI Hideaki   [NET] SUNRPC: Fix...
168
  	},
dc9a16e49   Tom Tucker   svc: Add /proc/sy...
169
170
171
172
  	{
  		.procname	= "transports",
  		.maxlen		= 256,
  		.mode		= 0444,
6d4561110   Eric W. Biederman   sysctl: Drop & in...
173
  		.proc_handler	= proc_do_xprt,
dc9a16e49   Tom Tucker   svc: Add /proc/sy...
174
  	},
f8572d8f2   Eric W. Biederman   sysctl net: Remov...
175
  	{ }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
176
  };
fe2c6338f   Joe Perches   net: Convert uses...
177
  static struct ctl_table sunrpc_table[] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
178
  	{
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
179
180
181
182
  		.procname	= "sunrpc",
  		.mode		= 0555,
  		.child		= debug_table
  	},
f8572d8f2   Eric W. Biederman   sysctl net: Remov...
183
  	{ }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
184
185
186
  };
  
  #endif