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>
39 #include <linux/nfs_xdr.h>
41 #include <asm/system.h>
45 #include "delegation.h"
50 #define NFSDBG_FACILITY NFSDBG_CLIENT
52 static DEFINE_SPINLOCK(nfs_client_lock
);
53 static LIST_HEAD(nfs_client_list
);
54 static LIST_HEAD(nfs_volume_list
);
55 static DECLARE_WAIT_QUEUE_HEAD(nfs_client_active_wq
);
60 static struct rpc_version
*nfs_version
[5] = {
70 struct rpc_program nfs_program
= {
72 .number
= NFS_PROGRAM
,
73 .nrvers
= ARRAY_SIZE(nfs_version
),
74 .version
= nfs_version
,
75 .stats
= &nfs_rpcstat
,
76 .pipe_dir_name
= "/nfs",
79 struct rpc_stat nfs_rpcstat
= {
80 .program
= &nfs_program
84 #ifdef CONFIG_NFS_V3_ACL
85 static struct rpc_stat nfsacl_rpcstat
= { &nfsacl_program
};
86 static struct rpc_version
* nfsacl_version
[] = {
87 [3] = &nfsacl_version3
,
90 struct rpc_program nfsacl_program
= {
92 .number
= NFS_ACL_PROGRAM
,
93 .nrvers
= ARRAY_SIZE(nfsacl_version
),
94 .version
= nfsacl_version
,
95 .stats
= &nfsacl_rpcstat
,
97 #endif /* CONFIG_NFS_V3_ACL */
99 struct nfs_client_initdata
{
100 const char *hostname
;
101 const struct sockaddr
*addr
;
103 const struct nfs_rpc_ops
*rpc_ops
;
108 * Allocate a shared client record
110 * Since these are allocated/deallocated very rarely, we don't
111 * bother putting them in a slab cache...
113 static struct nfs_client
*nfs_alloc_client(const struct nfs_client_initdata
*cl_init
)
115 struct nfs_client
*clp
;
116 struct rpc_cred
*cred
;
118 if ((clp
= kzalloc(sizeof(*clp
), GFP_KERNEL
)) == NULL
)
121 clp
->rpc_ops
= cl_init
->rpc_ops
;
123 if (cl_init
->rpc_ops
->version
== 4) {
124 if (nfs_callback_up() < 0)
126 __set_bit(NFS_CS_CALLBACK
, &clp
->cl_res_state
);
129 atomic_set(&clp
->cl_count
, 1);
130 clp
->cl_cons_state
= NFS_CS_INITING
;
132 memcpy(&clp
->cl_addr
, cl_init
->addr
, cl_init
->addrlen
);
133 clp
->cl_addrlen
= cl_init
->addrlen
;
135 if (cl_init
->hostname
) {
136 clp
->cl_hostname
= kstrdup(cl_init
->hostname
, GFP_KERNEL
);
137 if (!clp
->cl_hostname
)
141 INIT_LIST_HEAD(&clp
->cl_superblocks
);
142 clp
->cl_rpcclient
= ERR_PTR(-EINVAL
);
144 clp
->cl_proto
= cl_init
->proto
;
147 INIT_LIST_HEAD(&clp
->cl_delegations
);
148 spin_lock_init(&clp
->cl_lock
);
149 INIT_DELAYED_WORK(&clp
->cl_renewd
, nfs4_renew_state
);
150 rpc_init_wait_queue(&clp
->cl_rpcwaitq
, "NFS client");
151 clp
->cl_boot_time
= CURRENT_TIME
;
152 clp
->cl_state
= 1 << NFS4CLNT_LEASE_EXPIRED
;
154 cred
= rpc_lookup_machine_cred();
156 clp
->cl_machine_cred
= cred
;
158 nfs_fscache_get_client_cookie(clp
);
163 if (__test_and_clear_bit(NFS_CS_CALLBACK
, &clp
->cl_res_state
))
171 static void nfs4_shutdown_client(struct nfs_client
*clp
)
174 if (__test_and_clear_bit(NFS_CS_RENEWD
, &clp
->cl_res_state
))
175 nfs4_kill_renewd(clp
);
176 BUG_ON(!RB_EMPTY_ROOT(&clp
->cl_state_owners
));
177 if (__test_and_clear_bit(NFS_CS_IDMAP
, &clp
->cl_res_state
))
178 nfs_idmap_delete(clp
);
180 rpc_destroy_wait_queue(&clp
->cl_rpcwaitq
);
185 * Destroy a shared client record
187 static void nfs_free_client(struct nfs_client
*clp
)
189 dprintk("--> nfs_free_client(%u)\n", clp
->rpc_ops
->version
);
191 nfs4_shutdown_client(clp
);
193 nfs_fscache_release_client_cookie(clp
);
195 /* -EIO all pending I/O */
196 if (!IS_ERR(clp
->cl_rpcclient
))
197 rpc_shutdown_client(clp
->cl_rpcclient
);
199 if (__test_and_clear_bit(NFS_CS_CALLBACK
, &clp
->cl_res_state
))
202 if (clp
->cl_machine_cred
!= NULL
)
203 put_rpccred(clp
->cl_machine_cred
);
205 kfree(clp
->cl_hostname
);
208 dprintk("<-- nfs_free_client()\n");
212 * Release a reference to a shared client record
214 void nfs_put_client(struct nfs_client
*clp
)
219 dprintk("--> nfs_put_client({%d})\n", atomic_read(&clp
->cl_count
));
221 if (atomic_dec_and_lock(&clp
->cl_count
, &nfs_client_lock
)) {
222 list_del(&clp
->cl_share_link
);
223 spin_unlock(&nfs_client_lock
);
225 BUG_ON(!list_empty(&clp
->cl_superblocks
));
227 nfs_free_client(clp
);
231 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
233 * Test if two ip6 socket addresses refer to the same socket by
234 * comparing relevant fields. The padding bytes specifically, are not
235 * compared. sin6_flowinfo is not compared because it only affects QoS
236 * and sin6_scope_id is only compared if the address is "link local"
237 * because "link local" addresses need only be unique to a specific
238 * link. Conversely, ordinary unicast addresses might have different
241 * The caller should ensure both socket addresses are AF_INET6.
243 static int nfs_sockaddr_match_ipaddr6(const struct sockaddr
*sa1
,
244 const struct sockaddr
*sa2
)
246 const struct sockaddr_in6
*sin1
= (const struct sockaddr_in6
*)sa1
;
247 const struct sockaddr_in6
*sin2
= (const struct sockaddr_in6
*)sa2
;
249 if (ipv6_addr_scope(&sin1
->sin6_addr
) == IPV6_ADDR_SCOPE_LINKLOCAL
&&
250 sin1
->sin6_scope_id
!= sin2
->sin6_scope_id
)
253 return ipv6_addr_equal(&sin1
->sin6_addr
, &sin1
->sin6_addr
);
255 #else /* !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE) */
256 static int nfs_sockaddr_match_ipaddr6(const struct sockaddr
*sa1
,
257 const struct sockaddr
*sa2
)
264 * Test if two ip4 socket addresses refer to the same socket, by
265 * comparing relevant fields. The padding bytes specifically, are
268 * The caller should ensure both socket addresses are AF_INET.
270 static int nfs_sockaddr_match_ipaddr4(const struct sockaddr
*sa1
,
271 const struct sockaddr
*sa2
)
273 const struct sockaddr_in
*sin1
= (const struct sockaddr_in
*)sa1
;
274 const struct sockaddr_in
*sin2
= (const struct sockaddr_in
*)sa2
;
276 return sin1
->sin_addr
.s_addr
== sin2
->sin_addr
.s_addr
;
279 static int nfs_sockaddr_cmp_ip6(const struct sockaddr
*sa1
,
280 const struct sockaddr
*sa2
)
282 const struct sockaddr_in6
*sin1
= (const struct sockaddr_in6
*)sa1
;
283 const struct sockaddr_in6
*sin2
= (const struct sockaddr_in6
*)sa2
;
285 return nfs_sockaddr_match_ipaddr6(sa1
, sa2
) &&
286 (sin1
->sin6_port
== sin2
->sin6_port
);
289 static int nfs_sockaddr_cmp_ip4(const struct sockaddr
*sa1
,
290 const struct sockaddr
*sa2
)
292 const struct sockaddr_in
*sin1
= (const struct sockaddr_in
*)sa1
;
293 const struct sockaddr_in
*sin2
= (const struct sockaddr_in
*)sa2
;
295 return nfs_sockaddr_match_ipaddr4(sa1
, sa2
) &&
296 (sin1
->sin_port
== sin2
->sin_port
);
300 * Test if two socket addresses represent the same actual socket,
301 * by comparing (only) relevant fields, excluding the port number.
303 static int nfs_sockaddr_match_ipaddr(const struct sockaddr
*sa1
,
304 const struct sockaddr
*sa2
)
306 if (sa1
->sa_family
!= sa2
->sa_family
)
309 switch (sa1
->sa_family
) {
311 return nfs_sockaddr_match_ipaddr4(sa1
, sa2
);
313 return nfs_sockaddr_match_ipaddr6(sa1
, sa2
);
319 * Test if two socket addresses represent the same actual socket,
320 * by comparing (only) relevant fields, including the port number.
322 static int nfs_sockaddr_cmp(const struct sockaddr
*sa1
,
323 const struct sockaddr
*sa2
)
325 if (sa1
->sa_family
!= sa2
->sa_family
)
328 switch (sa1
->sa_family
) {
330 return nfs_sockaddr_cmp_ip4(sa1
, sa2
);
332 return nfs_sockaddr_cmp_ip6(sa1
, sa2
);
338 * Find a client by IP address and protocol version
339 * - returns NULL if no such client
341 struct nfs_client
*nfs_find_client(const struct sockaddr
*addr
, u32 nfsversion
)
343 struct nfs_client
*clp
;
345 spin_lock(&nfs_client_lock
);
346 list_for_each_entry(clp
, &nfs_client_list
, cl_share_link
) {
347 struct sockaddr
*clap
= (struct sockaddr
*)&clp
->cl_addr
;
349 /* Don't match clients that failed to initialise properly */
350 if (clp
->cl_cons_state
!= NFS_CS_READY
)
353 /* Different NFS versions cannot share the same nfs_client */
354 if (clp
->rpc_ops
->version
!= nfsversion
)
357 /* Match only the IP address, not the port number */
358 if (!nfs_sockaddr_match_ipaddr(addr
, clap
))
361 atomic_inc(&clp
->cl_count
);
362 spin_unlock(&nfs_client_lock
);
365 spin_unlock(&nfs_client_lock
);
370 * Find a client by IP address and protocol version
371 * - returns NULL if no such client
373 struct nfs_client
*nfs_find_client_next(struct nfs_client
*clp
)
375 struct sockaddr
*sap
= (struct sockaddr
*)&clp
->cl_addr
;
376 u32 nfsvers
= clp
->rpc_ops
->version
;
378 spin_lock(&nfs_client_lock
);
379 list_for_each_entry_continue(clp
, &nfs_client_list
, cl_share_link
) {
380 struct sockaddr
*clap
= (struct sockaddr
*)&clp
->cl_addr
;
382 /* Don't match clients that failed to initialise properly */
383 if (clp
->cl_cons_state
!= NFS_CS_READY
)
386 /* Different NFS versions cannot share the same nfs_client */
387 if (clp
->rpc_ops
->version
!= nfsvers
)
390 /* Match only the IP address, not the port number */
391 if (!nfs_sockaddr_match_ipaddr(sap
, clap
))
394 atomic_inc(&clp
->cl_count
);
395 spin_unlock(&nfs_client_lock
);
398 spin_unlock(&nfs_client_lock
);
403 * Find an nfs_client on the list that matches the initialisation data
406 static struct nfs_client
*nfs_match_client(const struct nfs_client_initdata
*data
)
408 struct nfs_client
*clp
;
409 const struct sockaddr
*sap
= data
->addr
;
411 list_for_each_entry(clp
, &nfs_client_list
, cl_share_link
) {
412 const struct sockaddr
*clap
= (struct sockaddr
*)&clp
->cl_addr
;
413 /* Don't match clients that failed to initialise properly */
414 if (clp
->cl_cons_state
< 0)
417 /* Different NFS versions cannot share the same nfs_client */
418 if (clp
->rpc_ops
!= data
->rpc_ops
)
421 if (clp
->cl_proto
!= data
->proto
)
424 /* Match the full socket address */
425 if (!nfs_sockaddr_cmp(sap
, clap
))
428 atomic_inc(&clp
->cl_count
);
435 * Look up a client by IP address and protocol version
436 * - creates a new record if one doesn't yet exist
438 static struct nfs_client
*nfs_get_client(const struct nfs_client_initdata
*cl_init
)
440 struct nfs_client
*clp
, *new = NULL
;
443 dprintk("--> nfs_get_client(%s,v%u)\n",
444 cl_init
->hostname
?: "", cl_init
->rpc_ops
->version
);
446 /* see if the client already exists */
448 spin_lock(&nfs_client_lock
);
450 clp
= nfs_match_client(cl_init
);
456 spin_unlock(&nfs_client_lock
);
458 new = nfs_alloc_client(cl_init
);
461 return ERR_PTR(-ENOMEM
);
463 /* install a new client and return with it unready */
466 list_add(&clp
->cl_share_link
, &nfs_client_list
);
467 spin_unlock(&nfs_client_lock
);
468 dprintk("--> nfs_get_client() = %p [new]\n", clp
);
471 /* found an existing client
472 * - make sure it's ready before returning
475 spin_unlock(&nfs_client_lock
);
478 nfs_free_client(new);
480 error
= wait_event_killable(nfs_client_active_wq
,
481 clp
->cl_cons_state
!= NFS_CS_INITING
);
484 return ERR_PTR(-ERESTARTSYS
);
487 if (clp
->cl_cons_state
< NFS_CS_READY
) {
488 error
= clp
->cl_cons_state
;
490 return ERR_PTR(error
);
493 BUG_ON(clp
->cl_cons_state
!= NFS_CS_READY
);
495 dprintk("--> nfs_get_client() = %p [share]\n", clp
);
500 * Mark a server as ready or failed
502 static void nfs_mark_client_ready(struct nfs_client
*clp
, int state
)
504 clp
->cl_cons_state
= state
;
505 wake_up_all(&nfs_client_active_wq
);
509 * Initialise the timeout values for a connection
511 static void nfs_init_timeout_values(struct rpc_timeout
*to
, int proto
,
512 unsigned int timeo
, unsigned int retrans
)
514 to
->to_initval
= timeo
* HZ
/ 10;
515 to
->to_retries
= retrans
;
518 case XPRT_TRANSPORT_TCP
:
519 case XPRT_TRANSPORT_RDMA
:
520 if (to
->to_retries
== 0)
521 to
->to_retries
= NFS_DEF_TCP_RETRANS
;
522 if (to
->to_initval
== 0)
523 to
->to_initval
= NFS_DEF_TCP_TIMEO
* HZ
/ 10;
524 if (to
->to_initval
> NFS_MAX_TCP_TIMEOUT
)
525 to
->to_initval
= NFS_MAX_TCP_TIMEOUT
;
526 to
->to_increment
= to
->to_initval
;
527 to
->to_maxval
= to
->to_initval
+ (to
->to_increment
* to
->to_retries
);
528 if (to
->to_maxval
> NFS_MAX_TCP_TIMEOUT
)
529 to
->to_maxval
= NFS_MAX_TCP_TIMEOUT
;
530 if (to
->to_maxval
< to
->to_initval
)
531 to
->to_maxval
= to
->to_initval
;
532 to
->to_exponential
= 0;
534 case XPRT_TRANSPORT_UDP
:
535 if (to
->to_retries
== 0)
536 to
->to_retries
= NFS_DEF_UDP_RETRANS
;
538 to
->to_initval
= NFS_DEF_UDP_TIMEO
* HZ
/ 10;
539 if (to
->to_initval
> NFS_MAX_UDP_TIMEOUT
)
540 to
->to_initval
= NFS_MAX_UDP_TIMEOUT
;
541 to
->to_maxval
= NFS_MAX_UDP_TIMEOUT
;
542 to
->to_exponential
= 1;
550 * Create an RPC client handle
552 static int nfs_create_rpc_client(struct nfs_client
*clp
,
553 const struct rpc_timeout
*timeparms
,
554 rpc_authflavor_t flavor
,
555 int discrtry
, int noresvport
)
557 struct rpc_clnt
*clnt
= NULL
;
558 struct rpc_create_args args
= {
559 .protocol
= clp
->cl_proto
,
560 .address
= (struct sockaddr
*)&clp
->cl_addr
,
561 .addrsize
= clp
->cl_addrlen
,
562 .timeout
= timeparms
,
563 .servername
= clp
->cl_hostname
,
564 .program
= &nfs_program
,
565 .version
= clp
->rpc_ops
->version
,
566 .authflavor
= flavor
,
570 args
.flags
|= RPC_CLNT_CREATE_DISCRTRY
;
572 args
.flags
|= RPC_CLNT_CREATE_NONPRIVPORT
;
574 if (!IS_ERR(clp
->cl_rpcclient
))
577 clnt
= rpc_create(&args
);
579 dprintk("%s: cannot create RPC client. Error = %ld\n",
580 __func__
, PTR_ERR(clnt
));
581 return PTR_ERR(clnt
);
584 clp
->cl_rpcclient
= clnt
;
589 * Version 2 or 3 client destruction
591 static void nfs_destroy_server(struct nfs_server
*server
)
593 if (!(server
->flags
& NFS_MOUNT_NONLM
))
594 nlmclnt_done(server
->nlm_host
);
598 * Version 2 or 3 lockd setup
600 static int nfs_start_lockd(struct nfs_server
*server
)
602 struct nlm_host
*host
;
603 struct nfs_client
*clp
= server
->nfs_client
;
604 struct nlmclnt_initdata nlm_init
= {
605 .hostname
= clp
->cl_hostname
,
606 .address
= (struct sockaddr
*)&clp
->cl_addr
,
607 .addrlen
= clp
->cl_addrlen
,
608 .protocol
= server
->flags
& NFS_MOUNT_TCP
?
609 IPPROTO_TCP
: IPPROTO_UDP
,
610 .nfs_version
= clp
->rpc_ops
->version
,
611 .noresvport
= server
->flags
& NFS_MOUNT_NORESVPORT
?
615 if (nlm_init
.nfs_version
> 3)
617 if (server
->flags
& NFS_MOUNT_NONLM
)
620 host
= nlmclnt_init(&nlm_init
);
622 return PTR_ERR(host
);
624 server
->nlm_host
= host
;
625 server
->destroy
= nfs_destroy_server
;
630 * Initialise an NFSv3 ACL client connection
632 #ifdef CONFIG_NFS_V3_ACL
633 static void nfs_init_server_aclclient(struct nfs_server
*server
)
635 if (server
->nfs_client
->rpc_ops
->version
!= 3)
637 if (server
->flags
& NFS_MOUNT_NOACL
)
640 server
->client_acl
= rpc_bind_new_program(server
->client
, &nfsacl_program
, 3);
641 if (IS_ERR(server
->client_acl
))
644 /* No errors! Assume that Sun nfsacls are supported */
645 server
->caps
|= NFS_CAP_ACLS
;
649 server
->caps
&= ~NFS_CAP_ACLS
;
652 static inline void nfs_init_server_aclclient(struct nfs_server
*server
)
654 server
->flags
&= ~NFS_MOUNT_NOACL
;
655 server
->caps
&= ~NFS_CAP_ACLS
;
660 * Create a general RPC client
662 static int nfs_init_server_rpcclient(struct nfs_server
*server
,
663 const struct rpc_timeout
*timeo
,
664 rpc_authflavor_t pseudoflavour
)
666 struct nfs_client
*clp
= server
->nfs_client
;
668 server
->client
= rpc_clone_client(clp
->cl_rpcclient
);
669 if (IS_ERR(server
->client
)) {
670 dprintk("%s: couldn't create rpc_client!\n", __func__
);
671 return PTR_ERR(server
->client
);
674 memcpy(&server
->client
->cl_timeout_default
,
676 sizeof(server
->client
->cl_timeout_default
));
677 server
->client
->cl_timeout
= &server
->client
->cl_timeout_default
;
679 if (pseudoflavour
!= clp
->cl_rpcclient
->cl_auth
->au_flavor
) {
680 struct rpc_auth
*auth
;
682 auth
= rpcauth_create(pseudoflavour
, server
->client
);
684 dprintk("%s: couldn't create credcache!\n", __func__
);
685 return PTR_ERR(auth
);
688 server
->client
->cl_softrtry
= 0;
689 if (server
->flags
& NFS_MOUNT_SOFT
)
690 server
->client
->cl_softrtry
= 1;
696 * Initialise an NFS2 or NFS3 client
698 static int nfs_init_client(struct nfs_client
*clp
,
699 const struct rpc_timeout
*timeparms
,
700 const struct nfs_parsed_mount_data
*data
)
704 if (clp
->cl_cons_state
== NFS_CS_READY
) {
705 /* the client is already initialised */
706 dprintk("<-- nfs_init_client() = 0 [already %p]\n", clp
);
711 * Create a client RPC handle for doing FSSTAT with UNIX auth only
712 * - RFC 2623, sec 2.3.2
714 error
= nfs_create_rpc_client(clp
, timeparms
, RPC_AUTH_UNIX
,
715 0, data
->flags
& NFS_MOUNT_NORESVPORT
);
718 nfs_mark_client_ready(clp
, NFS_CS_READY
);
722 nfs_mark_client_ready(clp
, error
);
723 dprintk("<-- nfs_init_client() = xerror %d\n", error
);
728 * Create a version 2 or 3 client
730 static int nfs_init_server(struct nfs_server
*server
,
731 const struct nfs_parsed_mount_data
*data
)
733 struct nfs_client_initdata cl_init
= {
734 .hostname
= data
->nfs_server
.hostname
,
735 .addr
= (const struct sockaddr
*)&data
->nfs_server
.address
,
736 .addrlen
= data
->nfs_server
.addrlen
,
737 .rpc_ops
= &nfs_v2_clientops
,
738 .proto
= data
->nfs_server
.protocol
,
740 struct rpc_timeout timeparms
;
741 struct nfs_client
*clp
;
744 dprintk("--> nfs_init_server()\n");
747 if (data
->flags
& NFS_MOUNT_VER3
)
748 cl_init
.rpc_ops
= &nfs_v3_clientops
;
751 /* Allocate or find a client reference we can use */
752 clp
= nfs_get_client(&cl_init
);
754 dprintk("<-- nfs_init_server() = error %ld\n", PTR_ERR(clp
));
758 nfs_init_timeout_values(&timeparms
, data
->nfs_server
.protocol
,
759 data
->timeo
, data
->retrans
);
760 error
= nfs_init_client(clp
, &timeparms
, data
);
764 server
->nfs_client
= clp
;
766 /* Initialise the client representation from the mount data */
767 server
->flags
= data
->flags
;
770 server
->rsize
= nfs_block_size(data
->rsize
, NULL
);
772 server
->wsize
= nfs_block_size(data
->wsize
, NULL
);
774 server
->acregmin
= data
->acregmin
* HZ
;
775 server
->acregmax
= data
->acregmax
* HZ
;
776 server
->acdirmin
= data
->acdirmin
* HZ
;
777 server
->acdirmax
= data
->acdirmax
* HZ
;
779 /* Start lockd here, before we might error out */
780 error
= nfs_start_lockd(server
);
784 server
->port
= data
->nfs_server
.port
;
786 error
= nfs_init_server_rpcclient(server
, &timeparms
, data
->auth_flavors
[0]);
790 /* Preserve the values of mount_server-related mount options */
791 if (data
->mount_server
.addrlen
) {
792 memcpy(&server
->mountd_address
, &data
->mount_server
.address
,
793 data
->mount_server
.addrlen
);
794 server
->mountd_addrlen
= data
->mount_server
.addrlen
;
796 server
->mountd_version
= data
->mount_server
.version
;
797 server
->mountd_port
= data
->mount_server
.port
;
798 server
->mountd_protocol
= data
->mount_server
.protocol
;
800 server
->namelen
= data
->namlen
;
801 /* Create a client RPC handle for the NFSv3 ACL management interface */
802 nfs_init_server_aclclient(server
);
803 dprintk("<-- nfs_init_server() = 0 [new %p]\n", clp
);
807 server
->nfs_client
= NULL
;
809 dprintk("<-- nfs_init_server() = xerror %d\n", error
);
814 * Load up the server record from information gained in an fsinfo record
816 static void nfs_server_set_fsinfo(struct nfs_server
*server
, struct nfs_fsinfo
*fsinfo
)
818 unsigned long max_rpc_payload
;
820 /* Work out a lot of parameters */
821 if (server
->rsize
== 0)
822 server
->rsize
= nfs_block_size(fsinfo
->rtpref
, NULL
);
823 if (server
->wsize
== 0)
824 server
->wsize
= nfs_block_size(fsinfo
->wtpref
, NULL
);
826 if (fsinfo
->rtmax
>= 512 && server
->rsize
> fsinfo
->rtmax
)
827 server
->rsize
= nfs_block_size(fsinfo
->rtmax
, NULL
);
828 if (fsinfo
->wtmax
>= 512 && server
->wsize
> fsinfo
->wtmax
)
829 server
->wsize
= nfs_block_size(fsinfo
->wtmax
, NULL
);
831 max_rpc_payload
= nfs_block_size(rpc_max_payload(server
->client
), NULL
);
832 if (server
->rsize
> max_rpc_payload
)
833 server
->rsize
= max_rpc_payload
;
834 if (server
->rsize
> NFS_MAX_FILE_IO_SIZE
)
835 server
->rsize
= NFS_MAX_FILE_IO_SIZE
;
836 server
->rpages
= (server
->rsize
+ PAGE_CACHE_SIZE
- 1) >> PAGE_CACHE_SHIFT
;
838 server
->backing_dev_info
.ra_pages
= server
->rpages
* NFS_MAX_READAHEAD
;
840 if (server
->wsize
> max_rpc_payload
)
841 server
->wsize
= max_rpc_payload
;
842 if (server
->wsize
> NFS_MAX_FILE_IO_SIZE
)
843 server
->wsize
= NFS_MAX_FILE_IO_SIZE
;
844 server
->wpages
= (server
->wsize
+ PAGE_CACHE_SIZE
- 1) >> PAGE_CACHE_SHIFT
;
845 server
->wtmult
= nfs_block_bits(fsinfo
->wtmult
, NULL
);
847 server
->dtsize
= nfs_block_size(fsinfo
->dtpref
, NULL
);
848 if (server
->dtsize
> PAGE_CACHE_SIZE
)
849 server
->dtsize
= PAGE_CACHE_SIZE
;
850 if (server
->dtsize
> server
->rsize
)
851 server
->dtsize
= server
->rsize
;
853 if (server
->flags
& NFS_MOUNT_NOAC
) {
854 server
->acregmin
= server
->acregmax
= 0;
855 server
->acdirmin
= server
->acdirmax
= 0;
858 server
->maxfilesize
= fsinfo
->maxfilesize
;
860 /* We're airborne Set socket buffersize */
861 rpc_setbufsize(server
->client
, server
->wsize
+ 100, server
->rsize
+ 100);
865 * Probe filesystem information, including the FSID on v2/v3
867 static int nfs_probe_fsinfo(struct nfs_server
*server
, struct nfs_fh
*mntfh
, struct nfs_fattr
*fattr
)
869 struct nfs_fsinfo fsinfo
;
870 struct nfs_client
*clp
= server
->nfs_client
;
873 dprintk("--> nfs_probe_fsinfo()\n");
875 if (clp
->rpc_ops
->set_capabilities
!= NULL
) {
876 error
= clp
->rpc_ops
->set_capabilities(server
, mntfh
);
881 fsinfo
.fattr
= fattr
;
882 nfs_fattr_init(fattr
);
883 error
= clp
->rpc_ops
->fsinfo(server
, mntfh
, &fsinfo
);
887 nfs_server_set_fsinfo(server
, &fsinfo
);
888 error
= bdi_init(&server
->backing_dev_info
);
893 /* Get some general file system info */
894 if (server
->namelen
== 0) {
895 struct nfs_pathconf pathinfo
;
897 pathinfo
.fattr
= fattr
;
898 nfs_fattr_init(fattr
);
900 if (clp
->rpc_ops
->pathconf(server
, mntfh
, &pathinfo
) >= 0)
901 server
->namelen
= pathinfo
.max_namelen
;
904 dprintk("<-- nfs_probe_fsinfo() = 0\n");
908 dprintk("nfs_probe_fsinfo: error = %d\n", -error
);
913 * Copy useful information when duplicating a server record
915 static void nfs_server_copy_userdata(struct nfs_server
*target
, struct nfs_server
*source
)
917 target
->flags
= source
->flags
;
918 target
->acregmin
= source
->acregmin
;
919 target
->acregmax
= source
->acregmax
;
920 target
->acdirmin
= source
->acdirmin
;
921 target
->acdirmax
= source
->acdirmax
;
922 target
->caps
= source
->caps
;
926 * Allocate and initialise a server record
928 static struct nfs_server
*nfs_alloc_server(void)
930 struct nfs_server
*server
;
932 server
= kzalloc(sizeof(struct nfs_server
), GFP_KERNEL
);
936 server
->client
= server
->client_acl
= ERR_PTR(-EINVAL
);
938 /* Zero out the NFS state stuff */
939 INIT_LIST_HEAD(&server
->client_link
);
940 INIT_LIST_HEAD(&server
->master_link
);
942 atomic_set(&server
->active
, 0);
944 server
->io_stats
= nfs_alloc_iostats();
945 if (!server
->io_stats
) {
954 * Free up a server record
956 void nfs_free_server(struct nfs_server
*server
)
958 dprintk("--> nfs_free_server()\n");
960 spin_lock(&nfs_client_lock
);
961 list_del(&server
->client_link
);
962 list_del(&server
->master_link
);
963 spin_unlock(&nfs_client_lock
);
965 if (server
->destroy
!= NULL
)
966 server
->destroy(server
);
968 if (!IS_ERR(server
->client_acl
))
969 rpc_shutdown_client(server
->client_acl
);
970 if (!IS_ERR(server
->client
))
971 rpc_shutdown_client(server
->client
);
973 nfs_put_client(server
->nfs_client
);
975 nfs_free_iostats(server
->io_stats
);
976 bdi_destroy(&server
->backing_dev_info
);
978 nfs_release_automount_timer();
979 dprintk("<-- nfs_free_server()\n");
983 * Create a version 2 or 3 volume record
984 * - keyed on server and FSID
986 struct nfs_server
*nfs_create_server(const struct nfs_parsed_mount_data
*data
,
987 struct nfs_fh
*mntfh
)
989 struct nfs_server
*server
;
990 struct nfs_fattr fattr
;
993 server
= nfs_alloc_server();
995 return ERR_PTR(-ENOMEM
);
997 /* Get a client representation */
998 error
= nfs_init_server(server
, data
);
1002 BUG_ON(!server
->nfs_client
);
1003 BUG_ON(!server
->nfs_client
->rpc_ops
);
1004 BUG_ON(!server
->nfs_client
->rpc_ops
->file_inode_ops
);
1006 /* Probe the root fh to retrieve its FSID */
1007 error
= nfs_probe_fsinfo(server
, mntfh
, &fattr
);
1010 if (server
->nfs_client
->rpc_ops
->version
== 3) {
1011 if (server
->namelen
== 0 || server
->namelen
> NFS3_MAXNAMLEN
)
1012 server
->namelen
= NFS3_MAXNAMLEN
;
1013 if (!(data
->flags
& NFS_MOUNT_NORDIRPLUS
))
1014 server
->caps
|= NFS_CAP_READDIRPLUS
;
1016 if (server
->namelen
== 0 || server
->namelen
> NFS2_MAXNAMLEN
)
1017 server
->namelen
= NFS2_MAXNAMLEN
;
1020 if (!(fattr
.valid
& NFS_ATTR_FATTR
)) {
1021 error
= server
->nfs_client
->rpc_ops
->getattr(server
, mntfh
, &fattr
);
1023 dprintk("nfs_create_server: getattr error = %d\n", -error
);
1027 memcpy(&server
->fsid
, &fattr
.fsid
, sizeof(server
->fsid
));
1029 dprintk("Server FSID: %llx:%llx\n",
1030 (unsigned long long) server
->fsid
.major
,
1031 (unsigned long long) server
->fsid
.minor
);
1033 BUG_ON(!server
->nfs_client
);
1034 BUG_ON(!server
->nfs_client
->rpc_ops
);
1035 BUG_ON(!server
->nfs_client
->rpc_ops
->file_inode_ops
);
1037 spin_lock(&nfs_client_lock
);
1038 list_add_tail(&server
->client_link
, &server
->nfs_client
->cl_superblocks
);
1039 list_add_tail(&server
->master_link
, &nfs_volume_list
);
1040 spin_unlock(&nfs_client_lock
);
1042 server
->mount_time
= jiffies
;
1046 nfs_free_server(server
);
1047 return ERR_PTR(error
);
1050 #ifdef CONFIG_NFS_V4
1052 * Initialise an NFS4 client record
1054 static int nfs4_init_client(struct nfs_client
*clp
,
1055 const struct rpc_timeout
*timeparms
,
1056 const char *ip_addr
,
1057 rpc_authflavor_t authflavour
,
1062 if (clp
->cl_cons_state
== NFS_CS_READY
) {
1063 /* the client is initialised already */
1064 dprintk("<-- nfs4_init_client() = 0 [already %p]\n", clp
);
1068 /* Check NFS protocol revision and initialize RPC op vector */
1069 clp
->rpc_ops
= &nfs_v4_clientops
;
1071 error
= nfs_create_rpc_client(clp
, timeparms
, authflavour
,
1072 1, flags
& NFS_MOUNT_NORESVPORT
);
1075 memcpy(clp
->cl_ipaddr
, ip_addr
, sizeof(clp
->cl_ipaddr
));
1077 error
= nfs_idmap_new(clp
);
1079 dprintk("%s: failed to create idmapper. Error = %d\n",
1083 __set_bit(NFS_CS_IDMAP
, &clp
->cl_res_state
);
1085 nfs_mark_client_ready(clp
, NFS_CS_READY
);
1089 nfs_mark_client_ready(clp
, error
);
1090 dprintk("<-- nfs4_init_client() = xerror %d\n", error
);
1095 * Set up an NFS4 client
1097 static int nfs4_set_client(struct nfs_server
*server
,
1098 const char *hostname
,
1099 const struct sockaddr
*addr
,
1100 const size_t addrlen
,
1101 const char *ip_addr
,
1102 rpc_authflavor_t authflavour
,
1103 int proto
, const struct rpc_timeout
*timeparms
)
1105 struct nfs_client_initdata cl_init
= {
1106 .hostname
= hostname
,
1109 .rpc_ops
= &nfs_v4_clientops
,
1112 struct nfs_client
*clp
;
1115 dprintk("--> nfs4_set_client()\n");
1117 /* Allocate or find a client reference we can use */
1118 clp
= nfs_get_client(&cl_init
);
1120 error
= PTR_ERR(clp
);
1123 error
= nfs4_init_client(clp
, timeparms
, ip_addr
, authflavour
,
1128 server
->nfs_client
= clp
;
1129 dprintk("<-- nfs4_set_client() = 0 [new %p]\n", clp
);
1133 nfs_put_client(clp
);
1135 dprintk("<-- nfs4_set_client() = xerror %d\n", error
);
1140 * Create a version 4 volume record
1142 static int nfs4_init_server(struct nfs_server
*server
,
1143 const struct nfs_parsed_mount_data
*data
)
1145 struct rpc_timeout timeparms
;
1148 dprintk("--> nfs4_init_server()\n");
1150 nfs_init_timeout_values(&timeparms
, data
->nfs_server
.protocol
,
1151 data
->timeo
, data
->retrans
);
1153 /* Initialise the client representation from the mount data */
1154 server
->flags
= data
->flags
;
1155 server
->caps
|= NFS_CAP_ATOMIC_OPEN
;
1157 /* Get a client record */
1158 error
= nfs4_set_client(server
,
1159 data
->nfs_server
.hostname
,
1160 (const struct sockaddr
*)&data
->nfs_server
.address
,
1161 data
->nfs_server
.addrlen
,
1162 data
->client_address
,
1163 data
->auth_flavors
[0],
1164 data
->nfs_server
.protocol
,
1170 server
->rsize
= nfs_block_size(data
->rsize
, NULL
);
1172 server
->wsize
= nfs_block_size(data
->wsize
, NULL
);
1174 server
->acregmin
= data
->acregmin
* HZ
;
1175 server
->acregmax
= data
->acregmax
* HZ
;
1176 server
->acdirmin
= data
->acdirmin
* HZ
;
1177 server
->acdirmax
= data
->acdirmax
* HZ
;
1179 server
->port
= data
->nfs_server
.port
;
1181 error
= nfs_init_server_rpcclient(server
, &timeparms
, data
->auth_flavors
[0]);
1185 dprintk("<-- nfs4_init_server() = %d\n", error
);
1190 * Create a version 4 volume record
1191 * - keyed on server and FSID
1193 struct nfs_server
*nfs4_create_server(const struct nfs_parsed_mount_data
*data
,
1194 struct nfs_fh
*mntfh
)
1196 struct nfs_fattr fattr
;
1197 struct nfs_server
*server
;
1200 dprintk("--> nfs4_create_server()\n");
1202 server
= nfs_alloc_server();
1204 return ERR_PTR(-ENOMEM
);
1206 /* set up the general RPC client */
1207 error
= nfs4_init_server(server
, data
);
1211 BUG_ON(!server
->nfs_client
);
1212 BUG_ON(!server
->nfs_client
->rpc_ops
);
1213 BUG_ON(!server
->nfs_client
->rpc_ops
->file_inode_ops
);
1215 /* Probe the root fh to retrieve its FSID */
1216 error
= nfs4_path_walk(server
, mntfh
, data
->nfs_server
.export_path
);
1220 dprintk("Server FSID: %llx:%llx\n",
1221 (unsigned long long) server
->fsid
.major
,
1222 (unsigned long long) server
->fsid
.minor
);
1223 dprintk("Mount FH: %d\n", mntfh
->size
);
1225 error
= nfs_probe_fsinfo(server
, mntfh
, &fattr
);
1229 if (server
->namelen
== 0 || server
->namelen
> NFS4_MAXNAMLEN
)
1230 server
->namelen
= NFS4_MAXNAMLEN
;
1232 BUG_ON(!server
->nfs_client
);
1233 BUG_ON(!server
->nfs_client
->rpc_ops
);
1234 BUG_ON(!server
->nfs_client
->rpc_ops
->file_inode_ops
);
1236 spin_lock(&nfs_client_lock
);
1237 list_add_tail(&server
->client_link
, &server
->nfs_client
->cl_superblocks
);
1238 list_add_tail(&server
->master_link
, &nfs_volume_list
);
1239 spin_unlock(&nfs_client_lock
);
1241 server
->mount_time
= jiffies
;
1242 dprintk("<-- nfs4_create_server() = %p\n", server
);
1246 nfs_free_server(server
);
1247 dprintk("<-- nfs4_create_server() = error %d\n", error
);
1248 return ERR_PTR(error
);
1252 * Create an NFS4 referral server record
1254 struct nfs_server
*nfs4_create_referral_server(struct nfs_clone_mount
*data
,
1255 struct nfs_fh
*mntfh
)
1257 struct nfs_client
*parent_client
;
1258 struct nfs_server
*server
, *parent_server
;
1259 struct nfs_fattr fattr
;
1262 dprintk("--> nfs4_create_referral_server()\n");
1264 server
= nfs_alloc_server();
1266 return ERR_PTR(-ENOMEM
);
1268 parent_server
= NFS_SB(data
->sb
);
1269 parent_client
= parent_server
->nfs_client
;
1271 /* Initialise the client representation from the parent server */
1272 nfs_server_copy_userdata(server
, parent_server
);
1273 server
->caps
|= NFS_CAP_ATOMIC_OPEN
;
1275 /* Get a client representation.
1276 * Note: NFSv4 always uses TCP, */
1277 error
= nfs4_set_client(server
, data
->hostname
,
1280 parent_client
->cl_ipaddr
,
1282 parent_server
->client
->cl_xprt
->prot
,
1283 parent_server
->client
->cl_timeout
);
1287 error
= nfs_init_server_rpcclient(server
, parent_server
->client
->cl_timeout
, data
->authflavor
);
1291 BUG_ON(!server
->nfs_client
);
1292 BUG_ON(!server
->nfs_client
->rpc_ops
);
1293 BUG_ON(!server
->nfs_client
->rpc_ops
->file_inode_ops
);
1295 /* Probe the root fh to retrieve its FSID and filehandle */
1296 error
= nfs4_path_walk(server
, mntfh
, data
->mnt_path
);
1300 /* probe the filesystem info for this server filesystem */
1301 error
= nfs_probe_fsinfo(server
, mntfh
, &fattr
);
1305 if (server
->namelen
== 0 || server
->namelen
> NFS4_MAXNAMLEN
)
1306 server
->namelen
= NFS4_MAXNAMLEN
;
1308 dprintk("Referral FSID: %llx:%llx\n",
1309 (unsigned long long) server
->fsid
.major
,
1310 (unsigned long long) server
->fsid
.minor
);
1312 spin_lock(&nfs_client_lock
);
1313 list_add_tail(&server
->client_link
, &server
->nfs_client
->cl_superblocks
);
1314 list_add_tail(&server
->master_link
, &nfs_volume_list
);
1315 spin_unlock(&nfs_client_lock
);
1317 server
->mount_time
= jiffies
;
1319 dprintk("<-- nfs_create_referral_server() = %p\n", server
);
1323 nfs_free_server(server
);
1324 dprintk("<-- nfs4_create_referral_server() = error %d\n", error
);
1325 return ERR_PTR(error
);
1328 #endif /* CONFIG_NFS_V4 */
1331 * Clone an NFS2, NFS3 or NFS4 server record
1333 struct nfs_server
*nfs_clone_server(struct nfs_server
*source
,
1335 struct nfs_fattr
*fattr
)
1337 struct nfs_server
*server
;
1338 struct nfs_fattr fattr_fsinfo
;
1341 dprintk("--> nfs_clone_server(,%llx:%llx,)\n",
1342 (unsigned long long) fattr
->fsid
.major
,
1343 (unsigned long long) fattr
->fsid
.minor
);
1345 server
= nfs_alloc_server();
1347 return ERR_PTR(-ENOMEM
);
1349 /* Copy data from the source */
1350 server
->nfs_client
= source
->nfs_client
;
1351 atomic_inc(&server
->nfs_client
->cl_count
);
1352 nfs_server_copy_userdata(server
, source
);
1354 server
->fsid
= fattr
->fsid
;
1356 error
= nfs_init_server_rpcclient(server
,
1357 source
->client
->cl_timeout
,
1358 source
->client
->cl_auth
->au_flavor
);
1360 goto out_free_server
;
1361 if (!IS_ERR(source
->client_acl
))
1362 nfs_init_server_aclclient(server
);
1364 /* probe the filesystem info for this server filesystem */
1365 error
= nfs_probe_fsinfo(server
, fh
, &fattr_fsinfo
);
1367 goto out_free_server
;
1369 if (server
->namelen
== 0 || server
->namelen
> NFS4_MAXNAMLEN
)
1370 server
->namelen
= NFS4_MAXNAMLEN
;
1372 dprintk("Cloned FSID: %llx:%llx\n",
1373 (unsigned long long) server
->fsid
.major
,
1374 (unsigned long long) server
->fsid
.minor
);
1376 error
= nfs_start_lockd(server
);
1378 goto out_free_server
;
1380 spin_lock(&nfs_client_lock
);
1381 list_add_tail(&server
->client_link
, &server
->nfs_client
->cl_superblocks
);
1382 list_add_tail(&server
->master_link
, &nfs_volume_list
);
1383 spin_unlock(&nfs_client_lock
);
1385 server
->mount_time
= jiffies
;
1387 dprintk("<-- nfs_clone_server() = %p\n", server
);
1391 nfs_free_server(server
);
1392 dprintk("<-- nfs_clone_server() = error %d\n", error
);
1393 return ERR_PTR(error
);
1396 #ifdef CONFIG_PROC_FS
1397 static struct proc_dir_entry
*proc_fs_nfs
;
1399 static int nfs_server_list_open(struct inode
*inode
, struct file
*file
);
1400 static void *nfs_server_list_start(struct seq_file
*p
, loff_t
*pos
);
1401 static void *nfs_server_list_next(struct seq_file
*p
, void *v
, loff_t
*pos
);
1402 static void nfs_server_list_stop(struct seq_file
*p
, void *v
);
1403 static int nfs_server_list_show(struct seq_file
*m
, void *v
);
1405 static struct seq_operations nfs_server_list_ops
= {
1406 .start
= nfs_server_list_start
,
1407 .next
= nfs_server_list_next
,
1408 .stop
= nfs_server_list_stop
,
1409 .show
= nfs_server_list_show
,
1412 static const struct file_operations nfs_server_list_fops
= {
1413 .open
= nfs_server_list_open
,
1415 .llseek
= seq_lseek
,
1416 .release
= seq_release
,
1417 .owner
= THIS_MODULE
,
1420 static int nfs_volume_list_open(struct inode
*inode
, struct file
*file
);
1421 static void *nfs_volume_list_start(struct seq_file
*p
, loff_t
*pos
);
1422 static void *nfs_volume_list_next(struct seq_file
*p
, void *v
, loff_t
*pos
);
1423 static void nfs_volume_list_stop(struct seq_file
*p
, void *v
);
1424 static int nfs_volume_list_show(struct seq_file
*m
, void *v
);
1426 static struct seq_operations nfs_volume_list_ops
= {
1427 .start
= nfs_volume_list_start
,
1428 .next
= nfs_volume_list_next
,
1429 .stop
= nfs_volume_list_stop
,
1430 .show
= nfs_volume_list_show
,
1433 static const struct file_operations nfs_volume_list_fops
= {
1434 .open
= nfs_volume_list_open
,
1436 .llseek
= seq_lseek
,
1437 .release
= seq_release
,
1438 .owner
= THIS_MODULE
,
1442 * open "/proc/fs/nfsfs/servers" which provides a summary of servers with which
1445 static int nfs_server_list_open(struct inode
*inode
, struct file
*file
)
1450 ret
= seq_open(file
, &nfs_server_list_ops
);
1454 m
= file
->private_data
;
1455 m
->private = PDE(inode
)->data
;
1461 * set up the iterator to start reading from the server list and return the first item
1463 static void *nfs_server_list_start(struct seq_file
*m
, loff_t
*_pos
)
1465 /* lock the list against modification */
1466 spin_lock(&nfs_client_lock
);
1467 return seq_list_start_head(&nfs_client_list
, *_pos
);
1471 * move to next server
1473 static void *nfs_server_list_next(struct seq_file
*p
, void *v
, loff_t
*pos
)
1475 return seq_list_next(v
, &nfs_client_list
, pos
);
1479 * clean up after reading from the transports list
1481 static void nfs_server_list_stop(struct seq_file
*p
, void *v
)
1483 spin_unlock(&nfs_client_lock
);
1487 * display a header line followed by a load of call lines
1489 static int nfs_server_list_show(struct seq_file
*m
, void *v
)
1491 struct nfs_client
*clp
;
1493 /* display header on line 1 */
1494 if (v
== &nfs_client_list
) {
1495 seq_puts(m
, "NV SERVER PORT USE HOSTNAME\n");
1499 /* display one transport per line on subsequent lines */
1500 clp
= list_entry(v
, struct nfs_client
, cl_share_link
);
1502 seq_printf(m
, "v%u %s %s %3d %s\n",
1503 clp
->rpc_ops
->version
,
1504 rpc_peeraddr2str(clp
->cl_rpcclient
, RPC_DISPLAY_HEX_ADDR
),
1505 rpc_peeraddr2str(clp
->cl_rpcclient
, RPC_DISPLAY_HEX_PORT
),
1506 atomic_read(&clp
->cl_count
),
1513 * open "/proc/fs/nfsfs/volumes" which provides a summary of extant volumes
1515 static int nfs_volume_list_open(struct inode
*inode
, struct file
*file
)
1520 ret
= seq_open(file
, &nfs_volume_list_ops
);
1524 m
= file
->private_data
;
1525 m
->private = PDE(inode
)->data
;
1531 * set up the iterator to start reading from the volume list and return the first item
1533 static void *nfs_volume_list_start(struct seq_file
*m
, loff_t
*_pos
)
1535 /* lock the list against modification */
1536 spin_lock(&nfs_client_lock
);
1537 return seq_list_start_head(&nfs_volume_list
, *_pos
);
1541 * move to next volume
1543 static void *nfs_volume_list_next(struct seq_file
*p
, void *v
, loff_t
*pos
)
1545 return seq_list_next(v
, &nfs_volume_list
, pos
);
1549 * clean up after reading from the transports list
1551 static void nfs_volume_list_stop(struct seq_file
*p
, void *v
)
1553 spin_unlock(&nfs_client_lock
);
1557 * display a header line followed by a load of call lines
1559 static int nfs_volume_list_show(struct seq_file
*m
, void *v
)
1561 struct nfs_server
*server
;
1562 struct nfs_client
*clp
;
1563 char dev
[8], fsid
[17];
1565 /* display header on line 1 */
1566 if (v
== &nfs_volume_list
) {
1567 seq_puts(m
, "NV SERVER PORT DEV FSID\n");
1570 /* display one transport per line on subsequent lines */
1571 server
= list_entry(v
, struct nfs_server
, master_link
);
1572 clp
= server
->nfs_client
;
1574 snprintf(dev
, 8, "%u:%u",
1575 MAJOR(server
->s_dev
), MINOR(server
->s_dev
));
1577 snprintf(fsid
, 17, "%llx:%llx",
1578 (unsigned long long) server
->fsid
.major
,
1579 (unsigned long long) server
->fsid
.minor
);
1581 seq_printf(m
, "v%u %s %s %-7s %-17s\n",
1582 clp
->rpc_ops
->version
,
1583 rpc_peeraddr2str(clp
->cl_rpcclient
, RPC_DISPLAY_HEX_ADDR
),
1584 rpc_peeraddr2str(clp
->cl_rpcclient
, RPC_DISPLAY_HEX_PORT
),
1592 * initialise the /proc/fs/nfsfs/ directory
1594 int __init
nfs_fs_proc_init(void)
1596 struct proc_dir_entry
*p
;
1598 proc_fs_nfs
= proc_mkdir("fs/nfsfs", NULL
);
1602 /* a file of servers with which we're dealing */
1603 p
= proc_create("servers", S_IFREG
|S_IRUGO
,
1604 proc_fs_nfs
, &nfs_server_list_fops
);
1608 /* a file of volumes that we have mounted */
1609 p
= proc_create("volumes", S_IFREG
|S_IRUGO
,
1610 proc_fs_nfs
, &nfs_volume_list_fops
);
1616 remove_proc_entry("servers", proc_fs_nfs
);
1618 remove_proc_entry("fs/nfsfs", NULL
);
1624 * clean up the /proc/fs/nfsfs/ directory
1626 void nfs_fs_proc_exit(void)
1628 remove_proc_entry("volumes", proc_fs_nfs
);
1629 remove_proc_entry("servers", proc_fs_nfs
);
1630 remove_proc_entry("fs/nfsfs", NULL
);
1633 #endif /* CONFIG_PROC_FS */