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