Commit | Line | Data |
---|---|---|
24c8dbbb DH |
1 | /* client.c: NFS client sharing and management code |
2 | * | |
3 | * Copyright (C) 2006 Red Hat, Inc. All Rights Reserved. | |
4 | * Written by David Howells (dhowells@redhat.com) | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public License | |
8 | * as published by the Free Software Foundation; either version | |
9 | * 2 of the License, or (at your option) any later version. | |
10 | */ | |
11 | ||
12 | ||
24c8dbbb DH |
13 | #include <linux/module.h> |
14 | #include <linux/init.h> | |
e8edc6e0 | 15 | #include <linux/sched.h> |
24c8dbbb DH |
16 | #include <linux/time.h> |
17 | #include <linux/kernel.h> | |
18 | #include <linux/mm.h> | |
19 | #include <linux/string.h> | |
20 | #include <linux/stat.h> | |
21 | #include <linux/errno.h> | |
22 | #include <linux/unistd.h> | |
23 | #include <linux/sunrpc/clnt.h> | |
24 | #include <linux/sunrpc/stats.h> | |
25 | #include <linux/sunrpc/metrics.h> | |
0896a725 | 26 | #include <linux/sunrpc/xprtsock.h> |
2cf7ff7a | 27 | #include <linux/sunrpc/xprtrdma.h> |
24c8dbbb DH |
28 | #include <linux/nfs_fs.h> |
29 | #include <linux/nfs_mount.h> | |
30 | #include <linux/nfs4_mount.h> | |
31 | #include <linux/lockd/bind.h> | |
24c8dbbb DH |
32 | #include <linux/seq_file.h> |
33 | #include <linux/mount.h> | |
34 | #include <linux/nfs_idmap.h> | |
35 | #include <linux/vfs.h> | |
36 | #include <linux/inet.h> | |
3b0d3f93 | 37 | #include <linux/in6.h> |
5a0e3ad6 | 38 | #include <linux/slab.h> |
40401530 | 39 | #include <linux/idr.h> |
3b0d3f93 | 40 | #include <net/ipv6.h> |
24c8dbbb | 41 | #include <linux/nfs_xdr.h> |
0b5b7ae0 | 42 | #include <linux/sunrpc/bc_xprt.h> |
6b13168b SK |
43 | #include <linux/nsproxy.h> |
44 | #include <linux/pid_namespace.h> | |
24c8dbbb | 45 | |
24c8dbbb DH |
46 | |
47 | #include "nfs4_fs.h" | |
48 | #include "callback.h" | |
49 | #include "delegation.h" | |
50 | #include "iostat.h" | |
51 | #include "internal.h" | |
14727281 | 52 | #include "fscache.h" |
85e174ba | 53 | #include "pnfs.h" |
6b13168b | 54 | #include "netns.h" |
24c8dbbb DH |
55 | |
56 | #define NFSDBG_FACILITY NFSDBG_CLIENT | |
57 | ||
24c8dbbb | 58 | static DECLARE_WAIT_QUEUE_HEAD(nfs_client_active_wq); |
f4eecd5d | 59 | #ifdef CONFIG_NFS_V4 |
f4eecd5d AA |
60 | |
61 | /* | |
62 | * Get a unique NFSv4.0 callback identifier which will be used | |
63 | * by the V4.0 callback service to lookup the nfs_client struct | |
64 | */ | |
65 | static int nfs_get_cb_ident_idr(struct nfs_client *clp, int minorversion) | |
66 | { | |
67 | int ret = 0; | |
73ea666c | 68 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
f4eecd5d AA |
69 | |
70 | if (clp->rpc_ops->version != 4 || minorversion != 0) | |
71 | return ret; | |
72 | retry: | |
28cd1b3f | 73 | if (!idr_pre_get(&nn->cb_ident_idr, GFP_KERNEL)) |
f4eecd5d | 74 | return -ENOMEM; |
dc030858 | 75 | spin_lock(&nn->nfs_client_lock); |
28cd1b3f | 76 | ret = idr_get_new(&nn->cb_ident_idr, clp, &clp->cl_cb_ident); |
dc030858 | 77 | spin_unlock(&nn->nfs_client_lock); |
f4eecd5d AA |
78 | if (ret == -EAGAIN) |
79 | goto retry; | |
80 | return ret; | |
81 | } | |
82 | #endif /* CONFIG_NFS_V4 */ | |
24c8dbbb | 83 | |
b064eca2 TM |
84 | /* |
85 | * Turn off NFSv4 uid/gid mapping when using AUTH_SYS | |
86 | */ | |
90ab5ee9 | 87 | static bool nfs4_disable_idmapping = true; |
b064eca2 | 88 | |
5006a76c DH |
89 | /* |
90 | * RPC cruft for NFS | |
91 | */ | |
a613fa16 | 92 | static const struct rpc_version *nfs_version[5] = { |
2ba68002 | 93 | #ifdef CONFIG_NFS_V2 |
5006a76c | 94 | [2] = &nfs_version2, |
2ba68002 | 95 | #endif |
5006a76c DH |
96 | #ifdef CONFIG_NFS_V3 |
97 | [3] = &nfs_version3, | |
98 | #endif | |
99 | #ifdef CONFIG_NFS_V4 | |
100 | [4] = &nfs_version4, | |
101 | #endif | |
102 | }; | |
103 | ||
a613fa16 | 104 | const struct rpc_program nfs_program = { |
5006a76c DH |
105 | .name = "nfs", |
106 | .number = NFS_PROGRAM, | |
107 | .nrvers = ARRAY_SIZE(nfs_version), | |
108 | .version = nfs_version, | |
109 | .stats = &nfs_rpcstat, | |
fe0a9b74 | 110 | .pipe_dir_name = NFS_PIPE_DIRNAME, |
5006a76c DH |
111 | }; |
112 | ||
113 | struct rpc_stat nfs_rpcstat = { | |
114 | .program = &nfs_program | |
115 | }; | |
116 | ||
117 | ||
118 | #ifdef CONFIG_NFS_V3_ACL | |
119 | static struct rpc_stat nfsacl_rpcstat = { &nfsacl_program }; | |
a613fa16 | 120 | static const struct rpc_version *nfsacl_version[] = { |
5006a76c DH |
121 | [3] = &nfsacl_version3, |
122 | }; | |
123 | ||
a613fa16 | 124 | const struct rpc_program nfsacl_program = { |
5006a76c DH |
125 | .name = "nfsacl", |
126 | .number = NFS_ACL_PROGRAM, | |
127 | .nrvers = ARRAY_SIZE(nfsacl_version), | |
128 | .version = nfsacl_version, | |
129 | .stats = &nfsacl_rpcstat, | |
130 | }; | |
131 | #endif /* CONFIG_NFS_V3_ACL */ | |
132 | ||
3a498026 | 133 | struct nfs_client_initdata { |
4bf590e0 | 134 | unsigned long init_flags; |
3a498026 | 135 | const char *hostname; |
d7422c47 | 136 | const struct sockaddr *addr; |
6e4cffd7 | 137 | size_t addrlen; |
40c55319 | 138 | const struct nfs_rpc_ops *rpc_ops; |
59dca3b2 | 139 | int proto; |
5aae4a9a | 140 | u32 minorversion; |
e50a7a1a | 141 | struct net *net; |
3a498026 TM |
142 | }; |
143 | ||
24c8dbbb DH |
144 | /* |
145 | * Allocate a shared client record | |
146 | * | |
147 | * Since these are allocated/deallocated very rarely, we don't | |
148 | * bother putting them in a slab cache... | |
149 | */ | |
3a498026 | 150 | static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init) |
24c8dbbb DH |
151 | { |
152 | struct nfs_client *clp; | |
7c67db3a | 153 | struct rpc_cred *cred; |
a21bdd9b | 154 | int err = -ENOMEM; |
24c8dbbb DH |
155 | |
156 | if ((clp = kzalloc(sizeof(*clp), GFP_KERNEL)) == NULL) | |
157 | goto error_0; | |
158 | ||
40c55319 TM |
159 | clp->rpc_ops = cl_init->rpc_ops; |
160 | ||
24c8dbbb DH |
161 | atomic_set(&clp->cl_count, 1); |
162 | clp->cl_cons_state = NFS_CS_INITING; | |
163 | ||
6e4cffd7 CL |
164 | memcpy(&clp->cl_addr, cl_init->addr, cl_init->addrlen); |
165 | clp->cl_addrlen = cl_init->addrlen; | |
24c8dbbb | 166 | |
3a498026 | 167 | if (cl_init->hostname) { |
a21bdd9b | 168 | err = -ENOMEM; |
3a498026 | 169 | clp->cl_hostname = kstrdup(cl_init->hostname, GFP_KERNEL); |
24c8dbbb | 170 | if (!clp->cl_hostname) |
71468513 | 171 | goto error_cleanup; |
24c8dbbb DH |
172 | } |
173 | ||
174 | INIT_LIST_HEAD(&clp->cl_superblocks); | |
175 | clp->cl_rpcclient = ERR_PTR(-EINVAL); | |
176 | ||
59dca3b2 | 177 | clp->cl_proto = cl_init->proto; |
73ea666c | 178 | clp->cl_net = get_net(cl_init->net); |
59dca3b2 | 179 | |
24c8dbbb | 180 | #ifdef CONFIG_NFS_V4 |
f4eecd5d AA |
181 | err = nfs_get_cb_ident_idr(clp, cl_init->minorversion); |
182 | if (err) | |
183 | goto error_cleanup; | |
184 | ||
24c8dbbb | 185 | spin_lock_init(&clp->cl_lock); |
65f27f38 | 186 | INIT_DELAYED_WORK(&clp->cl_renewd, nfs4_renew_state); |
24c8dbbb | 187 | rpc_init_wait_queue(&clp->cl_rpcwaitq, "NFS client"); |
24c8dbbb | 188 | clp->cl_state = 1 << NFS4CLNT_LEASE_EXPIRED; |
5aae4a9a | 189 | clp->cl_minorversion = cl_init->minorversion; |
97dc1359 | 190 | clp->cl_mvops = nfs_v4_minor_ops[cl_init->minorversion]; |
24c8dbbb | 191 | #endif |
68c97153 | 192 | cred = rpc_lookup_machine_cred("*"); |
7c67db3a TM |
193 | if (!IS_ERR(cred)) |
194 | clp->cl_machine_cred = cred; | |
14727281 DH |
195 | nfs_fscache_get_client_cookie(clp); |
196 | ||
24c8dbbb DH |
197 | return clp; |
198 | ||
71468513 | 199 | error_cleanup: |
24c8dbbb DH |
200 | kfree(clp); |
201 | error_0: | |
a21bdd9b | 202 | return ERR_PTR(err); |
24c8dbbb DH |
203 | } |
204 | ||
5dd3177a | 205 | #ifdef CONFIG_NFS_V4 |
557134a3 | 206 | #ifdef CONFIG_NFS_V4_1 |
ea005281 AA |
207 | static void nfs4_shutdown_session(struct nfs_client *clp) |
208 | { | |
7df529af TM |
209 | if (nfs4_has_session(clp)) { |
210 | nfs4_deviceid_purge_client(clp); | |
557134a3 | 211 | nfs4_destroy_session(clp->cl_session); |
7df529af TM |
212 | } |
213 | ||
888ef2e3 | 214 | } |
ea005281 AA |
215 | #else /* CONFIG_NFS_V4_1 */ |
216 | static void nfs4_shutdown_session(struct nfs_client *clp) | |
217 | { | |
218 | } | |
219 | #endif /* CONFIG_NFS_V4_1 */ | |
71468513 | 220 | |
888ef2e3 AB |
221 | /* |
222 | * Destroy the NFS4 callback service | |
223 | */ | |
224 | static void nfs4_destroy_callback(struct nfs_client *clp) | |
225 | { | |
226 | if (__test_and_clear_bit(NFS_CS_CALLBACK, &clp->cl_res_state)) | |
97dc1359 | 227 | nfs_callback_down(clp->cl_mvops->minor_version); |
888ef2e3 AB |
228 | } |
229 | ||
230 | static void nfs4_shutdown_client(struct nfs_client *clp) | |
231 | { | |
232 | if (__test_and_clear_bit(NFS_CS_RENEWD, &clp->cl_res_state)) | |
233 | nfs4_kill_renewd(clp); | |
ea005281 | 234 | nfs4_shutdown_session(clp); |
71468513 | 235 | nfs4_destroy_callback(clp); |
888ef2e3 AB |
236 | if (__test_and_clear_bit(NFS_CS_IDMAP, &clp->cl_res_state)) |
237 | nfs_idmap_delete(clp); | |
238 | ||
239 | rpc_destroy_wait_queue(&clp->cl_rpcwaitq); | |
acdeb69d | 240 | kfree(clp->cl_serverowner); |
79d4e1f0 | 241 | kfree(clp->cl_serverscope); |
59155546 | 242 | kfree(clp->cl_implid); |
557134a3 | 243 | } |
f4eecd5d AA |
244 | |
245 | /* idr_remove_all is not needed as all id's are removed by nfs_put_client */ | |
28cd1b3f | 246 | void nfs_cleanup_cb_ident_idr(struct net *net) |
f4eecd5d | 247 | { |
28cd1b3f SK |
248 | struct nfs_net *nn = net_generic(net, nfs_net_id); |
249 | ||
250 | idr_destroy(&nn->cb_ident_idr); | |
f4eecd5d AA |
251 | } |
252 | ||
253 | /* nfs_client_lock held */ | |
254 | static void nfs_cb_idr_remove_locked(struct nfs_client *clp) | |
255 | { | |
73ea666c | 256 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
28cd1b3f | 257 | |
f4eecd5d | 258 | if (clp->cl_cb_ident) |
28cd1b3f | 259 | idr_remove(&nn->cb_ident_idr, clp->cl_cb_ident); |
f4eecd5d AA |
260 | } |
261 | ||
f7e8917a FI |
262 | static void pnfs_init_server(struct nfs_server *server) |
263 | { | |
264 | rpc_init_wait_queue(&server->roc_rpcwaitq, "pNFS ROC"); | |
265 | } | |
266 | ||
0aaaf5c4 CL |
267 | static void nfs4_destroy_server(struct nfs_server *server) |
268 | { | |
269 | nfs4_purge_state_owners(server); | |
270 | } | |
271 | ||
888ef2e3 AB |
272 | #else |
273 | static void nfs4_shutdown_client(struct nfs_client *clp) | |
274 | { | |
275 | } | |
f4eecd5d | 276 | |
28cd1b3f | 277 | void nfs_cleanup_cb_ident_idr(struct net *net) |
f4eecd5d AA |
278 | { |
279 | } | |
280 | ||
281 | static void nfs_cb_idr_remove_locked(struct nfs_client *clp) | |
282 | { | |
283 | } | |
f7e8917a FI |
284 | |
285 | static void pnfs_init_server(struct nfs_server *server) | |
286 | { | |
287 | } | |
288 | ||
888ef2e3 | 289 | #endif /* CONFIG_NFS_V4 */ |
557134a3 | 290 | |
24c8dbbb DH |
291 | /* |
292 | * Destroy a shared client record | |
293 | */ | |
294 | static void nfs_free_client(struct nfs_client *clp) | |
295 | { | |
40c55319 | 296 | dprintk("--> nfs_free_client(%u)\n", clp->rpc_ops->version); |
24c8dbbb | 297 | |
5dd3177a | 298 | nfs4_shutdown_client(clp); |
24c8dbbb | 299 | |
14727281 DH |
300 | nfs_fscache_release_client_cookie(clp); |
301 | ||
24c8dbbb DH |
302 | /* -EIO all pending I/O */ |
303 | if (!IS_ERR(clp->cl_rpcclient)) | |
304 | rpc_shutdown_client(clp->cl_rpcclient); | |
305 | ||
7c67db3a TM |
306 | if (clp->cl_machine_cred != NULL) |
307 | put_rpccred(clp->cl_machine_cred); | |
308 | ||
73ea666c | 309 | put_net(clp->cl_net); |
24c8dbbb DH |
310 | kfree(clp->cl_hostname); |
311 | kfree(clp); | |
312 | ||
313 | dprintk("<-- nfs_free_client()\n"); | |
314 | } | |
315 | ||
316 | /* | |
317 | * Release a reference to a shared client record | |
318 | */ | |
319 | void nfs_put_client(struct nfs_client *clp) | |
320 | { | |
dc030858 SK |
321 | struct nfs_net *nn; |
322 | ||
27ba8512 DH |
323 | if (!clp) |
324 | return; | |
325 | ||
24c8dbbb | 326 | dprintk("--> nfs_put_client({%d})\n", atomic_read(&clp->cl_count)); |
73ea666c | 327 | nn = net_generic(clp->cl_net, nfs_net_id); |
24c8dbbb | 328 | |
dc030858 | 329 | if (atomic_dec_and_lock(&clp->cl_count, &nn->nfs_client_lock)) { |
24c8dbbb | 330 | list_del(&clp->cl_share_link); |
f4eecd5d | 331 | nfs_cb_idr_remove_locked(clp); |
dc030858 | 332 | spin_unlock(&nn->nfs_client_lock); |
24c8dbbb DH |
333 | |
334 | BUG_ON(!list_empty(&clp->cl_superblocks)); | |
335 | ||
336 | nfs_free_client(clp); | |
337 | } | |
338 | } | |
16b374ca | 339 | EXPORT_SYMBOL_GPL(nfs_put_client); |
24c8dbbb | 340 | |
9082a5cc | 341 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) |
9f4c899c TM |
342 | /* |
343 | * Test if two ip6 socket addresses refer to the same socket by | |
344 | * comparing relevant fields. The padding bytes specifically, are not | |
345 | * compared. sin6_flowinfo is not compared because it only affects QoS | |
346 | * and sin6_scope_id is only compared if the address is "link local" | |
347 | * because "link local" addresses need only be unique to a specific | |
348 | * link. Conversely, ordinary unicast addresses might have different | |
349 | * sin6_scope_id. | |
350 | * | |
351 | * The caller should ensure both socket addresses are AF_INET6. | |
352 | */ | |
3c8c45df CL |
353 | static int nfs_sockaddr_match_ipaddr6(const struct sockaddr *sa1, |
354 | const struct sockaddr *sa2) | |
9f4c899c | 355 | { |
3c8c45df CL |
356 | const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sa1; |
357 | const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sa2; | |
9f4c899c | 358 | |
b9dd3abb | 359 | if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr)) |
9f4c899c | 360 | return 0; |
b9dd3abb MJ |
361 | else if (ipv6_addr_type(&sin1->sin6_addr) & IPV6_ADDR_LINKLOCAL) |
362 | return sin1->sin6_scope_id == sin2->sin6_scope_id; | |
3b0d3f93 | 363 | |
b9dd3abb | 364 | return 1; |
3b0d3f93 | 365 | } |
3c8c45df CL |
366 | #else /* !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE) */ |
367 | static int nfs_sockaddr_match_ipaddr6(const struct sockaddr *sa1, | |
368 | const struct sockaddr *sa2) | |
9f4c899c TM |
369 | { |
370 | return 0; | |
371 | } | |
9082a5cc | 372 | #endif |
3b0d3f93 | 373 | |
d7371c41 ID |
374 | /* |
375 | * Test if two ip4 socket addresses refer to the same socket, by | |
376 | * comparing relevant fields. The padding bytes specifically, are | |
377 | * not compared. | |
378 | * | |
379 | * The caller should ensure both socket addresses are AF_INET. | |
380 | */ | |
3c8c45df CL |
381 | static int nfs_sockaddr_match_ipaddr4(const struct sockaddr *sa1, |
382 | const struct sockaddr *sa2) | |
383 | { | |
384 | const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sa1; | |
385 | const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sa2; | |
386 | ||
387 | return sin1->sin_addr.s_addr == sin2->sin_addr.s_addr; | |
388 | } | |
389 | ||
390 | static int nfs_sockaddr_cmp_ip6(const struct sockaddr *sa1, | |
391 | const struct sockaddr *sa2) | |
392 | { | |
393 | const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sa1; | |
394 | const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sa2; | |
395 | ||
396 | return nfs_sockaddr_match_ipaddr6(sa1, sa2) && | |
397 | (sin1->sin6_port == sin2->sin6_port); | |
398 | } | |
399 | ||
9f4c899c TM |
400 | static int nfs_sockaddr_cmp_ip4(const struct sockaddr *sa1, |
401 | const struct sockaddr *sa2) | |
d7371c41 | 402 | { |
3c8c45df CL |
403 | const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sa1; |
404 | const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sa2; | |
9f4c899c | 405 | |
3c8c45df CL |
406 | return nfs_sockaddr_match_ipaddr4(sa1, sa2) && |
407 | (sin1->sin_port == sin2->sin_port); | |
408 | } | |
409 | ||
4b7c8dd2 | 410 | #if defined(CONFIG_NFS_V4_1) |
3c8c45df CL |
411 | /* |
412 | * Test if two socket addresses represent the same actual socket, | |
413 | * by comparing (only) relevant fields, excluding the port number. | |
414 | */ | |
415 | static int nfs_sockaddr_match_ipaddr(const struct sockaddr *sa1, | |
416 | const struct sockaddr *sa2) | |
417 | { | |
418 | if (sa1->sa_family != sa2->sa_family) | |
d7371c41 | 419 | return 0; |
3c8c45df CL |
420 | |
421 | switch (sa1->sa_family) { | |
422 | case AF_INET: | |
423 | return nfs_sockaddr_match_ipaddr4(sa1, sa2); | |
424 | case AF_INET6: | |
425 | return nfs_sockaddr_match_ipaddr6(sa1, sa2); | |
426 | } | |
427 | return 0; | |
d7371c41 | 428 | } |
4b7c8dd2 | 429 | #endif /* CONFIG_NFS_V4_1 */ |
d7371c41 | 430 | |
d7371c41 ID |
431 | /* |
432 | * Test if two socket addresses represent the same actual socket, | |
3c8c45df | 433 | * by comparing (only) relevant fields, including the port number. |
d7371c41 ID |
434 | */ |
435 | static int nfs_sockaddr_cmp(const struct sockaddr *sa1, | |
436 | const struct sockaddr *sa2) | |
437 | { | |
438 | if (sa1->sa_family != sa2->sa_family) | |
439 | return 0; | |
440 | ||
441 | switch (sa1->sa_family) { | |
442 | case AF_INET: | |
9f4c899c | 443 | return nfs_sockaddr_cmp_ip4(sa1, sa2); |
d7371c41 | 444 | case AF_INET6: |
9f4c899c | 445 | return nfs_sockaddr_cmp_ip6(sa1, sa2); |
d7371c41 ID |
446 | } |
447 | return 0; | |
448 | } | |
449 | ||
4b7c8dd2 | 450 | #if defined(CONFIG_NFS_V4_1) |
c36fca52 | 451 | /* Common match routine for v4.0 and v4.1 callback services */ |
17280175 TM |
452 | static bool nfs4_cb_match_client(const struct sockaddr *addr, |
453 | struct nfs_client *clp, u32 minorversion) | |
24c8dbbb | 454 | { |
c36fca52 | 455 | struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr; |
24c8dbbb | 456 | |
c36fca52 AA |
457 | /* Don't match clients that failed to initialise */ |
458 | if (!(clp->cl_cons_state == NFS_CS_READY || | |
459 | clp->cl_cons_state == NFS_CS_SESSION_INITING)) | |
460 | return false; | |
3b0d3f93 | 461 | |
c36fca52 AA |
462 | /* Match the version and minorversion */ |
463 | if (clp->rpc_ops->version != 4 || | |
464 | clp->cl_minorversion != minorversion) | |
465 | return false; | |
13bbc06a | 466 | |
c36fca52 AA |
467 | /* Match only the IP address, not the port number */ |
468 | if (!nfs_sockaddr_match_ipaddr(addr, clap)) | |
469 | return false; | |
24c8dbbb | 470 | |
c36fca52 | 471 | return true; |
3fbd67ad | 472 | } |
4b7c8dd2 | 473 | #endif /* CONFIG_NFS_V4_1 */ |
3fbd67ad | 474 | |
24c8dbbb | 475 | /* |
c81468a1 TM |
476 | * Find an nfs_client on the list that matches the initialisation data |
477 | * that is supplied. | |
24c8dbbb | 478 | */ |
c81468a1 | 479 | static struct nfs_client *nfs_match_client(const struct nfs_client_initdata *data) |
24c8dbbb DH |
480 | { |
481 | struct nfs_client *clp; | |
d7371c41 | 482 | const struct sockaddr *sap = data->addr; |
6b13168b | 483 | struct nfs_net *nn = net_generic(data->net, nfs_net_id); |
24c8dbbb | 484 | |
6b13168b | 485 | list_for_each_entry(clp, &nn->nfs_client_list, cl_share_link) { |
d7371c41 | 486 | const struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr; |
c81468a1 TM |
487 | /* Don't match clients that failed to initialise properly */ |
488 | if (clp->cl_cons_state < 0) | |
489 | continue; | |
490 | ||
491 | /* Different NFS versions cannot share the same nfs_client */ | |
40c55319 | 492 | if (clp->rpc_ops != data->rpc_ops) |
c81468a1 TM |
493 | continue; |
494 | ||
59dca3b2 TM |
495 | if (clp->cl_proto != data->proto) |
496 | continue; | |
5aae4a9a BH |
497 | /* Match nfsv4 minorversion */ |
498 | if (clp->cl_minorversion != data->minorversion) | |
499 | continue; | |
c81468a1 | 500 | /* Match the full socket address */ |
d7371c41 | 501 | if (!nfs_sockaddr_cmp(sap, clap)) |
c81468a1 TM |
502 | continue; |
503 | ||
504 | atomic_inc(&clp->cl_count); | |
505 | return clp; | |
13bbc06a | 506 | } |
c81468a1 | 507 | return NULL; |
24c8dbbb DH |
508 | } |
509 | ||
f411703a CL |
510 | /* |
511 | * Found an existing client. Make sure it's ready before returning. | |
512 | */ | |
513 | static struct nfs_client * | |
514 | nfs_found_client(const struct nfs_client_initdata *cl_init, | |
515 | struct nfs_client *clp) | |
516 | { | |
517 | int error; | |
518 | ||
519 | error = wait_event_killable(nfs_client_active_wq, | |
520 | clp->cl_cons_state < NFS_CS_INITING); | |
521 | if (error < 0) { | |
522 | nfs_put_client(clp); | |
523 | return ERR_PTR(-ERESTARTSYS); | |
524 | } | |
525 | ||
526 | if (clp->cl_cons_state < NFS_CS_READY) { | |
527 | error = clp->cl_cons_state; | |
528 | nfs_put_client(clp); | |
529 | return ERR_PTR(error); | |
530 | } | |
531 | ||
532 | BUG_ON(clp->cl_cons_state != NFS_CS_READY); | |
533 | ||
534 | dprintk("<-- %s found nfs_client %p for %s\n", | |
535 | __func__, clp, cl_init->hostname ?: ""); | |
536 | return clp; | |
537 | } | |
538 | ||
24c8dbbb DH |
539 | /* |
540 | * Look up a client by IP address and protocol version | |
541 | * - creates a new record if one doesn't yet exist | |
542 | */ | |
45a52a02 AA |
543 | static struct nfs_client * |
544 | nfs_get_client(const struct nfs_client_initdata *cl_init, | |
545 | const struct rpc_timeout *timeparms, | |
546 | const char *ip_addr, | |
4bf590e0 | 547 | rpc_authflavor_t authflavour) |
24c8dbbb DH |
548 | { |
549 | struct nfs_client *clp, *new = NULL; | |
6b13168b | 550 | struct nfs_net *nn = net_generic(cl_init->net, nfs_net_id); |
24c8dbbb | 551 | |
d7422c47 CL |
552 | dprintk("--> nfs_get_client(%s,v%u)\n", |
553 | cl_init->hostname ?: "", cl_init->rpc_ops->version); | |
24c8dbbb DH |
554 | |
555 | /* see if the client already exists */ | |
556 | do { | |
dc030858 | 557 | spin_lock(&nn->nfs_client_lock); |
24c8dbbb | 558 | |
c81468a1 | 559 | clp = nfs_match_client(cl_init); |
f411703a CL |
560 | if (clp) { |
561 | spin_unlock(&nn->nfs_client_lock); | |
562 | if (new) | |
563 | nfs_free_client(new); | |
564 | return nfs_found_client(cl_init, clp); | |
565 | } | |
8cab4c39 CL |
566 | if (new) { |
567 | list_add(&new->cl_share_link, &nn->nfs_client_list); | |
568 | spin_unlock(&nn->nfs_client_lock); | |
4bf590e0 | 569 | new->cl_flags = cl_init->init_flags; |
8cab4c39 CL |
570 | return cl_init->rpc_ops->init_client(new, |
571 | timeparms, ip_addr, | |
4bf590e0 | 572 | authflavour); |
8cab4c39 | 573 | } |
24c8dbbb | 574 | |
dc030858 | 575 | spin_unlock(&nn->nfs_client_lock); |
24c8dbbb | 576 | |
3a498026 | 577 | new = nfs_alloc_client(cl_init); |
a21bdd9b | 578 | } while (!IS_ERR(new)); |
24c8dbbb | 579 | |
f411703a CL |
580 | dprintk("<-- nfs_get_client() Failed to find %s (%ld)\n", |
581 | cl_init->hostname ?: "", PTR_ERR(new)); | |
a21bdd9b | 582 | return new; |
24c8dbbb DH |
583 | } |
584 | ||
585 | /* | |
586 | * Mark a server as ready or failed | |
587 | */ | |
76db6d95 | 588 | void nfs_mark_client_ready(struct nfs_client *clp, int state) |
24c8dbbb DH |
589 | { |
590 | clp->cl_cons_state = state; | |
591 | wake_up_all(&nfs_client_active_wq); | |
592 | } | |
5006a76c | 593 | |
008f55d0 BH |
594 | /* |
595 | * With sessions, the client is not marked ready until after a | |
596 | * successful EXCHANGE_ID and CREATE_SESSION. | |
597 | * | |
598 | * Map errors cl_cons_state errors to EPROTONOSUPPORT to indicate | |
599 | * other versions of NFS can be tried. | |
600 | */ | |
601 | int nfs4_check_client_ready(struct nfs_client *clp) | |
602 | { | |
603 | if (!nfs4_has_session(clp)) | |
604 | return 0; | |
605 | if (clp->cl_cons_state < NFS_CS_READY) | |
606 | return -EPROTONOSUPPORT; | |
607 | return 0; | |
608 | } | |
609 | ||
5006a76c DH |
610 | /* |
611 | * Initialise the timeout values for a connection | |
612 | */ | |
613 | static void nfs_init_timeout_values(struct rpc_timeout *to, int proto, | |
614 | unsigned int timeo, unsigned int retrans) | |
615 | { | |
616 | to->to_initval = timeo * HZ / 10; | |
617 | to->to_retries = retrans; | |
5006a76c DH |
618 | |
619 | switch (proto) { | |
0896a725 | 620 | case XPRT_TRANSPORT_TCP: |
2cf7ff7a | 621 | case XPRT_TRANSPORT_RDMA: |
259875ef TM |
622 | if (to->to_retries == 0) |
623 | to->to_retries = NFS_DEF_TCP_RETRANS; | |
7a3e3e18 | 624 | if (to->to_initval == 0) |
259875ef | 625 | to->to_initval = NFS_DEF_TCP_TIMEO * HZ / 10; |
5006a76c DH |
626 | if (to->to_initval > NFS_MAX_TCP_TIMEOUT) |
627 | to->to_initval = NFS_MAX_TCP_TIMEOUT; | |
628 | to->to_increment = to->to_initval; | |
629 | to->to_maxval = to->to_initval + (to->to_increment * to->to_retries); | |
7a3e3e18 TM |
630 | if (to->to_maxval > NFS_MAX_TCP_TIMEOUT) |
631 | to->to_maxval = NFS_MAX_TCP_TIMEOUT; | |
632 | if (to->to_maxval < to->to_initval) | |
633 | to->to_maxval = to->to_initval; | |
5006a76c DH |
634 | to->to_exponential = 0; |
635 | break; | |
0896a725 | 636 | case XPRT_TRANSPORT_UDP: |
259875ef TM |
637 | if (to->to_retries == 0) |
638 | to->to_retries = NFS_DEF_UDP_RETRANS; | |
5006a76c | 639 | if (!to->to_initval) |
259875ef | 640 | to->to_initval = NFS_DEF_UDP_TIMEO * HZ / 10; |
5006a76c DH |
641 | if (to->to_initval > NFS_MAX_UDP_TIMEOUT) |
642 | to->to_initval = NFS_MAX_UDP_TIMEOUT; | |
643 | to->to_maxval = NFS_MAX_UDP_TIMEOUT; | |
644 | to->to_exponential = 1; | |
645 | break; | |
259875ef TM |
646 | default: |
647 | BUG(); | |
5006a76c DH |
648 | } |
649 | } | |
650 | ||
651 | /* | |
652 | * Create an RPC client handle | |
653 | */ | |
59dca3b2 | 654 | static int nfs_create_rpc_client(struct nfs_client *clp, |
33170233 | 655 | const struct rpc_timeout *timeparms, |
4bf590e0 | 656 | rpc_authflavor_t flavor) |
5006a76c | 657 | { |
5006a76c | 658 | struct rpc_clnt *clnt = NULL; |
41877d20 | 659 | struct rpc_create_args args = { |
73ea666c | 660 | .net = clp->cl_net, |
59dca3b2 | 661 | .protocol = clp->cl_proto, |
41877d20 | 662 | .address = (struct sockaddr *)&clp->cl_addr, |
6e4cffd7 | 663 | .addrsize = clp->cl_addrlen, |
33170233 | 664 | .timeout = timeparms, |
41877d20 CL |
665 | .servername = clp->cl_hostname, |
666 | .program = &nfs_program, | |
667 | .version = clp->rpc_ops->version, | |
668 | .authflavor = flavor, | |
669 | }; | |
5006a76c | 670 | |
4bf590e0 | 671 | if (test_bit(NFS_CS_DISCRTRY, &clp->cl_flags)) |
4a01b8a4 | 672 | args.flags |= RPC_CLNT_CREATE_DISCRTRY; |
4bf590e0 | 673 | if (test_bit(NFS_CS_NORESVPORT, &clp->cl_flags)) |
4a01b8a4 CL |
674 | args.flags |= RPC_CLNT_CREATE_NONPRIVPORT; |
675 | ||
5006a76c DH |
676 | if (!IS_ERR(clp->cl_rpcclient)) |
677 | return 0; | |
678 | ||
41877d20 | 679 | clnt = rpc_create(&args); |
5006a76c DH |
680 | if (IS_ERR(clnt)) { |
681 | dprintk("%s: cannot create RPC client. Error = %ld\n", | |
3110ff80 | 682 | __func__, PTR_ERR(clnt)); |
5006a76c DH |
683 | return PTR_ERR(clnt); |
684 | } | |
685 | ||
5006a76c DH |
686 | clp->cl_rpcclient = clnt; |
687 | return 0; | |
688 | } | |
54ceac45 DH |
689 | |
690 | /* | |
691 | * Version 2 or 3 client destruction | |
692 | */ | |
693 | static void nfs_destroy_server(struct nfs_server *server) | |
694 | { | |
5eebde23 SJ |
695 | if (!(server->flags & NFS_MOUNT_LOCAL_FLOCK) || |
696 | !(server->flags & NFS_MOUNT_LOCAL_FCNTL)) | |
9289e7f9 | 697 | nlmclnt_done(server->nlm_host); |
54ceac45 DH |
698 | } |
699 | ||
700 | /* | |
701 | * Version 2 or 3 lockd setup | |
702 | */ | |
703 | static int nfs_start_lockd(struct nfs_server *server) | |
704 | { | |
9289e7f9 CL |
705 | struct nlm_host *host; |
706 | struct nfs_client *clp = server->nfs_client; | |
883bb163 CL |
707 | struct nlmclnt_initdata nlm_init = { |
708 | .hostname = clp->cl_hostname, | |
709 | .address = (struct sockaddr *)&clp->cl_addr, | |
710 | .addrlen = clp->cl_addrlen, | |
883bb163 | 711 | .nfs_version = clp->rpc_ops->version, |
0cb2659b CL |
712 | .noresvport = server->flags & NFS_MOUNT_NORESVPORT ? |
713 | 1 : 0, | |
73ea666c | 714 | .net = clp->cl_net, |
883bb163 | 715 | }; |
54ceac45 | 716 | |
883bb163 | 717 | if (nlm_init.nfs_version > 3) |
9289e7f9 | 718 | return 0; |
5eebde23 SJ |
719 | if ((server->flags & NFS_MOUNT_LOCAL_FLOCK) && |
720 | (server->flags & NFS_MOUNT_LOCAL_FCNTL)) | |
9289e7f9 CL |
721 | return 0; |
722 | ||
8a6e5deb TM |
723 | switch (clp->cl_proto) { |
724 | default: | |
725 | nlm_init.protocol = IPPROTO_TCP; | |
726 | break; | |
727 | case XPRT_TRANSPORT_UDP: | |
728 | nlm_init.protocol = IPPROTO_UDP; | |
729 | } | |
730 | ||
883bb163 | 731 | host = nlmclnt_init(&nlm_init); |
9289e7f9 CL |
732 | if (IS_ERR(host)) |
733 | return PTR_ERR(host); | |
734 | ||
735 | server->nlm_host = host; | |
736 | server->destroy = nfs_destroy_server; | |
737 | return 0; | |
54ceac45 DH |
738 | } |
739 | ||
740 | /* | |
741 | * Initialise an NFSv3 ACL client connection | |
742 | */ | |
743 | #ifdef CONFIG_NFS_V3_ACL | |
744 | static void nfs_init_server_aclclient(struct nfs_server *server) | |
745 | { | |
40c55319 | 746 | if (server->nfs_client->rpc_ops->version != 3) |
54ceac45 DH |
747 | goto out_noacl; |
748 | if (server->flags & NFS_MOUNT_NOACL) | |
749 | goto out_noacl; | |
750 | ||
751 | server->client_acl = rpc_bind_new_program(server->client, &nfsacl_program, 3); | |
752 | if (IS_ERR(server->client_acl)) | |
753 | goto out_noacl; | |
754 | ||
755 | /* No errors! Assume that Sun nfsacls are supported */ | |
756 | server->caps |= NFS_CAP_ACLS; | |
757 | return; | |
758 | ||
759 | out_noacl: | |
760 | server->caps &= ~NFS_CAP_ACLS; | |
761 | } | |
762 | #else | |
763 | static inline void nfs_init_server_aclclient(struct nfs_server *server) | |
764 | { | |
765 | server->flags &= ~NFS_MOUNT_NOACL; | |
766 | server->caps &= ~NFS_CAP_ACLS; | |
767 | } | |
768 | #endif | |
769 | ||
770 | /* | |
771 | * Create a general RPC client | |
772 | */ | |
33170233 TM |
773 | static int nfs_init_server_rpcclient(struct nfs_server *server, |
774 | const struct rpc_timeout *timeo, | |
775 | rpc_authflavor_t pseudoflavour) | |
54ceac45 DH |
776 | { |
777 | struct nfs_client *clp = server->nfs_client; | |
778 | ||
779 | server->client = rpc_clone_client(clp->cl_rpcclient); | |
780 | if (IS_ERR(server->client)) { | |
3110ff80 | 781 | dprintk("%s: couldn't create rpc_client!\n", __func__); |
54ceac45 DH |
782 | return PTR_ERR(server->client); |
783 | } | |
784 | ||
33170233 TM |
785 | memcpy(&server->client->cl_timeout_default, |
786 | timeo, | |
787 | sizeof(server->client->cl_timeout_default)); | |
788 | server->client->cl_timeout = &server->client->cl_timeout_default; | |
789 | ||
54ceac45 DH |
790 | if (pseudoflavour != clp->cl_rpcclient->cl_auth->au_flavor) { |
791 | struct rpc_auth *auth; | |
792 | ||
793 | auth = rpcauth_create(pseudoflavour, server->client); | |
794 | if (IS_ERR(auth)) { | |
3110ff80 | 795 | dprintk("%s: couldn't create credcache!\n", __func__); |
54ceac45 DH |
796 | return PTR_ERR(auth); |
797 | } | |
798 | } | |
799 | server->client->cl_softrtry = 0; | |
800 | if (server->flags & NFS_MOUNT_SOFT) | |
801 | server->client->cl_softrtry = 1; | |
802 | ||
54ceac45 DH |
803 | return 0; |
804 | } | |
805 | ||
8cab4c39 CL |
806 | /** |
807 | * nfs_init_client - Initialise an NFS2 or NFS3 client | |
808 | * | |
809 | * @clp: nfs_client to initialise | |
810 | * @timeparms: timeout parameters for underlying RPC transport | |
811 | * @ip_addr: IP presentation address (not used) | |
812 | * @authflavor: authentication flavor for underlying RPC transport | |
8cab4c39 CL |
813 | * |
814 | * Returns pointer to an NFS client, or an ERR_PTR value. | |
54ceac45 | 815 | */ |
8cab4c39 CL |
816 | struct nfs_client *nfs_init_client(struct nfs_client *clp, |
817 | const struct rpc_timeout *timeparms, | |
4bf590e0 | 818 | const char *ip_addr, rpc_authflavor_t authflavour) |
54ceac45 | 819 | { |
54ceac45 DH |
820 | int error; |
821 | ||
822 | if (clp->cl_cons_state == NFS_CS_READY) { | |
823 | /* the client is already initialised */ | |
824 | dprintk("<-- nfs_init_client() = 0 [already %p]\n", clp); | |
8cab4c39 | 825 | return clp; |
54ceac45 DH |
826 | } |
827 | ||
54ceac45 DH |
828 | /* |
829 | * Create a client RPC handle for doing FSSTAT with UNIX auth only | |
830 | * - RFC 2623, sec 2.3.2 | |
831 | */ | |
4bf590e0 | 832 | error = nfs_create_rpc_client(clp, timeparms, RPC_AUTH_UNIX); |
54ceac45 DH |
833 | if (error < 0) |
834 | goto error; | |
835 | nfs_mark_client_ready(clp, NFS_CS_READY); | |
8cab4c39 | 836 | return clp; |
54ceac45 DH |
837 | |
838 | error: | |
839 | nfs_mark_client_ready(clp, error); | |
8cab4c39 | 840 | nfs_put_client(clp); |
54ceac45 | 841 | dprintk("<-- nfs_init_client() = xerror %d\n", error); |
8cab4c39 | 842 | return ERR_PTR(error); |
54ceac45 DH |
843 | } |
844 | ||
845 | /* | |
846 | * Create a version 2 or 3 client | |
847 | */ | |
2283f8d6 TT |
848 | static int nfs_init_server(struct nfs_server *server, |
849 | const struct nfs_parsed_mount_data *data) | |
54ceac45 | 850 | { |
3a498026 TM |
851 | struct nfs_client_initdata cl_init = { |
852 | .hostname = data->nfs_server.hostname, | |
d7422c47 | 853 | .addr = (const struct sockaddr *)&data->nfs_server.address, |
4c568017 | 854 | .addrlen = data->nfs_server.addrlen, |
2ba68002 | 855 | .rpc_ops = NULL, |
59dca3b2 | 856 | .proto = data->nfs_server.protocol, |
e50a7a1a | 857 | .net = data->net, |
3a498026 | 858 | }; |
33170233 | 859 | struct rpc_timeout timeparms; |
54ceac45 | 860 | struct nfs_client *clp; |
3a498026 | 861 | int error; |
54ceac45 DH |
862 | |
863 | dprintk("--> nfs_init_server()\n"); | |
864 | ||
2ba68002 BS |
865 | switch (data->version) { |
866 | #ifdef CONFIG_NFS_V2 | |
867 | case 2: | |
868 | cl_init.rpc_ops = &nfs_v2_clientops; | |
869 | break; | |
870 | #endif | |
54ceac45 | 871 | #ifdef CONFIG_NFS_V3 |
2ba68002 | 872 | case 3: |
40c55319 | 873 | cl_init.rpc_ops = &nfs_v3_clientops; |
2ba68002 | 874 | break; |
54ceac45 | 875 | #endif |
2ba68002 BS |
876 | default: |
877 | return -EPROTONOSUPPORT; | |
878 | } | |
54ceac45 | 879 | |
45a52a02 AA |
880 | nfs_init_timeout_values(&timeparms, data->nfs_server.protocol, |
881 | data->timeo, data->retrans); | |
4bf590e0 CL |
882 | if (data->flags & NFS_MOUNT_NORESVPORT) |
883 | set_bit(NFS_CS_NORESVPORT, &cl_init.init_flags); | |
45a52a02 | 884 | |
54ceac45 | 885 | /* Allocate or find a client reference we can use */ |
4bf590e0 | 886 | clp = nfs_get_client(&cl_init, &timeparms, NULL, RPC_AUTH_UNIX); |
54ceac45 DH |
887 | if (IS_ERR(clp)) { |
888 | dprintk("<-- nfs_init_server() = error %ld\n", PTR_ERR(clp)); | |
889 | return PTR_ERR(clp); | |
890 | } | |
891 | ||
54ceac45 DH |
892 | server->nfs_client = clp; |
893 | ||
894 | /* Initialise the client representation from the mount data */ | |
ff3525a5 | 895 | server->flags = data->flags; |
b797cac7 | 896 | server->options = data->options; |
62ab460c TM |
897 | server->caps |= NFS_CAP_HARDLINKS|NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
898 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER|NFS_CAP_OWNER_GROUP| | |
3a1556e8 | 899 | NFS_CAP_ATIME|NFS_CAP_CTIME|NFS_CAP_MTIME|NFS_CAP_CHANGE_ATTR; |
54ceac45 DH |
900 | |
901 | if (data->rsize) | |
902 | server->rsize = nfs_block_size(data->rsize, NULL); | |
903 | if (data->wsize) | |
904 | server->wsize = nfs_block_size(data->wsize, NULL); | |
905 | ||
906 | server->acregmin = data->acregmin * HZ; | |
907 | server->acregmax = data->acregmax * HZ; | |
908 | server->acdirmin = data->acdirmin * HZ; | |
909 | server->acdirmax = data->acdirmax * HZ; | |
910 | ||
911 | /* Start lockd here, before we might error out */ | |
912 | error = nfs_start_lockd(server); | |
913 | if (error < 0) | |
914 | goto error; | |
915 | ||
f22d6d79 CL |
916 | server->port = data->nfs_server.port; |
917 | ||
33170233 | 918 | error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]); |
54ceac45 DH |
919 | if (error < 0) |
920 | goto error; | |
921 | ||
3f8400d1 CL |
922 | /* Preserve the values of mount_server-related mount options */ |
923 | if (data->mount_server.addrlen) { | |
924 | memcpy(&server->mountd_address, &data->mount_server.address, | |
925 | data->mount_server.addrlen); | |
926 | server->mountd_addrlen = data->mount_server.addrlen; | |
927 | } | |
928 | server->mountd_version = data->mount_server.version; | |
929 | server->mountd_port = data->mount_server.port; | |
930 | server->mountd_protocol = data->mount_server.protocol; | |
931 | ||
54ceac45 DH |
932 | server->namelen = data->namlen; |
933 | /* Create a client RPC handle for the NFSv3 ACL management interface */ | |
934 | nfs_init_server_aclclient(server); | |
54ceac45 DH |
935 | dprintk("<-- nfs_init_server() = 0 [new %p]\n", clp); |
936 | return 0; | |
937 | ||
938 | error: | |
939 | server->nfs_client = NULL; | |
940 | nfs_put_client(clp); | |
941 | dprintk("<-- nfs_init_server() = xerror %d\n", error); | |
942 | return error; | |
943 | } | |
944 | ||
945 | /* | |
946 | * Load up the server record from information gained in an fsinfo record | |
947 | */ | |
738fd0f3 BH |
948 | static void nfs_server_set_fsinfo(struct nfs_server *server, |
949 | struct nfs_fh *mntfh, | |
950 | struct nfs_fsinfo *fsinfo) | |
54ceac45 DH |
951 | { |
952 | unsigned long max_rpc_payload; | |
953 | ||
954 | /* Work out a lot of parameters */ | |
955 | if (server->rsize == 0) | |
956 | server->rsize = nfs_block_size(fsinfo->rtpref, NULL); | |
957 | if (server->wsize == 0) | |
958 | server->wsize = nfs_block_size(fsinfo->wtpref, NULL); | |
959 | ||
960 | if (fsinfo->rtmax >= 512 && server->rsize > fsinfo->rtmax) | |
961 | server->rsize = nfs_block_size(fsinfo->rtmax, NULL); | |
962 | if (fsinfo->wtmax >= 512 && server->wsize > fsinfo->wtmax) | |
963 | server->wsize = nfs_block_size(fsinfo->wtmax, NULL); | |
964 | ||
965 | max_rpc_payload = nfs_block_size(rpc_max_payload(server->client), NULL); | |
966 | if (server->rsize > max_rpc_payload) | |
967 | server->rsize = max_rpc_payload; | |
968 | if (server->rsize > NFS_MAX_FILE_IO_SIZE) | |
969 | server->rsize = NFS_MAX_FILE_IO_SIZE; | |
970 | server->rpages = (server->rsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; | |
e0bf68dd | 971 | |
d993831f | 972 | server->backing_dev_info.name = "nfs"; |
54ceac45 DH |
973 | server->backing_dev_info.ra_pages = server->rpages * NFS_MAX_READAHEAD; |
974 | ||
975 | if (server->wsize > max_rpc_payload) | |
976 | server->wsize = max_rpc_payload; | |
977 | if (server->wsize > NFS_MAX_FILE_IO_SIZE) | |
978 | server->wsize = NFS_MAX_FILE_IO_SIZE; | |
979 | server->wpages = (server->wsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; | |
dae100c2 | 980 | server->pnfs_blksize = fsinfo->blksize; |
738fd0f3 | 981 | set_pnfs_layoutdriver(server, mntfh, fsinfo->layouttype); |
85e174ba | 982 | |
54ceac45 DH |
983 | server->wtmult = nfs_block_bits(fsinfo->wtmult, NULL); |
984 | ||
985 | server->dtsize = nfs_block_size(fsinfo->dtpref, NULL); | |
56e4ebf8 BS |
986 | if (server->dtsize > PAGE_CACHE_SIZE * NFS_MAX_READDIR_PAGES) |
987 | server->dtsize = PAGE_CACHE_SIZE * NFS_MAX_READDIR_PAGES; | |
54ceac45 DH |
988 | if (server->dtsize > server->rsize) |
989 | server->dtsize = server->rsize; | |
990 | ||
991 | if (server->flags & NFS_MOUNT_NOAC) { | |
992 | server->acregmin = server->acregmax = 0; | |
993 | server->acdirmin = server->acdirmax = 0; | |
994 | } | |
995 | ||
996 | server->maxfilesize = fsinfo->maxfilesize; | |
997 | ||
6b96724e RL |
998 | server->time_delta = fsinfo->time_delta; |
999 | ||
54ceac45 DH |
1000 | /* We're airborne Set socket buffersize */ |
1001 | rpc_setbufsize(server->client, server->wsize + 100, server->rsize + 100); | |
1002 | } | |
1003 | ||
1004 | /* | |
1005 | * Probe filesystem information, including the FSID on v2/v3 | |
1006 | */ | |
1007 | static int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *mntfh, struct nfs_fattr *fattr) | |
1008 | { | |
1009 | struct nfs_fsinfo fsinfo; | |
1010 | struct nfs_client *clp = server->nfs_client; | |
1011 | int error; | |
1012 | ||
1013 | dprintk("--> nfs_probe_fsinfo()\n"); | |
1014 | ||
1015 | if (clp->rpc_ops->set_capabilities != NULL) { | |
1016 | error = clp->rpc_ops->set_capabilities(server, mntfh); | |
1017 | if (error < 0) | |
1018 | goto out_error; | |
1019 | } | |
1020 | ||
1021 | fsinfo.fattr = fattr; | |
85e174ba | 1022 | fsinfo.layouttype = 0; |
54ceac45 DH |
1023 | error = clp->rpc_ops->fsinfo(server, mntfh, &fsinfo); |
1024 | if (error < 0) | |
1025 | goto out_error; | |
1026 | ||
738fd0f3 | 1027 | nfs_server_set_fsinfo(server, mntfh, &fsinfo); |
54ceac45 DH |
1028 | |
1029 | /* Get some general file system info */ | |
1030 | if (server->namelen == 0) { | |
1031 | struct nfs_pathconf pathinfo; | |
1032 | ||
1033 | pathinfo.fattr = fattr; | |
1034 | nfs_fattr_init(fattr); | |
1035 | ||
1036 | if (clp->rpc_ops->pathconf(server, mntfh, &pathinfo) >= 0) | |
1037 | server->namelen = pathinfo.max_namelen; | |
1038 | } | |
1039 | ||
1040 | dprintk("<-- nfs_probe_fsinfo() = 0\n"); | |
1041 | return 0; | |
1042 | ||
1043 | out_error: | |
1044 | dprintk("nfs_probe_fsinfo: error = %d\n", -error); | |
1045 | return error; | |
1046 | } | |
1047 | ||
1048 | /* | |
1049 | * Copy useful information when duplicating a server record | |
1050 | */ | |
1051 | static void nfs_server_copy_userdata(struct nfs_server *target, struct nfs_server *source) | |
1052 | { | |
1053 | target->flags = source->flags; | |
356e76b8 CL |
1054 | target->rsize = source->rsize; |
1055 | target->wsize = source->wsize; | |
54ceac45 DH |
1056 | target->acregmin = source->acregmin; |
1057 | target->acregmax = source->acregmax; | |
1058 | target->acdirmin = source->acdirmin; | |
1059 | target->acdirmax = source->acdirmax; | |
1060 | target->caps = source->caps; | |
2df54806 | 1061 | target->options = source->options; |
54ceac45 DH |
1062 | } |
1063 | ||
fca5238e CL |
1064 | static void nfs_server_insert_lists(struct nfs_server *server) |
1065 | { | |
1066 | struct nfs_client *clp = server->nfs_client; | |
73ea666c | 1067 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
fca5238e | 1068 | |
dc030858 | 1069 | spin_lock(&nn->nfs_client_lock); |
fca5238e | 1070 | list_add_tail_rcu(&server->client_link, &clp->cl_superblocks); |
c25d32b2 | 1071 | list_add_tail(&server->master_link, &nn->nfs_volume_list); |
d3b4c9d7 | 1072 | clear_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state); |
dc030858 | 1073 | spin_unlock(&nn->nfs_client_lock); |
fca5238e CL |
1074 | |
1075 | } | |
1076 | ||
1077 | static void nfs_server_remove_lists(struct nfs_server *server) | |
1078 | { | |
d3b4c9d7 | 1079 | struct nfs_client *clp = server->nfs_client; |
4c03ae4a | 1080 | struct nfs_net *nn; |
d3b4c9d7 | 1081 | |
4c03ae4a TM |
1082 | if (clp == NULL) |
1083 | return; | |
73ea666c | 1084 | nn = net_generic(clp->cl_net, nfs_net_id); |
dc030858 | 1085 | spin_lock(&nn->nfs_client_lock); |
fca5238e | 1086 | list_del_rcu(&server->client_link); |
4c03ae4a | 1087 | if (list_empty(&clp->cl_superblocks)) |
d3b4c9d7 | 1088 | set_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state); |
fca5238e | 1089 | list_del(&server->master_link); |
dc030858 | 1090 | spin_unlock(&nn->nfs_client_lock); |
fca5238e CL |
1091 | |
1092 | synchronize_rcu(); | |
1093 | } | |
1094 | ||
54ceac45 DH |
1095 | /* |
1096 | * Allocate and initialise a server record | |
1097 | */ | |
1098 | static struct nfs_server *nfs_alloc_server(void) | |
1099 | { | |
1100 | struct nfs_server *server; | |
1101 | ||
1102 | server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL); | |
1103 | if (!server) | |
1104 | return NULL; | |
1105 | ||
1106 | server->client = server->client_acl = ERR_PTR(-EINVAL); | |
1107 | ||
1108 | /* Zero out the NFS state stuff */ | |
1109 | INIT_LIST_HEAD(&server->client_link); | |
1110 | INIT_LIST_HEAD(&server->master_link); | |
d3978bb3 | 1111 | INIT_LIST_HEAD(&server->delegations); |
6382a441 | 1112 | INIT_LIST_HEAD(&server->layouts); |
0aaaf5c4 | 1113 | INIT_LIST_HEAD(&server->state_owners_lru); |
54ceac45 | 1114 | |
ef818a28 SD |
1115 | atomic_set(&server->active, 0); |
1116 | ||
54ceac45 DH |
1117 | server->io_stats = nfs_alloc_iostats(); |
1118 | if (!server->io_stats) { | |
1119 | kfree(server); | |
1120 | return NULL; | |
1121 | } | |
1122 | ||
48d07649 JA |
1123 | if (bdi_init(&server->backing_dev_info)) { |
1124 | nfs_free_iostats(server->io_stats); | |
1125 | kfree(server); | |
1126 | return NULL; | |
1127 | } | |
1128 | ||
9157c31d | 1129 | ida_init(&server->openowner_id); |
d2d7ce28 | 1130 | ida_init(&server->lockowner_id); |
f7e8917a FI |
1131 | pnfs_init_server(server); |
1132 | ||
54ceac45 DH |
1133 | return server; |
1134 | } | |
1135 | ||
1136 | /* | |
1137 | * Free up a server record | |
1138 | */ | |
1139 | void nfs_free_server(struct nfs_server *server) | |
1140 | { | |
1141 | dprintk("--> nfs_free_server()\n"); | |
1142 | ||
fca5238e | 1143 | nfs_server_remove_lists(server); |
85e174ba | 1144 | unset_pnfs_layoutdriver(server); |
54ceac45 DH |
1145 | |
1146 | if (server->destroy != NULL) | |
1147 | server->destroy(server); | |
5cef338b TM |
1148 | |
1149 | if (!IS_ERR(server->client_acl)) | |
1150 | rpc_shutdown_client(server->client_acl); | |
54ceac45 DH |
1151 | if (!IS_ERR(server->client)) |
1152 | rpc_shutdown_client(server->client); | |
1153 | ||
1154 | nfs_put_client(server->nfs_client); | |
1155 | ||
d2d7ce28 | 1156 | ida_destroy(&server->lockowner_id); |
9157c31d | 1157 | ida_destroy(&server->openowner_id); |
54ceac45 | 1158 | nfs_free_iostats(server->io_stats); |
e0bf68dd | 1159 | bdi_destroy(&server->backing_dev_info); |
54ceac45 DH |
1160 | kfree(server); |
1161 | nfs_release_automount_timer(); | |
1162 | dprintk("<-- nfs_free_server()\n"); | |
1163 | } | |
1164 | ||
1165 | /* | |
1166 | * Create a version 2 or 3 volume record | |
1167 | * - keyed on server and FSID | |
1168 | */ | |
2283f8d6 | 1169 | struct nfs_server *nfs_create_server(const struct nfs_parsed_mount_data *data, |
54ceac45 DH |
1170 | struct nfs_fh *mntfh) |
1171 | { | |
1172 | struct nfs_server *server; | |
fbca779a | 1173 | struct nfs_fattr *fattr; |
54ceac45 DH |
1174 | int error; |
1175 | ||
1176 | server = nfs_alloc_server(); | |
1177 | if (!server) | |
1178 | return ERR_PTR(-ENOMEM); | |
1179 | ||
fbca779a TM |
1180 | error = -ENOMEM; |
1181 | fattr = nfs_alloc_fattr(); | |
1182 | if (fattr == NULL) | |
1183 | goto error; | |
1184 | ||
54ceac45 DH |
1185 | /* Get a client representation */ |
1186 | error = nfs_init_server(server, data); | |
1187 | if (error < 0) | |
1188 | goto error; | |
1189 | ||
1190 | BUG_ON(!server->nfs_client); | |
1191 | BUG_ON(!server->nfs_client->rpc_ops); | |
1192 | BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops); | |
1193 | ||
1194 | /* Probe the root fh to retrieve its FSID */ | |
fbca779a | 1195 | error = nfs_probe_fsinfo(server, mntfh, fattr); |
54ceac45 DH |
1196 | if (error < 0) |
1197 | goto error; | |
54af3bb5 TM |
1198 | if (server->nfs_client->rpc_ops->version == 3) { |
1199 | if (server->namelen == 0 || server->namelen > NFS3_MAXNAMLEN) | |
1200 | server->namelen = NFS3_MAXNAMLEN; | |
1201 | if (!(data->flags & NFS_MOUNT_NORDIRPLUS)) | |
1202 | server->caps |= NFS_CAP_READDIRPLUS; | |
1203 | } else { | |
1204 | if (server->namelen == 0 || server->namelen > NFS2_MAXNAMLEN) | |
1205 | server->namelen = NFS2_MAXNAMLEN; | |
1206 | } | |
1207 | ||
fbca779a TM |
1208 | if (!(fattr->valid & NFS_ATTR_FATTR)) { |
1209 | error = server->nfs_client->rpc_ops->getattr(server, mntfh, fattr); | |
54ceac45 DH |
1210 | if (error < 0) { |
1211 | dprintk("nfs_create_server: getattr error = %d\n", -error); | |
1212 | goto error; | |
1213 | } | |
1214 | } | |
fbca779a | 1215 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
54ceac45 | 1216 | |
6daabf1b DH |
1217 | dprintk("Server FSID: %llx:%llx\n", |
1218 | (unsigned long long) server->fsid.major, | |
1219 | (unsigned long long) server->fsid.minor); | |
54ceac45 | 1220 | |
fca5238e | 1221 | nfs_server_insert_lists(server); |
54ceac45 | 1222 | server->mount_time = jiffies; |
fbca779a | 1223 | nfs_free_fattr(fattr); |
54ceac45 DH |
1224 | return server; |
1225 | ||
1226 | error: | |
fbca779a | 1227 | nfs_free_fattr(fattr); |
54ceac45 DH |
1228 | nfs_free_server(server); |
1229 | return ERR_PTR(error); | |
1230 | } | |
1231 | ||
1232 | #ifdef CONFIG_NFS_V4 | |
c36fca52 AA |
1233 | /* |
1234 | * NFSv4.0 callback thread helper | |
1235 | * | |
1236 | * Find a client by callback identifier | |
1237 | */ | |
1238 | struct nfs_client * | |
28cd1b3f | 1239 | nfs4_find_client_ident(struct net *net, int cb_ident) |
c36fca52 AA |
1240 | { |
1241 | struct nfs_client *clp; | |
28cd1b3f | 1242 | struct nfs_net *nn = net_generic(net, nfs_net_id); |
c36fca52 | 1243 | |
dc030858 | 1244 | spin_lock(&nn->nfs_client_lock); |
28cd1b3f | 1245 | clp = idr_find(&nn->cb_ident_idr, cb_ident); |
c36fca52 AA |
1246 | if (clp) |
1247 | atomic_inc(&clp->cl_count); | |
dc030858 | 1248 | spin_unlock(&nn->nfs_client_lock); |
c36fca52 AA |
1249 | return clp; |
1250 | } | |
1251 | ||
1252 | #if defined(CONFIG_NFS_V4_1) | |
1253 | /* | |
1254 | * NFSv4.1 callback thread helper | |
1255 | * For CB_COMPOUND calls, find a client by IP address, protocol version, | |
1256 | * minorversion, and sessionID | |
1257 | * | |
c36fca52 AA |
1258 | * Returns NULL if no such client |
1259 | */ | |
1260 | struct nfs_client * | |
c7add9a9 | 1261 | nfs4_find_client_sessionid(struct net *net, const struct sockaddr *addr, |
778be232 | 1262 | struct nfs4_sessionid *sid) |
c36fca52 AA |
1263 | { |
1264 | struct nfs_client *clp; | |
c7add9a9 | 1265 | struct nfs_net *nn = net_generic(net, nfs_net_id); |
c36fca52 | 1266 | |
dc030858 | 1267 | spin_lock(&nn->nfs_client_lock); |
6b13168b | 1268 | list_for_each_entry(clp, &nn->nfs_client_list, cl_share_link) { |
c36fca52 AA |
1269 | if (nfs4_cb_match_client(addr, clp, 1) == false) |
1270 | continue; | |
1271 | ||
1272 | if (!nfs4_has_session(clp)) | |
1273 | continue; | |
1274 | ||
778be232 AA |
1275 | /* Match sessionid*/ |
1276 | if (memcmp(clp->cl_session->sess_id.data, | |
1277 | sid->data, NFS4_MAX_SESSIONID_LEN) != 0) | |
c36fca52 AA |
1278 | continue; |
1279 | ||
1280 | atomic_inc(&clp->cl_count); | |
dc030858 | 1281 | spin_unlock(&nn->nfs_client_lock); |
c36fca52 AA |
1282 | return clp; |
1283 | } | |
dc030858 | 1284 | spin_unlock(&nn->nfs_client_lock); |
c36fca52 AA |
1285 | return NULL; |
1286 | } | |
1287 | ||
1288 | #else /* CONFIG_NFS_V4_1 */ | |
1289 | ||
1290 | struct nfs_client * | |
b6d1e83b | 1291 | nfs4_find_client_sessionid(struct net *net, const struct sockaddr *addr, |
778be232 | 1292 | struct nfs4_sessionid *sid) |
c36fca52 AA |
1293 | { |
1294 | return NULL; | |
1295 | } | |
1296 | #endif /* CONFIG_NFS_V4_1 */ | |
1297 | ||
9bdaa86d BH |
1298 | /* |
1299 | * Initialize the NFS4 callback service | |
1300 | */ | |
1301 | static int nfs4_init_callback(struct nfs_client *clp) | |
1302 | { | |
1303 | int error; | |
1304 | ||
1305 | if (clp->rpc_ops->version == 4) { | |
2446ab60 TM |
1306 | struct rpc_xprt *xprt; |
1307 | ||
1308 | xprt = rcu_dereference_raw(clp->cl_rpcclient->cl_xprt); | |
1309 | ||
0b5b7ae0 | 1310 | if (nfs4_has_session(clp)) { |
2446ab60 | 1311 | error = xprt_setup_backchannel(xprt, |
0b5b7ae0 AA |
1312 | NFS41_BC_MIN_CALLBACKS); |
1313 | if (error < 0) | |
1314 | return error; | |
1315 | } | |
1316 | ||
2446ab60 | 1317 | error = nfs_callback_up(clp->cl_mvops->minor_version, xprt); |
9bdaa86d BH |
1318 | if (error < 0) { |
1319 | dprintk("%s: failed to start callback. Error = %d\n", | |
1320 | __func__, error); | |
1321 | return error; | |
1322 | } | |
1323 | __set_bit(NFS_CS_CALLBACK, &clp->cl_res_state); | |
1324 | } | |
1325 | return 0; | |
1326 | } | |
1327 | ||
557134a3 AA |
1328 | /* |
1329 | * Initialize the minor version specific parts of an NFS4 client record | |
1330 | */ | |
1331 | static int nfs4_init_client_minor_version(struct nfs_client *clp) | |
1332 | { | |
1333 | #if defined(CONFIG_NFS_V4_1) | |
97dc1359 | 1334 | if (clp->cl_mvops->minor_version) { |
557134a3 AA |
1335 | struct nfs4_session *session = NULL; |
1336 | /* | |
1337 | * Create the session and mark it expired. | |
1338 | * When a SEQUENCE operation encounters the expired session | |
1339 | * it will do session recovery to initialize it. | |
1340 | */ | |
1341 | session = nfs4_alloc_session(clp); | |
1342 | if (!session) | |
1343 | return -ENOMEM; | |
1344 | ||
1345 | clp->cl_session = session; | |
fe74ba3a TM |
1346 | /* |
1347 | * The create session reply races with the server back | |
1348 | * channel probe. Mark the client NFS_CS_SESSION_INITING | |
1349 | * so that the client back channel can find the | |
1350 | * nfs_client struct | |
1351 | */ | |
1352 | clp->cl_cons_state = NFS_CS_SESSION_INITING; | |
557134a3 AA |
1353 | } |
1354 | #endif /* CONFIG_NFS_V4_1 */ | |
1355 | ||
71468513 | 1356 | return nfs4_init_callback(clp); |
557134a3 AA |
1357 | } |
1358 | ||
8cab4c39 CL |
1359 | /** |
1360 | * nfs4_init_client - Initialise an NFS4 client record | |
1361 | * | |
1362 | * @clp: nfs_client to initialise | |
1363 | * @timeparms: timeout parameters for underlying RPC transport | |
1364 | * @ip_addr: callback IP address in presentation format | |
1365 | * @authflavor: authentication flavor for underlying RPC transport | |
8cab4c39 CL |
1366 | * |
1367 | * Returns pointer to an NFS client, or an ERR_PTR value. | |
54ceac45 | 1368 | */ |
8cab4c39 CL |
1369 | struct nfs_client *nfs4_init_client(struct nfs_client *clp, |
1370 | const struct rpc_timeout *timeparms, | |
1371 | const char *ip_addr, | |
4bf590e0 | 1372 | rpc_authflavor_t authflavour) |
54ceac45 | 1373 | { |
31b8e2ae | 1374 | char buf[INET6_ADDRSTRLEN + 1]; |
54ceac45 DH |
1375 | int error; |
1376 | ||
1377 | if (clp->cl_cons_state == NFS_CS_READY) { | |
1378 | /* the client is initialised already */ | |
1379 | dprintk("<-- nfs4_init_client() = 0 [already %p]\n", clp); | |
8cab4c39 | 1380 | return clp; |
54ceac45 DH |
1381 | } |
1382 | ||
1383 | /* Check NFS protocol revision and initialize RPC op vector */ | |
1384 | clp->rpc_ops = &nfs_v4_clientops; | |
1385 | ||
4bf590e0 CL |
1386 | __set_bit(NFS_CS_DISCRTRY, &clp->cl_flags); |
1387 | error = nfs_create_rpc_client(clp, timeparms, authflavour); | |
54ceac45 DH |
1388 | if (error < 0) |
1389 | goto error; | |
31b8e2ae CL |
1390 | |
1391 | /* If no clientaddr= option was specified, find a usable cb address */ | |
1392 | if (ip_addr == NULL) { | |
1393 | struct sockaddr_storage cb_addr; | |
1394 | struct sockaddr *sap = (struct sockaddr *)&cb_addr; | |
1395 | ||
1396 | error = rpc_localaddr(clp->cl_rpcclient, sap, sizeof(cb_addr)); | |
1397 | if (error < 0) | |
1398 | goto error; | |
1399 | error = rpc_ntop(sap, buf, sizeof(buf)); | |
1400 | if (error < 0) | |
1401 | goto error; | |
1402 | ip_addr = (const char *)buf; | |
1403 | } | |
f4373bf9 | 1404 | strlcpy(clp->cl_ipaddr, ip_addr, sizeof(clp->cl_ipaddr)); |
54ceac45 DH |
1405 | |
1406 | error = nfs_idmap_new(clp); | |
1407 | if (error < 0) { | |
1408 | dprintk("%s: failed to create idmapper. Error = %d\n", | |
3110ff80 | 1409 | __func__, error); |
54ceac45 DH |
1410 | goto error; |
1411 | } | |
9c5bf38d | 1412 | __set_bit(NFS_CS_IDMAP, &clp->cl_res_state); |
54ceac45 | 1413 | |
557134a3 AA |
1414 | error = nfs4_init_client_minor_version(clp); |
1415 | if (error < 0) | |
1416 | goto error; | |
1417 | ||
76db6d95 AA |
1418 | if (!nfs4_has_session(clp)) |
1419 | nfs_mark_client_ready(clp, NFS_CS_READY); | |
8cab4c39 | 1420 | return clp; |
54ceac45 DH |
1421 | |
1422 | error: | |
1423 | nfs_mark_client_ready(clp, error); | |
8cab4c39 | 1424 | nfs_put_client(clp); |
54ceac45 | 1425 | dprintk("<-- nfs4_init_client() = xerror %d\n", error); |
8cab4c39 | 1426 | return ERR_PTR(error); |
54ceac45 DH |
1427 | } |
1428 | ||
1429 | /* | |
1430 | * Set up an NFS4 client | |
1431 | */ | |
1432 | static int nfs4_set_client(struct nfs_server *server, | |
dcecae0f CL |
1433 | const char *hostname, |
1434 | const struct sockaddr *addr, | |
1435 | const size_t addrlen, | |
7d9ac06f | 1436 | const char *ip_addr, |
54ceac45 | 1437 | rpc_authflavor_t authflavour, |
94a417f3 | 1438 | int proto, const struct rpc_timeout *timeparms, |
e50a7a1a | 1439 | u32 minorversion, struct net *net) |
54ceac45 | 1440 | { |
3a498026 TM |
1441 | struct nfs_client_initdata cl_init = { |
1442 | .hostname = hostname, | |
dcecae0f CL |
1443 | .addr = addr, |
1444 | .addrlen = addrlen, | |
40c55319 | 1445 | .rpc_ops = &nfs_v4_clientops, |
59dca3b2 | 1446 | .proto = proto, |
5aae4a9a | 1447 | .minorversion = minorversion, |
e50a7a1a | 1448 | .net = net, |
3a498026 | 1449 | }; |
54ceac45 DH |
1450 | struct nfs_client *clp; |
1451 | int error; | |
1452 | ||
1453 | dprintk("--> nfs4_set_client()\n"); | |
1454 | ||
4bf590e0 CL |
1455 | if (server->flags & NFS_MOUNT_NORESVPORT) |
1456 | set_bit(NFS_CS_NORESVPORT, &cl_init.init_flags); | |
1457 | ||
54ceac45 | 1458 | /* Allocate or find a client reference we can use */ |
4bf590e0 | 1459 | clp = nfs_get_client(&cl_init, timeparms, ip_addr, authflavour); |
54ceac45 DH |
1460 | if (IS_ERR(clp)) { |
1461 | error = PTR_ERR(clp); | |
1462 | goto error; | |
1463 | } | |
54ceac45 | 1464 | |
d6fb79d4 AA |
1465 | /* |
1466 | * Query for the lease time on clientid setup or renewal | |
1467 | * | |
1468 | * Note that this will be set on nfs_clients that were created | |
1469 | * only for the DS role and did not set this bit, but now will | |
1470 | * serve a dual role. | |
1471 | */ | |
1472 | set_bit(NFS_CS_CHECK_LEASE_TIME, &clp->cl_res_state); | |
1473 | ||
54ceac45 DH |
1474 | server->nfs_client = clp; |
1475 | dprintk("<-- nfs4_set_client() = 0 [new %p]\n", clp); | |
1476 | return 0; | |
54ceac45 DH |
1477 | error: |
1478 | dprintk("<-- nfs4_set_client() = xerror %d\n", error); | |
1479 | return error; | |
1480 | } | |
1481 | ||
d83217c1 AA |
1482 | /* |
1483 | * Set up a pNFS Data Server client. | |
1484 | * | |
1485 | * Return any existing nfs_client that matches server address,port,version | |
1486 | * and minorversion. | |
1487 | * | |
1488 | * For a new nfs_client, use a soft mount (default), a low retrans and a | |
1489 | * low timeout interval so that if a connection is lost, we retry through | |
1490 | * the MDS. | |
1491 | */ | |
1492 | struct nfs_client *nfs4_set_ds_client(struct nfs_client* mds_clp, | |
98fc685a AA |
1493 | const struct sockaddr *ds_addr, int ds_addrlen, |
1494 | int ds_proto, unsigned int ds_timeo, unsigned int ds_retrans) | |
d83217c1 AA |
1495 | { |
1496 | struct nfs_client_initdata cl_init = { | |
1497 | .addr = ds_addr, | |
1498 | .addrlen = ds_addrlen, | |
1499 | .rpc_ops = &nfs_v4_clientops, | |
1500 | .proto = ds_proto, | |
1501 | .minorversion = mds_clp->cl_minorversion, | |
73ea666c | 1502 | .net = mds_clp->cl_net, |
d83217c1 | 1503 | }; |
98fc685a | 1504 | struct rpc_timeout ds_timeout; |
d83217c1 AA |
1505 | struct nfs_client *clp; |
1506 | ||
1507 | /* | |
1508 | * Set an authflavor equual to the MDS value. Use the MDS nfs_client | |
1509 | * cl_ipaddr so as to use the same EXCHANGE_ID co_ownerid as the MDS | |
1510 | * (section 13.1 RFC 5661). | |
1511 | */ | |
98fc685a | 1512 | nfs_init_timeout_values(&ds_timeout, ds_proto, ds_timeo, ds_retrans); |
d83217c1 | 1513 | clp = nfs_get_client(&cl_init, &ds_timeout, mds_clp->cl_ipaddr, |
4bf590e0 | 1514 | mds_clp->cl_rpcclient->cl_auth->au_flavor); |
d83217c1 AA |
1515 | |
1516 | dprintk("<-- %s %p\n", __func__, clp); | |
1517 | return clp; | |
1518 | } | |
94b134ac | 1519 | EXPORT_SYMBOL_GPL(nfs4_set_ds_client); |
557134a3 | 1520 | |
96b09e02 AA |
1521 | /* |
1522 | * Session has been established, and the client marked ready. | |
1523 | * Set the mount rsize and wsize with negotiated fore channel | |
1524 | * attributes which will be bound checked in nfs_server_set_fsinfo. | |
1525 | */ | |
1526 | static void nfs4_session_set_rwsize(struct nfs_server *server) | |
1527 | { | |
1528 | #ifdef CONFIG_NFS_V4_1 | |
2449ea2e AB |
1529 | struct nfs4_session *sess; |
1530 | u32 server_resp_sz; | |
1531 | u32 server_rqst_sz; | |
1532 | ||
96b09e02 AA |
1533 | if (!nfs4_has_session(server->nfs_client)) |
1534 | return; | |
2449ea2e AB |
1535 | sess = server->nfs_client->cl_session; |
1536 | server_resp_sz = sess->fc_attrs.max_resp_sz - nfs41_maxread_overhead; | |
1537 | server_rqst_sz = sess->fc_attrs.max_rqst_sz - nfs41_maxwrite_overhead; | |
1538 | ||
1539 | if (server->rsize > server_resp_sz) | |
1540 | server->rsize = server_resp_sz; | |
1541 | if (server->wsize > server_rqst_sz) | |
1542 | server->wsize = server_rqst_sz; | |
96b09e02 AA |
1543 | #endif /* CONFIG_NFS_V4_1 */ |
1544 | } | |
1545 | ||
44950b67 TM |
1546 | static int nfs4_server_common_setup(struct nfs_server *server, |
1547 | struct nfs_fh *mntfh) | |
1548 | { | |
1549 | struct nfs_fattr *fattr; | |
1550 | int error; | |
1551 | ||
1552 | BUG_ON(!server->nfs_client); | |
1553 | BUG_ON(!server->nfs_client->rpc_ops); | |
1554 | BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops); | |
1555 | ||
94de8b27 AA |
1556 | /* data servers support only a subset of NFSv4.1 */ |
1557 | if (is_ds_only_client(server->nfs_client)) | |
1558 | return -EPROTONOSUPPORT; | |
1559 | ||
44950b67 TM |
1560 | fattr = nfs_alloc_fattr(); |
1561 | if (fattr == NULL) | |
1562 | return -ENOMEM; | |
1563 | ||
1564 | /* We must ensure the session is initialised first */ | |
1565 | error = nfs4_init_session(server); | |
1566 | if (error < 0) | |
1567 | goto out; | |
1568 | ||
1569 | /* Probe the root fh to retrieve its FSID and filehandle */ | |
1570 | error = nfs4_get_rootfh(server, mntfh); | |
1571 | if (error < 0) | |
1572 | goto out; | |
1573 | ||
1574 | dprintk("Server FSID: %llx:%llx\n", | |
1575 | (unsigned long long) server->fsid.major, | |
1576 | (unsigned long long) server->fsid.minor); | |
1577 | dprintk("Mount FH: %d\n", mntfh->size); | |
1578 | ||
1579 | nfs4_session_set_rwsize(server); | |
1580 | ||
1581 | error = nfs_probe_fsinfo(server, mntfh, fattr); | |
1582 | if (error < 0) | |
1583 | goto out; | |
1584 | ||
1585 | if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN) | |
1586 | server->namelen = NFS4_MAXNAMLEN; | |
1587 | ||
fca5238e | 1588 | nfs_server_insert_lists(server); |
44950b67 | 1589 | server->mount_time = jiffies; |
0aaaf5c4 | 1590 | server->destroy = nfs4_destroy_server; |
44950b67 TM |
1591 | out: |
1592 | nfs_free_fattr(fattr); | |
1593 | return error; | |
1594 | } | |
1595 | ||
54ceac45 DH |
1596 | /* |
1597 | * Create a version 4 volume record | |
1598 | */ | |
1599 | static int nfs4_init_server(struct nfs_server *server, | |
91ea40b9 | 1600 | const struct nfs_parsed_mount_data *data) |
54ceac45 | 1601 | { |
33170233 | 1602 | struct rpc_timeout timeparms; |
54ceac45 DH |
1603 | int error; |
1604 | ||
1605 | dprintk("--> nfs4_init_server()\n"); | |
1606 | ||
33170233 TM |
1607 | nfs_init_timeout_values(&timeparms, data->nfs_server.protocol, |
1608 | data->timeo, data->retrans); | |
1609 | ||
542fcc33 CL |
1610 | /* Initialise the client representation from the mount data */ |
1611 | server->flags = data->flags; | |
82f2e547 BS |
1612 | server->caps |= NFS_CAP_ATOMIC_OPEN|NFS_CAP_CHANGE_ATTR|NFS_CAP_POSIX_LOCK; |
1613 | if (!(data->flags & NFS_MOUNT_NORDIRPLUS)) | |
1614 | server->caps |= NFS_CAP_READDIRPLUS; | |
b797cac7 | 1615 | server->options = data->options; |
542fcc33 | 1616 | |
33170233 TM |
1617 | /* Get a client record */ |
1618 | error = nfs4_set_client(server, | |
1619 | data->nfs_server.hostname, | |
1620 | (const struct sockaddr *)&data->nfs_server.address, | |
1621 | data->nfs_server.addrlen, | |
1622 | data->client_address, | |
1623 | data->auth_flavors[0], | |
1624 | data->nfs_server.protocol, | |
94a417f3 | 1625 | &timeparms, |
e50a7a1a SK |
1626 | data->minorversion, |
1627 | data->net); | |
33170233 TM |
1628 | if (error < 0) |
1629 | goto error; | |
1630 | ||
b064eca2 TM |
1631 | /* |
1632 | * Don't use NFS uid/gid mapping if we're using AUTH_SYS or lower | |
1633 | * authentication. | |
1634 | */ | |
1635 | if (nfs4_disable_idmapping && data->auth_flavors[0] == RPC_AUTH_UNIX) | |
1636 | server->caps |= NFS_CAP_UIDGID_NOMAP; | |
1637 | ||
54ceac45 DH |
1638 | if (data->rsize) |
1639 | server->rsize = nfs_block_size(data->rsize, NULL); | |
1640 | if (data->wsize) | |
1641 | server->wsize = nfs_block_size(data->wsize, NULL); | |
1642 | ||
1643 | server->acregmin = data->acregmin * HZ; | |
1644 | server->acregmax = data->acregmax * HZ; | |
1645 | server->acdirmin = data->acdirmin * HZ; | |
1646 | server->acdirmax = data->acdirmax * HZ; | |
1647 | ||
f22d6d79 CL |
1648 | server->port = data->nfs_server.port; |
1649 | ||
33170233 | 1650 | error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]); |
54ceac45 | 1651 | |
33170233 | 1652 | error: |
54ceac45 DH |
1653 | /* Done */ |
1654 | dprintk("<-- nfs4_init_server() = %d\n", error); | |
1655 | return error; | |
1656 | } | |
1657 | ||
1658 | /* | |
1659 | * Create a version 4 volume record | |
1660 | * - keyed on server and FSID | |
1661 | */ | |
91ea40b9 | 1662 | struct nfs_server *nfs4_create_server(const struct nfs_parsed_mount_data *data, |
54ceac45 DH |
1663 | struct nfs_fh *mntfh) |
1664 | { | |
54ceac45 DH |
1665 | struct nfs_server *server; |
1666 | int error; | |
1667 | ||
1668 | dprintk("--> nfs4_create_server()\n"); | |
1669 | ||
1670 | server = nfs_alloc_server(); | |
1671 | if (!server) | |
1672 | return ERR_PTR(-ENOMEM); | |
1673 | ||
54ceac45 | 1674 | /* set up the general RPC client */ |
91ea40b9 | 1675 | error = nfs4_init_server(server, data); |
54ceac45 DH |
1676 | if (error < 0) |
1677 | goto error; | |
1678 | ||
44950b67 | 1679 | error = nfs4_server_common_setup(server, mntfh); |
54ceac45 DH |
1680 | if (error < 0) |
1681 | goto error; | |
1682 | ||
54ceac45 DH |
1683 | dprintk("<-- nfs4_create_server() = %p\n", server); |
1684 | return server; | |
1685 | ||
1686 | error: | |
1687 | nfs_free_server(server); | |
1688 | dprintk("<-- nfs4_create_server() = error %d\n", error); | |
1689 | return ERR_PTR(error); | |
1690 | } | |
1691 | ||
1692 | /* | |
1693 | * Create an NFS4 referral server record | |
1694 | */ | |
1695 | struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data, | |
f2d0d85e | 1696 | struct nfs_fh *mntfh) |
54ceac45 DH |
1697 | { |
1698 | struct nfs_client *parent_client; | |
1699 | struct nfs_server *server, *parent_server; | |
54ceac45 DH |
1700 | int error; |
1701 | ||
1702 | dprintk("--> nfs4_create_referral_server()\n"); | |
1703 | ||
1704 | server = nfs_alloc_server(); | |
1705 | if (!server) | |
1706 | return ERR_PTR(-ENOMEM); | |
1707 | ||
1708 | parent_server = NFS_SB(data->sb); | |
1709 | parent_client = parent_server->nfs_client; | |
1710 | ||
542fcc33 CL |
1711 | /* Initialise the client representation from the parent server */ |
1712 | nfs_server_copy_userdata(server, parent_server); | |
62ab460c | 1713 | server->caps |= NFS_CAP_ATOMIC_OPEN|NFS_CAP_CHANGE_ATTR; |
542fcc33 | 1714 | |
54ceac45 DH |
1715 | /* Get a client representation. |
1716 | * Note: NFSv4 always uses TCP, */ | |
dcecae0f | 1717 | error = nfs4_set_client(server, data->hostname, |
6677d095 CL |
1718 | data->addr, |
1719 | data->addrlen, | |
dcecae0f CL |
1720 | parent_client->cl_ipaddr, |
1721 | data->authflavor, | |
2446ab60 | 1722 | rpc_protocol(parent_server->client), |
94a417f3 | 1723 | parent_server->client->cl_timeout, |
e50a7a1a | 1724 | parent_client->cl_mvops->minor_version, |
73ea666c | 1725 | parent_client->cl_net); |
297de4f6 | 1726 | if (error < 0) |
1727 | goto error; | |
54ceac45 | 1728 | |
33170233 | 1729 | error = nfs_init_server_rpcclient(server, parent_server->client->cl_timeout, data->authflavor); |
54ceac45 DH |
1730 | if (error < 0) |
1731 | goto error; | |
1732 | ||
44950b67 | 1733 | error = nfs4_server_common_setup(server, mntfh); |
54ceac45 DH |
1734 | if (error < 0) |
1735 | goto error; | |
1736 | ||
54ceac45 DH |
1737 | dprintk("<-- nfs_create_referral_server() = %p\n", server); |
1738 | return server; | |
1739 | ||
1740 | error: | |
1741 | nfs_free_server(server); | |
1742 | dprintk("<-- nfs4_create_referral_server() = error %d\n", error); | |
1743 | return ERR_PTR(error); | |
1744 | } | |
1745 | ||
1746 | #endif /* CONFIG_NFS_V4 */ | |
1747 | ||
1748 | /* | |
1749 | * Clone an NFS2, NFS3 or NFS4 server record | |
1750 | */ | |
1751 | struct nfs_server *nfs_clone_server(struct nfs_server *source, | |
1752 | struct nfs_fh *fh, | |
7e6eb683 BS |
1753 | struct nfs_fattr *fattr, |
1754 | rpc_authflavor_t flavor) | |
54ceac45 DH |
1755 | { |
1756 | struct nfs_server *server; | |
fbca779a | 1757 | struct nfs_fattr *fattr_fsinfo; |
54ceac45 DH |
1758 | int error; |
1759 | ||
1760 | dprintk("--> nfs_clone_server(,%llx:%llx,)\n", | |
6daabf1b DH |
1761 | (unsigned long long) fattr->fsid.major, |
1762 | (unsigned long long) fattr->fsid.minor); | |
54ceac45 DH |
1763 | |
1764 | server = nfs_alloc_server(); | |
1765 | if (!server) | |
1766 | return ERR_PTR(-ENOMEM); | |
1767 | ||
fbca779a TM |
1768 | error = -ENOMEM; |
1769 | fattr_fsinfo = nfs_alloc_fattr(); | |
1770 | if (fattr_fsinfo == NULL) | |
1771 | goto out_free_server; | |
1772 | ||
54ceac45 DH |
1773 | /* Copy data from the source */ |
1774 | server->nfs_client = source->nfs_client; | |
0aaaf5c4 | 1775 | server->destroy = source->destroy; |
54ceac45 DH |
1776 | atomic_inc(&server->nfs_client->cl_count); |
1777 | nfs_server_copy_userdata(server, source); | |
1778 | ||
1779 | server->fsid = fattr->fsid; | |
1780 | ||
33170233 TM |
1781 | error = nfs_init_server_rpcclient(server, |
1782 | source->client->cl_timeout, | |
7e6eb683 | 1783 | flavor); |
54ceac45 DH |
1784 | if (error < 0) |
1785 | goto out_free_server; | |
1786 | if (!IS_ERR(source->client_acl)) | |
1787 | nfs_init_server_aclclient(server); | |
1788 | ||
1789 | /* probe the filesystem info for this server filesystem */ | |
fbca779a | 1790 | error = nfs_probe_fsinfo(server, fh, fattr_fsinfo); |
54ceac45 DH |
1791 | if (error < 0) |
1792 | goto out_free_server; | |
1793 | ||
54af3bb5 TM |
1794 | if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN) |
1795 | server->namelen = NFS4_MAXNAMLEN; | |
1796 | ||
54ceac45 | 1797 | dprintk("Cloned FSID: %llx:%llx\n", |
6daabf1b DH |
1798 | (unsigned long long) server->fsid.major, |
1799 | (unsigned long long) server->fsid.minor); | |
54ceac45 DH |
1800 | |
1801 | error = nfs_start_lockd(server); | |
1802 | if (error < 0) | |
1803 | goto out_free_server; | |
1804 | ||
fca5238e | 1805 | nfs_server_insert_lists(server); |
54ceac45 DH |
1806 | server->mount_time = jiffies; |
1807 | ||
fbca779a | 1808 | nfs_free_fattr(fattr_fsinfo); |
54ceac45 DH |
1809 | dprintk("<-- nfs_clone_server() = %p\n", server); |
1810 | return server; | |
1811 | ||
1812 | out_free_server: | |
fbca779a | 1813 | nfs_free_fattr(fattr_fsinfo); |
54ceac45 DH |
1814 | nfs_free_server(server); |
1815 | dprintk("<-- nfs_clone_server() = error %d\n", error); | |
1816 | return ERR_PTR(error); | |
1817 | } | |
6aaca566 | 1818 | |
6b13168b SK |
1819 | void nfs_clients_init(struct net *net) |
1820 | { | |
1821 | struct nfs_net *nn = net_generic(net, nfs_net_id); | |
1822 | ||
1823 | INIT_LIST_HEAD(&nn->nfs_client_list); | |
c25d32b2 | 1824 | INIT_LIST_HEAD(&nn->nfs_volume_list); |
28cd1b3f SK |
1825 | #ifdef CONFIG_NFS_V4 |
1826 | idr_init(&nn->cb_ident_idr); | |
1827 | #endif | |
4c03ae4a | 1828 | spin_lock_init(&nn->nfs_client_lock); |
f092075d | 1829 | nn->boot_time = CURRENT_TIME; |
6b13168b SK |
1830 | } |
1831 | ||
6aaca566 DH |
1832 | #ifdef CONFIG_PROC_FS |
1833 | static struct proc_dir_entry *proc_fs_nfs; | |
1834 | ||
1835 | static int nfs_server_list_open(struct inode *inode, struct file *file); | |
1836 | static void *nfs_server_list_start(struct seq_file *p, loff_t *pos); | |
1837 | static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos); | |
1838 | static void nfs_server_list_stop(struct seq_file *p, void *v); | |
1839 | static int nfs_server_list_show(struct seq_file *m, void *v); | |
1840 | ||
88e9d34c | 1841 | static const struct seq_operations nfs_server_list_ops = { |
6aaca566 DH |
1842 | .start = nfs_server_list_start, |
1843 | .next = nfs_server_list_next, | |
1844 | .stop = nfs_server_list_stop, | |
1845 | .show = nfs_server_list_show, | |
1846 | }; | |
1847 | ||
00977a59 | 1848 | static const struct file_operations nfs_server_list_fops = { |
6aaca566 DH |
1849 | .open = nfs_server_list_open, |
1850 | .read = seq_read, | |
1851 | .llseek = seq_lseek, | |
1852 | .release = seq_release, | |
34b37235 | 1853 | .owner = THIS_MODULE, |
6aaca566 DH |
1854 | }; |
1855 | ||
1856 | static int nfs_volume_list_open(struct inode *inode, struct file *file); | |
1857 | static void *nfs_volume_list_start(struct seq_file *p, loff_t *pos); | |
1858 | static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos); | |
1859 | static void nfs_volume_list_stop(struct seq_file *p, void *v); | |
1860 | static int nfs_volume_list_show(struct seq_file *m, void *v); | |
1861 | ||
88e9d34c | 1862 | static const struct seq_operations nfs_volume_list_ops = { |
6aaca566 DH |
1863 | .start = nfs_volume_list_start, |
1864 | .next = nfs_volume_list_next, | |
1865 | .stop = nfs_volume_list_stop, | |
1866 | .show = nfs_volume_list_show, | |
1867 | }; | |
1868 | ||
00977a59 | 1869 | static const struct file_operations nfs_volume_list_fops = { |
6aaca566 DH |
1870 | .open = nfs_volume_list_open, |
1871 | .read = seq_read, | |
1872 | .llseek = seq_lseek, | |
1873 | .release = seq_release, | |
34b37235 | 1874 | .owner = THIS_MODULE, |
6aaca566 DH |
1875 | }; |
1876 | ||
1877 | /* | |
1878 | * open "/proc/fs/nfsfs/servers" which provides a summary of servers with which | |
1879 | * we're dealing | |
1880 | */ | |
1881 | static int nfs_server_list_open(struct inode *inode, struct file *file) | |
1882 | { | |
1883 | struct seq_file *m; | |
1884 | int ret; | |
6b13168b SK |
1885 | struct pid_namespace *pid_ns = file->f_dentry->d_sb->s_fs_info; |
1886 | struct net *net = pid_ns->child_reaper->nsproxy->net_ns; | |
6aaca566 DH |
1887 | |
1888 | ret = seq_open(file, &nfs_server_list_ops); | |
1889 | if (ret < 0) | |
1890 | return ret; | |
1891 | ||
1892 | m = file->private_data; | |
6b13168b | 1893 | m->private = net; |
6aaca566 DH |
1894 | |
1895 | return 0; | |
1896 | } | |
1897 | ||
1898 | /* | |
1899 | * set up the iterator to start reading from the server list and return the first item | |
1900 | */ | |
1901 | static void *nfs_server_list_start(struct seq_file *m, loff_t *_pos) | |
1902 | { | |
6b13168b SK |
1903 | struct nfs_net *nn = net_generic(m->private, nfs_net_id); |
1904 | ||
6aaca566 | 1905 | /* lock the list against modification */ |
dc030858 | 1906 | spin_lock(&nn->nfs_client_lock); |
6b13168b | 1907 | return seq_list_start_head(&nn->nfs_client_list, *_pos); |
6aaca566 DH |
1908 | } |
1909 | ||
1910 | /* | |
1911 | * move to next server | |
1912 | */ | |
1913 | static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos) | |
1914 | { | |
6b13168b SK |
1915 | struct nfs_net *nn = net_generic(p->private, nfs_net_id); |
1916 | ||
1917 | return seq_list_next(v, &nn->nfs_client_list, pos); | |
6aaca566 DH |
1918 | } |
1919 | ||
1920 | /* | |
1921 | * clean up after reading from the transports list | |
1922 | */ | |
1923 | static void nfs_server_list_stop(struct seq_file *p, void *v) | |
1924 | { | |
dc030858 SK |
1925 | struct nfs_net *nn = net_generic(p->private, nfs_net_id); |
1926 | ||
1927 | spin_unlock(&nn->nfs_client_lock); | |
6aaca566 DH |
1928 | } |
1929 | ||
1930 | /* | |
1931 | * display a header line followed by a load of call lines | |
1932 | */ | |
1933 | static int nfs_server_list_show(struct seq_file *m, void *v) | |
1934 | { | |
1935 | struct nfs_client *clp; | |
6b13168b | 1936 | struct nfs_net *nn = net_generic(m->private, nfs_net_id); |
6aaca566 DH |
1937 | |
1938 | /* display header on line 1 */ | |
6b13168b | 1939 | if (v == &nn->nfs_client_list) { |
6aaca566 DH |
1940 | seq_puts(m, "NV SERVER PORT USE HOSTNAME\n"); |
1941 | return 0; | |
1942 | } | |
1943 | ||
1944 | /* display one transport per line on subsequent lines */ | |
1945 | clp = list_entry(v, struct nfs_client, cl_share_link); | |
1946 | ||
940aab49 MN |
1947 | /* Check if the client is initialized */ |
1948 | if (clp->cl_cons_state != NFS_CS_READY) | |
1949 | return 0; | |
1950 | ||
2446ab60 | 1951 | rcu_read_lock(); |
5d8515ca | 1952 | seq_printf(m, "v%u %s %s %3d %s\n", |
40c55319 | 1953 | clp->rpc_ops->version, |
5d8515ca CL |
1954 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR), |
1955 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT), | |
6aaca566 DH |
1956 | atomic_read(&clp->cl_count), |
1957 | clp->cl_hostname); | |
2446ab60 | 1958 | rcu_read_unlock(); |
6aaca566 DH |
1959 | |
1960 | return 0; | |
1961 | } | |
1962 | ||
1963 | /* | |
1964 | * open "/proc/fs/nfsfs/volumes" which provides a summary of extant volumes | |
1965 | */ | |
1966 | static int nfs_volume_list_open(struct inode *inode, struct file *file) | |
1967 | { | |
1968 | struct seq_file *m; | |
1969 | int ret; | |
c25d32b2 SK |
1970 | struct pid_namespace *pid_ns = file->f_dentry->d_sb->s_fs_info; |
1971 | struct net *net = pid_ns->child_reaper->nsproxy->net_ns; | |
6aaca566 DH |
1972 | |
1973 | ret = seq_open(file, &nfs_volume_list_ops); | |
1974 | if (ret < 0) | |
1975 | return ret; | |
1976 | ||
1977 | m = file->private_data; | |
c25d32b2 | 1978 | m->private = net; |
6aaca566 DH |
1979 | |
1980 | return 0; | |
1981 | } | |
1982 | ||
1983 | /* | |
1984 | * set up the iterator to start reading from the volume list and return the first item | |
1985 | */ | |
1986 | static void *nfs_volume_list_start(struct seq_file *m, loff_t *_pos) | |
1987 | { | |
c25d32b2 SK |
1988 | struct nfs_net *nn = net_generic(m->private, nfs_net_id); |
1989 | ||
6aaca566 | 1990 | /* lock the list against modification */ |
dc030858 | 1991 | spin_lock(&nn->nfs_client_lock); |
c25d32b2 | 1992 | return seq_list_start_head(&nn->nfs_volume_list, *_pos); |
6aaca566 DH |
1993 | } |
1994 | ||
1995 | /* | |
1996 | * move to next volume | |
1997 | */ | |
1998 | static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos) | |
1999 | { | |
c25d32b2 SK |
2000 | struct nfs_net *nn = net_generic(p->private, nfs_net_id); |
2001 | ||
2002 | return seq_list_next(v, &nn->nfs_volume_list, pos); | |
6aaca566 DH |
2003 | } |
2004 | ||
2005 | /* | |
2006 | * clean up after reading from the transports list | |
2007 | */ | |
2008 | static void nfs_volume_list_stop(struct seq_file *p, void *v) | |
2009 | { | |
dc030858 SK |
2010 | struct nfs_net *nn = net_generic(p->private, nfs_net_id); |
2011 | ||
2012 | spin_unlock(&nn->nfs_client_lock); | |
6aaca566 DH |
2013 | } |
2014 | ||
2015 | /* | |
2016 | * display a header line followed by a load of call lines | |
2017 | */ | |
2018 | static int nfs_volume_list_show(struct seq_file *m, void *v) | |
2019 | { | |
2020 | struct nfs_server *server; | |
2021 | struct nfs_client *clp; | |
2022 | char dev[8], fsid[17]; | |
c25d32b2 | 2023 | struct nfs_net *nn = net_generic(m->private, nfs_net_id); |
6aaca566 DH |
2024 | |
2025 | /* display header on line 1 */ | |
c25d32b2 | 2026 | if (v == &nn->nfs_volume_list) { |
5d1acff1 | 2027 | seq_puts(m, "NV SERVER PORT DEV FSID FSC\n"); |
6aaca566 DH |
2028 | return 0; |
2029 | } | |
2030 | /* display one transport per line on subsequent lines */ | |
2031 | server = list_entry(v, struct nfs_server, master_link); | |
2032 | clp = server->nfs_client; | |
2033 | ||
2034 | snprintf(dev, 8, "%u:%u", | |
2035 | MAJOR(server->s_dev), MINOR(server->s_dev)); | |
2036 | ||
2037 | snprintf(fsid, 17, "%llx:%llx", | |
6daabf1b DH |
2038 | (unsigned long long) server->fsid.major, |
2039 | (unsigned long long) server->fsid.minor); | |
6aaca566 | 2040 | |
2446ab60 | 2041 | rcu_read_lock(); |
5d1acff1 | 2042 | seq_printf(m, "v%u %s %s %-7s %-17s %s\n", |
40c55319 | 2043 | clp->rpc_ops->version, |
5d8515ca CL |
2044 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR), |
2045 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT), | |
6aaca566 | 2046 | dev, |
5d1acff1 DH |
2047 | fsid, |
2048 | nfs_server_fscache_state(server)); | |
2446ab60 | 2049 | rcu_read_unlock(); |
6aaca566 DH |
2050 | |
2051 | return 0; | |
2052 | } | |
2053 | ||
2054 | /* | |
2055 | * initialise the /proc/fs/nfsfs/ directory | |
2056 | */ | |
2057 | int __init nfs_fs_proc_init(void) | |
2058 | { | |
2059 | struct proc_dir_entry *p; | |
2060 | ||
36a5aeb8 | 2061 | proc_fs_nfs = proc_mkdir("fs/nfsfs", NULL); |
6aaca566 DH |
2062 | if (!proc_fs_nfs) |
2063 | goto error_0; | |
2064 | ||
6aaca566 | 2065 | /* a file of servers with which we're dealing */ |
34b37235 DL |
2066 | p = proc_create("servers", S_IFREG|S_IRUGO, |
2067 | proc_fs_nfs, &nfs_server_list_fops); | |
6aaca566 DH |
2068 | if (!p) |
2069 | goto error_1; | |
2070 | ||
6aaca566 | 2071 | /* a file of volumes that we have mounted */ |
34b37235 DL |
2072 | p = proc_create("volumes", S_IFREG|S_IRUGO, |
2073 | proc_fs_nfs, &nfs_volume_list_fops); | |
6aaca566 DH |
2074 | if (!p) |
2075 | goto error_2; | |
6aaca566 DH |
2076 | return 0; |
2077 | ||
2078 | error_2: | |
2079 | remove_proc_entry("servers", proc_fs_nfs); | |
2080 | error_1: | |
36a5aeb8 | 2081 | remove_proc_entry("fs/nfsfs", NULL); |
6aaca566 DH |
2082 | error_0: |
2083 | return -ENOMEM; | |
2084 | } | |
2085 | ||
2086 | /* | |
2087 | * clean up the /proc/fs/nfsfs/ directory | |
2088 | */ | |
2089 | void nfs_fs_proc_exit(void) | |
2090 | { | |
2091 | remove_proc_entry("volumes", proc_fs_nfs); | |
2092 | remove_proc_entry("servers", proc_fs_nfs); | |
36a5aeb8 | 2093 | remove_proc_entry("fs/nfsfs", NULL); |
6aaca566 DH |
2094 | } |
2095 | ||
2096 | #endif /* CONFIG_PROC_FS */ | |
b064eca2 TM |
2097 | |
2098 | module_param(nfs4_disable_idmapping, bool, 0644); | |
2099 | MODULE_PARM_DESC(nfs4_disable_idmapping, | |
2100 | "Turn off NFSv4 idmapping when using 'sec=sys'"); |