]>
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> |
24c8dbbb DH |
42 | |
43 | #include <asm/system.h> | |
44 | ||
45 | #include "nfs4_fs.h" | |
46 | #include "callback.h" | |
47 | #include "delegation.h" | |
48 | #include "iostat.h" | |
49 | #include "internal.h" | |
14727281 | 50 | #include "fscache.h" |
24c8dbbb DH |
51 | |
52 | #define NFSDBG_FACILITY NFSDBG_CLIENT | |
53 | ||
54 | static DEFINE_SPINLOCK(nfs_client_lock); | |
55 | static LIST_HEAD(nfs_client_list); | |
54ceac45 | 56 | static LIST_HEAD(nfs_volume_list); |
24c8dbbb DH |
57 | static DECLARE_WAIT_QUEUE_HEAD(nfs_client_active_wq); |
58 | ||
5006a76c DH |
59 | /* |
60 | * RPC cruft for NFS | |
61 | */ | |
62 | static struct rpc_version *nfs_version[5] = { | |
63 | [2] = &nfs_version2, | |
64 | #ifdef CONFIG_NFS_V3 | |
65 | [3] = &nfs_version3, | |
66 | #endif | |
67 | #ifdef CONFIG_NFS_V4 | |
68 | [4] = &nfs_version4, | |
69 | #endif | |
70 | }; | |
71 | ||
72 | struct rpc_program nfs_program = { | |
73 | .name = "nfs", | |
74 | .number = NFS_PROGRAM, | |
75 | .nrvers = ARRAY_SIZE(nfs_version), | |
76 | .version = nfs_version, | |
77 | .stats = &nfs_rpcstat, | |
78 | .pipe_dir_name = "/nfs", | |
79 | }; | |
80 | ||
81 | struct rpc_stat nfs_rpcstat = { | |
82 | .program = &nfs_program | |
83 | }; | |
84 | ||
85 | ||
86 | #ifdef CONFIG_NFS_V3_ACL | |
87 | static struct rpc_stat nfsacl_rpcstat = { &nfsacl_program }; | |
88 | static struct rpc_version * nfsacl_version[] = { | |
89 | [3] = &nfsacl_version3, | |
90 | }; | |
91 | ||
92 | struct rpc_program nfsacl_program = { | |
93 | .name = "nfsacl", | |
94 | .number = NFS_ACL_PROGRAM, | |
95 | .nrvers = ARRAY_SIZE(nfsacl_version), | |
96 | .version = nfsacl_version, | |
97 | .stats = &nfsacl_rpcstat, | |
98 | }; | |
99 | #endif /* CONFIG_NFS_V3_ACL */ | |
100 | ||
3a498026 TM |
101 | struct nfs_client_initdata { |
102 | const char *hostname; | |
d7422c47 | 103 | const struct sockaddr *addr; |
6e4cffd7 | 104 | size_t addrlen; |
40c55319 | 105 | const struct nfs_rpc_ops *rpc_ops; |
59dca3b2 | 106 | int proto; |
5aae4a9a | 107 | u32 minorversion; |
3a498026 TM |
108 | }; |
109 | ||
24c8dbbb DH |
110 | /* |
111 | * Allocate a shared client record | |
112 | * | |
113 | * Since these are allocated/deallocated very rarely, we don't | |
114 | * bother putting them in a slab cache... | |
115 | */ | |
3a498026 | 116 | static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init) |
24c8dbbb DH |
117 | { |
118 | struct nfs_client *clp; | |
7c67db3a | 119 | struct rpc_cred *cred; |
a21bdd9b | 120 | int err = -ENOMEM; |
24c8dbbb DH |
121 | |
122 | if ((clp = kzalloc(sizeof(*clp), GFP_KERNEL)) == NULL) | |
123 | goto error_0; | |
124 | ||
40c55319 TM |
125 | clp->rpc_ops = cl_init->rpc_ops; |
126 | ||
24c8dbbb DH |
127 | atomic_set(&clp->cl_count, 1); |
128 | clp->cl_cons_state = NFS_CS_INITING; | |
129 | ||
6e4cffd7 CL |
130 | memcpy(&clp->cl_addr, cl_init->addr, cl_init->addrlen); |
131 | clp->cl_addrlen = cl_init->addrlen; | |
24c8dbbb | 132 | |
3a498026 | 133 | if (cl_init->hostname) { |
a21bdd9b | 134 | err = -ENOMEM; |
3a498026 | 135 | clp->cl_hostname = kstrdup(cl_init->hostname, GFP_KERNEL); |
24c8dbbb | 136 | if (!clp->cl_hostname) |
71468513 | 137 | goto error_cleanup; |
24c8dbbb DH |
138 | } |
139 | ||
140 | INIT_LIST_HEAD(&clp->cl_superblocks); | |
141 | clp->cl_rpcclient = ERR_PTR(-EINVAL); | |
142 | ||
59dca3b2 TM |
143 | clp->cl_proto = cl_init->proto; |
144 | ||
24c8dbbb | 145 | #ifdef CONFIG_NFS_V4 |
24c8dbbb | 146 | INIT_LIST_HEAD(&clp->cl_delegations); |
24c8dbbb | 147 | spin_lock_init(&clp->cl_lock); |
65f27f38 | 148 | INIT_DELAYED_WORK(&clp->cl_renewd, nfs4_renew_state); |
24c8dbbb DH |
149 | rpc_init_wait_queue(&clp->cl_rpcwaitq, "NFS client"); |
150 | clp->cl_boot_time = CURRENT_TIME; | |
151 | clp->cl_state = 1 << NFS4CLNT_LEASE_EXPIRED; | |
5aae4a9a | 152 | clp->cl_minorversion = cl_init->minorversion; |
24c8dbbb | 153 | #endif |
7c67db3a TM |
154 | cred = rpc_lookup_machine_cred(); |
155 | if (!IS_ERR(cred)) | |
156 | clp->cl_machine_cred = cred; | |
24c8dbbb | 157 | |
14727281 DH |
158 | nfs_fscache_get_client_cookie(clp); |
159 | ||
24c8dbbb DH |
160 | return clp; |
161 | ||
71468513 | 162 | error_cleanup: |
24c8dbbb DH |
163 | kfree(clp); |
164 | error_0: | |
a21bdd9b | 165 | return ERR_PTR(err); |
24c8dbbb DH |
166 | } |
167 | ||
5dd3177a | 168 | #ifdef CONFIG_NFS_V4 |
557134a3 AA |
169 | /* |
170 | * Clears/puts all minor version specific parts from an nfs_client struct | |
171 | * reverting it to minorversion 0. | |
172 | */ | |
173 | static void nfs4_clear_client_minor_version(struct nfs_client *clp) | |
174 | { | |
175 | #ifdef CONFIG_NFS_V4_1 | |
176 | if (nfs4_has_session(clp)) { | |
177 | nfs4_destroy_session(clp->cl_session); | |
178 | clp->cl_session = NULL; | |
179 | } | |
cccef3b9 AA |
180 | |
181 | clp->cl_call_sync = _nfs4_call_sync; | |
557134a3 | 182 | #endif /* CONFIG_NFS_V4_1 */ |
888ef2e3 | 183 | } |
71468513 | 184 | |
888ef2e3 AB |
185 | /* |
186 | * Destroy the NFS4 callback service | |
187 | */ | |
188 | static void nfs4_destroy_callback(struct nfs_client *clp) | |
189 | { | |
190 | if (__test_and_clear_bit(NFS_CS_CALLBACK, &clp->cl_res_state)) | |
191 | nfs_callback_down(clp->cl_minorversion); | |
192 | } | |
193 | ||
194 | static void nfs4_shutdown_client(struct nfs_client *clp) | |
195 | { | |
196 | if (__test_and_clear_bit(NFS_CS_RENEWD, &clp->cl_res_state)) | |
197 | nfs4_kill_renewd(clp); | |
198 | nfs4_clear_client_minor_version(clp); | |
71468513 | 199 | nfs4_destroy_callback(clp); |
888ef2e3 AB |
200 | if (__test_and_clear_bit(NFS_CS_IDMAP, &clp->cl_res_state)) |
201 | nfs_idmap_delete(clp); | |
202 | ||
203 | rpc_destroy_wait_queue(&clp->cl_rpcwaitq); | |
557134a3 | 204 | } |
888ef2e3 AB |
205 | #else |
206 | static void nfs4_shutdown_client(struct nfs_client *clp) | |
207 | { | |
208 | } | |
209 | #endif /* CONFIG_NFS_V4 */ | |
557134a3 | 210 | |
24c8dbbb DH |
211 | /* |
212 | * Destroy a shared client record | |
213 | */ | |
214 | static void nfs_free_client(struct nfs_client *clp) | |
215 | { | |
40c55319 | 216 | dprintk("--> nfs_free_client(%u)\n", clp->rpc_ops->version); |
24c8dbbb | 217 | |
5dd3177a | 218 | nfs4_shutdown_client(clp); |
24c8dbbb | 219 | |
14727281 DH |
220 | nfs_fscache_release_client_cookie(clp); |
221 | ||
24c8dbbb DH |
222 | /* -EIO all pending I/O */ |
223 | if (!IS_ERR(clp->cl_rpcclient)) | |
224 | rpc_shutdown_client(clp->cl_rpcclient); | |
225 | ||
7c67db3a TM |
226 | if (clp->cl_machine_cred != NULL) |
227 | put_rpccred(clp->cl_machine_cred); | |
228 | ||
24c8dbbb DH |
229 | kfree(clp->cl_hostname); |
230 | kfree(clp); | |
231 | ||
232 | dprintk("<-- nfs_free_client()\n"); | |
233 | } | |
234 | ||
235 | /* | |
236 | * Release a reference to a shared client record | |
237 | */ | |
238 | void nfs_put_client(struct nfs_client *clp) | |
239 | { | |
27ba8512 DH |
240 | if (!clp) |
241 | return; | |
242 | ||
24c8dbbb DH |
243 | dprintk("--> nfs_put_client({%d})\n", atomic_read(&clp->cl_count)); |
244 | ||
245 | if (atomic_dec_and_lock(&clp->cl_count, &nfs_client_lock)) { | |
246 | list_del(&clp->cl_share_link); | |
247 | spin_unlock(&nfs_client_lock); | |
248 | ||
249 | BUG_ON(!list_empty(&clp->cl_superblocks)); | |
250 | ||
251 | nfs_free_client(clp); | |
252 | } | |
253 | } | |
254 | ||
9082a5cc | 255 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) |
9f4c899c TM |
256 | /* |
257 | * Test if two ip6 socket addresses refer to the same socket by | |
258 | * comparing relevant fields. The padding bytes specifically, are not | |
259 | * compared. sin6_flowinfo is not compared because it only affects QoS | |
260 | * and sin6_scope_id is only compared if the address is "link local" | |
261 | * because "link local" addresses need only be unique to a specific | |
262 | * link. Conversely, ordinary unicast addresses might have different | |
263 | * sin6_scope_id. | |
264 | * | |
265 | * The caller should ensure both socket addresses are AF_INET6. | |
266 | */ | |
3c8c45df CL |
267 | static int nfs_sockaddr_match_ipaddr6(const struct sockaddr *sa1, |
268 | const struct sockaddr *sa2) | |
9f4c899c | 269 | { |
3c8c45df CL |
270 | const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sa1; |
271 | const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sa2; | |
9f4c899c | 272 | |
3c8c45df CL |
273 | if (ipv6_addr_scope(&sin1->sin6_addr) == IPV6_ADDR_SCOPE_LINKLOCAL && |
274 | sin1->sin6_scope_id != sin2->sin6_scope_id) | |
9f4c899c | 275 | return 0; |
3b0d3f93 | 276 | |
3c8c45df | 277 | return ipv6_addr_equal(&sin1->sin6_addr, &sin1->sin6_addr); |
3b0d3f93 | 278 | } |
3c8c45df CL |
279 | #else /* !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE) */ |
280 | static int nfs_sockaddr_match_ipaddr6(const struct sockaddr *sa1, | |
281 | const struct sockaddr *sa2) | |
9f4c899c TM |
282 | { |
283 | return 0; | |
284 | } | |
9082a5cc | 285 | #endif |
3b0d3f93 | 286 | |
d7371c41 ID |
287 | /* |
288 | * Test if two ip4 socket addresses refer to the same socket, by | |
289 | * comparing relevant fields. The padding bytes specifically, are | |
290 | * not compared. | |
291 | * | |
292 | * The caller should ensure both socket addresses are AF_INET. | |
293 | */ | |
3c8c45df CL |
294 | static int nfs_sockaddr_match_ipaddr4(const struct sockaddr *sa1, |
295 | const struct sockaddr *sa2) | |
296 | { | |
297 | const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sa1; | |
298 | const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sa2; | |
299 | ||
300 | return sin1->sin_addr.s_addr == sin2->sin_addr.s_addr; | |
301 | } | |
302 | ||
303 | static int nfs_sockaddr_cmp_ip6(const struct sockaddr *sa1, | |
304 | const struct sockaddr *sa2) | |
305 | { | |
306 | const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sa1; | |
307 | const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sa2; | |
308 | ||
309 | return nfs_sockaddr_match_ipaddr6(sa1, sa2) && | |
310 | (sin1->sin6_port == sin2->sin6_port); | |
311 | } | |
312 | ||
9f4c899c TM |
313 | static int nfs_sockaddr_cmp_ip4(const struct sockaddr *sa1, |
314 | const struct sockaddr *sa2) | |
d7371c41 | 315 | { |
3c8c45df CL |
316 | const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sa1; |
317 | const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sa2; | |
9f4c899c | 318 | |
3c8c45df CL |
319 | return nfs_sockaddr_match_ipaddr4(sa1, sa2) && |
320 | (sin1->sin_port == sin2->sin_port); | |
321 | } | |
322 | ||
323 | /* | |
324 | * Test if two socket addresses represent the same actual socket, | |
325 | * by comparing (only) relevant fields, excluding the port number. | |
326 | */ | |
327 | static int nfs_sockaddr_match_ipaddr(const struct sockaddr *sa1, | |
328 | const struct sockaddr *sa2) | |
329 | { | |
330 | if (sa1->sa_family != sa2->sa_family) | |
d7371c41 | 331 | return 0; |
3c8c45df CL |
332 | |
333 | switch (sa1->sa_family) { | |
334 | case AF_INET: | |
335 | return nfs_sockaddr_match_ipaddr4(sa1, sa2); | |
336 | case AF_INET6: | |
337 | return nfs_sockaddr_match_ipaddr6(sa1, sa2); | |
338 | } | |
339 | return 0; | |
d7371c41 ID |
340 | } |
341 | ||
d7371c41 ID |
342 | /* |
343 | * Test if two socket addresses represent the same actual socket, | |
3c8c45df | 344 | * by comparing (only) relevant fields, including the port number. |
d7371c41 ID |
345 | */ |
346 | static int nfs_sockaddr_cmp(const struct sockaddr *sa1, | |
347 | const struct sockaddr *sa2) | |
348 | { | |
349 | if (sa1->sa_family != sa2->sa_family) | |
350 | return 0; | |
351 | ||
352 | switch (sa1->sa_family) { | |
353 | case AF_INET: | |
9f4c899c | 354 | return nfs_sockaddr_cmp_ip4(sa1, sa2); |
d7371c41 | 355 | case AF_INET6: |
9f4c899c | 356 | return nfs_sockaddr_cmp_ip6(sa1, sa2); |
d7371c41 ID |
357 | } |
358 | return 0; | |
359 | } | |
360 | ||
24c8dbbb | 361 | /* |
c81468a1 TM |
362 | * Find a client by IP address and protocol version |
363 | * - returns NULL if no such client | |
24c8dbbb | 364 | */ |
ff052645 | 365 | struct nfs_client *nfs_find_client(const struct sockaddr *addr, u32 nfsversion) |
24c8dbbb DH |
366 | { |
367 | struct nfs_client *clp; | |
368 | ||
c81468a1 | 369 | spin_lock(&nfs_client_lock); |
24c8dbbb | 370 | list_for_each_entry(clp, &nfs_client_list, cl_share_link) { |
3b0d3f93 TM |
371 | struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr; |
372 | ||
13bbc06a | 373 | /* Don't match clients that failed to initialise properly */ |
76db6d95 AA |
374 | if (!(clp->cl_cons_state == NFS_CS_READY || |
375 | clp->cl_cons_state == NFS_CS_SESSION_INITING)) | |
13bbc06a TM |
376 | continue; |
377 | ||
24c8dbbb | 378 | /* Different NFS versions cannot share the same nfs_client */ |
40c55319 | 379 | if (clp->rpc_ops->version != nfsversion) |
24c8dbbb DH |
380 | continue; |
381 | ||
c81468a1 | 382 | /* Match only the IP address, not the port number */ |
3b0d3f93 | 383 | if (!nfs_sockaddr_match_ipaddr(addr, clap)) |
24c8dbbb DH |
384 | continue; |
385 | ||
c81468a1 TM |
386 | atomic_inc(&clp->cl_count); |
387 | spin_unlock(&nfs_client_lock); | |
388 | return clp; | |
24c8dbbb | 389 | } |
c81468a1 | 390 | spin_unlock(&nfs_client_lock); |
24c8dbbb | 391 | return NULL; |
24c8dbbb DH |
392 | } |
393 | ||
3fbd67ad TM |
394 | /* |
395 | * Find a client by IP address and protocol version | |
396 | * - returns NULL if no such client | |
397 | */ | |
398 | struct nfs_client *nfs_find_client_next(struct nfs_client *clp) | |
399 | { | |
400 | struct sockaddr *sap = (struct sockaddr *)&clp->cl_addr; | |
401 | u32 nfsvers = clp->rpc_ops->version; | |
402 | ||
403 | spin_lock(&nfs_client_lock); | |
404 | list_for_each_entry_continue(clp, &nfs_client_list, cl_share_link) { | |
405 | struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr; | |
406 | ||
407 | /* Don't match clients that failed to initialise properly */ | |
408 | if (clp->cl_cons_state != NFS_CS_READY) | |
409 | continue; | |
410 | ||
411 | /* Different NFS versions cannot share the same nfs_client */ | |
412 | if (clp->rpc_ops->version != nfsvers) | |
413 | continue; | |
414 | ||
3fbd67ad TM |
415 | /* Match only the IP address, not the port number */ |
416 | if (!nfs_sockaddr_match_ipaddr(sap, clap)) | |
417 | continue; | |
418 | ||
419 | atomic_inc(&clp->cl_count); | |
420 | spin_unlock(&nfs_client_lock); | |
421 | return clp; | |
422 | } | |
423 | spin_unlock(&nfs_client_lock); | |
424 | return NULL; | |
425 | } | |
426 | ||
24c8dbbb | 427 | /* |
c81468a1 TM |
428 | * Find an nfs_client on the list that matches the initialisation data |
429 | * that is supplied. | |
24c8dbbb | 430 | */ |
c81468a1 | 431 | static struct nfs_client *nfs_match_client(const struct nfs_client_initdata *data) |
24c8dbbb DH |
432 | { |
433 | struct nfs_client *clp; | |
d7371c41 | 434 | const struct sockaddr *sap = data->addr; |
24c8dbbb | 435 | |
c81468a1 | 436 | list_for_each_entry(clp, &nfs_client_list, cl_share_link) { |
d7371c41 | 437 | const struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr; |
c81468a1 TM |
438 | /* Don't match clients that failed to initialise properly */ |
439 | if (clp->cl_cons_state < 0) | |
440 | continue; | |
441 | ||
442 | /* Different NFS versions cannot share the same nfs_client */ | |
40c55319 | 443 | if (clp->rpc_ops != data->rpc_ops) |
c81468a1 TM |
444 | continue; |
445 | ||
59dca3b2 TM |
446 | if (clp->cl_proto != data->proto) |
447 | continue; | |
5aae4a9a BH |
448 | /* Match nfsv4 minorversion */ |
449 | if (clp->cl_minorversion != data->minorversion) | |
450 | continue; | |
c81468a1 | 451 | /* Match the full socket address */ |
d7371c41 | 452 | if (!nfs_sockaddr_cmp(sap, clap)) |
c81468a1 TM |
453 | continue; |
454 | ||
455 | atomic_inc(&clp->cl_count); | |
456 | return clp; | |
13bbc06a | 457 | } |
c81468a1 | 458 | return NULL; |
24c8dbbb DH |
459 | } |
460 | ||
461 | /* | |
462 | * Look up a client by IP address and protocol version | |
463 | * - creates a new record if one doesn't yet exist | |
464 | */ | |
3a498026 | 465 | static struct nfs_client *nfs_get_client(const struct nfs_client_initdata *cl_init) |
24c8dbbb DH |
466 | { |
467 | struct nfs_client *clp, *new = NULL; | |
468 | int error; | |
469 | ||
d7422c47 CL |
470 | dprintk("--> nfs_get_client(%s,v%u)\n", |
471 | cl_init->hostname ?: "", cl_init->rpc_ops->version); | |
24c8dbbb DH |
472 | |
473 | /* see if the client already exists */ | |
474 | do { | |
475 | spin_lock(&nfs_client_lock); | |
476 | ||
c81468a1 | 477 | clp = nfs_match_client(cl_init); |
24c8dbbb DH |
478 | if (clp) |
479 | goto found_client; | |
480 | if (new) | |
481 | goto install_client; | |
482 | ||
483 | spin_unlock(&nfs_client_lock); | |
484 | ||
3a498026 | 485 | new = nfs_alloc_client(cl_init); |
a21bdd9b | 486 | } while (!IS_ERR(new)); |
24c8dbbb | 487 | |
a21bdd9b CL |
488 | dprintk("--> nfs_get_client() = %ld [failed]\n", PTR_ERR(new)); |
489 | return new; | |
24c8dbbb DH |
490 | |
491 | /* install a new client and return with it unready */ | |
492 | install_client: | |
493 | clp = new; | |
494 | list_add(&clp->cl_share_link, &nfs_client_list); | |
495 | spin_unlock(&nfs_client_lock); | |
496 | dprintk("--> nfs_get_client() = %p [new]\n", clp); | |
497 | return clp; | |
498 | ||
499 | /* found an existing client | |
500 | * - make sure it's ready before returning | |
501 | */ | |
502 | found_client: | |
503 | spin_unlock(&nfs_client_lock); | |
504 | ||
505 | if (new) | |
506 | nfs_free_client(new); | |
507 | ||
150030b7 | 508 | error = wait_event_killable(nfs_client_active_wq, |
76db6d95 | 509 | clp->cl_cons_state < NFS_CS_INITING); |
0bae89ec TM |
510 | if (error < 0) { |
511 | nfs_put_client(clp); | |
512 | return ERR_PTR(-ERESTARTSYS); | |
24c8dbbb DH |
513 | } |
514 | ||
515 | if (clp->cl_cons_state < NFS_CS_READY) { | |
516 | error = clp->cl_cons_state; | |
517 | nfs_put_client(clp); | |
518 | return ERR_PTR(error); | |
519 | } | |
520 | ||
54ceac45 DH |
521 | BUG_ON(clp->cl_cons_state != NFS_CS_READY); |
522 | ||
24c8dbbb DH |
523 | dprintk("--> nfs_get_client() = %p [share]\n", clp); |
524 | return clp; | |
525 | } | |
526 | ||
527 | /* | |
528 | * Mark a server as ready or failed | |
529 | */ | |
76db6d95 | 530 | void nfs_mark_client_ready(struct nfs_client *clp, int state) |
24c8dbbb DH |
531 | { |
532 | clp->cl_cons_state = state; | |
533 | wake_up_all(&nfs_client_active_wq); | |
534 | } | |
5006a76c | 535 | |
008f55d0 BH |
536 | /* |
537 | * With sessions, the client is not marked ready until after a | |
538 | * successful EXCHANGE_ID and CREATE_SESSION. | |
539 | * | |
540 | * Map errors cl_cons_state errors to EPROTONOSUPPORT to indicate | |
541 | * other versions of NFS can be tried. | |
542 | */ | |
543 | int nfs4_check_client_ready(struct nfs_client *clp) | |
544 | { | |
545 | if (!nfs4_has_session(clp)) | |
546 | return 0; | |
547 | if (clp->cl_cons_state < NFS_CS_READY) | |
548 | return -EPROTONOSUPPORT; | |
549 | return 0; | |
550 | } | |
551 | ||
5006a76c DH |
552 | /* |
553 | * Initialise the timeout values for a connection | |
554 | */ | |
555 | static void nfs_init_timeout_values(struct rpc_timeout *to, int proto, | |
556 | unsigned int timeo, unsigned int retrans) | |
557 | { | |
558 | to->to_initval = timeo * HZ / 10; | |
559 | to->to_retries = retrans; | |
5006a76c DH |
560 | |
561 | switch (proto) { | |
0896a725 | 562 | case XPRT_TRANSPORT_TCP: |
2cf7ff7a | 563 | case XPRT_TRANSPORT_RDMA: |
259875ef TM |
564 | if (to->to_retries == 0) |
565 | to->to_retries = NFS_DEF_TCP_RETRANS; | |
7a3e3e18 | 566 | if (to->to_initval == 0) |
259875ef | 567 | to->to_initval = NFS_DEF_TCP_TIMEO * HZ / 10; |
5006a76c DH |
568 | if (to->to_initval > NFS_MAX_TCP_TIMEOUT) |
569 | to->to_initval = NFS_MAX_TCP_TIMEOUT; | |
570 | to->to_increment = to->to_initval; | |
571 | to->to_maxval = to->to_initval + (to->to_increment * to->to_retries); | |
7a3e3e18 TM |
572 | if (to->to_maxval > NFS_MAX_TCP_TIMEOUT) |
573 | to->to_maxval = NFS_MAX_TCP_TIMEOUT; | |
574 | if (to->to_maxval < to->to_initval) | |
575 | to->to_maxval = to->to_initval; | |
5006a76c DH |
576 | to->to_exponential = 0; |
577 | break; | |
0896a725 | 578 | case XPRT_TRANSPORT_UDP: |
259875ef TM |
579 | if (to->to_retries == 0) |
580 | to->to_retries = NFS_DEF_UDP_RETRANS; | |
5006a76c | 581 | if (!to->to_initval) |
259875ef | 582 | to->to_initval = NFS_DEF_UDP_TIMEO * HZ / 10; |
5006a76c DH |
583 | if (to->to_initval > NFS_MAX_UDP_TIMEOUT) |
584 | to->to_initval = NFS_MAX_UDP_TIMEOUT; | |
585 | to->to_maxval = NFS_MAX_UDP_TIMEOUT; | |
586 | to->to_exponential = 1; | |
587 | break; | |
259875ef TM |
588 | default: |
589 | BUG(); | |
5006a76c DH |
590 | } |
591 | } | |
592 | ||
593 | /* | |
594 | * Create an RPC client handle | |
595 | */ | |
59dca3b2 | 596 | static int nfs_create_rpc_client(struct nfs_client *clp, |
33170233 TM |
597 | const struct rpc_timeout *timeparms, |
598 | rpc_authflavor_t flavor, | |
4a01b8a4 | 599 | int discrtry, int noresvport) |
5006a76c | 600 | { |
5006a76c | 601 | struct rpc_clnt *clnt = NULL; |
41877d20 | 602 | struct rpc_create_args args = { |
59dca3b2 | 603 | .protocol = clp->cl_proto, |
41877d20 | 604 | .address = (struct sockaddr *)&clp->cl_addr, |
6e4cffd7 | 605 | .addrsize = clp->cl_addrlen, |
33170233 | 606 | .timeout = timeparms, |
41877d20 CL |
607 | .servername = clp->cl_hostname, |
608 | .program = &nfs_program, | |
609 | .version = clp->rpc_ops->version, | |
610 | .authflavor = flavor, | |
611 | }; | |
5006a76c | 612 | |
4a01b8a4 CL |
613 | if (discrtry) |
614 | args.flags |= RPC_CLNT_CREATE_DISCRTRY; | |
615 | if (noresvport) | |
616 | args.flags |= RPC_CLNT_CREATE_NONPRIVPORT; | |
617 | ||
5006a76c DH |
618 | if (!IS_ERR(clp->cl_rpcclient)) |
619 | return 0; | |
620 | ||
41877d20 | 621 | clnt = rpc_create(&args); |
5006a76c DH |
622 | if (IS_ERR(clnt)) { |
623 | dprintk("%s: cannot create RPC client. Error = %ld\n", | |
3110ff80 | 624 | __func__, PTR_ERR(clnt)); |
5006a76c DH |
625 | return PTR_ERR(clnt); |
626 | } | |
627 | ||
5006a76c DH |
628 | clp->cl_rpcclient = clnt; |
629 | return 0; | |
630 | } | |
54ceac45 DH |
631 | |
632 | /* | |
633 | * Version 2 or 3 client destruction | |
634 | */ | |
635 | static void nfs_destroy_server(struct nfs_server *server) | |
636 | { | |
54ceac45 | 637 | if (!(server->flags & NFS_MOUNT_NONLM)) |
9289e7f9 | 638 | nlmclnt_done(server->nlm_host); |
54ceac45 DH |
639 | } |
640 | ||
641 | /* | |
642 | * Version 2 or 3 lockd setup | |
643 | */ | |
644 | static int nfs_start_lockd(struct nfs_server *server) | |
645 | { | |
9289e7f9 CL |
646 | struct nlm_host *host; |
647 | struct nfs_client *clp = server->nfs_client; | |
883bb163 CL |
648 | struct nlmclnt_initdata nlm_init = { |
649 | .hostname = clp->cl_hostname, | |
650 | .address = (struct sockaddr *)&clp->cl_addr, | |
651 | .addrlen = clp->cl_addrlen, | |
883bb163 | 652 | .nfs_version = clp->rpc_ops->version, |
0cb2659b CL |
653 | .noresvport = server->flags & NFS_MOUNT_NORESVPORT ? |
654 | 1 : 0, | |
883bb163 | 655 | }; |
54ceac45 | 656 | |
883bb163 | 657 | if (nlm_init.nfs_version > 3) |
9289e7f9 | 658 | return 0; |
54ceac45 | 659 | if (server->flags & NFS_MOUNT_NONLM) |
9289e7f9 CL |
660 | return 0; |
661 | ||
8a6e5deb TM |
662 | switch (clp->cl_proto) { |
663 | default: | |
664 | nlm_init.protocol = IPPROTO_TCP; | |
665 | break; | |
666 | case XPRT_TRANSPORT_UDP: | |
667 | nlm_init.protocol = IPPROTO_UDP; | |
668 | } | |
669 | ||
883bb163 | 670 | host = nlmclnt_init(&nlm_init); |
9289e7f9 CL |
671 | if (IS_ERR(host)) |
672 | return PTR_ERR(host); | |
673 | ||
674 | server->nlm_host = host; | |
675 | server->destroy = nfs_destroy_server; | |
676 | return 0; | |
54ceac45 DH |
677 | } |
678 | ||
679 | /* | |
680 | * Initialise an NFSv3 ACL client connection | |
681 | */ | |
682 | #ifdef CONFIG_NFS_V3_ACL | |
683 | static void nfs_init_server_aclclient(struct nfs_server *server) | |
684 | { | |
40c55319 | 685 | if (server->nfs_client->rpc_ops->version != 3) |
54ceac45 DH |
686 | goto out_noacl; |
687 | if (server->flags & NFS_MOUNT_NOACL) | |
688 | goto out_noacl; | |
689 | ||
690 | server->client_acl = rpc_bind_new_program(server->client, &nfsacl_program, 3); | |
691 | if (IS_ERR(server->client_acl)) | |
692 | goto out_noacl; | |
693 | ||
694 | /* No errors! Assume that Sun nfsacls are supported */ | |
695 | server->caps |= NFS_CAP_ACLS; | |
696 | return; | |
697 | ||
698 | out_noacl: | |
699 | server->caps &= ~NFS_CAP_ACLS; | |
700 | } | |
701 | #else | |
702 | static inline void nfs_init_server_aclclient(struct nfs_server *server) | |
703 | { | |
704 | server->flags &= ~NFS_MOUNT_NOACL; | |
705 | server->caps &= ~NFS_CAP_ACLS; | |
706 | } | |
707 | #endif | |
708 | ||
709 | /* | |
710 | * Create a general RPC client | |
711 | */ | |
33170233 TM |
712 | static int nfs_init_server_rpcclient(struct nfs_server *server, |
713 | const struct rpc_timeout *timeo, | |
714 | rpc_authflavor_t pseudoflavour) | |
54ceac45 DH |
715 | { |
716 | struct nfs_client *clp = server->nfs_client; | |
717 | ||
718 | server->client = rpc_clone_client(clp->cl_rpcclient); | |
719 | if (IS_ERR(server->client)) { | |
3110ff80 | 720 | dprintk("%s: couldn't create rpc_client!\n", __func__); |
54ceac45 DH |
721 | return PTR_ERR(server->client); |
722 | } | |
723 | ||
33170233 TM |
724 | memcpy(&server->client->cl_timeout_default, |
725 | timeo, | |
726 | sizeof(server->client->cl_timeout_default)); | |
727 | server->client->cl_timeout = &server->client->cl_timeout_default; | |
728 | ||
54ceac45 DH |
729 | if (pseudoflavour != clp->cl_rpcclient->cl_auth->au_flavor) { |
730 | struct rpc_auth *auth; | |
731 | ||
732 | auth = rpcauth_create(pseudoflavour, server->client); | |
733 | if (IS_ERR(auth)) { | |
3110ff80 | 734 | dprintk("%s: couldn't create credcache!\n", __func__); |
54ceac45 DH |
735 | return PTR_ERR(auth); |
736 | } | |
737 | } | |
738 | server->client->cl_softrtry = 0; | |
739 | if (server->flags & NFS_MOUNT_SOFT) | |
740 | server->client->cl_softrtry = 1; | |
741 | ||
54ceac45 DH |
742 | return 0; |
743 | } | |
744 | ||
745 | /* | |
746 | * Initialise an NFS2 or NFS3 client | |
747 | */ | |
2283f8d6 | 748 | static int nfs_init_client(struct nfs_client *clp, |
33170233 | 749 | const struct rpc_timeout *timeparms, |
2283f8d6 | 750 | const struct nfs_parsed_mount_data *data) |
54ceac45 | 751 | { |
54ceac45 DH |
752 | int error; |
753 | ||
754 | if (clp->cl_cons_state == NFS_CS_READY) { | |
755 | /* the client is already initialised */ | |
756 | dprintk("<-- nfs_init_client() = 0 [already %p]\n", clp); | |
757 | return 0; | |
758 | } | |
759 | ||
54ceac45 DH |
760 | /* |
761 | * Create a client RPC handle for doing FSSTAT with UNIX auth only | |
762 | * - RFC 2623, sec 2.3.2 | |
763 | */ | |
d740351b CL |
764 | error = nfs_create_rpc_client(clp, timeparms, RPC_AUTH_UNIX, |
765 | 0, data->flags & NFS_MOUNT_NORESVPORT); | |
54ceac45 DH |
766 | if (error < 0) |
767 | goto error; | |
768 | nfs_mark_client_ready(clp, NFS_CS_READY); | |
769 | return 0; | |
770 | ||
771 | error: | |
772 | nfs_mark_client_ready(clp, error); | |
773 | dprintk("<-- nfs_init_client() = xerror %d\n", error); | |
774 | return error; | |
775 | } | |
776 | ||
777 | /* | |
778 | * Create a version 2 or 3 client | |
779 | */ | |
2283f8d6 TT |
780 | static int nfs_init_server(struct nfs_server *server, |
781 | const struct nfs_parsed_mount_data *data) | |
54ceac45 | 782 | { |
3a498026 TM |
783 | struct nfs_client_initdata cl_init = { |
784 | .hostname = data->nfs_server.hostname, | |
d7422c47 | 785 | .addr = (const struct sockaddr *)&data->nfs_server.address, |
4c568017 | 786 | .addrlen = data->nfs_server.addrlen, |
40c55319 | 787 | .rpc_ops = &nfs_v2_clientops, |
59dca3b2 | 788 | .proto = data->nfs_server.protocol, |
3a498026 | 789 | }; |
33170233 | 790 | struct rpc_timeout timeparms; |
54ceac45 | 791 | struct nfs_client *clp; |
3a498026 | 792 | int error; |
54ceac45 DH |
793 | |
794 | dprintk("--> nfs_init_server()\n"); | |
795 | ||
796 | #ifdef CONFIG_NFS_V3 | |
8a6e5deb | 797 | if (data->version == 3) |
40c55319 | 798 | cl_init.rpc_ops = &nfs_v3_clientops; |
54ceac45 DH |
799 | #endif |
800 | ||
801 | /* Allocate or find a client reference we can use */ | |
3a498026 | 802 | clp = nfs_get_client(&cl_init); |
54ceac45 DH |
803 | if (IS_ERR(clp)) { |
804 | dprintk("<-- nfs_init_server() = error %ld\n", PTR_ERR(clp)); | |
805 | return PTR_ERR(clp); | |
806 | } | |
807 | ||
33170233 TM |
808 | nfs_init_timeout_values(&timeparms, data->nfs_server.protocol, |
809 | data->timeo, data->retrans); | |
810 | error = nfs_init_client(clp, &timeparms, data); | |
54ceac45 DH |
811 | if (error < 0) |
812 | goto error; | |
813 | ||
814 | server->nfs_client = clp; | |
815 | ||
816 | /* Initialise the client representation from the mount data */ | |
ff3525a5 | 817 | server->flags = data->flags; |
b797cac7 | 818 | server->options = data->options; |
62ab460c TM |
819 | server->caps |= NFS_CAP_HARDLINKS|NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
820 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER|NFS_CAP_OWNER_GROUP| | |
821 | NFS_CAP_ATIME|NFS_CAP_CTIME|NFS_CAP_MTIME; | |
54ceac45 DH |
822 | |
823 | if (data->rsize) | |
824 | server->rsize = nfs_block_size(data->rsize, NULL); | |
825 | if (data->wsize) | |
826 | server->wsize = nfs_block_size(data->wsize, NULL); | |
827 | ||
828 | server->acregmin = data->acregmin * HZ; | |
829 | server->acregmax = data->acregmax * HZ; | |
830 | server->acdirmin = data->acdirmin * HZ; | |
831 | server->acdirmax = data->acdirmax * HZ; | |
832 | ||
833 | /* Start lockd here, before we might error out */ | |
834 | error = nfs_start_lockd(server); | |
835 | if (error < 0) | |
836 | goto error; | |
837 | ||
f22d6d79 CL |
838 | server->port = data->nfs_server.port; |
839 | ||
33170233 | 840 | error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]); |
54ceac45 DH |
841 | if (error < 0) |
842 | goto error; | |
843 | ||
3f8400d1 CL |
844 | /* Preserve the values of mount_server-related mount options */ |
845 | if (data->mount_server.addrlen) { | |
846 | memcpy(&server->mountd_address, &data->mount_server.address, | |
847 | data->mount_server.addrlen); | |
848 | server->mountd_addrlen = data->mount_server.addrlen; | |
849 | } | |
850 | server->mountd_version = data->mount_server.version; | |
851 | server->mountd_port = data->mount_server.port; | |
852 | server->mountd_protocol = data->mount_server.protocol; | |
853 | ||
54ceac45 DH |
854 | server->namelen = data->namlen; |
855 | /* Create a client RPC handle for the NFSv3 ACL management interface */ | |
856 | nfs_init_server_aclclient(server); | |
54ceac45 DH |
857 | dprintk("<-- nfs_init_server() = 0 [new %p]\n", clp); |
858 | return 0; | |
859 | ||
860 | error: | |
861 | server->nfs_client = NULL; | |
862 | nfs_put_client(clp); | |
863 | dprintk("<-- nfs_init_server() = xerror %d\n", error); | |
864 | return error; | |
865 | } | |
866 | ||
867 | /* | |
868 | * Load up the server record from information gained in an fsinfo record | |
869 | */ | |
870 | static void nfs_server_set_fsinfo(struct nfs_server *server, struct nfs_fsinfo *fsinfo) | |
871 | { | |
872 | unsigned long max_rpc_payload; | |
873 | ||
874 | /* Work out a lot of parameters */ | |
875 | if (server->rsize == 0) | |
876 | server->rsize = nfs_block_size(fsinfo->rtpref, NULL); | |
877 | if (server->wsize == 0) | |
878 | server->wsize = nfs_block_size(fsinfo->wtpref, NULL); | |
879 | ||
880 | if (fsinfo->rtmax >= 512 && server->rsize > fsinfo->rtmax) | |
881 | server->rsize = nfs_block_size(fsinfo->rtmax, NULL); | |
882 | if (fsinfo->wtmax >= 512 && server->wsize > fsinfo->wtmax) | |
883 | server->wsize = nfs_block_size(fsinfo->wtmax, NULL); | |
884 | ||
885 | max_rpc_payload = nfs_block_size(rpc_max_payload(server->client), NULL); | |
886 | if (server->rsize > max_rpc_payload) | |
887 | server->rsize = max_rpc_payload; | |
888 | if (server->rsize > NFS_MAX_FILE_IO_SIZE) | |
889 | server->rsize = NFS_MAX_FILE_IO_SIZE; | |
890 | server->rpages = (server->rsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; | |
e0bf68dd | 891 | |
d993831f | 892 | server->backing_dev_info.name = "nfs"; |
54ceac45 DH |
893 | server->backing_dev_info.ra_pages = server->rpages * NFS_MAX_READAHEAD; |
894 | ||
895 | if (server->wsize > max_rpc_payload) | |
896 | server->wsize = max_rpc_payload; | |
897 | if (server->wsize > NFS_MAX_FILE_IO_SIZE) | |
898 | server->wsize = NFS_MAX_FILE_IO_SIZE; | |
899 | server->wpages = (server->wsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; | |
900 | server->wtmult = nfs_block_bits(fsinfo->wtmult, NULL); | |
901 | ||
902 | server->dtsize = nfs_block_size(fsinfo->dtpref, NULL); | |
903 | if (server->dtsize > PAGE_CACHE_SIZE) | |
904 | server->dtsize = PAGE_CACHE_SIZE; | |
905 | if (server->dtsize > server->rsize) | |
906 | server->dtsize = server->rsize; | |
907 | ||
908 | if (server->flags & NFS_MOUNT_NOAC) { | |
909 | server->acregmin = server->acregmax = 0; | |
910 | server->acdirmin = server->acdirmax = 0; | |
911 | } | |
912 | ||
913 | server->maxfilesize = fsinfo->maxfilesize; | |
914 | ||
915 | /* We're airborne Set socket buffersize */ | |
916 | rpc_setbufsize(server->client, server->wsize + 100, server->rsize + 100); | |
917 | } | |
918 | ||
919 | /* | |
920 | * Probe filesystem information, including the FSID on v2/v3 | |
921 | */ | |
922 | static int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *mntfh, struct nfs_fattr *fattr) | |
923 | { | |
924 | struct nfs_fsinfo fsinfo; | |
925 | struct nfs_client *clp = server->nfs_client; | |
926 | int error; | |
927 | ||
928 | dprintk("--> nfs_probe_fsinfo()\n"); | |
929 | ||
930 | if (clp->rpc_ops->set_capabilities != NULL) { | |
931 | error = clp->rpc_ops->set_capabilities(server, mntfh); | |
932 | if (error < 0) | |
933 | goto out_error; | |
934 | } | |
935 | ||
936 | fsinfo.fattr = fattr; | |
937 | nfs_fattr_init(fattr); | |
938 | error = clp->rpc_ops->fsinfo(server, mntfh, &fsinfo); | |
939 | if (error < 0) | |
940 | goto out_error; | |
941 | ||
942 | nfs_server_set_fsinfo(server, &fsinfo); | |
943 | ||
944 | /* Get some general file system info */ | |
945 | if (server->namelen == 0) { | |
946 | struct nfs_pathconf pathinfo; | |
947 | ||
948 | pathinfo.fattr = fattr; | |
949 | nfs_fattr_init(fattr); | |
950 | ||
951 | if (clp->rpc_ops->pathconf(server, mntfh, &pathinfo) >= 0) | |
952 | server->namelen = pathinfo.max_namelen; | |
953 | } | |
954 | ||
955 | dprintk("<-- nfs_probe_fsinfo() = 0\n"); | |
956 | return 0; | |
957 | ||
958 | out_error: | |
959 | dprintk("nfs_probe_fsinfo: error = %d\n", -error); | |
960 | return error; | |
961 | } | |
962 | ||
963 | /* | |
964 | * Copy useful information when duplicating a server record | |
965 | */ | |
966 | static void nfs_server_copy_userdata(struct nfs_server *target, struct nfs_server *source) | |
967 | { | |
968 | target->flags = source->flags; | |
356e76b8 CL |
969 | target->rsize = source->rsize; |
970 | target->wsize = source->wsize; | |
54ceac45 DH |
971 | target->acregmin = source->acregmin; |
972 | target->acregmax = source->acregmax; | |
973 | target->acdirmin = source->acdirmin; | |
974 | target->acdirmax = source->acdirmax; | |
975 | target->caps = source->caps; | |
2df54806 | 976 | target->options = source->options; |
54ceac45 DH |
977 | } |
978 | ||
979 | /* | |
980 | * Allocate and initialise a server record | |
981 | */ | |
982 | static struct nfs_server *nfs_alloc_server(void) | |
983 | { | |
984 | struct nfs_server *server; | |
985 | ||
986 | server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL); | |
987 | if (!server) | |
988 | return NULL; | |
989 | ||
990 | server->client = server->client_acl = ERR_PTR(-EINVAL); | |
991 | ||
992 | /* Zero out the NFS state stuff */ | |
993 | INIT_LIST_HEAD(&server->client_link); | |
994 | INIT_LIST_HEAD(&server->master_link); | |
995 | ||
ef818a28 SD |
996 | atomic_set(&server->active, 0); |
997 | ||
54ceac45 DH |
998 | server->io_stats = nfs_alloc_iostats(); |
999 | if (!server->io_stats) { | |
1000 | kfree(server); | |
1001 | return NULL; | |
1002 | } | |
1003 | ||
48d07649 JA |
1004 | if (bdi_init(&server->backing_dev_info)) { |
1005 | nfs_free_iostats(server->io_stats); | |
1006 | kfree(server); | |
1007 | return NULL; | |
1008 | } | |
1009 | ||
54ceac45 DH |
1010 | return server; |
1011 | } | |
1012 | ||
1013 | /* | |
1014 | * Free up a server record | |
1015 | */ | |
1016 | void nfs_free_server(struct nfs_server *server) | |
1017 | { | |
1018 | dprintk("--> nfs_free_server()\n"); | |
1019 | ||
1020 | spin_lock(&nfs_client_lock); | |
1021 | list_del(&server->client_link); | |
1022 | list_del(&server->master_link); | |
1023 | spin_unlock(&nfs_client_lock); | |
1024 | ||
1025 | if (server->destroy != NULL) | |
1026 | server->destroy(server); | |
5cef338b TM |
1027 | |
1028 | if (!IS_ERR(server->client_acl)) | |
1029 | rpc_shutdown_client(server->client_acl); | |
54ceac45 DH |
1030 | if (!IS_ERR(server->client)) |
1031 | rpc_shutdown_client(server->client); | |
1032 | ||
1033 | nfs_put_client(server->nfs_client); | |
1034 | ||
1035 | nfs_free_iostats(server->io_stats); | |
e0bf68dd | 1036 | bdi_destroy(&server->backing_dev_info); |
54ceac45 DH |
1037 | kfree(server); |
1038 | nfs_release_automount_timer(); | |
1039 | dprintk("<-- nfs_free_server()\n"); | |
1040 | } | |
1041 | ||
1042 | /* | |
1043 | * Create a version 2 or 3 volume record | |
1044 | * - keyed on server and FSID | |
1045 | */ | |
2283f8d6 | 1046 | struct nfs_server *nfs_create_server(const struct nfs_parsed_mount_data *data, |
54ceac45 DH |
1047 | struct nfs_fh *mntfh) |
1048 | { | |
1049 | struct nfs_server *server; | |
1050 | struct nfs_fattr fattr; | |
1051 | int error; | |
1052 | ||
1053 | server = nfs_alloc_server(); | |
1054 | if (!server) | |
1055 | return ERR_PTR(-ENOMEM); | |
1056 | ||
1057 | /* Get a client representation */ | |
1058 | error = nfs_init_server(server, data); | |
1059 | if (error < 0) | |
1060 | goto error; | |
1061 | ||
1062 | BUG_ON(!server->nfs_client); | |
1063 | BUG_ON(!server->nfs_client->rpc_ops); | |
1064 | BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops); | |
1065 | ||
1066 | /* Probe the root fh to retrieve its FSID */ | |
1067 | error = nfs_probe_fsinfo(server, mntfh, &fattr); | |
1068 | if (error < 0) | |
1069 | goto error; | |
54af3bb5 TM |
1070 | if (server->nfs_client->rpc_ops->version == 3) { |
1071 | if (server->namelen == 0 || server->namelen > NFS3_MAXNAMLEN) | |
1072 | server->namelen = NFS3_MAXNAMLEN; | |
1073 | if (!(data->flags & NFS_MOUNT_NORDIRPLUS)) | |
1074 | server->caps |= NFS_CAP_READDIRPLUS; | |
1075 | } else { | |
1076 | if (server->namelen == 0 || server->namelen > NFS2_MAXNAMLEN) | |
1077 | server->namelen = NFS2_MAXNAMLEN; | |
1078 | } | |
1079 | ||
54ceac45 DH |
1080 | if (!(fattr.valid & NFS_ATTR_FATTR)) { |
1081 | error = server->nfs_client->rpc_ops->getattr(server, mntfh, &fattr); | |
1082 | if (error < 0) { | |
1083 | dprintk("nfs_create_server: getattr error = %d\n", -error); | |
1084 | goto error; | |
1085 | } | |
1086 | } | |
1087 | memcpy(&server->fsid, &fattr.fsid, sizeof(server->fsid)); | |
1088 | ||
6daabf1b DH |
1089 | dprintk("Server FSID: %llx:%llx\n", |
1090 | (unsigned long long) server->fsid.major, | |
1091 | (unsigned long long) server->fsid.minor); | |
54ceac45 | 1092 | |
54ceac45 DH |
1093 | spin_lock(&nfs_client_lock); |
1094 | list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks); | |
1095 | list_add_tail(&server->master_link, &nfs_volume_list); | |
1096 | spin_unlock(&nfs_client_lock); | |
1097 | ||
1098 | server->mount_time = jiffies; | |
1099 | return server; | |
1100 | ||
1101 | error: | |
1102 | nfs_free_server(server); | |
1103 | return ERR_PTR(error); | |
1104 | } | |
1105 | ||
1106 | #ifdef CONFIG_NFS_V4 | |
9bdaa86d BH |
1107 | /* |
1108 | * Initialize the NFS4 callback service | |
1109 | */ | |
1110 | static int nfs4_init_callback(struct nfs_client *clp) | |
1111 | { | |
1112 | int error; | |
1113 | ||
1114 | if (clp->rpc_ops->version == 4) { | |
0b5b7ae0 AA |
1115 | if (nfs4_has_session(clp)) { |
1116 | error = xprt_setup_backchannel( | |
1117 | clp->cl_rpcclient->cl_xprt, | |
1118 | NFS41_BC_MIN_CALLBACKS); | |
1119 | if (error < 0) | |
1120 | return error; | |
1121 | } | |
1122 | ||
71468513 BH |
1123 | error = nfs_callback_up(clp->cl_minorversion, |
1124 | clp->cl_rpcclient->cl_xprt); | |
9bdaa86d BH |
1125 | if (error < 0) { |
1126 | dprintk("%s: failed to start callback. Error = %d\n", | |
1127 | __func__, error); | |
1128 | return error; | |
1129 | } | |
1130 | __set_bit(NFS_CS_CALLBACK, &clp->cl_res_state); | |
1131 | } | |
1132 | return 0; | |
1133 | } | |
1134 | ||
557134a3 AA |
1135 | /* |
1136 | * Initialize the minor version specific parts of an NFS4 client record | |
1137 | */ | |
1138 | static int nfs4_init_client_minor_version(struct nfs_client *clp) | |
1139 | { | |
cccef3b9 AA |
1140 | clp->cl_call_sync = _nfs4_call_sync; |
1141 | ||
557134a3 AA |
1142 | #if defined(CONFIG_NFS_V4_1) |
1143 | if (clp->cl_minorversion) { | |
1144 | struct nfs4_session *session = NULL; | |
1145 | /* | |
1146 | * Create the session and mark it expired. | |
1147 | * When a SEQUENCE operation encounters the expired session | |
1148 | * it will do session recovery to initialize it. | |
1149 | */ | |
1150 | session = nfs4_alloc_session(clp); | |
1151 | if (!session) | |
1152 | return -ENOMEM; | |
1153 | ||
1154 | clp->cl_session = session; | |
cccef3b9 | 1155 | clp->cl_call_sync = _nfs4_call_sync_session; |
557134a3 AA |
1156 | } |
1157 | #endif /* CONFIG_NFS_V4_1 */ | |
1158 | ||
71468513 | 1159 | return nfs4_init_callback(clp); |
557134a3 AA |
1160 | } |
1161 | ||
54ceac45 DH |
1162 | /* |
1163 | * Initialise an NFS4 client record | |
1164 | */ | |
1165 | static int nfs4_init_client(struct nfs_client *clp, | |
33170233 | 1166 | const struct rpc_timeout *timeparms, |
7d9ac06f | 1167 | const char *ip_addr, |
d740351b CL |
1168 | rpc_authflavor_t authflavour, |
1169 | int flags) | |
54ceac45 DH |
1170 | { |
1171 | int error; | |
1172 | ||
1173 | if (clp->cl_cons_state == NFS_CS_READY) { | |
1174 | /* the client is initialised already */ | |
1175 | dprintk("<-- nfs4_init_client() = 0 [already %p]\n", clp); | |
1176 | return 0; | |
1177 | } | |
1178 | ||
1179 | /* Check NFS protocol revision and initialize RPC op vector */ | |
1180 | clp->rpc_ops = &nfs_v4_clientops; | |
1181 | ||
59dca3b2 | 1182 | error = nfs_create_rpc_client(clp, timeparms, authflavour, |
d740351b | 1183 | 1, flags & NFS_MOUNT_NORESVPORT); |
54ceac45 DH |
1184 | if (error < 0) |
1185 | goto error; | |
f4373bf9 | 1186 | strlcpy(clp->cl_ipaddr, ip_addr, sizeof(clp->cl_ipaddr)); |
54ceac45 DH |
1187 | |
1188 | error = nfs_idmap_new(clp); | |
1189 | if (error < 0) { | |
1190 | dprintk("%s: failed to create idmapper. Error = %d\n", | |
3110ff80 | 1191 | __func__, error); |
54ceac45 DH |
1192 | goto error; |
1193 | } | |
9c5bf38d | 1194 | __set_bit(NFS_CS_IDMAP, &clp->cl_res_state); |
54ceac45 | 1195 | |
557134a3 AA |
1196 | error = nfs4_init_client_minor_version(clp); |
1197 | if (error < 0) | |
1198 | goto error; | |
1199 | ||
76db6d95 AA |
1200 | if (!nfs4_has_session(clp)) |
1201 | nfs_mark_client_ready(clp, NFS_CS_READY); | |
54ceac45 DH |
1202 | return 0; |
1203 | ||
1204 | error: | |
1205 | nfs_mark_client_ready(clp, error); | |
1206 | dprintk("<-- nfs4_init_client() = xerror %d\n", error); | |
1207 | return error; | |
1208 | } | |
1209 | ||
1210 | /* | |
1211 | * Set up an NFS4 client | |
1212 | */ | |
1213 | static int nfs4_set_client(struct nfs_server *server, | |
dcecae0f CL |
1214 | const char *hostname, |
1215 | const struct sockaddr *addr, | |
1216 | const size_t addrlen, | |
7d9ac06f | 1217 | const char *ip_addr, |
54ceac45 | 1218 | rpc_authflavor_t authflavour, |
94a417f3 BH |
1219 | int proto, const struct rpc_timeout *timeparms, |
1220 | u32 minorversion) | |
54ceac45 | 1221 | { |
3a498026 TM |
1222 | struct nfs_client_initdata cl_init = { |
1223 | .hostname = hostname, | |
dcecae0f CL |
1224 | .addr = addr, |
1225 | .addrlen = addrlen, | |
40c55319 | 1226 | .rpc_ops = &nfs_v4_clientops, |
59dca3b2 | 1227 | .proto = proto, |
5aae4a9a | 1228 | .minorversion = minorversion, |
3a498026 | 1229 | }; |
54ceac45 DH |
1230 | struct nfs_client *clp; |
1231 | int error; | |
1232 | ||
1233 | dprintk("--> nfs4_set_client()\n"); | |
1234 | ||
1235 | /* Allocate or find a client reference we can use */ | |
3a498026 | 1236 | clp = nfs_get_client(&cl_init); |
54ceac45 DH |
1237 | if (IS_ERR(clp)) { |
1238 | error = PTR_ERR(clp); | |
1239 | goto error; | |
1240 | } | |
d740351b CL |
1241 | error = nfs4_init_client(clp, timeparms, ip_addr, authflavour, |
1242 | server->flags); | |
54ceac45 DH |
1243 | if (error < 0) |
1244 | goto error_put; | |
1245 | ||
1246 | server->nfs_client = clp; | |
1247 | dprintk("<-- nfs4_set_client() = 0 [new %p]\n", clp); | |
1248 | return 0; | |
1249 | ||
1250 | error_put: | |
1251 | nfs_put_client(clp); | |
1252 | error: | |
1253 | dprintk("<-- nfs4_set_client() = xerror %d\n", error); | |
1254 | return error; | |
1255 | } | |
1256 | ||
557134a3 | 1257 | |
96b09e02 AA |
1258 | /* |
1259 | * Session has been established, and the client marked ready. | |
1260 | * Set the mount rsize and wsize with negotiated fore channel | |
1261 | * attributes which will be bound checked in nfs_server_set_fsinfo. | |
1262 | */ | |
1263 | static void nfs4_session_set_rwsize(struct nfs_server *server) | |
1264 | { | |
1265 | #ifdef CONFIG_NFS_V4_1 | |
2449ea2e AB |
1266 | struct nfs4_session *sess; |
1267 | u32 server_resp_sz; | |
1268 | u32 server_rqst_sz; | |
1269 | ||
96b09e02 AA |
1270 | if (!nfs4_has_session(server->nfs_client)) |
1271 | return; | |
2449ea2e AB |
1272 | sess = server->nfs_client->cl_session; |
1273 | server_resp_sz = sess->fc_attrs.max_resp_sz - nfs41_maxread_overhead; | |
1274 | server_rqst_sz = sess->fc_attrs.max_rqst_sz - nfs41_maxwrite_overhead; | |
1275 | ||
1276 | if (server->rsize > server_resp_sz) | |
1277 | server->rsize = server_resp_sz; | |
1278 | if (server->wsize > server_rqst_sz) | |
1279 | server->wsize = server_rqst_sz; | |
96b09e02 AA |
1280 | #endif /* CONFIG_NFS_V4_1 */ |
1281 | } | |
1282 | ||
54ceac45 DH |
1283 | /* |
1284 | * Create a version 4 volume record | |
1285 | */ | |
1286 | static int nfs4_init_server(struct nfs_server *server, | |
91ea40b9 | 1287 | const struct nfs_parsed_mount_data *data) |
54ceac45 | 1288 | { |
33170233 | 1289 | struct rpc_timeout timeparms; |
54ceac45 DH |
1290 | int error; |
1291 | ||
1292 | dprintk("--> nfs4_init_server()\n"); | |
1293 | ||
33170233 TM |
1294 | nfs_init_timeout_values(&timeparms, data->nfs_server.protocol, |
1295 | data->timeo, data->retrans); | |
1296 | ||
542fcc33 CL |
1297 | /* Initialise the client representation from the mount data */ |
1298 | server->flags = data->flags; | |
0df5dd4a TM |
1299 | server->caps |= NFS_CAP_ATOMIC_OPEN|NFS_CAP_CHANGE_ATTR| |
1300 | NFS_CAP_POSIX_LOCK; | |
b797cac7 | 1301 | server->options = data->options; |
542fcc33 | 1302 | |
33170233 TM |
1303 | /* Get a client record */ |
1304 | error = nfs4_set_client(server, | |
1305 | data->nfs_server.hostname, | |
1306 | (const struct sockaddr *)&data->nfs_server.address, | |
1307 | data->nfs_server.addrlen, | |
1308 | data->client_address, | |
1309 | data->auth_flavors[0], | |
1310 | data->nfs_server.protocol, | |
94a417f3 BH |
1311 | &timeparms, |
1312 | data->minorversion); | |
33170233 TM |
1313 | if (error < 0) |
1314 | goto error; | |
1315 | ||
54ceac45 DH |
1316 | if (data->rsize) |
1317 | server->rsize = nfs_block_size(data->rsize, NULL); | |
1318 | if (data->wsize) | |
1319 | server->wsize = nfs_block_size(data->wsize, NULL); | |
1320 | ||
1321 | server->acregmin = data->acregmin * HZ; | |
1322 | server->acregmax = data->acregmax * HZ; | |
1323 | server->acdirmin = data->acdirmin * HZ; | |
1324 | server->acdirmax = data->acdirmax * HZ; | |
1325 | ||
f22d6d79 CL |
1326 | server->port = data->nfs_server.port; |
1327 | ||
33170233 | 1328 | error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]); |
54ceac45 | 1329 | |
33170233 | 1330 | error: |
54ceac45 DH |
1331 | /* Done */ |
1332 | dprintk("<-- nfs4_init_server() = %d\n", error); | |
1333 | return error; | |
1334 | } | |
1335 | ||
1336 | /* | |
1337 | * Create a version 4 volume record | |
1338 | * - keyed on server and FSID | |
1339 | */ | |
91ea40b9 | 1340 | struct nfs_server *nfs4_create_server(const struct nfs_parsed_mount_data *data, |
54ceac45 DH |
1341 | struct nfs_fh *mntfh) |
1342 | { | |
1343 | struct nfs_fattr fattr; | |
1344 | struct nfs_server *server; | |
1345 | int error; | |
1346 | ||
1347 | dprintk("--> nfs4_create_server()\n"); | |
1348 | ||
1349 | server = nfs_alloc_server(); | |
1350 | if (!server) | |
1351 | return ERR_PTR(-ENOMEM); | |
1352 | ||
54ceac45 | 1353 | /* set up the general RPC client */ |
91ea40b9 | 1354 | error = nfs4_init_server(server, data); |
54ceac45 DH |
1355 | if (error < 0) |
1356 | goto error; | |
1357 | ||
1358 | BUG_ON(!server->nfs_client); | |
1359 | BUG_ON(!server->nfs_client->rpc_ops); | |
1360 | BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops); | |
1361 | ||
fccba804 TM |
1362 | error = nfs4_init_session(server); |
1363 | if (error < 0) | |
1364 | goto error; | |
557134a3 | 1365 | |
54ceac45 | 1366 | /* Probe the root fh to retrieve its FSID */ |
91ea40b9 | 1367 | error = nfs4_path_walk(server, mntfh, data->nfs_server.export_path); |
54ceac45 DH |
1368 | if (error < 0) |
1369 | goto error; | |
1370 | ||
6daabf1b DH |
1371 | dprintk("Server FSID: %llx:%llx\n", |
1372 | (unsigned long long) server->fsid.major, | |
1373 | (unsigned long long) server->fsid.minor); | |
54ceac45 DH |
1374 | dprintk("Mount FH: %d\n", mntfh->size); |
1375 | ||
96b09e02 AA |
1376 | nfs4_session_set_rwsize(server); |
1377 | ||
54ceac45 DH |
1378 | error = nfs_probe_fsinfo(server, mntfh, &fattr); |
1379 | if (error < 0) | |
1380 | goto error; | |
1381 | ||
54af3bb5 TM |
1382 | if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN) |
1383 | server->namelen = NFS4_MAXNAMLEN; | |
1384 | ||
54ceac45 DH |
1385 | spin_lock(&nfs_client_lock); |
1386 | list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks); | |
1387 | list_add_tail(&server->master_link, &nfs_volume_list); | |
1388 | spin_unlock(&nfs_client_lock); | |
1389 | ||
1390 | server->mount_time = jiffies; | |
1391 | dprintk("<-- nfs4_create_server() = %p\n", server); | |
1392 | return server; | |
1393 | ||
1394 | error: | |
1395 | nfs_free_server(server); | |
1396 | dprintk("<-- nfs4_create_server() = error %d\n", error); | |
1397 | return ERR_PTR(error); | |
1398 | } | |
1399 | ||
1400 | /* | |
1401 | * Create an NFS4 referral server record | |
1402 | */ | |
1403 | struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data, | |
f2d0d85e | 1404 | struct nfs_fh *mntfh) |
54ceac45 DH |
1405 | { |
1406 | struct nfs_client *parent_client; | |
1407 | struct nfs_server *server, *parent_server; | |
1408 | struct nfs_fattr fattr; | |
1409 | int error; | |
1410 | ||
1411 | dprintk("--> nfs4_create_referral_server()\n"); | |
1412 | ||
1413 | server = nfs_alloc_server(); | |
1414 | if (!server) | |
1415 | return ERR_PTR(-ENOMEM); | |
1416 | ||
1417 | parent_server = NFS_SB(data->sb); | |
1418 | parent_client = parent_server->nfs_client; | |
1419 | ||
542fcc33 CL |
1420 | /* Initialise the client representation from the parent server */ |
1421 | nfs_server_copy_userdata(server, parent_server); | |
62ab460c | 1422 | server->caps |= NFS_CAP_ATOMIC_OPEN|NFS_CAP_CHANGE_ATTR; |
542fcc33 | 1423 | |
54ceac45 DH |
1424 | /* Get a client representation. |
1425 | * Note: NFSv4 always uses TCP, */ | |
dcecae0f | 1426 | error = nfs4_set_client(server, data->hostname, |
6677d095 CL |
1427 | data->addr, |
1428 | data->addrlen, | |
dcecae0f CL |
1429 | parent_client->cl_ipaddr, |
1430 | data->authflavor, | |
1431 | parent_server->client->cl_xprt->prot, | |
94a417f3 BH |
1432 | parent_server->client->cl_timeout, |
1433 | parent_client->cl_minorversion); | |
297de4f6 AA |
1434 | if (error < 0) |
1435 | goto error; | |
54ceac45 | 1436 | |
33170233 | 1437 | error = nfs_init_server_rpcclient(server, parent_server->client->cl_timeout, data->authflavor); |
54ceac45 DH |
1438 | if (error < 0) |
1439 | goto error; | |
1440 | ||
1441 | BUG_ON(!server->nfs_client); | |
1442 | BUG_ON(!server->nfs_client->rpc_ops); | |
1443 | BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops); | |
1444 | ||
f2d0d85e TM |
1445 | /* Probe the root fh to retrieve its FSID and filehandle */ |
1446 | error = nfs4_path_walk(server, mntfh, data->mnt_path); | |
1447 | if (error < 0) | |
1448 | goto error; | |
1449 | ||
54ceac45 | 1450 | /* probe the filesystem info for this server filesystem */ |
f2d0d85e | 1451 | error = nfs_probe_fsinfo(server, mntfh, &fattr); |
54ceac45 DH |
1452 | if (error < 0) |
1453 | goto error; | |
1454 | ||
54af3bb5 TM |
1455 | if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN) |
1456 | server->namelen = NFS4_MAXNAMLEN; | |
1457 | ||
54ceac45 | 1458 | dprintk("Referral FSID: %llx:%llx\n", |
6daabf1b DH |
1459 | (unsigned long long) server->fsid.major, |
1460 | (unsigned long long) server->fsid.minor); | |
54ceac45 DH |
1461 | |
1462 | spin_lock(&nfs_client_lock); | |
1463 | list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks); | |
1464 | list_add_tail(&server->master_link, &nfs_volume_list); | |
1465 | spin_unlock(&nfs_client_lock); | |
1466 | ||
1467 | server->mount_time = jiffies; | |
1468 | ||
1469 | dprintk("<-- nfs_create_referral_server() = %p\n", server); | |
1470 | return server; | |
1471 | ||
1472 | error: | |
1473 | nfs_free_server(server); | |
1474 | dprintk("<-- nfs4_create_referral_server() = error %d\n", error); | |
1475 | return ERR_PTR(error); | |
1476 | } | |
1477 | ||
1478 | #endif /* CONFIG_NFS_V4 */ | |
1479 | ||
1480 | /* | |
1481 | * Clone an NFS2, NFS3 or NFS4 server record | |
1482 | */ | |
1483 | struct nfs_server *nfs_clone_server(struct nfs_server *source, | |
1484 | struct nfs_fh *fh, | |
1485 | struct nfs_fattr *fattr) | |
1486 | { | |
1487 | struct nfs_server *server; | |
1488 | struct nfs_fattr fattr_fsinfo; | |
1489 | int error; | |
1490 | ||
1491 | dprintk("--> nfs_clone_server(,%llx:%llx,)\n", | |
6daabf1b DH |
1492 | (unsigned long long) fattr->fsid.major, |
1493 | (unsigned long long) fattr->fsid.minor); | |
54ceac45 DH |
1494 | |
1495 | server = nfs_alloc_server(); | |
1496 | if (!server) | |
1497 | return ERR_PTR(-ENOMEM); | |
1498 | ||
1499 | /* Copy data from the source */ | |
1500 | server->nfs_client = source->nfs_client; | |
1501 | atomic_inc(&server->nfs_client->cl_count); | |
1502 | nfs_server_copy_userdata(server, source); | |
1503 | ||
1504 | server->fsid = fattr->fsid; | |
1505 | ||
33170233 TM |
1506 | error = nfs_init_server_rpcclient(server, |
1507 | source->client->cl_timeout, | |
1508 | source->client->cl_auth->au_flavor); | |
54ceac45 DH |
1509 | if (error < 0) |
1510 | goto out_free_server; | |
1511 | if (!IS_ERR(source->client_acl)) | |
1512 | nfs_init_server_aclclient(server); | |
1513 | ||
1514 | /* probe the filesystem info for this server filesystem */ | |
1515 | error = nfs_probe_fsinfo(server, fh, &fattr_fsinfo); | |
1516 | if (error < 0) | |
1517 | goto out_free_server; | |
1518 | ||
54af3bb5 TM |
1519 | if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN) |
1520 | server->namelen = NFS4_MAXNAMLEN; | |
1521 | ||
54ceac45 | 1522 | dprintk("Cloned FSID: %llx:%llx\n", |
6daabf1b DH |
1523 | (unsigned long long) server->fsid.major, |
1524 | (unsigned long long) server->fsid.minor); | |
54ceac45 DH |
1525 | |
1526 | error = nfs_start_lockd(server); | |
1527 | if (error < 0) | |
1528 | goto out_free_server; | |
1529 | ||
1530 | spin_lock(&nfs_client_lock); | |
1531 | list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks); | |
1532 | list_add_tail(&server->master_link, &nfs_volume_list); | |
1533 | spin_unlock(&nfs_client_lock); | |
1534 | ||
1535 | server->mount_time = jiffies; | |
1536 | ||
1537 | dprintk("<-- nfs_clone_server() = %p\n", server); | |
1538 | return server; | |
1539 | ||
1540 | out_free_server: | |
1541 | nfs_free_server(server); | |
1542 | dprintk("<-- nfs_clone_server() = error %d\n", error); | |
1543 | return ERR_PTR(error); | |
1544 | } | |
6aaca566 DH |
1545 | |
1546 | #ifdef CONFIG_PROC_FS | |
1547 | static struct proc_dir_entry *proc_fs_nfs; | |
1548 | ||
1549 | static int nfs_server_list_open(struct inode *inode, struct file *file); | |
1550 | static void *nfs_server_list_start(struct seq_file *p, loff_t *pos); | |
1551 | static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos); | |
1552 | static void nfs_server_list_stop(struct seq_file *p, void *v); | |
1553 | static int nfs_server_list_show(struct seq_file *m, void *v); | |
1554 | ||
88e9d34c | 1555 | static const struct seq_operations nfs_server_list_ops = { |
6aaca566 DH |
1556 | .start = nfs_server_list_start, |
1557 | .next = nfs_server_list_next, | |
1558 | .stop = nfs_server_list_stop, | |
1559 | .show = nfs_server_list_show, | |
1560 | }; | |
1561 | ||
00977a59 | 1562 | static const struct file_operations nfs_server_list_fops = { |
6aaca566 DH |
1563 | .open = nfs_server_list_open, |
1564 | .read = seq_read, | |
1565 | .llseek = seq_lseek, | |
1566 | .release = seq_release, | |
34b37235 | 1567 | .owner = THIS_MODULE, |
6aaca566 DH |
1568 | }; |
1569 | ||
1570 | static int nfs_volume_list_open(struct inode *inode, struct file *file); | |
1571 | static void *nfs_volume_list_start(struct seq_file *p, loff_t *pos); | |
1572 | static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos); | |
1573 | static void nfs_volume_list_stop(struct seq_file *p, void *v); | |
1574 | static int nfs_volume_list_show(struct seq_file *m, void *v); | |
1575 | ||
88e9d34c | 1576 | static const struct seq_operations nfs_volume_list_ops = { |
6aaca566 DH |
1577 | .start = nfs_volume_list_start, |
1578 | .next = nfs_volume_list_next, | |
1579 | .stop = nfs_volume_list_stop, | |
1580 | .show = nfs_volume_list_show, | |
1581 | }; | |
1582 | ||
00977a59 | 1583 | static const struct file_operations nfs_volume_list_fops = { |
6aaca566 DH |
1584 | .open = nfs_volume_list_open, |
1585 | .read = seq_read, | |
1586 | .llseek = seq_lseek, | |
1587 | .release = seq_release, | |
34b37235 | 1588 | .owner = THIS_MODULE, |
6aaca566 DH |
1589 | }; |
1590 | ||
1591 | /* | |
1592 | * open "/proc/fs/nfsfs/servers" which provides a summary of servers with which | |
1593 | * we're dealing | |
1594 | */ | |
1595 | static int nfs_server_list_open(struct inode *inode, struct file *file) | |
1596 | { | |
1597 | struct seq_file *m; | |
1598 | int ret; | |
1599 | ||
1600 | ret = seq_open(file, &nfs_server_list_ops); | |
1601 | if (ret < 0) | |
1602 | return ret; | |
1603 | ||
1604 | m = file->private_data; | |
1605 | m->private = PDE(inode)->data; | |
1606 | ||
1607 | return 0; | |
1608 | } | |
1609 | ||
1610 | /* | |
1611 | * set up the iterator to start reading from the server list and return the first item | |
1612 | */ | |
1613 | static void *nfs_server_list_start(struct seq_file *m, loff_t *_pos) | |
1614 | { | |
6aaca566 DH |
1615 | /* lock the list against modification */ |
1616 | spin_lock(&nfs_client_lock); | |
259902ea | 1617 | return seq_list_start_head(&nfs_client_list, *_pos); |
6aaca566 DH |
1618 | } |
1619 | ||
1620 | /* | |
1621 | * move to next server | |
1622 | */ | |
1623 | static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos) | |
1624 | { | |
259902ea | 1625 | return seq_list_next(v, &nfs_client_list, pos); |
6aaca566 DH |
1626 | } |
1627 | ||
1628 | /* | |
1629 | * clean up after reading from the transports list | |
1630 | */ | |
1631 | static void nfs_server_list_stop(struct seq_file *p, void *v) | |
1632 | { | |
1633 | spin_unlock(&nfs_client_lock); | |
1634 | } | |
1635 | ||
1636 | /* | |
1637 | * display a header line followed by a load of call lines | |
1638 | */ | |
1639 | static int nfs_server_list_show(struct seq_file *m, void *v) | |
1640 | { | |
1641 | struct nfs_client *clp; | |
1642 | ||
1643 | /* display header on line 1 */ | |
259902ea | 1644 | if (v == &nfs_client_list) { |
6aaca566 DH |
1645 | seq_puts(m, "NV SERVER PORT USE HOSTNAME\n"); |
1646 | return 0; | |
1647 | } | |
1648 | ||
1649 | /* display one transport per line on subsequent lines */ | |
1650 | clp = list_entry(v, struct nfs_client, cl_share_link); | |
1651 | ||
5d8515ca | 1652 | seq_printf(m, "v%u %s %s %3d %s\n", |
40c55319 | 1653 | clp->rpc_ops->version, |
5d8515ca CL |
1654 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR), |
1655 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT), | |
6aaca566 DH |
1656 | atomic_read(&clp->cl_count), |
1657 | clp->cl_hostname); | |
1658 | ||
1659 | return 0; | |
1660 | } | |
1661 | ||
1662 | /* | |
1663 | * open "/proc/fs/nfsfs/volumes" which provides a summary of extant volumes | |
1664 | */ | |
1665 | static int nfs_volume_list_open(struct inode *inode, struct file *file) | |
1666 | { | |
1667 | struct seq_file *m; | |
1668 | int ret; | |
1669 | ||
1670 | ret = seq_open(file, &nfs_volume_list_ops); | |
1671 | if (ret < 0) | |
1672 | return ret; | |
1673 | ||
1674 | m = file->private_data; | |
1675 | m->private = PDE(inode)->data; | |
1676 | ||
1677 | return 0; | |
1678 | } | |
1679 | ||
1680 | /* | |
1681 | * set up the iterator to start reading from the volume list and return the first item | |
1682 | */ | |
1683 | static void *nfs_volume_list_start(struct seq_file *m, loff_t *_pos) | |
1684 | { | |
6aaca566 DH |
1685 | /* lock the list against modification */ |
1686 | spin_lock(&nfs_client_lock); | |
259902ea | 1687 | return seq_list_start_head(&nfs_volume_list, *_pos); |
6aaca566 DH |
1688 | } |
1689 | ||
1690 | /* | |
1691 | * move to next volume | |
1692 | */ | |
1693 | static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos) | |
1694 | { | |
259902ea | 1695 | return seq_list_next(v, &nfs_volume_list, pos); |
6aaca566 DH |
1696 | } |
1697 | ||
1698 | /* | |
1699 | * clean up after reading from the transports list | |
1700 | */ | |
1701 | static void nfs_volume_list_stop(struct seq_file *p, void *v) | |
1702 | { | |
1703 | spin_unlock(&nfs_client_lock); | |
1704 | } | |
1705 | ||
1706 | /* | |
1707 | * display a header line followed by a load of call lines | |
1708 | */ | |
1709 | static int nfs_volume_list_show(struct seq_file *m, void *v) | |
1710 | { | |
1711 | struct nfs_server *server; | |
1712 | struct nfs_client *clp; | |
1713 | char dev[8], fsid[17]; | |
1714 | ||
1715 | /* display header on line 1 */ | |
259902ea | 1716 | if (v == &nfs_volume_list) { |
5d1acff1 | 1717 | seq_puts(m, "NV SERVER PORT DEV FSID FSC\n"); |
6aaca566 DH |
1718 | return 0; |
1719 | } | |
1720 | /* display one transport per line on subsequent lines */ | |
1721 | server = list_entry(v, struct nfs_server, master_link); | |
1722 | clp = server->nfs_client; | |
1723 | ||
1724 | snprintf(dev, 8, "%u:%u", | |
1725 | MAJOR(server->s_dev), MINOR(server->s_dev)); | |
1726 | ||
1727 | snprintf(fsid, 17, "%llx:%llx", | |
6daabf1b DH |
1728 | (unsigned long long) server->fsid.major, |
1729 | (unsigned long long) server->fsid.minor); | |
6aaca566 | 1730 | |
5d1acff1 | 1731 | seq_printf(m, "v%u %s %s %-7s %-17s %s\n", |
40c55319 | 1732 | clp->rpc_ops->version, |
5d8515ca CL |
1733 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR), |
1734 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT), | |
6aaca566 | 1735 | dev, |
5d1acff1 DH |
1736 | fsid, |
1737 | nfs_server_fscache_state(server)); | |
6aaca566 DH |
1738 | |
1739 | return 0; | |
1740 | } | |
1741 | ||
1742 | /* | |
1743 | * initialise the /proc/fs/nfsfs/ directory | |
1744 | */ | |
1745 | int __init nfs_fs_proc_init(void) | |
1746 | { | |
1747 | struct proc_dir_entry *p; | |
1748 | ||
36a5aeb8 | 1749 | proc_fs_nfs = proc_mkdir("fs/nfsfs", NULL); |
6aaca566 DH |
1750 | if (!proc_fs_nfs) |
1751 | goto error_0; | |
1752 | ||
6aaca566 | 1753 | /* a file of servers with which we're dealing */ |
34b37235 DL |
1754 | p = proc_create("servers", S_IFREG|S_IRUGO, |
1755 | proc_fs_nfs, &nfs_server_list_fops); | |
6aaca566 DH |
1756 | if (!p) |
1757 | goto error_1; | |
1758 | ||
6aaca566 | 1759 | /* a file of volumes that we have mounted */ |
34b37235 DL |
1760 | p = proc_create("volumes", S_IFREG|S_IRUGO, |
1761 | proc_fs_nfs, &nfs_volume_list_fops); | |
6aaca566 DH |
1762 | if (!p) |
1763 | goto error_2; | |
6aaca566 DH |
1764 | return 0; |
1765 | ||
1766 | error_2: | |
1767 | remove_proc_entry("servers", proc_fs_nfs); | |
1768 | error_1: | |
36a5aeb8 | 1769 | remove_proc_entry("fs/nfsfs", NULL); |
6aaca566 DH |
1770 | error_0: |
1771 | return -ENOMEM; | |
1772 | } | |
1773 | ||
1774 | /* | |
1775 | * clean up the /proc/fs/nfsfs/ directory | |
1776 | */ | |
1777 | void nfs_fs_proc_exit(void) | |
1778 | { | |
1779 | remove_proc_entry("volumes", proc_fs_nfs); | |
1780 | remove_proc_entry("servers", proc_fs_nfs); | |
36a5aeb8 | 1781 | remove_proc_entry("fs/nfsfs", NULL); |
6aaca566 DH |
1782 | } |
1783 | ||
1784 | #endif /* CONFIG_PROC_FS */ |