blob: 684b67771199051a9b97c988e0bde39069d37bd8 [file] [log] [blame]
David Howells24c8dbb2006-08-22 20:06:10 -04001/* client.c: NFS client sharing and management code
2 *
3 * Copyright (C) 2006 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12
David Howells24c8dbb2006-08-22 20:06:10 -040013#include <linux/module.h>
14#include <linux/init.h>
Alexey Dobriyane8edc6e2007-05-21 01:22:52 +040015#include <linux/sched.h>
David Howells24c8dbb2006-08-22 20:06:10 -040016#include <linux/time.h>
17#include <linux/kernel.h>
18#include <linux/mm.h>
19#include <linux/string.h>
20#include <linux/stat.h>
21#include <linux/errno.h>
22#include <linux/unistd.h>
23#include <linux/sunrpc/clnt.h>
24#include <linux/sunrpc/stats.h>
25#include <linux/sunrpc/metrics.h>
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -040026#include <linux/sunrpc/xprtsock.h>
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040027#include <linux/sunrpc/xprtrdma.h>
David Howells24c8dbb2006-08-22 20:06:10 -040028#include <linux/nfs_fs.h>
29#include <linux/nfs_mount.h>
30#include <linux/nfs4_mount.h>
31#include <linux/lockd/bind.h>
David Howells24c8dbb2006-08-22 20:06:10 -040032#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>
Trond Myklebust3b0d3f92008-01-03 13:28:58 -050037#include <linux/in6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090038#include <linux/slab.h>
Trond Myklebust3b0d3f92008-01-03 13:28:58 -050039#include <net/ipv6.h>
David Howells24c8dbb2006-08-22 20:06:10 -040040#include <linux/nfs_xdr.h>
Andy Adamson0b5b7ae2009-04-01 09:23:15 -040041#include <linux/sunrpc/bc_xprt.h>
David Howells24c8dbb2006-08-22 20:06:10 -040042
43#include <asm/system.h>
44
45#include "nfs4_fs.h"
46#include "callback.h"
47#include "delegation.h"
48#include "iostat.h"
49#include "internal.h"
David Howells14727282009-04-03 16:42:42 +010050#include "fscache.h"
Ricardo Labiaga85e174b2010-10-20 00:17:58 -040051#include "pnfs.h"
David Howells24c8dbb2006-08-22 20:06:10 -040052
53#define NFSDBG_FACILITY NFSDBG_CLIENT
54
55static DEFINE_SPINLOCK(nfs_client_lock);
56static LIST_HEAD(nfs_client_list);
David Howells54ceac42006-08-22 20:06:13 -040057static LIST_HEAD(nfs_volume_list);
David Howells24c8dbb2006-08-22 20:06:10 -040058static DECLARE_WAIT_QUEUE_HEAD(nfs_client_active_wq);
Andy Adamsonf4eecd52011-01-06 02:04:30 +000059#ifdef CONFIG_NFS_V4
60static DEFINE_IDR(cb_ident_idr); /* Protected by nfs_client_lock */
61
62/*
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
65 */
66static int nfs_get_cb_ident_idr(struct nfs_client *clp, int minorversion)
67{
68 int ret = 0;
69
70 if (clp->rpc_ops->version != 4 || minorversion != 0)
71 return ret;
72retry:
73 if (!idr_pre_get(&cb_ident_idr, GFP_KERNEL))
74 return -ENOMEM;
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);
78 if (ret == -EAGAIN)
79 goto retry;
80 return ret;
81}
82#endif /* CONFIG_NFS_V4 */
David Howells24c8dbb2006-08-22 20:06:10 -040083
84/*
David Howells5006a762006-08-22 20:06:12 -040085 * RPC cruft for NFS
86 */
87static struct rpc_version *nfs_version[5] = {
88 [2] = &nfs_version2,
89#ifdef CONFIG_NFS_V3
90 [3] = &nfs_version3,
91#endif
92#ifdef CONFIG_NFS_V4
93 [4] = &nfs_version4,
94#endif
95};
96
97struct rpc_program nfs_program = {
98 .name = "nfs",
99 .number = NFS_PROGRAM,
100 .nrvers = ARRAY_SIZE(nfs_version),
101 .version = nfs_version,
102 .stats = &nfs_rpcstat,
103 .pipe_dir_name = "/nfs",
104};
105
106struct rpc_stat nfs_rpcstat = {
107 .program = &nfs_program
108};
109
110
111#ifdef CONFIG_NFS_V3_ACL
112static struct rpc_stat nfsacl_rpcstat = { &nfsacl_program };
113static struct rpc_version * nfsacl_version[] = {
114 [3] = &nfsacl_version3,
115};
116
117struct rpc_program nfsacl_program = {
118 .name = "nfsacl",
119 .number = NFS_ACL_PROGRAM,
120 .nrvers = ARRAY_SIZE(nfsacl_version),
121 .version = nfsacl_version,
122 .stats = &nfsacl_rpcstat,
123};
124#endif /* CONFIG_NFS_V3_ACL */
125
Trond Myklebust3a498022007-12-14 14:56:04 -0500126struct nfs_client_initdata {
127 const char *hostname;
Chuck Leverd7422c42007-12-10 14:58:51 -0500128 const struct sockaddr *addr;
Chuck Lever6e4cffd2007-12-10 14:58:15 -0500129 size_t addrlen;
Trond Myklebust40c553192007-12-14 14:56:07 -0500130 const struct nfs_rpc_ops *rpc_ops;
Trond Myklebust59dca3b2008-01-03 16:29:06 -0500131 int proto;
Benny Halevy5aae4a92009-04-01 09:21:50 -0400132 u32 minorversion;
Trond Myklebust3a498022007-12-14 14:56:04 -0500133};
134
David Howells5006a762006-08-22 20:06:12 -0400135/*
David Howells24c8dbb2006-08-22 20:06:10 -0400136 * Allocate a shared client record
137 *
138 * Since these are allocated/deallocated very rarely, we don't
139 * bother putting them in a slab cache...
140 */
Trond Myklebust3a498022007-12-14 14:56:04 -0500141static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init)
David Howells24c8dbb2006-08-22 20:06:10 -0400142{
143 struct nfs_client *clp;
Trond Myklebust7c67db32008-04-07 20:50:11 -0400144 struct rpc_cred *cred;
Chuck Levera21bdd92009-06-17 18:02:10 -0700145 int err = -ENOMEM;
David Howells24c8dbb2006-08-22 20:06:10 -0400146
147 if ((clp = kzalloc(sizeof(*clp), GFP_KERNEL)) == NULL)
148 goto error_0;
149
Trond Myklebust40c553192007-12-14 14:56:07 -0500150 clp->rpc_ops = cl_init->rpc_ops;
151
David Howells24c8dbb2006-08-22 20:06:10 -0400152 atomic_set(&clp->cl_count, 1);
153 clp->cl_cons_state = NFS_CS_INITING;
154
Chuck Lever6e4cffd2007-12-10 14:58:15 -0500155 memcpy(&clp->cl_addr, cl_init->addr, cl_init->addrlen);
156 clp->cl_addrlen = cl_init->addrlen;
David Howells24c8dbb2006-08-22 20:06:10 -0400157
Trond Myklebust3a498022007-12-14 14:56:04 -0500158 if (cl_init->hostname) {
Chuck Levera21bdd92009-06-17 18:02:10 -0700159 err = -ENOMEM;
Trond Myklebust3a498022007-12-14 14:56:04 -0500160 clp->cl_hostname = kstrdup(cl_init->hostname, GFP_KERNEL);
David Howells24c8dbb2006-08-22 20:06:10 -0400161 if (!clp->cl_hostname)
Benny Halevy71468512009-04-01 09:22:56 -0400162 goto error_cleanup;
David Howells24c8dbb2006-08-22 20:06:10 -0400163 }
164
165 INIT_LIST_HEAD(&clp->cl_superblocks);
166 clp->cl_rpcclient = ERR_PTR(-EINVAL);
167
Trond Myklebust59dca3b2008-01-03 16:29:06 -0500168 clp->cl_proto = cl_init->proto;
169
David Howells24c8dbb2006-08-22 20:06:10 -0400170#ifdef CONFIG_NFS_V4
Andy Adamsonf4eecd52011-01-06 02:04:30 +0000171 err = nfs_get_cb_ident_idr(clp, cl_init->minorversion);
172 if (err)
173 goto error_cleanup;
174
David Howells24c8dbb2006-08-22 20:06:10 -0400175 INIT_LIST_HEAD(&clp->cl_delegations);
David Howells24c8dbb2006-08-22 20:06:10 -0400176 spin_lock_init(&clp->cl_lock);
David Howells65f27f32006-11-22 14:55:48 +0000177 INIT_DELAYED_WORK(&clp->cl_renewd, nfs4_renew_state);
David Howells24c8dbb2006-08-22 20:06:10 -0400178 rpc_init_wait_queue(&clp->cl_rpcwaitq, "NFS client");
179 clp->cl_boot_time = CURRENT_TIME;
180 clp->cl_state = 1 << NFS4CLNT_LEASE_EXPIRED;
Benny Halevy5aae4a92009-04-01 09:21:50 -0400181 clp->cl_minorversion = cl_init->minorversion;
Trond Myklebust97dc1352010-06-16 09:52:26 -0400182 clp->cl_mvops = nfs_v4_minor_ops[cl_init->minorversion];
David Howells24c8dbb2006-08-22 20:06:10 -0400183#endif
Trond Myklebust7c67db32008-04-07 20:50:11 -0400184 cred = rpc_lookup_machine_cred();
185 if (!IS_ERR(cred))
186 clp->cl_machine_cred = cred;
Andy Adamson974cec82010-10-20 00:18:02 -0400187#if defined(CONFIG_NFS_V4_1)
188 INIT_LIST_HEAD(&clp->cl_layouts);
189#endif
David Howells14727282009-04-03 16:42:42 +0100190 nfs_fscache_get_client_cookie(clp);
191
David Howells24c8dbb2006-08-22 20:06:10 -0400192 return clp;
193
Benny Halevy71468512009-04-01 09:22:56 -0400194error_cleanup:
David Howells24c8dbb2006-08-22 20:06:10 -0400195 kfree(clp);
196error_0:
Chuck Levera21bdd92009-06-17 18:02:10 -0700197 return ERR_PTR(err);
David Howells24c8dbb2006-08-22 20:06:10 -0400198}
199
Trond Myklebust5dd31772006-08-24 01:03:05 -0400200#ifdef CONFIG_NFS_V4
Andy Adamson557134a2009-04-01 09:21:53 -0400201#ifdef CONFIG_NFS_V4_1
Andy Adamsonea005282011-01-06 02:04:29 +0000202static void nfs4_shutdown_session(struct nfs_client *clp)
203{
204 if (nfs4_has_session(clp))
Andy Adamson557134a2009-04-01 09:21:53 -0400205 nfs4_destroy_session(clp->cl_session);
Andy Adamson557134a2009-04-01 09:21:53 -0400206}
Andy Adamsonea005282011-01-06 02:04:29 +0000207#else /* CONFIG_NFS_V4_1 */
208static void nfs4_shutdown_session(struct nfs_client *clp)
209{
210}
211#endif /* CONFIG_NFS_V4_1 */
Andy Adamson557134a2009-04-01 09:21:53 -0400212
213/*
Alexandros Batsakis888ef2e2010-02-05 03:45:03 -0800214 * Destroy the NFS4 callback service
215 */
216static void nfs4_destroy_callback(struct nfs_client *clp)
217{
218 if (__test_and_clear_bit(NFS_CS_CALLBACK, &clp->cl_res_state))
Trond Myklebust97dc1352010-06-16 09:52:26 -0400219 nfs_callback_down(clp->cl_mvops->minor_version);
Alexandros Batsakis888ef2e2010-02-05 03:45:03 -0800220}
221
222static void nfs4_shutdown_client(struct nfs_client *clp)
223{
224 if (__test_and_clear_bit(NFS_CS_RENEWD, &clp->cl_res_state))
225 nfs4_kill_renewd(clp);
Andy Adamsonea005282011-01-06 02:04:29 +0000226 nfs4_shutdown_session(clp);
Alexandros Batsakis888ef2e2010-02-05 03:45:03 -0800227 nfs4_destroy_callback(clp);
228 if (__test_and_clear_bit(NFS_CS_IDMAP, &clp->cl_res_state))
229 nfs_idmap_delete(clp);
230
231 rpc_destroy_wait_queue(&clp->cl_rpcwaitq);
232}
Andy Adamsonf4eecd52011-01-06 02:04:30 +0000233
234/* idr_remove_all is not needed as all id's are removed by nfs_put_client */
235void nfs_cleanup_cb_ident_idr(void)
236{
237 idr_destroy(&cb_ident_idr);
238}
239
240/* nfs_client_lock held */
241static void nfs_cb_idr_remove_locked(struct nfs_client *clp)
242{
243 if (clp->cl_cb_ident)
244 idr_remove(&cb_ident_idr, clp->cl_cb_ident);
245}
246
Fred Isamanf7e89172011-01-06 11:36:32 +0000247static void pnfs_init_server(struct nfs_server *server)
248{
249 rpc_init_wait_queue(&server->roc_rpcwaitq, "pNFS ROC");
250}
251
Alexandros Batsakis888ef2e2010-02-05 03:45:03 -0800252#else
253static void nfs4_shutdown_client(struct nfs_client *clp)
254{
255}
Andy Adamsonf4eecd52011-01-06 02:04:30 +0000256
257void nfs_cleanup_cb_ident_idr(void)
258{
259}
260
261static void nfs_cb_idr_remove_locked(struct nfs_client *clp)
262{
263}
Fred Isamanf7e89172011-01-06 11:36:32 +0000264
265static void pnfs_init_server(struct nfs_server *server)
266{
267}
268
Alexandros Batsakis888ef2e2010-02-05 03:45:03 -0800269#endif /* CONFIG_NFS_V4 */
270
271/*
David Howells24c8dbb2006-08-22 20:06:10 -0400272 * Destroy a shared client record
273 */
274static void nfs_free_client(struct nfs_client *clp)
275{
Trond Myklebust40c553192007-12-14 14:56:07 -0500276 dprintk("--> nfs_free_client(%u)\n", clp->rpc_ops->version);
David Howells24c8dbb2006-08-22 20:06:10 -0400277
Trond Myklebust5dd31772006-08-24 01:03:05 -0400278 nfs4_shutdown_client(clp);
David Howells24c8dbb2006-08-22 20:06:10 -0400279
David Howells14727282009-04-03 16:42:42 +0100280 nfs_fscache_release_client_cookie(clp);
281
David Howells24c8dbb2006-08-22 20:06:10 -0400282 /* -EIO all pending I/O */
283 if (!IS_ERR(clp->cl_rpcclient))
284 rpc_shutdown_client(clp->cl_rpcclient);
285
Trond Myklebust7c67db32008-04-07 20:50:11 -0400286 if (clp->cl_machine_cred != NULL)
287 put_rpccred(clp->cl_machine_cred);
288
David Howells24c8dbb2006-08-22 20:06:10 -0400289 kfree(clp->cl_hostname);
290 kfree(clp);
291
292 dprintk("<-- nfs_free_client()\n");
293}
294
295/*
296 * Release a reference to a shared client record
297 */
298void nfs_put_client(struct nfs_client *clp)
299{
David Howells27ba8512006-07-30 14:40:56 -0400300 if (!clp)
301 return;
302
David Howells24c8dbb2006-08-22 20:06:10 -0400303 dprintk("--> nfs_put_client({%d})\n", atomic_read(&clp->cl_count));
304
305 if (atomic_dec_and_lock(&clp->cl_count, &nfs_client_lock)) {
306 list_del(&clp->cl_share_link);
Andy Adamsonf4eecd52011-01-06 02:04:30 +0000307 nfs_cb_idr_remove_locked(clp);
David Howells24c8dbb2006-08-22 20:06:10 -0400308 spin_unlock(&nfs_client_lock);
309
310 BUG_ON(!list_empty(&clp->cl_superblocks));
311
312 nfs_free_client(clp);
313 }
314}
Andy Adamson16b374c2010-10-20 00:18:04 -0400315EXPORT_SYMBOL_GPL(nfs_put_client);
David Howells24c8dbb2006-08-22 20:06:10 -0400316
Trond Myklebust9082a5c2008-12-23 15:21:53 -0500317#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
Trond Myklebust9f4c8992009-03-12 14:51:32 -0400318/*
319 * Test if two ip6 socket addresses refer to the same socket by
320 * comparing relevant fields. The padding bytes specifically, are not
321 * compared. sin6_flowinfo is not compared because it only affects QoS
322 * and sin6_scope_id is only compared if the address is "link local"
323 * because "link local" addresses need only be unique to a specific
324 * link. Conversely, ordinary unicast addresses might have different
325 * sin6_scope_id.
326 *
327 * The caller should ensure both socket addresses are AF_INET6.
328 */
Chuck Lever3c8c45d2009-03-18 20:48:14 -0400329static int nfs_sockaddr_match_ipaddr6(const struct sockaddr *sa1,
330 const struct sockaddr *sa2)
Trond Myklebust9f4c8992009-03-12 14:51:32 -0400331{
Chuck Lever3c8c45d2009-03-18 20:48:14 -0400332 const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sa1;
333 const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sa2;
Trond Myklebust9f4c8992009-03-12 14:51:32 -0400334
Chuck Lever3c8c45d2009-03-18 20:48:14 -0400335 if (ipv6_addr_scope(&sin1->sin6_addr) == IPV6_ADDR_SCOPE_LINKLOCAL &&
336 sin1->sin6_scope_id != sin2->sin6_scope_id)
Trond Myklebust9f4c8992009-03-12 14:51:32 -0400337 return 0;
Trond Myklebust3b0d3f92008-01-03 13:28:58 -0500338
Trond Myklebustb20d37c2010-09-12 19:55:26 -0400339 return ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr);
Trond Myklebust3b0d3f92008-01-03 13:28:58 -0500340}
Chuck Lever3c8c45d2009-03-18 20:48:14 -0400341#else /* !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE) */
342static int nfs_sockaddr_match_ipaddr6(const struct sockaddr *sa1,
343 const struct sockaddr *sa2)
Trond Myklebust9f4c8992009-03-12 14:51:32 -0400344{
345 return 0;
346}
Trond Myklebust9082a5c2008-12-23 15:21:53 -0500347#endif
Trond Myklebust3b0d3f92008-01-03 13:28:58 -0500348
David Howells24c8dbb2006-08-22 20:06:10 -0400349/*
Ian Dalld7371c42009-03-10 20:33:22 -0400350 * Test if two ip4 socket addresses refer to the same socket, by
351 * comparing relevant fields. The padding bytes specifically, are
352 * not compared.
353 *
354 * The caller should ensure both socket addresses are AF_INET.
355 */
Chuck Lever3c8c45d2009-03-18 20:48:14 -0400356static int nfs_sockaddr_match_ipaddr4(const struct sockaddr *sa1,
357 const struct sockaddr *sa2)
358{
359 const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sa1;
360 const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sa2;
361
362 return sin1->sin_addr.s_addr == sin2->sin_addr.s_addr;
363}
364
365static int nfs_sockaddr_cmp_ip6(const struct sockaddr *sa1,
366 const struct sockaddr *sa2)
367{
368 const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sa1;
369 const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sa2;
370
371 return nfs_sockaddr_match_ipaddr6(sa1, sa2) &&
372 (sin1->sin6_port == sin2->sin6_port);
373}
374
Trond Myklebust9f4c8992009-03-12 14:51:32 -0400375static int nfs_sockaddr_cmp_ip4(const struct sockaddr *sa1,
376 const struct sockaddr *sa2)
Ian Dalld7371c42009-03-10 20:33:22 -0400377{
Chuck Lever3c8c45d2009-03-18 20:48:14 -0400378 const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sa1;
379 const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sa2;
Trond Myklebust9f4c8992009-03-12 14:51:32 -0400380
Chuck Lever3c8c45d2009-03-18 20:48:14 -0400381 return nfs_sockaddr_match_ipaddr4(sa1, sa2) &&
382 (sin1->sin_port == sin2->sin_port);
Ian Dalld7371c42009-03-10 20:33:22 -0400383}
384
385/*
Ian Dalld7371c42009-03-10 20:33:22 -0400386 * Test if two socket addresses represent the same actual socket,
Chuck Lever3c8c45d2009-03-18 20:48:14 -0400387 * by comparing (only) relevant fields, excluding the port number.
388 */
389static int nfs_sockaddr_match_ipaddr(const struct sockaddr *sa1,
390 const struct sockaddr *sa2)
391{
392 if (sa1->sa_family != sa2->sa_family)
393 return 0;
394
395 switch (sa1->sa_family) {
396 case AF_INET:
397 return nfs_sockaddr_match_ipaddr4(sa1, sa2);
398 case AF_INET6:
399 return nfs_sockaddr_match_ipaddr6(sa1, sa2);
400 }
401 return 0;
402}
403
404/*
405 * Test if two socket addresses represent the same actual socket,
406 * by comparing (only) relevant fields, including the port number.
Ian Dalld7371c42009-03-10 20:33:22 -0400407 */
408static int nfs_sockaddr_cmp(const struct sockaddr *sa1,
409 const struct sockaddr *sa2)
410{
411 if (sa1->sa_family != sa2->sa_family)
412 return 0;
413
414 switch (sa1->sa_family) {
415 case AF_INET:
Trond Myklebust9f4c8992009-03-12 14:51:32 -0400416 return nfs_sockaddr_cmp_ip4(sa1, sa2);
Ian Dalld7371c42009-03-10 20:33:22 -0400417 case AF_INET6:
Trond Myklebust9f4c8992009-03-12 14:51:32 -0400418 return nfs_sockaddr_cmp_ip6(sa1, sa2);
Ian Dalld7371c42009-03-10 20:33:22 -0400419 }
420 return 0;
421}
422
Andy Adamsonc36fca52011-01-06 02:04:32 +0000423/* Common match routine for v4.0 and v4.1 callback services */
424bool
425nfs4_cb_match_client(const struct sockaddr *addr, struct nfs_client *clp,
426 u32 minorversion)
Trond Myklebustc81468a2007-12-14 14:56:05 -0500427{
Andy Adamsonc36fca52011-01-06 02:04:32 +0000428 struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr;
Trond Myklebustc81468a2007-12-14 14:56:05 -0500429
Andy Adamsonc36fca52011-01-06 02:04:32 +0000430 /* Don't match clients that failed to initialise */
431 if (!(clp->cl_cons_state == NFS_CS_READY ||
432 clp->cl_cons_state == NFS_CS_SESSION_INITING))
433 return false;
Trond Myklebust3b0d3f92008-01-03 13:28:58 -0500434
Andy Adamsonc36fca52011-01-06 02:04:32 +0000435 /* Match the version and minorversion */
436 if (clp->rpc_ops->version != 4 ||
437 clp->cl_minorversion != minorversion)
438 return false;
Trond Myklebustc81468a2007-12-14 14:56:05 -0500439
Andy Adamsonc36fca52011-01-06 02:04:32 +0000440 /* Match only the IP address, not the port number */
441 if (!nfs_sockaddr_match_ipaddr(addr, clap))
442 return false;
Trond Myklebustc81468a2007-12-14 14:56:05 -0500443
Andy Adamsonc36fca52011-01-06 02:04:32 +0000444 return true;
Trond Myklebust3fbd67a2008-01-26 01:06:40 -0500445}
446
447/*
Trond Myklebustc81468a2007-12-14 14:56:05 -0500448 * Find an nfs_client on the list that matches the initialisation data
449 * that is supplied.
450 */
451static struct nfs_client *nfs_match_client(const struct nfs_client_initdata *data)
David Howells24c8dbb2006-08-22 20:06:10 -0400452{
453 struct nfs_client *clp;
Ian Dalld7371c42009-03-10 20:33:22 -0400454 const struct sockaddr *sap = data->addr;
David Howells24c8dbb2006-08-22 20:06:10 -0400455
456 list_for_each_entry(clp, &nfs_client_list, cl_share_link) {
Ian Dalld7371c42009-03-10 20:33:22 -0400457 const struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr;
Trond Myklebust13bbc062006-10-19 23:28:40 -0700458 /* Don't match clients that failed to initialise properly */
459 if (clp->cl_cons_state < 0)
460 continue;
461
David Howells24c8dbb2006-08-22 20:06:10 -0400462 /* Different NFS versions cannot share the same nfs_client */
Trond Myklebust40c553192007-12-14 14:56:07 -0500463 if (clp->rpc_ops != data->rpc_ops)
David Howells24c8dbb2006-08-22 20:06:10 -0400464 continue;
465
Trond Myklebust59dca3b2008-01-03 16:29:06 -0500466 if (clp->cl_proto != data->proto)
467 continue;
Benny Halevy5aae4a92009-04-01 09:21:50 -0400468 /* Match nfsv4 minorversion */
469 if (clp->cl_minorversion != data->minorversion)
470 continue;
Trond Myklebustc81468a2007-12-14 14:56:05 -0500471 /* Match the full socket address */
Ian Dalld7371c42009-03-10 20:33:22 -0400472 if (!nfs_sockaddr_cmp(sap, clap))
David Howells24c8dbb2006-08-22 20:06:10 -0400473 continue;
474
Trond Myklebustc81468a2007-12-14 14:56:05 -0500475 atomic_inc(&clp->cl_count);
476 return clp;
David Howells24c8dbb2006-08-22 20:06:10 -0400477 }
David Howells24c8dbb2006-08-22 20:06:10 -0400478 return NULL;
David Howells24c8dbb2006-08-22 20:06:10 -0400479}
480
481/*
482 * Look up a client by IP address and protocol version
483 * - creates a new record if one doesn't yet exist
484 */
Trond Myklebust3a498022007-12-14 14:56:04 -0500485static struct nfs_client *nfs_get_client(const struct nfs_client_initdata *cl_init)
David Howells24c8dbb2006-08-22 20:06:10 -0400486{
487 struct nfs_client *clp, *new = NULL;
488 int error;
489
Chuck Leverd7422c42007-12-10 14:58:51 -0500490 dprintk("--> nfs_get_client(%s,v%u)\n",
491 cl_init->hostname ?: "", cl_init->rpc_ops->version);
David Howells24c8dbb2006-08-22 20:06:10 -0400492
493 /* see if the client already exists */
494 do {
495 spin_lock(&nfs_client_lock);
496
Trond Myklebustc81468a2007-12-14 14:56:05 -0500497 clp = nfs_match_client(cl_init);
David Howells24c8dbb2006-08-22 20:06:10 -0400498 if (clp)
499 goto found_client;
500 if (new)
501 goto install_client;
502
503 spin_unlock(&nfs_client_lock);
504
Trond Myklebust3a498022007-12-14 14:56:04 -0500505 new = nfs_alloc_client(cl_init);
Chuck Levera21bdd92009-06-17 18:02:10 -0700506 } while (!IS_ERR(new));
David Howells24c8dbb2006-08-22 20:06:10 -0400507
Chuck Levera21bdd92009-06-17 18:02:10 -0700508 dprintk("--> nfs_get_client() = %ld [failed]\n", PTR_ERR(new));
509 return new;
David Howells24c8dbb2006-08-22 20:06:10 -0400510
511 /* install a new client and return with it unready */
512install_client:
513 clp = new;
514 list_add(&clp->cl_share_link, &nfs_client_list);
515 spin_unlock(&nfs_client_lock);
516 dprintk("--> nfs_get_client() = %p [new]\n", clp);
517 return clp;
518
519 /* found an existing client
520 * - make sure it's ready before returning
521 */
522found_client:
523 spin_unlock(&nfs_client_lock);
524
525 if (new)
526 nfs_free_client(new);
527
Matthew Wilcox150030b2007-12-06 16:24:39 -0500528 error = wait_event_killable(nfs_client_active_wq,
Andy Adamson76db6d92009-04-01 09:22:38 -0400529 clp->cl_cons_state < NFS_CS_INITING);
Trond Myklebust0bae89e2006-10-08 14:33:24 -0400530 if (error < 0) {
531 nfs_put_client(clp);
532 return ERR_PTR(-ERESTARTSYS);
David Howells24c8dbb2006-08-22 20:06:10 -0400533 }
534
535 if (clp->cl_cons_state < NFS_CS_READY) {
536 error = clp->cl_cons_state;
537 nfs_put_client(clp);
538 return ERR_PTR(error);
539 }
540
David Howells54ceac42006-08-22 20:06:13 -0400541 BUG_ON(clp->cl_cons_state != NFS_CS_READY);
542
David Howells24c8dbb2006-08-22 20:06:10 -0400543 dprintk("--> nfs_get_client() = %p [share]\n", clp);
544 return clp;
545}
546
547/*
548 * Mark a server as ready or failed
549 */
Andy Adamson76db6d92009-04-01 09:22:38 -0400550void nfs_mark_client_ready(struct nfs_client *clp, int state)
David Howells24c8dbb2006-08-22 20:06:10 -0400551{
552 clp->cl_cons_state = state;
553 wake_up_all(&nfs_client_active_wq);
554}
David Howells5006a762006-08-22 20:06:12 -0400555
556/*
Benny Halevy008f55d2009-04-01 09:22:50 -0400557 * With sessions, the client is not marked ready until after a
558 * successful EXCHANGE_ID and CREATE_SESSION.
559 *
560 * Map errors cl_cons_state errors to EPROTONOSUPPORT to indicate
561 * other versions of NFS can be tried.
562 */
563int nfs4_check_client_ready(struct nfs_client *clp)
564{
565 if (!nfs4_has_session(clp))
566 return 0;
567 if (clp->cl_cons_state < NFS_CS_READY)
568 return -EPROTONOSUPPORT;
569 return 0;
570}
571
572/*
David Howells5006a762006-08-22 20:06:12 -0400573 * Initialise the timeout values for a connection
574 */
575static void nfs_init_timeout_values(struct rpc_timeout *to, int proto,
576 unsigned int timeo, unsigned int retrans)
577{
578 to->to_initval = timeo * HZ / 10;
579 to->to_retries = retrans;
David Howells5006a762006-08-22 20:06:12 -0400580
581 switch (proto) {
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400582 case XPRT_TRANSPORT_TCP:
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400583 case XPRT_TRANSPORT_RDMA:
Trond Myklebust259875e2008-07-02 14:43:47 -0400584 if (to->to_retries == 0)
585 to->to_retries = NFS_DEF_TCP_RETRANS;
Trond Myklebust7a3e3e12007-12-20 16:03:57 -0500586 if (to->to_initval == 0)
Trond Myklebust259875e2008-07-02 14:43:47 -0400587 to->to_initval = NFS_DEF_TCP_TIMEO * HZ / 10;
David Howells5006a762006-08-22 20:06:12 -0400588 if (to->to_initval > NFS_MAX_TCP_TIMEOUT)
589 to->to_initval = NFS_MAX_TCP_TIMEOUT;
590 to->to_increment = to->to_initval;
591 to->to_maxval = to->to_initval + (to->to_increment * to->to_retries);
Trond Myklebust7a3e3e12007-12-20 16:03:57 -0500592 if (to->to_maxval > NFS_MAX_TCP_TIMEOUT)
593 to->to_maxval = NFS_MAX_TCP_TIMEOUT;
594 if (to->to_maxval < to->to_initval)
595 to->to_maxval = to->to_initval;
David Howells5006a762006-08-22 20:06:12 -0400596 to->to_exponential = 0;
597 break;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400598 case XPRT_TRANSPORT_UDP:
Trond Myklebust259875e2008-07-02 14:43:47 -0400599 if (to->to_retries == 0)
600 to->to_retries = NFS_DEF_UDP_RETRANS;
David Howells5006a762006-08-22 20:06:12 -0400601 if (!to->to_initval)
Trond Myklebust259875e2008-07-02 14:43:47 -0400602 to->to_initval = NFS_DEF_UDP_TIMEO * HZ / 10;
David Howells5006a762006-08-22 20:06:12 -0400603 if (to->to_initval > NFS_MAX_UDP_TIMEOUT)
604 to->to_initval = NFS_MAX_UDP_TIMEOUT;
605 to->to_maxval = NFS_MAX_UDP_TIMEOUT;
606 to->to_exponential = 1;
607 break;
Trond Myklebust259875e2008-07-02 14:43:47 -0400608 default:
609 BUG();
David Howells5006a762006-08-22 20:06:12 -0400610 }
611}
612
613/*
614 * Create an RPC client handle
615 */
Trond Myklebust59dca3b2008-01-03 16:29:06 -0500616static int nfs_create_rpc_client(struct nfs_client *clp,
Trond Myklebust33170232007-12-20 16:03:59 -0500617 const struct rpc_timeout *timeparms,
618 rpc_authflavor_t flavor,
Chuck Lever4a01b8a2008-12-23 15:21:35 -0500619 int discrtry, int noresvport)
David Howells5006a762006-08-22 20:06:12 -0400620{
David Howells5006a762006-08-22 20:06:12 -0400621 struct rpc_clnt *clnt = NULL;
Chuck Lever41877d22006-08-22 20:06:20 -0400622 struct rpc_create_args args = {
Pavel Emelyanovc653ce32010-09-29 16:04:45 +0400623 .net = &init_net,
Trond Myklebust59dca3b2008-01-03 16:29:06 -0500624 .protocol = clp->cl_proto,
Chuck Lever41877d22006-08-22 20:06:20 -0400625 .address = (struct sockaddr *)&clp->cl_addr,
Chuck Lever6e4cffd2007-12-10 14:58:15 -0500626 .addrsize = clp->cl_addrlen,
Trond Myklebust33170232007-12-20 16:03:59 -0500627 .timeout = timeparms,
Chuck Lever41877d22006-08-22 20:06:20 -0400628 .servername = clp->cl_hostname,
629 .program = &nfs_program,
630 .version = clp->rpc_ops->version,
631 .authflavor = flavor,
632 };
David Howells5006a762006-08-22 20:06:12 -0400633
Chuck Lever4a01b8a2008-12-23 15:21:35 -0500634 if (discrtry)
635 args.flags |= RPC_CLNT_CREATE_DISCRTRY;
636 if (noresvport)
637 args.flags |= RPC_CLNT_CREATE_NONPRIVPORT;
638
David Howells5006a762006-08-22 20:06:12 -0400639 if (!IS_ERR(clp->cl_rpcclient))
640 return 0;
641
Chuck Lever41877d22006-08-22 20:06:20 -0400642 clnt = rpc_create(&args);
David Howells5006a762006-08-22 20:06:12 -0400643 if (IS_ERR(clnt)) {
644 dprintk("%s: cannot create RPC client. Error = %ld\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -0700645 __func__, PTR_ERR(clnt));
David Howells5006a762006-08-22 20:06:12 -0400646 return PTR_ERR(clnt);
647 }
648
David Howells5006a762006-08-22 20:06:12 -0400649 clp->cl_rpcclient = clnt;
650 return 0;
651}
David Howells54ceac42006-08-22 20:06:13 -0400652
653/*
654 * Version 2 or 3 client destruction
655 */
656static void nfs_destroy_server(struct nfs_server *server)
657{
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400658 if (!(server->flags & NFS_MOUNT_LOCAL_FLOCK) ||
659 !(server->flags & NFS_MOUNT_LOCAL_FCNTL))
Chuck Lever9289e7f2008-01-11 17:09:52 -0500660 nlmclnt_done(server->nlm_host);
David Howells54ceac42006-08-22 20:06:13 -0400661}
662
663/*
664 * Version 2 or 3 lockd setup
665 */
666static int nfs_start_lockd(struct nfs_server *server)
667{
Chuck Lever9289e7f2008-01-11 17:09:52 -0500668 struct nlm_host *host;
669 struct nfs_client *clp = server->nfs_client;
Chuck Lever883bb162008-01-15 16:04:20 -0500670 struct nlmclnt_initdata nlm_init = {
671 .hostname = clp->cl_hostname,
672 .address = (struct sockaddr *)&clp->cl_addr,
673 .addrlen = clp->cl_addrlen,
Chuck Lever883bb162008-01-15 16:04:20 -0500674 .nfs_version = clp->rpc_ops->version,
Chuck Lever0cb26592008-12-23 15:21:38 -0500675 .noresvport = server->flags & NFS_MOUNT_NORESVPORT ?
676 1 : 0,
Chuck Lever883bb162008-01-15 16:04:20 -0500677 };
David Howells54ceac42006-08-22 20:06:13 -0400678
Chuck Lever883bb162008-01-15 16:04:20 -0500679 if (nlm_init.nfs_version > 3)
Chuck Lever9289e7f2008-01-11 17:09:52 -0500680 return 0;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400681 if ((server->flags & NFS_MOUNT_LOCAL_FLOCK) &&
682 (server->flags & NFS_MOUNT_LOCAL_FCNTL))
Chuck Lever9289e7f2008-01-11 17:09:52 -0500683 return 0;
684
Trond Myklebust8a6e5de2009-09-23 14:36:37 -0400685 switch (clp->cl_proto) {
686 default:
687 nlm_init.protocol = IPPROTO_TCP;
688 break;
689 case XPRT_TRANSPORT_UDP:
690 nlm_init.protocol = IPPROTO_UDP;
691 }
692
Chuck Lever883bb162008-01-15 16:04:20 -0500693 host = nlmclnt_init(&nlm_init);
Chuck Lever9289e7f2008-01-11 17:09:52 -0500694 if (IS_ERR(host))
695 return PTR_ERR(host);
696
697 server->nlm_host = host;
698 server->destroy = nfs_destroy_server;
699 return 0;
David Howells54ceac42006-08-22 20:06:13 -0400700}
701
702/*
703 * Initialise an NFSv3 ACL client connection
704 */
705#ifdef CONFIG_NFS_V3_ACL
706static void nfs_init_server_aclclient(struct nfs_server *server)
707{
Trond Myklebust40c553192007-12-14 14:56:07 -0500708 if (server->nfs_client->rpc_ops->version != 3)
David Howells54ceac42006-08-22 20:06:13 -0400709 goto out_noacl;
710 if (server->flags & NFS_MOUNT_NOACL)
711 goto out_noacl;
712
713 server->client_acl = rpc_bind_new_program(server->client, &nfsacl_program, 3);
714 if (IS_ERR(server->client_acl))
715 goto out_noacl;
716
717 /* No errors! Assume that Sun nfsacls are supported */
718 server->caps |= NFS_CAP_ACLS;
719 return;
720
721out_noacl:
722 server->caps &= ~NFS_CAP_ACLS;
723}
724#else
725static inline void nfs_init_server_aclclient(struct nfs_server *server)
726{
727 server->flags &= ~NFS_MOUNT_NOACL;
728 server->caps &= ~NFS_CAP_ACLS;
729}
730#endif
731
732/*
733 * Create a general RPC client
734 */
Trond Myklebust33170232007-12-20 16:03:59 -0500735static int nfs_init_server_rpcclient(struct nfs_server *server,
736 const struct rpc_timeout *timeo,
737 rpc_authflavor_t pseudoflavour)
David Howells54ceac42006-08-22 20:06:13 -0400738{
739 struct nfs_client *clp = server->nfs_client;
740
741 server->client = rpc_clone_client(clp->cl_rpcclient);
742 if (IS_ERR(server->client)) {
Harvey Harrison3110ff82008-05-02 13:42:44 -0700743 dprintk("%s: couldn't create rpc_client!\n", __func__);
David Howells54ceac42006-08-22 20:06:13 -0400744 return PTR_ERR(server->client);
745 }
746
Trond Myklebust33170232007-12-20 16:03:59 -0500747 memcpy(&server->client->cl_timeout_default,
748 timeo,
749 sizeof(server->client->cl_timeout_default));
750 server->client->cl_timeout = &server->client->cl_timeout_default;
751
David Howells54ceac42006-08-22 20:06:13 -0400752 if (pseudoflavour != clp->cl_rpcclient->cl_auth->au_flavor) {
753 struct rpc_auth *auth;
754
755 auth = rpcauth_create(pseudoflavour, server->client);
756 if (IS_ERR(auth)) {
Harvey Harrison3110ff82008-05-02 13:42:44 -0700757 dprintk("%s: couldn't create credcache!\n", __func__);
David Howells54ceac42006-08-22 20:06:13 -0400758 return PTR_ERR(auth);
759 }
760 }
761 server->client->cl_softrtry = 0;
762 if (server->flags & NFS_MOUNT_SOFT)
763 server->client->cl_softrtry = 1;
764
David Howells54ceac42006-08-22 20:06:13 -0400765 return 0;
766}
767
768/*
769 * Initialise an NFS2 or NFS3 client
770 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -0400771static int nfs_init_client(struct nfs_client *clp,
Trond Myklebust33170232007-12-20 16:03:59 -0500772 const struct rpc_timeout *timeparms,
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -0400773 const struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -0400774{
David Howells54ceac42006-08-22 20:06:13 -0400775 int error;
776
777 if (clp->cl_cons_state == NFS_CS_READY) {
778 /* the client is already initialised */
779 dprintk("<-- nfs_init_client() = 0 [already %p]\n", clp);
780 return 0;
781 }
782
David Howells54ceac42006-08-22 20:06:13 -0400783 /*
784 * Create a client RPC handle for doing FSSTAT with UNIX auth only
785 * - RFC 2623, sec 2.3.2
786 */
Chuck Leverd7403512008-12-23 15:21:37 -0500787 error = nfs_create_rpc_client(clp, timeparms, RPC_AUTH_UNIX,
788 0, data->flags & NFS_MOUNT_NORESVPORT);
David Howells54ceac42006-08-22 20:06:13 -0400789 if (error < 0)
790 goto error;
791 nfs_mark_client_ready(clp, NFS_CS_READY);
792 return 0;
793
794error:
795 nfs_mark_client_ready(clp, error);
796 dprintk("<-- nfs_init_client() = xerror %d\n", error);
797 return error;
798}
799
800/*
801 * Create a version 2 or 3 client
802 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -0400803static int nfs_init_server(struct nfs_server *server,
804 const struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -0400805{
Trond Myklebust3a498022007-12-14 14:56:04 -0500806 struct nfs_client_initdata cl_init = {
807 .hostname = data->nfs_server.hostname,
Chuck Leverd7422c42007-12-10 14:58:51 -0500808 .addr = (const struct sockaddr *)&data->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -0500809 .addrlen = data->nfs_server.addrlen,
Trond Myklebust40c553192007-12-14 14:56:07 -0500810 .rpc_ops = &nfs_v2_clientops,
Trond Myklebust59dca3b2008-01-03 16:29:06 -0500811 .proto = data->nfs_server.protocol,
Trond Myklebust3a498022007-12-14 14:56:04 -0500812 };
Trond Myklebust33170232007-12-20 16:03:59 -0500813 struct rpc_timeout timeparms;
David Howells54ceac42006-08-22 20:06:13 -0400814 struct nfs_client *clp;
Trond Myklebust3a498022007-12-14 14:56:04 -0500815 int error;
David Howells54ceac42006-08-22 20:06:13 -0400816
817 dprintk("--> nfs_init_server()\n");
818
819#ifdef CONFIG_NFS_V3
Trond Myklebust8a6e5de2009-09-23 14:36:37 -0400820 if (data->version == 3)
Trond Myklebust40c553192007-12-14 14:56:07 -0500821 cl_init.rpc_ops = &nfs_v3_clientops;
David Howells54ceac42006-08-22 20:06:13 -0400822#endif
823
824 /* Allocate or find a client reference we can use */
Trond Myklebust3a498022007-12-14 14:56:04 -0500825 clp = nfs_get_client(&cl_init);
David Howells54ceac42006-08-22 20:06:13 -0400826 if (IS_ERR(clp)) {
827 dprintk("<-- nfs_init_server() = error %ld\n", PTR_ERR(clp));
828 return PTR_ERR(clp);
829 }
830
Trond Myklebust33170232007-12-20 16:03:59 -0500831 nfs_init_timeout_values(&timeparms, data->nfs_server.protocol,
832 data->timeo, data->retrans);
833 error = nfs_init_client(clp, &timeparms, data);
David Howells54ceac42006-08-22 20:06:13 -0400834 if (error < 0)
835 goto error;
836
837 server->nfs_client = clp;
838
839 /* Initialise the client representation from the mount data */
Trond Myklebustff3525a2008-08-15 16:59:14 -0400840 server->flags = data->flags;
David Howellsb797cac2009-04-03 16:42:48 +0100841 server->options = data->options;
Trond Myklebust62ab460c2009-08-09 15:06:19 -0400842 server->caps |= NFS_CAP_HARDLINKS|NFS_CAP_SYMLINKS|NFS_CAP_FILEID|
843 NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER|NFS_CAP_OWNER_GROUP|
844 NFS_CAP_ATIME|NFS_CAP_CTIME|NFS_CAP_MTIME;
David Howells54ceac42006-08-22 20:06:13 -0400845
846 if (data->rsize)
847 server->rsize = nfs_block_size(data->rsize, NULL);
848 if (data->wsize)
849 server->wsize = nfs_block_size(data->wsize, NULL);
850
851 server->acregmin = data->acregmin * HZ;
852 server->acregmax = data->acregmax * HZ;
853 server->acdirmin = data->acdirmin * HZ;
854 server->acdirmax = data->acdirmax * HZ;
855
856 /* Start lockd here, before we might error out */
857 error = nfs_start_lockd(server);
858 if (error < 0)
859 goto error;
860
Chuck Leverf22d6d72008-03-14 14:10:22 -0400861 server->port = data->nfs_server.port;
862
Trond Myklebust33170232007-12-20 16:03:59 -0500863 error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]);
David Howells54ceac42006-08-22 20:06:13 -0400864 if (error < 0)
865 goto error;
866
Chuck Lever3f8400d2008-03-14 14:10:30 -0400867 /* Preserve the values of mount_server-related mount options */
868 if (data->mount_server.addrlen) {
869 memcpy(&server->mountd_address, &data->mount_server.address,
870 data->mount_server.addrlen);
871 server->mountd_addrlen = data->mount_server.addrlen;
872 }
873 server->mountd_version = data->mount_server.version;
874 server->mountd_port = data->mount_server.port;
875 server->mountd_protocol = data->mount_server.protocol;
876
David Howells54ceac42006-08-22 20:06:13 -0400877 server->namelen = data->namlen;
878 /* Create a client RPC handle for the NFSv3 ACL management interface */
879 nfs_init_server_aclclient(server);
David Howells54ceac42006-08-22 20:06:13 -0400880 dprintk("<-- nfs_init_server() = 0 [new %p]\n", clp);
881 return 0;
882
883error:
884 server->nfs_client = NULL;
885 nfs_put_client(clp);
886 dprintk("<-- nfs_init_server() = xerror %d\n", error);
887 return error;
888}
889
890/*
891 * Load up the server record from information gained in an fsinfo record
892 */
893static void nfs_server_set_fsinfo(struct nfs_server *server, struct nfs_fsinfo *fsinfo)
894{
895 unsigned long max_rpc_payload;
896
897 /* Work out a lot of parameters */
898 if (server->rsize == 0)
899 server->rsize = nfs_block_size(fsinfo->rtpref, NULL);
900 if (server->wsize == 0)
901 server->wsize = nfs_block_size(fsinfo->wtpref, NULL);
902
903 if (fsinfo->rtmax >= 512 && server->rsize > fsinfo->rtmax)
904 server->rsize = nfs_block_size(fsinfo->rtmax, NULL);
905 if (fsinfo->wtmax >= 512 && server->wsize > fsinfo->wtmax)
906 server->wsize = nfs_block_size(fsinfo->wtmax, NULL);
907
908 max_rpc_payload = nfs_block_size(rpc_max_payload(server->client), NULL);
909 if (server->rsize > max_rpc_payload)
910 server->rsize = max_rpc_payload;
911 if (server->rsize > NFS_MAX_FILE_IO_SIZE)
912 server->rsize = NFS_MAX_FILE_IO_SIZE;
913 server->rpages = (server->rsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
Peter Zijlstrae0bf68d2007-10-16 23:25:46 -0700914
Jens Axboed9938312009-06-12 14:45:52 +0200915 server->backing_dev_info.name = "nfs";
David Howells54ceac42006-08-22 20:06:13 -0400916 server->backing_dev_info.ra_pages = server->rpages * NFS_MAX_READAHEAD;
917
918 if (server->wsize > max_rpc_payload)
919 server->wsize = max_rpc_payload;
920 if (server->wsize > NFS_MAX_FILE_IO_SIZE)
921 server->wsize = NFS_MAX_FILE_IO_SIZE;
922 server->wpages = (server->wsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
Ricardo Labiaga85e174b2010-10-20 00:17:58 -0400923 set_pnfs_layoutdriver(server, fsinfo->layouttype);
924
David Howells54ceac42006-08-22 20:06:13 -0400925 server->wtmult = nfs_block_bits(fsinfo->wtmult, NULL);
926
927 server->dtsize = nfs_block_size(fsinfo->dtpref, NULL);
Bryan Schumaker56e4ebf2010-10-20 15:44:37 -0400928 if (server->dtsize > PAGE_CACHE_SIZE * NFS_MAX_READDIR_PAGES)
929 server->dtsize = PAGE_CACHE_SIZE * NFS_MAX_READDIR_PAGES;
David Howells54ceac42006-08-22 20:06:13 -0400930 if (server->dtsize > server->rsize)
931 server->dtsize = server->rsize;
932
933 if (server->flags & NFS_MOUNT_NOAC) {
934 server->acregmin = server->acregmax = 0;
935 server->acdirmin = server->acdirmax = 0;
936 }
937
938 server->maxfilesize = fsinfo->maxfilesize;
939
Ricardo Labiaga6b967242010-10-12 16:30:05 -0700940 server->time_delta = fsinfo->time_delta;
941
David Howells54ceac42006-08-22 20:06:13 -0400942 /* We're airborne Set socket buffersize */
943 rpc_setbufsize(server->client, server->wsize + 100, server->rsize + 100);
944}
945
946/*
947 * Probe filesystem information, including the FSID on v2/v3
948 */
949static int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *mntfh, struct nfs_fattr *fattr)
950{
951 struct nfs_fsinfo fsinfo;
952 struct nfs_client *clp = server->nfs_client;
953 int error;
954
955 dprintk("--> nfs_probe_fsinfo()\n");
956
957 if (clp->rpc_ops->set_capabilities != NULL) {
958 error = clp->rpc_ops->set_capabilities(server, mntfh);
959 if (error < 0)
960 goto out_error;
961 }
962
963 fsinfo.fattr = fattr;
Ricardo Labiaga85e174b2010-10-20 00:17:58 -0400964 fsinfo.layouttype = 0;
David Howells54ceac42006-08-22 20:06:13 -0400965 error = clp->rpc_ops->fsinfo(server, mntfh, &fsinfo);
966 if (error < 0)
967 goto out_error;
968
969 nfs_server_set_fsinfo(server, &fsinfo);
970
971 /* Get some general file system info */
972 if (server->namelen == 0) {
973 struct nfs_pathconf pathinfo;
974
975 pathinfo.fattr = fattr;
976 nfs_fattr_init(fattr);
977
978 if (clp->rpc_ops->pathconf(server, mntfh, &pathinfo) >= 0)
979 server->namelen = pathinfo.max_namelen;
980 }
981
982 dprintk("<-- nfs_probe_fsinfo() = 0\n");
983 return 0;
984
985out_error:
986 dprintk("nfs_probe_fsinfo: error = %d\n", -error);
987 return error;
988}
989
990/*
991 * Copy useful information when duplicating a server record
992 */
993static void nfs_server_copy_userdata(struct nfs_server *target, struct nfs_server *source)
994{
995 target->flags = source->flags;
Chuck Lever356e76b2010-04-22 15:35:56 -0400996 target->rsize = source->rsize;
997 target->wsize = source->wsize;
David Howells54ceac42006-08-22 20:06:13 -0400998 target->acregmin = source->acregmin;
999 target->acregmax = source->acregmax;
1000 target->acdirmin = source->acdirmin;
1001 target->acdirmax = source->acdirmax;
1002 target->caps = source->caps;
David Howells2df54802009-09-23 14:36:39 -04001003 target->options = source->options;
David Howells54ceac42006-08-22 20:06:13 -04001004}
1005
1006/*
1007 * Allocate and initialise a server record
1008 */
1009static struct nfs_server *nfs_alloc_server(void)
1010{
1011 struct nfs_server *server;
1012
1013 server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL);
1014 if (!server)
1015 return NULL;
1016
1017 server->client = server->client_acl = ERR_PTR(-EINVAL);
1018
1019 /* Zero out the NFS state stuff */
1020 INIT_LIST_HEAD(&server->client_link);
1021 INIT_LIST_HEAD(&server->master_link);
1022
Steve Dicksonef818a22007-11-08 04:05:04 -05001023 atomic_set(&server->active, 0);
1024
David Howells54ceac42006-08-22 20:06:13 -04001025 server->io_stats = nfs_alloc_iostats();
1026 if (!server->io_stats) {
1027 kfree(server);
1028 return NULL;
1029 }
1030
Jens Axboe48d07642009-09-21 09:59:39 +02001031 if (bdi_init(&server->backing_dev_info)) {
1032 nfs_free_iostats(server->io_stats);
1033 kfree(server);
1034 return NULL;
1035 }
1036
Fred Isamanf7e89172011-01-06 11:36:32 +00001037 pnfs_init_server(server);
1038
David Howells54ceac42006-08-22 20:06:13 -04001039 return server;
1040}
1041
1042/*
1043 * Free up a server record
1044 */
1045void nfs_free_server(struct nfs_server *server)
1046{
1047 dprintk("--> nfs_free_server()\n");
1048
Ricardo Labiaga85e174b2010-10-20 00:17:58 -04001049 unset_pnfs_layoutdriver(server);
David Howells54ceac42006-08-22 20:06:13 -04001050 spin_lock(&nfs_client_lock);
1051 list_del(&server->client_link);
1052 list_del(&server->master_link);
1053 spin_unlock(&nfs_client_lock);
1054
1055 if (server->destroy != NULL)
1056 server->destroy(server);
Trond Myklebust5cef3382007-12-11 22:01:56 -05001057
1058 if (!IS_ERR(server->client_acl))
1059 rpc_shutdown_client(server->client_acl);
David Howells54ceac42006-08-22 20:06:13 -04001060 if (!IS_ERR(server->client))
1061 rpc_shutdown_client(server->client);
1062
1063 nfs_put_client(server->nfs_client);
1064
1065 nfs_free_iostats(server->io_stats);
Peter Zijlstrae0bf68d2007-10-16 23:25:46 -07001066 bdi_destroy(&server->backing_dev_info);
David Howells54ceac42006-08-22 20:06:13 -04001067 kfree(server);
1068 nfs_release_automount_timer();
1069 dprintk("<-- nfs_free_server()\n");
1070}
1071
1072/*
1073 * Create a version 2 or 3 volume record
1074 * - keyed on server and FSID
1075 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001076struct nfs_server *nfs_create_server(const struct nfs_parsed_mount_data *data,
David Howells54ceac42006-08-22 20:06:13 -04001077 struct nfs_fh *mntfh)
1078{
1079 struct nfs_server *server;
Trond Myklebustfbca7792010-04-16 16:22:46 -04001080 struct nfs_fattr *fattr;
David Howells54ceac42006-08-22 20:06:13 -04001081 int error;
1082
1083 server = nfs_alloc_server();
1084 if (!server)
1085 return ERR_PTR(-ENOMEM);
1086
Trond Myklebustfbca7792010-04-16 16:22:46 -04001087 error = -ENOMEM;
1088 fattr = nfs_alloc_fattr();
1089 if (fattr == NULL)
1090 goto error;
1091
David Howells54ceac42006-08-22 20:06:13 -04001092 /* Get a client representation */
1093 error = nfs_init_server(server, data);
1094 if (error < 0)
1095 goto error;
1096
1097 BUG_ON(!server->nfs_client);
1098 BUG_ON(!server->nfs_client->rpc_ops);
1099 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
1100
1101 /* Probe the root fh to retrieve its FSID */
Trond Myklebustfbca7792010-04-16 16:22:46 -04001102 error = nfs_probe_fsinfo(server, mntfh, fattr);
David Howells54ceac42006-08-22 20:06:13 -04001103 if (error < 0)
1104 goto error;
Trond Myklebust54af3bb2007-09-28 12:27:41 -04001105 if (server->nfs_client->rpc_ops->version == 3) {
1106 if (server->namelen == 0 || server->namelen > NFS3_MAXNAMLEN)
1107 server->namelen = NFS3_MAXNAMLEN;
1108 if (!(data->flags & NFS_MOUNT_NORDIRPLUS))
1109 server->caps |= NFS_CAP_READDIRPLUS;
1110 } else {
1111 if (server->namelen == 0 || server->namelen > NFS2_MAXNAMLEN)
1112 server->namelen = NFS2_MAXNAMLEN;
1113 }
1114
Trond Myklebustfbca7792010-04-16 16:22:46 -04001115 if (!(fattr->valid & NFS_ATTR_FATTR)) {
1116 error = server->nfs_client->rpc_ops->getattr(server, mntfh, fattr);
David Howells54ceac42006-08-22 20:06:13 -04001117 if (error < 0) {
1118 dprintk("nfs_create_server: getattr error = %d\n", -error);
1119 goto error;
1120 }
1121 }
Trond Myklebustfbca7792010-04-16 16:22:46 -04001122 memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid));
David Howells54ceac42006-08-22 20:06:13 -04001123
David Howells6daabf12006-08-24 15:44:16 -04001124 dprintk("Server FSID: %llx:%llx\n",
1125 (unsigned long long) server->fsid.major,
1126 (unsigned long long) server->fsid.minor);
David Howells54ceac42006-08-22 20:06:13 -04001127
David Howells54ceac42006-08-22 20:06:13 -04001128 spin_lock(&nfs_client_lock);
1129 list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks);
1130 list_add_tail(&server->master_link, &nfs_volume_list);
1131 spin_unlock(&nfs_client_lock);
1132
1133 server->mount_time = jiffies;
Trond Myklebustfbca7792010-04-16 16:22:46 -04001134 nfs_free_fattr(fattr);
David Howells54ceac42006-08-22 20:06:13 -04001135 return server;
1136
1137error:
Trond Myklebustfbca7792010-04-16 16:22:46 -04001138 nfs_free_fattr(fattr);
David Howells54ceac42006-08-22 20:06:13 -04001139 nfs_free_server(server);
1140 return ERR_PTR(error);
1141}
1142
1143#ifdef CONFIG_NFS_V4
1144/*
Andy Adamsonc36fca52011-01-06 02:04:32 +00001145 * NFSv4.0 callback thread helper
1146 *
1147 * Find a client by IP address, protocol version, and minorversion
1148 *
1149 * Called from the pg_authenticate method. The callback identifier
1150 * is not used as it has not been decoded.
1151 *
1152 * Returns NULL if no such client
1153 */
1154struct nfs_client *
1155nfs4_find_client_no_ident(const struct sockaddr *addr)
1156{
1157 struct nfs_client *clp;
1158
1159 spin_lock(&nfs_client_lock);
1160 list_for_each_entry(clp, &nfs_client_list, cl_share_link) {
1161 if (nfs4_cb_match_client(addr, clp, 0) == false)
1162 continue;
1163 atomic_inc(&clp->cl_count);
1164 spin_unlock(&nfs_client_lock);
1165 return clp;
1166 }
1167 spin_unlock(&nfs_client_lock);
1168 return NULL;
1169}
1170
1171/*
1172 * NFSv4.0 callback thread helper
1173 *
1174 * Find a client by callback identifier
1175 */
1176struct nfs_client *
1177nfs4_find_client_ident(int cb_ident)
1178{
1179 struct nfs_client *clp;
1180
1181 spin_lock(&nfs_client_lock);
1182 clp = idr_find(&cb_ident_idr, cb_ident);
1183 if (clp)
1184 atomic_inc(&clp->cl_count);
1185 spin_unlock(&nfs_client_lock);
1186 return clp;
1187}
1188
1189#if defined(CONFIG_NFS_V4_1)
1190/*
1191 * NFSv4.1 callback thread helper
1192 * For CB_COMPOUND calls, find a client by IP address, protocol version,
1193 * minorversion, and sessionID
1194 *
1195 * CREATE_SESSION triggers a CB_NULL ping from servers. The callback service
1196 * sessionid can only be set after the CREATE_SESSION return, so a CB_NULL
1197 * can arrive before the callback sessionid is set. For CB_NULL calls,
1198 * find a client by IP address protocol version, and minorversion.
1199 *
1200 * Returns NULL if no such client
1201 */
1202struct nfs_client *
1203nfs4_find_client_sessionid(const struct sockaddr *addr,
1204 struct nfs4_sessionid *sid, int is_cb_compound)
1205{
1206 struct nfs_client *clp;
1207
1208 spin_lock(&nfs_client_lock);
1209 list_for_each_entry(clp, &nfs_client_list, cl_share_link) {
1210 if (nfs4_cb_match_client(addr, clp, 1) == false)
1211 continue;
1212
1213 if (!nfs4_has_session(clp))
1214 continue;
1215
1216 /* Match sessionid unless cb_null call*/
1217 if (is_cb_compound && (memcmp(clp->cl_session->sess_id.data,
1218 sid->data, NFS4_MAX_SESSIONID_LEN) != 0))
1219 continue;
1220
1221 atomic_inc(&clp->cl_count);
1222 spin_unlock(&nfs_client_lock);
1223 return clp;
1224 }
1225 spin_unlock(&nfs_client_lock);
1226 return NULL;
1227}
1228
1229#else /* CONFIG_NFS_V4_1 */
1230
1231struct nfs_client *
1232nfs4_find_client_sessionid(const struct sockaddr *addr,
1233 struct nfs4_sessionid *sid, int is_cb_compound)
1234{
1235 return NULL;
1236}
1237#endif /* CONFIG_NFS_V4_1 */
1238
1239/*
Benny Halevy9bdaa862009-04-01 09:22:55 -04001240 * Initialize the NFS4 callback service
1241 */
1242static int nfs4_init_callback(struct nfs_client *clp)
1243{
1244 int error;
1245
1246 if (clp->rpc_ops->version == 4) {
Andy Adamson0b5b7ae2009-04-01 09:23:15 -04001247 if (nfs4_has_session(clp)) {
1248 error = xprt_setup_backchannel(
1249 clp->cl_rpcclient->cl_xprt,
1250 NFS41_BC_MIN_CALLBACKS);
1251 if (error < 0)
1252 return error;
1253 }
1254
Trond Myklebust97dc1352010-06-16 09:52:26 -04001255 error = nfs_callback_up(clp->cl_mvops->minor_version,
Benny Halevy71468512009-04-01 09:22:56 -04001256 clp->cl_rpcclient->cl_xprt);
Benny Halevy9bdaa862009-04-01 09:22:55 -04001257 if (error < 0) {
1258 dprintk("%s: failed to start callback. Error = %d\n",
1259 __func__, error);
1260 return error;
1261 }
1262 __set_bit(NFS_CS_CALLBACK, &clp->cl_res_state);
1263 }
1264 return 0;
1265}
1266
1267/*
Andy Adamson557134a2009-04-01 09:21:53 -04001268 * Initialize the minor version specific parts of an NFS4 client record
1269 */
1270static int nfs4_init_client_minor_version(struct nfs_client *clp)
1271{
1272#if defined(CONFIG_NFS_V4_1)
Trond Myklebust97dc1352010-06-16 09:52:26 -04001273 if (clp->cl_mvops->minor_version) {
Andy Adamson557134a2009-04-01 09:21:53 -04001274 struct nfs4_session *session = NULL;
1275 /*
1276 * Create the session and mark it expired.
1277 * When a SEQUENCE operation encounters the expired session
1278 * it will do session recovery to initialize it.
1279 */
1280 session = nfs4_alloc_session(clp);
1281 if (!session)
1282 return -ENOMEM;
1283
1284 clp->cl_session = session;
Trond Myklebustfe74ba32010-06-16 09:52:27 -04001285 /*
1286 * The create session reply races with the server back
1287 * channel probe. Mark the client NFS_CS_SESSION_INITING
1288 * so that the client back channel can find the
1289 * nfs_client struct
1290 */
1291 clp->cl_cons_state = NFS_CS_SESSION_INITING;
Andy Adamson557134a2009-04-01 09:21:53 -04001292 }
1293#endif /* CONFIG_NFS_V4_1 */
1294
Benny Halevy71468512009-04-01 09:22:56 -04001295 return nfs4_init_callback(clp);
Andy Adamson557134a2009-04-01 09:21:53 -04001296}
1297
1298/*
David Howells54ceac42006-08-22 20:06:13 -04001299 * Initialise an NFS4 client record
1300 */
1301static int nfs4_init_client(struct nfs_client *clp,
Trond Myklebust33170232007-12-20 16:03:59 -05001302 const struct rpc_timeout *timeparms,
J. Bruce Fields7d9ac062006-10-19 23:28:39 -07001303 const char *ip_addr,
Chuck Leverd7403512008-12-23 15:21:37 -05001304 rpc_authflavor_t authflavour,
1305 int flags)
David Howells54ceac42006-08-22 20:06:13 -04001306{
1307 int error;
1308
1309 if (clp->cl_cons_state == NFS_CS_READY) {
1310 /* the client is initialised already */
1311 dprintk("<-- nfs4_init_client() = 0 [already %p]\n", clp);
1312 return 0;
1313 }
1314
1315 /* Check NFS protocol revision and initialize RPC op vector */
1316 clp->rpc_ops = &nfs_v4_clientops;
1317
Trond Myklebust59dca3b2008-01-03 16:29:06 -05001318 error = nfs_create_rpc_client(clp, timeparms, authflavour,
Chuck Leverd7403512008-12-23 15:21:37 -05001319 1, flags & NFS_MOUNT_NORESVPORT);
David Howells54ceac42006-08-22 20:06:13 -04001320 if (error < 0)
1321 goto error;
Ben Hutchingsf4373bf2009-10-06 15:42:18 -04001322 strlcpy(clp->cl_ipaddr, ip_addr, sizeof(clp->cl_ipaddr));
David Howells54ceac42006-08-22 20:06:13 -04001323
1324 error = nfs_idmap_new(clp);
1325 if (error < 0) {
1326 dprintk("%s: failed to create idmapper. Error = %d\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07001327 __func__, error);
David Howells54ceac42006-08-22 20:06:13 -04001328 goto error;
1329 }
Trond Myklebust9c5bf382006-08-22 20:06:14 -04001330 __set_bit(NFS_CS_IDMAP, &clp->cl_res_state);
David Howells54ceac42006-08-22 20:06:13 -04001331
Andy Adamson557134a2009-04-01 09:21:53 -04001332 error = nfs4_init_client_minor_version(clp);
1333 if (error < 0)
1334 goto error;
1335
Andy Adamson76db6d92009-04-01 09:22:38 -04001336 if (!nfs4_has_session(clp))
1337 nfs_mark_client_ready(clp, NFS_CS_READY);
David Howells54ceac42006-08-22 20:06:13 -04001338 return 0;
1339
1340error:
1341 nfs_mark_client_ready(clp, error);
1342 dprintk("<-- nfs4_init_client() = xerror %d\n", error);
1343 return error;
1344}
1345
1346/*
1347 * Set up an NFS4 client
1348 */
1349static int nfs4_set_client(struct nfs_server *server,
Chuck Leverdcecae02007-12-10 14:58:59 -05001350 const char *hostname,
1351 const struct sockaddr *addr,
1352 const size_t addrlen,
J. Bruce Fields7d9ac062006-10-19 23:28:39 -07001353 const char *ip_addr,
David Howells54ceac42006-08-22 20:06:13 -04001354 rpc_authflavor_t authflavour,
Benny Halevy94a417f2009-04-01 09:21:49 -04001355 int proto, const struct rpc_timeout *timeparms,
1356 u32 minorversion)
David Howells54ceac42006-08-22 20:06:13 -04001357{
Trond Myklebust3a498022007-12-14 14:56:04 -05001358 struct nfs_client_initdata cl_init = {
1359 .hostname = hostname,
Chuck Leverdcecae02007-12-10 14:58:59 -05001360 .addr = addr,
1361 .addrlen = addrlen,
Trond Myklebust40c553192007-12-14 14:56:07 -05001362 .rpc_ops = &nfs_v4_clientops,
Trond Myklebust59dca3b2008-01-03 16:29:06 -05001363 .proto = proto,
Benny Halevy5aae4a92009-04-01 09:21:50 -04001364 .minorversion = minorversion,
Trond Myklebust3a498022007-12-14 14:56:04 -05001365 };
David Howells54ceac42006-08-22 20:06:13 -04001366 struct nfs_client *clp;
1367 int error;
1368
1369 dprintk("--> nfs4_set_client()\n");
1370
1371 /* Allocate or find a client reference we can use */
Trond Myklebust3a498022007-12-14 14:56:04 -05001372 clp = nfs_get_client(&cl_init);
David Howells54ceac42006-08-22 20:06:13 -04001373 if (IS_ERR(clp)) {
1374 error = PTR_ERR(clp);
1375 goto error;
1376 }
Chuck Leverd7403512008-12-23 15:21:37 -05001377 error = nfs4_init_client(clp, timeparms, ip_addr, authflavour,
1378 server->flags);
David Howells54ceac42006-08-22 20:06:13 -04001379 if (error < 0)
1380 goto error_put;
1381
1382 server->nfs_client = clp;
1383 dprintk("<-- nfs4_set_client() = 0 [new %p]\n", clp);
1384 return 0;
1385
1386error_put:
1387 nfs_put_client(clp);
1388error:
1389 dprintk("<-- nfs4_set_client() = xerror %d\n", error);
1390 return error;
1391}
1392
Andy Adamson557134a2009-04-01 09:21:53 -04001393
1394/*
Andy Adamson96b09e02009-04-01 09:22:33 -04001395 * Session has been established, and the client marked ready.
1396 * Set the mount rsize and wsize with negotiated fore channel
1397 * attributes which will be bound checked in nfs_server_set_fsinfo.
1398 */
1399static void nfs4_session_set_rwsize(struct nfs_server *server)
1400{
1401#ifdef CONFIG_NFS_V4_1
Alexandros Batsakis2449ea22009-12-05 13:36:55 -05001402 struct nfs4_session *sess;
1403 u32 server_resp_sz;
1404 u32 server_rqst_sz;
1405
Andy Adamson96b09e02009-04-01 09:22:33 -04001406 if (!nfs4_has_session(server->nfs_client))
1407 return;
Alexandros Batsakis2449ea22009-12-05 13:36:55 -05001408 sess = server->nfs_client->cl_session;
1409 server_resp_sz = sess->fc_attrs.max_resp_sz - nfs41_maxread_overhead;
1410 server_rqst_sz = sess->fc_attrs.max_rqst_sz - nfs41_maxwrite_overhead;
1411
1412 if (server->rsize > server_resp_sz)
1413 server->rsize = server_resp_sz;
1414 if (server->wsize > server_rqst_sz)
1415 server->wsize = server_rqst_sz;
Andy Adamson96b09e02009-04-01 09:22:33 -04001416#endif /* CONFIG_NFS_V4_1 */
1417}
1418
Trond Myklebust44950b62010-06-17 11:45:12 -04001419static int nfs4_server_common_setup(struct nfs_server *server,
1420 struct nfs_fh *mntfh)
1421{
1422 struct nfs_fattr *fattr;
1423 int error;
1424
1425 BUG_ON(!server->nfs_client);
1426 BUG_ON(!server->nfs_client->rpc_ops);
1427 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
1428
1429 fattr = nfs_alloc_fattr();
1430 if (fattr == NULL)
1431 return -ENOMEM;
1432
1433 /* We must ensure the session is initialised first */
1434 error = nfs4_init_session(server);
1435 if (error < 0)
1436 goto out;
1437
1438 /* Probe the root fh to retrieve its FSID and filehandle */
1439 error = nfs4_get_rootfh(server, mntfh);
1440 if (error < 0)
1441 goto out;
1442
1443 dprintk("Server FSID: %llx:%llx\n",
1444 (unsigned long long) server->fsid.major,
1445 (unsigned long long) server->fsid.minor);
1446 dprintk("Mount FH: %d\n", mntfh->size);
1447
1448 nfs4_session_set_rwsize(server);
1449
1450 error = nfs_probe_fsinfo(server, mntfh, fattr);
1451 if (error < 0)
1452 goto out;
1453
1454 if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN)
1455 server->namelen = NFS4_MAXNAMLEN;
1456
1457 spin_lock(&nfs_client_lock);
1458 list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks);
1459 list_add_tail(&server->master_link, &nfs_volume_list);
1460 spin_unlock(&nfs_client_lock);
1461
1462 server->mount_time = jiffies;
1463out:
1464 nfs_free_fattr(fattr);
1465 return error;
1466}
1467
Andy Adamson96b09e02009-04-01 09:22:33 -04001468/*
David Howells54ceac42006-08-22 20:06:13 -04001469 * Create a version 4 volume record
1470 */
1471static int nfs4_init_server(struct nfs_server *server,
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001472 const struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001473{
Trond Myklebust33170232007-12-20 16:03:59 -05001474 struct rpc_timeout timeparms;
David Howells54ceac42006-08-22 20:06:13 -04001475 int error;
1476
1477 dprintk("--> nfs4_init_server()\n");
1478
Trond Myklebust33170232007-12-20 16:03:59 -05001479 nfs_init_timeout_values(&timeparms, data->nfs_server.protocol,
1480 data->timeo, data->retrans);
1481
Chuck Lever542fcc32008-12-23 15:21:36 -05001482 /* Initialise the client representation from the mount data */
1483 server->flags = data->flags;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001484 server->caps |= NFS_CAP_ATOMIC_OPEN|NFS_CAP_CHANGE_ATTR|NFS_CAP_POSIX_LOCK;
1485 if (!(data->flags & NFS_MOUNT_NORDIRPLUS))
1486 server->caps |= NFS_CAP_READDIRPLUS;
David Howellsb797cac2009-04-03 16:42:48 +01001487 server->options = data->options;
Chuck Lever542fcc32008-12-23 15:21:36 -05001488
Trond Myklebust33170232007-12-20 16:03:59 -05001489 /* Get a client record */
1490 error = nfs4_set_client(server,
1491 data->nfs_server.hostname,
1492 (const struct sockaddr *)&data->nfs_server.address,
1493 data->nfs_server.addrlen,
1494 data->client_address,
1495 data->auth_flavors[0],
1496 data->nfs_server.protocol,
Benny Halevy94a417f2009-04-01 09:21:49 -04001497 &timeparms,
1498 data->minorversion);
Trond Myklebust33170232007-12-20 16:03:59 -05001499 if (error < 0)
1500 goto error;
1501
David Howells54ceac42006-08-22 20:06:13 -04001502 if (data->rsize)
1503 server->rsize = nfs_block_size(data->rsize, NULL);
1504 if (data->wsize)
1505 server->wsize = nfs_block_size(data->wsize, NULL);
1506
1507 server->acregmin = data->acregmin * HZ;
1508 server->acregmax = data->acregmax * HZ;
1509 server->acdirmin = data->acdirmin * HZ;
1510 server->acdirmax = data->acdirmax * HZ;
1511
Chuck Leverf22d6d72008-03-14 14:10:22 -04001512 server->port = data->nfs_server.port;
1513
Trond Myklebust33170232007-12-20 16:03:59 -05001514 error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]);
David Howells54ceac42006-08-22 20:06:13 -04001515
Trond Myklebust33170232007-12-20 16:03:59 -05001516error:
David Howells54ceac42006-08-22 20:06:13 -04001517 /* Done */
1518 dprintk("<-- nfs4_init_server() = %d\n", error);
1519 return error;
1520}
1521
1522/*
1523 * Create a version 4 volume record
1524 * - keyed on server and FSID
1525 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001526struct nfs_server *nfs4_create_server(const struct nfs_parsed_mount_data *data,
David Howells54ceac42006-08-22 20:06:13 -04001527 struct nfs_fh *mntfh)
1528{
David Howells54ceac42006-08-22 20:06:13 -04001529 struct nfs_server *server;
1530 int error;
1531
1532 dprintk("--> nfs4_create_server()\n");
1533
1534 server = nfs_alloc_server();
1535 if (!server)
1536 return ERR_PTR(-ENOMEM);
1537
David Howells54ceac42006-08-22 20:06:13 -04001538 /* set up the general RPC client */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001539 error = nfs4_init_server(server, data);
David Howells54ceac42006-08-22 20:06:13 -04001540 if (error < 0)
1541 goto error;
1542
Trond Myklebust44950b62010-06-17 11:45:12 -04001543 error = nfs4_server_common_setup(server, mntfh);
Trond Myklebustfccba802009-07-21 16:48:07 -04001544 if (error < 0)
1545 goto error;
Andy Adamson557134a2009-04-01 09:21:53 -04001546
David Howells54ceac42006-08-22 20:06:13 -04001547 dprintk("<-- nfs4_create_server() = %p\n", server);
1548 return server;
1549
1550error:
1551 nfs_free_server(server);
1552 dprintk("<-- nfs4_create_server() = error %d\n", error);
1553 return ERR_PTR(error);
1554}
1555
1556/*
1557 * Create an NFS4 referral server record
1558 */
1559struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data,
Trond Myklebustf2d0d852007-02-02 14:46:09 -08001560 struct nfs_fh *mntfh)
David Howells54ceac42006-08-22 20:06:13 -04001561{
1562 struct nfs_client *parent_client;
1563 struct nfs_server *server, *parent_server;
David Howells54ceac42006-08-22 20:06:13 -04001564 int error;
1565
1566 dprintk("--> nfs4_create_referral_server()\n");
1567
1568 server = nfs_alloc_server();
1569 if (!server)
1570 return ERR_PTR(-ENOMEM);
1571
1572 parent_server = NFS_SB(data->sb);
1573 parent_client = parent_server->nfs_client;
1574
Chuck Lever542fcc32008-12-23 15:21:36 -05001575 /* Initialise the client representation from the parent server */
1576 nfs_server_copy_userdata(server, parent_server);
Trond Myklebust62ab460c2009-08-09 15:06:19 -04001577 server->caps |= NFS_CAP_ATOMIC_OPEN|NFS_CAP_CHANGE_ATTR;
Chuck Lever542fcc32008-12-23 15:21:36 -05001578
David Howells54ceac42006-08-22 20:06:13 -04001579 /* Get a client representation.
1580 * Note: NFSv4 always uses TCP, */
Chuck Leverdcecae02007-12-10 14:58:59 -05001581 error = nfs4_set_client(server, data->hostname,
Chuck Lever6677d092007-12-10 14:59:06 -05001582 data->addr,
1583 data->addrlen,
Chuck Leverdcecae02007-12-10 14:58:59 -05001584 parent_client->cl_ipaddr,
1585 data->authflavor,
1586 parent_server->client->cl_xprt->prot,
Benny Halevy94a417f2009-04-01 09:21:49 -04001587 parent_server->client->cl_timeout,
Trond Myklebust97dc1352010-06-16 09:52:26 -04001588 parent_client->cl_mvops->minor_version);
andros@citi.umich.edu297de4f2006-08-29 12:19:41 -04001589 if (error < 0)
1590 goto error;
David Howells54ceac42006-08-22 20:06:13 -04001591
Trond Myklebust33170232007-12-20 16:03:59 -05001592 error = nfs_init_server_rpcclient(server, parent_server->client->cl_timeout, data->authflavor);
David Howells54ceac42006-08-22 20:06:13 -04001593 if (error < 0)
1594 goto error;
1595
Trond Myklebust44950b62010-06-17 11:45:12 -04001596 error = nfs4_server_common_setup(server, mntfh);
Trond Myklebustf2d0d852007-02-02 14:46:09 -08001597 if (error < 0)
1598 goto error;
1599
David Howells54ceac42006-08-22 20:06:13 -04001600 dprintk("<-- nfs_create_referral_server() = %p\n", server);
1601 return server;
1602
1603error:
1604 nfs_free_server(server);
1605 dprintk("<-- nfs4_create_referral_server() = error %d\n", error);
1606 return ERR_PTR(error);
1607}
1608
1609#endif /* CONFIG_NFS_V4 */
1610
1611/*
1612 * Clone an NFS2, NFS3 or NFS4 server record
1613 */
1614struct nfs_server *nfs_clone_server(struct nfs_server *source,
1615 struct nfs_fh *fh,
1616 struct nfs_fattr *fattr)
1617{
1618 struct nfs_server *server;
Trond Myklebustfbca7792010-04-16 16:22:46 -04001619 struct nfs_fattr *fattr_fsinfo;
David Howells54ceac42006-08-22 20:06:13 -04001620 int error;
1621
1622 dprintk("--> nfs_clone_server(,%llx:%llx,)\n",
David Howells6daabf12006-08-24 15:44:16 -04001623 (unsigned long long) fattr->fsid.major,
1624 (unsigned long long) fattr->fsid.minor);
David Howells54ceac42006-08-22 20:06:13 -04001625
1626 server = nfs_alloc_server();
1627 if (!server)
1628 return ERR_PTR(-ENOMEM);
1629
Trond Myklebustfbca7792010-04-16 16:22:46 -04001630 error = -ENOMEM;
1631 fattr_fsinfo = nfs_alloc_fattr();
1632 if (fattr_fsinfo == NULL)
1633 goto out_free_server;
1634
David Howells54ceac42006-08-22 20:06:13 -04001635 /* Copy data from the source */
1636 server->nfs_client = source->nfs_client;
1637 atomic_inc(&server->nfs_client->cl_count);
1638 nfs_server_copy_userdata(server, source);
1639
1640 server->fsid = fattr->fsid;
1641
Trond Myklebust33170232007-12-20 16:03:59 -05001642 error = nfs_init_server_rpcclient(server,
1643 source->client->cl_timeout,
1644 source->client->cl_auth->au_flavor);
David Howells54ceac42006-08-22 20:06:13 -04001645 if (error < 0)
1646 goto out_free_server;
1647 if (!IS_ERR(source->client_acl))
1648 nfs_init_server_aclclient(server);
1649
1650 /* probe the filesystem info for this server filesystem */
Trond Myklebustfbca7792010-04-16 16:22:46 -04001651 error = nfs_probe_fsinfo(server, fh, fattr_fsinfo);
David Howells54ceac42006-08-22 20:06:13 -04001652 if (error < 0)
1653 goto out_free_server;
1654
Trond Myklebust54af3bb2007-09-28 12:27:41 -04001655 if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN)
1656 server->namelen = NFS4_MAXNAMLEN;
1657
David Howells54ceac42006-08-22 20:06:13 -04001658 dprintk("Cloned FSID: %llx:%llx\n",
David Howells6daabf12006-08-24 15:44:16 -04001659 (unsigned long long) server->fsid.major,
1660 (unsigned long long) server->fsid.minor);
David Howells54ceac42006-08-22 20:06:13 -04001661
1662 error = nfs_start_lockd(server);
1663 if (error < 0)
1664 goto out_free_server;
1665
1666 spin_lock(&nfs_client_lock);
1667 list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks);
1668 list_add_tail(&server->master_link, &nfs_volume_list);
1669 spin_unlock(&nfs_client_lock);
1670
1671 server->mount_time = jiffies;
1672
Trond Myklebustfbca7792010-04-16 16:22:46 -04001673 nfs_free_fattr(fattr_fsinfo);
David Howells54ceac42006-08-22 20:06:13 -04001674 dprintk("<-- nfs_clone_server() = %p\n", server);
1675 return server;
1676
1677out_free_server:
Trond Myklebustfbca7792010-04-16 16:22:46 -04001678 nfs_free_fattr(fattr_fsinfo);
David Howells54ceac42006-08-22 20:06:13 -04001679 nfs_free_server(server);
1680 dprintk("<-- nfs_clone_server() = error %d\n", error);
1681 return ERR_PTR(error);
1682}
David Howells6aaca562006-08-22 20:06:13 -04001683
1684#ifdef CONFIG_PROC_FS
1685static struct proc_dir_entry *proc_fs_nfs;
1686
1687static int nfs_server_list_open(struct inode *inode, struct file *file);
1688static void *nfs_server_list_start(struct seq_file *p, loff_t *pos);
1689static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos);
1690static void nfs_server_list_stop(struct seq_file *p, void *v);
1691static int nfs_server_list_show(struct seq_file *m, void *v);
1692
James Morris88e9d342009-09-22 16:43:43 -07001693static const struct seq_operations nfs_server_list_ops = {
David Howells6aaca562006-08-22 20:06:13 -04001694 .start = nfs_server_list_start,
1695 .next = nfs_server_list_next,
1696 .stop = nfs_server_list_stop,
1697 .show = nfs_server_list_show,
1698};
1699
Arjan van de Ven00977a52007-02-12 00:55:34 -08001700static const struct file_operations nfs_server_list_fops = {
David Howells6aaca562006-08-22 20:06:13 -04001701 .open = nfs_server_list_open,
1702 .read = seq_read,
1703 .llseek = seq_lseek,
1704 .release = seq_release,
Denis V. Lunev34b37232008-04-29 01:02:07 -07001705 .owner = THIS_MODULE,
David Howells6aaca562006-08-22 20:06:13 -04001706};
1707
1708static int nfs_volume_list_open(struct inode *inode, struct file *file);
1709static void *nfs_volume_list_start(struct seq_file *p, loff_t *pos);
1710static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos);
1711static void nfs_volume_list_stop(struct seq_file *p, void *v);
1712static int nfs_volume_list_show(struct seq_file *m, void *v);
1713
James Morris88e9d342009-09-22 16:43:43 -07001714static const struct seq_operations nfs_volume_list_ops = {
David Howells6aaca562006-08-22 20:06:13 -04001715 .start = nfs_volume_list_start,
1716 .next = nfs_volume_list_next,
1717 .stop = nfs_volume_list_stop,
1718 .show = nfs_volume_list_show,
1719};
1720
Arjan van de Ven00977a52007-02-12 00:55:34 -08001721static const struct file_operations nfs_volume_list_fops = {
David Howells6aaca562006-08-22 20:06:13 -04001722 .open = nfs_volume_list_open,
1723 .read = seq_read,
1724 .llseek = seq_lseek,
1725 .release = seq_release,
Denis V. Lunev34b37232008-04-29 01:02:07 -07001726 .owner = THIS_MODULE,
David Howells6aaca562006-08-22 20:06:13 -04001727};
1728
1729/*
1730 * open "/proc/fs/nfsfs/servers" which provides a summary of servers with which
1731 * we're dealing
1732 */
1733static int nfs_server_list_open(struct inode *inode, struct file *file)
1734{
1735 struct seq_file *m;
1736 int ret;
1737
1738 ret = seq_open(file, &nfs_server_list_ops);
1739 if (ret < 0)
1740 return ret;
1741
1742 m = file->private_data;
1743 m->private = PDE(inode)->data;
1744
1745 return 0;
1746}
1747
1748/*
1749 * set up the iterator to start reading from the server list and return the first item
1750 */
1751static void *nfs_server_list_start(struct seq_file *m, loff_t *_pos)
1752{
David Howells6aaca562006-08-22 20:06:13 -04001753 /* lock the list against modification */
1754 spin_lock(&nfs_client_lock);
Pavel Emelianov259902e2007-07-15 23:39:56 -07001755 return seq_list_start_head(&nfs_client_list, *_pos);
David Howells6aaca562006-08-22 20:06:13 -04001756}
1757
1758/*
1759 * move to next server
1760 */
1761static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos)
1762{
Pavel Emelianov259902e2007-07-15 23:39:56 -07001763 return seq_list_next(v, &nfs_client_list, pos);
David Howells6aaca562006-08-22 20:06:13 -04001764}
1765
1766/*
1767 * clean up after reading from the transports list
1768 */
1769static void nfs_server_list_stop(struct seq_file *p, void *v)
1770{
1771 spin_unlock(&nfs_client_lock);
1772}
1773
1774/*
1775 * display a header line followed by a load of call lines
1776 */
1777static int nfs_server_list_show(struct seq_file *m, void *v)
1778{
1779 struct nfs_client *clp;
1780
1781 /* display header on line 1 */
Pavel Emelianov259902e2007-07-15 23:39:56 -07001782 if (v == &nfs_client_list) {
David Howells6aaca562006-08-22 20:06:13 -04001783 seq_puts(m, "NV SERVER PORT USE HOSTNAME\n");
1784 return 0;
1785 }
1786
1787 /* display one transport per line on subsequent lines */
1788 clp = list_entry(v, struct nfs_client, cl_share_link);
1789
Chuck Lever5d8515c2007-12-10 14:57:16 -05001790 seq_printf(m, "v%u %s %s %3d %s\n",
Trond Myklebust40c553192007-12-14 14:56:07 -05001791 clp->rpc_ops->version,
Chuck Lever5d8515c2007-12-10 14:57:16 -05001792 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR),
1793 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT),
David Howells6aaca562006-08-22 20:06:13 -04001794 atomic_read(&clp->cl_count),
1795 clp->cl_hostname);
1796
1797 return 0;
1798}
1799
1800/*
1801 * open "/proc/fs/nfsfs/volumes" which provides a summary of extant volumes
1802 */
1803static int nfs_volume_list_open(struct inode *inode, struct file *file)
1804{
1805 struct seq_file *m;
1806 int ret;
1807
1808 ret = seq_open(file, &nfs_volume_list_ops);
1809 if (ret < 0)
1810 return ret;
1811
1812 m = file->private_data;
1813 m->private = PDE(inode)->data;
1814
1815 return 0;
1816}
1817
1818/*
1819 * set up the iterator to start reading from the volume list and return the first item
1820 */
1821static void *nfs_volume_list_start(struct seq_file *m, loff_t *_pos)
1822{
David Howells6aaca562006-08-22 20:06:13 -04001823 /* lock the list against modification */
1824 spin_lock(&nfs_client_lock);
Pavel Emelianov259902e2007-07-15 23:39:56 -07001825 return seq_list_start_head(&nfs_volume_list, *_pos);
David Howells6aaca562006-08-22 20:06:13 -04001826}
1827
1828/*
1829 * move to next volume
1830 */
1831static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos)
1832{
Pavel Emelianov259902e2007-07-15 23:39:56 -07001833 return seq_list_next(v, &nfs_volume_list, pos);
David Howells6aaca562006-08-22 20:06:13 -04001834}
1835
1836/*
1837 * clean up after reading from the transports list
1838 */
1839static void nfs_volume_list_stop(struct seq_file *p, void *v)
1840{
1841 spin_unlock(&nfs_client_lock);
1842}
1843
1844/*
1845 * display a header line followed by a load of call lines
1846 */
1847static int nfs_volume_list_show(struct seq_file *m, void *v)
1848{
1849 struct nfs_server *server;
1850 struct nfs_client *clp;
1851 char dev[8], fsid[17];
1852
1853 /* display header on line 1 */
Pavel Emelianov259902e2007-07-15 23:39:56 -07001854 if (v == &nfs_volume_list) {
David Howells5d1acff2009-04-03 16:42:47 +01001855 seq_puts(m, "NV SERVER PORT DEV FSID FSC\n");
David Howells6aaca562006-08-22 20:06:13 -04001856 return 0;
1857 }
1858 /* display one transport per line on subsequent lines */
1859 server = list_entry(v, struct nfs_server, master_link);
1860 clp = server->nfs_client;
1861
1862 snprintf(dev, 8, "%u:%u",
1863 MAJOR(server->s_dev), MINOR(server->s_dev));
1864
1865 snprintf(fsid, 17, "%llx:%llx",
David Howells6daabf12006-08-24 15:44:16 -04001866 (unsigned long long) server->fsid.major,
1867 (unsigned long long) server->fsid.minor);
David Howells6aaca562006-08-22 20:06:13 -04001868
David Howells5d1acff2009-04-03 16:42:47 +01001869 seq_printf(m, "v%u %s %s %-7s %-17s %s\n",
Trond Myklebust40c553192007-12-14 14:56:07 -05001870 clp->rpc_ops->version,
Chuck Lever5d8515c2007-12-10 14:57:16 -05001871 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR),
1872 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT),
David Howells6aaca562006-08-22 20:06:13 -04001873 dev,
David Howells5d1acff2009-04-03 16:42:47 +01001874 fsid,
1875 nfs_server_fscache_state(server));
David Howells6aaca562006-08-22 20:06:13 -04001876
1877 return 0;
1878}
1879
1880/*
1881 * initialise the /proc/fs/nfsfs/ directory
1882 */
1883int __init nfs_fs_proc_init(void)
1884{
1885 struct proc_dir_entry *p;
1886
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -07001887 proc_fs_nfs = proc_mkdir("fs/nfsfs", NULL);
David Howells6aaca562006-08-22 20:06:13 -04001888 if (!proc_fs_nfs)
1889 goto error_0;
1890
David Howells6aaca562006-08-22 20:06:13 -04001891 /* a file of servers with which we're dealing */
Denis V. Lunev34b37232008-04-29 01:02:07 -07001892 p = proc_create("servers", S_IFREG|S_IRUGO,
1893 proc_fs_nfs, &nfs_server_list_fops);
David Howells6aaca562006-08-22 20:06:13 -04001894 if (!p)
1895 goto error_1;
1896
David Howells6aaca562006-08-22 20:06:13 -04001897 /* a file of volumes that we have mounted */
Denis V. Lunev34b37232008-04-29 01:02:07 -07001898 p = proc_create("volumes", S_IFREG|S_IRUGO,
1899 proc_fs_nfs, &nfs_volume_list_fops);
David Howells6aaca562006-08-22 20:06:13 -04001900 if (!p)
1901 goto error_2;
David Howells6aaca562006-08-22 20:06:13 -04001902 return 0;
1903
1904error_2:
1905 remove_proc_entry("servers", proc_fs_nfs);
1906error_1:
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -07001907 remove_proc_entry("fs/nfsfs", NULL);
David Howells6aaca562006-08-22 20:06:13 -04001908error_0:
1909 return -ENOMEM;
1910}
1911
1912/*
1913 * clean up the /proc/fs/nfsfs/ directory
1914 */
1915void nfs_fs_proc_exit(void)
1916{
1917 remove_proc_entry("volumes", proc_fs_nfs);
1918 remove_proc_entry("servers", proc_fs_nfs);
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -07001919 remove_proc_entry("fs/nfsfs", NULL);
David Howells6aaca562006-08-22 20:06:13 -04001920}
1921
1922#endif /* CONFIG_PROC_FS */