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
;
153 clp
->cl_mvops
= nfs_v4_minor_ops
[cl_init
->minorversion
];
155 cred
= rpc_lookup_machine_cred();
157 clp
->cl_machine_cred
= cred
;
159 nfs_fscache_get_client_cookie(clp
);
171 * Clears/puts all minor version specific parts from an nfs_client struct
172 * reverting it to minorversion 0.
174 static void nfs4_clear_client_minor_version(struct nfs_client
*clp
)
176 #ifdef CONFIG_NFS_V4_1
177 if (nfs4_has_session(clp
)) {
178 nfs4_destroy_session(clp
->cl_session
);
179 clp
->cl_session
= NULL
;
182 clp
->cl_mvops
= nfs_v4_minor_ops
[0];
183 #endif /* CONFIG_NFS_V4_1 */
187 * Destroy the NFS4 callback service
189 static void nfs4_destroy_callback(struct nfs_client
*clp
)
191 if (__test_and_clear_bit(NFS_CS_CALLBACK
, &clp
->cl_res_state
))
192 nfs_callback_down(clp
->cl_mvops
->minor_version
);
195 static void nfs4_shutdown_client(struct nfs_client
*clp
)
197 if (__test_and_clear_bit(NFS_CS_RENEWD
, &clp
->cl_res_state
))
198 nfs4_kill_renewd(clp
);
199 nfs4_clear_client_minor_version(clp
);
200 nfs4_destroy_callback(clp
);
201 if (__test_and_clear_bit(NFS_CS_IDMAP
, &clp
->cl_res_state
))
202 nfs_idmap_delete(clp
);
204 rpc_destroy_wait_queue(&clp
->cl_rpcwaitq
);
207 static void nfs4_shutdown_client(struct nfs_client
*clp
)
210 #endif /* CONFIG_NFS_V4 */
213 * Destroy a shared client record
215 static void nfs_free_client(struct nfs_client
*clp
)
217 dprintk("--> nfs_free_client(%u)\n", clp
->rpc_ops
->version
);
219 nfs4_shutdown_client(clp
);
221 nfs_fscache_release_client_cookie(clp
);
223 /* -EIO all pending I/O */
224 if (!IS_ERR(clp
->cl_rpcclient
))
225 rpc_shutdown_client(clp
->cl_rpcclient
);
227 if (clp
->cl_machine_cred
!= NULL
)
228 put_rpccred(clp
->cl_machine_cred
);
230 kfree(clp
->cl_hostname
);
233 dprintk("<-- nfs_free_client()\n");
237 * Release a reference to a shared client record
239 void nfs_put_client(struct nfs_client
*clp
)
244 dprintk("--> nfs_put_client({%d})\n", atomic_read(&clp
->cl_count
));
246 if (atomic_dec_and_lock(&clp
->cl_count
, &nfs_client_lock
)) {
247 list_del(&clp
->cl_share_link
);
248 spin_unlock(&nfs_client_lock
);
250 BUG_ON(!list_empty(&clp
->cl_superblocks
));
252 nfs_free_client(clp
);
256 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
258 * Test if two ip6 socket addresses refer to the same socket by
259 * comparing relevant fields. The padding bytes specifically, are not
260 * compared. sin6_flowinfo is not compared because it only affects QoS
261 * and sin6_scope_id is only compared if the address is "link local"
262 * because "link local" addresses need only be unique to a specific
263 * link. Conversely, ordinary unicast addresses might have different
266 * The caller should ensure both socket addresses are AF_INET6.
268 static int nfs_sockaddr_match_ipaddr6(const struct sockaddr
*sa1
,
269 const struct sockaddr
*sa2
)
271 const struct sockaddr_in6
*sin1
= (const struct sockaddr_in6
*)sa1
;
272 const struct sockaddr_in6
*sin2
= (const struct sockaddr_in6
*)sa2
;
274 if (ipv6_addr_scope(&sin1
->sin6_addr
) == IPV6_ADDR_SCOPE_LINKLOCAL
&&
275 sin1
->sin6_scope_id
!= sin2
->sin6_scope_id
)
278 return ipv6_addr_equal(&sin1
->sin6_addr
, &sin2
->sin6_addr
);
280 #else /* !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE) */
281 static int nfs_sockaddr_match_ipaddr6(const struct sockaddr
*sa1
,
282 const struct sockaddr
*sa2
)
289 * Test if two ip4 socket addresses refer to the same socket, by
290 * comparing relevant fields. The padding bytes specifically, are
293 * The caller should ensure both socket addresses are AF_INET.
295 static int nfs_sockaddr_match_ipaddr4(const struct sockaddr
*sa1
,
296 const struct sockaddr
*sa2
)
298 const struct sockaddr_in
*sin1
= (const struct sockaddr_in
*)sa1
;
299 const struct sockaddr_in
*sin2
= (const struct sockaddr_in
*)sa2
;
301 return sin1
->sin_addr
.s_addr
== sin2
->sin_addr
.s_addr
;
304 static int nfs_sockaddr_cmp_ip6(const struct sockaddr
*sa1
,
305 const struct sockaddr
*sa2
)
307 const struct sockaddr_in6
*sin1
= (const struct sockaddr_in6
*)sa1
;
308 const struct sockaddr_in6
*sin2
= (const struct sockaddr_in6
*)sa2
;
310 return nfs_sockaddr_match_ipaddr6(sa1
, sa2
) &&
311 (sin1
->sin6_port
== sin2
->sin6_port
);
314 static int nfs_sockaddr_cmp_ip4(const struct sockaddr
*sa1
,
315 const struct sockaddr
*sa2
)
317 const struct sockaddr_in
*sin1
= (const struct sockaddr_in
*)sa1
;
318 const struct sockaddr_in
*sin2
= (const struct sockaddr_in
*)sa2
;
320 return nfs_sockaddr_match_ipaddr4(sa1
, sa2
) &&
321 (sin1
->sin_port
== sin2
->sin_port
);
325 * Test if two socket addresses represent the same actual socket,
326 * by comparing (only) relevant fields, excluding the port number.
328 static int nfs_sockaddr_match_ipaddr(const struct sockaddr
*sa1
,
329 const struct sockaddr
*sa2
)
331 if (sa1
->sa_family
!= sa2
->sa_family
)
334 switch (sa1
->sa_family
) {
336 return nfs_sockaddr_match_ipaddr4(sa1
, sa2
);
338 return nfs_sockaddr_match_ipaddr6(sa1
, sa2
);
344 * Test if two socket addresses represent the same actual socket,
345 * by comparing (only) relevant fields, including the port number.
347 static int nfs_sockaddr_cmp(const struct sockaddr
*sa1
,
348 const struct sockaddr
*sa2
)
350 if (sa1
->sa_family
!= sa2
->sa_family
)
353 switch (sa1
->sa_family
) {
355 return nfs_sockaddr_cmp_ip4(sa1
, sa2
);
357 return nfs_sockaddr_cmp_ip6(sa1
, sa2
);
363 * Find a client by IP address and protocol version
364 * - returns NULL if no such client
366 struct nfs_client
*nfs_find_client(const struct sockaddr
*addr
, u32 nfsversion
)
368 struct nfs_client
*clp
;
370 spin_lock(&nfs_client_lock
);
371 list_for_each_entry(clp
, &nfs_client_list
, cl_share_link
) {
372 struct sockaddr
*clap
= (struct sockaddr
*)&clp
->cl_addr
;
374 /* Don't match clients that failed to initialise properly */
375 if (!(clp
->cl_cons_state
== NFS_CS_READY
||
376 clp
->cl_cons_state
== NFS_CS_SESSION_INITING
))
379 /* Different NFS versions cannot share the same nfs_client */
380 if (clp
->rpc_ops
->version
!= nfsversion
)
383 /* Match only the IP address, not the port number */
384 if (!nfs_sockaddr_match_ipaddr(addr
, clap
))
387 atomic_inc(&clp
->cl_count
);
388 spin_unlock(&nfs_client_lock
);
391 spin_unlock(&nfs_client_lock
);
396 * Find a client by IP address and protocol version
397 * - returns NULL if no such client
399 struct nfs_client
*nfs_find_client_next(struct nfs_client
*clp
)
401 struct sockaddr
*sap
= (struct sockaddr
*)&clp
->cl_addr
;
402 u32 nfsvers
= clp
->rpc_ops
->version
;
404 spin_lock(&nfs_client_lock
);
405 list_for_each_entry_continue(clp
, &nfs_client_list
, cl_share_link
) {
406 struct sockaddr
*clap
= (struct sockaddr
*)&clp
->cl_addr
;
408 /* Don't match clients that failed to initialise properly */
409 if (clp
->cl_cons_state
!= NFS_CS_READY
)
412 /* Different NFS versions cannot share the same nfs_client */
413 if (clp
->rpc_ops
->version
!= nfsvers
)
416 /* Match only the IP address, not the port number */
417 if (!nfs_sockaddr_match_ipaddr(sap
, clap
))
420 atomic_inc(&clp
->cl_count
);
421 spin_unlock(&nfs_client_lock
);
424 spin_unlock(&nfs_client_lock
);
429 * Find an nfs_client on the list that matches the initialisation data
432 static struct nfs_client
*nfs_match_client(const struct nfs_client_initdata
*data
)
434 struct nfs_client
*clp
;
435 const struct sockaddr
*sap
= data
->addr
;
437 list_for_each_entry(clp
, &nfs_client_list
, cl_share_link
) {
438 const struct sockaddr
*clap
= (struct sockaddr
*)&clp
->cl_addr
;
439 /* Don't match clients that failed to initialise properly */
440 if (clp
->cl_cons_state
< 0)
443 /* Different NFS versions cannot share the same nfs_client */
444 if (clp
->rpc_ops
!= data
->rpc_ops
)
447 if (clp
->cl_proto
!= data
->proto
)
449 /* Match nfsv4 minorversion */
450 if (clp
->cl_minorversion
!= data
->minorversion
)
452 /* Match the full socket address */
453 if (!nfs_sockaddr_cmp(sap
, clap
))
456 atomic_inc(&clp
->cl_count
);
463 * Look up a client by IP address and protocol version
464 * - creates a new record if one doesn't yet exist
466 static struct nfs_client
*nfs_get_client(const struct nfs_client_initdata
*cl_init
)
468 struct nfs_client
*clp
, *new = NULL
;
471 dprintk("--> nfs_get_client(%s,v%u)\n",
472 cl_init
->hostname
?: "", cl_init
->rpc_ops
->version
);
474 /* see if the client already exists */
476 spin_lock(&nfs_client_lock
);
478 clp
= nfs_match_client(cl_init
);
484 spin_unlock(&nfs_client_lock
);
486 new = nfs_alloc_client(cl_init
);
487 } while (!IS_ERR(new));
489 dprintk("--> nfs_get_client() = %ld [failed]\n", PTR_ERR(new));
492 /* install a new client and return with it unready */
495 list_add(&clp
->cl_share_link
, &nfs_client_list
);
496 spin_unlock(&nfs_client_lock
);
497 dprintk("--> nfs_get_client() = %p [new]\n", clp
);
500 /* found an existing client
501 * - make sure it's ready before returning
504 spin_unlock(&nfs_client_lock
);
507 nfs_free_client(new);
509 error
= wait_event_killable(nfs_client_active_wq
,
510 clp
->cl_cons_state
< NFS_CS_INITING
);
513 return ERR_PTR(-ERESTARTSYS
);
516 if (clp
->cl_cons_state
< NFS_CS_READY
) {
517 error
= clp
->cl_cons_state
;
519 return ERR_PTR(error
);
522 BUG_ON(clp
->cl_cons_state
!= NFS_CS_READY
);
524 dprintk("--> nfs_get_client() = %p [share]\n", clp
);
529 * Mark a server as ready or failed
531 void nfs_mark_client_ready(struct nfs_client
*clp
, int state
)
533 clp
->cl_cons_state
= state
;
534 wake_up_all(&nfs_client_active_wq
);
538 * With sessions, the client is not marked ready until after a
539 * successful EXCHANGE_ID and CREATE_SESSION.
541 * Map errors cl_cons_state errors to EPROTONOSUPPORT to indicate
542 * other versions of NFS can be tried.
544 int nfs4_check_client_ready(struct nfs_client
*clp
)
546 if (!nfs4_has_session(clp
))
548 if (clp
->cl_cons_state
< NFS_CS_READY
)
549 return -EPROTONOSUPPORT
;
554 * Initialise the timeout values for a connection
556 static void nfs_init_timeout_values(struct rpc_timeout
*to
, int proto
,
557 unsigned int timeo
, unsigned int retrans
)
559 to
->to_initval
= timeo
* HZ
/ 10;
560 to
->to_retries
= retrans
;
563 case XPRT_TRANSPORT_TCP
:
564 case XPRT_TRANSPORT_RDMA
:
565 if (to
->to_retries
== 0)
566 to
->to_retries
= NFS_DEF_TCP_RETRANS
;
567 if (to
->to_initval
== 0)
568 to
->to_initval
= NFS_DEF_TCP_TIMEO
* HZ
/ 10;
569 if (to
->to_initval
> NFS_MAX_TCP_TIMEOUT
)
570 to
->to_initval
= NFS_MAX_TCP_TIMEOUT
;
571 to
->to_increment
= to
->to_initval
;
572 to
->to_maxval
= to
->to_initval
+ (to
->to_increment
* to
->to_retries
);
573 if (to
->to_maxval
> NFS_MAX_TCP_TIMEOUT
)
574 to
->to_maxval
= NFS_MAX_TCP_TIMEOUT
;
575 if (to
->to_maxval
< to
->to_initval
)
576 to
->to_maxval
= to
->to_initval
;
577 to
->to_exponential
= 0;
579 case XPRT_TRANSPORT_UDP
:
580 if (to
->to_retries
== 0)
581 to
->to_retries
= NFS_DEF_UDP_RETRANS
;
583 to
->to_initval
= NFS_DEF_UDP_TIMEO
* HZ
/ 10;
584 if (to
->to_initval
> NFS_MAX_UDP_TIMEOUT
)
585 to
->to_initval
= NFS_MAX_UDP_TIMEOUT
;
586 to
->to_maxval
= NFS_MAX_UDP_TIMEOUT
;
587 to
->to_exponential
= 1;
595 * Create an RPC client handle
597 static int nfs_create_rpc_client(struct nfs_client
*clp
,
598 const struct rpc_timeout
*timeparms
,
599 rpc_authflavor_t flavor
,
600 int discrtry
, int noresvport
)
602 struct rpc_clnt
*clnt
= NULL
;
603 struct rpc_create_args args
= {
604 .protocol
= clp
->cl_proto
,
605 .address
= (struct sockaddr
*)&clp
->cl_addr
,
606 .addrsize
= clp
->cl_addrlen
,
607 .timeout
= timeparms
,
608 .servername
= clp
->cl_hostname
,
609 .program
= &nfs_program
,
610 .version
= clp
->rpc_ops
->version
,
611 .authflavor
= flavor
,
615 args
.flags
|= RPC_CLNT_CREATE_DISCRTRY
;
617 args
.flags
|= RPC_CLNT_CREATE_NONPRIVPORT
;
619 if (!IS_ERR(clp
->cl_rpcclient
))
622 clnt
= rpc_create(&args
);
624 dprintk("%s: cannot create RPC client. Error = %ld\n",
625 __func__
, PTR_ERR(clnt
));
626 return PTR_ERR(clnt
);
629 clp
->cl_rpcclient
= clnt
;
634 * Version 2 or 3 client destruction
636 static void nfs_destroy_server(struct nfs_server
*server
)
638 if (!(server
->flags
& NFS_MOUNT_NONLM
))
639 nlmclnt_done(server
->nlm_host
);
643 * Version 2 or 3 lockd setup
645 static int nfs_start_lockd(struct nfs_server
*server
)
647 struct nlm_host
*host
;
648 struct nfs_client
*clp
= server
->nfs_client
;
649 struct nlmclnt_initdata nlm_init
= {
650 .hostname
= clp
->cl_hostname
,
651 .address
= (struct sockaddr
*)&clp
->cl_addr
,
652 .addrlen
= clp
->cl_addrlen
,
653 .nfs_version
= clp
->rpc_ops
->version
,
654 .noresvport
= server
->flags
& NFS_MOUNT_NORESVPORT
?
658 if (nlm_init
.nfs_version
> 3)
660 if (server
->flags
& NFS_MOUNT_NONLM
)
663 switch (clp
->cl_proto
) {
665 nlm_init
.protocol
= IPPROTO_TCP
;
667 case XPRT_TRANSPORT_UDP
:
668 nlm_init
.protocol
= IPPROTO_UDP
;
671 host
= nlmclnt_init(&nlm_init
);
673 return PTR_ERR(host
);
675 server
->nlm_host
= host
;
676 server
->destroy
= nfs_destroy_server
;
681 * Initialise an NFSv3 ACL client connection
683 #ifdef CONFIG_NFS_V3_ACL
684 static void nfs_init_server_aclclient(struct nfs_server
*server
)
686 if (server
->nfs_client
->rpc_ops
->version
!= 3)
688 if (server
->flags
& NFS_MOUNT_NOACL
)
691 server
->client_acl
= rpc_bind_new_program(server
->client
, &nfsacl_program
, 3);
692 if (IS_ERR(server
->client_acl
))
695 /* No errors! Assume that Sun nfsacls are supported */
696 server
->caps
|= NFS_CAP_ACLS
;
700 server
->caps
&= ~NFS_CAP_ACLS
;
703 static inline void nfs_init_server_aclclient(struct nfs_server
*server
)
705 server
->flags
&= ~NFS_MOUNT_NOACL
;
706 server
->caps
&= ~NFS_CAP_ACLS
;
711 * Create a general RPC client
713 static int nfs_init_server_rpcclient(struct nfs_server
*server
,
714 const struct rpc_timeout
*timeo
,
715 rpc_authflavor_t pseudoflavour
)
717 struct nfs_client
*clp
= server
->nfs_client
;
719 server
->client
= rpc_clone_client(clp
->cl_rpcclient
);
720 if (IS_ERR(server
->client
)) {
721 dprintk("%s: couldn't create rpc_client!\n", __func__
);
722 return PTR_ERR(server
->client
);
725 memcpy(&server
->client
->cl_timeout_default
,
727 sizeof(server
->client
->cl_timeout_default
));
728 server
->client
->cl_timeout
= &server
->client
->cl_timeout_default
;
730 if (pseudoflavour
!= clp
->cl_rpcclient
->cl_auth
->au_flavor
) {
731 struct rpc_auth
*auth
;
733 auth
= rpcauth_create(pseudoflavour
, server
->client
);
735 dprintk("%s: couldn't create credcache!\n", __func__
);
736 return PTR_ERR(auth
);
739 server
->client
->cl_softrtry
= 0;
740 if (server
->flags
& NFS_MOUNT_SOFT
)
741 server
->client
->cl_softrtry
= 1;
747 * Initialise an NFS2 or NFS3 client
749 static int nfs_init_client(struct nfs_client
*clp
,
750 const struct rpc_timeout
*timeparms
,
751 const struct nfs_parsed_mount_data
*data
)
755 if (clp
->cl_cons_state
== NFS_CS_READY
) {
756 /* the client is already initialised */
757 dprintk("<-- nfs_init_client() = 0 [already %p]\n", clp
);
762 * Create a client RPC handle for doing FSSTAT with UNIX auth only
763 * - RFC 2623, sec 2.3.2
765 error
= nfs_create_rpc_client(clp
, timeparms
, RPC_AUTH_UNIX
,
766 0, data
->flags
& NFS_MOUNT_NORESVPORT
);
769 nfs_mark_client_ready(clp
, NFS_CS_READY
);
773 nfs_mark_client_ready(clp
, error
);
774 dprintk("<-- nfs_init_client() = xerror %d\n", error
);
779 * Create a version 2 or 3 client
781 static int nfs_init_server(struct nfs_server
*server
,
782 const struct nfs_parsed_mount_data
*data
)
784 struct nfs_client_initdata cl_init
= {
785 .hostname
= data
->nfs_server
.hostname
,
786 .addr
= (const struct sockaddr
*)&data
->nfs_server
.address
,
787 .addrlen
= data
->nfs_server
.addrlen
,
788 .rpc_ops
= &nfs_v2_clientops
,
789 .proto
= data
->nfs_server
.protocol
,
791 struct rpc_timeout timeparms
;
792 struct nfs_client
*clp
;
795 dprintk("--> nfs_init_server()\n");
798 if (data
->version
== 3)
799 cl_init
.rpc_ops
= &nfs_v3_clientops
;
802 /* Allocate or find a client reference we can use */
803 clp
= nfs_get_client(&cl_init
);
805 dprintk("<-- nfs_init_server() = error %ld\n", PTR_ERR(clp
));
809 nfs_init_timeout_values(&timeparms
, data
->nfs_server
.protocol
,
810 data
->timeo
, data
->retrans
);
811 error
= nfs_init_client(clp
, &timeparms
, data
);
815 server
->nfs_client
= clp
;
817 /* Initialise the client representation from the mount data */
818 server
->flags
= data
->flags
;
819 server
->options
= data
->options
;
820 server
->caps
|= NFS_CAP_HARDLINKS
|NFS_CAP_SYMLINKS
|NFS_CAP_FILEID
|
821 NFS_CAP_MODE
|NFS_CAP_NLINK
|NFS_CAP_OWNER
|NFS_CAP_OWNER_GROUP
|
822 NFS_CAP_ATIME
|NFS_CAP_CTIME
|NFS_CAP_MTIME
;
825 server
->rsize
= nfs_block_size(data
->rsize
, NULL
);
827 server
->wsize
= nfs_block_size(data
->wsize
, NULL
);
829 server
->acregmin
= data
->acregmin
* HZ
;
830 server
->acregmax
= data
->acregmax
* HZ
;
831 server
->acdirmin
= data
->acdirmin
* HZ
;
832 server
->acdirmax
= data
->acdirmax
* HZ
;
834 /* Start lockd here, before we might error out */
835 error
= nfs_start_lockd(server
);
839 server
->port
= data
->nfs_server
.port
;
841 error
= nfs_init_server_rpcclient(server
, &timeparms
, data
->auth_flavors
[0]);
845 /* Preserve the values of mount_server-related mount options */
846 if (data
->mount_server
.addrlen
) {
847 memcpy(&server
->mountd_address
, &data
->mount_server
.address
,
848 data
->mount_server
.addrlen
);
849 server
->mountd_addrlen
= data
->mount_server
.addrlen
;
851 server
->mountd_version
= data
->mount_server
.version
;
852 server
->mountd_port
= data
->mount_server
.port
;
853 server
->mountd_protocol
= data
->mount_server
.protocol
;
855 server
->namelen
= data
->namlen
;
856 /* Create a client RPC handle for the NFSv3 ACL management interface */
857 nfs_init_server_aclclient(server
);
858 dprintk("<-- nfs_init_server() = 0 [new %p]\n", clp
);
862 server
->nfs_client
= NULL
;
864 dprintk("<-- nfs_init_server() = xerror %d\n", error
);
869 * Load up the server record from information gained in an fsinfo record
871 static void nfs_server_set_fsinfo(struct nfs_server
*server
, struct nfs_fsinfo
*fsinfo
)
873 unsigned long max_rpc_payload
;
875 /* Work out a lot of parameters */
876 if (server
->rsize
== 0)
877 server
->rsize
= nfs_block_size(fsinfo
->rtpref
, NULL
);
878 if (server
->wsize
== 0)
879 server
->wsize
= nfs_block_size(fsinfo
->wtpref
, NULL
);
881 if (fsinfo
->rtmax
>= 512 && server
->rsize
> fsinfo
->rtmax
)
882 server
->rsize
= nfs_block_size(fsinfo
->rtmax
, NULL
);
883 if (fsinfo
->wtmax
>= 512 && server
->wsize
> fsinfo
->wtmax
)
884 server
->wsize
= nfs_block_size(fsinfo
->wtmax
, NULL
);
886 max_rpc_payload
= nfs_block_size(rpc_max_payload(server
->client
), NULL
);
887 if (server
->rsize
> max_rpc_payload
)
888 server
->rsize
= max_rpc_payload
;
889 if (server
->rsize
> NFS_MAX_FILE_IO_SIZE
)
890 server
->rsize
= NFS_MAX_FILE_IO_SIZE
;
891 server
->rpages
= (server
->rsize
+ PAGE_CACHE_SIZE
- 1) >> PAGE_CACHE_SHIFT
;
893 server
->backing_dev_info
.name
= "nfs";
894 server
->backing_dev_info
.ra_pages
= server
->rpages
* NFS_MAX_READAHEAD
;
896 if (server
->wsize
> max_rpc_payload
)
897 server
->wsize
= max_rpc_payload
;
898 if (server
->wsize
> NFS_MAX_FILE_IO_SIZE
)
899 server
->wsize
= NFS_MAX_FILE_IO_SIZE
;
900 server
->wpages
= (server
->wsize
+ PAGE_CACHE_SIZE
- 1) >> PAGE_CACHE_SHIFT
;
901 server
->wtmult
= nfs_block_bits(fsinfo
->wtmult
, NULL
);
903 server
->dtsize
= nfs_block_size(fsinfo
->dtpref
, NULL
);
904 if (server
->dtsize
> PAGE_CACHE_SIZE
)
905 server
->dtsize
= PAGE_CACHE_SIZE
;
906 if (server
->dtsize
> server
->rsize
)
907 server
->dtsize
= server
->rsize
;
909 if (server
->flags
& NFS_MOUNT_NOAC
) {
910 server
->acregmin
= server
->acregmax
= 0;
911 server
->acdirmin
= server
->acdirmax
= 0;
914 server
->maxfilesize
= fsinfo
->maxfilesize
;
916 /* We're airborne Set socket buffersize */
917 rpc_setbufsize(server
->client
, server
->wsize
+ 100, server
->rsize
+ 100);
921 * Probe filesystem information, including the FSID on v2/v3
923 static int nfs_probe_fsinfo(struct nfs_server
*server
, struct nfs_fh
*mntfh
, struct nfs_fattr
*fattr
)
925 struct nfs_fsinfo fsinfo
;
926 struct nfs_client
*clp
= server
->nfs_client
;
929 dprintk("--> nfs_probe_fsinfo()\n");
931 if (clp
->rpc_ops
->set_capabilities
!= NULL
) {
932 error
= clp
->rpc_ops
->set_capabilities(server
, mntfh
);
937 fsinfo
.fattr
= fattr
;
938 error
= clp
->rpc_ops
->fsinfo(server
, mntfh
, &fsinfo
);
942 nfs_server_set_fsinfo(server
, &fsinfo
);
944 /* Get some general file system info */
945 if (server
->namelen
== 0) {
946 struct nfs_pathconf pathinfo
;
948 pathinfo
.fattr
= fattr
;
949 nfs_fattr_init(fattr
);
951 if (clp
->rpc_ops
->pathconf(server
, mntfh
, &pathinfo
) >= 0)
952 server
->namelen
= pathinfo
.max_namelen
;
955 dprintk("<-- nfs_probe_fsinfo() = 0\n");
959 dprintk("nfs_probe_fsinfo: error = %d\n", -error
);
964 * Copy useful information when duplicating a server record
966 static void nfs_server_copy_userdata(struct nfs_server
*target
, struct nfs_server
*source
)
968 target
->flags
= source
->flags
;
969 target
->rsize
= source
->rsize
;
970 target
->wsize
= source
->wsize
;
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
;
976 target
->options
= source
->options
;
980 * Allocate and initialise a server record
982 static struct nfs_server
*nfs_alloc_server(void)
984 struct nfs_server
*server
;
986 server
= kzalloc(sizeof(struct nfs_server
), GFP_KERNEL
);
990 server
->client
= server
->client_acl
= ERR_PTR(-EINVAL
);
992 /* Zero out the NFS state stuff */
993 INIT_LIST_HEAD(&server
->client_link
);
994 INIT_LIST_HEAD(&server
->master_link
);
996 atomic_set(&server
->active
, 0);
998 server
->io_stats
= nfs_alloc_iostats();
999 if (!server
->io_stats
) {
1004 if (bdi_init(&server
->backing_dev_info
)) {
1005 nfs_free_iostats(server
->io_stats
);
1014 * Free up a server record
1016 void nfs_free_server(struct nfs_server
*server
)
1018 dprintk("--> nfs_free_server()\n");
1020 spin_lock(&nfs_client_lock
);
1021 list_del(&server
->client_link
);
1022 list_del(&server
->master_link
);
1023 spin_unlock(&nfs_client_lock
);
1025 if (server
->destroy
!= NULL
)
1026 server
->destroy(server
);
1028 if (!IS_ERR(server
->client_acl
))
1029 rpc_shutdown_client(server
->client_acl
);
1030 if (!IS_ERR(server
->client
))
1031 rpc_shutdown_client(server
->client
);
1033 nfs_put_client(server
->nfs_client
);
1035 nfs_free_iostats(server
->io_stats
);
1036 bdi_destroy(&server
->backing_dev_info
);
1038 nfs_release_automount_timer();
1039 dprintk("<-- nfs_free_server()\n");
1043 * Create a version 2 or 3 volume record
1044 * - keyed on server and FSID
1046 struct nfs_server
*nfs_create_server(const struct nfs_parsed_mount_data
*data
,
1047 struct nfs_fh
*mntfh
)
1049 struct nfs_server
*server
;
1050 struct nfs_fattr
*fattr
;
1053 server
= nfs_alloc_server();
1055 return ERR_PTR(-ENOMEM
);
1058 fattr
= nfs_alloc_fattr();
1062 /* Get a client representation */
1063 error
= nfs_init_server(server
, data
);
1067 BUG_ON(!server
->nfs_client
);
1068 BUG_ON(!server
->nfs_client
->rpc_ops
);
1069 BUG_ON(!server
->nfs_client
->rpc_ops
->file_inode_ops
);
1071 /* Probe the root fh to retrieve its FSID */
1072 error
= nfs_probe_fsinfo(server
, mntfh
, fattr
);
1075 if (server
->nfs_client
->rpc_ops
->version
== 3) {
1076 if (server
->namelen
== 0 || server
->namelen
> NFS3_MAXNAMLEN
)
1077 server
->namelen
= NFS3_MAXNAMLEN
;
1078 if (!(data
->flags
& NFS_MOUNT_NORDIRPLUS
))
1079 server
->caps
|= NFS_CAP_READDIRPLUS
;
1081 if (server
->namelen
== 0 || server
->namelen
> NFS2_MAXNAMLEN
)
1082 server
->namelen
= NFS2_MAXNAMLEN
;
1085 if (!(fattr
->valid
& NFS_ATTR_FATTR
)) {
1086 error
= server
->nfs_client
->rpc_ops
->getattr(server
, mntfh
, fattr
);
1088 dprintk("nfs_create_server: getattr error = %d\n", -error
);
1092 memcpy(&server
->fsid
, &fattr
->fsid
, sizeof(server
->fsid
));
1094 dprintk("Server FSID: %llx:%llx\n",
1095 (unsigned long long) server
->fsid
.major
,
1096 (unsigned long long) server
->fsid
.minor
);
1098 spin_lock(&nfs_client_lock
);
1099 list_add_tail(&server
->client_link
, &server
->nfs_client
->cl_superblocks
);
1100 list_add_tail(&server
->master_link
, &nfs_volume_list
);
1101 spin_unlock(&nfs_client_lock
);
1103 server
->mount_time
= jiffies
;
1104 nfs_free_fattr(fattr
);
1108 nfs_free_fattr(fattr
);
1109 nfs_free_server(server
);
1110 return ERR_PTR(error
);
1113 #ifdef CONFIG_NFS_V4
1115 * Initialize the NFS4 callback service
1117 static int nfs4_init_callback(struct nfs_client
*clp
)
1121 if (clp
->rpc_ops
->version
== 4) {
1122 if (nfs4_has_session(clp
)) {
1123 error
= xprt_setup_backchannel(
1124 clp
->cl_rpcclient
->cl_xprt
,
1125 NFS41_BC_MIN_CALLBACKS
);
1130 error
= nfs_callback_up(clp
->cl_mvops
->minor_version
,
1131 clp
->cl_rpcclient
->cl_xprt
);
1133 dprintk("%s: failed to start callback. Error = %d\n",
1137 __set_bit(NFS_CS_CALLBACK
, &clp
->cl_res_state
);
1143 * Initialize the minor version specific parts of an NFS4 client record
1145 static int nfs4_init_client_minor_version(struct nfs_client
*clp
)
1147 #if defined(CONFIG_NFS_V4_1)
1148 if (clp
->cl_mvops
->minor_version
) {
1149 struct nfs4_session
*session
= NULL
;
1151 * Create the session and mark it expired.
1152 * When a SEQUENCE operation encounters the expired session
1153 * it will do session recovery to initialize it.
1155 session
= nfs4_alloc_session(clp
);
1159 clp
->cl_session
= session
;
1161 * The create session reply races with the server back
1162 * channel probe. Mark the client NFS_CS_SESSION_INITING
1163 * so that the client back channel can find the
1166 clp
->cl_cons_state
= NFS_CS_SESSION_INITING
;
1168 #endif /* CONFIG_NFS_V4_1 */
1170 return nfs4_init_callback(clp
);
1174 * Initialise an NFS4 client record
1176 static int nfs4_init_client(struct nfs_client
*clp
,
1177 const struct rpc_timeout
*timeparms
,
1178 const char *ip_addr
,
1179 rpc_authflavor_t authflavour
,
1184 if (clp
->cl_cons_state
== NFS_CS_READY
) {
1185 /* the client is initialised already */
1186 dprintk("<-- nfs4_init_client() = 0 [already %p]\n", clp
);
1190 /* Check NFS protocol revision and initialize RPC op vector */
1191 clp
->rpc_ops
= &nfs_v4_clientops
;
1193 error
= nfs_create_rpc_client(clp
, timeparms
, authflavour
,
1194 1, flags
& NFS_MOUNT_NORESVPORT
);
1197 strlcpy(clp
->cl_ipaddr
, ip_addr
, sizeof(clp
->cl_ipaddr
));
1199 error
= nfs_idmap_new(clp
);
1201 dprintk("%s: failed to create idmapper. Error = %d\n",
1205 __set_bit(NFS_CS_IDMAP
, &clp
->cl_res_state
);
1207 error
= nfs4_init_client_minor_version(clp
);
1211 if (!nfs4_has_session(clp
))
1212 nfs_mark_client_ready(clp
, NFS_CS_READY
);
1216 nfs_mark_client_ready(clp
, error
);
1217 dprintk("<-- nfs4_init_client() = xerror %d\n", error
);
1222 * Set up an NFS4 client
1224 static int nfs4_set_client(struct nfs_server
*server
,
1225 const char *hostname
,
1226 const struct sockaddr
*addr
,
1227 const size_t addrlen
,
1228 const char *ip_addr
,
1229 rpc_authflavor_t authflavour
,
1230 int proto
, const struct rpc_timeout
*timeparms
,
1233 struct nfs_client_initdata cl_init
= {
1234 .hostname
= hostname
,
1237 .rpc_ops
= &nfs_v4_clientops
,
1239 .minorversion
= minorversion
,
1241 struct nfs_client
*clp
;
1244 dprintk("--> nfs4_set_client()\n");
1246 /* Allocate or find a client reference we can use */
1247 clp
= nfs_get_client(&cl_init
);
1249 error
= PTR_ERR(clp
);
1252 error
= nfs4_init_client(clp
, timeparms
, ip_addr
, authflavour
,
1257 server
->nfs_client
= clp
;
1258 dprintk("<-- nfs4_set_client() = 0 [new %p]\n", clp
);
1262 nfs_put_client(clp
);
1264 dprintk("<-- nfs4_set_client() = xerror %d\n", error
);
1270 * Session has been established, and the client marked ready.
1271 * Set the mount rsize and wsize with negotiated fore channel
1272 * attributes which will be bound checked in nfs_server_set_fsinfo.
1274 static void nfs4_session_set_rwsize(struct nfs_server
*server
)
1276 #ifdef CONFIG_NFS_V4_1
1277 struct nfs4_session
*sess
;
1281 if (!nfs4_has_session(server
->nfs_client
))
1283 sess
= server
->nfs_client
->cl_session
;
1284 server_resp_sz
= sess
->fc_attrs
.max_resp_sz
- nfs41_maxread_overhead
;
1285 server_rqst_sz
= sess
->fc_attrs
.max_rqst_sz
- nfs41_maxwrite_overhead
;
1287 if (server
->rsize
> server_resp_sz
)
1288 server
->rsize
= server_resp_sz
;
1289 if (server
->wsize
> server_rqst_sz
)
1290 server
->wsize
= server_rqst_sz
;
1291 #endif /* CONFIG_NFS_V4_1 */
1294 static int nfs4_server_common_setup(struct nfs_server
*server
,
1295 struct nfs_fh
*mntfh
)
1297 struct nfs_fattr
*fattr
;
1300 BUG_ON(!server
->nfs_client
);
1301 BUG_ON(!server
->nfs_client
->rpc_ops
);
1302 BUG_ON(!server
->nfs_client
->rpc_ops
->file_inode_ops
);
1304 fattr
= nfs_alloc_fattr();
1308 /* We must ensure the session is initialised first */
1309 error
= nfs4_init_session(server
);
1313 /* Probe the root fh to retrieve its FSID and filehandle */
1314 error
= nfs4_get_rootfh(server
, mntfh
);
1318 dprintk("Server FSID: %llx:%llx\n",
1319 (unsigned long long) server
->fsid
.major
,
1320 (unsigned long long) server
->fsid
.minor
);
1321 dprintk("Mount FH: %d\n", mntfh
->size
);
1323 nfs4_session_set_rwsize(server
);
1325 error
= nfs_probe_fsinfo(server
, mntfh
, fattr
);
1329 if (server
->namelen
== 0 || server
->namelen
> NFS4_MAXNAMLEN
)
1330 server
->namelen
= NFS4_MAXNAMLEN
;
1332 spin_lock(&nfs_client_lock
);
1333 list_add_tail(&server
->client_link
, &server
->nfs_client
->cl_superblocks
);
1334 list_add_tail(&server
->master_link
, &nfs_volume_list
);
1335 spin_unlock(&nfs_client_lock
);
1337 server
->mount_time
= jiffies
;
1339 nfs_free_fattr(fattr
);
1344 * Create a version 4 volume record
1346 static int nfs4_init_server(struct nfs_server
*server
,
1347 const struct nfs_parsed_mount_data
*data
)
1349 struct rpc_timeout timeparms
;
1352 dprintk("--> nfs4_init_server()\n");
1354 nfs_init_timeout_values(&timeparms
, data
->nfs_server
.protocol
,
1355 data
->timeo
, data
->retrans
);
1357 /* Initialise the client representation from the mount data */
1358 server
->flags
= data
->flags
;
1359 server
->caps
|= NFS_CAP_ATOMIC_OPEN
|NFS_CAP_CHANGE_ATTR
|
1361 server
->options
= data
->options
;
1363 /* Get a client record */
1364 error
= nfs4_set_client(server
,
1365 data
->nfs_server
.hostname
,
1366 (const struct sockaddr
*)&data
->nfs_server
.address
,
1367 data
->nfs_server
.addrlen
,
1368 data
->client_address
,
1369 data
->auth_flavors
[0],
1370 data
->nfs_server
.protocol
,
1372 data
->minorversion
);
1377 server
->rsize
= nfs_block_size(data
->rsize
, NULL
);
1379 server
->wsize
= nfs_block_size(data
->wsize
, NULL
);
1381 server
->acregmin
= data
->acregmin
* HZ
;
1382 server
->acregmax
= data
->acregmax
* HZ
;
1383 server
->acdirmin
= data
->acdirmin
* HZ
;
1384 server
->acdirmax
= data
->acdirmax
* HZ
;
1386 server
->port
= data
->nfs_server
.port
;
1388 error
= nfs_init_server_rpcclient(server
, &timeparms
, data
->auth_flavors
[0]);
1392 dprintk("<-- nfs4_init_server() = %d\n", error
);
1397 * Create a version 4 volume record
1398 * - keyed on server and FSID
1400 struct nfs_server
*nfs4_create_server(const struct nfs_parsed_mount_data
*data
,
1401 struct nfs_fh
*mntfh
)
1403 struct nfs_server
*server
;
1406 dprintk("--> nfs4_create_server()\n");
1408 server
= nfs_alloc_server();
1410 return ERR_PTR(-ENOMEM
);
1412 /* set up the general RPC client */
1413 error
= nfs4_init_server(server
, data
);
1417 error
= nfs4_server_common_setup(server
, mntfh
);
1421 dprintk("<-- nfs4_create_server() = %p\n", server
);
1425 nfs_free_server(server
);
1426 dprintk("<-- nfs4_create_server() = error %d\n", error
);
1427 return ERR_PTR(error
);
1431 * Create an NFS4 referral server record
1433 struct nfs_server
*nfs4_create_referral_server(struct nfs_clone_mount
*data
,
1434 struct nfs_fh
*mntfh
)
1436 struct nfs_client
*parent_client
;
1437 struct nfs_server
*server
, *parent_server
;
1440 dprintk("--> nfs4_create_referral_server()\n");
1442 server
= nfs_alloc_server();
1444 return ERR_PTR(-ENOMEM
);
1446 parent_server
= NFS_SB(data
->sb
);
1447 parent_client
= parent_server
->nfs_client
;
1449 /* Initialise the client representation from the parent server */
1450 nfs_server_copy_userdata(server
, parent_server
);
1451 server
->caps
|= NFS_CAP_ATOMIC_OPEN
|NFS_CAP_CHANGE_ATTR
;
1453 /* Get a client representation.
1454 * Note: NFSv4 always uses TCP, */
1455 error
= nfs4_set_client(server
, data
->hostname
,
1458 parent_client
->cl_ipaddr
,
1460 parent_server
->client
->cl_xprt
->prot
,
1461 parent_server
->client
->cl_timeout
,
1462 parent_client
->cl_mvops
->minor_version
);
1466 error
= nfs_init_server_rpcclient(server
, parent_server
->client
->cl_timeout
, data
->authflavor
);
1470 error
= nfs4_server_common_setup(server
, mntfh
);
1474 dprintk("<-- nfs_create_referral_server() = %p\n", server
);
1478 nfs_free_server(server
);
1479 dprintk("<-- nfs4_create_referral_server() = error %d\n", error
);
1480 return ERR_PTR(error
);
1483 #endif /* CONFIG_NFS_V4 */
1486 * Clone an NFS2, NFS3 or NFS4 server record
1488 struct nfs_server
*nfs_clone_server(struct nfs_server
*source
,
1490 struct nfs_fattr
*fattr
)
1492 struct nfs_server
*server
;
1493 struct nfs_fattr
*fattr_fsinfo
;
1496 dprintk("--> nfs_clone_server(,%llx:%llx,)\n",
1497 (unsigned long long) fattr
->fsid
.major
,
1498 (unsigned long long) fattr
->fsid
.minor
);
1500 server
= nfs_alloc_server();
1502 return ERR_PTR(-ENOMEM
);
1505 fattr_fsinfo
= nfs_alloc_fattr();
1506 if (fattr_fsinfo
== NULL
)
1507 goto out_free_server
;
1509 /* Copy data from the source */
1510 server
->nfs_client
= source
->nfs_client
;
1511 atomic_inc(&server
->nfs_client
->cl_count
);
1512 nfs_server_copy_userdata(server
, source
);
1514 server
->fsid
= fattr
->fsid
;
1516 error
= nfs_init_server_rpcclient(server
,
1517 source
->client
->cl_timeout
,
1518 source
->client
->cl_auth
->au_flavor
);
1520 goto out_free_server
;
1521 if (!IS_ERR(source
->client_acl
))
1522 nfs_init_server_aclclient(server
);
1524 /* probe the filesystem info for this server filesystem */
1525 error
= nfs_probe_fsinfo(server
, fh
, fattr_fsinfo
);
1527 goto out_free_server
;
1529 if (server
->namelen
== 0 || server
->namelen
> NFS4_MAXNAMLEN
)
1530 server
->namelen
= NFS4_MAXNAMLEN
;
1532 dprintk("Cloned FSID: %llx:%llx\n",
1533 (unsigned long long) server
->fsid
.major
,
1534 (unsigned long long) server
->fsid
.minor
);
1536 error
= nfs_start_lockd(server
);
1538 goto out_free_server
;
1540 spin_lock(&nfs_client_lock
);
1541 list_add_tail(&server
->client_link
, &server
->nfs_client
->cl_superblocks
);
1542 list_add_tail(&server
->master_link
, &nfs_volume_list
);
1543 spin_unlock(&nfs_client_lock
);
1545 server
->mount_time
= jiffies
;
1547 nfs_free_fattr(fattr_fsinfo
);
1548 dprintk("<-- nfs_clone_server() = %p\n", server
);
1552 nfs_free_fattr(fattr_fsinfo
);
1553 nfs_free_server(server
);
1554 dprintk("<-- nfs_clone_server() = error %d\n", error
);
1555 return ERR_PTR(error
);
1558 #ifdef CONFIG_PROC_FS
1559 static struct proc_dir_entry
*proc_fs_nfs
;
1561 static int nfs_server_list_open(struct inode
*inode
, struct file
*file
);
1562 static void *nfs_server_list_start(struct seq_file
*p
, loff_t
*pos
);
1563 static void *nfs_server_list_next(struct seq_file
*p
, void *v
, loff_t
*pos
);
1564 static void nfs_server_list_stop(struct seq_file
*p
, void *v
);
1565 static int nfs_server_list_show(struct seq_file
*m
, void *v
);
1567 static const struct seq_operations nfs_server_list_ops
= {
1568 .start
= nfs_server_list_start
,
1569 .next
= nfs_server_list_next
,
1570 .stop
= nfs_server_list_stop
,
1571 .show
= nfs_server_list_show
,
1574 static const struct file_operations nfs_server_list_fops
= {
1575 .open
= nfs_server_list_open
,
1577 .llseek
= seq_lseek
,
1578 .release
= seq_release
,
1579 .owner
= THIS_MODULE
,
1582 static int nfs_volume_list_open(struct inode
*inode
, struct file
*file
);
1583 static void *nfs_volume_list_start(struct seq_file
*p
, loff_t
*pos
);
1584 static void *nfs_volume_list_next(struct seq_file
*p
, void *v
, loff_t
*pos
);
1585 static void nfs_volume_list_stop(struct seq_file
*p
, void *v
);
1586 static int nfs_volume_list_show(struct seq_file
*m
, void *v
);
1588 static const struct seq_operations nfs_volume_list_ops
= {
1589 .start
= nfs_volume_list_start
,
1590 .next
= nfs_volume_list_next
,
1591 .stop
= nfs_volume_list_stop
,
1592 .show
= nfs_volume_list_show
,
1595 static const struct file_operations nfs_volume_list_fops
= {
1596 .open
= nfs_volume_list_open
,
1598 .llseek
= seq_lseek
,
1599 .release
= seq_release
,
1600 .owner
= THIS_MODULE
,
1604 * open "/proc/fs/nfsfs/servers" which provides a summary of servers with which
1607 static int nfs_server_list_open(struct inode
*inode
, struct file
*file
)
1612 ret
= seq_open(file
, &nfs_server_list_ops
);
1616 m
= file
->private_data
;
1617 m
->private = PDE(inode
)->data
;
1623 * set up the iterator to start reading from the server list and return the first item
1625 static void *nfs_server_list_start(struct seq_file
*m
, loff_t
*_pos
)
1627 /* lock the list against modification */
1628 spin_lock(&nfs_client_lock
);
1629 return seq_list_start_head(&nfs_client_list
, *_pos
);
1633 * move to next server
1635 static void *nfs_server_list_next(struct seq_file
*p
, void *v
, loff_t
*pos
)
1637 return seq_list_next(v
, &nfs_client_list
, pos
);
1641 * clean up after reading from the transports list
1643 static void nfs_server_list_stop(struct seq_file
*p
, void *v
)
1645 spin_unlock(&nfs_client_lock
);
1649 * display a header line followed by a load of call lines
1651 static int nfs_server_list_show(struct seq_file
*m
, void *v
)
1653 struct nfs_client
*clp
;
1655 /* display header on line 1 */
1656 if (v
== &nfs_client_list
) {
1657 seq_puts(m
, "NV SERVER PORT USE HOSTNAME\n");
1661 /* display one transport per line on subsequent lines */
1662 clp
= list_entry(v
, struct nfs_client
, cl_share_link
);
1664 seq_printf(m
, "v%u %s %s %3d %s\n",
1665 clp
->rpc_ops
->version
,
1666 rpc_peeraddr2str(clp
->cl_rpcclient
, RPC_DISPLAY_HEX_ADDR
),
1667 rpc_peeraddr2str(clp
->cl_rpcclient
, RPC_DISPLAY_HEX_PORT
),
1668 atomic_read(&clp
->cl_count
),
1675 * open "/proc/fs/nfsfs/volumes" which provides a summary of extant volumes
1677 static int nfs_volume_list_open(struct inode
*inode
, struct file
*file
)
1682 ret
= seq_open(file
, &nfs_volume_list_ops
);
1686 m
= file
->private_data
;
1687 m
->private = PDE(inode
)->data
;
1693 * set up the iterator to start reading from the volume list and return the first item
1695 static void *nfs_volume_list_start(struct seq_file
*m
, loff_t
*_pos
)
1697 /* lock the list against modification */
1698 spin_lock(&nfs_client_lock
);
1699 return seq_list_start_head(&nfs_volume_list
, *_pos
);
1703 * move to next volume
1705 static void *nfs_volume_list_next(struct seq_file
*p
, void *v
, loff_t
*pos
)
1707 return seq_list_next(v
, &nfs_volume_list
, pos
);
1711 * clean up after reading from the transports list
1713 static void nfs_volume_list_stop(struct seq_file
*p
, void *v
)
1715 spin_unlock(&nfs_client_lock
);
1719 * display a header line followed by a load of call lines
1721 static int nfs_volume_list_show(struct seq_file
*m
, void *v
)
1723 struct nfs_server
*server
;
1724 struct nfs_client
*clp
;
1725 char dev
[8], fsid
[17];
1727 /* display header on line 1 */
1728 if (v
== &nfs_volume_list
) {
1729 seq_puts(m
, "NV SERVER PORT DEV FSID FSC\n");
1732 /* display one transport per line on subsequent lines */
1733 server
= list_entry(v
, struct nfs_server
, master_link
);
1734 clp
= server
->nfs_client
;
1736 snprintf(dev
, 8, "%u:%u",
1737 MAJOR(server
->s_dev
), MINOR(server
->s_dev
));
1739 snprintf(fsid
, 17, "%llx:%llx",
1740 (unsigned long long) server
->fsid
.major
,
1741 (unsigned long long) server
->fsid
.minor
);
1743 seq_printf(m
, "v%u %s %s %-7s %-17s %s\n",
1744 clp
->rpc_ops
->version
,
1745 rpc_peeraddr2str(clp
->cl_rpcclient
, RPC_DISPLAY_HEX_ADDR
),
1746 rpc_peeraddr2str(clp
->cl_rpcclient
, RPC_DISPLAY_HEX_PORT
),
1749 nfs_server_fscache_state(server
));
1755 * initialise the /proc/fs/nfsfs/ directory
1757 int __init
nfs_fs_proc_init(void)
1759 struct proc_dir_entry
*p
;
1761 proc_fs_nfs
= proc_mkdir("fs/nfsfs", NULL
);
1765 /* a file of servers with which we're dealing */
1766 p
= proc_create("servers", S_IFREG
|S_IRUGO
,
1767 proc_fs_nfs
, &nfs_server_list_fops
);
1771 /* a file of volumes that we have mounted */
1772 p
= proc_create("volumes", S_IFREG
|S_IRUGO
,
1773 proc_fs_nfs
, &nfs_volume_list_fops
);
1779 remove_proc_entry("servers", proc_fs_nfs
);
1781 remove_proc_entry("fs/nfsfs", NULL
);
1787 * clean up the /proc/fs/nfsfs/ directory
1789 void nfs_fs_proc_exit(void)
1791 remove_proc_entry("volumes", proc_fs_nfs
);
1792 remove_proc_entry("servers", proc_fs_nfs
);
1793 remove_proc_entry("fs/nfsfs", NULL
);
1796 #endif /* CONFIG_PROC_FS */