1 /* client.c: NFS client sharing and management code
3 * Copyright (C) 2006 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
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.
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/sched.h>
16 #include <linux/time.h>
17 #include <linux/kernel.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>
26 #include <linux/sunrpc/xprtsock.h>
27 #include <linux/sunrpc/xprtrdma.h>
28 #include <linux/nfs_fs.h>
29 #include <linux/nfs_mount.h>
30 #include <linux/nfs4_mount.h>
31 #include <linux/lockd/bind.h>
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>
37 #include <linux/in6.h>
38 #include <linux/slab.h>
40 #include <linux/nfs_xdr.h>
41 #include <linux/sunrpc/bc_xprt.h>
43 #include <asm/system.h>
47 #include "delegation.h"
52 #define NFSDBG_FACILITY NFSDBG_CLIENT
54 static DEFINE_SPINLOCK(nfs_client_lock
);
55 static LIST_HEAD(nfs_client_list
);
56 static LIST_HEAD(nfs_volume_list
);
57 static DECLARE_WAIT_QUEUE_HEAD(nfs_client_active_wq
);
62 static struct rpc_version
*nfs_version
[5] = {
72 struct rpc_program nfs_program
= {
74 .number
= NFS_PROGRAM
,
75 .nrvers
= ARRAY_SIZE(nfs_version
),
76 .version
= nfs_version
,
77 .stats
= &nfs_rpcstat
,
78 .pipe_dir_name
= "/nfs",
81 struct rpc_stat nfs_rpcstat
= {
82 .program
= &nfs_program
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
,
92 struct rpc_program nfsacl_program
= {
94 .number
= NFS_ACL_PROGRAM
,
95 .nrvers
= ARRAY_SIZE(nfsacl_version
),
96 .version
= nfsacl_version
,
97 .stats
= &nfsacl_rpcstat
,
99 #endif /* CONFIG_NFS_V3_ACL */
101 struct nfs_client_initdata
{
102 const char *hostname
;
103 const struct sockaddr
*addr
;
105 const struct nfs_rpc_ops
*rpc_ops
;
111 * Allocate a shared client record
113 * Since these are allocated/deallocated very rarely, we don't
114 * bother putting them in a slab cache...
116 static struct nfs_client
*nfs_alloc_client(const struct nfs_client_initdata
*cl_init
)
118 struct nfs_client
*clp
;
119 struct rpc_cred
*cred
;
122 if ((clp
= kzalloc(sizeof(*clp
), GFP_KERNEL
)) == NULL
)
125 clp
->rpc_ops
= cl_init
->rpc_ops
;
127 atomic_set(&clp
->cl_count
, 1);
128 clp
->cl_cons_state
= NFS_CS_INITING
;
130 memcpy(&clp
->cl_addr
, cl_init
->addr
, cl_init
->addrlen
);
131 clp
->cl_addrlen
= cl_init
->addrlen
;
133 if (cl_init
->hostname
) {
135 clp
->cl_hostname
= kstrdup(cl_init
->hostname
, GFP_KERNEL
);
136 if (!clp
->cl_hostname
)
140 INIT_LIST_HEAD(&clp
->cl_superblocks
);
141 clp
->cl_rpcclient
= ERR_PTR(-EINVAL
);
143 clp
->cl_proto
= cl_init
->proto
;
146 INIT_LIST_HEAD(&clp
->cl_delegations
);
147 spin_lock_init(&clp
->cl_lock
);
148 INIT_DELAYED_WORK(&clp
->cl_renewd
, nfs4_renew_state
);
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
;
152 clp
->cl_minorversion
= cl_init
->minorversion
;
154 cred
= rpc_lookup_machine_cred();
156 clp
->cl_machine_cred
= cred
;
158 nfs_fscache_get_client_cookie(clp
);
170 * Clears/puts all minor version specific parts from an nfs_client struct
171 * reverting it to minorversion 0.
173 static void nfs4_clear_client_minor_version(struct nfs_client
*clp
)
175 #ifdef CONFIG_NFS_V4_1
176 if (nfs4_has_session(clp
)) {
177 nfs4_destroy_session(clp
->cl_session
);
178 clp
->cl_session
= NULL
;
181 clp
->cl_call_sync
= _nfs4_call_sync
;
182 #endif /* CONFIG_NFS_V4_1 */
186 * Destroy the NFS4 callback service
188 static void nfs4_destroy_callback(struct nfs_client
*clp
)
190 if (__test_and_clear_bit(NFS_CS_CALLBACK
, &clp
->cl_res_state
))
191 nfs_callback_down(clp
->cl_minorversion
);
194 static void nfs4_shutdown_client(struct nfs_client
*clp
)
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
);
199 nfs4_destroy_callback(clp
);
200 if (__test_and_clear_bit(NFS_CS_IDMAP
, &clp
->cl_res_state
))
201 nfs_idmap_delete(clp
);
203 rpc_destroy_wait_queue(&clp
->cl_rpcwaitq
);
206 static void nfs4_shutdown_client(struct nfs_client
*clp
)
209 #endif /* CONFIG_NFS_V4 */
212 * Destroy a shared client record
214 static void nfs_free_client(struct nfs_client
*clp
)
216 dprintk("--> nfs_free_client(%u)\n", clp
->rpc_ops
->version
);
218 nfs4_shutdown_client(clp
);
220 nfs_fscache_release_client_cookie(clp
);
222 /* -EIO all pending I/O */
223 if (!IS_ERR(clp
->cl_rpcclient
))
224 rpc_shutdown_client(clp
->cl_rpcclient
);
226 if (clp
->cl_machine_cred
!= NULL
)
227 put_rpccred(clp
->cl_machine_cred
);
229 kfree(clp
->cl_hostname
);
232 dprintk("<-- nfs_free_client()\n");
236 * Release a reference to a shared client record
238 void nfs_put_client(struct nfs_client
*clp
)
243 dprintk("--> nfs_put_client({%d})\n", atomic_read(&clp
->cl_count
));
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
);
249 BUG_ON(!list_empty(&clp
->cl_superblocks
));
251 nfs_free_client(clp
);
255 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
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
265 * The caller should ensure both socket addresses are AF_INET6.
267 static int nfs_sockaddr_match_ipaddr6(const struct sockaddr
*sa1
,
268 const struct sockaddr
*sa2
)
270 const struct sockaddr_in6
*sin1
= (const struct sockaddr_in6
*)sa1
;
271 const struct sockaddr_in6
*sin2
= (const struct sockaddr_in6
*)sa2
;
273 if (ipv6_addr_scope(&sin1
->sin6_addr
) == IPV6_ADDR_SCOPE_LINKLOCAL
&&
274 sin1
->sin6_scope_id
!= sin2
->sin6_scope_id
)
277 return ipv6_addr_equal(&sin1
->sin6_addr
, &sin1
->sin6_addr
);
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
)
288 * Test if two ip4 socket addresses refer to the same socket, by
289 * comparing relevant fields. The padding bytes specifically, are
292 * The caller should ensure both socket addresses are AF_INET.
294 static int nfs_sockaddr_match_ipaddr4(const struct sockaddr
*sa1
,
295 const struct sockaddr
*sa2
)
297 const struct sockaddr_in
*sin1
= (const struct sockaddr_in
*)sa1
;
298 const struct sockaddr_in
*sin2
= (const struct sockaddr_in
*)sa2
;
300 return sin1
->sin_addr
.s_addr
== sin2
->sin_addr
.s_addr
;
303 static int nfs_sockaddr_cmp_ip6(const struct sockaddr
*sa1
,
304 const struct sockaddr
*sa2
)
306 const struct sockaddr_in6
*sin1
= (const struct sockaddr_in6
*)sa1
;
307 const struct sockaddr_in6
*sin2
= (const struct sockaddr_in6
*)sa2
;
309 return nfs_sockaddr_match_ipaddr6(sa1
, sa2
) &&
310 (sin1
->sin6_port
== sin2
->sin6_port
);
313 static int nfs_sockaddr_cmp_ip4(const struct sockaddr
*sa1
,
314 const struct sockaddr
*sa2
)
316 const struct sockaddr_in
*sin1
= (const struct sockaddr_in
*)sa1
;
317 const struct sockaddr_in
*sin2
= (const struct sockaddr_in
*)sa2
;
319 return nfs_sockaddr_match_ipaddr4(sa1
, sa2
) &&
320 (sin1
->sin_port
== sin2
->sin_port
);
324 * Test if two socket addresses represent the same actual socket,
325 * by comparing (only) relevant fields, excluding the port number.
327 static int nfs_sockaddr_match_ipaddr(const struct sockaddr
*sa1
,
328 const struct sockaddr
*sa2
)
330 if (sa1
->sa_family
!= sa2
->sa_family
)
333 switch (sa1
->sa_family
) {
335 return nfs_sockaddr_match_ipaddr4(sa1
, sa2
);
337 return nfs_sockaddr_match_ipaddr6(sa1
, sa2
);
343 * Test if two socket addresses represent the same actual socket,
344 * by comparing (only) relevant fields, including the port number.
346 static int nfs_sockaddr_cmp(const struct sockaddr
*sa1
,
347 const struct sockaddr
*sa2
)
349 if (sa1
->sa_family
!= sa2
->sa_family
)
352 switch (sa1
->sa_family
) {
354 return nfs_sockaddr_cmp_ip4(sa1
, sa2
);
356 return nfs_sockaddr_cmp_ip6(sa1
, sa2
);
362 * Find a client by IP address and protocol version
363 * - returns NULL if no such client
365 struct nfs_client
*nfs_find_client(const struct sockaddr
*addr
, u32 nfsversion
)
367 struct nfs_client
*clp
;
369 spin_lock(&nfs_client_lock
);
370 list_for_each_entry(clp
, &nfs_client_list
, cl_share_link
) {
371 struct sockaddr
*clap
= (struct sockaddr
*)&clp
->cl_addr
;
373 /* Don't match clients that failed to initialise properly */
374 if (!(clp
->cl_cons_state
== NFS_CS_READY
||
375 clp
->cl_cons_state
== NFS_CS_SESSION_INITING
))
378 /* Different NFS versions cannot share the same nfs_client */
379 if (clp
->rpc_ops
->version
!= nfsversion
)
382 /* Match only the IP address, not the port number */
383 if (!nfs_sockaddr_match_ipaddr(addr
, clap
))
386 atomic_inc(&clp
->cl_count
);
387 spin_unlock(&nfs_client_lock
);
390 spin_unlock(&nfs_client_lock
);
395 * Find a client by IP address and protocol version
396 * - returns NULL if no such client
398 struct nfs_client
*nfs_find_client_next(struct nfs_client
*clp
)
400 struct sockaddr
*sap
= (struct sockaddr
*)&clp
->cl_addr
;
401 u32 nfsvers
= clp
->rpc_ops
->version
;
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
;
407 /* Don't match clients that failed to initialise properly */
408 if (clp
->cl_cons_state
!= NFS_CS_READY
)
411 /* Different NFS versions cannot share the same nfs_client */
412 if (clp
->rpc_ops
->version
!= nfsvers
)
415 /* Match only the IP address, not the port number */
416 if (!nfs_sockaddr_match_ipaddr(sap
, clap
))
419 atomic_inc(&clp
->cl_count
);
420 spin_unlock(&nfs_client_lock
);
423 spin_unlock(&nfs_client_lock
);
428 * Find an nfs_client on the list that matches the initialisation data
431 static struct nfs_client
*nfs_match_client(const struct nfs_client_initdata
*data
)
433 struct nfs_client
*clp
;
434 const struct sockaddr
*sap
= data
->addr
;
436 list_for_each_entry(clp
, &nfs_client_list
, cl_share_link
) {
437 const struct sockaddr
*clap
= (struct sockaddr
*)&clp
->cl_addr
;
438 /* Don't match clients that failed to initialise properly */
439 if (clp
->cl_cons_state
< 0)
442 /* Different NFS versions cannot share the same nfs_client */
443 if (clp
->rpc_ops
!= data
->rpc_ops
)
446 if (clp
->cl_proto
!= data
->proto
)
448 /* Match nfsv4 minorversion */
449 if (clp
->cl_minorversion
!= data
->minorversion
)
451 /* Match the full socket address */
452 if (!nfs_sockaddr_cmp(sap
, clap
))
455 atomic_inc(&clp
->cl_count
);
462 * Look up a client by IP address and protocol version
463 * - creates a new record if one doesn't yet exist
465 static struct nfs_client
*nfs_get_client(const struct nfs_client_initdata
*cl_init
)
467 struct nfs_client
*clp
, *new = NULL
;
470 dprintk("--> nfs_get_client(%s,v%u)\n",
471 cl_init
->hostname
?: "", cl_init
->rpc_ops
->version
);
473 /* see if the client already exists */
475 spin_lock(&nfs_client_lock
);
477 clp
= nfs_match_client(cl_init
);
483 spin_unlock(&nfs_client_lock
);
485 new = nfs_alloc_client(cl_init
);
486 } while (!IS_ERR(new));
488 dprintk("--> nfs_get_client() = %ld [failed]\n", PTR_ERR(new));
491 /* install a new client and return with it unready */
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
);
499 /* found an existing client
500 * - make sure it's ready before returning
503 spin_unlock(&nfs_client_lock
);
506 nfs_free_client(new);
508 error
= wait_event_killable(nfs_client_active_wq
,
509 clp
->cl_cons_state
< NFS_CS_INITING
);
512 return ERR_PTR(-ERESTARTSYS
);
515 if (clp
->cl_cons_state
< NFS_CS_READY
) {
516 error
= clp
->cl_cons_state
;
518 return ERR_PTR(error
);
521 BUG_ON(clp
->cl_cons_state
!= NFS_CS_READY
);
523 dprintk("--> nfs_get_client() = %p [share]\n", clp
);
528 * Mark a server as ready or failed
530 void nfs_mark_client_ready(struct nfs_client
*clp
, int state
)
532 clp
->cl_cons_state
= state
;
533 wake_up_all(&nfs_client_active_wq
);
537 * With sessions, the client is not marked ready until after a
538 * successful EXCHANGE_ID and CREATE_SESSION.
540 * Map errors cl_cons_state errors to EPROTONOSUPPORT to indicate
541 * other versions of NFS can be tried.
543 int nfs4_check_client_ready(struct nfs_client
*clp
)
545 if (!nfs4_has_session(clp
))
547 if (clp
->cl_cons_state
< NFS_CS_READY
)
548 return -EPROTONOSUPPORT
;
553 * Initialise the timeout values for a connection
555 static void nfs_init_timeout_values(struct rpc_timeout
*to
, int proto
,
556 unsigned int timeo
, unsigned int retrans
)
558 to
->to_initval
= timeo
* HZ
/ 10;
559 to
->to_retries
= retrans
;
562 case XPRT_TRANSPORT_TCP
:
563 case XPRT_TRANSPORT_RDMA
:
564 if (to
->to_retries
== 0)
565 to
->to_retries
= NFS_DEF_TCP_RETRANS
;
566 if (to
->to_initval
== 0)
567 to
->to_initval
= NFS_DEF_TCP_TIMEO
* HZ
/ 10;
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
);
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
;
576 to
->to_exponential
= 0;
578 case XPRT_TRANSPORT_UDP
:
579 if (to
->to_retries
== 0)
580 to
->to_retries
= NFS_DEF_UDP_RETRANS
;
582 to
->to_initval
= NFS_DEF_UDP_TIMEO
* HZ
/ 10;
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;
594 * Create an RPC client handle
596 static int nfs_create_rpc_client(struct nfs_client
*clp
,
597 const struct rpc_timeout
*timeparms
,
598 rpc_authflavor_t flavor
,
599 int discrtry
, int noresvport
)
601 struct rpc_clnt
*clnt
= NULL
;
602 struct rpc_create_args args
= {
603 .protocol
= clp
->cl_proto
,
604 .address
= (struct sockaddr
*)&clp
->cl_addr
,
605 .addrsize
= clp
->cl_addrlen
,
606 .timeout
= timeparms
,
607 .servername
= clp
->cl_hostname
,
608 .program
= &nfs_program
,
609 .version
= clp
->rpc_ops
->version
,
610 .authflavor
= flavor
,
614 args
.flags
|= RPC_CLNT_CREATE_DISCRTRY
;
616 args
.flags
|= RPC_CLNT_CREATE_NONPRIVPORT
;
618 if (!IS_ERR(clp
->cl_rpcclient
))
621 clnt
= rpc_create(&args
);
623 dprintk("%s: cannot create RPC client. Error = %ld\n",
624 __func__
, PTR_ERR(clnt
));
625 return PTR_ERR(clnt
);
628 clp
->cl_rpcclient
= clnt
;
633 * Version 2 or 3 client destruction
635 static void nfs_destroy_server(struct nfs_server
*server
)
637 if (!(server
->flags
& NFS_MOUNT_NONLM
))
638 nlmclnt_done(server
->nlm_host
);
642 * Version 2 or 3 lockd setup
644 static int nfs_start_lockd(struct nfs_server
*server
)
646 struct nlm_host
*host
;
647 struct nfs_client
*clp
= server
->nfs_client
;
648 struct nlmclnt_initdata nlm_init
= {
649 .hostname
= clp
->cl_hostname
,
650 .address
= (struct sockaddr
*)&clp
->cl_addr
,
651 .addrlen
= clp
->cl_addrlen
,
652 .nfs_version
= clp
->rpc_ops
->version
,
653 .noresvport
= server
->flags
& NFS_MOUNT_NORESVPORT
?
657 if (nlm_init
.nfs_version
> 3)
659 if (server
->flags
& NFS_MOUNT_NONLM
)
662 switch (clp
->cl_proto
) {
664 nlm_init
.protocol
= IPPROTO_TCP
;
666 case XPRT_TRANSPORT_UDP
:
667 nlm_init
.protocol
= IPPROTO_UDP
;
670 host
= nlmclnt_init(&nlm_init
);
672 return PTR_ERR(host
);
674 server
->nlm_host
= host
;
675 server
->destroy
= nfs_destroy_server
;
680 * Initialise an NFSv3 ACL client connection
682 #ifdef CONFIG_NFS_V3_ACL
683 static void nfs_init_server_aclclient(struct nfs_server
*server
)
685 if (server
->nfs_client
->rpc_ops
->version
!= 3)
687 if (server
->flags
& NFS_MOUNT_NOACL
)
690 server
->client_acl
= rpc_bind_new_program(server
->client
, &nfsacl_program
, 3);
691 if (IS_ERR(server
->client_acl
))
694 /* No errors! Assume that Sun nfsacls are supported */
695 server
->caps
|= NFS_CAP_ACLS
;
699 server
->caps
&= ~NFS_CAP_ACLS
;
702 static inline void nfs_init_server_aclclient(struct nfs_server
*server
)
704 server
->flags
&= ~NFS_MOUNT_NOACL
;
705 server
->caps
&= ~NFS_CAP_ACLS
;
710 * Create a general RPC client
712 static int nfs_init_server_rpcclient(struct nfs_server
*server
,
713 const struct rpc_timeout
*timeo
,
714 rpc_authflavor_t pseudoflavour
)
716 struct nfs_client
*clp
= server
->nfs_client
;
718 server
->client
= rpc_clone_client(clp
->cl_rpcclient
);
719 if (IS_ERR(server
->client
)) {
720 dprintk("%s: couldn't create rpc_client!\n", __func__
);
721 return PTR_ERR(server
->client
);
724 memcpy(&server
->client
->cl_timeout_default
,
726 sizeof(server
->client
->cl_timeout_default
));
727 server
->client
->cl_timeout
= &server
->client
->cl_timeout_default
;
729 if (pseudoflavour
!= clp
->cl_rpcclient
->cl_auth
->au_flavor
) {
730 struct rpc_auth
*auth
;
732 auth
= rpcauth_create(pseudoflavour
, server
->client
);
734 dprintk("%s: couldn't create credcache!\n", __func__
);
735 return PTR_ERR(auth
);
738 server
->client
->cl_softrtry
= 0;
739 if (server
->flags
& NFS_MOUNT_SOFT
)
740 server
->client
->cl_softrtry
= 1;
746 * Initialise an NFS2 or NFS3 client
748 static int nfs_init_client(struct nfs_client
*clp
,
749 const struct rpc_timeout
*timeparms
,
750 const struct nfs_parsed_mount_data
*data
)
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
);
761 * Create a client RPC handle for doing FSSTAT with UNIX auth only
762 * - RFC 2623, sec 2.3.2
764 error
= nfs_create_rpc_client(clp
, timeparms
, RPC_AUTH_UNIX
,
765 0, data
->flags
& NFS_MOUNT_NORESVPORT
);
768 nfs_mark_client_ready(clp
, NFS_CS_READY
);
772 nfs_mark_client_ready(clp
, error
);
773 dprintk("<-- nfs_init_client() = xerror %d\n", error
);
778 * Create a version 2 or 3 client
780 static int nfs_init_server(struct nfs_server
*server
,
781 const struct nfs_parsed_mount_data
*data
)
783 struct nfs_client_initdata cl_init
= {
784 .hostname
= data
->nfs_server
.hostname
,
785 .addr
= (const struct sockaddr
*)&data
->nfs_server
.address
,
786 .addrlen
= data
->nfs_server
.addrlen
,
787 .rpc_ops
= &nfs_v2_clientops
,
788 .proto
= data
->nfs_server
.protocol
,
790 struct rpc_timeout timeparms
;
791 struct nfs_client
*clp
;
794 dprintk("--> nfs_init_server()\n");
797 if (data
->version
== 3)
798 cl_init
.rpc_ops
= &nfs_v3_clientops
;
801 /* Allocate or find a client reference we can use */
802 clp
= nfs_get_client(&cl_init
);
804 dprintk("<-- nfs_init_server() = error %ld\n", PTR_ERR(clp
));
808 nfs_init_timeout_values(&timeparms
, data
->nfs_server
.protocol
,
809 data
->timeo
, data
->retrans
);
810 error
= nfs_init_client(clp
, &timeparms
, data
);
814 server
->nfs_client
= clp
;
816 /* Initialise the client representation from the mount data */
817 server
->flags
= data
->flags
;
818 server
->options
= data
->options
;
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
;
824 server
->rsize
= nfs_block_size(data
->rsize
, NULL
);
826 server
->wsize
= nfs_block_size(data
->wsize
, NULL
);
828 server
->acregmin
= data
->acregmin
* HZ
;
829 server
->acregmax
= data
->acregmax
* HZ
;
830 server
->acdirmin
= data
->acdirmin
* HZ
;
831 server
->acdirmax
= data
->acdirmax
* HZ
;
833 /* Start lockd here, before we might error out */
834 error
= nfs_start_lockd(server
);
838 server
->port
= data
->nfs_server
.port
;
840 error
= nfs_init_server_rpcclient(server
, &timeparms
, data
->auth_flavors
[0]);
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
;
850 server
->mountd_version
= data
->mount_server
.version
;
851 server
->mountd_port
= data
->mount_server
.port
;
852 server
->mountd_protocol
= data
->mount_server
.protocol
;
854 server
->namelen
= data
->namlen
;
855 /* Create a client RPC handle for the NFSv3 ACL management interface */
856 nfs_init_server_aclclient(server
);
857 dprintk("<-- nfs_init_server() = 0 [new %p]\n", clp
);
861 server
->nfs_client
= NULL
;
863 dprintk("<-- nfs_init_server() = xerror %d\n", error
);
868 * Load up the server record from information gained in an fsinfo record
870 static void nfs_server_set_fsinfo(struct nfs_server
*server
, struct nfs_fsinfo
*fsinfo
)
872 unsigned long max_rpc_payload
;
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
);
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
);
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
;
892 server
->backing_dev_info
.name
= "nfs";
893 server
->backing_dev_info
.ra_pages
= server
->rpages
* NFS_MAX_READAHEAD
;
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
);
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
;
908 if (server
->flags
& NFS_MOUNT_NOAC
) {
909 server
->acregmin
= server
->acregmax
= 0;
910 server
->acdirmin
= server
->acdirmax
= 0;
913 server
->maxfilesize
= fsinfo
->maxfilesize
;
915 /* We're airborne Set socket buffersize */
916 rpc_setbufsize(server
->client
, server
->wsize
+ 100, server
->rsize
+ 100);
920 * Probe filesystem information, including the FSID on v2/v3
922 static int nfs_probe_fsinfo(struct nfs_server
*server
, struct nfs_fh
*mntfh
, struct nfs_fattr
*fattr
)
924 struct nfs_fsinfo fsinfo
;
925 struct nfs_client
*clp
= server
->nfs_client
;
928 dprintk("--> nfs_probe_fsinfo()\n");
930 if (clp
->rpc_ops
->set_capabilities
!= NULL
) {
931 error
= clp
->rpc_ops
->set_capabilities(server
, mntfh
);
936 fsinfo
.fattr
= fattr
;
937 error
= clp
->rpc_ops
->fsinfo(server
, mntfh
, &fsinfo
);
941 nfs_server_set_fsinfo(server
, &fsinfo
);
943 /* Get some general file system info */
944 if (server
->namelen
== 0) {
945 struct nfs_pathconf pathinfo
;
947 pathinfo
.fattr
= fattr
;
948 nfs_fattr_init(fattr
);
950 if (clp
->rpc_ops
->pathconf(server
, mntfh
, &pathinfo
) >= 0)
951 server
->namelen
= pathinfo
.max_namelen
;
954 dprintk("<-- nfs_probe_fsinfo() = 0\n");
958 dprintk("nfs_probe_fsinfo: error = %d\n", -error
);
963 * Copy useful information when duplicating a server record
965 static void nfs_server_copy_userdata(struct nfs_server
*target
, struct nfs_server
*source
)
967 target
->flags
= source
->flags
;
968 target
->rsize
= source
->rsize
;
969 target
->wsize
= source
->wsize
;
970 target
->acregmin
= source
->acregmin
;
971 target
->acregmax
= source
->acregmax
;
972 target
->acdirmin
= source
->acdirmin
;
973 target
->acdirmax
= source
->acdirmax
;
974 target
->caps
= source
->caps
;
975 target
->options
= source
->options
;
979 * Allocate and initialise a server record
981 static struct nfs_server
*nfs_alloc_server(void)
983 struct nfs_server
*server
;
985 server
= kzalloc(sizeof(struct nfs_server
), GFP_KERNEL
);
989 server
->client
= server
->client_acl
= ERR_PTR(-EINVAL
);
991 /* Zero out the NFS state stuff */
992 INIT_LIST_HEAD(&server
->client_link
);
993 INIT_LIST_HEAD(&server
->master_link
);
995 atomic_set(&server
->active
, 0);
997 server
->io_stats
= nfs_alloc_iostats();
998 if (!server
->io_stats
) {
1003 if (bdi_init(&server
->backing_dev_info
)) {
1004 nfs_free_iostats(server
->io_stats
);
1013 * Free up a server record
1015 void nfs_free_server(struct nfs_server
*server
)
1017 dprintk("--> nfs_free_server()\n");
1019 spin_lock(&nfs_client_lock
);
1020 list_del(&server
->client_link
);
1021 list_del(&server
->master_link
);
1022 spin_unlock(&nfs_client_lock
);
1024 if (server
->destroy
!= NULL
)
1025 server
->destroy(server
);
1027 if (!IS_ERR(server
->client_acl
))
1028 rpc_shutdown_client(server
->client_acl
);
1029 if (!IS_ERR(server
->client
))
1030 rpc_shutdown_client(server
->client
);
1032 nfs_put_client(server
->nfs_client
);
1034 nfs_free_iostats(server
->io_stats
);
1035 bdi_destroy(&server
->backing_dev_info
);
1037 nfs_release_automount_timer();
1038 dprintk("<-- nfs_free_server()\n");
1042 * Create a version 2 or 3 volume record
1043 * - keyed on server and FSID
1045 struct nfs_server
*nfs_create_server(const struct nfs_parsed_mount_data
*data
,
1046 struct nfs_fh
*mntfh
)
1048 struct nfs_server
*server
;
1049 struct nfs_fattr
*fattr
;
1052 server
= nfs_alloc_server();
1054 return ERR_PTR(-ENOMEM
);
1057 fattr
= nfs_alloc_fattr();
1061 /* Get a client representation */
1062 error
= nfs_init_server(server
, data
);
1066 BUG_ON(!server
->nfs_client
);
1067 BUG_ON(!server
->nfs_client
->rpc_ops
);
1068 BUG_ON(!server
->nfs_client
->rpc_ops
->file_inode_ops
);
1070 /* Probe the root fh to retrieve its FSID */
1071 error
= nfs_probe_fsinfo(server
, mntfh
, fattr
);
1074 if (server
->nfs_client
->rpc_ops
->version
== 3) {
1075 if (server
->namelen
== 0 || server
->namelen
> NFS3_MAXNAMLEN
)
1076 server
->namelen
= NFS3_MAXNAMLEN
;
1077 if (!(data
->flags
& NFS_MOUNT_NORDIRPLUS
))
1078 server
->caps
|= NFS_CAP_READDIRPLUS
;
1080 if (server
->namelen
== 0 || server
->namelen
> NFS2_MAXNAMLEN
)
1081 server
->namelen
= NFS2_MAXNAMLEN
;
1084 if (!(fattr
->valid
& NFS_ATTR_FATTR
)) {
1085 error
= server
->nfs_client
->rpc_ops
->getattr(server
, mntfh
, fattr
);
1087 dprintk("nfs_create_server: getattr error = %d\n", -error
);
1091 memcpy(&server
->fsid
, &fattr
->fsid
, sizeof(server
->fsid
));
1093 dprintk("Server FSID: %llx:%llx\n",
1094 (unsigned long long) server
->fsid
.major
,
1095 (unsigned long long) server
->fsid
.minor
);
1097 spin_lock(&nfs_client_lock
);
1098 list_add_tail(&server
->client_link
, &server
->nfs_client
->cl_superblocks
);
1099 list_add_tail(&server
->master_link
, &nfs_volume_list
);
1100 spin_unlock(&nfs_client_lock
);
1102 server
->mount_time
= jiffies
;
1103 nfs_free_fattr(fattr
);
1107 nfs_free_fattr(fattr
);
1108 nfs_free_server(server
);
1109 return ERR_PTR(error
);
1112 #ifdef CONFIG_NFS_V4
1114 * Initialize the NFS4 callback service
1116 static int nfs4_init_callback(struct nfs_client
*clp
)
1120 if (clp
->rpc_ops
->version
== 4) {
1121 if (nfs4_has_session(clp
)) {
1122 error
= xprt_setup_backchannel(
1123 clp
->cl_rpcclient
->cl_xprt
,
1124 NFS41_BC_MIN_CALLBACKS
);
1129 error
= nfs_callback_up(clp
->cl_minorversion
,
1130 clp
->cl_rpcclient
->cl_xprt
);
1132 dprintk("%s: failed to start callback. Error = %d\n",
1136 __set_bit(NFS_CS_CALLBACK
, &clp
->cl_res_state
);
1142 * Initialize the minor version specific parts of an NFS4 client record
1144 static int nfs4_init_client_minor_version(struct nfs_client
*clp
)
1146 clp
->cl_call_sync
= _nfs4_call_sync
;
1148 #if defined(CONFIG_NFS_V4_1)
1149 if (clp
->cl_minorversion
) {
1150 struct nfs4_session
*session
= NULL
;
1152 * Create the session and mark it expired.
1153 * When a SEQUENCE operation encounters the expired session
1154 * it will do session recovery to initialize it.
1156 session
= nfs4_alloc_session(clp
);
1160 clp
->cl_session
= session
;
1161 clp
->cl_call_sync
= _nfs4_call_sync_session
;
1163 #endif /* CONFIG_NFS_V4_1 */
1165 return nfs4_init_callback(clp
);
1169 * Initialise an NFS4 client record
1171 static int nfs4_init_client(struct nfs_client
*clp
,
1172 const struct rpc_timeout
*timeparms
,
1173 const char *ip_addr
,
1174 rpc_authflavor_t authflavour
,
1179 if (clp
->cl_cons_state
== NFS_CS_READY
) {
1180 /* the client is initialised already */
1181 dprintk("<-- nfs4_init_client() = 0 [already %p]\n", clp
);
1185 /* Check NFS protocol revision and initialize RPC op vector */
1186 clp
->rpc_ops
= &nfs_v4_clientops
;
1188 error
= nfs_create_rpc_client(clp
, timeparms
, authflavour
,
1189 1, flags
& NFS_MOUNT_NORESVPORT
);
1192 strlcpy(clp
->cl_ipaddr
, ip_addr
, sizeof(clp
->cl_ipaddr
));
1194 error
= nfs_idmap_new(clp
);
1196 dprintk("%s: failed to create idmapper. Error = %d\n",
1200 __set_bit(NFS_CS_IDMAP
, &clp
->cl_res_state
);
1202 error
= nfs4_init_client_minor_version(clp
);
1206 if (!nfs4_has_session(clp
))
1207 nfs_mark_client_ready(clp
, NFS_CS_READY
);
1211 nfs_mark_client_ready(clp
, error
);
1212 dprintk("<-- nfs4_init_client() = xerror %d\n", error
);
1217 * Set up an NFS4 client
1219 static int nfs4_set_client(struct nfs_server
*server
,
1220 const char *hostname
,
1221 const struct sockaddr
*addr
,
1222 const size_t addrlen
,
1223 const char *ip_addr
,
1224 rpc_authflavor_t authflavour
,
1225 int proto
, const struct rpc_timeout
*timeparms
,
1228 struct nfs_client_initdata cl_init
= {
1229 .hostname
= hostname
,
1232 .rpc_ops
= &nfs_v4_clientops
,
1234 .minorversion
= minorversion
,
1236 struct nfs_client
*clp
;
1239 dprintk("--> nfs4_set_client()\n");
1241 /* Allocate or find a client reference we can use */
1242 clp
= nfs_get_client(&cl_init
);
1244 error
= PTR_ERR(clp
);
1247 error
= nfs4_init_client(clp
, timeparms
, ip_addr
, authflavour
,
1252 server
->nfs_client
= clp
;
1253 dprintk("<-- nfs4_set_client() = 0 [new %p]\n", clp
);
1257 nfs_put_client(clp
);
1259 dprintk("<-- nfs4_set_client() = xerror %d\n", error
);
1265 * Session has been established, and the client marked ready.
1266 * Set the mount rsize and wsize with negotiated fore channel
1267 * attributes which will be bound checked in nfs_server_set_fsinfo.
1269 static void nfs4_session_set_rwsize(struct nfs_server
*server
)
1271 #ifdef CONFIG_NFS_V4_1
1272 struct nfs4_session
*sess
;
1276 if (!nfs4_has_session(server
->nfs_client
))
1278 sess
= server
->nfs_client
->cl_session
;
1279 server_resp_sz
= sess
->fc_attrs
.max_resp_sz
- nfs41_maxread_overhead
;
1280 server_rqst_sz
= sess
->fc_attrs
.max_rqst_sz
- nfs41_maxwrite_overhead
;
1282 if (server
->rsize
> server_resp_sz
)
1283 server
->rsize
= server_resp_sz
;
1284 if (server
->wsize
> server_rqst_sz
)
1285 server
->wsize
= server_rqst_sz
;
1286 #endif /* CONFIG_NFS_V4_1 */
1290 * Create a version 4 volume record
1292 static int nfs4_init_server(struct nfs_server
*server
,
1293 const struct nfs_parsed_mount_data
*data
)
1295 struct rpc_timeout timeparms
;
1298 dprintk("--> nfs4_init_server()\n");
1300 nfs_init_timeout_values(&timeparms
, data
->nfs_server
.protocol
,
1301 data
->timeo
, data
->retrans
);
1303 /* Initialise the client representation from the mount data */
1304 server
->flags
= data
->flags
;
1305 server
->caps
|= NFS_CAP_ATOMIC_OPEN
|NFS_CAP_CHANGE_ATTR
|
1307 server
->options
= data
->options
;
1309 /* Get a client record */
1310 error
= nfs4_set_client(server
,
1311 data
->nfs_server
.hostname
,
1312 (const struct sockaddr
*)&data
->nfs_server
.address
,
1313 data
->nfs_server
.addrlen
,
1314 data
->client_address
,
1315 data
->auth_flavors
[0],
1316 data
->nfs_server
.protocol
,
1318 data
->minorversion
);
1323 server
->rsize
= nfs_block_size(data
->rsize
, NULL
);
1325 server
->wsize
= nfs_block_size(data
->wsize
, NULL
);
1327 server
->acregmin
= data
->acregmin
* HZ
;
1328 server
->acregmax
= data
->acregmax
* HZ
;
1329 server
->acdirmin
= data
->acdirmin
* HZ
;
1330 server
->acdirmax
= data
->acdirmax
* HZ
;
1332 server
->port
= data
->nfs_server
.port
;
1334 error
= nfs_init_server_rpcclient(server
, &timeparms
, data
->auth_flavors
[0]);
1338 dprintk("<-- nfs4_init_server() = %d\n", error
);
1343 * Create a version 4 volume record
1344 * - keyed on server and FSID
1346 struct nfs_server
*nfs4_create_server(const struct nfs_parsed_mount_data
*data
,
1347 struct nfs_fh
*mntfh
)
1349 struct nfs_fattr
*fattr
;
1350 struct nfs_server
*server
;
1353 dprintk("--> nfs4_create_server()\n");
1355 server
= nfs_alloc_server();
1357 return ERR_PTR(-ENOMEM
);
1360 fattr
= nfs_alloc_fattr();
1364 /* set up the general RPC client */
1365 error
= nfs4_init_server(server
, data
);
1369 BUG_ON(!server
->nfs_client
);
1370 BUG_ON(!server
->nfs_client
->rpc_ops
);
1371 BUG_ON(!server
->nfs_client
->rpc_ops
->file_inode_ops
);
1373 error
= nfs4_init_session(server
);
1377 /* Probe the root fh to retrieve its FSID */
1378 error
= nfs4_get_rootfh(server
, mntfh
);
1382 dprintk("Server FSID: %llx:%llx\n",
1383 (unsigned long long) server
->fsid
.major
,
1384 (unsigned long long) server
->fsid
.minor
);
1385 dprintk("Mount FH: %d\n", mntfh
->size
);
1387 nfs4_session_set_rwsize(server
);
1389 error
= nfs_probe_fsinfo(server
, mntfh
, fattr
);
1393 if (server
->namelen
== 0 || server
->namelen
> NFS4_MAXNAMLEN
)
1394 server
->namelen
= NFS4_MAXNAMLEN
;
1396 spin_lock(&nfs_client_lock
);
1397 list_add_tail(&server
->client_link
, &server
->nfs_client
->cl_superblocks
);
1398 list_add_tail(&server
->master_link
, &nfs_volume_list
);
1399 spin_unlock(&nfs_client_lock
);
1401 server
->mount_time
= jiffies
;
1402 dprintk("<-- nfs4_create_server() = %p\n", server
);
1403 nfs_free_fattr(fattr
);
1407 nfs_free_fattr(fattr
);
1408 nfs_free_server(server
);
1409 dprintk("<-- nfs4_create_server() = error %d\n", error
);
1410 return ERR_PTR(error
);
1414 * Create an NFS4 referral server record
1416 struct nfs_server
*nfs4_create_referral_server(struct nfs_clone_mount
*data
,
1417 struct nfs_fh
*mntfh
)
1419 struct nfs_client
*parent_client
;
1420 struct nfs_server
*server
, *parent_server
;
1421 struct nfs_fattr
*fattr
;
1424 dprintk("--> nfs4_create_referral_server()\n");
1426 server
= nfs_alloc_server();
1428 return ERR_PTR(-ENOMEM
);
1431 fattr
= nfs_alloc_fattr();
1435 parent_server
= NFS_SB(data
->sb
);
1436 parent_client
= parent_server
->nfs_client
;
1438 /* Initialise the client representation from the parent server */
1439 nfs_server_copy_userdata(server
, parent_server
);
1440 server
->caps
|= NFS_CAP_ATOMIC_OPEN
|NFS_CAP_CHANGE_ATTR
;
1442 /* Get a client representation.
1443 * Note: NFSv4 always uses TCP, */
1444 error
= nfs4_set_client(server
, data
->hostname
,
1447 parent_client
->cl_ipaddr
,
1449 parent_server
->client
->cl_xprt
->prot
,
1450 parent_server
->client
->cl_timeout
,
1451 parent_client
->cl_minorversion
);
1455 error
= nfs_init_server_rpcclient(server
, parent_server
->client
->cl_timeout
, data
->authflavor
);
1459 BUG_ON(!server
->nfs_client
);
1460 BUG_ON(!server
->nfs_client
->rpc_ops
);
1461 BUG_ON(!server
->nfs_client
->rpc_ops
->file_inode_ops
);
1463 /* Probe the root fh to retrieve its FSID and filehandle */
1464 error
= nfs4_get_rootfh(server
, mntfh
);
1468 /* probe the filesystem info for this server filesystem */
1469 error
= nfs_probe_fsinfo(server
, mntfh
, fattr
);
1473 if (server
->namelen
== 0 || server
->namelen
> NFS4_MAXNAMLEN
)
1474 server
->namelen
= NFS4_MAXNAMLEN
;
1476 dprintk("Referral FSID: %llx:%llx\n",
1477 (unsigned long long) server
->fsid
.major
,
1478 (unsigned long long) server
->fsid
.minor
);
1480 spin_lock(&nfs_client_lock
);
1481 list_add_tail(&server
->client_link
, &server
->nfs_client
->cl_superblocks
);
1482 list_add_tail(&server
->master_link
, &nfs_volume_list
);
1483 spin_unlock(&nfs_client_lock
);
1485 server
->mount_time
= jiffies
;
1487 nfs_free_fattr(fattr
);
1488 dprintk("<-- nfs_create_referral_server() = %p\n", server
);
1492 nfs_free_fattr(fattr
);
1493 nfs_free_server(server
);
1494 dprintk("<-- nfs4_create_referral_server() = error %d\n", error
);
1495 return ERR_PTR(error
);
1498 #endif /* CONFIG_NFS_V4 */
1501 * Clone an NFS2, NFS3 or NFS4 server record
1503 struct nfs_server
*nfs_clone_server(struct nfs_server
*source
,
1505 struct nfs_fattr
*fattr
)
1507 struct nfs_server
*server
;
1508 struct nfs_fattr
*fattr_fsinfo
;
1511 dprintk("--> nfs_clone_server(,%llx:%llx,)\n",
1512 (unsigned long long) fattr
->fsid
.major
,
1513 (unsigned long long) fattr
->fsid
.minor
);
1515 server
= nfs_alloc_server();
1517 return ERR_PTR(-ENOMEM
);
1520 fattr_fsinfo
= nfs_alloc_fattr();
1521 if (fattr_fsinfo
== NULL
)
1522 goto out_free_server
;
1524 /* Copy data from the source */
1525 server
->nfs_client
= source
->nfs_client
;
1526 atomic_inc(&server
->nfs_client
->cl_count
);
1527 nfs_server_copy_userdata(server
, source
);
1529 server
->fsid
= fattr
->fsid
;
1531 error
= nfs_init_server_rpcclient(server
,
1532 source
->client
->cl_timeout
,
1533 source
->client
->cl_auth
->au_flavor
);
1535 goto out_free_server
;
1536 if (!IS_ERR(source
->client_acl
))
1537 nfs_init_server_aclclient(server
);
1539 /* probe the filesystem info for this server filesystem */
1540 error
= nfs_probe_fsinfo(server
, fh
, fattr_fsinfo
);
1542 goto out_free_server
;
1544 if (server
->namelen
== 0 || server
->namelen
> NFS4_MAXNAMLEN
)
1545 server
->namelen
= NFS4_MAXNAMLEN
;
1547 dprintk("Cloned FSID: %llx:%llx\n",
1548 (unsigned long long) server
->fsid
.major
,
1549 (unsigned long long) server
->fsid
.minor
);
1551 error
= nfs_start_lockd(server
);
1553 goto out_free_server
;
1555 spin_lock(&nfs_client_lock
);
1556 list_add_tail(&server
->client_link
, &server
->nfs_client
->cl_superblocks
);
1557 list_add_tail(&server
->master_link
, &nfs_volume_list
);
1558 spin_unlock(&nfs_client_lock
);
1560 server
->mount_time
= jiffies
;
1562 nfs_free_fattr(fattr_fsinfo
);
1563 dprintk("<-- nfs_clone_server() = %p\n", server
);
1567 nfs_free_fattr(fattr_fsinfo
);
1568 nfs_free_server(server
);
1569 dprintk("<-- nfs_clone_server() = error %d\n", error
);
1570 return ERR_PTR(error
);
1573 #ifdef CONFIG_PROC_FS
1574 static struct proc_dir_entry
*proc_fs_nfs
;
1576 static int nfs_server_list_open(struct inode
*inode
, struct file
*file
);
1577 static void *nfs_server_list_start(struct seq_file
*p
, loff_t
*pos
);
1578 static void *nfs_server_list_next(struct seq_file
*p
, void *v
, loff_t
*pos
);
1579 static void nfs_server_list_stop(struct seq_file
*p
, void *v
);
1580 static int nfs_server_list_show(struct seq_file
*m
, void *v
);
1582 static const struct seq_operations nfs_server_list_ops
= {
1583 .start
= nfs_server_list_start
,
1584 .next
= nfs_server_list_next
,
1585 .stop
= nfs_server_list_stop
,
1586 .show
= nfs_server_list_show
,
1589 static const struct file_operations nfs_server_list_fops
= {
1590 .open
= nfs_server_list_open
,
1592 .llseek
= seq_lseek
,
1593 .release
= seq_release
,
1594 .owner
= THIS_MODULE
,
1597 static int nfs_volume_list_open(struct inode
*inode
, struct file
*file
);
1598 static void *nfs_volume_list_start(struct seq_file
*p
, loff_t
*pos
);
1599 static void *nfs_volume_list_next(struct seq_file
*p
, void *v
, loff_t
*pos
);
1600 static void nfs_volume_list_stop(struct seq_file
*p
, void *v
);
1601 static int nfs_volume_list_show(struct seq_file
*m
, void *v
);
1603 static const struct seq_operations nfs_volume_list_ops
= {
1604 .start
= nfs_volume_list_start
,
1605 .next
= nfs_volume_list_next
,
1606 .stop
= nfs_volume_list_stop
,
1607 .show
= nfs_volume_list_show
,
1610 static const struct file_operations nfs_volume_list_fops
= {
1611 .open
= nfs_volume_list_open
,
1613 .llseek
= seq_lseek
,
1614 .release
= seq_release
,
1615 .owner
= THIS_MODULE
,
1619 * open "/proc/fs/nfsfs/servers" which provides a summary of servers with which
1622 static int nfs_server_list_open(struct inode
*inode
, struct file
*file
)
1627 ret
= seq_open(file
, &nfs_server_list_ops
);
1631 m
= file
->private_data
;
1632 m
->private = PDE(inode
)->data
;
1638 * set up the iterator to start reading from the server list and return the first item
1640 static void *nfs_server_list_start(struct seq_file
*m
, loff_t
*_pos
)
1642 /* lock the list against modification */
1643 spin_lock(&nfs_client_lock
);
1644 return seq_list_start_head(&nfs_client_list
, *_pos
);
1648 * move to next server
1650 static void *nfs_server_list_next(struct seq_file
*p
, void *v
, loff_t
*pos
)
1652 return seq_list_next(v
, &nfs_client_list
, pos
);
1656 * clean up after reading from the transports list
1658 static void nfs_server_list_stop(struct seq_file
*p
, void *v
)
1660 spin_unlock(&nfs_client_lock
);
1664 * display a header line followed by a load of call lines
1666 static int nfs_server_list_show(struct seq_file
*m
, void *v
)
1668 struct nfs_client
*clp
;
1670 /* display header on line 1 */
1671 if (v
== &nfs_client_list
) {
1672 seq_puts(m
, "NV SERVER PORT USE HOSTNAME\n");
1676 /* display one transport per line on subsequent lines */
1677 clp
= list_entry(v
, struct nfs_client
, cl_share_link
);
1679 seq_printf(m
, "v%u %s %s %3d %s\n",
1680 clp
->rpc_ops
->version
,
1681 rpc_peeraddr2str(clp
->cl_rpcclient
, RPC_DISPLAY_HEX_ADDR
),
1682 rpc_peeraddr2str(clp
->cl_rpcclient
, RPC_DISPLAY_HEX_PORT
),
1683 atomic_read(&clp
->cl_count
),
1690 * open "/proc/fs/nfsfs/volumes" which provides a summary of extant volumes
1692 static int nfs_volume_list_open(struct inode
*inode
, struct file
*file
)
1697 ret
= seq_open(file
, &nfs_volume_list_ops
);
1701 m
= file
->private_data
;
1702 m
->private = PDE(inode
)->data
;
1708 * set up the iterator to start reading from the volume list and return the first item
1710 static void *nfs_volume_list_start(struct seq_file
*m
, loff_t
*_pos
)
1712 /* lock the list against modification */
1713 spin_lock(&nfs_client_lock
);
1714 return seq_list_start_head(&nfs_volume_list
, *_pos
);
1718 * move to next volume
1720 static void *nfs_volume_list_next(struct seq_file
*p
, void *v
, loff_t
*pos
)
1722 return seq_list_next(v
, &nfs_volume_list
, pos
);
1726 * clean up after reading from the transports list
1728 static void nfs_volume_list_stop(struct seq_file
*p
, void *v
)
1730 spin_unlock(&nfs_client_lock
);
1734 * display a header line followed by a load of call lines
1736 static int nfs_volume_list_show(struct seq_file
*m
, void *v
)
1738 struct nfs_server
*server
;
1739 struct nfs_client
*clp
;
1740 char dev
[8], fsid
[17];
1742 /* display header on line 1 */
1743 if (v
== &nfs_volume_list
) {
1744 seq_puts(m
, "NV SERVER PORT DEV FSID FSC\n");
1747 /* display one transport per line on subsequent lines */
1748 server
= list_entry(v
, struct nfs_server
, master_link
);
1749 clp
= server
->nfs_client
;
1751 snprintf(dev
, 8, "%u:%u",
1752 MAJOR(server
->s_dev
), MINOR(server
->s_dev
));
1754 snprintf(fsid
, 17, "%llx:%llx",
1755 (unsigned long long) server
->fsid
.major
,
1756 (unsigned long long) server
->fsid
.minor
);
1758 seq_printf(m
, "v%u %s %s %-7s %-17s %s\n",
1759 clp
->rpc_ops
->version
,
1760 rpc_peeraddr2str(clp
->cl_rpcclient
, RPC_DISPLAY_HEX_ADDR
),
1761 rpc_peeraddr2str(clp
->cl_rpcclient
, RPC_DISPLAY_HEX_PORT
),
1764 nfs_server_fscache_state(server
));
1770 * initialise the /proc/fs/nfsfs/ directory
1772 int __init
nfs_fs_proc_init(void)
1774 struct proc_dir_entry
*p
;
1776 proc_fs_nfs
= proc_mkdir("fs/nfsfs", NULL
);
1780 /* a file of servers with which we're dealing */
1781 p
= proc_create("servers", S_IFREG
|S_IRUGO
,
1782 proc_fs_nfs
, &nfs_server_list_fops
);
1786 /* a file of volumes that we have mounted */
1787 p
= proc_create("volumes", S_IFREG
|S_IRUGO
,
1788 proc_fs_nfs
, &nfs_volume_list_fops
);
1794 remove_proc_entry("servers", proc_fs_nfs
);
1796 remove_proc_entry("fs/nfsfs", NULL
);
1802 * clean up the /proc/fs/nfsfs/ directory
1804 void nfs_fs_proc_exit(void)
1806 remove_proc_entry("volumes", proc_fs_nfs
);
1807 remove_proc_entry("servers", proc_fs_nfs
);
1808 remove_proc_entry("fs/nfsfs", NULL
);
1811 #endif /* CONFIG_PROC_FS */