Blame view

net/sunrpc/sysctl.c 3.6 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
  /*
   * 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
9
10
11
12
13
14
15
16
17
18
19
  #include <linux/types.h>
  #include <linux/linkage.h>
  #include <linux/ctype.h>
  #include <linux/fs.h>
  #include <linux/sysctl.h>
  #include <linux/module.h>
  
  #include <asm/uaccess.h>
  #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,
dc9a16e49   Tom Tucker   svc: Add /proc/sy...
59
60
61
  			void __user *buffer, size_t *lenp, loff_t *ppos)
  {
  	char tmpbuf[256];
27df6f25f   Cyrill Gorcunov   sunrpc: fix possi...
62
  	size_t len;
dc9a16e49   Tom Tucker   svc: Add /proc/sy...
63
64
65
66
  	if ((*ppos && !write) || !*lenp) {
  		*lenp = 0;
  		return 0;
  	}
27df6f25f   Cyrill Gorcunov   sunrpc: fix possi...
67
68
  	len = svc_print_xprts(tmpbuf, sizeof(tmpbuf));
  	return simple_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len);
dc9a16e49   Tom Tucker   svc: Add /proc/sy...
69
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
70
  static int
fe2c6338f   Joe Perches   net: Convert uses...
71
  proc_dodebug(struct ctl_table *table, int write,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
  				void __user *buffer, size_t *lenp, loff_t *ppos)
  {
  	char		tmpbuf[20], c, *s;
  	char __user *p;
  	unsigned int	value;
  	size_t		left, len;
  
  	if ((*ppos && !write) || !*lenp) {
  		*lenp = 0;
  		return 0;
  	}
  
  	left = *lenp;
  
  	if (write) {
  		if (!access_ok(VERIFY_READ, buffer, left))
  			return -EFAULT;
  		p = buffer;
  		while (left && __get_user(c, p) >= 0 && isspace(c))
  			left--, p++;
  		if (!left)
  			goto done;
  
  		if (left > sizeof(tmpbuf) - 1)
  			return -EINVAL;
  		if (copy_from_user(tmpbuf, p, left))
  			return -EFAULT;
  		tmpbuf[left] = '\0';
  
  		for (s = tmpbuf, value = 0; '0' <= *s && *s <= '9'; s++, left--)
  			value = 10 * value + (*s - '0');
  		if (*s && !isspace(*s))
  			return -EINVAL;
  		while (left && isspace(*s))
  			left--, s++;
  		*(unsigned int *) table->data = value;
  		/* Display the RPC tasks on writing to rpc_debug */
bc2a3f86f   J. Bruce Fields   sunrpc: fix rpc d...
109
  		if (strcmp(table->procname, "rpc_debug") == 0)
70abc49b4   Stanislav Kinsbursky   SUNRPC: make SUNP...
110
  			rpc_show_tasks(&init_net);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
  	} else {
  		if (!access_ok(VERIFY_WRITE, buffer, left))
  			return -EFAULT;
  		len = sprintf(tmpbuf, "%d", *(unsigned int *) table->data);
  		if (len > left)
  			len = left;
  		if (__copy_to_user(buffer, tmpbuf, len))
  			return -EFAULT;
  		if ((left -= len) > 0) {
  			if (put_user('
  ', (char __user *)buffer + len))
  				return -EFAULT;
  			left--;
  		}
  	}
  
  done:
  	*lenp -= left;
  	*ppos += *lenp;
  	return 0;
  }
a246b0105   Chuck Lever   [PATCH] RPC: intr...
132

fe2c6338f   Joe Perches   net: Convert uses...
133
  static struct ctl_table debug_table[] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
134
  	{
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
135
136
137
138
  		.procname	= "rpc_debug",
  		.data		= &rpc_debug,
  		.maxlen		= sizeof(int),
  		.mode		= 0644,
6d4561110   Eric W. Biederman   sysctl: Drop & in...
139
  		.proc_handler	= proc_dodebug
cca5172a7   YOSHIFUJI Hideaki   [NET] SUNRPC: Fix...
140
  	},
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
141
  	{
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
142
143
144
145
  		.procname	= "nfs_debug",
  		.data		= &nfs_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	= "nfsd_debug",
  		.data		= &nfsd_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	= "nlm_debug",
  		.data		= &nlm_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
  	},
dc9a16e49   Tom Tucker   svc: Add /proc/sy...
162
163
164
165
  	{
  		.procname	= "transports",
  		.maxlen		= 256,
  		.mode		= 0444,
6d4561110   Eric W. Biederman   sysctl: Drop & in...
166
  		.proc_handler	= proc_do_xprt,
dc9a16e49   Tom Tucker   svc: Add /proc/sy...
167
  	},
f8572d8f2   Eric W. Biederman   sysctl net: Remov...
168
  	{ }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
169
  };
fe2c6338f   Joe Perches   net: Convert uses...
170
  static struct ctl_table sunrpc_table[] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
171
  	{
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
172
173
174
175
  		.procname	= "sunrpc",
  		.mode		= 0555,
  		.child		= debug_table
  	},
f8572d8f2   Eric W. Biederman   sysctl net: Remov...
176
  	{ }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
177
178
179
  };
  
  #endif