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"
53 #define NFSDBG_FACILITY NFSDBG_CLIENT
55 static DEFINE_SPINLOCK(nfs_client_lock);
56 static LIST_HEAD(nfs_client_list);
57 static LIST_HEAD(nfs_volume_list);
58 static DECLARE_WAIT_QUEUE_HEAD(nfs_client_active_wq);
60 static DEFINE_IDR(cb_ident_idr); /* Protected by nfs_client_lock */
63 * Get a unique NFSv4.0 callback identifier which will be used
64 * by the V4.0 callback service to lookup the nfs_client struct
66 static int nfs_get_cb_ident_idr(struct nfs_client *clp, int minorversion)
70 if (clp->rpc_ops->version != 4 || minorversion != 0)
73 if (!idr_pre_get(&cb_ident_idr, GFP_KERNEL))
75 spin_lock(&nfs_client_lock);
76 ret = idr_get_new(&cb_ident_idr, clp, &clp->cl_cb_ident);
77 spin_unlock(&nfs_client_lock);
82 #endif /* CONFIG_NFS_V4 */
87 static struct rpc_version *nfs_version[5] = {
97 struct rpc_program nfs_program = {
99 .number = NFS_PROGRAM,
100 .nrvers = ARRAY_SIZE(nfs_version),
101 .version = nfs_version,
102 .stats = &nfs_rpcstat,
103 .pipe_dir_name = "/nfs",
106 struct rpc_stat nfs_rpcstat = {
107 .program = &nfs_program
111 #ifdef CONFIG_NFS_V3_ACL
112 static struct rpc_stat nfsacl_rpcstat = { &nfsacl_program };
113 static struct rpc_version * nfsacl_version[] = {
114 [3] = &nfsacl_version3,
117 struct rpc_program nfsacl_program = {
119 .number = NFS_ACL_PROGRAM,
120 .nrvers = ARRAY_SIZE(nfsacl_version),
121 .version = nfsacl_version,
122 .stats = &nfsacl_rpcstat,
124 #endif /* CONFIG_NFS_V3_ACL */
126 struct nfs_client_initdata {
127 const char *hostname;
128 const struct sockaddr *addr;
130 const struct nfs_rpc_ops *rpc_ops;
136 * Allocate a shared client record
138 * Since these are allocated/deallocated very rarely, we don't
139 * bother putting them in a slab cache...
141 static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init)
143 struct nfs_client *clp;
144 struct rpc_cred *cred;
147 if ((clp = kzalloc(sizeof(*clp), GFP_KERNEL)) == NULL)
150 clp->rpc_ops = cl_init->rpc_ops;
152 atomic_set(&clp->cl_count, 1);
153 clp->cl_cons_state = NFS_CS_INITING;
155 memcpy(&clp->cl_addr, cl_init->addr, cl_init->addrlen);
156 clp->cl_addrlen = cl_init->addrlen;
158 if (cl_init->hostname) {
160 clp->cl_hostname = kstrdup(cl_init->hostname, GFP_KERNEL);
161 if (!clp->cl_hostname)
165 INIT_LIST_HEAD(&clp->cl_superblocks);
166 clp->cl_rpcclient = ERR_PTR(-EINVAL);
168 clp->cl_proto = cl_init->proto;
171 err = nfs_get_cb_ident_idr(clp, cl_init->minorversion);
175 spin_lock_init(&clp->cl_lock);
176 INIT_DELAYED_WORK(&clp->cl_renewd, nfs4_renew_state);
177 rpc_init_wait_queue(&clp->cl_rpcwaitq, "NFS client");
178 clp->cl_boot_time = CURRENT_TIME;
179 clp->cl_state = 1 << NFS4CLNT_LEASE_EXPIRED;
180 clp->cl_minorversion = cl_init->minorversion;
181 clp->cl_mvops = nfs_v4_minor_ops[cl_init->minorversion];
183 cred = rpc_lookup_machine_cred();
185 clp->cl_machine_cred = cred;
186 #if defined(CONFIG_NFS_V4_1)
187 INIT_LIST_HEAD(&clp->cl_layouts);
189 nfs_fscache_get_client_cookie(clp);
200 #ifdef CONFIG_NFS_V4_1
201 static void nfs4_shutdown_session(struct nfs_client *clp)
203 if (nfs4_has_session(clp))
204 nfs4_destroy_session(clp->cl_session);
206 #else /* CONFIG_NFS_V4_1 */
207 static void nfs4_shutdown_session(struct nfs_client *clp)
210 #endif /* CONFIG_NFS_V4_1 */
213 * Destroy the NFS4 callback service
215 static void nfs4_destroy_callback(struct nfs_client *clp)
217 if (__test_and_clear_bit(NFS_CS_CALLBACK, &clp->cl_res_state))
218 nfs_callback_down(clp->cl_mvops->minor_version);
221 static void nfs4_shutdown_client(struct nfs_client *clp)
223 if (__test_and_clear_bit(NFS_CS_RENEWD, &clp->cl_res_state))
224 nfs4_kill_renewd(clp);
225 nfs4_shutdown_session(clp);
226 nfs4_destroy_callback(clp);
227 if (__test_and_clear_bit(NFS_CS_IDMAP, &clp->cl_res_state))
228 nfs_idmap_delete(clp);
230 rpc_destroy_wait_queue(&clp->cl_rpcwaitq);
233 /* idr_remove_all is not needed as all id's are removed by nfs_put_client */
234 void nfs_cleanup_cb_ident_idr(void)
236 idr_destroy(&cb_ident_idr);
239 /* nfs_client_lock held */
240 static void nfs_cb_idr_remove_locked(struct nfs_client *clp)
242 if (clp->cl_cb_ident)
243 idr_remove(&cb_ident_idr, clp->cl_cb_ident);
246 static void pnfs_init_server(struct nfs_server *server)
248 rpc_init_wait_queue(&server->roc_rpcwaitq, "pNFS ROC");
252 static void nfs4_shutdown_client(struct nfs_client *clp)
256 void nfs_cleanup_cb_ident_idr(void)
260 static void nfs_cb_idr_remove_locked(struct nfs_client *clp)
264 static void pnfs_init_server(struct nfs_server *server)
268 #endif /* CONFIG_NFS_V4 */
271 * Destroy a shared client record
273 static void nfs_free_client(struct nfs_client *clp)
275 dprintk("--> nfs_free_client(%u)\n", clp->rpc_ops->version);
277 nfs4_shutdown_client(clp);
279 nfs_fscache_release_client_cookie(clp);
281 /* -EIO all pending I/O */
282 if (!IS_ERR(clp->cl_rpcclient))
283 rpc_shutdown_client(clp->cl_rpcclient);
285 if (clp->cl_machine_cred != NULL)
286 put_rpccred(clp->cl_machine_cred);
288 kfree(clp->cl_hostname);
291 dprintk("<-- nfs_free_client()\n");
295 * Release a reference to a shared client record
297 void nfs_put_client(struct nfs_client *clp)
302 dprintk("--> nfs_put_client({%d})\n", atomic_read(&clp->cl_count));
304 if (atomic_dec_and_lock(&clp->cl_count, &nfs_client_lock)) {
305 list_del(&clp->cl_share_link);
306 nfs_cb_idr_remove_locked(clp);
307 spin_unlock(&nfs_client_lock);
309 BUG_ON(!list_empty(&clp->cl_superblocks));
311 nfs_free_client(clp);
314 EXPORT_SYMBOL_GPL(nfs_put_client);
316 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
318 * Test if two ip6 socket addresses refer to the same socket by
319 * comparing relevant fields. The padding bytes specifically, are not
320 * compared. sin6_flowinfo is not compared because it only affects QoS
321 * and sin6_scope_id is only compared if the address is "link local"
322 * because "link local" addresses need only be unique to a specific
323 * link. Conversely, ordinary unicast addresses might have different
326 * The caller should ensure both socket addresses are AF_INET6.
328 static int nfs_sockaddr_match_ipaddr6(const struct sockaddr *sa1,
329 const struct sockaddr *sa2)
331 const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sa1;
332 const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sa2;
334 if (ipv6_addr_scope(&sin1->sin6_addr) == IPV6_ADDR_SCOPE_LINKLOCAL &&
335 sin1->sin6_scope_id != sin2->sin6_scope_id)
338 return ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr);
340 #else /* !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE) */
341 static int nfs_sockaddr_match_ipaddr6(const struct sockaddr *sa1,
342 const struct sockaddr *sa2)
349 * Test if two ip4 socket addresses refer to the same socket, by
350 * comparing relevant fields. The padding bytes specifically, are
353 * The caller should ensure both socket addresses are AF_INET.
355 static int nfs_sockaddr_match_ipaddr4(const struct sockaddr *sa1,
356 const struct sockaddr *sa2)
358 const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sa1;
359 const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sa2;
361 return sin1->sin_addr.s_addr == sin2->sin_addr.s_addr;
364 static int nfs_sockaddr_cmp_ip6(const struct sockaddr *sa1,
365 const struct sockaddr *sa2)
367 const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sa1;
368 const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sa2;
370 return nfs_sockaddr_match_ipaddr6(sa1, sa2) &&
371 (sin1->sin6_port == sin2->sin6_port);
374 static int nfs_sockaddr_cmp_ip4(const struct sockaddr *sa1,
375 const struct sockaddr *sa2)
377 const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sa1;
378 const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sa2;
380 return nfs_sockaddr_match_ipaddr4(sa1, sa2) &&
381 (sin1->sin_port == sin2->sin_port);
385 * Test if two socket addresses represent the same actual socket,
386 * by comparing (only) relevant fields, excluding the port number.
388 static int nfs_sockaddr_match_ipaddr(const struct sockaddr *sa1,
389 const struct sockaddr *sa2)
391 if (sa1->sa_family != sa2->sa_family)
394 switch (sa1->sa_family) {
396 return nfs_sockaddr_match_ipaddr4(sa1, sa2);
398 return nfs_sockaddr_match_ipaddr6(sa1, sa2);
404 * Test if two socket addresses represent the same actual socket,
405 * by comparing (only) relevant fields, including the port number.
407 static int nfs_sockaddr_cmp(const struct sockaddr *sa1,
408 const struct sockaddr *sa2)
410 if (sa1->sa_family != sa2->sa_family)
413 switch (sa1->sa_family) {
415 return nfs_sockaddr_cmp_ip4(sa1, sa2);
417 return nfs_sockaddr_cmp_ip6(sa1, sa2);
422 /* Common match routine for v4.0 and v4.1 callback services */
424 nfs4_cb_match_client(const struct sockaddr *addr, struct nfs_client *clp,
427 struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr;
429 /* Don't match clients that failed to initialise */
430 if (!(clp->cl_cons_state == NFS_CS_READY ||
431 clp->cl_cons_state == NFS_CS_SESSION_INITING))
434 /* Match the version and minorversion */
435 if (clp->rpc_ops->version != 4 ||
436 clp->cl_minorversion != minorversion)
439 /* Match only the IP address, not the port number */
440 if (!nfs_sockaddr_match_ipaddr(addr, clap))
447 * Find an nfs_client on the list that matches the initialisation data
450 static struct nfs_client *nfs_match_client(const struct nfs_client_initdata *data)
452 struct nfs_client *clp;
453 const struct sockaddr *sap = data->addr;
455 list_for_each_entry(clp, &nfs_client_list, cl_share_link) {
456 const struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr;
457 /* Don't match clients that failed to initialise properly */
458 if (clp->cl_cons_state < 0)
461 /* Different NFS versions cannot share the same nfs_client */
462 if (clp->rpc_ops != data->rpc_ops)
465 if (clp->cl_proto != data->proto)
467 /* Match nfsv4 minorversion */
468 if (clp->cl_minorversion != data->minorversion)
470 /* Match the full socket address */
471 if (!nfs_sockaddr_cmp(sap, clap))
474 atomic_inc(&clp->cl_count);
481 * Look up a client by IP address and protocol version
482 * - creates a new record if one doesn't yet exist
484 static struct nfs_client *
485 nfs_get_client(const struct nfs_client_initdata *cl_init,
486 const struct rpc_timeout *timeparms,
488 rpc_authflavor_t authflavour,
491 struct nfs_client *clp, *new = NULL;
494 dprintk("--> nfs_get_client(%s,v%u)\n",
495 cl_init->hostname ?: "", cl_init->rpc_ops->version);
497 /* see if the client already exists */
499 spin_lock(&nfs_client_lock);
501 clp = nfs_match_client(cl_init);
507 spin_unlock(&nfs_client_lock);
509 new = nfs_alloc_client(cl_init);
510 } while (!IS_ERR(new));
512 dprintk("--> nfs_get_client() = %ld [failed]\n", PTR_ERR(new));
515 /* install a new client and return with it unready */
518 list_add(&clp->cl_share_link, &nfs_client_list);
519 spin_unlock(&nfs_client_lock);
521 error = cl_init->rpc_ops->init_client(clp, timeparms, ip_addr,
522 authflavour, noresvport);
525 return ERR_PTR(error);
527 dprintk("--> nfs_get_client() = %p [new]\n", clp);
530 /* found an existing client
531 * - make sure it's ready before returning
534 spin_unlock(&nfs_client_lock);
537 nfs_free_client(new);
539 error = wait_event_killable(nfs_client_active_wq,
540 clp->cl_cons_state < NFS_CS_INITING);
543 return ERR_PTR(-ERESTARTSYS);
546 if (clp->cl_cons_state < NFS_CS_READY) {
547 error = clp->cl_cons_state;
549 return ERR_PTR(error);
552 BUG_ON(clp->cl_cons_state != NFS_CS_READY);
554 dprintk("--> nfs_get_client() = %p [share]\n", clp);
559 * Mark a server as ready or failed
561 void nfs_mark_client_ready(struct nfs_client *clp, int state)
563 clp->cl_cons_state = state;
564 wake_up_all(&nfs_client_active_wq);
568 * With sessions, the client is not marked ready until after a
569 * successful EXCHANGE_ID and CREATE_SESSION.
571 * Map errors cl_cons_state errors to EPROTONOSUPPORT to indicate
572 * other versions of NFS can be tried.
574 int nfs4_check_client_ready(struct nfs_client *clp)
576 if (!nfs4_has_session(clp))
578 if (clp->cl_cons_state < NFS_CS_READY)
579 return -EPROTONOSUPPORT;
584 * Initialise the timeout values for a connection
586 static void nfs_init_timeout_values(struct rpc_timeout *to, int proto,
587 unsigned int timeo, unsigned int retrans)
589 to->to_initval = timeo * HZ / 10;
590 to->to_retries = retrans;
593 case XPRT_TRANSPORT_TCP:
594 case XPRT_TRANSPORT_RDMA:
595 if (to->to_retries == 0)
596 to->to_retries = NFS_DEF_TCP_RETRANS;
597 if (to->to_initval == 0)
598 to->to_initval = NFS_DEF_TCP_TIMEO * HZ / 10;
599 if (to->to_initval > NFS_MAX_TCP_TIMEOUT)
600 to->to_initval = NFS_MAX_TCP_TIMEOUT;
601 to->to_increment = to->to_initval;
602 to->to_maxval = to->to_initval + (to->to_increment * to->to_retries);
603 if (to->to_maxval > NFS_MAX_TCP_TIMEOUT)
604 to->to_maxval = NFS_MAX_TCP_TIMEOUT;
605 if (to->to_maxval < to->to_initval)
606 to->to_maxval = to->to_initval;
607 to->to_exponential = 0;
609 case XPRT_TRANSPORT_UDP:
610 if (to->to_retries == 0)
611 to->to_retries = NFS_DEF_UDP_RETRANS;
613 to->to_initval = NFS_DEF_UDP_TIMEO * HZ / 10;
614 if (to->to_initval > NFS_MAX_UDP_TIMEOUT)
615 to->to_initval = NFS_MAX_UDP_TIMEOUT;
616 to->to_maxval = NFS_MAX_UDP_TIMEOUT;
617 to->to_exponential = 1;
625 * Create an RPC client handle
627 static int nfs_create_rpc_client(struct nfs_client *clp,
628 const struct rpc_timeout *timeparms,
629 rpc_authflavor_t flavor,
630 int discrtry, int noresvport)
632 struct rpc_clnt *clnt = NULL;
633 struct rpc_create_args args = {
635 .protocol = clp->cl_proto,
636 .address = (struct sockaddr *)&clp->cl_addr,
637 .addrsize = clp->cl_addrlen,
638 .timeout = timeparms,
639 .servername = clp->cl_hostname,
640 .program = &nfs_program,
641 .version = clp->rpc_ops->version,
642 .authflavor = flavor,
646 args.flags |= RPC_CLNT_CREATE_DISCRTRY;
648 args.flags |= RPC_CLNT_CREATE_NONPRIVPORT;
650 if (!IS_ERR(clp->cl_rpcclient))
653 clnt = rpc_create(&args);
655 dprintk("%s: cannot create RPC client. Error = %ld\n",
656 __func__, PTR_ERR(clnt));
657 return PTR_ERR(clnt);
660 clp->cl_rpcclient = clnt;
665 * Version 2 or 3 client destruction
667 static void nfs_destroy_server(struct nfs_server *server)
669 if (!(server->flags & NFS_MOUNT_LOCAL_FLOCK) ||
670 !(server->flags & NFS_MOUNT_LOCAL_FCNTL))
671 nlmclnt_done(server->nlm_host);
675 * Version 2 or 3 lockd setup
677 static int nfs_start_lockd(struct nfs_server *server)
679 struct nlm_host *host;
680 struct nfs_client *clp = server->nfs_client;
681 struct nlmclnt_initdata nlm_init = {
682 .hostname = clp->cl_hostname,
683 .address = (struct sockaddr *)&clp->cl_addr,
684 .addrlen = clp->cl_addrlen,
685 .nfs_version = clp->rpc_ops->version,
686 .noresvport = server->flags & NFS_MOUNT_NORESVPORT ?
690 if (nlm_init.nfs_version > 3)
692 if ((server->flags & NFS_MOUNT_LOCAL_FLOCK) &&
693 (server->flags & NFS_MOUNT_LOCAL_FCNTL))
696 switch (clp->cl_proto) {
698 nlm_init.protocol = IPPROTO_TCP;
700 case XPRT_TRANSPORT_UDP:
701 nlm_init.protocol = IPPROTO_UDP;
704 host = nlmclnt_init(&nlm_init);
706 return PTR_ERR(host);
708 server->nlm_host = host;
709 server->destroy = nfs_destroy_server;
714 * Initialise an NFSv3 ACL client connection
716 #ifdef CONFIG_NFS_V3_ACL
717 static void nfs_init_server_aclclient(struct nfs_server *server)
719 if (server->nfs_client->rpc_ops->version != 3)
721 if (server->flags & NFS_MOUNT_NOACL)
724 server->client_acl = rpc_bind_new_program(server->client, &nfsacl_program, 3);
725 if (IS_ERR(server->client_acl))
728 /* No errors! Assume that Sun nfsacls are supported */
729 server->caps |= NFS_CAP_ACLS;
733 server->caps &= ~NFS_CAP_ACLS;
736 static inline void nfs_init_server_aclclient(struct nfs_server *server)
738 server->flags &= ~NFS_MOUNT_NOACL;
739 server->caps &= ~NFS_CAP_ACLS;
744 * Create a general RPC client
746 static int nfs_init_server_rpcclient(struct nfs_server *server,
747 const struct rpc_timeout *timeo,
748 rpc_authflavor_t pseudoflavour)
750 struct nfs_client *clp = server->nfs_client;
752 server->client = rpc_clone_client(clp->cl_rpcclient);
753 if (IS_ERR(server->client)) {
754 dprintk("%s: couldn't create rpc_client!\n", __func__);
755 return PTR_ERR(server->client);
758 memcpy(&server->client->cl_timeout_default,
760 sizeof(server->client->cl_timeout_default));
761 server->client->cl_timeout = &server->client->cl_timeout_default;
763 if (pseudoflavour != clp->cl_rpcclient->cl_auth->au_flavor) {
764 struct rpc_auth *auth;
766 auth = rpcauth_create(pseudoflavour, server->client);
768 dprintk("%s: couldn't create credcache!\n", __func__);
769 return PTR_ERR(auth);
772 server->client->cl_softrtry = 0;
773 if (server->flags & NFS_MOUNT_SOFT)
774 server->client->cl_softrtry = 1;
780 * Initialise an NFS2 or NFS3 client
782 int nfs_init_client(struct nfs_client *clp, const struct rpc_timeout *timeparms,
783 const char *ip_addr, rpc_authflavor_t authflavour,
788 if (clp->cl_cons_state == NFS_CS_READY) {
789 /* the client is already initialised */
790 dprintk("<-- nfs_init_client() = 0 [already %p]\n", clp);
795 * Create a client RPC handle for doing FSSTAT with UNIX auth only
796 * - RFC 2623, sec 2.3.2
798 error = nfs_create_rpc_client(clp, timeparms, RPC_AUTH_UNIX,
802 nfs_mark_client_ready(clp, NFS_CS_READY);
806 nfs_mark_client_ready(clp, error);
807 dprintk("<-- nfs_init_client() = xerror %d\n", error);
812 * Create a version 2 or 3 client
814 static int nfs_init_server(struct nfs_server *server,
815 const struct nfs_parsed_mount_data *data)
817 struct nfs_client_initdata cl_init = {
818 .hostname = data->nfs_server.hostname,
819 .addr = (const struct sockaddr *)&data->nfs_server.address,
820 .addrlen = data->nfs_server.addrlen,
821 .rpc_ops = &nfs_v2_clientops,
822 .proto = data->nfs_server.protocol,
824 struct rpc_timeout timeparms;
825 struct nfs_client *clp;
828 dprintk("--> nfs_init_server()\n");
831 if (data->version == 3)
832 cl_init.rpc_ops = &nfs_v3_clientops;
835 nfs_init_timeout_values(&timeparms, data->nfs_server.protocol,
836 data->timeo, data->retrans);
838 /* Allocate or find a client reference we can use */
839 clp = nfs_get_client(&cl_init, &timeparms, NULL, RPC_AUTH_UNIX,
840 data->flags & NFS_MOUNT_NORESVPORT);
842 dprintk("<-- nfs_init_server() = error %ld\n", PTR_ERR(clp));
846 server->nfs_client = clp;
848 /* Initialise the client representation from the mount data */
849 server->flags = data->flags;
850 server->options = data->options;
851 server->caps |= NFS_CAP_HARDLINKS|NFS_CAP_SYMLINKS|NFS_CAP_FILEID|
852 NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER|NFS_CAP_OWNER_GROUP|
853 NFS_CAP_ATIME|NFS_CAP_CTIME|NFS_CAP_MTIME;
856 server->rsize = nfs_block_size(data->rsize, NULL);
858 server->wsize = nfs_block_size(data->wsize, NULL);
860 server->acregmin = data->acregmin * HZ;
861 server->acregmax = data->acregmax * HZ;
862 server->acdirmin = data->acdirmin * HZ;
863 server->acdirmax = data->acdirmax * HZ;
865 /* Start lockd here, before we might error out */
866 error = nfs_start_lockd(server);
870 server->port = data->nfs_server.port;
872 error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]);
876 /* Preserve the values of mount_server-related mount options */
877 if (data->mount_server.addrlen) {
878 memcpy(&server->mountd_address, &data->mount_server.address,
879 data->mount_server.addrlen);
880 server->mountd_addrlen = data->mount_server.addrlen;
882 server->mountd_version = data->mount_server.version;
883 server->mountd_port = data->mount_server.port;
884 server->mountd_protocol = data->mount_server.protocol;
886 server->namelen = data->namlen;
887 /* Create a client RPC handle for the NFSv3 ACL management interface */
888 nfs_init_server_aclclient(server);
889 dprintk("<-- nfs_init_server() = 0 [new %p]\n", clp);
893 server->nfs_client = NULL;
895 dprintk("<-- nfs_init_server() = xerror %d\n", error);
900 * Load up the server record from information gained in an fsinfo record
902 static void nfs_server_set_fsinfo(struct nfs_server *server, struct nfs_fsinfo *fsinfo)
904 unsigned long max_rpc_payload;
906 /* Work out a lot of parameters */
907 if (server->rsize == 0)
908 server->rsize = nfs_block_size(fsinfo->rtpref, NULL);
909 if (server->wsize == 0)
910 server->wsize = nfs_block_size(fsinfo->wtpref, NULL);
912 if (fsinfo->rtmax >= 512 && server->rsize > fsinfo->rtmax)
913 server->rsize = nfs_block_size(fsinfo->rtmax, NULL);
914 if (fsinfo->wtmax >= 512 && server->wsize > fsinfo->wtmax)
915 server->wsize = nfs_block_size(fsinfo->wtmax, NULL);
917 max_rpc_payload = nfs_block_size(rpc_max_payload(server->client), NULL);
918 if (server->rsize > max_rpc_payload)
919 server->rsize = max_rpc_payload;
920 if (server->rsize > NFS_MAX_FILE_IO_SIZE)
921 server->rsize = NFS_MAX_FILE_IO_SIZE;
922 server->rpages = (server->rsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
924 server->backing_dev_info.name = "nfs";
925 server->backing_dev_info.ra_pages = server->rpages * NFS_MAX_READAHEAD;
927 if (server->wsize > max_rpc_payload)
928 server->wsize = max_rpc_payload;
929 if (server->wsize > NFS_MAX_FILE_IO_SIZE)
930 server->wsize = NFS_MAX_FILE_IO_SIZE;
931 server->wpages = (server->wsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
932 set_pnfs_layoutdriver(server, fsinfo->layouttype);
934 server->wtmult = nfs_block_bits(fsinfo->wtmult, NULL);
936 server->dtsize = nfs_block_size(fsinfo->dtpref, NULL);
937 if (server->dtsize > PAGE_CACHE_SIZE * NFS_MAX_READDIR_PAGES)
938 server->dtsize = PAGE_CACHE_SIZE * NFS_MAX_READDIR_PAGES;
939 if (server->dtsize > server->rsize)
940 server->dtsize = server->rsize;
942 if (server->flags & NFS_MOUNT_NOAC) {
943 server->acregmin = server->acregmax = 0;
944 server->acdirmin = server->acdirmax = 0;
947 server->maxfilesize = fsinfo->maxfilesize;
949 server->time_delta = fsinfo->time_delta;
951 /* We're airborne Set socket buffersize */
952 rpc_setbufsize(server->client, server->wsize + 100, server->rsize + 100);
956 * Probe filesystem information, including the FSID on v2/v3
958 static int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *mntfh, struct nfs_fattr *fattr)
960 struct nfs_fsinfo fsinfo;
961 struct nfs_client *clp = server->nfs_client;
964 dprintk("--> nfs_probe_fsinfo()\n");
966 if (clp->rpc_ops->set_capabilities != NULL) {
967 error = clp->rpc_ops->set_capabilities(server, mntfh);
972 fsinfo.fattr = fattr;
973 fsinfo.layouttype = 0;
974 error = clp->rpc_ops->fsinfo(server, mntfh, &fsinfo);
978 nfs_server_set_fsinfo(server, &fsinfo);
980 /* Get some general file system info */
981 if (server->namelen == 0) {
982 struct nfs_pathconf pathinfo;
984 pathinfo.fattr = fattr;
985 nfs_fattr_init(fattr);
987 if (clp->rpc_ops->pathconf(server, mntfh, &pathinfo) >= 0)
988 server->namelen = pathinfo.max_namelen;
991 dprintk("<-- nfs_probe_fsinfo() = 0\n");
995 dprintk("nfs_probe_fsinfo: error = %d\n", -error);
1000 * Copy useful information when duplicating a server record
1002 static void nfs_server_copy_userdata(struct nfs_server *target, struct nfs_server *source)
1004 target->flags = source->flags;
1005 target->rsize = source->rsize;
1006 target->wsize = source->wsize;
1007 target->acregmin = source->acregmin;
1008 target->acregmax = source->acregmax;
1009 target->acdirmin = source->acdirmin;
1010 target->acdirmax = source->acdirmax;
1011 target->caps = source->caps;
1012 target->options = source->options;
1015 static void nfs_server_insert_lists(struct nfs_server *server)
1017 struct nfs_client *clp = server->nfs_client;
1019 spin_lock(&nfs_client_lock);
1020 list_add_tail_rcu(&server->client_link, &clp->cl_superblocks);
1021 list_add_tail(&server->master_link, &nfs_volume_list);
1022 clear_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state);
1023 spin_unlock(&nfs_client_lock);
1027 static void nfs_server_remove_lists(struct nfs_server *server)
1029 struct nfs_client *clp = server->nfs_client;
1031 spin_lock(&nfs_client_lock);
1032 list_del_rcu(&server->client_link);
1033 if (clp && list_empty(&clp->cl_superblocks))
1034 set_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state);
1035 list_del(&server->master_link);
1036 spin_unlock(&nfs_client_lock);
1042 * Allocate and initialise a server record
1044 static struct nfs_server *nfs_alloc_server(void)
1046 struct nfs_server *server;
1048 server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL);
1052 server->client = server->client_acl = ERR_PTR(-EINVAL);
1054 /* Zero out the NFS state stuff */
1055 INIT_LIST_HEAD(&server->client_link);
1056 INIT_LIST_HEAD(&server->master_link);
1057 INIT_LIST_HEAD(&server->delegations);
1059 atomic_set(&server->active, 0);
1061 server->io_stats = nfs_alloc_iostats();
1062 if (!server->io_stats) {
1067 if (bdi_init(&server->backing_dev_info)) {
1068 nfs_free_iostats(server->io_stats);
1073 pnfs_init_server(server);
1079 * Free up a server record
1081 void nfs_free_server(struct nfs_server *server)
1083 dprintk("--> nfs_free_server()\n");
1085 nfs_server_remove_lists(server);
1086 unset_pnfs_layoutdriver(server);
1088 if (server->destroy != NULL)
1089 server->destroy(server);
1091 if (!IS_ERR(server->client_acl))
1092 rpc_shutdown_client(server->client_acl);
1093 if (!IS_ERR(server->client))
1094 rpc_shutdown_client(server->client);
1096 nfs_put_client(server->nfs_client);
1098 nfs_free_iostats(server->io_stats);
1099 bdi_destroy(&server->backing_dev_info);
1101 nfs_release_automount_timer();
1102 dprintk("<-- nfs_free_server()\n");
1106 * Create a version 2 or 3 volume record
1107 * - keyed on server and FSID
1109 struct nfs_server *nfs_create_server(const struct nfs_parsed_mount_data *data,
1110 struct nfs_fh *mntfh)
1112 struct nfs_server *server;
1113 struct nfs_fattr *fattr;
1116 server = nfs_alloc_server();
1118 return ERR_PTR(-ENOMEM);
1121 fattr = nfs_alloc_fattr();
1125 /* Get a client representation */
1126 error = nfs_init_server(server, data);
1130 BUG_ON(!server->nfs_client);
1131 BUG_ON(!server->nfs_client->rpc_ops);
1132 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
1134 /* Probe the root fh to retrieve its FSID */
1135 error = nfs_probe_fsinfo(server, mntfh, fattr);
1138 if (server->nfs_client->rpc_ops->version == 3) {
1139 if (server->namelen == 0 || server->namelen > NFS3_MAXNAMLEN)
1140 server->namelen = NFS3_MAXNAMLEN;
1141 if (!(data->flags & NFS_MOUNT_NORDIRPLUS))
1142 server->caps |= NFS_CAP_READDIRPLUS;
1144 if (server->namelen == 0 || server->namelen > NFS2_MAXNAMLEN)
1145 server->namelen = NFS2_MAXNAMLEN;
1148 if (!(fattr->valid & NFS_ATTR_FATTR)) {
1149 error = server->nfs_client->rpc_ops->getattr(server, mntfh, fattr);
1151 dprintk("nfs_create_server: getattr error = %d\n", -error);
1155 memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid));
1157 dprintk("Server FSID: %llx:%llx\n",
1158 (unsigned long long) server->fsid.major,
1159 (unsigned long long) server->fsid.minor);
1161 nfs_server_insert_lists(server);
1162 server->mount_time = jiffies;
1163 nfs_free_fattr(fattr);
1167 nfs_free_fattr(fattr);
1168 nfs_free_server(server);
1169 return ERR_PTR(error);
1172 #ifdef CONFIG_NFS_V4
1174 * NFSv4.0 callback thread helper
1176 * Find a client by IP address, protocol version, and minorversion
1178 * Called from the pg_authenticate method. The callback identifier
1179 * is not used as it has not been decoded.
1181 * Returns NULL if no such client
1184 nfs4_find_client_no_ident(const struct sockaddr *addr)
1186 struct nfs_client *clp;
1188 spin_lock(&nfs_client_lock);
1189 list_for_each_entry(clp, &nfs_client_list, cl_share_link) {
1190 if (nfs4_cb_match_client(addr, clp, 0) == false)
1192 atomic_inc(&clp->cl_count);
1193 spin_unlock(&nfs_client_lock);
1196 spin_unlock(&nfs_client_lock);
1201 * NFSv4.0 callback thread helper
1203 * Find a client by callback identifier
1206 nfs4_find_client_ident(int cb_ident)
1208 struct nfs_client *clp;
1210 spin_lock(&nfs_client_lock);
1211 clp = idr_find(&cb_ident_idr, cb_ident);
1213 atomic_inc(&clp->cl_count);
1214 spin_unlock(&nfs_client_lock);
1218 #if defined(CONFIG_NFS_V4_1)
1220 * NFSv4.1 callback thread helper
1221 * For CB_COMPOUND calls, find a client by IP address, protocol version,
1222 * minorversion, and sessionID
1224 * Returns NULL if no such client
1227 nfs4_find_client_sessionid(const struct sockaddr *addr,
1228 struct nfs4_sessionid *sid)
1230 struct nfs_client *clp;
1232 spin_lock(&nfs_client_lock);
1233 list_for_each_entry(clp, &nfs_client_list, cl_share_link) {
1234 if (nfs4_cb_match_client(addr, clp, 1) == false)
1237 if (!nfs4_has_session(clp))
1240 /* Match sessionid*/
1241 if (memcmp(clp->cl_session->sess_id.data,
1242 sid->data, NFS4_MAX_SESSIONID_LEN) != 0)
1245 atomic_inc(&clp->cl_count);
1246 spin_unlock(&nfs_client_lock);
1249 spin_unlock(&nfs_client_lock);
1253 #else /* CONFIG_NFS_V4_1 */
1256 nfs4_find_client_sessionid(const struct sockaddr *addr,
1257 struct nfs4_sessionid *sid)
1261 #endif /* CONFIG_NFS_V4_1 */
1264 * Initialize the NFS4 callback service
1266 static int nfs4_init_callback(struct nfs_client *clp)
1270 if (clp->rpc_ops->version == 4) {
1271 if (nfs4_has_session(clp)) {
1272 error = xprt_setup_backchannel(
1273 clp->cl_rpcclient->cl_xprt,
1274 NFS41_BC_MIN_CALLBACKS);
1279 error = nfs_callback_up(clp->cl_mvops->minor_version,
1280 clp->cl_rpcclient->cl_xprt);
1282 dprintk("%s: failed to start callback. Error = %d\n",
1286 __set_bit(NFS_CS_CALLBACK, &clp->cl_res_state);
1292 * Initialize the minor version specific parts of an NFS4 client record
1294 static int nfs4_init_client_minor_version(struct nfs_client *clp)
1296 #if defined(CONFIG_NFS_V4_1)
1297 if (clp->cl_mvops->minor_version) {
1298 struct nfs4_session *session = NULL;
1300 * Create the session and mark it expired.
1301 * When a SEQUENCE operation encounters the expired session
1302 * it will do session recovery to initialize it.
1304 session = nfs4_alloc_session(clp);
1308 clp->cl_session = session;
1310 * The create session reply races with the server back
1311 * channel probe. Mark the client NFS_CS_SESSION_INITING
1312 * so that the client back channel can find the
1315 clp->cl_cons_state = NFS_CS_SESSION_INITING;
1317 #endif /* CONFIG_NFS_V4_1 */
1319 return nfs4_init_callback(clp);
1323 * Initialise an NFS4 client record
1325 int nfs4_init_client(struct nfs_client *clp,
1326 const struct rpc_timeout *timeparms,
1327 const char *ip_addr,
1328 rpc_authflavor_t authflavour,
1333 if (clp->cl_cons_state == NFS_CS_READY) {
1334 /* the client is initialised already */
1335 dprintk("<-- nfs4_init_client() = 0 [already %p]\n", clp);
1339 /* Check NFS protocol revision and initialize RPC op vector */
1340 clp->rpc_ops = &nfs_v4_clientops;
1342 error = nfs_create_rpc_client(clp, timeparms, authflavour,
1346 strlcpy(clp->cl_ipaddr, ip_addr, sizeof(clp->cl_ipaddr));
1348 error = nfs_idmap_new(clp);
1350 dprintk("%s: failed to create idmapper. Error = %d\n",
1354 __set_bit(NFS_CS_IDMAP, &clp->cl_res_state);
1356 error = nfs4_init_client_minor_version(clp);
1360 if (!nfs4_has_session(clp))
1361 nfs_mark_client_ready(clp, NFS_CS_READY);
1365 nfs_mark_client_ready(clp, error);
1366 dprintk("<-- nfs4_init_client() = xerror %d\n", error);
1371 * Set up an NFS4 client
1373 static int nfs4_set_client(struct nfs_server *server,
1374 const char *hostname,
1375 const struct sockaddr *addr,
1376 const size_t addrlen,
1377 const char *ip_addr,
1378 rpc_authflavor_t authflavour,
1379 int proto, const struct rpc_timeout *timeparms,
1382 struct nfs_client_initdata cl_init = {
1383 .hostname = hostname,
1386 .rpc_ops = &nfs_v4_clientops,
1388 .minorversion = minorversion,
1390 struct nfs_client *clp;
1393 dprintk("--> nfs4_set_client()\n");
1395 /* Allocate or find a client reference we can use */
1396 clp = nfs_get_client(&cl_init, timeparms, ip_addr, authflavour,
1397 server->flags & NFS_MOUNT_NORESVPORT);
1399 error = PTR_ERR(clp);
1404 * Query for the lease time on clientid setup or renewal
1406 * Note that this will be set on nfs_clients that were created
1407 * only for the DS role and did not set this bit, but now will
1408 * serve a dual role.
1410 set_bit(NFS_CS_CHECK_LEASE_TIME, &clp->cl_res_state);
1412 server->nfs_client = clp;
1413 dprintk("<-- nfs4_set_client() = 0 [new %p]\n", clp);
1416 dprintk("<-- nfs4_set_client() = xerror %d\n", error);
1422 * Session has been established, and the client marked ready.
1423 * Set the mount rsize and wsize with negotiated fore channel
1424 * attributes which will be bound checked in nfs_server_set_fsinfo.
1426 static void nfs4_session_set_rwsize(struct nfs_server *server)
1428 #ifdef CONFIG_NFS_V4_1
1429 struct nfs4_session *sess;
1433 if (!nfs4_has_session(server->nfs_client))
1435 sess = server->nfs_client->cl_session;
1436 server_resp_sz = sess->fc_attrs.max_resp_sz - nfs41_maxread_overhead;
1437 server_rqst_sz = sess->fc_attrs.max_rqst_sz - nfs41_maxwrite_overhead;
1439 if (server->rsize > server_resp_sz)
1440 server->rsize = server_resp_sz;
1441 if (server->wsize > server_rqst_sz)
1442 server->wsize = server_rqst_sz;
1443 #endif /* CONFIG_NFS_V4_1 */
1446 static int nfs4_server_common_setup(struct nfs_server *server,
1447 struct nfs_fh *mntfh)
1449 struct nfs_fattr *fattr;
1452 BUG_ON(!server->nfs_client);
1453 BUG_ON(!server->nfs_client->rpc_ops);
1454 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
1456 /* data servers support only a subset of NFSv4.1 */
1457 if (is_ds_only_client(server->nfs_client))
1458 return -EPROTONOSUPPORT;
1460 fattr = nfs_alloc_fattr();
1464 /* We must ensure the session is initialised first */
1465 error = nfs4_init_session(server);
1469 /* Probe the root fh to retrieve its FSID and filehandle */
1470 error = nfs4_get_rootfh(server, mntfh);
1474 dprintk("Server FSID: %llx:%llx\n",
1475 (unsigned long long) server->fsid.major,
1476 (unsigned long long) server->fsid.minor);
1477 dprintk("Mount FH: %d\n", mntfh->size);
1479 nfs4_session_set_rwsize(server);
1481 error = nfs_probe_fsinfo(server, mntfh, fattr);
1485 if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN)
1486 server->namelen = NFS4_MAXNAMLEN;
1488 nfs_server_insert_lists(server);
1489 server->mount_time = jiffies;
1491 nfs_free_fattr(fattr);
1496 * Create a version 4 volume record
1498 static int nfs4_init_server(struct nfs_server *server,
1499 const struct nfs_parsed_mount_data *data)
1501 struct rpc_timeout timeparms;
1504 dprintk("--> nfs4_init_server()\n");
1506 nfs_init_timeout_values(&timeparms, data->nfs_server.protocol,
1507 data->timeo, data->retrans);
1509 /* Initialise the client representation from the mount data */
1510 server->flags = data->flags;
1511 server->caps |= NFS_CAP_ATOMIC_OPEN|NFS_CAP_CHANGE_ATTR|NFS_CAP_POSIX_LOCK;
1512 if (!(data->flags & NFS_MOUNT_NORDIRPLUS))
1513 server->caps |= NFS_CAP_READDIRPLUS;
1514 server->options = data->options;
1516 /* Get a client record */
1517 error = nfs4_set_client(server,
1518 data->nfs_server.hostname,
1519 (const struct sockaddr *)&data->nfs_server.address,
1520 data->nfs_server.addrlen,
1521 data->client_address,
1522 data->auth_flavors[0],
1523 data->nfs_server.protocol,
1525 data->minorversion);
1530 server->rsize = nfs_block_size(data->rsize, NULL);
1532 server->wsize = nfs_block_size(data->wsize, NULL);
1534 server->acregmin = data->acregmin * HZ;
1535 server->acregmax = data->acregmax * HZ;
1536 server->acdirmin = data->acdirmin * HZ;
1537 server->acdirmax = data->acdirmax * HZ;
1539 server->port = data->nfs_server.port;
1541 error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]);
1545 dprintk("<-- nfs4_init_server() = %d\n", error);
1550 * Create a version 4 volume record
1551 * - keyed on server and FSID
1553 struct nfs_server *nfs4_create_server(const struct nfs_parsed_mount_data *data,
1554 struct nfs_fh *mntfh)
1556 struct nfs_server *server;
1559 dprintk("--> nfs4_create_server()\n");
1561 server = nfs_alloc_server();
1563 return ERR_PTR(-ENOMEM);
1565 /* set up the general RPC client */
1566 error = nfs4_init_server(server, data);
1570 error = nfs4_server_common_setup(server, mntfh);
1574 dprintk("<-- nfs4_create_server() = %p\n", server);
1578 nfs_free_server(server);
1579 dprintk("<-- nfs4_create_server() = error %d\n", error);
1580 return ERR_PTR(error);
1584 * Create an NFS4 referral server record
1586 struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data,
1587 struct nfs_fh *mntfh)
1589 struct nfs_client *parent_client;
1590 struct nfs_server *server, *parent_server;
1593 dprintk("--> nfs4_create_referral_server()\n");
1595 server = nfs_alloc_server();
1597 return ERR_PTR(-ENOMEM);
1599 parent_server = NFS_SB(data->sb);
1600 parent_client = parent_server->nfs_client;
1602 /* Initialise the client representation from the parent server */
1603 nfs_server_copy_userdata(server, parent_server);
1604 server->caps |= NFS_CAP_ATOMIC_OPEN|NFS_CAP_CHANGE_ATTR;
1606 /* Get a client representation.
1607 * Note: NFSv4 always uses TCP, */
1608 error = nfs4_set_client(server, data->hostname,
1611 parent_client->cl_ipaddr,
1613 parent_server->client->cl_xprt->prot,
1614 parent_server->client->cl_timeout,
1615 parent_client->cl_mvops->minor_version);
1619 error = nfs_init_server_rpcclient(server, parent_server->client->cl_timeout, data->authflavor);
1623 error = nfs4_server_common_setup(server, mntfh);
1627 dprintk("<-- nfs_create_referral_server() = %p\n", server);
1631 nfs_free_server(server);
1632 dprintk("<-- nfs4_create_referral_server() = error %d\n", error);
1633 return ERR_PTR(error);
1636 #endif /* CONFIG_NFS_V4 */
1639 * Clone an NFS2, NFS3 or NFS4 server record
1641 struct nfs_server *nfs_clone_server(struct nfs_server *source,
1643 struct nfs_fattr *fattr)
1645 struct nfs_server *server;
1646 struct nfs_fattr *fattr_fsinfo;
1649 dprintk("--> nfs_clone_server(,%llx:%llx,)\n",
1650 (unsigned long long) fattr->fsid.major,
1651 (unsigned long long) fattr->fsid.minor);
1653 server = nfs_alloc_server();
1655 return ERR_PTR(-ENOMEM);
1658 fattr_fsinfo = nfs_alloc_fattr();
1659 if (fattr_fsinfo == NULL)
1660 goto out_free_server;
1662 /* Copy data from the source */
1663 server->nfs_client = source->nfs_client;
1664 atomic_inc(&server->nfs_client->cl_count);
1665 nfs_server_copy_userdata(server, source);
1667 server->fsid = fattr->fsid;
1669 error = nfs_init_server_rpcclient(server,
1670 source->client->cl_timeout,
1671 source->client->cl_auth->au_flavor);
1673 goto out_free_server;
1674 if (!IS_ERR(source->client_acl))
1675 nfs_init_server_aclclient(server);
1677 /* probe the filesystem info for this server filesystem */
1678 error = nfs_probe_fsinfo(server, fh, fattr_fsinfo);
1680 goto out_free_server;
1682 if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN)
1683 server->namelen = NFS4_MAXNAMLEN;
1685 dprintk("Cloned FSID: %llx:%llx\n",
1686 (unsigned long long) server->fsid.major,
1687 (unsigned long long) server->fsid.minor);
1689 error = nfs_start_lockd(server);
1691 goto out_free_server;
1693 nfs_server_insert_lists(server);
1694 server->mount_time = jiffies;
1696 nfs_free_fattr(fattr_fsinfo);
1697 dprintk("<-- nfs_clone_server() = %p\n", server);
1701 nfs_free_fattr(fattr_fsinfo);
1702 nfs_free_server(server);
1703 dprintk("<-- nfs_clone_server() = error %d\n", error);
1704 return ERR_PTR(error);
1707 #ifdef CONFIG_PROC_FS
1708 static struct proc_dir_entry *proc_fs_nfs;
1710 static int nfs_server_list_open(struct inode *inode, struct file *file);
1711 static void *nfs_server_list_start(struct seq_file *p, loff_t *pos);
1712 static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos);
1713 static void nfs_server_list_stop(struct seq_file *p, void *v);
1714 static int nfs_server_list_show(struct seq_file *m, void *v);
1716 static const struct seq_operations nfs_server_list_ops = {
1717 .start = nfs_server_list_start,
1718 .next = nfs_server_list_next,
1719 .stop = nfs_server_list_stop,
1720 .show = nfs_server_list_show,
1723 static const struct file_operations nfs_server_list_fops = {
1724 .open = nfs_server_list_open,
1726 .llseek = seq_lseek,
1727 .release = seq_release,
1728 .owner = THIS_MODULE,
1731 static int nfs_volume_list_open(struct inode *inode, struct file *file);
1732 static void *nfs_volume_list_start(struct seq_file *p, loff_t *pos);
1733 static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos);
1734 static void nfs_volume_list_stop(struct seq_file *p, void *v);
1735 static int nfs_volume_list_show(struct seq_file *m, void *v);
1737 static const struct seq_operations nfs_volume_list_ops = {
1738 .start = nfs_volume_list_start,
1739 .next = nfs_volume_list_next,
1740 .stop = nfs_volume_list_stop,
1741 .show = nfs_volume_list_show,
1744 static const struct file_operations nfs_volume_list_fops = {
1745 .open = nfs_volume_list_open,
1747 .llseek = seq_lseek,
1748 .release = seq_release,
1749 .owner = THIS_MODULE,
1753 * open "/proc/fs/nfsfs/servers" which provides a summary of servers with which
1756 static int nfs_server_list_open(struct inode *inode, struct file *file)
1761 ret = seq_open(file, &nfs_server_list_ops);
1765 m = file->private_data;
1766 m->private = PDE(inode)->data;
1772 * set up the iterator to start reading from the server list and return the first item
1774 static void *nfs_server_list_start(struct seq_file *m, loff_t *_pos)
1776 /* lock the list against modification */
1777 spin_lock(&nfs_client_lock);
1778 return seq_list_start_head(&nfs_client_list, *_pos);
1782 * move to next server
1784 static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos)
1786 return seq_list_next(v, &nfs_client_list, pos);
1790 * clean up after reading from the transports list
1792 static void nfs_server_list_stop(struct seq_file *p, void *v)
1794 spin_unlock(&nfs_client_lock);
1798 * display a header line followed by a load of call lines
1800 static int nfs_server_list_show(struct seq_file *m, void *v)
1802 struct nfs_client *clp;
1804 /* display header on line 1 */
1805 if (v == &nfs_client_list) {
1806 seq_puts(m, "NV SERVER PORT USE HOSTNAME\n");
1810 /* display one transport per line on subsequent lines */
1811 clp = list_entry(v, struct nfs_client, cl_share_link);
1813 seq_printf(m, "v%u %s %s %3d %s\n",
1814 clp->rpc_ops->version,
1815 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR),
1816 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT),
1817 atomic_read(&clp->cl_count),
1824 * open "/proc/fs/nfsfs/volumes" which provides a summary of extant volumes
1826 static int nfs_volume_list_open(struct inode *inode, struct file *file)
1831 ret = seq_open(file, &nfs_volume_list_ops);
1835 m = file->private_data;
1836 m->private = PDE(inode)->data;
1842 * set up the iterator to start reading from the volume list and return the first item
1844 static void *nfs_volume_list_start(struct seq_file *m, loff_t *_pos)
1846 /* lock the list against modification */
1847 spin_lock(&nfs_client_lock);
1848 return seq_list_start_head(&nfs_volume_list, *_pos);
1852 * move to next volume
1854 static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos)
1856 return seq_list_next(v, &nfs_volume_list, pos);
1860 * clean up after reading from the transports list
1862 static void nfs_volume_list_stop(struct seq_file *p, void *v)
1864 spin_unlock(&nfs_client_lock);
1868 * display a header line followed by a load of call lines
1870 static int nfs_volume_list_show(struct seq_file *m, void *v)
1872 struct nfs_server *server;
1873 struct nfs_client *clp;
1874 char dev[8], fsid[17];
1876 /* display header on line 1 */
1877 if (v == &nfs_volume_list) {
1878 seq_puts(m, "NV SERVER PORT DEV FSID FSC\n");
1881 /* display one transport per line on subsequent lines */
1882 server = list_entry(v, struct nfs_server, master_link);
1883 clp = server->nfs_client;
1885 snprintf(dev, 8, "%u:%u",
1886 MAJOR(server->s_dev), MINOR(server->s_dev));
1888 snprintf(fsid, 17, "%llx:%llx",
1889 (unsigned long long) server->fsid.major,
1890 (unsigned long long) server->fsid.minor);
1892 seq_printf(m, "v%u %s %s %-7s %-17s %s\n",
1893 clp->rpc_ops->version,
1894 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR),
1895 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT),
1898 nfs_server_fscache_state(server));
1904 * initialise the /proc/fs/nfsfs/ directory
1906 int __init nfs_fs_proc_init(void)
1908 struct proc_dir_entry *p;
1910 proc_fs_nfs = proc_mkdir("fs/nfsfs", NULL);
1914 /* a file of servers with which we're dealing */
1915 p = proc_create("servers", S_IFREG|S_IRUGO,
1916 proc_fs_nfs, &nfs_server_list_fops);
1920 /* a file of volumes that we have mounted */
1921 p = proc_create("volumes", S_IFREG|S_IRUGO,
1922 proc_fs_nfs, &nfs_volume_list_fops);
1928 remove_proc_entry("servers", proc_fs_nfs);
1930 remove_proc_entry("fs/nfsfs", NULL);
1936 * clean up the /proc/fs/nfsfs/ directory
1938 void nfs_fs_proc_exit(void)
1940 remove_proc_entry("volumes", proc_fs_nfs);
1941 remove_proc_entry("servers", proc_fs_nfs);
1942 remove_proc_entry("fs/nfsfs", NULL);
1945 #endif /* CONFIG_PROC_FS */