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