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