Blame view

net/sunrpc/sysctl.c 3.55 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
  #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...
15
  #include <linux/uaccess.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
16
17
18
  #include <linux/sunrpc/types.h>
  #include <linux/sunrpc/sched.h>
  #include <linux/sunrpc/stats.h>
dc9a16e49   Tom Tucker   svc: Add /proc/sy...
19
  #include <linux/sunrpc/svc_xprt.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
20

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

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

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

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

f895b252d   Jeff Layton   sunrpc: eliminate...
37
  #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
38
39
  
  static struct ctl_table_header *sunrpc_table_header;
fe2c6338f   Joe Perches   net: Convert uses...
40
  static struct ctl_table sunrpc_table[];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
41
42
43
44
  
  void
  rpc_register_sysctl(void)
  {
2b1bec5f5   Eric W. Biederman   [PATCH] sysctl: s...
45
  	if (!sunrpc_table_header)
0b4d41471   Eric W. Biederman   [PATCH] sysctl: r...
46
  		sunrpc_table_header = register_sysctl_table(sunrpc_table);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
47
48
49
50
51
52
53
54
55
56
  }
  
  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...
57
  static int proc_do_xprt(struct ctl_table *table, int write,
dc9a16e49   Tom Tucker   svc: Add /proc/sy...
58
59
60
  			void __user *buffer, size_t *lenp, loff_t *ppos)
  {
  	char tmpbuf[256];
27df6f25f   Cyrill Gorcunov   sunrpc: fix possi...
61
  	size_t len;
dc9a16e49   Tom Tucker   svc: Add /proc/sy...
62
63
64
65
  	if ((*ppos && !write) || !*lenp) {
  		*lenp = 0;
  		return 0;
  	}
27df6f25f   Cyrill Gorcunov   sunrpc: fix possi...
66
67
  	len = svc_print_xprts(tmpbuf, sizeof(tmpbuf));
  	return simple_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len);
dc9a16e49   Tom Tucker   svc: Add /proc/sy...
68
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
69
  static int
fe2c6338f   Joe Perches   net: Convert uses...
70
  proc_dodebug(struct ctl_table *table, int write,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
71
72
  				void __user *buffer, size_t *lenp, loff_t *ppos)
  {
941c3ff31   Kinglong Mee   Sunrpc: Supports ...
73
  	char		tmpbuf[20], c, *s = NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
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
  	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';
941c3ff31   Kinglong Mee   Sunrpc: Supports ...
99
100
101
102
103
104
105
106
107
  		value = simple_strtol(tmpbuf, &s, 0);
  		if (s) {
  			left -= (s - tmpbuf);
  			if (left && !isspace(*s))
  				return -EINVAL;
  			while (left && isspace(*s))
  				left--, s++;
  		} else
  			left = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
108
109
  		*(unsigned int *) table->data = value;
  		/* Display the RPC tasks on writing to rpc_debug */
bc2a3f86f   J. Bruce Fields   sunrpc: fix rpc d...
110
  		if (strcmp(table->procname, "rpc_debug") == 0)
70abc49b4   Stanislav Kinsbursky   SUNRPC: make SUNP...
111
  			rpc_show_tasks(&init_net);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
112
  	} else {
941c3ff31   Kinglong Mee   Sunrpc: Supports ...
113
  		len = sprintf(tmpbuf, "0x%04x", *(unsigned int *) table->data);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
114
115
  		if (len > left)
  			len = left;
941c3ff31   Kinglong Mee   Sunrpc: Supports ...
116
  		if (copy_to_user(buffer, tmpbuf, len))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
117
118
119
120
121
122
123
124
125
126
127
128
129
130
  			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...
131

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