aboutsummaryrefslogtreecommitdiffstats
path: root/net/sunrpc
diff options
context:
space:
mode:
authorTrond Myklebust <Trond.Myklebust@netapp.com>2009-09-11 14:59:37 -0400
committerTrond Myklebust <Trond.Myklebust@netapp.com>2009-09-11 14:59:37 -0400
commitab3bbaa8b257845e248e9a01d12a69ca245f4197 (patch)
treef3054be9bd612194826ed6969d01346d329c3306 /net/sunrpc
parent332a3392188e0ad966543c87b8da2b9d246f301d (diff)
parent2ecda72b49a0849ce41e7fa1fa974a245b9119f8 (diff)
Merge branch 'nfs-for-2.6.32'
Diffstat (limited to 'net/sunrpc')
-rw-r--r--net/sunrpc/Makefile2
-rw-r--r--net/sunrpc/addr.c364
-rw-r--r--net/sunrpc/auth_gss/auth_gss.c12
-rw-r--r--net/sunrpc/auth_gss/svcauth_gss.c7
-rw-r--r--net/sunrpc/cache.c622
-rw-r--r--net/sunrpc/clnt.c60
-rw-r--r--net/sunrpc/rpc_pipe.c685
-rw-r--r--net/sunrpc/rpcb_clnt.c420
-rw-r--r--net/sunrpc/sunrpc_syms.c2
-rw-r--r--net/sunrpc/svcauth_unix.c14
-rw-r--r--net/sunrpc/timer.c45
-rw-r--r--net/sunrpc/xdr.c12
-rw-r--r--net/sunrpc/xprtrdma/transport.c48
-rw-r--r--net/sunrpc/xprtsock.c287
14 files changed, 1780 insertions, 800 deletions
diff --git a/net/sunrpc/Makefile b/net/sunrpc/Makefile
index db73fd2a3f0e..9d2fca5ad14a 100644
--- a/net/sunrpc/Makefile
+++ b/net/sunrpc/Makefile
@@ -10,7 +10,7 @@ obj-$(CONFIG_SUNRPC_XPRT_RDMA) += xprtrdma/
10sunrpc-y := clnt.o xprt.o socklib.o xprtsock.o sched.o \ 10sunrpc-y := clnt.o xprt.o socklib.o xprtsock.o sched.o \
11 auth.o auth_null.o auth_unix.o auth_generic.o \ 11 auth.o auth_null.o auth_unix.o auth_generic.o \
12 svc.o svcsock.o svcauth.o svcauth_unix.o \ 12 svc.o svcsock.o svcauth.o svcauth_unix.o \
13 rpcb_clnt.o timer.o xdr.o \ 13 addr.o rpcb_clnt.o timer.o xdr.o \
14 sunrpc_syms.o cache.o rpc_pipe.o \ 14 sunrpc_syms.o cache.o rpc_pipe.o \
15 svc_xprt.o 15 svc_xprt.o
16sunrpc-$(CONFIG_NFS_V4_1) += backchannel_rqst.o bc_svc.o 16sunrpc-$(CONFIG_NFS_V4_1) += backchannel_rqst.o bc_svc.o
diff --git a/net/sunrpc/addr.c b/net/sunrpc/addr.c
new file mode 100644
index 000000000000..22e8fd89477f
--- /dev/null
+++ b/net/sunrpc/addr.c
@@ -0,0 +1,364 @@
1/*
2 * Copyright 2009, Oracle. All rights reserved.
3 *
4 * Convert socket addresses to presentation addresses and universal
5 * addresses, and vice versa.
6 *
7 * Universal addresses are introduced by RFC 1833 and further refined by
8 * recent RFCs describing NFSv4. The universal address format is part
9 * of the external (network) interface provided by rpcbind version 3
10 * and 4, and by NFSv4. Such an address is a string containing a
11 * presentation format IP address followed by a port number in
12 * "hibyte.lobyte" format.
13 *
14 * IPv6 addresses can also include a scope ID, typically denoted by
15 * a '%' followed by a device name or a non-negative integer. Refer to
16 * RFC 4291, Section 2.2 for details on IPv6 presentation formats.
17 */
18
19#include <net/ipv6.h>
20#include <linux/sunrpc/clnt.h>
21
22#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
23
24static size_t rpc_ntop6_noscopeid(const struct sockaddr *sap,
25 char *buf, const int buflen)
26{
27 const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
28 const struct in6_addr *addr = &sin6->sin6_addr;
29
30 /*
31 * RFC 4291, Section 2.2.2
32 *
33 * Shorthanded ANY address
34 */
35 if (ipv6_addr_any(addr))
36 return snprintf(buf, buflen, "::");
37
38 /*
39 * RFC 4291, Section 2.2.2
40 *
41 * Shorthanded loopback address
42 */
43 if (ipv6_addr_loopback(addr))
44 return snprintf(buf, buflen, "::1");
45
46 /*
47 * RFC 4291, Section 2.2.3
48 *
49 * Special presentation address format for mapped v4
50 * addresses.
51 */
52 if (ipv6_addr_v4mapped(addr))
53 return snprintf(buf, buflen, "::ffff:%pI4",
54 &addr->s6_addr32[3]);
55
56 /*
57 * RFC 4291, Section 2.2.1
58 *
59 * To keep the result as short as possible, especially
60 * since we don't shorthand, we don't want leading zeros
61 * in each halfword, so avoid %pI6.
62 */
63 return snprintf(buf, buflen, "%x:%x:%x:%x:%x:%x:%x:%x",
64 ntohs(addr->s6_addr16[0]), ntohs(addr->s6_addr16[1]),
65 ntohs(addr->s6_addr16[2]), ntohs(addr->s6_addr16[3]),
66 ntohs(addr->s6_addr16[4]), ntohs(addr->s6_addr16[5]),
67 ntohs(addr->s6_addr16[6]), ntohs(addr->s6_addr16[7]));
68}
69
70static size_t rpc_ntop6(const struct sockaddr *sap,
71 char *buf, const size_t buflen)
72{
73 const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
74 char scopebuf[IPV6_SCOPE_ID_LEN];
75 size_t len;
76 int rc;
77
78 len = rpc_ntop6_noscopeid(sap, buf, buflen);
79 if (unlikely(len == 0))
80 return len;
81
82 if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL) &&
83 !(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_SITELOCAL))
84 return len;
85
86 rc = snprintf(scopebuf, sizeof(scopebuf), "%c%u",
87 IPV6_SCOPE_DELIMITER, sin6->sin6_scope_id);
88 if (unlikely((size_t)rc > sizeof(scopebuf)))
89 return 0;
90
91 len += rc;
92 if (unlikely(len > buflen))
93 return 0;
94
95 strcat(buf, scopebuf);
96 return len;
97}
98
99#else /* !(defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)) */
100
101static size_t rpc_ntop6_noscopeid(const struct sockaddr *sap,
102 char *buf, const int buflen)
103{
104 return 0;
105}
106
107static size_t rpc_ntop6(const struct sockaddr *sap,
108 char *buf, const size_t buflen)
109{
110 return 0;
111}
112
113#endif /* !(defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)) */
114
115static int rpc_ntop4(const struct sockaddr *sap,
116 char *buf, const size_t buflen)
117{
118 const struct sockaddr_in *sin = (struct sockaddr_in *)sap;
119
120 return snprintf(buf, buflen, "%pI4", &sin->sin_addr);
121}
122
123/**
124 * rpc_ntop - construct a presentation address in @buf
125 * @sap: socket address
126 * @buf: construction area
127 * @buflen: size of @buf, in bytes
128 *
129 * Plants a %NUL-terminated string in @buf and returns the length
130 * of the string, excluding the %NUL. Otherwise zero is returned.
131 */
132size_t rpc_ntop(const struct sockaddr *sap, char *buf, const size_t buflen)
133{
134 switch (sap->sa_family) {
135 case AF_INET:
136 return rpc_ntop4(sap, buf, buflen);
137 case AF_INET6:
138 return rpc_ntop6(sap, buf, buflen);
139 }
140
141 return 0;
142}
143EXPORT_SYMBOL_GPL(rpc_ntop);
144
145static size_t rpc_pton4(const char *buf, const size_t buflen,
146 struct sockaddr *sap, const size_t salen)
147{
148 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
149 u8 *addr = (u8 *)&sin->sin_addr.s_addr;
150
151 if (buflen > INET_ADDRSTRLEN || salen < sizeof(struct sockaddr_in))
152 return 0;
153
154 memset(sap, 0, sizeof(struct sockaddr_in));
155
156 if (in4_pton(buf, buflen, addr, '\0', NULL) == 0)
157 return 0;
158
159 sin->sin_family = AF_INET;
160 return sizeof(struct sockaddr_in);;
161}
162
163#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
164static int rpc_parse_scope_id(const char *buf, const size_t buflen,
165 const char *delim, struct sockaddr_in6 *sin6)
166{
167 char *p;
168 size_t len;
169
170 if ((buf + buflen) == delim)
171 return 1;
172
173 if (*delim != IPV6_SCOPE_DELIMITER)
174 return 0;
175
176 if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL) &&
177 !(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_SITELOCAL))
178 return 0;
179
180 len = (buf + buflen) - delim - 1;
181 p = kstrndup(delim + 1, len, GFP_KERNEL);
182 if (p) {
183 unsigned long scope_id = 0;
184 struct net_device *dev;
185
186 dev = dev_get_by_name(&init_net, p);
187 if (dev != NULL) {
188 scope_id = dev->ifindex;
189 dev_put(dev);
190 } else {
191 if (strict_strtoul(p, 10, &scope_id) == 0) {
192 kfree(p);
193 return 0;
194 }
195 }
196
197 kfree(p);
198
199 sin6->sin6_scope_id = scope_id;
200 return 1;
201 }
202
203 return 0;
204}
205
206static size_t rpc_pton6(const char *buf, const size_t buflen,
207 struct sockaddr *sap, const size_t salen)
208{
209 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
210 u8 *addr = (u8 *)&sin6->sin6_addr.in6_u;
211 const char *delim;
212
213 if (buflen > (INET6_ADDRSTRLEN + IPV6_SCOPE_ID_LEN) ||
214 salen < sizeof(struct sockaddr_in6))
215 return 0;
216
217 memset(sap, 0, sizeof(struct sockaddr_in6));
218
219 if (in6_pton(buf, buflen, addr, IPV6_SCOPE_DELIMITER, &delim) == 0)
220 return 0;
221
222 if (!rpc_parse_scope_id(buf, buflen, delim, sin6))
223 return 0;
224
225 sin6->sin6_family = AF_INET6;
226 return sizeof(struct sockaddr_in6);
227}
228#else
229static size_t rpc_pton6(const char *buf, const size_t buflen,
230 struct sockaddr *sap, const size_t salen)
231{
232 return 0;
233}
234#endif
235
236/**
237 * rpc_pton - Construct a sockaddr in @sap
238 * @buf: C string containing presentation format IP address
239 * @buflen: length of presentation address in bytes
240 * @sap: buffer into which to plant socket address
241 * @salen: size of buffer in bytes
242 *
243 * Returns the size of the socket address if successful; otherwise
244 * zero is returned.
245 *
246 * Plants a socket address in @sap and returns the size of the
247 * socket address, if successful. Returns zero if an error
248 * occurred.
249 */
250size_t rpc_pton(const char *buf, const size_t buflen,
251 struct sockaddr *sap, const size_t salen)
252{
253 unsigned int i;
254
255 for (i = 0; i < buflen; i++)
256 if (buf[i] == ':')
257 return rpc_pton6(buf, buflen, sap, salen);
258 return rpc_pton4(buf, buflen, sap, salen);
259}
260EXPORT_SYMBOL_GPL(rpc_pton);
261
262/**
263 * rpc_sockaddr2uaddr - Construct a universal address string from @sap.
264 * @sap: socket address
265 *
266 * Returns a %NUL-terminated string in dynamically allocated memory;
267 * otherwise NULL is returned if an error occurred. Caller must
268 * free the returned string.
269 */
270char *rpc_sockaddr2uaddr(const struct sockaddr *sap)
271{
272 char portbuf[RPCBIND_MAXUADDRPLEN];
273 char addrbuf[RPCBIND_MAXUADDRLEN];
274 unsigned short port;
275
276 switch (sap->sa_family) {
277 case AF_INET:
278 if (rpc_ntop4(sap, addrbuf, sizeof(addrbuf)) == 0)
279 return NULL;
280 port = ntohs(((struct sockaddr_in *)sap)->sin_port);
281 break;
282 case AF_INET6:
283 if (rpc_ntop6_noscopeid(sap, addrbuf, sizeof(addrbuf)) == 0)
284 return NULL;
285 port = ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
286 break;
287 default:
288 return NULL;
289 }
290
291 if (snprintf(portbuf, sizeof(portbuf),
292 ".%u.%u", port >> 8, port & 0xff) > (int)sizeof(portbuf))
293 return NULL;
294
295 if (strlcat(addrbuf, portbuf, sizeof(addrbuf)) > sizeof(addrbuf))
296 return NULL;
297
298 return kstrdup(addrbuf, GFP_KERNEL);
299}
300EXPORT_SYMBOL_GPL(rpc_sockaddr2uaddr);
301
302/**
303 * rpc_uaddr2sockaddr - convert a universal address to a socket address.
304 * @uaddr: C string containing universal address to convert
305 * @uaddr_len: length of universal address string
306 * @sap: buffer into which to plant socket address
307 * @salen: size of buffer
308 *
309 * Returns the size of the socket address if successful; otherwise
310 * zero is returned.
311 */
312size_t rpc_uaddr2sockaddr(const char *uaddr, const size_t uaddr_len,
313 struct sockaddr *sap, const size_t salen)
314{
315 char *c, buf[RPCBIND_MAXUADDRLEN];
316 unsigned long portlo, porthi;
317 unsigned short port;
318
319 if (uaddr_len > sizeof(buf))
320 return 0;
321
322 memcpy(buf, uaddr, uaddr_len);
323
324 buf[uaddr_len] = '\n';
325 buf[uaddr_len + 1] = '\0';
326
327 c = strrchr(buf, '.');
328 if (unlikely(c == NULL))
329 return 0;
330 if (unlikely(strict_strtoul(c + 1, 10, &portlo) != 0))
331 return 0;
332 if (unlikely(portlo > 255))
333 return 0;
334
335 c[0] = '\n';
336 c[1] = '\0';
337
338 c = strrchr(buf, '.');
339 if (unlikely(c == NULL))
340 return 0;
341 if (unlikely(strict_strtoul(c + 1, 10, &porthi) != 0))
342 return 0;
343 if (unlikely(porthi > 255))
344 return 0;
345
346 port = (unsigned short)((porthi << 8) | portlo);
347
348 c[0] = '\0';
349
350 if (rpc_pton(buf, strlen(buf), sap, salen) == 0)
351 return 0;
352
353 switch (sap->sa_family) {
354 case AF_INET:
355 ((struct sockaddr_in *)sap)->sin_port = htons(port);
356 return sizeof(struct sockaddr_in);
357 case AF_INET6:
358 ((struct sockaddr_in6 *)sap)->sin6_port = htons(port);
359 return sizeof(struct sockaddr_in6);
360 }
361
362 return 0;
363}
364EXPORT_SYMBOL_GPL(rpc_uaddr2sockaddr);
diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
index 66d458fc6920..fc6a43ccd950 100644
--- a/net/sunrpc/auth_gss/auth_gss.c
+++ b/net/sunrpc/auth_gss/auth_gss.c
@@ -89,8 +89,8 @@ static struct rpc_wait_queue pipe_version_rpc_waitqueue;
89static DECLARE_WAIT_QUEUE_HEAD(pipe_version_waitqueue); 89static DECLARE_WAIT_QUEUE_HEAD(pipe_version_waitqueue);
90 90
91static void gss_free_ctx(struct gss_cl_ctx *); 91static void gss_free_ctx(struct gss_cl_ctx *);
92static struct rpc_pipe_ops gss_upcall_ops_v0; 92static const struct rpc_pipe_ops gss_upcall_ops_v0;
93static struct rpc_pipe_ops gss_upcall_ops_v1; 93static const struct rpc_pipe_ops gss_upcall_ops_v1;
94 94
95static inline struct gss_cl_ctx * 95static inline struct gss_cl_ctx *
96gss_get_ctx(struct gss_cl_ctx *ctx) 96gss_get_ctx(struct gss_cl_ctx *ctx)
@@ -777,7 +777,7 @@ gss_create(struct rpc_clnt *clnt, rpc_authflavor_t flavor)
777 * that we supported only the old pipe. So we instead create 777 * that we supported only the old pipe. So we instead create
778 * the new pipe first. 778 * the new pipe first.
779 */ 779 */
780 gss_auth->dentry[1] = rpc_mkpipe(clnt->cl_dentry, 780 gss_auth->dentry[1] = rpc_mkpipe(clnt->cl_path.dentry,
781 "gssd", 781 "gssd",
782 clnt, &gss_upcall_ops_v1, 782 clnt, &gss_upcall_ops_v1,
783 RPC_PIPE_WAIT_FOR_OPEN); 783 RPC_PIPE_WAIT_FOR_OPEN);
@@ -786,7 +786,7 @@ gss_create(struct rpc_clnt *clnt, rpc_authflavor_t flavor)
786 goto err_put_mech; 786 goto err_put_mech;
787 } 787 }
788 788
789 gss_auth->dentry[0] = rpc_mkpipe(clnt->cl_dentry, 789 gss_auth->dentry[0] = rpc_mkpipe(clnt->cl_path.dentry,
790 gss_auth->mech->gm_name, 790 gss_auth->mech->gm_name,
791 clnt, &gss_upcall_ops_v0, 791 clnt, &gss_upcall_ops_v0,
792 RPC_PIPE_WAIT_FOR_OPEN); 792 RPC_PIPE_WAIT_FOR_OPEN);
@@ -1507,7 +1507,7 @@ static const struct rpc_credops gss_nullops = {
1507 .crunwrap_resp = gss_unwrap_resp, 1507 .crunwrap_resp = gss_unwrap_resp,
1508}; 1508};
1509 1509
1510static struct rpc_pipe_ops gss_upcall_ops_v0 = { 1510static const struct rpc_pipe_ops gss_upcall_ops_v0 = {
1511 .upcall = gss_pipe_upcall, 1511 .upcall = gss_pipe_upcall,
1512 .downcall = gss_pipe_downcall, 1512 .downcall = gss_pipe_downcall,
1513 .destroy_msg = gss_pipe_destroy_msg, 1513 .destroy_msg = gss_pipe_destroy_msg,
@@ -1515,7 +1515,7 @@ static struct rpc_pipe_ops gss_upcall_ops_v0 = {
1515 .release_pipe = gss_pipe_release, 1515 .release_pipe = gss_pipe_release,
1516}; 1516};
1517 1517
1518static struct rpc_pipe_ops gss_upcall_ops_v1 = { 1518static const struct rpc_pipe_ops gss_upcall_ops_v1 = {
1519 .upcall = gss_pipe_upcall, 1519 .upcall = gss_pipe_upcall,
1520 .downcall = gss_pipe_downcall, 1520 .downcall = gss_pipe_downcall,
1521 .destroy_msg = gss_pipe_destroy_msg, 1521 .destroy_msg = gss_pipe_destroy_msg,
diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
index 2278a50c6444..2e6a148d277c 100644
--- a/net/sunrpc/auth_gss/svcauth_gss.c
+++ b/net/sunrpc/auth_gss/svcauth_gss.c
@@ -181,6 +181,11 @@ static void rsi_request(struct cache_detail *cd,
181 (*bpp)[-1] = '\n'; 181 (*bpp)[-1] = '\n';
182} 182}
183 183
184static int rsi_upcall(struct cache_detail *cd, struct cache_head *h)
185{
186 return sunrpc_cache_pipe_upcall(cd, h, rsi_request);
187}
188
184 189
185static int rsi_parse(struct cache_detail *cd, 190static int rsi_parse(struct cache_detail *cd,
186 char *mesg, int mlen) 191 char *mesg, int mlen)
@@ -270,7 +275,7 @@ static struct cache_detail rsi_cache = {
270 .hash_table = rsi_table, 275 .hash_table = rsi_table,
271 .name = "auth.rpcsec.init", 276 .name = "auth.rpcsec.init",
272 .cache_put = rsi_put, 277 .cache_put = rsi_put,
273 .cache_request = rsi_request, 278 .cache_upcall = rsi_upcall,
274 .cache_parse = rsi_parse, 279 .cache_parse = rsi_parse,
275 .match = rsi_match, 280 .match = rsi_match,
276 .init = rsi_init, 281 .init = rsi_init,
diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
index ff0c23053d2f..45cdaff9b361 100644
--- a/net/sunrpc/cache.c
+++ b/net/sunrpc/cache.c
@@ -27,10 +27,12 @@
27#include <linux/net.h> 27#include <linux/net.h>
28#include <linux/workqueue.h> 28#include <linux/workqueue.h>
29#include <linux/mutex.h> 29#include <linux/mutex.h>
30#include <linux/pagemap.h>
30#include <asm/ioctls.h> 31#include <asm/ioctls.h>
31#include <linux/sunrpc/types.h> 32#include <linux/sunrpc/types.h>
32#include <linux/sunrpc/cache.h> 33#include <linux/sunrpc/cache.h>
33#include <linux/sunrpc/stats.h> 34#include <linux/sunrpc/stats.h>
35#include <linux/sunrpc/rpc_pipe_fs.h>
34 36
35#define RPCDBG_FACILITY RPCDBG_CACHE 37#define RPCDBG_FACILITY RPCDBG_CACHE
36 38
@@ -175,7 +177,13 @@ struct cache_head *sunrpc_cache_update(struct cache_detail *detail,
175} 177}
176EXPORT_SYMBOL_GPL(sunrpc_cache_update); 178EXPORT_SYMBOL_GPL(sunrpc_cache_update);
177 179
178static int cache_make_upcall(struct cache_detail *detail, struct cache_head *h); 180static int cache_make_upcall(struct cache_detail *cd, struct cache_head *h)
181{
182 if (!cd->cache_upcall)
183 return -EINVAL;
184 return cd->cache_upcall(cd, h);
185}
186
179/* 187/*
180 * This is the generic cache management routine for all 188 * This is the generic cache management routine for all
181 * the authentication caches. 189 * the authentication caches.
@@ -284,76 +292,11 @@ static DEFINE_SPINLOCK(cache_list_lock);
284static struct cache_detail *current_detail; 292static struct cache_detail *current_detail;
285static int current_index; 293static int current_index;
286 294
287static const struct file_operations cache_file_operations;
288static const struct file_operations content_file_operations;
289static const struct file_operations cache_flush_operations;
290
291static void do_cache_clean(struct work_struct *work); 295static void do_cache_clean(struct work_struct *work);
292static DECLARE_DELAYED_WORK(cache_cleaner, do_cache_clean); 296static DECLARE_DELAYED_WORK(cache_cleaner, do_cache_clean);
293 297
294static void remove_cache_proc_entries(struct cache_detail *cd) 298static void sunrpc_init_cache_detail(struct cache_detail *cd)
295{
296 if (cd->proc_ent == NULL)
297 return;
298 if (cd->flush_ent)
299 remove_proc_entry("flush", cd->proc_ent);
300 if (cd->channel_ent)
301 remove_proc_entry("channel", cd->proc_ent);
302 if (cd->content_ent)
303 remove_proc_entry("content", cd->proc_ent);
304 cd->proc_ent = NULL;
305 remove_proc_entry(cd->name, proc_net_rpc);
306}
307
308#ifdef CONFIG_PROC_FS
309static int create_cache_proc_entries(struct cache_detail *cd)
310{
311 struct proc_dir_entry *p;
312
313 cd->proc_ent = proc_mkdir(cd->name, proc_net_rpc);
314 if (cd->proc_ent == NULL)
315 goto out_nomem;
316 cd->channel_ent = cd->content_ent = NULL;
317
318 p = proc_create_data("flush", S_IFREG|S_IRUSR|S_IWUSR,
319 cd->proc_ent, &cache_flush_operations, cd);
320 cd->flush_ent = p;
321 if (p == NULL)
322 goto out_nomem;
323
324 if (cd->cache_request || cd->cache_parse) {
325 p = proc_create_data("channel", S_IFREG|S_IRUSR|S_IWUSR,
326 cd->proc_ent, &cache_file_operations, cd);
327 cd->channel_ent = p;
328 if (p == NULL)
329 goto out_nomem;
330 }
331 if (cd->cache_show) {
332 p = proc_create_data("content", S_IFREG|S_IRUSR|S_IWUSR,
333 cd->proc_ent, &content_file_operations, cd);
334 cd->content_ent = p;
335 if (p == NULL)
336 goto out_nomem;
337 }
338 return 0;
339out_nomem:
340 remove_cache_proc_entries(cd);
341 return -ENOMEM;
342}
343#else /* CONFIG_PROC_FS */
344static int create_cache_proc_entries(struct cache_detail *cd)
345{
346 return 0;
347}
348#endif
349
350int cache_register(struct cache_detail *cd)
351{ 299{
352 int ret;
353
354 ret = create_cache_proc_entries(cd);
355 if (ret)
356 return ret;
357 rwlock_init(&cd->hash_lock); 300 rwlock_init(&cd->hash_lock);
358 INIT_LIST_HEAD(&cd->queue); 301 INIT_LIST_HEAD(&cd->queue);
359 spin_lock(&cache_list_lock); 302 spin_lock(&cache_list_lock);
@@ -367,11 +310,9 @@ int cache_register(struct cache_detail *cd)
367 310
368 /* start the cleaning process */ 311 /* start the cleaning process */
369 schedule_delayed_work(&cache_cleaner, 0); 312 schedule_delayed_work(&cache_cleaner, 0);
370 return 0;
371} 313}
372EXPORT_SYMBOL_GPL(cache_register);
373 314
374void cache_unregister(struct cache_detail *cd) 315static void sunrpc_destroy_cache_detail(struct cache_detail *cd)
375{ 316{
376 cache_purge(cd); 317 cache_purge(cd);
377 spin_lock(&cache_list_lock); 318 spin_lock(&cache_list_lock);
@@ -386,7 +327,6 @@ void cache_unregister(struct cache_detail *cd)
386 list_del_init(&cd->others); 327 list_del_init(&cd->others);
387 write_unlock(&cd->hash_lock); 328 write_unlock(&cd->hash_lock);
388 spin_unlock(&cache_list_lock); 329 spin_unlock(&cache_list_lock);
389 remove_cache_proc_entries(cd);
390 if (list_empty(&cache_list)) { 330 if (list_empty(&cache_list)) {
391 /* module must be being unloaded so its safe to kill the worker */ 331 /* module must be being unloaded so its safe to kill the worker */
392 cancel_delayed_work_sync(&cache_cleaner); 332 cancel_delayed_work_sync(&cache_cleaner);
@@ -395,7 +335,6 @@ void cache_unregister(struct cache_detail *cd)
395out: 335out:
396 printk(KERN_ERR "nfsd: failed to unregister %s cache\n", cd->name); 336 printk(KERN_ERR "nfsd: failed to unregister %s cache\n", cd->name);
397} 337}
398EXPORT_SYMBOL_GPL(cache_unregister);
399 338
400/* clean cache tries to find something to clean 339/* clean cache tries to find something to clean
401 * and cleans it. 340 * and cleans it.
@@ -687,18 +626,18 @@ struct cache_reader {
687 int offset; /* if non-0, we have a refcnt on next request */ 626 int offset; /* if non-0, we have a refcnt on next request */
688}; 627};
689 628
690static ssize_t 629static ssize_t cache_read(struct file *filp, char __user *buf, size_t count,
691cache_read(struct file *filp, char __user *buf, size_t count, loff_t *ppos) 630 loff_t *ppos, struct cache_detail *cd)
692{ 631{
693 struct cache_reader *rp = filp->private_data; 632 struct cache_reader *rp = filp->private_data;
694 struct cache_request *rq; 633 struct cache_request *rq;
695 struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data; 634 struct inode *inode = filp->f_path.dentry->d_inode;
696 int err; 635 int err;
697 636
698 if (count == 0) 637 if (count == 0)
699 return 0; 638 return 0;
700 639
701 mutex_lock(&queue_io_mutex); /* protect against multiple concurrent 640 mutex_lock(&inode->i_mutex); /* protect against multiple concurrent
702 * readers on this file */ 641 * readers on this file */
703 again: 642 again:
704 spin_lock(&queue_lock); 643 spin_lock(&queue_lock);
@@ -711,7 +650,7 @@ cache_read(struct file *filp, char __user *buf, size_t count, loff_t *ppos)
711 } 650 }
712 if (rp->q.list.next == &cd->queue) { 651 if (rp->q.list.next == &cd->queue) {
713 spin_unlock(&queue_lock); 652 spin_unlock(&queue_lock);
714 mutex_unlock(&queue_io_mutex); 653 mutex_unlock(&inode->i_mutex);
715 BUG_ON(rp->offset); 654 BUG_ON(rp->offset);
716 return 0; 655 return 0;
717 } 656 }
@@ -758,49 +697,90 @@ cache_read(struct file *filp, char __user *buf, size_t count, loff_t *ppos)
758 } 697 }
759 if (err == -EAGAIN) 698 if (err == -EAGAIN)
760 goto again; 699 goto again;
761 mutex_unlock(&queue_io_mutex); 700 mutex_unlock(&inode->i_mutex);
762 return err ? err : count; 701 return err ? err : count;
763} 702}
764 703
765static char write_buf[8192]; /* protected by queue_io_mutex */ 704static ssize_t cache_do_downcall(char *kaddr, const char __user *buf,
705 size_t count, struct cache_detail *cd)
706{
707 ssize_t ret;
766 708
767static ssize_t 709 if (copy_from_user(kaddr, buf, count))
768cache_write(struct file *filp, const char __user *buf, size_t count, 710 return -EFAULT;
769 loff_t *ppos) 711 kaddr[count] = '\0';
712 ret = cd->cache_parse(cd, kaddr, count);
713 if (!ret)
714 ret = count;
715 return ret;
716}
717
718static ssize_t cache_slow_downcall(const char __user *buf,
719 size_t count, struct cache_detail *cd)
770{ 720{
771 int err; 721 static char write_buf[8192]; /* protected by queue_io_mutex */
772 struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data; 722 ssize_t ret = -EINVAL;
773 723
774 if (count == 0)
775 return 0;
776 if (count >= sizeof(write_buf)) 724 if (count >= sizeof(write_buf))
777 return -EINVAL; 725 goto out;
778
779 mutex_lock(&queue_io_mutex); 726 mutex_lock(&queue_io_mutex);
727 ret = cache_do_downcall(write_buf, buf, count, cd);
728 mutex_unlock(&queue_io_mutex);
729out:
730 return ret;
731}
780 732
781 if (copy_from_user(write_buf, buf, count)) { 733static ssize_t cache_downcall(struct address_space *mapping,
782 mutex_unlock(&queue_io_mutex); 734 const char __user *buf,
783 return -EFAULT; 735 size_t count, struct cache_detail *cd)
784 } 736{
785 write_buf[count] = '\0'; 737 struct page *page;
786 if (cd->cache_parse) 738 char *kaddr;
787 err = cd->cache_parse(cd, write_buf, count); 739 ssize_t ret = -ENOMEM;
788 else 740
789 err = -EINVAL; 741 if (count >= PAGE_CACHE_SIZE)
742 goto out_slow;
743
744 page = find_or_create_page(mapping, 0, GFP_KERNEL);
745 if (!page)
746 goto out_slow;
747
748 kaddr = kmap(page);
749 ret = cache_do_downcall(kaddr, buf, count, cd);
750 kunmap(page);
751 unlock_page(page);
752 page_cache_release(page);
753 return ret;
754out_slow:
755 return cache_slow_downcall(buf, count, cd);
756}
790 757
791 mutex_unlock(&queue_io_mutex); 758static ssize_t cache_write(struct file *filp, const char __user *buf,
792 return err ? err : count; 759 size_t count, loff_t *ppos,
760 struct cache_detail *cd)
761{
762 struct address_space *mapping = filp->f_mapping;
763 struct inode *inode = filp->f_path.dentry->d_inode;
764 ssize_t ret = -EINVAL;
765
766 if (!cd->cache_parse)
767 goto out;
768
769 mutex_lock(&inode->i_mutex);
770 ret = cache_downcall(mapping, buf, count, cd);
771 mutex_unlock(&inode->i_mutex);
772out:
773 return ret;
793} 774}
794 775
795static DECLARE_WAIT_QUEUE_HEAD(queue_wait); 776static DECLARE_WAIT_QUEUE_HEAD(queue_wait);
796 777
797static unsigned int 778static unsigned int cache_poll(struct file *filp, poll_table *wait,
798cache_poll(struct file *filp, poll_table *wait) 779 struct cache_detail *cd)
799{ 780{
800 unsigned int mask; 781 unsigned int mask;
801 struct cache_reader *rp = filp->private_data; 782 struct cache_reader *rp = filp->private_data;
802 struct cache_queue *cq; 783 struct cache_queue *cq;
803 struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data;
804 784
805 poll_wait(filp, &queue_wait, wait); 785 poll_wait(filp, &queue_wait, wait);
806 786
@@ -822,14 +802,13 @@ cache_poll(struct file *filp, poll_table *wait)
822 return mask; 802 return mask;
823} 803}
824 804
825static int 805static int cache_ioctl(struct inode *ino, struct file *filp,
826cache_ioctl(struct inode *ino, struct file *filp, 806 unsigned int cmd, unsigned long arg,
827 unsigned int cmd, unsigned long arg) 807 struct cache_detail *cd)
828{ 808{
829 int len = 0; 809 int len = 0;
830 struct cache_reader *rp = filp->private_data; 810 struct cache_reader *rp = filp->private_data;
831 struct cache_queue *cq; 811 struct cache_queue *cq;
832 struct cache_detail *cd = PDE(ino)->data;
833 812
834 if (cmd != FIONREAD || !rp) 813 if (cmd != FIONREAD || !rp)
835 return -EINVAL; 814 return -EINVAL;
@@ -852,15 +831,15 @@ cache_ioctl(struct inode *ino, struct file *filp,
852 return put_user(len, (int __user *)arg); 831 return put_user(len, (int __user *)arg);
853} 832}
854 833
855static int 834static int cache_open(struct inode *inode, struct file *filp,
856cache_open(struct inode *inode, struct file *filp) 835 struct cache_detail *cd)
857{ 836{
858 struct cache_reader *rp = NULL; 837 struct cache_reader *rp = NULL;
859 838
839 if (!cd || !try_module_get(cd->owner))
840 return -EACCES;
860 nonseekable_open(inode, filp); 841 nonseekable_open(inode, filp);
861 if (filp->f_mode & FMODE_READ) { 842 if (filp->f_mode & FMODE_READ) {
862 struct cache_detail *cd = PDE(inode)->data;
863
864 rp = kmalloc(sizeof(*rp), GFP_KERNEL); 843 rp = kmalloc(sizeof(*rp), GFP_KERNEL);
865 if (!rp) 844 if (!rp)
866 return -ENOMEM; 845 return -ENOMEM;
@@ -875,11 +854,10 @@ cache_open(struct inode *inode, struct file *filp)
875 return 0; 854 return 0;
876} 855}
877 856
878static int 857static int cache_release(struct inode *inode, struct file *filp,
879cache_release(struct inode *inode, struct file *filp) 858 struct cache_detail *cd)
880{ 859{
881 struct cache_reader *rp = filp->private_data; 860 struct cache_reader *rp = filp->private_data;
882 struct cache_detail *cd = PDE(inode)->data;
883 861
884 if (rp) { 862 if (rp) {
885 spin_lock(&queue_lock); 863 spin_lock(&queue_lock);
@@ -903,23 +881,12 @@ cache_release(struct inode *inode, struct file *filp)
903 cd->last_close = get_seconds(); 881 cd->last_close = get_seconds();
904 atomic_dec(&cd->readers); 882 atomic_dec(&cd->readers);
905 } 883 }
884 module_put(cd->owner);
906 return 0; 885 return 0;
907} 886}
908 887
909 888
910 889
911static const struct file_operations cache_file_operations = {
912 .owner = THIS_MODULE,
913 .llseek = no_llseek,
914 .read = cache_read,
915 .write = cache_write,
916 .poll = cache_poll,
917 .ioctl = cache_ioctl, /* for FIONREAD */
918 .open = cache_open,
919 .release = cache_release,
920};
921
922
923static void queue_loose(struct cache_detail *detail, struct cache_head *ch) 890static void queue_loose(struct cache_detail *detail, struct cache_head *ch)
924{ 891{
925 struct cache_queue *cq; 892 struct cache_queue *cq;
@@ -1020,15 +987,21 @@ static void warn_no_listener(struct cache_detail *detail)
1020 if (detail->last_warn != detail->last_close) { 987 if (detail->last_warn != detail->last_close) {
1021 detail->last_warn = detail->last_close; 988 detail->last_warn = detail->last_close;
1022 if (detail->warn_no_listener) 989 if (detail->warn_no_listener)
1023 detail->warn_no_listener(detail); 990 detail->warn_no_listener(detail, detail->last_close != 0);
1024 } 991 }
1025} 992}
1026 993
1027/* 994/*
1028 * register an upcall request to user-space. 995 * register an upcall request to user-space and queue it up for read() by the
996 * upcall daemon.
997 *
1029 * Each request is at most one page long. 998 * Each request is at most one page long.
1030 */ 999 */
1031static int cache_make_upcall(struct cache_detail *detail, struct cache_head *h) 1000int sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h,
1001 void (*cache_request)(struct cache_detail *,
1002 struct cache_head *,
1003 char **,
1004 int *))
1032{ 1005{
1033 1006
1034 char *buf; 1007 char *buf;
@@ -1036,9 +1009,6 @@ static int cache_make_upcall(struct cache_detail *detail, struct cache_head *h)
1036 char *bp; 1009 char *bp;
1037 int len; 1010 int len;
1038 1011
1039 if (detail->cache_request == NULL)
1040 return -EINVAL;
1041
1042 if (atomic_read(&detail->readers) == 0 && 1012 if (atomic_read(&detail->readers) == 0 &&
1043 detail->last_close < get_seconds() - 30) { 1013 detail->last_close < get_seconds() - 30) {
1044 warn_no_listener(detail); 1014 warn_no_listener(detail);
@@ -1057,7 +1027,7 @@ static int cache_make_upcall(struct cache_detail *detail, struct cache_head *h)
1057 1027
1058 bp = buf; len = PAGE_SIZE; 1028 bp = buf; len = PAGE_SIZE;
1059 1029
1060 detail->cache_request(detail, h, &bp, &len); 1030 cache_request(detail, h, &bp, &len);
1061 1031
1062 if (len < 0) { 1032 if (len < 0) {
1063 kfree(buf); 1033 kfree(buf);
@@ -1075,6 +1045,7 @@ static int cache_make_upcall(struct cache_detail *detail, struct cache_head *h)
1075 wake_up(&queue_wait); 1045 wake_up(&queue_wait);
1076 return 0; 1046 return 0;
1077} 1047}
1048EXPORT_SYMBOL_GPL(sunrpc_cache_pipe_upcall);
1078 1049
1079/* 1050/*
1080 * parse a message from user-space and pass it 1051 * parse a message from user-space and pass it
@@ -1242,11 +1213,13 @@ static const struct seq_operations cache_content_op = {
1242 .show = c_show, 1213 .show = c_show,
1243}; 1214};
1244 1215
1245static int content_open(struct inode *inode, struct file *file) 1216static int content_open(struct inode *inode, struct file *file,
1217 struct cache_detail *cd)
1246{ 1218{
1247 struct handle *han; 1219 struct handle *han;
1248 struct cache_detail *cd = PDE(inode)->data;
1249 1220
1221 if (!cd || !try_module_get(cd->owner))
1222 return -EACCES;
1250 han = __seq_open_private(file, &cache_content_op, sizeof(*han)); 1223 han = __seq_open_private(file, &cache_content_op, sizeof(*han));
1251 if (han == NULL) 1224 if (han == NULL)
1252 return -ENOMEM; 1225 return -ENOMEM;
@@ -1255,17 +1228,33 @@ static int content_open(struct inode *inode, struct file *file)
1255 return 0; 1228 return 0;
1256} 1229}
1257 1230
1258static const struct file_operations content_file_operations = { 1231static int content_release(struct inode *inode, struct file *file,
1259 .open = content_open, 1232 struct cache_detail *cd)
1260 .read = seq_read, 1233{
1261 .llseek = seq_lseek, 1234 int ret = seq_release_private(inode, file);
1262 .release = seq_release_private, 1235 module_put(cd->owner);
1263}; 1236 return ret;
1237}
1238
1239static int open_flush(struct inode *inode, struct file *file,
1240 struct cache_detail *cd)
1241{
1242 if (!cd || !try_module_get(cd->owner))
1243 return -EACCES;
1244 return nonseekable_open(inode, file);
1245}
1246
1247static int release_flush(struct inode *inode, struct file *file,
1248 struct cache_detail *cd)
1249{
1250 module_put(cd->owner);
1251 return 0;
1252}
1264 1253
1265static ssize_t read_flush(struct file *file, char __user *buf, 1254static ssize_t read_flush(struct file *file, char __user *buf,
1266 size_t count, loff_t *ppos) 1255 size_t count, loff_t *ppos,
1256 struct cache_detail *cd)
1267{ 1257{
1268 struct cache_detail *cd = PDE(file->f_path.dentry->d_inode)->data;
1269 char tbuf[20]; 1258 char tbuf[20];
1270 unsigned long p = *ppos; 1259 unsigned long p = *ppos;
1271 size_t len; 1260 size_t len;
@@ -1283,10 +1272,10 @@ static ssize_t read_flush(struct file *file, char __user *buf,
1283 return len; 1272 return len;
1284} 1273}
1285 1274
1286static ssize_t write_flush(struct file * file, const char __user * buf, 1275static ssize_t write_flush(struct file *file, const char __user *buf,
1287 size_t count, loff_t *ppos) 1276 size_t count, loff_t *ppos,
1277 struct cache_detail *cd)
1288{ 1278{
1289 struct cache_detail *cd = PDE(file->f_path.dentry->d_inode)->data;
1290 char tbuf[20]; 1279 char tbuf[20];
1291 char *ep; 1280 char *ep;
1292 long flushtime; 1281 long flushtime;
@@ -1307,8 +1296,343 @@ static ssize_t write_flush(struct file * file, const char __user * buf,
1307 return count; 1296 return count;
1308} 1297}
1309 1298
1310static const struct file_operations cache_flush_operations = { 1299static ssize_t cache_read_procfs(struct file *filp, char __user *buf,
1311 .open = nonseekable_open, 1300 size_t count, loff_t *ppos)
1312 .read = read_flush, 1301{
1313 .write = write_flush, 1302 struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data;
1303
1304 return cache_read(filp, buf, count, ppos, cd);
1305}
1306
1307static ssize_t cache_write_procfs(struct file *filp, const char __user *buf,
1308 size_t count, loff_t *ppos)
1309{
1310 struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data;
1311
1312 return cache_write(filp, buf, count, ppos, cd);
1313}
1314
1315static unsigned int cache_poll_procfs(struct file *filp, poll_table *wait)
1316{
1317 struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data;
1318
1319 return cache_poll(filp, wait, cd);
1320}
1321
1322static int cache_ioctl_procfs(struct inode *inode, struct file *filp,
1323 unsigned int cmd, unsigned long arg)
1324{
1325 struct cache_detail *cd = PDE(inode)->data;
1326
1327 return cache_ioctl(inode, filp, cmd, arg, cd);
1328}
1329
1330static int cache_open_procfs(struct inode *inode, struct file *filp)
1331{
1332 struct cache_detail *cd = PDE(inode)->data;
1333
1334 return cache_open(inode, filp, cd);
1335}
1336
1337static int cache_release_procfs(struct inode *inode, struct file *filp)
1338{
1339 struct cache_detail *cd = PDE(inode)->data;
1340
1341 return cache_release(inode, filp, cd);
1342}
1343
1344static const struct file_operations cache_file_operations_procfs = {
1345 .owner = THIS_MODULE,
1346 .llseek = no_llseek,
1347 .read = cache_read_procfs,
1348 .write = cache_write_procfs,
1349 .poll = cache_poll_procfs,
1350 .ioctl = cache_ioctl_procfs, /* for FIONREAD */
1351 .open = cache_open_procfs,
1352 .release = cache_release_procfs,
1314}; 1353};
1354
1355static int content_open_procfs(struct inode *inode, struct file *filp)
1356{
1357 struct cache_detail *cd = PDE(inode)->data;
1358
1359 return content_open(inode, filp, cd);
1360}
1361
1362static int content_release_procfs(struct inode *inode, struct file *filp)
1363{
1364 struct cache_detail *cd = PDE(inode)->data;
1365
1366 return content_release(inode, filp, cd);
1367}
1368
1369static const struct file_operations content_file_operations_procfs = {
1370 .open = content_open_procfs,
1371 .read = seq_read,
1372 .llseek = seq_lseek,
1373 .release = content_release_procfs,
1374};
1375
1376static int open_flush_procfs(struct inode *inode, struct file *filp)
1377{
1378 struct cache_detail *cd = PDE(inode)->data;
1379
1380 return open_flush(inode, filp, cd);
1381}
1382
1383static int release_flush_procfs(struct inode *inode, struct file *filp)
1384{
1385 struct cache_detail *cd = PDE(inode)->data;
1386
1387 return release_flush(inode, filp, cd);
1388}
1389
1390static ssize_t read_flush_procfs(struct file *filp, char __user *buf,
1391 size_t count, loff_t *ppos)
1392{
1393 struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data;
1394
1395 return read_flush(filp, buf, count, ppos, cd);
1396}
1397
1398static ssize_t write_flush_procfs(struct file *filp,
1399 const char __user *buf,
1400 size_t count, loff_t *ppos)
1401{
1402 struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data;
1403
1404 return write_flush(filp, buf, count, ppos, cd);
1405}
1406
1407static const struct file_operations cache_flush_operations_procfs = {
1408 .open = open_flush_procfs,
1409 .read = read_flush_procfs,
1410 .write = write_flush_procfs,
1411 .release = release_flush_procfs,
1412};
1413
1414static void remove_cache_proc_entries(struct cache_detail *cd)
1415{
1416 if (cd->u.procfs.proc_ent == NULL)
1417 return;
1418 if (cd->u.procfs.flush_ent)
1419 remove_proc_entry("flush", cd->u.procfs.proc_ent);
1420 if (cd->u.procfs.channel_ent)
1421 remove_proc_entry("channel", cd->u.procfs.proc_ent);
1422 if (cd->u.procfs.content_ent)
1423 remove_proc_entry("content", cd->u.procfs.proc_ent);
1424 cd->u.procfs.proc_ent = NULL;
1425 remove_proc_entry(cd->name, proc_net_rpc);
1426}
1427
1428#ifdef CONFIG_PROC_FS
1429static int create_cache_proc_entries(struct cache_detail *cd)
1430{
1431 struct proc_dir_entry *p;
1432
1433 cd->u.procfs.proc_ent = proc_mkdir(cd->name, proc_net_rpc);
1434 if (cd->u.procfs.proc_ent == NULL)
1435 goto out_nomem;
1436 cd->u.procfs.channel_ent = NULL;
1437 cd->u.procfs.content_ent = NULL;
1438
1439 p = proc_create_data("flush", S_IFREG|S_IRUSR|S_IWUSR,
1440 cd->u.procfs.proc_ent,
1441 &cache_flush_operations_procfs, cd);
1442 cd->u.procfs.flush_ent = p;
1443 if (p == NULL)
1444 goto out_nomem;
1445
1446 if (cd->cache_upcall || cd->cache_parse) {
1447 p = proc_create_data("channel", S_IFREG|S_IRUSR|S_IWUSR,
1448 cd->u.procfs.proc_ent,
1449 &cache_file_operations_procfs, cd);
1450 cd->u.procfs.channel_ent = p;
1451 if (p == NULL)
1452 goto out_nomem;
1453 }
1454 if (cd->cache_show) {
1455 p = proc_create_data("content", S_IFREG|S_IRUSR|S_IWUSR,
1456 cd->u.procfs.proc_ent,
1457 &content_file_operations_procfs, cd);
1458 cd->u.procfs.content_ent = p;
1459 if (p == NULL)
1460 goto out_nomem;
1461 }
1462 return 0;
1463out_nomem:
1464 remove_cache_proc_entries(cd);
1465 return -ENOMEM;
1466}
1467#else /* CONFIG_PROC_FS */
1468static int create_cache_proc_entries(struct cache_detail *cd)
1469{
1470 return 0;
1471}
1472#endif
1473
1474int cache_register(struct cache_detail *cd)
1475{
1476 int ret;
1477
1478 sunrpc_init_cache_detail(cd);
1479 ret = create_cache_proc_entries(cd);
1480 if (ret)
1481 sunrpc_destroy_cache_detail(cd);
1482 return ret;
1483}
1484EXPORT_SYMBOL_GPL(cache_register);
1485
1486void cache_unregister(struct cache_detail *cd)
1487{
1488 remove_cache_proc_entries(cd);
1489 sunrpc_destroy_cache_detail(cd);
1490}
1491EXPORT_SYMBOL_GPL(cache_unregister);
1492
1493static ssize_t cache_read_pipefs(struct file *filp, char __user *buf,
1494 size_t count, loff_t *ppos)
1495{
1496 struct cache_detail *cd = RPC_I(filp->f_path.dentry->d_inode)->private;
1497
1498 return cache_read(filp, buf, count, ppos, cd);
1499}
1500
1501static ssize_t cache_write_pipefs(struct file *filp, const char __user *buf,
1502 size_t count, loff_t *ppos)
1503{
1504 struct cache_detail *cd = RPC_I(filp->f_path.dentry->d_inode)->private;
1505
1506 return cache_write(filp, buf, count, ppos, cd);
1507}
1508
1509static unsigned int cache_poll_pipefs(struct file *filp, poll_table *wait)
1510{
1511 struct cache_detail *cd = RPC_I(filp->f_path.dentry->d_inode)->private;
1512
1513 return cache_poll(filp, wait, cd);
1514}
1515
1516static int cache_ioctl_pipefs(struct inode *inode, struct file *filp,
1517 unsigned int cmd, unsigned long arg)
1518{
1519 struct cache_detail *cd = RPC_I(inode)->private;
1520
1521 return cache_ioctl(inode, filp, cmd, arg, cd);
1522}
1523
1524static int cache_open_pipefs(struct inode *inode, struct file *filp)
1525{
1526 struct cache_detail *cd = RPC_I(inode)->private;
1527
1528 return cache_open(inode, filp, cd);
1529}
1530
1531static int cache_release_pipefs(struct inode *inode, struct file *filp)
1532{
1533 struct cache_detail *cd = RPC_I(inode)->private;
1534
1535 return cache_release(inode, filp, cd);
1536}
1537
1538const struct file_operations cache_file_operations_pipefs = {
1539 .owner = THIS_MODULE,
1540 .llseek = no_llseek,
1541 .read = cache_read_pipefs,
1542 .write = cache_write_pipefs,
1543 .poll = cache_poll_pipefs,
1544 .ioctl = cache_ioctl_pipefs, /* for FIONREAD */
1545 .open = cache_open_pipefs,
1546 .release = cache_release_pipefs,
1547};
1548
1549static int content_open_pipefs(struct inode *inode, struct file *filp)
1550{
1551 struct cache_detail *cd = RPC_I(inode)->private;
1552
1553 return content_open(inode, filp, cd);
1554}
1555
1556static int content_release_pipefs(struct inode *inode, struct file *filp)
1557{
1558 struct cache_detail *cd = RPC_I(inode)->private;
1559
1560 return content_release(inode, filp, cd);
1561}
1562
1563const struct file_operations content_file_operations_pipefs = {
1564 .open = content_open_pipefs,
1565 .read = seq_read,
1566 .llseek = seq_lseek,
1567 .release = content_release_pipefs,
1568};
1569
1570static int open_flush_pipefs(struct inode *inode, struct file *filp)
1571{
1572 struct cache_detail *cd = RPC_I(inode)->private;
1573
1574 return open_flush(inode, filp, cd);
1575}
1576
1577static int release_flush_pipefs(struct inode *inode, struct file *filp)
1578{
1579 struct cache_detail *cd = RPC_I(inode)->private;
1580
1581 return release_flush(inode, filp, cd);
1582}
1583
1584static ssize_t read_flush_pipefs(struct file *filp, char __user *buf,
1585 size_t count, loff_t *ppos)
1586{
1587 struct cache_detail *cd = RPC_I(filp->f_path.dentry->d_inode)->private;
1588
1589 return read_flush(filp, buf, count, ppos, cd);
1590}
1591
1592static ssize_t write_flush_pipefs(struct file *filp,
1593 const char __user *buf,
1594 size_t count, loff_t *ppos)
1595{
1596 struct cache_detail *cd = RPC_I(filp->f_path.dentry->d_inode)->private;
1597
1598 return write_flush(filp, buf, count, ppos, cd);
1599}
1600
1601const struct file_operations cache_flush_operations_pipefs = {
1602 .open = open_flush_pipefs,
1603 .read = read_flush_pipefs,
1604 .write = write_flush_pipefs,
1605 .release = release_flush_pipefs,
1606};
1607
1608int sunrpc_cache_register_pipefs(struct dentry *parent,
1609 const char *name, mode_t umode,
1610 struct cache_detail *cd)
1611{
1612 struct qstr q;
1613 struct dentry *dir;
1614 int ret = 0;
1615
1616 sunrpc_init_cache_detail(cd);
1617 q.name = name;
1618 q.len = strlen(name);
1619 q.hash = full_name_hash(q.name, q.len);
1620 dir = rpc_create_cache_dir(parent, &q, umode, cd);
1621 if (!IS_ERR(dir))
1622 cd->u.pipefs.dir = dir;
1623 else {
1624 sunrpc_destroy_cache_detail(cd);
1625 ret = PTR_ERR(dir);
1626 }
1627 return ret;
1628}
1629EXPORT_SYMBOL_GPL(sunrpc_cache_register_pipefs);
1630
1631void sunrpc_cache_unregister_pipefs(struct cache_detail *cd)
1632{
1633 rpc_remove_cache_dir(cd->u.pipefs.dir);
1634 cd->u.pipefs.dir = NULL;
1635 sunrpc_destroy_cache_detail(cd);
1636}
1637EXPORT_SYMBOL_GPL(sunrpc_cache_unregister_pipefs);
1638
diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index df1039f077c2..fac0ca93f06b 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -27,6 +27,8 @@
27#include <linux/types.h> 27#include <linux/types.h>
28#include <linux/kallsyms.h> 28#include <linux/kallsyms.h>
29#include <linux/mm.h> 29#include <linux/mm.h>
30#include <linux/namei.h>
31#include <linux/mount.h>
30#include <linux/slab.h> 32#include <linux/slab.h>
31#include <linux/utsname.h> 33#include <linux/utsname.h>
32#include <linux/workqueue.h> 34#include <linux/workqueue.h>
@@ -97,33 +99,49 @@ static int
97rpc_setup_pipedir(struct rpc_clnt *clnt, char *dir_name) 99rpc_setup_pipedir(struct rpc_clnt *clnt, char *dir_name)
98{ 100{
99 static uint32_t clntid; 101 static uint32_t clntid;
102 struct nameidata nd;
103 struct path path;
104 char name[15];
105 struct qstr q = {
106 .name = name,
107 };
100 int error; 108 int error;
101 109
102 clnt->cl_vfsmnt = ERR_PTR(-ENOENT); 110 clnt->cl_path.mnt = ERR_PTR(-ENOENT);
103 clnt->cl_dentry = ERR_PTR(-ENOENT); 111 clnt->cl_path.dentry = ERR_PTR(-ENOENT);
104 if (dir_name == NULL) 112 if (dir_name == NULL)
105 return 0; 113 return 0;
106 114
107 clnt->cl_vfsmnt = rpc_get_mount(); 115 path.mnt = rpc_get_mount();
108 if (IS_ERR(clnt->cl_vfsmnt)) 116 if (IS_ERR(path.mnt))
109 return PTR_ERR(clnt->cl_vfsmnt); 117 return PTR_ERR(path.mnt);
118 error = vfs_path_lookup(path.mnt->mnt_root, path.mnt, dir_name, 0, &nd);
119 if (error)
120 goto err;
110 121
111 for (;;) { 122 for (;;) {
112 snprintf(clnt->cl_pathname, sizeof(clnt->cl_pathname), 123 q.len = snprintf(name, sizeof(name), "clnt%x", (unsigned int)clntid++);
113 "%s/clnt%x", dir_name, 124 name[sizeof(name) - 1] = '\0';
114 (unsigned int)clntid++); 125 q.hash = full_name_hash(q.name, q.len);
115 clnt->cl_pathname[sizeof(clnt->cl_pathname) - 1] = '\0'; 126 path.dentry = rpc_create_client_dir(nd.path.dentry, &q, clnt);
116 clnt->cl_dentry = rpc_mkdir(clnt->cl_pathname, clnt); 127 if (!IS_ERR(path.dentry))
117 if (!IS_ERR(clnt->cl_dentry)) 128 break;
118 return 0; 129 error = PTR_ERR(path.dentry);
119 error = PTR_ERR(clnt->cl_dentry);
120 if (error != -EEXIST) { 130 if (error != -EEXIST) {
121 printk(KERN_INFO "RPC: Couldn't create pipefs entry %s, error %d\n", 131 printk(KERN_INFO "RPC: Couldn't create pipefs entry"
122 clnt->cl_pathname, error); 132 " %s/%s, error %d\n",
123 rpc_put_mount(); 133 dir_name, name, error);
124 return error; 134 goto err_path_put;
125 } 135 }
126 } 136 }
137 path_put(&nd.path);
138 clnt->cl_path = path;
139 return 0;
140err_path_put:
141 path_put(&nd.path);
142err:
143 rpc_put_mount();
144 return error;
127} 145}
128 146
129static struct rpc_clnt * rpc_new_client(const struct rpc_create_args *args, struct rpc_xprt *xprt) 147static struct rpc_clnt * rpc_new_client(const struct rpc_create_args *args, struct rpc_xprt *xprt)
@@ -231,8 +249,8 @@ static struct rpc_clnt * rpc_new_client(const struct rpc_create_args *args, stru
231 return clnt; 249 return clnt;
232 250
233out_no_auth: 251out_no_auth:
234 if (!IS_ERR(clnt->cl_dentry)) { 252 if (!IS_ERR(clnt->cl_path.dentry)) {
235 rpc_rmdir(clnt->cl_dentry); 253 rpc_remove_client_dir(clnt->cl_path.dentry);
236 rpc_put_mount(); 254 rpc_put_mount();
237 } 255 }
238out_no_path: 256out_no_path:
@@ -423,8 +441,8 @@ rpc_free_client(struct kref *kref)
423 441
424 dprintk("RPC: destroying %s client for %s\n", 442 dprintk("RPC: destroying %s client for %s\n",
425 clnt->cl_protname, clnt->cl_server); 443 clnt->cl_protname, clnt->cl_server);
426 if (!IS_ERR(clnt->cl_dentry)) { 444 if (!IS_ERR(clnt->cl_path.dentry)) {
427 rpc_rmdir(clnt->cl_dentry); 445 rpc_remove_client_dir(clnt->cl_path.dentry);
428 rpc_put_mount(); 446 rpc_put_mount();
429 } 447 }
430 if (clnt->cl_parent != clnt) { 448 if (clnt->cl_parent != clnt) {
diff --git a/net/sunrpc/rpc_pipe.c b/net/sunrpc/rpc_pipe.c
index 9ced0628d69c..7f676bdf70d3 100644
--- a/net/sunrpc/rpc_pipe.c
+++ b/net/sunrpc/rpc_pipe.c
@@ -26,6 +26,7 @@
26#include <linux/sunrpc/clnt.h> 26#include <linux/sunrpc/clnt.h>
27#include <linux/workqueue.h> 27#include <linux/workqueue.h>
28#include <linux/sunrpc/rpc_pipe_fs.h> 28#include <linux/sunrpc/rpc_pipe_fs.h>
29#include <linux/sunrpc/cache.h>
29 30
30static struct vfsmount *rpc_mount __read_mostly; 31static struct vfsmount *rpc_mount __read_mostly;
31static int rpc_mount_count; 32static int rpc_mount_count;
@@ -125,7 +126,7 @@ static void
125rpc_close_pipes(struct inode *inode) 126rpc_close_pipes(struct inode *inode)
126{ 127{
127 struct rpc_inode *rpci = RPC_I(inode); 128 struct rpc_inode *rpci = RPC_I(inode);
128 struct rpc_pipe_ops *ops; 129 const struct rpc_pipe_ops *ops;
129 int need_release; 130 int need_release;
130 131
131 mutex_lock(&inode->i_mutex); 132 mutex_lock(&inode->i_mutex);
@@ -398,66 +399,12 @@ static const struct file_operations rpc_info_operations = {
398 399
399 400
400/* 401/*
401 * We have a single directory with 1 node in it.
402 */
403enum {
404 RPCAUTH_Root = 1,
405 RPCAUTH_lockd,
406 RPCAUTH_mount,
407 RPCAUTH_nfs,
408 RPCAUTH_portmap,
409 RPCAUTH_statd,
410 RPCAUTH_nfsd4_cb,
411 RPCAUTH_RootEOF
412};
413
414/*
415 * Description of fs contents. 402 * Description of fs contents.
416 */ 403 */
417struct rpc_filelist { 404struct rpc_filelist {
418 char *name; 405 const char *name;
419 const struct file_operations *i_fop; 406 const struct file_operations *i_fop;
420 int mode; 407 umode_t mode;
421};
422
423static struct rpc_filelist files[] = {
424 [RPCAUTH_lockd] = {
425 .name = "lockd",
426 .mode = S_IFDIR | S_IRUGO | S_IXUGO,
427 },
428 [RPCAUTH_mount] = {
429 .name = "mount",
430 .mode = S_IFDIR | S_IRUGO | S_IXUGO,
431 },
432 [RPCAUTH_nfs] = {
433 .name = "nfs",
434 .mode = S_IFDIR | S_IRUGO | S_IXUGO,
435 },
436 [RPCAUTH_portmap] = {
437 .name = "portmap",
438 .mode = S_IFDIR | S_IRUGO | S_IXUGO,
439 },
440 [RPCAUTH_statd] = {
441 .name = "statd",
442 .mode = S_IFDIR | S_IRUGO | S_IXUGO,
443 },
444 [RPCAUTH_nfsd4_cb] = {
445 .name = "nfsd4_cb",
446 .mode = S_IFDIR | S_IRUGO | S_IXUGO,
447 },
448};
449
450enum {
451 RPCAUTH_info = 2,
452 RPCAUTH_EOF
453};
454
455static struct rpc_filelist authfiles[] = {
456 [RPCAUTH_info] = {
457 .name = "info",
458 .i_fop = &rpc_info_operations,
459 .mode = S_IFREG | S_IRUSR,
460 },
461}; 408};
462 409
463struct vfsmount *rpc_get_mount(void) 410struct vfsmount *rpc_get_mount(void)
@@ -469,11 +416,13 @@ struct vfsmount *rpc_get_mount(void)
469 return ERR_PTR(err); 416 return ERR_PTR(err);
470 return rpc_mount; 417 return rpc_mount;
471} 418}
419EXPORT_SYMBOL_GPL(rpc_get_mount);
472 420
473void rpc_put_mount(void) 421void rpc_put_mount(void)
474{ 422{
475 simple_release_fs(&rpc_mount, &rpc_mount_count); 423 simple_release_fs(&rpc_mount, &rpc_mount_count);
476} 424}
425EXPORT_SYMBOL_GPL(rpc_put_mount);
477 426
478static int rpc_delete_dentry(struct dentry *dentry) 427static int rpc_delete_dentry(struct dentry *dentry)
479{ 428{
@@ -484,39 +433,8 @@ static const struct dentry_operations rpc_dentry_operations = {
484 .d_delete = rpc_delete_dentry, 433 .d_delete = rpc_delete_dentry,
485}; 434};
486 435
487static int
488rpc_lookup_parent(char *path, struct nameidata *nd)
489{
490 struct vfsmount *mnt;
491
492 if (path[0] == '\0')
493 return -ENOENT;
494
495 mnt = rpc_get_mount();
496 if (IS_ERR(mnt)) {
497 printk(KERN_WARNING "%s: %s failed to mount "
498 "pseudofilesystem \n", __FILE__, __func__);
499 return PTR_ERR(mnt);
500 }
501
502 if (vfs_path_lookup(mnt->mnt_root, mnt, path, LOOKUP_PARENT, nd)) {
503 printk(KERN_WARNING "%s: %s failed to find path %s\n",
504 __FILE__, __func__, path);
505 rpc_put_mount();
506 return -ENOENT;
507 }
508 return 0;
509}
510
511static void
512rpc_release_path(struct nameidata *nd)
513{
514 path_put(&nd->path);
515 rpc_put_mount();
516}
517
518static struct inode * 436static struct inode *
519rpc_get_inode(struct super_block *sb, int mode) 437rpc_get_inode(struct super_block *sb, umode_t mode)
520{ 438{
521 struct inode *inode = new_inode(sb); 439 struct inode *inode = new_inode(sb);
522 if (!inode) 440 if (!inode)
@@ -534,212 +452,274 @@ rpc_get_inode(struct super_block *sb, int mode)
534 return inode; 452 return inode;
535} 453}
536 454
537/* 455static int __rpc_create_common(struct inode *dir, struct dentry *dentry,
538 * FIXME: This probably has races. 456 umode_t mode,
539 */ 457 const struct file_operations *i_fop,
540static void rpc_depopulate(struct dentry *parent, 458 void *private)
541 unsigned long start, unsigned long eof)
542{ 459{
543 struct inode *dir = parent->d_inode; 460 struct inode *inode;
544 struct list_head *pos, *next;
545 struct dentry *dentry, *dvec[10];
546 int n = 0;
547 461
548 mutex_lock_nested(&dir->i_mutex, I_MUTEX_CHILD); 462 BUG_ON(!d_unhashed(dentry));
549repeat: 463 inode = rpc_get_inode(dir->i_sb, mode);
550 spin_lock(&dcache_lock); 464 if (!inode)
551 list_for_each_safe(pos, next, &parent->d_subdirs) { 465 goto out_err;
552 dentry = list_entry(pos, struct dentry, d_u.d_child); 466 inode->i_ino = iunique(dir->i_sb, 100);
553 if (!dentry->d_inode || 467 if (i_fop)
554 dentry->d_inode->i_ino < start || 468 inode->i_fop = i_fop;
555 dentry->d_inode->i_ino >= eof) 469 if (private)
556 continue; 470 rpc_inode_setowner(inode, private);
557 spin_lock(&dentry->d_lock); 471 d_add(dentry, inode);
558 if (!d_unhashed(dentry)) { 472 return 0;
559 dget_locked(dentry); 473out_err:
560 __d_drop(dentry); 474 printk(KERN_WARNING "%s: %s failed to allocate inode for dentry %s\n",
561 spin_unlock(&dentry->d_lock); 475 __FILE__, __func__, dentry->d_name.name);
562 dvec[n++] = dentry; 476 dput(dentry);
563 if (n == ARRAY_SIZE(dvec)) 477 return -ENOMEM;
564 break;
565 } else
566 spin_unlock(&dentry->d_lock);
567 }
568 spin_unlock(&dcache_lock);
569 if (n) {
570 do {
571 dentry = dvec[--n];
572 if (S_ISREG(dentry->d_inode->i_mode))
573 simple_unlink(dir, dentry);
574 else if (S_ISDIR(dentry->d_inode->i_mode))
575 simple_rmdir(dir, dentry);
576 d_delete(dentry);
577 dput(dentry);
578 } while (n);
579 goto repeat;
580 }
581 mutex_unlock(&dir->i_mutex);
582} 478}
583 479
584static int 480static int __rpc_create(struct inode *dir, struct dentry *dentry,
585rpc_populate(struct dentry *parent, 481 umode_t mode,
586 struct rpc_filelist *files, 482 const struct file_operations *i_fop,
587 int start, int eof) 483 void *private)
588{ 484{
589 struct inode *inode, *dir = parent->d_inode; 485 int err;
590 void *private = RPC_I(dir)->private;
591 struct dentry *dentry;
592 int mode, i;
593 486
594 mutex_lock(&dir->i_mutex); 487 err = __rpc_create_common(dir, dentry, S_IFREG | mode, i_fop, private);
595 for (i = start; i < eof; i++) { 488 if (err)
596 dentry = d_alloc_name(parent, files[i].name); 489 return err;
597 if (!dentry) 490 fsnotify_create(dir, dentry);
598 goto out_bad;
599 dentry->d_op = &rpc_dentry_operations;
600 mode = files[i].mode;
601 inode = rpc_get_inode(dir->i_sb, mode);
602 if (!inode) {
603 dput(dentry);
604 goto out_bad;
605 }
606 inode->i_ino = i;
607 if (files[i].i_fop)
608 inode->i_fop = files[i].i_fop;
609 if (private)
610 rpc_inode_setowner(inode, private);
611 if (S_ISDIR(mode))
612 inc_nlink(dir);
613 d_add(dentry, inode);
614 fsnotify_create(dir, dentry);
615 }
616 mutex_unlock(&dir->i_mutex);
617 return 0; 491 return 0;
618out_bad:
619 mutex_unlock(&dir->i_mutex);
620 printk(KERN_WARNING "%s: %s failed to populate directory %s\n",
621 __FILE__, __func__, parent->d_name.name);
622 return -ENOMEM;
623} 492}
624 493
625static int 494static int __rpc_mkdir(struct inode *dir, struct dentry *dentry,
626__rpc_mkdir(struct inode *dir, struct dentry *dentry) 495 umode_t mode,
496 const struct file_operations *i_fop,
497 void *private)
627{ 498{
628 struct inode *inode; 499 int err;
629 500
630 inode = rpc_get_inode(dir->i_sb, S_IFDIR | S_IRUGO | S_IXUGO); 501 err = __rpc_create_common(dir, dentry, S_IFDIR | mode, i_fop, private);
631 if (!inode) 502 if (err)
632 goto out_err; 503 return err;
633 inode->i_ino = iunique(dir->i_sb, 100);
634 d_instantiate(dentry, inode);
635 inc_nlink(dir); 504 inc_nlink(dir);
636 fsnotify_mkdir(dir, dentry); 505 fsnotify_mkdir(dir, dentry);
637 return 0; 506 return 0;
638out_err:
639 printk(KERN_WARNING "%s: %s failed to allocate inode for dentry %s\n",
640 __FILE__, __func__, dentry->d_name.name);
641 return -ENOMEM;
642} 507}
643 508
644static int 509static int __rpc_mkpipe(struct inode *dir, struct dentry *dentry,
645__rpc_rmdir(struct inode *dir, struct dentry *dentry) 510 umode_t mode,
511 const struct file_operations *i_fop,
512 void *private,
513 const struct rpc_pipe_ops *ops,
514 int flags)
646{ 515{
647 int error; 516 struct rpc_inode *rpci;
648 error = simple_rmdir(dir, dentry); 517 int err;
649 if (!error) 518
650 d_delete(dentry); 519 err = __rpc_create_common(dir, dentry, S_IFIFO | mode, i_fop, private);
651 return error; 520 if (err)
521 return err;
522 rpci = RPC_I(dentry->d_inode);
523 rpci->nkern_readwriters = 1;
524 rpci->private = private;
525 rpci->flags = flags;
526 rpci->ops = ops;
527 fsnotify_create(dir, dentry);
528 return 0;
652} 529}
653 530
654static struct dentry * 531static int __rpc_rmdir(struct inode *dir, struct dentry *dentry)
655rpc_lookup_create(struct dentry *parent, const char *name, int len, int exclusive) 532{
533 int ret;
534
535 dget(dentry);
536 ret = simple_rmdir(dir, dentry);
537 d_delete(dentry);
538 dput(dentry);
539 return ret;
540}
541
542static int __rpc_unlink(struct inode *dir, struct dentry *dentry)
543{
544 int ret;
545
546 dget(dentry);
547 ret = simple_unlink(dir, dentry);
548 d_delete(dentry);
549 dput(dentry);
550 return ret;
551}
552
553static int __rpc_rmpipe(struct inode *dir, struct dentry *dentry)
554{
555 struct inode *inode = dentry->d_inode;
556 struct rpc_inode *rpci = RPC_I(inode);
557
558 rpci->nkern_readwriters--;
559 if (rpci->nkern_readwriters != 0)
560 return 0;
561 rpc_close_pipes(inode);
562 return __rpc_unlink(dir, dentry);
563}
564
565static struct dentry *__rpc_lookup_create(struct dentry *parent,
566 struct qstr *name)
656{ 567{
657 struct inode *dir = parent->d_inode;
658 struct dentry *dentry; 568 struct dentry *dentry;
659 569
660 mutex_lock_nested(&dir->i_mutex, I_MUTEX_PARENT); 570 dentry = d_lookup(parent, name);
661 dentry = lookup_one_len(name, parent, len); 571 if (!dentry) {
662 if (IS_ERR(dentry)) 572 dentry = d_alloc(parent, name);
663 goto out_err; 573 if (!dentry) {
574 dentry = ERR_PTR(-ENOMEM);
575 goto out_err;
576 }
577 }
664 if (!dentry->d_inode) 578 if (!dentry->d_inode)
665 dentry->d_op = &rpc_dentry_operations; 579 dentry->d_op = &rpc_dentry_operations;
666 else if (exclusive) {
667 dput(dentry);
668 dentry = ERR_PTR(-EEXIST);
669 goto out_err;
670 }
671 return dentry;
672out_err: 580out_err:
673 mutex_unlock(&dir->i_mutex);
674 return dentry; 581 return dentry;
675} 582}
676 583
677static struct dentry * 584static struct dentry *__rpc_lookup_create_exclusive(struct dentry *parent,
678rpc_lookup_negative(char *path, struct nameidata *nd) 585 struct qstr *name)
679{ 586{
680 struct dentry *dentry; 587 struct dentry *dentry;
681 int error;
682 588
683 if ((error = rpc_lookup_parent(path, nd)) != 0) 589 dentry = __rpc_lookup_create(parent, name);
684 return ERR_PTR(error); 590 if (dentry->d_inode == NULL)
685 dentry = rpc_lookup_create(nd->path.dentry, nd->last.name, nd->last.len, 591 return dentry;
686 1); 592 dput(dentry);
687 if (IS_ERR(dentry)) 593 return ERR_PTR(-EEXIST);
688 rpc_release_path(nd);
689 return dentry;
690} 594}
691 595
692/** 596/*
693 * rpc_mkdir - Create a new directory in rpc_pipefs 597 * FIXME: This probably has races.
694 * @path: path from the rpc_pipefs root to the new directory
695 * @rpc_client: rpc client to associate with this directory
696 *
697 * This creates a directory at the given @path associated with
698 * @rpc_clnt, which will contain a file named "info" with some basic
699 * information about the client, together with any "pipes" that may
700 * later be created using rpc_mkpipe().
701 */ 598 */
702struct dentry * 599static void __rpc_depopulate(struct dentry *parent,
703rpc_mkdir(char *path, struct rpc_clnt *rpc_client) 600 const struct rpc_filelist *files,
601 int start, int eof)
704{ 602{
705 struct nameidata nd; 603 struct inode *dir = parent->d_inode;
706 struct dentry *dentry; 604 struct dentry *dentry;
707 struct inode *dir; 605 struct qstr name;
606 int i;
607
608 for (i = start; i < eof; i++) {
609 name.name = files[i].name;
610 name.len = strlen(files[i].name);
611 name.hash = full_name_hash(name.name, name.len);
612 dentry = d_lookup(parent, &name);
613
614 if (dentry == NULL)
615 continue;
616 if (dentry->d_inode == NULL)
617 goto next;
618 switch (dentry->d_inode->i_mode & S_IFMT) {
619 default:
620 BUG();
621 case S_IFREG:
622 __rpc_unlink(dir, dentry);
623 break;
624 case S_IFDIR:
625 __rpc_rmdir(dir, dentry);
626 }
627next:
628 dput(dentry);
629 }
630}
631
632static void rpc_depopulate(struct dentry *parent,
633 const struct rpc_filelist *files,
634 int start, int eof)
635{
636 struct inode *dir = parent->d_inode;
637
638 mutex_lock_nested(&dir->i_mutex, I_MUTEX_CHILD);
639 __rpc_depopulate(parent, files, start, eof);
640 mutex_unlock(&dir->i_mutex);
641}
642
643static int rpc_populate(struct dentry *parent,
644 const struct rpc_filelist *files,
645 int start, int eof,
646 void *private)
647{
648 struct inode *dir = parent->d_inode;
649 struct dentry *dentry;
650 int i, err;
651
652 mutex_lock(&dir->i_mutex);
653 for (i = start; i < eof; i++) {
654 struct qstr q;
655
656 q.name = files[i].name;
657 q.len = strlen(files[i].name);
658 q.hash = full_name_hash(q.name, q.len);
659 dentry = __rpc_lookup_create_exclusive(parent, &q);
660 err = PTR_ERR(dentry);
661 if (IS_ERR(dentry))
662 goto out_bad;
663 switch (files[i].mode & S_IFMT) {
664 default:
665 BUG();
666 case S_IFREG:
667 err = __rpc_create(dir, dentry,
668 files[i].mode,
669 files[i].i_fop,
670 private);
671 break;
672 case S_IFDIR:
673 err = __rpc_mkdir(dir, dentry,
674 files[i].mode,
675 NULL,
676 private);
677 }
678 if (err != 0)
679 goto out_bad;
680 }
681 mutex_unlock(&dir->i_mutex);
682 return 0;
683out_bad:
684 __rpc_depopulate(parent, files, start, eof);
685 mutex_unlock(&dir->i_mutex);
686 printk(KERN_WARNING "%s: %s failed to populate directory %s\n",
687 __FILE__, __func__, parent->d_name.name);
688 return err;
689}
690
691static struct dentry *rpc_mkdir_populate(struct dentry *parent,
692 struct qstr *name, umode_t mode, void *private,
693 int (*populate)(struct dentry *, void *), void *args_populate)
694{
695 struct dentry *dentry;
696 struct inode *dir = parent->d_inode;
708 int error; 697 int error;
709 698
710 dentry = rpc_lookup_negative(path, &nd); 699 mutex_lock_nested(&dir->i_mutex, I_MUTEX_PARENT);
700 dentry = __rpc_lookup_create_exclusive(parent, name);
711 if (IS_ERR(dentry)) 701 if (IS_ERR(dentry))
712 return dentry; 702 goto out;
713 dir = nd.path.dentry->d_inode; 703 error = __rpc_mkdir(dir, dentry, mode, NULL, private);
714 if ((error = __rpc_mkdir(dir, dentry)) != 0) 704 if (error != 0)
715 goto err_dput; 705 goto out_err;
716 RPC_I(dentry->d_inode)->private = rpc_client; 706 if (populate != NULL) {
717 error = rpc_populate(dentry, authfiles, 707 error = populate(dentry, args_populate);
718 RPCAUTH_info, RPCAUTH_EOF); 708 if (error)
719 if (error) 709 goto err_rmdir;
720 goto err_depopulate; 710 }
721 dget(dentry);
722out: 711out:
723 mutex_unlock(&dir->i_mutex); 712 mutex_unlock(&dir->i_mutex);
724 rpc_release_path(&nd);
725 return dentry; 713 return dentry;
726err_depopulate: 714err_rmdir:
727 rpc_depopulate(dentry, RPCAUTH_info, RPCAUTH_EOF);
728 __rpc_rmdir(dir, dentry); 715 __rpc_rmdir(dir, dentry);
729err_dput: 716out_err:
730 dput(dentry);
731 printk(KERN_WARNING "%s: %s() failed to create directory %s (errno = %d)\n",
732 __FILE__, __func__, path, error);
733 dentry = ERR_PTR(error); 717 dentry = ERR_PTR(error);
734 goto out; 718 goto out;
735} 719}
736 720
737/** 721static int rpc_rmdir_depopulate(struct dentry *dentry,
738 * rpc_rmdir - Remove a directory created with rpc_mkdir() 722 void (*depopulate)(struct dentry *))
739 * @dentry: directory to remove
740 */
741int
742rpc_rmdir(struct dentry *dentry)
743{ 723{
744 struct dentry *parent; 724 struct dentry *parent;
745 struct inode *dir; 725 struct inode *dir;
@@ -748,9 +728,9 @@ rpc_rmdir(struct dentry *dentry)
748 parent = dget_parent(dentry); 728 parent = dget_parent(dentry);
749 dir = parent->d_inode; 729 dir = parent->d_inode;
750 mutex_lock_nested(&dir->i_mutex, I_MUTEX_PARENT); 730 mutex_lock_nested(&dir->i_mutex, I_MUTEX_PARENT);
751 rpc_depopulate(dentry, RPCAUTH_info, RPCAUTH_EOF); 731 if (depopulate != NULL)
732 depopulate(dentry);
752 error = __rpc_rmdir(dir, dentry); 733 error = __rpc_rmdir(dir, dentry);
753 dput(dentry);
754 mutex_unlock(&dir->i_mutex); 734 mutex_unlock(&dir->i_mutex);
755 dput(parent); 735 dput(parent);
756 return error; 736 return error;
@@ -776,50 +756,54 @@ rpc_rmdir(struct dentry *dentry)
776 * The @private argument passed here will be available to all these methods 756 * The @private argument passed here will be available to all these methods
777 * from the file pointer, via RPC_I(file->f_dentry->d_inode)->private. 757 * from the file pointer, via RPC_I(file->f_dentry->d_inode)->private.
778 */ 758 */
779struct dentry * 759struct dentry *rpc_mkpipe(struct dentry *parent, const char *name,
780rpc_mkpipe(struct dentry *parent, const char *name, void *private, struct rpc_pipe_ops *ops, int flags) 760 void *private, const struct rpc_pipe_ops *ops,
761 int flags)
781{ 762{
782 struct dentry *dentry; 763 struct dentry *dentry;
783 struct inode *dir, *inode; 764 struct inode *dir = parent->d_inode;
784 struct rpc_inode *rpci; 765 umode_t umode = S_IFIFO | S_IRUSR | S_IWUSR;
766 struct qstr q;
767 int err;
768
769 if (ops->upcall == NULL)
770 umode &= ~S_IRUGO;
771 if (ops->downcall == NULL)
772 umode &= ~S_IWUGO;
773
774 q.name = name;
775 q.len = strlen(name);
776 q.hash = full_name_hash(q.name, q.len),
785 777
786 dentry = rpc_lookup_create(parent, name, strlen(name), 0); 778 mutex_lock_nested(&dir->i_mutex, I_MUTEX_PARENT);
779 dentry = __rpc_lookup_create(parent, &q);
787 if (IS_ERR(dentry)) 780 if (IS_ERR(dentry))
788 return dentry; 781 goto out;
789 dir = parent->d_inode;
790 if (dentry->d_inode) { 782 if (dentry->d_inode) {
791 rpci = RPC_I(dentry->d_inode); 783 struct rpc_inode *rpci = RPC_I(dentry->d_inode);
792 if (rpci->private != private || 784 if (rpci->private != private ||
793 rpci->ops != ops || 785 rpci->ops != ops ||
794 rpci->flags != flags) { 786 rpci->flags != flags) {
795 dput (dentry); 787 dput (dentry);
796 dentry = ERR_PTR(-EBUSY); 788 err = -EBUSY;
789 goto out_err;
797 } 790 }
798 rpci->nkern_readwriters++; 791 rpci->nkern_readwriters++;
799 goto out; 792 goto out;
800 } 793 }
801 inode = rpc_get_inode(dir->i_sb, S_IFIFO | S_IRUSR | S_IWUSR); 794
802 if (!inode) 795 err = __rpc_mkpipe(dir, dentry, umode, &rpc_pipe_fops,
803 goto err_dput; 796 private, ops, flags);
804 inode->i_ino = iunique(dir->i_sb, 100); 797 if (err)
805 inode->i_fop = &rpc_pipe_fops; 798 goto out_err;
806 d_instantiate(dentry, inode);
807 rpci = RPC_I(inode);
808 rpci->private = private;
809 rpci->flags = flags;
810 rpci->ops = ops;
811 rpci->nkern_readwriters = 1;
812 fsnotify_create(dir, dentry);
813 dget(dentry);
814out: 799out:
815 mutex_unlock(&dir->i_mutex); 800 mutex_unlock(&dir->i_mutex);
816 return dentry; 801 return dentry;
817err_dput: 802out_err:
818 dput(dentry); 803 dentry = ERR_PTR(err);
819 dentry = ERR_PTR(-ENOMEM);
820 printk(KERN_WARNING "%s: %s() failed to create pipe %s/%s (errno = %d)\n", 804 printk(KERN_WARNING "%s: %s() failed to create pipe %s/%s (errno = %d)\n",
821 __FILE__, __func__, parent->d_name.name, name, 805 __FILE__, __func__, parent->d_name.name, name,
822 -ENOMEM); 806 err);
823 goto out; 807 goto out;
824} 808}
825EXPORT_SYMBOL_GPL(rpc_mkpipe); 809EXPORT_SYMBOL_GPL(rpc_mkpipe);
@@ -842,19 +826,107 @@ rpc_unlink(struct dentry *dentry)
842 parent = dget_parent(dentry); 826 parent = dget_parent(dentry);
843 dir = parent->d_inode; 827 dir = parent->d_inode;
844 mutex_lock_nested(&dir->i_mutex, I_MUTEX_PARENT); 828 mutex_lock_nested(&dir->i_mutex, I_MUTEX_PARENT);
845 if (--RPC_I(dentry->d_inode)->nkern_readwriters == 0) { 829 error = __rpc_rmpipe(dir, dentry);
846 rpc_close_pipes(dentry->d_inode);
847 error = simple_unlink(dir, dentry);
848 if (!error)
849 d_delete(dentry);
850 }
851 dput(dentry);
852 mutex_unlock(&dir->i_mutex); 830 mutex_unlock(&dir->i_mutex);
853 dput(parent); 831 dput(parent);
854 return error; 832 return error;
855} 833}
856EXPORT_SYMBOL_GPL(rpc_unlink); 834EXPORT_SYMBOL_GPL(rpc_unlink);
857 835
836enum {
837 RPCAUTH_info,
838 RPCAUTH_EOF
839};
840
841static const struct rpc_filelist authfiles[] = {
842 [RPCAUTH_info] = {
843 .name = "info",
844 .i_fop = &rpc_info_operations,
845 .mode = S_IFREG | S_IRUSR,
846 },
847};
848
849static int rpc_clntdir_populate(struct dentry *dentry, void *private)
850{
851 return rpc_populate(dentry,
852 authfiles, RPCAUTH_info, RPCAUTH_EOF,
853 private);
854}
855
856static void rpc_clntdir_depopulate(struct dentry *dentry)
857{
858 rpc_depopulate(dentry, authfiles, RPCAUTH_info, RPCAUTH_EOF);
859}
860
861/**
862 * rpc_create_client_dir - Create a new rpc_client directory in rpc_pipefs
863 * @path: path from the rpc_pipefs root to the new directory
864 * @rpc_client: rpc client to associate with this directory
865 *
866 * This creates a directory at the given @path associated with
867 * @rpc_clnt, which will contain a file named "info" with some basic
868 * information about the client, together with any "pipes" that may
869 * later be created using rpc_mkpipe().
870 */
871struct dentry *rpc_create_client_dir(struct dentry *dentry,
872 struct qstr *name,
873 struct rpc_clnt *rpc_client)
874{
875 return rpc_mkdir_populate(dentry, name, S_IRUGO | S_IXUGO, NULL,
876 rpc_clntdir_populate, rpc_client);
877}
878
879/**
880 * rpc_remove_client_dir - Remove a directory created with rpc_create_client_dir()
881 * @dentry: directory to remove
882 */
883int rpc_remove_client_dir(struct dentry *dentry)
884{
885 return rpc_rmdir_depopulate(dentry, rpc_clntdir_depopulate);
886}
887
888static const struct rpc_filelist cache_pipefs_files[3] = {
889 [0] = {
890 .name = "channel",
891 .i_fop = &cache_file_operations_pipefs,
892 .mode = S_IFREG|S_IRUSR|S_IWUSR,
893 },
894 [1] = {
895 .name = "content",
896 .i_fop = &content_file_operations_pipefs,
897 .mode = S_IFREG|S_IRUSR,
898 },
899 [2] = {
900 .name = "flush",
901 .i_fop = &cache_flush_operations_pipefs,
902 .mode = S_IFREG|S_IRUSR|S_IWUSR,
903 },
904};
905
906static int rpc_cachedir_populate(struct dentry *dentry, void *private)
907{
908 return rpc_populate(dentry,
909 cache_pipefs_files, 0, 3,
910 private);
911}
912
913static void rpc_cachedir_depopulate(struct dentry *dentry)
914{
915 rpc_depopulate(dentry, cache_pipefs_files, 0, 3);
916}
917
918struct dentry *rpc_create_cache_dir(struct dentry *parent, struct qstr *name,
919 mode_t umode, struct cache_detail *cd)
920{
921 return rpc_mkdir_populate(parent, name, umode, NULL,
922 rpc_cachedir_populate, cd);
923}
924
925void rpc_remove_cache_dir(struct dentry *dentry)
926{
927 rpc_rmdir_depopulate(dentry, rpc_cachedir_depopulate);
928}
929
858/* 930/*
859 * populate the filesystem 931 * populate the filesystem
860 */ 932 */
@@ -866,6 +938,51 @@ static struct super_operations s_ops = {
866 938
867#define RPCAUTH_GSSMAGIC 0x67596969 939#define RPCAUTH_GSSMAGIC 0x67596969
868 940
941/*
942 * We have a single directory with 1 node in it.
943 */
944enum {
945 RPCAUTH_lockd,
946 RPCAUTH_mount,
947 RPCAUTH_nfs,
948 RPCAUTH_portmap,
949 RPCAUTH_statd,
950 RPCAUTH_nfsd4_cb,
951 RPCAUTH_cache,
952 RPCAUTH_RootEOF
953};
954
955static const struct rpc_filelist files[] = {
956 [RPCAUTH_lockd] = {
957 .name = "lockd",
958 .mode = S_IFDIR | S_IRUGO | S_IXUGO,
959 },
960 [RPCAUTH_mount] = {
961 .name = "mount",
962 .mode = S_IFDIR | S_IRUGO | S_IXUGO,
963 },
964 [RPCAUTH_nfs] = {
965 .name = "nfs",
966 .mode = S_IFDIR | S_IRUGO | S_IXUGO,
967 },
968 [RPCAUTH_portmap] = {
969 .name = "portmap",
970 .mode = S_IFDIR | S_IRUGO | S_IXUGO,
971 },
972 [RPCAUTH_statd] = {
973 .name = "statd",
974 .mode = S_IFDIR | S_IRUGO | S_IXUGO,
975 },
976 [RPCAUTH_nfsd4_cb] = {
977 .name = "nfsd4_cb",
978 .mode = S_IFDIR | S_IRUGO | S_IXUGO,
979 },
980 [RPCAUTH_cache] = {
981 .name = "cache",
982 .mode = S_IFDIR | S_IRUGO | S_IXUGO,
983 },
984};
985
869static int 986static int
870rpc_fill_super(struct super_block *sb, void *data, int silent) 987rpc_fill_super(struct super_block *sb, void *data, int silent)
871{ 988{
@@ -886,7 +1003,7 @@ rpc_fill_super(struct super_block *sb, void *data, int silent)
886 iput(inode); 1003 iput(inode);
887 return -ENOMEM; 1004 return -ENOMEM;
888 } 1005 }
889 if (rpc_populate(root, files, RPCAUTH_Root + 1, RPCAUTH_RootEOF)) 1006 if (rpc_populate(root, files, RPCAUTH_lockd, RPCAUTH_RootEOF, NULL))
890 goto out; 1007 goto out;
891 sb->s_root = root; 1008 sb->s_root = root;
892 return 0; 1009 return 0;
diff --git a/net/sunrpc/rpcb_clnt.c b/net/sunrpc/rpcb_clnt.c
index beee6da33035..830faf4d9997 100644
--- a/net/sunrpc/rpcb_clnt.c
+++ b/net/sunrpc/rpcb_clnt.c
@@ -75,6 +75,37 @@ enum {
75#define RPCB_OWNER_STRING "0" 75#define RPCB_OWNER_STRING "0"
76#define RPCB_MAXOWNERLEN sizeof(RPCB_OWNER_STRING) 76#define RPCB_MAXOWNERLEN sizeof(RPCB_OWNER_STRING)
77 77
78/*
79 * XDR data type sizes
80 */
81#define RPCB_program_sz (1)
82#define RPCB_version_sz (1)
83#define RPCB_protocol_sz (1)
84#define RPCB_port_sz (1)
85#define RPCB_boolean_sz (1)
86
87#define RPCB_netid_sz (1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN))
88#define RPCB_addr_sz (1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
89#define RPCB_ownerstring_sz (1 + XDR_QUADLEN(RPCB_MAXOWNERLEN))
90
91/*
92 * XDR argument and result sizes
93 */
94#define RPCB_mappingargs_sz (RPCB_program_sz + RPCB_version_sz + \
95 RPCB_protocol_sz + RPCB_port_sz)
96#define RPCB_getaddrargs_sz (RPCB_program_sz + RPCB_version_sz + \
97 RPCB_netid_sz + RPCB_addr_sz + \
98 RPCB_ownerstring_sz)
99
100#define RPCB_getportres_sz RPCB_port_sz
101#define RPCB_setres_sz RPCB_boolean_sz
102
103/*
104 * Note that RFC 1833 does not put any size restrictions on the
105 * address string returned by the remote rpcbind database.
106 */
107#define RPCB_getaddrres_sz RPCB_addr_sz
108
78static void rpcb_getport_done(struct rpc_task *, void *); 109static void rpcb_getport_done(struct rpc_task *, void *);
79static void rpcb_map_release(void *data); 110static void rpcb_map_release(void *data);
80static struct rpc_program rpcb_program; 111static struct rpc_program rpcb_program;
@@ -122,6 +153,7 @@ static void rpcb_map_release(void *data)
122 153
123 rpcb_wake_rpcbind_waiters(map->r_xprt, map->r_status); 154 rpcb_wake_rpcbind_waiters(map->r_xprt, map->r_status);
124 xprt_put(map->r_xprt); 155 xprt_put(map->r_xprt);
156 kfree(map->r_addr);
125 kfree(map); 157 kfree(map);
126} 158}
127 159
@@ -268,12 +300,9 @@ static int rpcb_register_inet4(const struct sockaddr *sap,
268 const struct sockaddr_in *sin = (const struct sockaddr_in *)sap; 300 const struct sockaddr_in *sin = (const struct sockaddr_in *)sap;
269 struct rpcbind_args *map = msg->rpc_argp; 301 struct rpcbind_args *map = msg->rpc_argp;
270 unsigned short port = ntohs(sin->sin_port); 302 unsigned short port = ntohs(sin->sin_port);
271 char buf[32]; 303 int result;
272 304
273 /* Construct AF_INET universal address */ 305 map->r_addr = rpc_sockaddr2uaddr(sap);
274 snprintf(buf, sizeof(buf), "%pI4.%u.%u",
275 &sin->sin_addr.s_addr, port >> 8, port & 0xff);
276 map->r_addr = buf;
277 306
278 dprintk("RPC: %sregistering [%u, %u, %s, '%s'] with " 307 dprintk("RPC: %sregistering [%u, %u, %s, '%s'] with "
279 "local rpcbind\n", (port ? "" : "un"), 308 "local rpcbind\n", (port ? "" : "un"),
@@ -284,7 +313,9 @@ static int rpcb_register_inet4(const struct sockaddr *sap,
284 if (port) 313 if (port)
285 msg->rpc_proc = &rpcb_procedures4[RPCBPROC_SET]; 314 msg->rpc_proc = &rpcb_procedures4[RPCBPROC_SET];
286 315
287 return rpcb_register_call(RPCBVERS_4, msg); 316 result = rpcb_register_call(RPCBVERS_4, msg);
317 kfree(map->r_addr);
318 return result;
288} 319}
289 320
290/* 321/*
@@ -296,16 +327,9 @@ static int rpcb_register_inet6(const struct sockaddr *sap,
296 const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)sap; 327 const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)sap;
297 struct rpcbind_args *map = msg->rpc_argp; 328 struct rpcbind_args *map = msg->rpc_argp;
298 unsigned short port = ntohs(sin6->sin6_port); 329 unsigned short port = ntohs(sin6->sin6_port);
299 char buf[64]; 330 int result;
300 331
301 /* Construct AF_INET6 universal address */ 332 map->r_addr = rpc_sockaddr2uaddr(sap);
302 if (ipv6_addr_any(&sin6->sin6_addr))
303 snprintf(buf, sizeof(buf), "::.%u.%u",
304 port >> 8, port & 0xff);
305 else
306 snprintf(buf, sizeof(buf), "%pI6.%u.%u",
307 &sin6->sin6_addr, port >> 8, port & 0xff);
308 map->r_addr = buf;
309 333
310 dprintk("RPC: %sregistering [%u, %u, %s, '%s'] with " 334 dprintk("RPC: %sregistering [%u, %u, %s, '%s'] with "
311 "local rpcbind\n", (port ? "" : "un"), 335 "local rpcbind\n", (port ? "" : "un"),
@@ -316,7 +340,9 @@ static int rpcb_register_inet6(const struct sockaddr *sap,
316 if (port) 340 if (port)
317 msg->rpc_proc = &rpcb_procedures4[RPCBPROC_SET]; 341 msg->rpc_proc = &rpcb_procedures4[RPCBPROC_SET];
318 342
319 return rpcb_register_call(RPCBVERS_4, msg); 343 result = rpcb_register_call(RPCBVERS_4, msg);
344 kfree(map->r_addr);
345 return result;
320} 346}
321 347
322static int rpcb_unregister_all_protofamilies(struct rpc_message *msg) 348static int rpcb_unregister_all_protofamilies(struct rpc_message *msg)
@@ -428,7 +454,7 @@ int rpcb_getport_sync(struct sockaddr_in *sin, u32 prog, u32 vers, int prot)
428 struct rpc_message msg = { 454 struct rpc_message msg = {
429 .rpc_proc = &rpcb_procedures2[RPCBPROC_GETPORT], 455 .rpc_proc = &rpcb_procedures2[RPCBPROC_GETPORT],
430 .rpc_argp = &map, 456 .rpc_argp = &map,
431 .rpc_resp = &map.r_port, 457 .rpc_resp = &map,
432 }; 458 };
433 struct rpc_clnt *rpcb_clnt; 459 struct rpc_clnt *rpcb_clnt;
434 int status; 460 int status;
@@ -458,7 +484,7 @@ static struct rpc_task *rpcb_call_async(struct rpc_clnt *rpcb_clnt, struct rpcbi
458 struct rpc_message msg = { 484 struct rpc_message msg = {
459 .rpc_proc = proc, 485 .rpc_proc = proc,
460 .rpc_argp = map, 486 .rpc_argp = map,
461 .rpc_resp = &map->r_port, 487 .rpc_resp = map,
462 }; 488 };
463 struct rpc_task_setup task_setup_data = { 489 struct rpc_task_setup task_setup_data = {
464 .rpc_client = rpcb_clnt, 490 .rpc_client = rpcb_clnt,
@@ -539,6 +565,7 @@ void rpcb_getport_async(struct rpc_task *task)
539 goto bailout_nofree; 565 goto bailout_nofree;
540 } 566 }
541 567
568 /* Parent transport's destination address */
542 salen = rpc_peeraddr(clnt, sap, sizeof(addr)); 569 salen = rpc_peeraddr(clnt, sap, sizeof(addr));
543 570
544 /* Don't ever use rpcbind v2 for AF_INET6 requests */ 571 /* Don't ever use rpcbind v2 for AF_INET6 requests */
@@ -589,11 +616,22 @@ void rpcb_getport_async(struct rpc_task *task)
589 map->r_prot = xprt->prot; 616 map->r_prot = xprt->prot;
590 map->r_port = 0; 617 map->r_port = 0;
591 map->r_xprt = xprt_get(xprt); 618 map->r_xprt = xprt_get(xprt);
592 map->r_netid = rpc_peeraddr2str(clnt, RPC_DISPLAY_NETID);
593 map->r_addr = rpc_peeraddr2str(rpcb_clnt, RPC_DISPLAY_UNIVERSAL_ADDR);
594 map->r_owner = "";
595 map->r_status = -EIO; 619 map->r_status = -EIO;
596 620
621 switch (bind_version) {
622 case RPCBVERS_4:
623 case RPCBVERS_3:
624 map->r_netid = rpc_peeraddr2str(clnt, RPC_DISPLAY_NETID);
625 map->r_addr = rpc_sockaddr2uaddr(sap);
626 map->r_owner = "";
627 break;
628 case RPCBVERS_2:
629 map->r_addr = NULL;
630 break;
631 default:
632 BUG();
633 }
634
597 child = rpcb_call_async(rpcb_clnt, map, proc); 635 child = rpcb_call_async(rpcb_clnt, map, proc);
598 rpc_release_client(rpcb_clnt); 636 rpc_release_client(rpcb_clnt);
599 if (IS_ERR(child)) { 637 if (IS_ERR(child)) {
@@ -656,176 +694,278 @@ static void rpcb_getport_done(struct rpc_task *child, void *data)
656 * XDR functions for rpcbind 694 * XDR functions for rpcbind
657 */ 695 */
658 696
659static int rpcb_encode_mapping(struct rpc_rqst *req, __be32 *p, 697static int rpcb_enc_mapping(struct rpc_rqst *req, __be32 *p,
660 struct rpcbind_args *rpcb) 698 const struct rpcbind_args *rpcb)
661{ 699{
662 dprintk("RPC: encoding rpcb request (%u, %u, %d, %u)\n", 700 struct rpc_task *task = req->rq_task;
701 struct xdr_stream xdr;
702
703 dprintk("RPC: %5u encoding PMAP_%s call (%u, %u, %d, %u)\n",
704 task->tk_pid, task->tk_msg.rpc_proc->p_name,
663 rpcb->r_prog, rpcb->r_vers, rpcb->r_prot, rpcb->r_port); 705 rpcb->r_prog, rpcb->r_vers, rpcb->r_prot, rpcb->r_port);
706
707 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
708
709 p = xdr_reserve_space(&xdr, sizeof(__be32) * RPCB_mappingargs_sz);
710 if (unlikely(p == NULL))
711 return -EIO;
712
664 *p++ = htonl(rpcb->r_prog); 713 *p++ = htonl(rpcb->r_prog);
665 *p++ = htonl(rpcb->r_vers); 714 *p++ = htonl(rpcb->r_vers);
666 *p++ = htonl(rpcb->r_prot); 715 *p++ = htonl(rpcb->r_prot);
667 *p++ = htonl(rpcb->r_port); 716 *p = htonl(rpcb->r_port);
668 717
669 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
670 return 0; 718 return 0;
671} 719}
672 720
673static int rpcb_decode_getport(struct rpc_rqst *req, __be32 *p, 721static int rpcb_dec_getport(struct rpc_rqst *req, __be32 *p,
674 unsigned short *portp) 722 struct rpcbind_args *rpcb)
675{ 723{
676 *portp = (unsigned short) ntohl(*p++); 724 struct rpc_task *task = req->rq_task;
677 dprintk("RPC: rpcb getport result: %u\n", 725 struct xdr_stream xdr;
678 *portp); 726 unsigned long port;
727
728 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
729
730 rpcb->r_port = 0;
731
732 p = xdr_inline_decode(&xdr, sizeof(__be32));
733 if (unlikely(p == NULL))
734 return -EIO;
735
736 port = ntohl(*p);
737 dprintk("RPC: %5u PMAP_%s result: %lu\n", task->tk_pid,
738 task->tk_msg.rpc_proc->p_name, port);
739 if (unlikely(port > USHORT_MAX))
740 return -EIO;
741
742 rpcb->r_port = port;
679 return 0; 743 return 0;
680} 744}
681 745
682static int rpcb_decode_set(struct rpc_rqst *req, __be32 *p, 746static int rpcb_dec_set(struct rpc_rqst *req, __be32 *p,
683 unsigned int *boolp) 747 unsigned int *boolp)
684{ 748{
685 *boolp = (unsigned int) ntohl(*p++); 749 struct rpc_task *task = req->rq_task;
686 dprintk("RPC: rpcb set/unset call %s\n", 750 struct xdr_stream xdr;
751
752 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
753
754 p = xdr_inline_decode(&xdr, sizeof(__be32));
755 if (unlikely(p == NULL))
756 return -EIO;
757
758 *boolp = 0;
759 if (*p)
760 *boolp = 1;
761
762 dprintk("RPC: %5u RPCB_%s call %s\n",
763 task->tk_pid, task->tk_msg.rpc_proc->p_name,
687 (*boolp ? "succeeded" : "failed")); 764 (*boolp ? "succeeded" : "failed"));
688 return 0; 765 return 0;
689} 766}
690 767
691static int rpcb_encode_getaddr(struct rpc_rqst *req, __be32 *p, 768static int encode_rpcb_string(struct xdr_stream *xdr, const char *string,
692 struct rpcbind_args *rpcb) 769 const u32 maxstrlen)
693{ 770{
694 dprintk("RPC: encoding rpcb request (%u, %u, %s)\n", 771 u32 len;
695 rpcb->r_prog, rpcb->r_vers, rpcb->r_addr); 772 __be32 *p;
696 *p++ = htonl(rpcb->r_prog);
697 *p++ = htonl(rpcb->r_vers);
698 773
699 p = xdr_encode_string(p, rpcb->r_netid); 774 if (unlikely(string == NULL))
700 p = xdr_encode_string(p, rpcb->r_addr); 775 return -EIO;
701 p = xdr_encode_string(p, rpcb->r_owner); 776 len = strlen(string);
777 if (unlikely(len > maxstrlen))
778 return -EIO;
702 779
703 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); 780 p = xdr_reserve_space(xdr, sizeof(__be32) + len);
781 if (unlikely(p == NULL))
782 return -EIO;
783 xdr_encode_opaque(p, string, len);
704 784
705 return 0; 785 return 0;
706} 786}
707 787
708static int rpcb_decode_getaddr(struct rpc_rqst *req, __be32 *p, 788static int rpcb_enc_getaddr(struct rpc_rqst *req, __be32 *p,
709 unsigned short *portp) 789 const struct rpcbind_args *rpcb)
710{ 790{
711 char *addr; 791 struct rpc_task *task = req->rq_task;
712 u32 addr_len; 792 struct xdr_stream xdr;
713 int c, i, f, first, val;
714 793
715 *portp = 0; 794 dprintk("RPC: %5u encoding RPCB_%s call (%u, %u, '%s', '%s')\n",
716 addr_len = ntohl(*p++); 795 task->tk_pid, task->tk_msg.rpc_proc->p_name,
796 rpcb->r_prog, rpcb->r_vers,
797 rpcb->r_netid, rpcb->r_addr);
717 798
718 if (addr_len == 0) { 799 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
719 dprintk("RPC: rpcb_decode_getaddr: "
720 "service is not registered\n");
721 return 0;
722 }
723 800
724 /* 801 p = xdr_reserve_space(&xdr,
725 * Simple sanity check. 802 sizeof(__be32) * (RPCB_program_sz + RPCB_version_sz));
726 */ 803 if (unlikely(p == NULL))
727 if (addr_len > RPCBIND_MAXUADDRLEN) 804 return -EIO;
728 goto out_err; 805 *p++ = htonl(rpcb->r_prog);
729 806 *p = htonl(rpcb->r_vers);
730 /*
731 * Start at the end and walk backwards until the first dot
732 * is encountered. When the second dot is found, we have
733 * both parts of the port number.
734 */
735 addr = (char *)p;
736 val = 0;
737 first = 1;
738 f = 1;
739 for (i = addr_len - 1; i > 0; i--) {
740 c = addr[i];
741 if (c >= '0' && c <= '9') {
742 val += (c - '0') * f;
743 f *= 10;
744 } else if (c == '.') {
745 if (first) {
746 *portp = val;
747 val = first = 0;
748 f = 1;
749 } else {
750 *portp |= (val << 8);
751 break;
752 }
753 }
754 }
755 807
756 /* 808 if (encode_rpcb_string(&xdr, rpcb->r_netid, RPCBIND_MAXNETIDLEN))
757 * Simple sanity check. If we never saw a dot in the reply, 809 return -EIO;
758 * then this was probably just garbage. 810 if (encode_rpcb_string(&xdr, rpcb->r_addr, RPCBIND_MAXUADDRLEN))
759 */ 811 return -EIO;
760 if (first) 812 if (encode_rpcb_string(&xdr, rpcb->r_owner, RPCB_MAXOWNERLEN))
761 goto out_err; 813 return -EIO;
762 814
763 dprintk("RPC: rpcb_decode_getaddr port=%u\n", *portp);
764 return 0; 815 return 0;
765
766out_err:
767 dprintk("RPC: rpcbind server returned malformed reply\n");
768 return -EIO;
769} 816}
770 817
771#define RPCB_program_sz (1u) 818static int rpcb_dec_getaddr(struct rpc_rqst *req, __be32 *p,
772#define RPCB_version_sz (1u) 819 struct rpcbind_args *rpcb)
773#define RPCB_protocol_sz (1u) 820{
774#define RPCB_port_sz (1u) 821 struct sockaddr_storage address;
775#define RPCB_boolean_sz (1u) 822 struct sockaddr *sap = (struct sockaddr *)&address;
823 struct rpc_task *task = req->rq_task;
824 struct xdr_stream xdr;
825 u32 len;
776 826
777#define RPCB_netid_sz (1+XDR_QUADLEN(RPCBIND_MAXNETIDLEN)) 827 rpcb->r_port = 0;
778#define RPCB_addr_sz (1+XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
779#define RPCB_ownerstring_sz (1+XDR_QUADLEN(RPCB_MAXOWNERLEN))
780 828
781#define RPCB_mappingargs_sz RPCB_program_sz+RPCB_version_sz+ \ 829 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
782 RPCB_protocol_sz+RPCB_port_sz
783#define RPCB_getaddrargs_sz RPCB_program_sz+RPCB_version_sz+ \
784 RPCB_netid_sz+RPCB_addr_sz+ \
785 RPCB_ownerstring_sz
786 830
787#define RPCB_setres_sz RPCB_boolean_sz 831 p = xdr_inline_decode(&xdr, sizeof(__be32));
788#define RPCB_getportres_sz RPCB_port_sz 832 if (unlikely(p == NULL))
789 833 goto out_fail;
790/* 834 len = ntohl(*p);
791 * Note that RFC 1833 does not put any size restrictions on the
792 * address string returned by the remote rpcbind database.
793 */
794#define RPCB_getaddrres_sz RPCB_addr_sz
795 835
796#define PROC(proc, argtype, restype) \ 836 /*
797 [RPCBPROC_##proc] = { \ 837 * If the returned universal address is a null string,
798 .p_proc = RPCBPROC_##proc, \ 838 * the requested RPC service was not registered.
799 .p_encode = (kxdrproc_t) rpcb_encode_##argtype, \ 839 */
800 .p_decode = (kxdrproc_t) rpcb_decode_##restype, \ 840 if (len == 0) {
801 .p_arglen = RPCB_##argtype##args_sz, \ 841 dprintk("RPC: %5u RPCB reply: program not registered\n",
802 .p_replen = RPCB_##restype##res_sz, \ 842 task->tk_pid);
803 .p_statidx = RPCBPROC_##proc, \ 843 return 0;
804 .p_timer = 0, \
805 .p_name = #proc, \
806 } 844 }
807 845
846 if (unlikely(len > RPCBIND_MAXUADDRLEN))
847 goto out_fail;
848
849 p = xdr_inline_decode(&xdr, len);
850 if (unlikely(p == NULL))
851 goto out_fail;
852 dprintk("RPC: %5u RPCB_%s reply: %s\n", task->tk_pid,
853 task->tk_msg.rpc_proc->p_name, (char *)p);
854
855 if (rpc_uaddr2sockaddr((char *)p, len, sap, sizeof(address)) == 0)
856 goto out_fail;
857 rpcb->r_port = rpc_get_port(sap);
858
859 return 0;
860
861out_fail:
862 dprintk("RPC: %5u malformed RPCB_%s reply\n",
863 task->tk_pid, task->tk_msg.rpc_proc->p_name);
864 return -EIO;
865}
866
808/* 867/*
809 * Not all rpcbind procedures described in RFC 1833 are implemented 868 * Not all rpcbind procedures described in RFC 1833 are implemented
810 * since the Linux kernel RPC code requires only these. 869 * since the Linux kernel RPC code requires only these.
811 */ 870 */
871
812static struct rpc_procinfo rpcb_procedures2[] = { 872static struct rpc_procinfo rpcb_procedures2[] = {
813 PROC(SET, mapping, set), 873 [RPCBPROC_SET] = {
814 PROC(UNSET, mapping, set), 874 .p_proc = RPCBPROC_SET,
815 PROC(GETPORT, mapping, getport), 875 .p_encode = (kxdrproc_t)rpcb_enc_mapping,
876 .p_decode = (kxdrproc_t)rpcb_dec_set,
877 .p_arglen = RPCB_mappingargs_sz,
878 .p_replen = RPCB_setres_sz,
879 .p_statidx = RPCBPROC_SET,
880 .p_timer = 0,
881 .p_name = "SET",
882 },
883 [RPCBPROC_UNSET] = {
884 .p_proc = RPCBPROC_UNSET,
885 .p_encode = (kxdrproc_t)rpcb_enc_mapping,
886 .p_decode = (kxdrproc_t)rpcb_dec_set,
887 .p_arglen = RPCB_mappingargs_sz,
888 .p_replen = RPCB_setres_sz,
889 .p_statidx = RPCBPROC_UNSET,
890 .p_timer = 0,
891 .p_name = "UNSET",
892 },
893 [RPCBPROC_GETPORT] = {
894 .p_proc = RPCBPROC_GETPORT,
895 .p_encode = (kxdrproc_t)rpcb_enc_mapping,
896 .p_decode = (kxdrproc_t)rpcb_dec_getport,
897 .p_arglen = RPCB_mappingargs_sz,
898 .p_replen = RPCB_getportres_sz,
899 .p_statidx = RPCBPROC_GETPORT,
900 .p_timer = 0,
901 .p_name = "GETPORT",
902 },
816}; 903};
817 904
818static struct rpc_procinfo rpcb_procedures3[] = { 905static struct rpc_procinfo rpcb_procedures3[] = {
819 PROC(SET, getaddr, set), 906 [RPCBPROC_SET] = {
820 PROC(UNSET, getaddr, set), 907 .p_proc = RPCBPROC_SET,
821 PROC(GETADDR, getaddr, getaddr), 908 .p_encode = (kxdrproc_t)rpcb_enc_getaddr,
909 .p_decode = (kxdrproc_t)rpcb_dec_set,
910 .p_arglen = RPCB_getaddrargs_sz,
911 .p_replen = RPCB_setres_sz,
912 .p_statidx = RPCBPROC_SET,
913 .p_timer = 0,
914 .p_name = "SET",
915 },
916 [RPCBPROC_UNSET] = {
917 .p_proc = RPCBPROC_UNSET,
918 .p_encode = (kxdrproc_t)rpcb_enc_getaddr,
919 .p_decode = (kxdrproc_t)rpcb_dec_set,
920 .p_arglen = RPCB_getaddrargs_sz,
921 .p_replen = RPCB_setres_sz,
922 .p_statidx = RPCBPROC_UNSET,
923 .p_timer = 0,
924 .p_name = "UNSET",
925 },
926 [RPCBPROC_GETADDR] = {
927 .p_proc = RPCBPROC_GETADDR,
928 .p_encode = (kxdrproc_t)rpcb_enc_getaddr,
929 .p_decode = (kxdrproc_t)rpcb_dec_getaddr,
930 .p_arglen = RPCB_getaddrargs_sz,
931 .p_replen = RPCB_getaddrres_sz,
932 .p_statidx = RPCBPROC_GETADDR,
933 .p_timer = 0,
934 .p_name = "GETADDR",
935 },
822}; 936};
823 937
824static struct rpc_procinfo rpcb_procedures4[] = { 938static struct rpc_procinfo rpcb_procedures4[] = {
825 PROC(SET, getaddr, set), 939 [RPCBPROC_SET] = {
826 PROC(UNSET, getaddr, set), 940 .p_proc = RPCBPROC_SET,
827 PROC(GETADDR, getaddr, getaddr), 941 .p_encode = (kxdrproc_t)rpcb_enc_getaddr,
828 PROC(GETVERSADDR, getaddr, getaddr), 942 .p_decode = (kxdrproc_t)rpcb_dec_set,
943 .p_arglen = RPCB_getaddrargs_sz,
944 .p_replen = RPCB_setres_sz,
945 .p_statidx = RPCBPROC_SET,
946 .p_timer = 0,
947 .p_name = "SET",
948 },
949 [RPCBPROC_UNSET] = {
950 .p_proc = RPCBPROC_UNSET,
951 .p_encode = (kxdrproc_t)rpcb_enc_getaddr,
952 .p_decode = (kxdrproc_t)rpcb_dec_set,
953 .p_arglen = RPCB_getaddrargs_sz,
954 .p_replen = RPCB_setres_sz,
955 .p_statidx = RPCBPROC_UNSET,
956 .p_timer = 0,
957 .p_name = "UNSET",
958 },
959 [RPCBPROC_GETADDR] = {
960 .p_proc = RPCBPROC_GETADDR,
961 .p_encode = (kxdrproc_t)rpcb_enc_getaddr,
962 .p_decode = (kxdrproc_t)rpcb_dec_getaddr,
963 .p_arglen = RPCB_getaddrargs_sz,
964 .p_replen = RPCB_getaddrres_sz,
965 .p_statidx = RPCBPROC_GETADDR,
966 .p_timer = 0,
967 .p_name = "GETADDR",
968 },
829}; 969};
830 970
831static struct rpcb_info rpcb_next_version[] = { 971static struct rpcb_info rpcb_next_version[] = {
diff --git a/net/sunrpc/sunrpc_syms.c b/net/sunrpc/sunrpc_syms.c
index adaa81982f74..8cce92189019 100644
--- a/net/sunrpc/sunrpc_syms.c
+++ b/net/sunrpc/sunrpc_syms.c
@@ -69,5 +69,5 @@ cleanup_sunrpc(void)
69 rcu_barrier(); /* Wait for completion of call_rcu()'s */ 69 rcu_barrier(); /* Wait for completion of call_rcu()'s */
70} 70}
71MODULE_LICENSE("GPL"); 71MODULE_LICENSE("GPL");
72module_init(init_sunrpc); 72fs_initcall(init_sunrpc); /* Ensure we're initialised before nfs */
73module_exit(cleanup_sunrpc); 73module_exit(cleanup_sunrpc);
diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
index 5c865e2d299e..6caffa34ac01 100644
--- a/net/sunrpc/svcauth_unix.c
+++ b/net/sunrpc/svcauth_unix.c
@@ -171,6 +171,11 @@ static void ip_map_request(struct cache_detail *cd,
171 (*bpp)[-1] = '\n'; 171 (*bpp)[-1] = '\n';
172} 172}
173 173
174static int ip_map_upcall(struct cache_detail *cd, struct cache_head *h)
175{
176 return sunrpc_cache_pipe_upcall(cd, h, ip_map_request);
177}
178
174static struct ip_map *ip_map_lookup(char *class, struct in6_addr *addr); 179static struct ip_map *ip_map_lookup(char *class, struct in6_addr *addr);
175static int ip_map_update(struct ip_map *ipm, struct unix_domain *udom, time_t expiry); 180static int ip_map_update(struct ip_map *ipm, struct unix_domain *udom, time_t expiry);
176 181
@@ -289,7 +294,7 @@ struct cache_detail ip_map_cache = {
289 .hash_table = ip_table, 294 .hash_table = ip_table,
290 .name = "auth.unix.ip", 295 .name = "auth.unix.ip",
291 .cache_put = ip_map_put, 296 .cache_put = ip_map_put,
292 .cache_request = ip_map_request, 297 .cache_upcall = ip_map_upcall,
293 .cache_parse = ip_map_parse, 298 .cache_parse = ip_map_parse,
294 .cache_show = ip_map_show, 299 .cache_show = ip_map_show,
295 .match = ip_map_match, 300 .match = ip_map_match,
@@ -523,6 +528,11 @@ static void unix_gid_request(struct cache_detail *cd,
523 (*bpp)[-1] = '\n'; 528 (*bpp)[-1] = '\n';
524} 529}
525 530
531static int unix_gid_upcall(struct cache_detail *cd, struct cache_head *h)
532{
533 return sunrpc_cache_pipe_upcall(cd, h, unix_gid_request);
534}
535
526static struct unix_gid *unix_gid_lookup(uid_t uid); 536static struct unix_gid *unix_gid_lookup(uid_t uid);
527extern struct cache_detail unix_gid_cache; 537extern struct cache_detail unix_gid_cache;
528 538
@@ -622,7 +632,7 @@ struct cache_detail unix_gid_cache = {
622 .hash_table = gid_table, 632 .hash_table = gid_table,
623 .name = "auth.unix.gid", 633 .name = "auth.unix.gid",
624 .cache_put = unix_gid_put, 634 .cache_put = unix_gid_put,
625 .cache_request = unix_gid_request, 635 .cache_upcall = unix_gid_upcall,
626 .cache_parse = unix_gid_parse, 636 .cache_parse = unix_gid_parse,
627 .cache_show = unix_gid_show, 637 .cache_show = unix_gid_show,
628 .match = unix_gid_match, 638 .match = unix_gid_match,
diff --git a/net/sunrpc/timer.c b/net/sunrpc/timer.c
index 31becbf09263..dd824341c349 100644
--- a/net/sunrpc/timer.c
+++ b/net/sunrpc/timer.c
@@ -25,8 +25,13 @@
25#define RPC_RTO_INIT (HZ/5) 25#define RPC_RTO_INIT (HZ/5)
26#define RPC_RTO_MIN (HZ/10) 26#define RPC_RTO_MIN (HZ/10)
27 27
28void 28/**
29rpc_init_rtt(struct rpc_rtt *rt, unsigned long timeo) 29 * rpc_init_rtt - Initialize an RPC RTT estimator context
30 * @rt: context to initialize
31 * @timeo: initial timeout value, in jiffies
32 *
33 */
34void rpc_init_rtt(struct rpc_rtt *rt, unsigned long timeo)
30{ 35{
31 unsigned long init = 0; 36 unsigned long init = 0;
32 unsigned i; 37 unsigned i;
@@ -43,12 +48,16 @@ rpc_init_rtt(struct rpc_rtt *rt, unsigned long timeo)
43} 48}
44EXPORT_SYMBOL_GPL(rpc_init_rtt); 49EXPORT_SYMBOL_GPL(rpc_init_rtt);
45 50
46/* 51/**
52 * rpc_update_rtt - Update an RPC RTT estimator context
53 * @rt: context to update
54 * @timer: timer array index (request type)
55 * @m: recent actual RTT, in jiffies
56 *
47 * NB: When computing the smoothed RTT and standard deviation, 57 * NB: When computing the smoothed RTT and standard deviation,
48 * be careful not to produce negative intermediate results. 58 * be careful not to produce negative intermediate results.
49 */ 59 */
50void 60void rpc_update_rtt(struct rpc_rtt *rt, unsigned timer, long m)
51rpc_update_rtt(struct rpc_rtt *rt, unsigned timer, long m)
52{ 61{
53 long *srtt, *sdrtt; 62 long *srtt, *sdrtt;
54 63
@@ -79,21 +88,25 @@ rpc_update_rtt(struct rpc_rtt *rt, unsigned timer, long m)
79} 88}
80EXPORT_SYMBOL_GPL(rpc_update_rtt); 89EXPORT_SYMBOL_GPL(rpc_update_rtt);
81 90
82/* 91/**
83 * Estimate rto for an nfs rpc sent via. an unreliable datagram. 92 * rpc_calc_rto - Provide an estimated timeout value
84 * Use the mean and mean deviation of rtt for the appropriate type of rpc 93 * @rt: context to use for calculation
85 * for the frequent rpcs and a default for the others. 94 * @timer: timer array index (request type)
86 * The justification for doing "other" this way is that these rpcs 95 *
87 * happen so infrequently that timer est. would probably be stale. 96 * Estimate RTO for an NFS RPC sent via an unreliable datagram. Use
88 * Also, since many of these rpcs are 97 * the mean and mean deviation of RTT for the appropriate type of RPC
89 * non-idempotent, a conservative timeout is desired. 98 * for frequently issued RPCs, and a fixed default for the others.
99 *
100 * The justification for doing "other" this way is that these RPCs
101 * happen so infrequently that timer estimation would probably be
102 * stale. Also, since many of these RPCs are non-idempotent, a
103 * conservative timeout is desired.
104 *
90 * getattr, lookup, 105 * getattr, lookup,
91 * read, write, commit - A+4D 106 * read, write, commit - A+4D
92 * other - timeo 107 * other - timeo
93 */ 108 */
94 109unsigned long rpc_calc_rto(struct rpc_rtt *rt, unsigned timer)
95unsigned long
96rpc_calc_rto(struct rpc_rtt *rt, unsigned timer)
97{ 110{
98 unsigned long res; 111 unsigned long res;
99 112
diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c
index 406e26de584e..8bd690c48b69 100644
--- a/net/sunrpc/xdr.c
+++ b/net/sunrpc/xdr.c
@@ -24,7 +24,7 @@ xdr_encode_netobj(__be32 *p, const struct xdr_netobj *obj)
24 unsigned int quadlen = XDR_QUADLEN(obj->len); 24 unsigned int quadlen = XDR_QUADLEN(obj->len);
25 25
26 p[quadlen] = 0; /* zero trailing bytes */ 26 p[quadlen] = 0; /* zero trailing bytes */
27 *p++ = htonl(obj->len); 27 *p++ = cpu_to_be32(obj->len);
28 memcpy(p, obj->data, obj->len); 28 memcpy(p, obj->data, obj->len);
29 return p + XDR_QUADLEN(obj->len); 29 return p + XDR_QUADLEN(obj->len);
30} 30}
@@ -35,7 +35,7 @@ xdr_decode_netobj(__be32 *p, struct xdr_netobj *obj)
35{ 35{
36 unsigned int len; 36 unsigned int len;
37 37
38 if ((len = ntohl(*p++)) > XDR_MAX_NETOBJ) 38 if ((len = be32_to_cpu(*p++)) > XDR_MAX_NETOBJ)
39 return NULL; 39 return NULL;
40 obj->len = len; 40 obj->len = len;
41 obj->data = (u8 *) p; 41 obj->data = (u8 *) p;
@@ -83,7 +83,7 @@ EXPORT_SYMBOL_GPL(xdr_encode_opaque_fixed);
83 */ 83 */
84__be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes) 84__be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes)
85{ 85{
86 *p++ = htonl(nbytes); 86 *p++ = cpu_to_be32(nbytes);
87 return xdr_encode_opaque_fixed(p, ptr, nbytes); 87 return xdr_encode_opaque_fixed(p, ptr, nbytes);
88} 88}
89EXPORT_SYMBOL_GPL(xdr_encode_opaque); 89EXPORT_SYMBOL_GPL(xdr_encode_opaque);
@@ -101,7 +101,7 @@ xdr_decode_string_inplace(__be32 *p, char **sp,
101{ 101{
102 u32 len; 102 u32 len;
103 103
104 len = ntohl(*p++); 104 len = be32_to_cpu(*p++);
105 if (len > maxlen) 105 if (len > maxlen)
106 return NULL; 106 return NULL;
107 *lenp = len; 107 *lenp = len;
@@ -771,7 +771,7 @@ xdr_decode_word(struct xdr_buf *buf, unsigned int base, u32 *obj)
771 status = read_bytes_from_xdr_buf(buf, base, &raw, sizeof(*obj)); 771 status = read_bytes_from_xdr_buf(buf, base, &raw, sizeof(*obj));
772 if (status) 772 if (status)
773 return status; 773 return status;
774 *obj = ntohl(raw); 774 *obj = be32_to_cpu(raw);
775 return 0; 775 return 0;
776} 776}
777EXPORT_SYMBOL_GPL(xdr_decode_word); 777EXPORT_SYMBOL_GPL(xdr_decode_word);
@@ -779,7 +779,7 @@ EXPORT_SYMBOL_GPL(xdr_decode_word);
779int 779int
780xdr_encode_word(struct xdr_buf *buf, unsigned int base, u32 obj) 780xdr_encode_word(struct xdr_buf *buf, unsigned int base, u32 obj)
781{ 781{
782 __be32 raw = htonl(obj); 782 __be32 raw = cpu_to_be32(obj);
783 783
784 return write_bytes_to_xdr_buf(buf, base, &raw, sizeof(obj)); 784 return write_bytes_to_xdr_buf(buf, base, &raw, sizeof(obj));
785} 785}
diff --git a/net/sunrpc/xprtrdma/transport.c b/net/sunrpc/xprtrdma/transport.c
index 1dd6123070e9..9a63f669ece4 100644
--- a/net/sunrpc/xprtrdma/transport.c
+++ b/net/sunrpc/xprtrdma/transport.c
@@ -168,47 +168,25 @@ static struct rpc_xprt_ops xprt_rdma_procs; /* forward reference */
168static void 168static void
169xprt_rdma_format_addresses(struct rpc_xprt *xprt) 169xprt_rdma_format_addresses(struct rpc_xprt *xprt)
170{ 170{
171 struct sockaddr_in *addr = (struct sockaddr_in *) 171 struct sockaddr *sap = (struct sockaddr *)
172 &rpcx_to_rdmad(xprt).addr; 172 &rpcx_to_rdmad(xprt).addr;
173 char *buf; 173 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
174 char buf[64];
174 175
175 buf = kzalloc(20, GFP_KERNEL); 176 (void)rpc_ntop(sap, buf, sizeof(buf));
176 if (buf) 177 xprt->address_strings[RPC_DISPLAY_ADDR] = kstrdup(buf, GFP_KERNEL);
177 snprintf(buf, 20, "%pI4", &addr->sin_addr.s_addr);
178 xprt->address_strings[RPC_DISPLAY_ADDR] = buf;
179 178
180 buf = kzalloc(8, GFP_KERNEL); 179 (void)snprintf(buf, sizeof(buf), "%u", rpc_get_port(sap));
181 if (buf) 180 xprt->address_strings[RPC_DISPLAY_PORT] = kstrdup(buf, GFP_KERNEL);
182 snprintf(buf, 8, "%u", ntohs(addr->sin_port));
183 xprt->address_strings[RPC_DISPLAY_PORT] = buf;
184 181
185 xprt->address_strings[RPC_DISPLAY_PROTO] = "rdma"; 182 xprt->address_strings[RPC_DISPLAY_PROTO] = "rdma";
186 183
187 buf = kzalloc(48, GFP_KERNEL); 184 (void)snprintf(buf, sizeof(buf), "%02x%02x%02x%02x",
188 if (buf) 185 NIPQUAD(sin->sin_addr.s_addr));
189 snprintf(buf, 48, "addr=%pI4 port=%u proto=%s", 186 xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = kstrdup(buf, GFP_KERNEL);
190 &addr->sin_addr.s_addr, 187
191 ntohs(addr->sin_port), "rdma"); 188 (void)snprintf(buf, sizeof(buf), "%4hx", rpc_get_port(sap));
192 xprt->address_strings[RPC_DISPLAY_ALL] = buf; 189 xprt->address_strings[RPC_DISPLAY_HEX_PORT] = kstrdup(buf, GFP_KERNEL);
193
194 buf = kzalloc(10, GFP_KERNEL);
195 if (buf)
196 snprintf(buf, 10, "%02x%02x%02x%02x",
197 NIPQUAD(addr->sin_addr.s_addr));
198 xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = buf;
199
200 buf = kzalloc(8, GFP_KERNEL);
201 if (buf)
202 snprintf(buf, 8, "%4hx", ntohs(addr->sin_port));
203 xprt->address_strings[RPC_DISPLAY_HEX_PORT] = buf;
204
205 buf = kzalloc(30, GFP_KERNEL);
206 if (buf)
207 snprintf(buf, 30, "%pI4.%u.%u",
208 &addr->sin_addr.s_addr,
209 ntohs(addr->sin_port) >> 8,
210 ntohs(addr->sin_port) & 0xff);
211 xprt->address_strings[RPC_DISPLAY_UNIVERSAL_ADDR] = buf;
212 190
213 /* netid */ 191 /* netid */
214 xprt->address_strings[RPC_DISPLAY_NETID] = "rdma"; 192 xprt->address_strings[RPC_DISPLAY_NETID] = "rdma";
diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
index 83c73c4d017a..62438f3a914d 100644
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -248,8 +248,8 @@ struct sock_xprt {
248 * Connection of transports 248 * Connection of transports
249 */ 249 */
250 struct delayed_work connect_worker; 250 struct delayed_work connect_worker;
251 struct sockaddr_storage addr; 251 struct sockaddr_storage srcaddr;
252 unsigned short port; 252 unsigned short srcport;
253 253
254 /* 254 /*
255 * UDP socket buffer size parameters 255 * UDP socket buffer size parameters
@@ -296,117 +296,60 @@ static inline struct sockaddr_in6 *xs_addr_in6(struct rpc_xprt *xprt)
296 return (struct sockaddr_in6 *) &xprt->addr; 296 return (struct sockaddr_in6 *) &xprt->addr;
297} 297}
298 298
299static void xs_format_ipv4_peer_addresses(struct rpc_xprt *xprt, 299static void xs_format_common_peer_addresses(struct rpc_xprt *xprt)
300 const char *protocol,
301 const char *netid)
302{ 300{
303 struct sockaddr_in *addr = xs_addr_in(xprt); 301 struct sockaddr *sap = xs_addr(xprt);
304 char *buf; 302 struct sockaddr_in6 *sin6;
303 struct sockaddr_in *sin;
304 char buf[128];
305 305
306 buf = kzalloc(20, GFP_KERNEL); 306 (void)rpc_ntop(sap, buf, sizeof(buf));
307 if (buf) { 307 xprt->address_strings[RPC_DISPLAY_ADDR] = kstrdup(buf, GFP_KERNEL);
308 snprintf(buf, 20, "%pI4", &addr->sin_addr.s_addr);
309 }
310 xprt->address_strings[RPC_DISPLAY_ADDR] = buf;
311
312 buf = kzalloc(8, GFP_KERNEL);
313 if (buf) {
314 snprintf(buf, 8, "%u",
315 ntohs(addr->sin_port));
316 }
317 xprt->address_strings[RPC_DISPLAY_PORT] = buf;
318
319 xprt->address_strings[RPC_DISPLAY_PROTO] = protocol;
320
321 buf = kzalloc(48, GFP_KERNEL);
322 if (buf) {
323 snprintf(buf, 48, "addr=%pI4 port=%u proto=%s",
324 &addr->sin_addr.s_addr,
325 ntohs(addr->sin_port),
326 protocol);
327 }
328 xprt->address_strings[RPC_DISPLAY_ALL] = buf;
329
330 buf = kzalloc(10, GFP_KERNEL);
331 if (buf) {
332 snprintf(buf, 10, "%02x%02x%02x%02x",
333 NIPQUAD(addr->sin_addr.s_addr));
334 }
335 xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = buf;
336 308
337 buf = kzalloc(8, GFP_KERNEL); 309 switch (sap->sa_family) {
338 if (buf) { 310 case AF_INET:
339 snprintf(buf, 8, "%4hx", 311 sin = xs_addr_in(xprt);
340 ntohs(addr->sin_port)); 312 (void)snprintf(buf, sizeof(buf), "%02x%02x%02x%02x",
341 } 313 NIPQUAD(sin->sin_addr.s_addr));
342 xprt->address_strings[RPC_DISPLAY_HEX_PORT] = buf; 314 break;
343 315 case AF_INET6:
344 buf = kzalloc(30, GFP_KERNEL); 316 sin6 = xs_addr_in6(xprt);
345 if (buf) { 317 (void)snprintf(buf, sizeof(buf), "%pi6", &sin6->sin6_addr);
346 snprintf(buf, 30, "%pI4.%u.%u", 318 break;
347 &addr->sin_addr.s_addr, 319 default:
348 ntohs(addr->sin_port) >> 8, 320 BUG();
349 ntohs(addr->sin_port) & 0xff);
350 } 321 }
351 xprt->address_strings[RPC_DISPLAY_UNIVERSAL_ADDR] = buf; 322 xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = kstrdup(buf, GFP_KERNEL);
352
353 xprt->address_strings[RPC_DISPLAY_NETID] = netid;
354} 323}
355 324
356static void xs_format_ipv6_peer_addresses(struct rpc_xprt *xprt, 325static void xs_format_common_peer_ports(struct rpc_xprt *xprt)
357 const char *protocol,
358 const char *netid)
359{ 326{
360 struct sockaddr_in6 *addr = xs_addr_in6(xprt); 327 struct sockaddr *sap = xs_addr(xprt);
361 char *buf; 328 char buf[128];
362 329
363 buf = kzalloc(40, GFP_KERNEL); 330 (void)snprintf(buf, sizeof(buf), "%u", rpc_get_port(sap));
364 if (buf) { 331 xprt->address_strings[RPC_DISPLAY_PORT] = kstrdup(buf, GFP_KERNEL);
365 snprintf(buf, 40, "%pI6",&addr->sin6_addr);
366 }
367 xprt->address_strings[RPC_DISPLAY_ADDR] = buf;
368 332
369 buf = kzalloc(8, GFP_KERNEL); 333 (void)snprintf(buf, sizeof(buf), "%4hx", rpc_get_port(sap));
370 if (buf) { 334 xprt->address_strings[RPC_DISPLAY_HEX_PORT] = kstrdup(buf, GFP_KERNEL);
371 snprintf(buf, 8, "%u", 335}
372 ntohs(addr->sin6_port));
373 }
374 xprt->address_strings[RPC_DISPLAY_PORT] = buf;
375 336
337static void xs_format_peer_addresses(struct rpc_xprt *xprt,
338 const char *protocol,
339 const char *netid)
340{
376 xprt->address_strings[RPC_DISPLAY_PROTO] = protocol; 341 xprt->address_strings[RPC_DISPLAY_PROTO] = protocol;
342 xprt->address_strings[RPC_DISPLAY_NETID] = netid;
343 xs_format_common_peer_addresses(xprt);
344 xs_format_common_peer_ports(xprt);
345}
377 346
378 buf = kzalloc(64, GFP_KERNEL); 347static void xs_update_peer_port(struct rpc_xprt *xprt)
379 if (buf) { 348{
380 snprintf(buf, 64, "addr=%pI6 port=%u proto=%s", 349 kfree(xprt->address_strings[RPC_DISPLAY_HEX_PORT]);
381 &addr->sin6_addr, 350 kfree(xprt->address_strings[RPC_DISPLAY_PORT]);
382 ntohs(addr->sin6_port),
383 protocol);
384 }
385 xprt->address_strings[RPC_DISPLAY_ALL] = buf;
386
387 buf = kzalloc(36, GFP_KERNEL);
388 if (buf)
389 snprintf(buf, 36, "%pi6", &addr->sin6_addr);
390
391 xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = buf;
392
393 buf = kzalloc(8, GFP_KERNEL);
394 if (buf) {
395 snprintf(buf, 8, "%4hx",
396 ntohs(addr->sin6_port));
397 }
398 xprt->address_strings[RPC_DISPLAY_HEX_PORT] = buf;
399
400 buf = kzalloc(50, GFP_KERNEL);
401 if (buf) {
402 snprintf(buf, 50, "%pI6.%u.%u",
403 &addr->sin6_addr,
404 ntohs(addr->sin6_port) >> 8,
405 ntohs(addr->sin6_port) & 0xff);
406 }
407 xprt->address_strings[RPC_DISPLAY_UNIVERSAL_ADDR] = buf;
408 351
409 xprt->address_strings[RPC_DISPLAY_NETID] = netid; 352 xs_format_common_peer_ports(xprt);
410} 353}
411 354
412static void xs_free_peer_addresses(struct rpc_xprt *xprt) 355static void xs_free_peer_addresses(struct rpc_xprt *xprt)
@@ -1587,25 +1530,15 @@ static unsigned short xs_get_random_port(void)
1587 */ 1530 */
1588static void xs_set_port(struct rpc_xprt *xprt, unsigned short port) 1531static void xs_set_port(struct rpc_xprt *xprt, unsigned short port)
1589{ 1532{
1590 struct sockaddr *addr = xs_addr(xprt);
1591
1592 dprintk("RPC: setting port for xprt %p to %u\n", xprt, port); 1533 dprintk("RPC: setting port for xprt %p to %u\n", xprt, port);
1593 1534
1594 switch (addr->sa_family) { 1535 rpc_set_port(xs_addr(xprt), port);
1595 case AF_INET: 1536 xs_update_peer_port(xprt);
1596 ((struct sockaddr_in *)addr)->sin_port = htons(port);
1597 break;
1598 case AF_INET6:
1599 ((struct sockaddr_in6 *)addr)->sin6_port = htons(port);
1600 break;
1601 default:
1602 BUG();
1603 }
1604} 1537}
1605 1538
1606static unsigned short xs_get_srcport(struct sock_xprt *transport, struct socket *sock) 1539static unsigned short xs_get_srcport(struct sock_xprt *transport, struct socket *sock)
1607{ 1540{
1608 unsigned short port = transport->port; 1541 unsigned short port = transport->srcport;
1609 1542
1610 if (port == 0 && transport->xprt.resvport) 1543 if (port == 0 && transport->xprt.resvport)
1611 port = xs_get_random_port(); 1544 port = xs_get_random_port();
@@ -1614,8 +1547,8 @@ static unsigned short xs_get_srcport(struct sock_xprt *transport, struct socket
1614 1547
1615static unsigned short xs_next_srcport(struct sock_xprt *transport, struct socket *sock, unsigned short port) 1548static unsigned short xs_next_srcport(struct sock_xprt *transport, struct socket *sock, unsigned short port)
1616{ 1549{
1617 if (transport->port != 0) 1550 if (transport->srcport != 0)
1618 transport->port = 0; 1551 transport->srcport = 0;
1619 if (!transport->xprt.resvport) 1552 if (!transport->xprt.resvport)
1620 return 0; 1553 return 0;
1621 if (port <= xprt_min_resvport || port > xprt_max_resvport) 1554 if (port <= xprt_min_resvport || port > xprt_max_resvport)
@@ -1633,7 +1566,7 @@ static int xs_bind4(struct sock_xprt *transport, struct socket *sock)
1633 unsigned short port = xs_get_srcport(transport, sock); 1566 unsigned short port = xs_get_srcport(transport, sock);
1634 unsigned short last; 1567 unsigned short last;
1635 1568
1636 sa = (struct sockaddr_in *)&transport->addr; 1569 sa = (struct sockaddr_in *)&transport->srcaddr;
1637 myaddr.sin_addr = sa->sin_addr; 1570 myaddr.sin_addr = sa->sin_addr;
1638 do { 1571 do {
1639 myaddr.sin_port = htons(port); 1572 myaddr.sin_port = htons(port);
@@ -1642,7 +1575,7 @@ static int xs_bind4(struct sock_xprt *transport, struct socket *sock)
1642 if (port == 0) 1575 if (port == 0)
1643 break; 1576 break;
1644 if (err == 0) { 1577 if (err == 0) {
1645 transport->port = port; 1578 transport->srcport = port;
1646 break; 1579 break;
1647 } 1580 }
1648 last = port; 1581 last = port;
@@ -1666,7 +1599,7 @@ static int xs_bind6(struct sock_xprt *transport, struct socket *sock)
1666 unsigned short port = xs_get_srcport(transport, sock); 1599 unsigned short port = xs_get_srcport(transport, sock);
1667 unsigned short last; 1600 unsigned short last;
1668 1601
1669 sa = (struct sockaddr_in6 *)&transport->addr; 1602 sa = (struct sockaddr_in6 *)&transport->srcaddr;
1670 myaddr.sin6_addr = sa->sin6_addr; 1603 myaddr.sin6_addr = sa->sin6_addr;
1671 do { 1604 do {
1672 myaddr.sin6_port = htons(port); 1605 myaddr.sin6_port = htons(port);
@@ -1675,7 +1608,7 @@ static int xs_bind6(struct sock_xprt *transport, struct socket *sock)
1675 if (port == 0) 1608 if (port == 0)
1676 break; 1609 break;
1677 if (err == 0) { 1610 if (err == 0) {
1678 transport->port = port; 1611 transport->srcport = port;
1679 break; 1612 break;
1680 } 1613 }
1681 last = port; 1614 last = port;
@@ -1780,8 +1713,11 @@ static void xs_udp_connect_worker4(struct work_struct *work)
1780 goto out; 1713 goto out;
1781 } 1714 }
1782 1715
1783 dprintk("RPC: worker connecting xprt %p to address: %s\n", 1716 dprintk("RPC: worker connecting xprt %p via %s to "
1784 xprt, xprt->address_strings[RPC_DISPLAY_ALL]); 1717 "%s (port %s)\n", xprt,
1718 xprt->address_strings[RPC_DISPLAY_PROTO],
1719 xprt->address_strings[RPC_DISPLAY_ADDR],
1720 xprt->address_strings[RPC_DISPLAY_PORT]);
1785 1721
1786 xs_udp_finish_connecting(xprt, sock); 1722 xs_udp_finish_connecting(xprt, sock);
1787 status = 0; 1723 status = 0;
@@ -1822,8 +1758,11 @@ static void xs_udp_connect_worker6(struct work_struct *work)
1822 goto out; 1758 goto out;
1823 } 1759 }
1824 1760
1825 dprintk("RPC: worker connecting xprt %p to address: %s\n", 1761 dprintk("RPC: worker connecting xprt %p via %s to "
1826 xprt, xprt->address_strings[RPC_DISPLAY_ALL]); 1762 "%s (port %s)\n", xprt,
1763 xprt->address_strings[RPC_DISPLAY_PROTO],
1764 xprt->address_strings[RPC_DISPLAY_ADDR],
1765 xprt->address_strings[RPC_DISPLAY_PORT]);
1827 1766
1828 xs_udp_finish_connecting(xprt, sock); 1767 xs_udp_finish_connecting(xprt, sock);
1829 status = 0; 1768 status = 0;
@@ -1948,8 +1887,11 @@ static void xs_tcp_setup_socket(struct rpc_xprt *xprt,
1948 goto out_eagain; 1887 goto out_eagain;
1949 } 1888 }
1950 1889
1951 dprintk("RPC: worker connecting xprt %p to address: %s\n", 1890 dprintk("RPC: worker connecting xprt %p via %s to "
1952 xprt, xprt->address_strings[RPC_DISPLAY_ALL]); 1891 "%s (port %s)\n", xprt,
1892 xprt->address_strings[RPC_DISPLAY_PROTO],
1893 xprt->address_strings[RPC_DISPLAY_ADDR],
1894 xprt->address_strings[RPC_DISPLAY_PORT]);
1953 1895
1954 status = xs_tcp_finish_connecting(xprt, sock); 1896 status = xs_tcp_finish_connecting(xprt, sock);
1955 dprintk("RPC: %p connect status %d connected %d sock state %d\n", 1897 dprintk("RPC: %p connect status %d connected %d sock state %d\n",
@@ -2120,7 +2062,7 @@ static void xs_udp_print_stats(struct rpc_xprt *xprt, struct seq_file *seq)
2120 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); 2062 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
2121 2063
2122 seq_printf(seq, "\txprt:\tudp %u %lu %lu %lu %lu %Lu %Lu\n", 2064 seq_printf(seq, "\txprt:\tudp %u %lu %lu %lu %lu %Lu %Lu\n",
2123 transport->port, 2065 transport->srcport,
2124 xprt->stat.bind_count, 2066 xprt->stat.bind_count,
2125 xprt->stat.sends, 2067 xprt->stat.sends,
2126 xprt->stat.recvs, 2068 xprt->stat.recvs,
@@ -2144,7 +2086,7 @@ static void xs_tcp_print_stats(struct rpc_xprt *xprt, struct seq_file *seq)
2144 idle_time = (long)(jiffies - xprt->last_used) / HZ; 2086 idle_time = (long)(jiffies - xprt->last_used) / HZ;
2145 2087
2146 seq_printf(seq, "\txprt:\ttcp %u %lu %lu %lu %ld %lu %lu %lu %Lu %Lu\n", 2088 seq_printf(seq, "\txprt:\ttcp %u %lu %lu %lu %ld %lu %lu %lu %Lu %Lu\n",
2147 transport->port, 2089 transport->srcport,
2148 xprt->stat.bind_count, 2090 xprt->stat.bind_count,
2149 xprt->stat.connect_count, 2091 xprt->stat.connect_count,
2150 xprt->stat.connect_time, 2092 xprt->stat.connect_time,
@@ -2223,7 +2165,7 @@ static struct rpc_xprt *xs_setup_xprt(struct xprt_create *args,
2223 memcpy(&xprt->addr, args->dstaddr, args->addrlen); 2165 memcpy(&xprt->addr, args->dstaddr, args->addrlen);
2224 xprt->addrlen = args->addrlen; 2166 xprt->addrlen = args->addrlen;
2225 if (args->srcaddr) 2167 if (args->srcaddr)
2226 memcpy(&new->addr, args->srcaddr, args->addrlen); 2168 memcpy(&new->srcaddr, args->srcaddr, args->addrlen);
2227 2169
2228 return xprt; 2170 return xprt;
2229} 2171}
@@ -2272,7 +2214,7 @@ static struct rpc_xprt *xs_setup_udp(struct xprt_create *args)
2272 2214
2273 INIT_DELAYED_WORK(&transport->connect_worker, 2215 INIT_DELAYED_WORK(&transport->connect_worker,
2274 xs_udp_connect_worker4); 2216 xs_udp_connect_worker4);
2275 xs_format_ipv4_peer_addresses(xprt, "udp", RPCBIND_NETID_UDP); 2217 xs_format_peer_addresses(xprt, "udp", RPCBIND_NETID_UDP);
2276 break; 2218 break;
2277 case AF_INET6: 2219 case AF_INET6:
2278 if (((struct sockaddr_in6 *)addr)->sin6_port != htons(0)) 2220 if (((struct sockaddr_in6 *)addr)->sin6_port != htons(0))
@@ -2280,15 +2222,22 @@ static struct rpc_xprt *xs_setup_udp(struct xprt_create *args)
2280 2222
2281 INIT_DELAYED_WORK(&transport->connect_worker, 2223 INIT_DELAYED_WORK(&transport->connect_worker,
2282 xs_udp_connect_worker6); 2224 xs_udp_connect_worker6);
2283 xs_format_ipv6_peer_addresses(xprt, "udp", RPCBIND_NETID_UDP6); 2225 xs_format_peer_addresses(xprt, "udp", RPCBIND_NETID_UDP6);
2284 break; 2226 break;
2285 default: 2227 default:
2286 kfree(xprt); 2228 kfree(xprt);
2287 return ERR_PTR(-EAFNOSUPPORT); 2229 return ERR_PTR(-EAFNOSUPPORT);
2288 } 2230 }
2289 2231
2290 dprintk("RPC: set up transport to address %s\n", 2232 if (xprt_bound(xprt))
2291 xprt->address_strings[RPC_DISPLAY_ALL]); 2233 dprintk("RPC: set up xprt to %s (port %s) via %s\n",
2234 xprt->address_strings[RPC_DISPLAY_ADDR],
2235 xprt->address_strings[RPC_DISPLAY_PORT],
2236 xprt->address_strings[RPC_DISPLAY_PROTO]);
2237 else
2238 dprintk("RPC: set up xprt to %s (autobind) via %s\n",
2239 xprt->address_strings[RPC_DISPLAY_ADDR],
2240 xprt->address_strings[RPC_DISPLAY_PROTO]);
2292 2241
2293 if (try_module_get(THIS_MODULE)) 2242 if (try_module_get(THIS_MODULE))
2294 return xprt; 2243 return xprt;
@@ -2337,23 +2286,33 @@ static struct rpc_xprt *xs_setup_tcp(struct xprt_create *args)
2337 if (((struct sockaddr_in *)addr)->sin_port != htons(0)) 2286 if (((struct sockaddr_in *)addr)->sin_port != htons(0))
2338 xprt_set_bound(xprt); 2287 xprt_set_bound(xprt);
2339 2288
2340 INIT_DELAYED_WORK(&transport->connect_worker, xs_tcp_connect_worker4); 2289 INIT_DELAYED_WORK(&transport->connect_worker,
2341 xs_format_ipv4_peer_addresses(xprt, "tcp", RPCBIND_NETID_TCP); 2290 xs_tcp_connect_worker4);
2291 xs_format_peer_addresses(xprt, "tcp", RPCBIND_NETID_TCP);
2342 break; 2292 break;
2343 case AF_INET6: 2293 case AF_INET6:
2344 if (((struct sockaddr_in6 *)addr)->sin6_port != htons(0)) 2294 if (((struct sockaddr_in6 *)addr)->sin6_port != htons(0))
2345 xprt_set_bound(xprt); 2295 xprt_set_bound(xprt);
2346 2296
2347 INIT_DELAYED_WORK(&transport->connect_worker, xs_tcp_connect_worker6); 2297 INIT_DELAYED_WORK(&transport->connect_worker,
2348 xs_format_ipv6_peer_addresses(xprt, "tcp", RPCBIND_NETID_TCP6); 2298 xs_tcp_connect_worker6);
2299 xs_format_peer_addresses(xprt, "tcp", RPCBIND_NETID_TCP6);
2349 break; 2300 break;
2350 default: 2301 default:
2351 kfree(xprt); 2302 kfree(xprt);
2352 return ERR_PTR(-EAFNOSUPPORT); 2303 return ERR_PTR(-EAFNOSUPPORT);
2353 } 2304 }
2354 2305
2355 dprintk("RPC: set up transport to address %s\n", 2306 if (xprt_bound(xprt))
2356 xprt->address_strings[RPC_DISPLAY_ALL]); 2307 dprintk("RPC: set up xprt to %s (port %s) via %s\n",
2308 xprt->address_strings[RPC_DISPLAY_ADDR],
2309 xprt->address_strings[RPC_DISPLAY_PORT],
2310 xprt->address_strings[RPC_DISPLAY_PROTO]);
2311 else
2312 dprintk("RPC: set up xprt to %s (autobind) via %s\n",
2313 xprt->address_strings[RPC_DISPLAY_ADDR],
2314 xprt->address_strings[RPC_DISPLAY_PROTO]);
2315
2357 2316
2358 if (try_module_get(THIS_MODULE)) 2317 if (try_module_get(THIS_MODULE))
2359 return xprt; 2318 return xprt;
@@ -2412,3 +2371,55 @@ void cleanup_socket_xprt(void)
2412 xprt_unregister_transport(&xs_udp_transport); 2371 xprt_unregister_transport(&xs_udp_transport);
2413 xprt_unregister_transport(&xs_tcp_transport); 2372 xprt_unregister_transport(&xs_tcp_transport);
2414} 2373}
2374
2375static int param_set_uint_minmax(const char *val, struct kernel_param *kp,
2376 unsigned int min, unsigned int max)
2377{
2378 unsigned long num;
2379 int ret;
2380
2381 if (!val)
2382 return -EINVAL;
2383 ret = strict_strtoul(val, 0, &num);
2384 if (ret == -EINVAL || num < min || num > max)
2385 return -EINVAL;
2386 *((unsigned int *)kp->arg) = num;
2387 return 0;
2388}
2389
2390static int param_set_portnr(const char *val, struct kernel_param *kp)
2391{
2392 return param_set_uint_minmax(val, kp,
2393 RPC_MIN_RESVPORT,
2394 RPC_MAX_RESVPORT);
2395}
2396
2397static int param_get_portnr(char *buffer, struct kernel_param *kp)
2398{
2399 return param_get_uint(buffer, kp);
2400}
2401#define param_check_portnr(name, p) \
2402 __param_check(name, p, unsigned int);
2403
2404module_param_named(min_resvport, xprt_min_resvport, portnr, 0644);
2405module_param_named(max_resvport, xprt_max_resvport, portnr, 0644);
2406
2407static int param_set_slot_table_size(const char *val, struct kernel_param *kp)
2408{
2409 return param_set_uint_minmax(val, kp,
2410 RPC_MIN_SLOT_TABLE,
2411 RPC_MAX_SLOT_TABLE);
2412}
2413
2414static int param_get_slot_table_size(char *buffer, struct kernel_param *kp)
2415{
2416 return param_get_uint(buffer, kp);
2417}
2418#define param_check_slot_table_size(name, p) \
2419 __param_check(name, p, unsigned int);
2420
2421module_param_named(tcp_slot_table_entries, xprt_tcp_slot_table_entries,
2422 slot_table_size, 0644);
2423module_param_named(udp_slot_table_entries, xprt_udp_slot_table_entries,
2424 slot_table_size, 0644);
2425