blob: b9ed2a8bc26ad382d20bc17bc0dbb72ce31e37e7 [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 spin_lock_init(&clp->cl_lock);
David Howells65f27f32006-11-22 14:55:48 +0000176 INIT_DELAYED_WORK(&clp->cl_renewd, nfs4_renew_state);
David Howells24c8dbb2006-08-22 20:06:10 -0400177 rpc_init_wait_queue(&clp->cl_rpcwaitq, "NFS client");
178 clp->cl_boot_time = CURRENT_TIME;
179 clp->cl_state = 1 << NFS4CLNT_LEASE_EXPIRED;
Benny Halevy5aae4a92009-04-01 09:21:50 -0400180 clp->cl_minorversion = cl_init->minorversion;
Trond Myklebust97dc1352010-06-16 09:52:26 -0400181 clp->cl_mvops = nfs_v4_minor_ops[cl_init->minorversion];
David Howells24c8dbb2006-08-22 20:06:10 -0400182#endif
Trond Myklebust7c67db32008-04-07 20:50:11 -0400183 cred = rpc_lookup_machine_cred();
184 if (!IS_ERR(cred))
185 clp->cl_machine_cred = cred;
Andy Adamson974cec82010-10-20 00:18:02 -0400186#if defined(CONFIG_NFS_V4_1)
187 INIT_LIST_HEAD(&clp->cl_layouts);
188#endif
David Howells14727282009-04-03 16:42:42 +0100189 nfs_fscache_get_client_cookie(clp);
190
David Howells24c8dbb2006-08-22 20:06:10 -0400191 return clp;
192
Benny Halevy71468512009-04-01 09:22:56 -0400193error_cleanup:
David Howells24c8dbb2006-08-22 20:06:10 -0400194 kfree(clp);
195error_0:
Chuck Levera21bdd92009-06-17 18:02:10 -0700196 return ERR_PTR(err);
David Howells24c8dbb2006-08-22 20:06:10 -0400197}
198
Trond Myklebust5dd31772006-08-24 01:03:05 -0400199#ifdef CONFIG_NFS_V4
Andy Adamson557134a2009-04-01 09:21:53 -0400200#ifdef CONFIG_NFS_V4_1
Andy Adamsonea005282011-01-06 02:04:29 +0000201static void nfs4_shutdown_session(struct nfs_client *clp)
202{
203 if (nfs4_has_session(clp))
Andy Adamson557134a2009-04-01 09:21:53 -0400204 nfs4_destroy_session(clp->cl_session);
Andy Adamson557134a2009-04-01 09:21:53 -0400205}
Andy Adamsonea005282011-01-06 02:04:29 +0000206#else /* CONFIG_NFS_V4_1 */
207static void nfs4_shutdown_session(struct nfs_client *clp)
208{
209}
210#endif /* CONFIG_NFS_V4_1 */
Andy Adamson557134a2009-04-01 09:21:53 -0400211
212/*
Alexandros Batsakis888ef2e2010-02-05 03:45:03 -0800213 * Destroy the NFS4 callback service
214 */
215static void nfs4_destroy_callback(struct nfs_client *clp)
216{
217 if (__test_and_clear_bit(NFS_CS_CALLBACK, &clp->cl_res_state))
Trond Myklebust97dc1352010-06-16 09:52:26 -0400218 nfs_callback_down(clp->cl_mvops->minor_version);
Alexandros Batsakis888ef2e2010-02-05 03:45:03 -0800219}
220
221static void nfs4_shutdown_client(struct nfs_client *clp)
222{
223 if (__test_and_clear_bit(NFS_CS_RENEWD, &clp->cl_res_state))
224 nfs4_kill_renewd(clp);
Andy Adamsonea005282011-01-06 02:04:29 +0000225 nfs4_shutdown_session(clp);
Alexandros Batsakis888ef2e2010-02-05 03:45:03 -0800226 nfs4_destroy_callback(clp);
227 if (__test_and_clear_bit(NFS_CS_IDMAP, &clp->cl_res_state))
228 nfs_idmap_delete(clp);
229
230 rpc_destroy_wait_queue(&clp->cl_rpcwaitq);
231}
Andy Adamsonf4eecd52011-01-06 02:04:30 +0000232
233/* idr_remove_all is not needed as all id's are removed by nfs_put_client */
234void nfs_cleanup_cb_ident_idr(void)
235{
236 idr_destroy(&cb_ident_idr);
237}
238
239/* nfs_client_lock held */
240static void nfs_cb_idr_remove_locked(struct nfs_client *clp)
241{
242 if (clp->cl_cb_ident)
243 idr_remove(&cb_ident_idr, clp->cl_cb_ident);
244}
245
Fred Isamanf7e89172011-01-06 11:36:32 +0000246static void pnfs_init_server(struct nfs_server *server)
247{
248 rpc_init_wait_queue(&server->roc_rpcwaitq, "pNFS ROC");
249}
250
Alexandros Batsakis888ef2e2010-02-05 03:45:03 -0800251#else
252static void nfs4_shutdown_client(struct nfs_client *clp)
253{
254}
Andy Adamsonf4eecd52011-01-06 02:04:30 +0000255
256void nfs_cleanup_cb_ident_idr(void)
257{
258}
259
260static void nfs_cb_idr_remove_locked(struct nfs_client *clp)
261{
262}
Fred Isamanf7e89172011-01-06 11:36:32 +0000263
264static void pnfs_init_server(struct nfs_server *server)
265{
266}
267
Alexandros Batsakis888ef2e2010-02-05 03:45:03 -0800268#endif /* CONFIG_NFS_V4 */
269
270/*
David Howells24c8dbb2006-08-22 20:06:10 -0400271 * Destroy a shared client record
272 */
273static void nfs_free_client(struct nfs_client *clp)
274{
Trond Myklebust40c553192007-12-14 14:56:07 -0500275 dprintk("--> nfs_free_client(%u)\n", clp->rpc_ops->version);
David Howells24c8dbb2006-08-22 20:06:10 -0400276
Trond Myklebust5dd31772006-08-24 01:03:05 -0400277 nfs4_shutdown_client(clp);
David Howells24c8dbb2006-08-22 20:06:10 -0400278
David Howells14727282009-04-03 16:42:42 +0100279 nfs_fscache_release_client_cookie(clp);
280
David Howells24c8dbb2006-08-22 20:06:10 -0400281 /* -EIO all pending I/O */
282 if (!IS_ERR(clp->cl_rpcclient))
283 rpc_shutdown_client(clp->cl_rpcclient);
284
Trond Myklebust7c67db32008-04-07 20:50:11 -0400285 if (clp->cl_machine_cred != NULL)
286 put_rpccred(clp->cl_machine_cred);
287
David Howells24c8dbb2006-08-22 20:06:10 -0400288 kfree(clp->cl_hostname);
289 kfree(clp);
290
291 dprintk("<-- nfs_free_client()\n");
292}
293
294/*
295 * Release a reference to a shared client record
296 */
297void nfs_put_client(struct nfs_client *clp)
298{
David Howells27ba8512006-07-30 14:40:56 -0400299 if (!clp)
300 return;
301
David Howells24c8dbb2006-08-22 20:06:10 -0400302 dprintk("--> nfs_put_client({%d})\n", atomic_read(&clp->cl_count));
303
304 if (atomic_dec_and_lock(&clp->cl_count, &nfs_client_lock)) {
305 list_del(&clp->cl_share_link);
Andy Adamsonf4eecd52011-01-06 02:04:30 +0000306 nfs_cb_idr_remove_locked(clp);
David Howells24c8dbb2006-08-22 20:06:10 -0400307 spin_unlock(&nfs_client_lock);
308
309 BUG_ON(!list_empty(&clp->cl_superblocks));
310
311 nfs_free_client(clp);
312 }
313}
Andy Adamson16b374c2010-10-20 00:18:04 -0400314EXPORT_SYMBOL_GPL(nfs_put_client);
David Howells24c8dbb2006-08-22 20:06:10 -0400315
Trond Myklebust9082a5c2008-12-23 15:21:53 -0500316#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
Trond Myklebust9f4c899c2009-03-12 14:51:32 -0400317/*
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
324 * sin6_scope_id.
325 *
326 * The caller should ensure both socket addresses are AF_INET6.
327 */
Chuck Lever3c8c45d2009-03-18 20:48:14 -0400328static int nfs_sockaddr_match_ipaddr6(const struct sockaddr *sa1,
329 const struct sockaddr *sa2)
Trond Myklebust9f4c899c2009-03-12 14:51:32 -0400330{
Chuck Lever3c8c45d2009-03-18 20:48:14 -0400331 const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sa1;
332 const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sa2;
Trond Myklebust9f4c899c2009-03-12 14:51:32 -0400333
Chuck Lever3c8c45d2009-03-18 20:48:14 -0400334 if (ipv6_addr_scope(&sin1->sin6_addr) == IPV6_ADDR_SCOPE_LINKLOCAL &&
335 sin1->sin6_scope_id != sin2->sin6_scope_id)
Trond Myklebust9f4c899c2009-03-12 14:51:32 -0400336 return 0;
Trond Myklebust3b0d3f92008-01-03 13:28:58 -0500337
Trond Myklebustb20d37c2010-09-12 19:55:26 -0400338 return ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr);
Trond Myklebust3b0d3f92008-01-03 13:28:58 -0500339}
Chuck Lever3c8c45d2009-03-18 20:48:14 -0400340#else /* !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE) */
341static int nfs_sockaddr_match_ipaddr6(const struct sockaddr *sa1,
342 const struct sockaddr *sa2)
Trond Myklebust9f4c899c2009-03-12 14:51:32 -0400343{
344 return 0;
345}
Trond Myklebust9082a5c2008-12-23 15:21:53 -0500346#endif
Trond Myklebust3b0d3f92008-01-03 13:28:58 -0500347
David Howells24c8dbb2006-08-22 20:06:10 -0400348/*
Ian Dalld7371c42009-03-10 20:33:22 -0400349 * Test if two ip4 socket addresses refer to the same socket, by
350 * comparing relevant fields. The padding bytes specifically, are
351 * not compared.
352 *
353 * The caller should ensure both socket addresses are AF_INET.
354 */
Chuck Lever3c8c45d2009-03-18 20:48:14 -0400355static int nfs_sockaddr_match_ipaddr4(const struct sockaddr *sa1,
356 const struct sockaddr *sa2)
357{
358 const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sa1;
359 const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sa2;
360
361 return sin1->sin_addr.s_addr == sin2->sin_addr.s_addr;
362}
363
364static int nfs_sockaddr_cmp_ip6(const struct sockaddr *sa1,
365 const struct sockaddr *sa2)
366{
367 const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sa1;
368 const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sa2;
369
370 return nfs_sockaddr_match_ipaddr6(sa1, sa2) &&
371 (sin1->sin6_port == sin2->sin6_port);
372}
373
Trond Myklebust9f4c899c2009-03-12 14:51:32 -0400374static int nfs_sockaddr_cmp_ip4(const struct sockaddr *sa1,
375 const struct sockaddr *sa2)
Ian Dalld7371c42009-03-10 20:33:22 -0400376{
Chuck Lever3c8c45d2009-03-18 20:48:14 -0400377 const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sa1;
378 const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sa2;
Trond Myklebust9f4c899c2009-03-12 14:51:32 -0400379
Chuck Lever3c8c45d2009-03-18 20:48:14 -0400380 return nfs_sockaddr_match_ipaddr4(sa1, sa2) &&
381 (sin1->sin_port == sin2->sin_port);
Ian Dalld7371c42009-03-10 20:33:22 -0400382}
383
384/*
Ian Dalld7371c42009-03-10 20:33:22 -0400385 * Test if two socket addresses represent the same actual socket,
Chuck Lever3c8c45d2009-03-18 20:48:14 -0400386 * by comparing (only) relevant fields, excluding the port number.
387 */
388static int nfs_sockaddr_match_ipaddr(const struct sockaddr *sa1,
389 const struct sockaddr *sa2)
390{
391 if (sa1->sa_family != sa2->sa_family)
392 return 0;
393
394 switch (sa1->sa_family) {
395 case AF_INET:
396 return nfs_sockaddr_match_ipaddr4(sa1, sa2);
397 case AF_INET6:
398 return nfs_sockaddr_match_ipaddr6(sa1, sa2);
399 }
400 return 0;
401}
402
403/*
404 * Test if two socket addresses represent the same actual socket,
405 * by comparing (only) relevant fields, including the port number.
Ian Dalld7371c42009-03-10 20:33:22 -0400406 */
407static int nfs_sockaddr_cmp(const struct sockaddr *sa1,
408 const struct sockaddr *sa2)
409{
410 if (sa1->sa_family != sa2->sa_family)
411 return 0;
412
413 switch (sa1->sa_family) {
414 case AF_INET:
Trond Myklebust9f4c899c2009-03-12 14:51:32 -0400415 return nfs_sockaddr_cmp_ip4(sa1, sa2);
Ian Dalld7371c42009-03-10 20:33:22 -0400416 case AF_INET6:
Trond Myklebust9f4c899c2009-03-12 14:51:32 -0400417 return nfs_sockaddr_cmp_ip6(sa1, sa2);
Ian Dalld7371c42009-03-10 20:33:22 -0400418 }
419 return 0;
420}
421
Andy Adamsonc36fca52011-01-06 02:04:32 +0000422/* Common match routine for v4.0 and v4.1 callback services */
423bool
424nfs4_cb_match_client(const struct sockaddr *addr, struct nfs_client *clp,
425 u32 minorversion)
Trond Myklebustc81468a2007-12-14 14:56:05 -0500426{
Andy Adamsonc36fca52011-01-06 02:04:32 +0000427 struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr;
Trond Myklebustc81468a2007-12-14 14:56:05 -0500428
Andy Adamsonc36fca52011-01-06 02:04:32 +0000429 /* 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))
432 return false;
Trond Myklebust3b0d3f92008-01-03 13:28:58 -0500433
Andy Adamsonc36fca52011-01-06 02:04:32 +0000434 /* Match the version and minorversion */
435 if (clp->rpc_ops->version != 4 ||
436 clp->cl_minorversion != minorversion)
437 return false;
Trond Myklebustc81468a2007-12-14 14:56:05 -0500438
Andy Adamsonc36fca52011-01-06 02:04:32 +0000439 /* Match only the IP address, not the port number */
440 if (!nfs_sockaddr_match_ipaddr(addr, clap))
441 return false;
Trond Myklebustc81468a2007-12-14 14:56:05 -0500442
Andy Adamsonc36fca52011-01-06 02:04:32 +0000443 return true;
Trond Myklebust3fbd67a2008-01-26 01:06:40 -0500444}
445
446/*
Trond Myklebustc81468a2007-12-14 14:56:05 -0500447 * Find an nfs_client on the list that matches the initialisation data
448 * that is supplied.
449 */
450static struct nfs_client *nfs_match_client(const struct nfs_client_initdata *data)
David Howells24c8dbb2006-08-22 20:06:10 -0400451{
452 struct nfs_client *clp;
Ian Dalld7371c42009-03-10 20:33:22 -0400453 const struct sockaddr *sap = data->addr;
David Howells24c8dbb2006-08-22 20:06:10 -0400454
455 list_for_each_entry(clp, &nfs_client_list, cl_share_link) {
Ian Dalld7371c42009-03-10 20:33:22 -0400456 const struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr;
Trond Myklebust13bbc062006-10-19 23:28:40 -0700457 /* Don't match clients that failed to initialise properly */
458 if (clp->cl_cons_state < 0)
459 continue;
460
David Howells24c8dbb2006-08-22 20:06:10 -0400461 /* Different NFS versions cannot share the same nfs_client */
Trond Myklebust40c553192007-12-14 14:56:07 -0500462 if (clp->rpc_ops != data->rpc_ops)
David Howells24c8dbb2006-08-22 20:06:10 -0400463 continue;
464
Trond Myklebust59dca3b2008-01-03 16:29:06 -0500465 if (clp->cl_proto != data->proto)
466 continue;
Benny Halevy5aae4a92009-04-01 09:21:50 -0400467 /* Match nfsv4 minorversion */
468 if (clp->cl_minorversion != data->minorversion)
469 continue;
Trond Myklebustc81468a2007-12-14 14:56:05 -0500470 /* Match the full socket address */
Ian Dalld7371c42009-03-10 20:33:22 -0400471 if (!nfs_sockaddr_cmp(sap, clap))
David Howells24c8dbb2006-08-22 20:06:10 -0400472 continue;
473
Trond Myklebustc81468a2007-12-14 14:56:05 -0500474 atomic_inc(&clp->cl_count);
475 return clp;
David Howells24c8dbb2006-08-22 20:06:10 -0400476 }
David Howells24c8dbb2006-08-22 20:06:10 -0400477 return NULL;
David Howells24c8dbb2006-08-22 20:06:10 -0400478}
479
480/*
481 * Look up a client by IP address and protocol version
482 * - creates a new record if one doesn't yet exist
483 */
Andy Adamson45a52a02011-03-01 01:34:08 +0000484static struct nfs_client *
485nfs_get_client(const struct nfs_client_initdata *cl_init,
486 const struct rpc_timeout *timeparms,
487 const char *ip_addr,
488 rpc_authflavor_t authflavour,
489 int noresvport)
David Howells24c8dbb2006-08-22 20:06:10 -0400490{
491 struct nfs_client *clp, *new = NULL;
492 int error;
493
Chuck Leverd7422c42007-12-10 14:58:51 -0500494 dprintk("--> nfs_get_client(%s,v%u)\n",
495 cl_init->hostname ?: "", cl_init->rpc_ops->version);
David Howells24c8dbb2006-08-22 20:06:10 -0400496
497 /* see if the client already exists */
498 do {
499 spin_lock(&nfs_client_lock);
500
Trond Myklebustc81468a2007-12-14 14:56:05 -0500501 clp = nfs_match_client(cl_init);
David Howells24c8dbb2006-08-22 20:06:10 -0400502 if (clp)
503 goto found_client;
504 if (new)
505 goto install_client;
506
507 spin_unlock(&nfs_client_lock);
508
Trond Myklebust3a498022007-12-14 14:56:04 -0500509 new = nfs_alloc_client(cl_init);
Chuck Levera21bdd92009-06-17 18:02:10 -0700510 } while (!IS_ERR(new));
David Howells24c8dbb2006-08-22 20:06:10 -0400511
Chuck Levera21bdd92009-06-17 18:02:10 -0700512 dprintk("--> nfs_get_client() = %ld [failed]\n", PTR_ERR(new));
513 return new;
David Howells24c8dbb2006-08-22 20:06:10 -0400514
515 /* install a new client and return with it unready */
516install_client:
517 clp = new;
518 list_add(&clp->cl_share_link, &nfs_client_list);
519 spin_unlock(&nfs_client_lock);
Andy Adamson45a52a02011-03-01 01:34:08 +0000520
521 error = cl_init->rpc_ops->init_client(clp, timeparms, ip_addr,
522 authflavour, noresvport);
523 if (error < 0) {
524 nfs_put_client(clp);
525 return ERR_PTR(error);
526 }
David Howells24c8dbb2006-08-22 20:06:10 -0400527 dprintk("--> nfs_get_client() = %p [new]\n", clp);
528 return clp;
529
530 /* found an existing client
531 * - make sure it's ready before returning
532 */
533found_client:
534 spin_unlock(&nfs_client_lock);
535
536 if (new)
537 nfs_free_client(new);
538
Matthew Wilcox150030b2007-12-06 16:24:39 -0500539 error = wait_event_killable(nfs_client_active_wq,
Andy Adamson76db6d92009-04-01 09:22:38 -0400540 clp->cl_cons_state < NFS_CS_INITING);
Trond Myklebust0bae89e2006-10-08 14:33:24 -0400541 if (error < 0) {
542 nfs_put_client(clp);
543 return ERR_PTR(-ERESTARTSYS);
David Howells24c8dbb2006-08-22 20:06:10 -0400544 }
545
546 if (clp->cl_cons_state < NFS_CS_READY) {
547 error = clp->cl_cons_state;
548 nfs_put_client(clp);
549 return ERR_PTR(error);
550 }
551
David Howells54ceac42006-08-22 20:06:13 -0400552 BUG_ON(clp->cl_cons_state != NFS_CS_READY);
553
David Howells24c8dbb2006-08-22 20:06:10 -0400554 dprintk("--> nfs_get_client() = %p [share]\n", clp);
555 return clp;
556}
557
558/*
559 * Mark a server as ready or failed
560 */
Andy Adamson76db6d92009-04-01 09:22:38 -0400561void nfs_mark_client_ready(struct nfs_client *clp, int state)
David Howells24c8dbb2006-08-22 20:06:10 -0400562{
563 clp->cl_cons_state = state;
564 wake_up_all(&nfs_client_active_wq);
565}
David Howells5006a762006-08-22 20:06:12 -0400566
567/*
Benny Halevy008f55d2009-04-01 09:22:50 -0400568 * With sessions, the client is not marked ready until after a
569 * successful EXCHANGE_ID and CREATE_SESSION.
570 *
571 * Map errors cl_cons_state errors to EPROTONOSUPPORT to indicate
572 * other versions of NFS can be tried.
573 */
574int nfs4_check_client_ready(struct nfs_client *clp)
575{
576 if (!nfs4_has_session(clp))
577 return 0;
578 if (clp->cl_cons_state < NFS_CS_READY)
579 return -EPROTONOSUPPORT;
580 return 0;
581}
582
583/*
David Howells5006a762006-08-22 20:06:12 -0400584 * Initialise the timeout values for a connection
585 */
586static void nfs_init_timeout_values(struct rpc_timeout *to, int proto,
587 unsigned int timeo, unsigned int retrans)
588{
589 to->to_initval = timeo * HZ / 10;
590 to->to_retries = retrans;
David Howells5006a762006-08-22 20:06:12 -0400591
592 switch (proto) {
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400593 case XPRT_TRANSPORT_TCP:
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400594 case XPRT_TRANSPORT_RDMA:
Trond Myklebust259875e2008-07-02 14:43:47 -0400595 if (to->to_retries == 0)
596 to->to_retries = NFS_DEF_TCP_RETRANS;
Trond Myklebust7a3e3e12007-12-20 16:03:57 -0500597 if (to->to_initval == 0)
Trond Myklebust259875e2008-07-02 14:43:47 -0400598 to->to_initval = NFS_DEF_TCP_TIMEO * HZ / 10;
David Howells5006a762006-08-22 20:06:12 -0400599 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);
Trond Myklebust7a3e3e12007-12-20 16:03:57 -0500603 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;
David Howells5006a762006-08-22 20:06:12 -0400607 to->to_exponential = 0;
608 break;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400609 case XPRT_TRANSPORT_UDP:
Trond Myklebust259875e2008-07-02 14:43:47 -0400610 if (to->to_retries == 0)
611 to->to_retries = NFS_DEF_UDP_RETRANS;
David Howells5006a762006-08-22 20:06:12 -0400612 if (!to->to_initval)
Trond Myklebust259875e2008-07-02 14:43:47 -0400613 to->to_initval = NFS_DEF_UDP_TIMEO * HZ / 10;
David Howells5006a762006-08-22 20:06:12 -0400614 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;
618 break;
Trond Myklebust259875e2008-07-02 14:43:47 -0400619 default:
620 BUG();
David Howells5006a762006-08-22 20:06:12 -0400621 }
622}
623
624/*
625 * Create an RPC client handle
626 */
Trond Myklebust59dca3b2008-01-03 16:29:06 -0500627static int nfs_create_rpc_client(struct nfs_client *clp,
Trond Myklebust33170232007-12-20 16:03:59 -0500628 const struct rpc_timeout *timeparms,
629 rpc_authflavor_t flavor,
Chuck Lever4a01b8a2008-12-23 15:21:35 -0500630 int discrtry, int noresvport)
David Howells5006a762006-08-22 20:06:12 -0400631{
David Howells5006a762006-08-22 20:06:12 -0400632 struct rpc_clnt *clnt = NULL;
Chuck Lever41877d22006-08-22 20:06:20 -0400633 struct rpc_create_args args = {
Pavel Emelyanovc653ce32010-09-29 16:04:45 +0400634 .net = &init_net,
Trond Myklebust59dca3b2008-01-03 16:29:06 -0500635 .protocol = clp->cl_proto,
Chuck Lever41877d22006-08-22 20:06:20 -0400636 .address = (struct sockaddr *)&clp->cl_addr,
Chuck Lever6e4cffd2007-12-10 14:58:15 -0500637 .addrsize = clp->cl_addrlen,
Trond Myklebust33170232007-12-20 16:03:59 -0500638 .timeout = timeparms,
Chuck Lever41877d22006-08-22 20:06:20 -0400639 .servername = clp->cl_hostname,
640 .program = &nfs_program,
641 .version = clp->rpc_ops->version,
642 .authflavor = flavor,
643 };
David Howells5006a762006-08-22 20:06:12 -0400644
Chuck Lever4a01b8a2008-12-23 15:21:35 -0500645 if (discrtry)
646 args.flags |= RPC_CLNT_CREATE_DISCRTRY;
647 if (noresvport)
648 args.flags |= RPC_CLNT_CREATE_NONPRIVPORT;
649
David Howells5006a762006-08-22 20:06:12 -0400650 if (!IS_ERR(clp->cl_rpcclient))
651 return 0;
652
Chuck Lever41877d22006-08-22 20:06:20 -0400653 clnt = rpc_create(&args);
David Howells5006a762006-08-22 20:06:12 -0400654 if (IS_ERR(clnt)) {
655 dprintk("%s: cannot create RPC client. Error = %ld\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -0700656 __func__, PTR_ERR(clnt));
David Howells5006a762006-08-22 20:06:12 -0400657 return PTR_ERR(clnt);
658 }
659
David Howells5006a762006-08-22 20:06:12 -0400660 clp->cl_rpcclient = clnt;
661 return 0;
662}
David Howells54ceac42006-08-22 20:06:13 -0400663
664/*
665 * Version 2 or 3 client destruction
666 */
667static void nfs_destroy_server(struct nfs_server *server)
668{
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400669 if (!(server->flags & NFS_MOUNT_LOCAL_FLOCK) ||
670 !(server->flags & NFS_MOUNT_LOCAL_FCNTL))
Chuck Lever9289e7f2008-01-11 17:09:52 -0500671 nlmclnt_done(server->nlm_host);
David Howells54ceac42006-08-22 20:06:13 -0400672}
673
674/*
675 * Version 2 or 3 lockd setup
676 */
677static int nfs_start_lockd(struct nfs_server *server)
678{
Chuck Lever9289e7f2008-01-11 17:09:52 -0500679 struct nlm_host *host;
680 struct nfs_client *clp = server->nfs_client;
Chuck Lever883bb162008-01-15 16:04:20 -0500681 struct nlmclnt_initdata nlm_init = {
682 .hostname = clp->cl_hostname,
683 .address = (struct sockaddr *)&clp->cl_addr,
684 .addrlen = clp->cl_addrlen,
Chuck Lever883bb162008-01-15 16:04:20 -0500685 .nfs_version = clp->rpc_ops->version,
Chuck Lever0cb26592008-12-23 15:21:38 -0500686 .noresvport = server->flags & NFS_MOUNT_NORESVPORT ?
687 1 : 0,
Chuck Lever883bb162008-01-15 16:04:20 -0500688 };
David Howells54ceac42006-08-22 20:06:13 -0400689
Chuck Lever883bb162008-01-15 16:04:20 -0500690 if (nlm_init.nfs_version > 3)
Chuck Lever9289e7f2008-01-11 17:09:52 -0500691 return 0;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400692 if ((server->flags & NFS_MOUNT_LOCAL_FLOCK) &&
693 (server->flags & NFS_MOUNT_LOCAL_FCNTL))
Chuck Lever9289e7f2008-01-11 17:09:52 -0500694 return 0;
695
Trond Myklebust8a6e5de2009-09-23 14:36:37 -0400696 switch (clp->cl_proto) {
697 default:
698 nlm_init.protocol = IPPROTO_TCP;
699 break;
700 case XPRT_TRANSPORT_UDP:
701 nlm_init.protocol = IPPROTO_UDP;
702 }
703
Chuck Lever883bb162008-01-15 16:04:20 -0500704 host = nlmclnt_init(&nlm_init);
Chuck Lever9289e7f2008-01-11 17:09:52 -0500705 if (IS_ERR(host))
706 return PTR_ERR(host);
707
708 server->nlm_host = host;
709 server->destroy = nfs_destroy_server;
710 return 0;
David Howells54ceac42006-08-22 20:06:13 -0400711}
712
713/*
714 * Initialise an NFSv3 ACL client connection
715 */
716#ifdef CONFIG_NFS_V3_ACL
717static void nfs_init_server_aclclient(struct nfs_server *server)
718{
Trond Myklebust40c553192007-12-14 14:56:07 -0500719 if (server->nfs_client->rpc_ops->version != 3)
David Howells54ceac42006-08-22 20:06:13 -0400720 goto out_noacl;
721 if (server->flags & NFS_MOUNT_NOACL)
722 goto out_noacl;
723
724 server->client_acl = rpc_bind_new_program(server->client, &nfsacl_program, 3);
725 if (IS_ERR(server->client_acl))
726 goto out_noacl;
727
728 /* No errors! Assume that Sun nfsacls are supported */
729 server->caps |= NFS_CAP_ACLS;
730 return;
731
732out_noacl:
733 server->caps &= ~NFS_CAP_ACLS;
734}
735#else
736static inline void nfs_init_server_aclclient(struct nfs_server *server)
737{
738 server->flags &= ~NFS_MOUNT_NOACL;
739 server->caps &= ~NFS_CAP_ACLS;
740}
741#endif
742
743/*
744 * Create a general RPC client
745 */
Trond Myklebust33170232007-12-20 16:03:59 -0500746static int nfs_init_server_rpcclient(struct nfs_server *server,
747 const struct rpc_timeout *timeo,
748 rpc_authflavor_t pseudoflavour)
David Howells54ceac42006-08-22 20:06:13 -0400749{
750 struct nfs_client *clp = server->nfs_client;
751
752 server->client = rpc_clone_client(clp->cl_rpcclient);
753 if (IS_ERR(server->client)) {
Harvey Harrison3110ff82008-05-02 13:42:44 -0700754 dprintk("%s: couldn't create rpc_client!\n", __func__);
David Howells54ceac42006-08-22 20:06:13 -0400755 return PTR_ERR(server->client);
756 }
757
Trond Myklebust33170232007-12-20 16:03:59 -0500758 memcpy(&server->client->cl_timeout_default,
759 timeo,
760 sizeof(server->client->cl_timeout_default));
761 server->client->cl_timeout = &server->client->cl_timeout_default;
762
David Howells54ceac42006-08-22 20:06:13 -0400763 if (pseudoflavour != clp->cl_rpcclient->cl_auth->au_flavor) {
764 struct rpc_auth *auth;
765
766 auth = rpcauth_create(pseudoflavour, server->client);
767 if (IS_ERR(auth)) {
Harvey Harrison3110ff82008-05-02 13:42:44 -0700768 dprintk("%s: couldn't create credcache!\n", __func__);
David Howells54ceac42006-08-22 20:06:13 -0400769 return PTR_ERR(auth);
770 }
771 }
772 server->client->cl_softrtry = 0;
773 if (server->flags & NFS_MOUNT_SOFT)
774 server->client->cl_softrtry = 1;
775
David Howells54ceac42006-08-22 20:06:13 -0400776 return 0;
777}
778
779/*
780 * Initialise an NFS2 or NFS3 client
781 */
Andy Adamson45a52a02011-03-01 01:34:08 +0000782int nfs_init_client(struct nfs_client *clp, const struct rpc_timeout *timeparms,
783 const char *ip_addr, rpc_authflavor_t authflavour,
784 int noresvport)
David Howells54ceac42006-08-22 20:06:13 -0400785{
David Howells54ceac42006-08-22 20:06:13 -0400786 int error;
787
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);
791 return 0;
792 }
793
David Howells54ceac42006-08-22 20:06:13 -0400794 /*
795 * Create a client RPC handle for doing FSSTAT with UNIX auth only
796 * - RFC 2623, sec 2.3.2
797 */
Chuck Leverd7403512008-12-23 15:21:37 -0500798 error = nfs_create_rpc_client(clp, timeparms, RPC_AUTH_UNIX,
Andy Adamson45a52a02011-03-01 01:34:08 +0000799 0, noresvport);
David Howells54ceac42006-08-22 20:06:13 -0400800 if (error < 0)
801 goto error;
802 nfs_mark_client_ready(clp, NFS_CS_READY);
803 return 0;
804
805error:
806 nfs_mark_client_ready(clp, error);
807 dprintk("<-- nfs_init_client() = xerror %d\n", error);
808 return error;
809}
810
811/*
812 * Create a version 2 or 3 client
813 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -0400814static int nfs_init_server(struct nfs_server *server,
815 const struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -0400816{
Trond Myklebust3a498022007-12-14 14:56:04 -0500817 struct nfs_client_initdata cl_init = {
818 .hostname = data->nfs_server.hostname,
Chuck Leverd7422c42007-12-10 14:58:51 -0500819 .addr = (const struct sockaddr *)&data->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -0500820 .addrlen = data->nfs_server.addrlen,
Trond Myklebust40c553192007-12-14 14:56:07 -0500821 .rpc_ops = &nfs_v2_clientops,
Trond Myklebust59dca3b2008-01-03 16:29:06 -0500822 .proto = data->nfs_server.protocol,
Trond Myklebust3a498022007-12-14 14:56:04 -0500823 };
Trond Myklebust33170232007-12-20 16:03:59 -0500824 struct rpc_timeout timeparms;
David Howells54ceac42006-08-22 20:06:13 -0400825 struct nfs_client *clp;
Trond Myklebust3a498022007-12-14 14:56:04 -0500826 int error;
David Howells54ceac42006-08-22 20:06:13 -0400827
828 dprintk("--> nfs_init_server()\n");
829
830#ifdef CONFIG_NFS_V3
Trond Myklebust8a6e5de2009-09-23 14:36:37 -0400831 if (data->version == 3)
Trond Myklebust40c553192007-12-14 14:56:07 -0500832 cl_init.rpc_ops = &nfs_v3_clientops;
David Howells54ceac42006-08-22 20:06:13 -0400833#endif
834
Andy Adamson45a52a02011-03-01 01:34:08 +0000835 nfs_init_timeout_values(&timeparms, data->nfs_server.protocol,
836 data->timeo, data->retrans);
837
David Howells54ceac42006-08-22 20:06:13 -0400838 /* Allocate or find a client reference we can use */
Andy Adamson45a52a02011-03-01 01:34:08 +0000839 clp = nfs_get_client(&cl_init, &timeparms, NULL, RPC_AUTH_UNIX,
840 data->flags & NFS_MOUNT_NORESVPORT);
David Howells54ceac42006-08-22 20:06:13 -0400841 if (IS_ERR(clp)) {
842 dprintk("<-- nfs_init_server() = error %ld\n", PTR_ERR(clp));
843 return PTR_ERR(clp);
844 }
845
David Howells54ceac42006-08-22 20:06:13 -0400846 server->nfs_client = clp;
847
848 /* Initialise the client representation from the mount data */
Trond Myklebustff3525a2008-08-15 16:59:14 -0400849 server->flags = data->flags;
David Howellsb797cac2009-04-03 16:42:48 +0100850 server->options = data->options;
Trond Myklebust62ab4602009-08-09 15:06:19 -0400851 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;
David Howells54ceac42006-08-22 20:06:13 -0400854
855 if (data->rsize)
856 server->rsize = nfs_block_size(data->rsize, NULL);
857 if (data->wsize)
858 server->wsize = nfs_block_size(data->wsize, NULL);
859
860 server->acregmin = data->acregmin * HZ;
861 server->acregmax = data->acregmax * HZ;
862 server->acdirmin = data->acdirmin * HZ;
863 server->acdirmax = data->acdirmax * HZ;
864
865 /* Start lockd here, before we might error out */
866 error = nfs_start_lockd(server);
867 if (error < 0)
868 goto error;
869
Chuck Leverf22d6d72008-03-14 14:10:22 -0400870 server->port = data->nfs_server.port;
871
Trond Myklebust33170232007-12-20 16:03:59 -0500872 error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]);
David Howells54ceac42006-08-22 20:06:13 -0400873 if (error < 0)
874 goto error;
875
Chuck Lever3f8400d2008-03-14 14:10:30 -0400876 /* 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;
881 }
882 server->mountd_version = data->mount_server.version;
883 server->mountd_port = data->mount_server.port;
884 server->mountd_protocol = data->mount_server.protocol;
885
David Howells54ceac42006-08-22 20:06:13 -0400886 server->namelen = data->namlen;
887 /* Create a client RPC handle for the NFSv3 ACL management interface */
888 nfs_init_server_aclclient(server);
David Howells54ceac42006-08-22 20:06:13 -0400889 dprintk("<-- nfs_init_server() = 0 [new %p]\n", clp);
890 return 0;
891
892error:
893 server->nfs_client = NULL;
894 nfs_put_client(clp);
895 dprintk("<-- nfs_init_server() = xerror %d\n", error);
896 return error;
897}
898
899/*
900 * Load up the server record from information gained in an fsinfo record
901 */
902static void nfs_server_set_fsinfo(struct nfs_server *server, struct nfs_fsinfo *fsinfo)
903{
904 unsigned long max_rpc_payload;
905
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);
911
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);
916
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;
Peter Zijlstrae0bf68d2007-10-16 23:25:46 -0700923
Jens Axboed9938312009-06-12 14:45:52 +0200924 server->backing_dev_info.name = "nfs";
David Howells54ceac42006-08-22 20:06:13 -0400925 server->backing_dev_info.ra_pages = server->rpages * NFS_MAX_READAHEAD;
926
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;
Ricardo Labiaga85e174b2010-10-20 00:17:58 -0400932 set_pnfs_layoutdriver(server, fsinfo->layouttype);
933
David Howells54ceac42006-08-22 20:06:13 -0400934 server->wtmult = nfs_block_bits(fsinfo->wtmult, NULL);
935
936 server->dtsize = nfs_block_size(fsinfo->dtpref, NULL);
Bryan Schumaker56e4ebf2010-10-20 15:44:37 -0400937 if (server->dtsize > PAGE_CACHE_SIZE * NFS_MAX_READDIR_PAGES)
938 server->dtsize = PAGE_CACHE_SIZE * NFS_MAX_READDIR_PAGES;
David Howells54ceac42006-08-22 20:06:13 -0400939 if (server->dtsize > server->rsize)
940 server->dtsize = server->rsize;
941
942 if (server->flags & NFS_MOUNT_NOAC) {
943 server->acregmin = server->acregmax = 0;
944 server->acdirmin = server->acdirmax = 0;
945 }
946
947 server->maxfilesize = fsinfo->maxfilesize;
948
Ricardo Labiaga6b967242010-10-12 16:30:05 -0700949 server->time_delta = fsinfo->time_delta;
950
David Howells54ceac42006-08-22 20:06:13 -0400951 /* We're airborne Set socket buffersize */
952 rpc_setbufsize(server->client, server->wsize + 100, server->rsize + 100);
953}
954
955/*
956 * Probe filesystem information, including the FSID on v2/v3
957 */
958static int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *mntfh, struct nfs_fattr *fattr)
959{
960 struct nfs_fsinfo fsinfo;
961 struct nfs_client *clp = server->nfs_client;
962 int error;
963
964 dprintk("--> nfs_probe_fsinfo()\n");
965
966 if (clp->rpc_ops->set_capabilities != NULL) {
967 error = clp->rpc_ops->set_capabilities(server, mntfh);
968 if (error < 0)
969 goto out_error;
970 }
971
972 fsinfo.fattr = fattr;
Ricardo Labiaga85e174b2010-10-20 00:17:58 -0400973 fsinfo.layouttype = 0;
David Howells54ceac42006-08-22 20:06:13 -0400974 error = clp->rpc_ops->fsinfo(server, mntfh, &fsinfo);
975 if (error < 0)
976 goto out_error;
977
978 nfs_server_set_fsinfo(server, &fsinfo);
979
980 /* Get some general file system info */
981 if (server->namelen == 0) {
982 struct nfs_pathconf pathinfo;
983
984 pathinfo.fattr = fattr;
985 nfs_fattr_init(fattr);
986
987 if (clp->rpc_ops->pathconf(server, mntfh, &pathinfo) >= 0)
988 server->namelen = pathinfo.max_namelen;
989 }
990
991 dprintk("<-- nfs_probe_fsinfo() = 0\n");
992 return 0;
993
994out_error:
995 dprintk("nfs_probe_fsinfo: error = %d\n", -error);
996 return error;
997}
998
999/*
1000 * Copy useful information when duplicating a server record
1001 */
1002static void nfs_server_copy_userdata(struct nfs_server *target, struct nfs_server *source)
1003{
1004 target->flags = source->flags;
Chuck Lever356e76b2010-04-22 15:35:56 -04001005 target->rsize = source->rsize;
1006 target->wsize = source->wsize;
David Howells54ceac42006-08-22 20:06:13 -04001007 target->acregmin = source->acregmin;
1008 target->acregmax = source->acregmax;
1009 target->acdirmin = source->acdirmin;
1010 target->acdirmax = source->acdirmax;
1011 target->caps = source->caps;
David Howells2df54802009-09-23 14:36:39 -04001012 target->options = source->options;
David Howells54ceac42006-08-22 20:06:13 -04001013}
1014
Chuck Leverfca52382010-12-24 01:32:32 +00001015static void nfs_server_insert_lists(struct nfs_server *server)
1016{
1017 struct nfs_client *clp = server->nfs_client;
1018
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 spin_unlock(&nfs_client_lock);
1023
1024}
1025
1026static void nfs_server_remove_lists(struct nfs_server *server)
1027{
1028 spin_lock(&nfs_client_lock);
1029 list_del_rcu(&server->client_link);
1030 list_del(&server->master_link);
1031 spin_unlock(&nfs_client_lock);
1032
1033 synchronize_rcu();
1034}
1035
David Howells54ceac42006-08-22 20:06:13 -04001036/*
1037 * Allocate and initialise a server record
1038 */
1039static struct nfs_server *nfs_alloc_server(void)
1040{
1041 struct nfs_server *server;
1042
1043 server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL);
1044 if (!server)
1045 return NULL;
1046
1047 server->client = server->client_acl = ERR_PTR(-EINVAL);
1048
1049 /* Zero out the NFS state stuff */
1050 INIT_LIST_HEAD(&server->client_link);
1051 INIT_LIST_HEAD(&server->master_link);
Chuck Leverd3978bb2010-12-24 01:33:04 +00001052 INIT_LIST_HEAD(&server->delegations);
David Howells54ceac42006-08-22 20:06:13 -04001053
Steve Dicksonef818a22007-11-08 04:05:04 -05001054 atomic_set(&server->active, 0);
1055
David Howells54ceac42006-08-22 20:06:13 -04001056 server->io_stats = nfs_alloc_iostats();
1057 if (!server->io_stats) {
1058 kfree(server);
1059 return NULL;
1060 }
1061
Jens Axboe48d07642009-09-21 09:59:39 +02001062 if (bdi_init(&server->backing_dev_info)) {
1063 nfs_free_iostats(server->io_stats);
1064 kfree(server);
1065 return NULL;
1066 }
1067
Fred Isamanf7e89172011-01-06 11:36:32 +00001068 pnfs_init_server(server);
1069
David Howells54ceac42006-08-22 20:06:13 -04001070 return server;
1071}
1072
1073/*
1074 * Free up a server record
1075 */
1076void nfs_free_server(struct nfs_server *server)
1077{
1078 dprintk("--> nfs_free_server()\n");
1079
Chuck Leverfca52382010-12-24 01:32:32 +00001080 nfs_server_remove_lists(server);
Ricardo Labiaga85e174b2010-10-20 00:17:58 -04001081 unset_pnfs_layoutdriver(server);
David Howells54ceac42006-08-22 20:06:13 -04001082
1083 if (server->destroy != NULL)
1084 server->destroy(server);
Trond Myklebust5cef3382007-12-11 22:01:56 -05001085
1086 if (!IS_ERR(server->client_acl))
1087 rpc_shutdown_client(server->client_acl);
David Howells54ceac42006-08-22 20:06:13 -04001088 if (!IS_ERR(server->client))
1089 rpc_shutdown_client(server->client);
1090
1091 nfs_put_client(server->nfs_client);
1092
1093 nfs_free_iostats(server->io_stats);
Peter Zijlstrae0bf68d2007-10-16 23:25:46 -07001094 bdi_destroy(&server->backing_dev_info);
David Howells54ceac42006-08-22 20:06:13 -04001095 kfree(server);
1096 nfs_release_automount_timer();
1097 dprintk("<-- nfs_free_server()\n");
1098}
1099
1100/*
1101 * Create a version 2 or 3 volume record
1102 * - keyed on server and FSID
1103 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001104struct nfs_server *nfs_create_server(const struct nfs_parsed_mount_data *data,
David Howells54ceac42006-08-22 20:06:13 -04001105 struct nfs_fh *mntfh)
1106{
1107 struct nfs_server *server;
Trond Myklebustfbca7792010-04-16 16:22:46 -04001108 struct nfs_fattr *fattr;
David Howells54ceac42006-08-22 20:06:13 -04001109 int error;
1110
1111 server = nfs_alloc_server();
1112 if (!server)
1113 return ERR_PTR(-ENOMEM);
1114
Trond Myklebustfbca7792010-04-16 16:22:46 -04001115 error = -ENOMEM;
1116 fattr = nfs_alloc_fattr();
1117 if (fattr == NULL)
1118 goto error;
1119
David Howells54ceac42006-08-22 20:06:13 -04001120 /* Get a client representation */
1121 error = nfs_init_server(server, data);
1122 if (error < 0)
1123 goto error;
1124
1125 BUG_ON(!server->nfs_client);
1126 BUG_ON(!server->nfs_client->rpc_ops);
1127 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
1128
1129 /* Probe the root fh to retrieve its FSID */
Trond Myklebustfbca7792010-04-16 16:22:46 -04001130 error = nfs_probe_fsinfo(server, mntfh, fattr);
David Howells54ceac42006-08-22 20:06:13 -04001131 if (error < 0)
1132 goto error;
Trond Myklebust54af3bb2007-09-28 12:27:41 -04001133 if (server->nfs_client->rpc_ops->version == 3) {
1134 if (server->namelen == 0 || server->namelen > NFS3_MAXNAMLEN)
1135 server->namelen = NFS3_MAXNAMLEN;
1136 if (!(data->flags & NFS_MOUNT_NORDIRPLUS))
1137 server->caps |= NFS_CAP_READDIRPLUS;
1138 } else {
1139 if (server->namelen == 0 || server->namelen > NFS2_MAXNAMLEN)
1140 server->namelen = NFS2_MAXNAMLEN;
1141 }
1142
Trond Myklebustfbca7792010-04-16 16:22:46 -04001143 if (!(fattr->valid & NFS_ATTR_FATTR)) {
1144 error = server->nfs_client->rpc_ops->getattr(server, mntfh, fattr);
David Howells54ceac42006-08-22 20:06:13 -04001145 if (error < 0) {
1146 dprintk("nfs_create_server: getattr error = %d\n", -error);
1147 goto error;
1148 }
1149 }
Trond Myklebustfbca7792010-04-16 16:22:46 -04001150 memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid));
David Howells54ceac42006-08-22 20:06:13 -04001151
David Howells6daabf12006-08-24 15:44:16 -04001152 dprintk("Server FSID: %llx:%llx\n",
1153 (unsigned long long) server->fsid.major,
1154 (unsigned long long) server->fsid.minor);
David Howells54ceac42006-08-22 20:06:13 -04001155
Chuck Leverfca52382010-12-24 01:32:32 +00001156 nfs_server_insert_lists(server);
David Howells54ceac42006-08-22 20:06:13 -04001157 server->mount_time = jiffies;
Trond Myklebustfbca7792010-04-16 16:22:46 -04001158 nfs_free_fattr(fattr);
David Howells54ceac42006-08-22 20:06:13 -04001159 return server;
1160
1161error:
Trond Myklebustfbca7792010-04-16 16:22:46 -04001162 nfs_free_fattr(fattr);
David Howells54ceac42006-08-22 20:06:13 -04001163 nfs_free_server(server);
1164 return ERR_PTR(error);
1165}
1166
1167#ifdef CONFIG_NFS_V4
1168/*
Andy Adamsonc36fca52011-01-06 02:04:32 +00001169 * NFSv4.0 callback thread helper
1170 *
1171 * Find a client by IP address, protocol version, and minorversion
1172 *
1173 * Called from the pg_authenticate method. The callback identifier
1174 * is not used as it has not been decoded.
1175 *
1176 * Returns NULL if no such client
1177 */
1178struct nfs_client *
1179nfs4_find_client_no_ident(const struct sockaddr *addr)
1180{
1181 struct nfs_client *clp;
1182
1183 spin_lock(&nfs_client_lock);
1184 list_for_each_entry(clp, &nfs_client_list, cl_share_link) {
1185 if (nfs4_cb_match_client(addr, clp, 0) == false)
1186 continue;
1187 atomic_inc(&clp->cl_count);
1188 spin_unlock(&nfs_client_lock);
1189 return clp;
1190 }
1191 spin_unlock(&nfs_client_lock);
1192 return NULL;
1193}
1194
1195/*
1196 * NFSv4.0 callback thread helper
1197 *
1198 * Find a client by callback identifier
1199 */
1200struct nfs_client *
1201nfs4_find_client_ident(int cb_ident)
1202{
1203 struct nfs_client *clp;
1204
1205 spin_lock(&nfs_client_lock);
1206 clp = idr_find(&cb_ident_idr, cb_ident);
1207 if (clp)
1208 atomic_inc(&clp->cl_count);
1209 spin_unlock(&nfs_client_lock);
1210 return clp;
1211}
1212
1213#if defined(CONFIG_NFS_V4_1)
1214/*
1215 * NFSv4.1 callback thread helper
1216 * For CB_COMPOUND calls, find a client by IP address, protocol version,
1217 * minorversion, and sessionID
1218 *
Andy Adamsonc36fca52011-01-06 02:04:32 +00001219 * Returns NULL if no such client
1220 */
1221struct nfs_client *
1222nfs4_find_client_sessionid(const struct sockaddr *addr,
Andy Adamson778be232011-01-25 15:38:01 +00001223 struct nfs4_sessionid *sid)
Andy Adamsonc36fca52011-01-06 02:04:32 +00001224{
1225 struct nfs_client *clp;
1226
1227 spin_lock(&nfs_client_lock);
1228 list_for_each_entry(clp, &nfs_client_list, cl_share_link) {
1229 if (nfs4_cb_match_client(addr, clp, 1) == false)
1230 continue;
1231
1232 if (!nfs4_has_session(clp))
1233 continue;
1234
Andy Adamson778be232011-01-25 15:38:01 +00001235 /* Match sessionid*/
1236 if (memcmp(clp->cl_session->sess_id.data,
1237 sid->data, NFS4_MAX_SESSIONID_LEN) != 0)
Andy Adamsonc36fca52011-01-06 02:04:32 +00001238 continue;
1239
1240 atomic_inc(&clp->cl_count);
1241 spin_unlock(&nfs_client_lock);
1242 return clp;
1243 }
1244 spin_unlock(&nfs_client_lock);
1245 return NULL;
1246}
1247
1248#else /* CONFIG_NFS_V4_1 */
1249
1250struct nfs_client *
1251nfs4_find_client_sessionid(const struct sockaddr *addr,
Andy Adamson778be232011-01-25 15:38:01 +00001252 struct nfs4_sessionid *sid)
Andy Adamsonc36fca52011-01-06 02:04:32 +00001253{
1254 return NULL;
1255}
1256#endif /* CONFIG_NFS_V4_1 */
1257
1258/*
Benny Halevy9bdaa862009-04-01 09:22:55 -04001259 * Initialize the NFS4 callback service
1260 */
1261static int nfs4_init_callback(struct nfs_client *clp)
1262{
1263 int error;
1264
1265 if (clp->rpc_ops->version == 4) {
Andy Adamson0b5b7ae2009-04-01 09:23:15 -04001266 if (nfs4_has_session(clp)) {
1267 error = xprt_setup_backchannel(
1268 clp->cl_rpcclient->cl_xprt,
1269 NFS41_BC_MIN_CALLBACKS);
1270 if (error < 0)
1271 return error;
1272 }
1273
Trond Myklebust97dc1352010-06-16 09:52:26 -04001274 error = nfs_callback_up(clp->cl_mvops->minor_version,
Benny Halevy71468512009-04-01 09:22:56 -04001275 clp->cl_rpcclient->cl_xprt);
Benny Halevy9bdaa862009-04-01 09:22:55 -04001276 if (error < 0) {
1277 dprintk("%s: failed to start callback. Error = %d\n",
1278 __func__, error);
1279 return error;
1280 }
1281 __set_bit(NFS_CS_CALLBACK, &clp->cl_res_state);
1282 }
1283 return 0;
1284}
1285
1286/*
Andy Adamson557134a2009-04-01 09:21:53 -04001287 * Initialize the minor version specific parts of an NFS4 client record
1288 */
1289static int nfs4_init_client_minor_version(struct nfs_client *clp)
1290{
1291#if defined(CONFIG_NFS_V4_1)
Trond Myklebust97dc1352010-06-16 09:52:26 -04001292 if (clp->cl_mvops->minor_version) {
Andy Adamson557134a2009-04-01 09:21:53 -04001293 struct nfs4_session *session = NULL;
1294 /*
1295 * Create the session and mark it expired.
1296 * When a SEQUENCE operation encounters the expired session
1297 * it will do session recovery to initialize it.
1298 */
1299 session = nfs4_alloc_session(clp);
1300 if (!session)
1301 return -ENOMEM;
1302
1303 clp->cl_session = session;
Trond Myklebustfe74ba32010-06-16 09:52:27 -04001304 /*
1305 * The create session reply races with the server back
1306 * channel probe. Mark the client NFS_CS_SESSION_INITING
1307 * so that the client back channel can find the
1308 * nfs_client struct
1309 */
1310 clp->cl_cons_state = NFS_CS_SESSION_INITING;
Andy Adamson557134a2009-04-01 09:21:53 -04001311 }
1312#endif /* CONFIG_NFS_V4_1 */
1313
Benny Halevy71468512009-04-01 09:22:56 -04001314 return nfs4_init_callback(clp);
Andy Adamson557134a2009-04-01 09:21:53 -04001315}
1316
1317/*
David Howells54ceac42006-08-22 20:06:13 -04001318 * Initialise an NFS4 client record
1319 */
Andy Adamson45a52a02011-03-01 01:34:08 +00001320int nfs4_init_client(struct nfs_client *clp,
1321 const struct rpc_timeout *timeparms,
1322 const char *ip_addr,
1323 rpc_authflavor_t authflavour,
1324 int noresvport)
David Howells54ceac42006-08-22 20:06:13 -04001325{
1326 int error;
1327
1328 if (clp->cl_cons_state == NFS_CS_READY) {
1329 /* the client is initialised already */
1330 dprintk("<-- nfs4_init_client() = 0 [already %p]\n", clp);
1331 return 0;
1332 }
1333
1334 /* Check NFS protocol revision and initialize RPC op vector */
1335 clp->rpc_ops = &nfs_v4_clientops;
1336
Trond Myklebust59dca3b2008-01-03 16:29:06 -05001337 error = nfs_create_rpc_client(clp, timeparms, authflavour,
Andy Adamson45a52a02011-03-01 01:34:08 +00001338 1, noresvport);
David Howells54ceac42006-08-22 20:06:13 -04001339 if (error < 0)
1340 goto error;
Ben Hutchingsf4373bf2009-10-06 15:42:18 -04001341 strlcpy(clp->cl_ipaddr, ip_addr, sizeof(clp->cl_ipaddr));
David Howells54ceac42006-08-22 20:06:13 -04001342
1343 error = nfs_idmap_new(clp);
1344 if (error < 0) {
1345 dprintk("%s: failed to create idmapper. Error = %d\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07001346 __func__, error);
David Howells54ceac42006-08-22 20:06:13 -04001347 goto error;
1348 }
Trond Myklebust9c5bf382006-08-22 20:06:14 -04001349 __set_bit(NFS_CS_IDMAP, &clp->cl_res_state);
David Howells54ceac42006-08-22 20:06:13 -04001350
Andy Adamson557134a2009-04-01 09:21:53 -04001351 error = nfs4_init_client_minor_version(clp);
1352 if (error < 0)
1353 goto error;
1354
Andy Adamson76db6d92009-04-01 09:22:38 -04001355 if (!nfs4_has_session(clp))
1356 nfs_mark_client_ready(clp, NFS_CS_READY);
David Howells54ceac42006-08-22 20:06:13 -04001357 return 0;
1358
1359error:
1360 nfs_mark_client_ready(clp, error);
1361 dprintk("<-- nfs4_init_client() = xerror %d\n", error);
1362 return error;
1363}
1364
1365/*
1366 * Set up an NFS4 client
1367 */
1368static int nfs4_set_client(struct nfs_server *server,
Chuck Leverdcecae02007-12-10 14:58:59 -05001369 const char *hostname,
1370 const struct sockaddr *addr,
1371 const size_t addrlen,
J. Bruce Fields7d9ac062006-10-19 23:28:39 -07001372 const char *ip_addr,
David Howells54ceac42006-08-22 20:06:13 -04001373 rpc_authflavor_t authflavour,
Benny Halevy94a417f2009-04-01 09:21:49 -04001374 int proto, const struct rpc_timeout *timeparms,
1375 u32 minorversion)
David Howells54ceac42006-08-22 20:06:13 -04001376{
Trond Myklebust3a498022007-12-14 14:56:04 -05001377 struct nfs_client_initdata cl_init = {
1378 .hostname = hostname,
Chuck Leverdcecae02007-12-10 14:58:59 -05001379 .addr = addr,
1380 .addrlen = addrlen,
Trond Myklebust40c553192007-12-14 14:56:07 -05001381 .rpc_ops = &nfs_v4_clientops,
Trond Myklebust59dca3b2008-01-03 16:29:06 -05001382 .proto = proto,
Benny Halevy5aae4a92009-04-01 09:21:50 -04001383 .minorversion = minorversion,
Trond Myklebust3a498022007-12-14 14:56:04 -05001384 };
David Howells54ceac42006-08-22 20:06:13 -04001385 struct nfs_client *clp;
1386 int error;
1387
1388 dprintk("--> nfs4_set_client()\n");
1389
1390 /* Allocate or find a client reference we can use */
Andy Adamson45a52a02011-03-01 01:34:08 +00001391 clp = nfs_get_client(&cl_init, timeparms, ip_addr, authflavour,
1392 server->flags & NFS_MOUNT_NORESVPORT);
David Howells54ceac42006-08-22 20:06:13 -04001393 if (IS_ERR(clp)) {
1394 error = PTR_ERR(clp);
1395 goto error;
1396 }
David Howells54ceac42006-08-22 20:06:13 -04001397
1398 server->nfs_client = clp;
1399 dprintk("<-- nfs4_set_client() = 0 [new %p]\n", clp);
1400 return 0;
David Howells54ceac42006-08-22 20:06:13 -04001401error:
1402 dprintk("<-- nfs4_set_client() = xerror %d\n", error);
1403 return error;
1404}
1405
Andy Adamson557134a2009-04-01 09:21:53 -04001406
1407/*
Andy Adamson96b09e02009-04-01 09:22:33 -04001408 * Session has been established, and the client marked ready.
1409 * Set the mount rsize and wsize with negotiated fore channel
1410 * attributes which will be bound checked in nfs_server_set_fsinfo.
1411 */
1412static void nfs4_session_set_rwsize(struct nfs_server *server)
1413{
1414#ifdef CONFIG_NFS_V4_1
Alexandros Batsakis2449ea22009-12-05 13:36:55 -05001415 struct nfs4_session *sess;
1416 u32 server_resp_sz;
1417 u32 server_rqst_sz;
1418
Andy Adamson96b09e02009-04-01 09:22:33 -04001419 if (!nfs4_has_session(server->nfs_client))
1420 return;
Alexandros Batsakis2449ea22009-12-05 13:36:55 -05001421 sess = server->nfs_client->cl_session;
1422 server_resp_sz = sess->fc_attrs.max_resp_sz - nfs41_maxread_overhead;
1423 server_rqst_sz = sess->fc_attrs.max_rqst_sz - nfs41_maxwrite_overhead;
1424
1425 if (server->rsize > server_resp_sz)
1426 server->rsize = server_resp_sz;
1427 if (server->wsize > server_rqst_sz)
1428 server->wsize = server_rqst_sz;
Andy Adamson96b09e02009-04-01 09:22:33 -04001429#endif /* CONFIG_NFS_V4_1 */
1430}
1431
Trond Myklebust44950b62010-06-17 11:45:12 -04001432static int nfs4_server_common_setup(struct nfs_server *server,
1433 struct nfs_fh *mntfh)
1434{
1435 struct nfs_fattr *fattr;
1436 int error;
1437
1438 BUG_ON(!server->nfs_client);
1439 BUG_ON(!server->nfs_client->rpc_ops);
1440 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
1441
1442 fattr = nfs_alloc_fattr();
1443 if (fattr == NULL)
1444 return -ENOMEM;
1445
1446 /* We must ensure the session is initialised first */
1447 error = nfs4_init_session(server);
1448 if (error < 0)
1449 goto out;
1450
1451 /* Probe the root fh to retrieve its FSID and filehandle */
1452 error = nfs4_get_rootfh(server, mntfh);
1453 if (error < 0)
1454 goto out;
1455
1456 dprintk("Server FSID: %llx:%llx\n",
1457 (unsigned long long) server->fsid.major,
1458 (unsigned long long) server->fsid.minor);
1459 dprintk("Mount FH: %d\n", mntfh->size);
1460
1461 nfs4_session_set_rwsize(server);
1462
1463 error = nfs_probe_fsinfo(server, mntfh, fattr);
1464 if (error < 0)
1465 goto out;
1466
1467 if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN)
1468 server->namelen = NFS4_MAXNAMLEN;
1469
Chuck Leverfca52382010-12-24 01:32:32 +00001470 nfs_server_insert_lists(server);
Trond Myklebust44950b62010-06-17 11:45:12 -04001471 server->mount_time = jiffies;
1472out:
1473 nfs_free_fattr(fattr);
1474 return error;
1475}
1476
Andy Adamson96b09e02009-04-01 09:22:33 -04001477/*
David Howells54ceac42006-08-22 20:06:13 -04001478 * Create a version 4 volume record
1479 */
1480static int nfs4_init_server(struct nfs_server *server,
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001481 const struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001482{
Trond Myklebust33170232007-12-20 16:03:59 -05001483 struct rpc_timeout timeparms;
David Howells54ceac42006-08-22 20:06:13 -04001484 int error;
1485
1486 dprintk("--> nfs4_init_server()\n");
1487
Trond Myklebust33170232007-12-20 16:03:59 -05001488 nfs_init_timeout_values(&timeparms, data->nfs_server.protocol,
1489 data->timeo, data->retrans);
1490
Chuck Lever542fcc32008-12-23 15:21:36 -05001491 /* Initialise the client representation from the mount data */
1492 server->flags = data->flags;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001493 server->caps |= NFS_CAP_ATOMIC_OPEN|NFS_CAP_CHANGE_ATTR|NFS_CAP_POSIX_LOCK;
1494 if (!(data->flags & NFS_MOUNT_NORDIRPLUS))
1495 server->caps |= NFS_CAP_READDIRPLUS;
David Howellsb797cac2009-04-03 16:42:48 +01001496 server->options = data->options;
Chuck Lever542fcc32008-12-23 15:21:36 -05001497
Trond Myklebust33170232007-12-20 16:03:59 -05001498 /* Get a client record */
1499 error = nfs4_set_client(server,
1500 data->nfs_server.hostname,
1501 (const struct sockaddr *)&data->nfs_server.address,
1502 data->nfs_server.addrlen,
1503 data->client_address,
1504 data->auth_flavors[0],
1505 data->nfs_server.protocol,
Benny Halevy94a417f2009-04-01 09:21:49 -04001506 &timeparms,
1507 data->minorversion);
Trond Myklebust33170232007-12-20 16:03:59 -05001508 if (error < 0)
1509 goto error;
1510
David Howells54ceac42006-08-22 20:06:13 -04001511 if (data->rsize)
1512 server->rsize = nfs_block_size(data->rsize, NULL);
1513 if (data->wsize)
1514 server->wsize = nfs_block_size(data->wsize, NULL);
1515
1516 server->acregmin = data->acregmin * HZ;
1517 server->acregmax = data->acregmax * HZ;
1518 server->acdirmin = data->acdirmin * HZ;
1519 server->acdirmax = data->acdirmax * HZ;
1520
Chuck Leverf22d6d72008-03-14 14:10:22 -04001521 server->port = data->nfs_server.port;
1522
Trond Myklebust33170232007-12-20 16:03:59 -05001523 error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]);
David Howells54ceac42006-08-22 20:06:13 -04001524
Trond Myklebust33170232007-12-20 16:03:59 -05001525error:
David Howells54ceac42006-08-22 20:06:13 -04001526 /* Done */
1527 dprintk("<-- nfs4_init_server() = %d\n", error);
1528 return error;
1529}
1530
1531/*
1532 * Create a version 4 volume record
1533 * - keyed on server and FSID
1534 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001535struct nfs_server *nfs4_create_server(const struct nfs_parsed_mount_data *data,
David Howells54ceac42006-08-22 20:06:13 -04001536 struct nfs_fh *mntfh)
1537{
David Howells54ceac42006-08-22 20:06:13 -04001538 struct nfs_server *server;
1539 int error;
1540
1541 dprintk("--> nfs4_create_server()\n");
1542
1543 server = nfs_alloc_server();
1544 if (!server)
1545 return ERR_PTR(-ENOMEM);
1546
David Howells54ceac42006-08-22 20:06:13 -04001547 /* set up the general RPC client */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001548 error = nfs4_init_server(server, data);
David Howells54ceac42006-08-22 20:06:13 -04001549 if (error < 0)
1550 goto error;
1551
Trond Myklebust44950b62010-06-17 11:45:12 -04001552 error = nfs4_server_common_setup(server, mntfh);
Trond Myklebustfccba802009-07-21 16:48:07 -04001553 if (error < 0)
1554 goto error;
Andy Adamson557134a2009-04-01 09:21:53 -04001555
David Howells54ceac42006-08-22 20:06:13 -04001556 dprintk("<-- nfs4_create_server() = %p\n", server);
1557 return server;
1558
1559error:
1560 nfs_free_server(server);
1561 dprintk("<-- nfs4_create_server() = error %d\n", error);
1562 return ERR_PTR(error);
1563}
1564
1565/*
1566 * Create an NFS4 referral server record
1567 */
1568struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data,
Trond Myklebustf2d0d852007-02-02 14:46:09 -08001569 struct nfs_fh *mntfh)
David Howells54ceac42006-08-22 20:06:13 -04001570{
1571 struct nfs_client *parent_client;
1572 struct nfs_server *server, *parent_server;
David Howells54ceac42006-08-22 20:06:13 -04001573 int error;
1574
1575 dprintk("--> nfs4_create_referral_server()\n");
1576
1577 server = nfs_alloc_server();
1578 if (!server)
1579 return ERR_PTR(-ENOMEM);
1580
1581 parent_server = NFS_SB(data->sb);
1582 parent_client = parent_server->nfs_client;
1583
Chuck Lever542fcc32008-12-23 15:21:36 -05001584 /* Initialise the client representation from the parent server */
1585 nfs_server_copy_userdata(server, parent_server);
Trond Myklebust62ab4602009-08-09 15:06:19 -04001586 server->caps |= NFS_CAP_ATOMIC_OPEN|NFS_CAP_CHANGE_ATTR;
Chuck Lever542fcc32008-12-23 15:21:36 -05001587
David Howells54ceac42006-08-22 20:06:13 -04001588 /* Get a client representation.
1589 * Note: NFSv4 always uses TCP, */
Chuck Leverdcecae02007-12-10 14:58:59 -05001590 error = nfs4_set_client(server, data->hostname,
Chuck Lever6677d092007-12-10 14:59:06 -05001591 data->addr,
1592 data->addrlen,
Chuck Leverdcecae02007-12-10 14:58:59 -05001593 parent_client->cl_ipaddr,
1594 data->authflavor,
1595 parent_server->client->cl_xprt->prot,
Benny Halevy94a417f2009-04-01 09:21:49 -04001596 parent_server->client->cl_timeout,
Trond Myklebust97dc1352010-06-16 09:52:26 -04001597 parent_client->cl_mvops->minor_version);
andros@citi.umich.edu297de4f2006-08-29 12:19:41 -04001598 if (error < 0)
1599 goto error;
David Howells54ceac42006-08-22 20:06:13 -04001600
Trond Myklebust33170232007-12-20 16:03:59 -05001601 error = nfs_init_server_rpcclient(server, parent_server->client->cl_timeout, data->authflavor);
David Howells54ceac42006-08-22 20:06:13 -04001602 if (error < 0)
1603 goto error;
1604
Trond Myklebust44950b62010-06-17 11:45:12 -04001605 error = nfs4_server_common_setup(server, mntfh);
Trond Myklebustf2d0d852007-02-02 14:46:09 -08001606 if (error < 0)
1607 goto error;
1608
David Howells54ceac42006-08-22 20:06:13 -04001609 dprintk("<-- nfs_create_referral_server() = %p\n", server);
1610 return server;
1611
1612error:
1613 nfs_free_server(server);
1614 dprintk("<-- nfs4_create_referral_server() = error %d\n", error);
1615 return ERR_PTR(error);
1616}
1617
1618#endif /* CONFIG_NFS_V4 */
1619
1620/*
1621 * Clone an NFS2, NFS3 or NFS4 server record
1622 */
1623struct nfs_server *nfs_clone_server(struct nfs_server *source,
1624 struct nfs_fh *fh,
1625 struct nfs_fattr *fattr)
1626{
1627 struct nfs_server *server;
Trond Myklebustfbca7792010-04-16 16:22:46 -04001628 struct nfs_fattr *fattr_fsinfo;
David Howells54ceac42006-08-22 20:06:13 -04001629 int error;
1630
1631 dprintk("--> nfs_clone_server(,%llx:%llx,)\n",
David Howells6daabf12006-08-24 15:44:16 -04001632 (unsigned long long) fattr->fsid.major,
1633 (unsigned long long) fattr->fsid.minor);
David Howells54ceac42006-08-22 20:06:13 -04001634
1635 server = nfs_alloc_server();
1636 if (!server)
1637 return ERR_PTR(-ENOMEM);
1638
Trond Myklebustfbca7792010-04-16 16:22:46 -04001639 error = -ENOMEM;
1640 fattr_fsinfo = nfs_alloc_fattr();
1641 if (fattr_fsinfo == NULL)
1642 goto out_free_server;
1643
David Howells54ceac42006-08-22 20:06:13 -04001644 /* Copy data from the source */
1645 server->nfs_client = source->nfs_client;
1646 atomic_inc(&server->nfs_client->cl_count);
1647 nfs_server_copy_userdata(server, source);
1648
1649 server->fsid = fattr->fsid;
1650
Trond Myklebust33170232007-12-20 16:03:59 -05001651 error = nfs_init_server_rpcclient(server,
1652 source->client->cl_timeout,
1653 source->client->cl_auth->au_flavor);
David Howells54ceac42006-08-22 20:06:13 -04001654 if (error < 0)
1655 goto out_free_server;
1656 if (!IS_ERR(source->client_acl))
1657 nfs_init_server_aclclient(server);
1658
1659 /* probe the filesystem info for this server filesystem */
Trond Myklebustfbca7792010-04-16 16:22:46 -04001660 error = nfs_probe_fsinfo(server, fh, fattr_fsinfo);
David Howells54ceac42006-08-22 20:06:13 -04001661 if (error < 0)
1662 goto out_free_server;
1663
Trond Myklebust54af3bb2007-09-28 12:27:41 -04001664 if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN)
1665 server->namelen = NFS4_MAXNAMLEN;
1666
David Howells54ceac42006-08-22 20:06:13 -04001667 dprintk("Cloned FSID: %llx:%llx\n",
David Howells6daabf12006-08-24 15:44:16 -04001668 (unsigned long long) server->fsid.major,
1669 (unsigned long long) server->fsid.minor);
David Howells54ceac42006-08-22 20:06:13 -04001670
1671 error = nfs_start_lockd(server);
1672 if (error < 0)
1673 goto out_free_server;
1674
Chuck Leverfca52382010-12-24 01:32:32 +00001675 nfs_server_insert_lists(server);
David Howells54ceac42006-08-22 20:06:13 -04001676 server->mount_time = jiffies;
1677
Trond Myklebustfbca7792010-04-16 16:22:46 -04001678 nfs_free_fattr(fattr_fsinfo);
David Howells54ceac42006-08-22 20:06:13 -04001679 dprintk("<-- nfs_clone_server() = %p\n", server);
1680 return server;
1681
1682out_free_server:
Trond Myklebustfbca7792010-04-16 16:22:46 -04001683 nfs_free_fattr(fattr_fsinfo);
David Howells54ceac42006-08-22 20:06:13 -04001684 nfs_free_server(server);
1685 dprintk("<-- nfs_clone_server() = error %d\n", error);
1686 return ERR_PTR(error);
1687}
David Howells6aaca562006-08-22 20:06:13 -04001688
1689#ifdef CONFIG_PROC_FS
1690static struct proc_dir_entry *proc_fs_nfs;
1691
1692static int nfs_server_list_open(struct inode *inode, struct file *file);
1693static void *nfs_server_list_start(struct seq_file *p, loff_t *pos);
1694static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos);
1695static void nfs_server_list_stop(struct seq_file *p, void *v);
1696static int nfs_server_list_show(struct seq_file *m, void *v);
1697
James Morris88e9d342009-09-22 16:43:43 -07001698static const struct seq_operations nfs_server_list_ops = {
David Howells6aaca562006-08-22 20:06:13 -04001699 .start = nfs_server_list_start,
1700 .next = nfs_server_list_next,
1701 .stop = nfs_server_list_stop,
1702 .show = nfs_server_list_show,
1703};
1704
Arjan van de Ven00977a52007-02-12 00:55:34 -08001705static const struct file_operations nfs_server_list_fops = {
David Howells6aaca562006-08-22 20:06:13 -04001706 .open = nfs_server_list_open,
1707 .read = seq_read,
1708 .llseek = seq_lseek,
1709 .release = seq_release,
Denis V. Lunev34b37232008-04-29 01:02:07 -07001710 .owner = THIS_MODULE,
David Howells6aaca562006-08-22 20:06:13 -04001711};
1712
1713static int nfs_volume_list_open(struct inode *inode, struct file *file);
1714static void *nfs_volume_list_start(struct seq_file *p, loff_t *pos);
1715static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos);
1716static void nfs_volume_list_stop(struct seq_file *p, void *v);
1717static int nfs_volume_list_show(struct seq_file *m, void *v);
1718
James Morris88e9d342009-09-22 16:43:43 -07001719static const struct seq_operations nfs_volume_list_ops = {
David Howells6aaca562006-08-22 20:06:13 -04001720 .start = nfs_volume_list_start,
1721 .next = nfs_volume_list_next,
1722 .stop = nfs_volume_list_stop,
1723 .show = nfs_volume_list_show,
1724};
1725
Arjan van de Ven00977a52007-02-12 00:55:34 -08001726static const struct file_operations nfs_volume_list_fops = {
David Howells6aaca562006-08-22 20:06:13 -04001727 .open = nfs_volume_list_open,
1728 .read = seq_read,
1729 .llseek = seq_lseek,
1730 .release = seq_release,
Denis V. Lunev34b37232008-04-29 01:02:07 -07001731 .owner = THIS_MODULE,
David Howells6aaca562006-08-22 20:06:13 -04001732};
1733
1734/*
1735 * open "/proc/fs/nfsfs/servers" which provides a summary of servers with which
1736 * we're dealing
1737 */
1738static int nfs_server_list_open(struct inode *inode, struct file *file)
1739{
1740 struct seq_file *m;
1741 int ret;
1742
1743 ret = seq_open(file, &nfs_server_list_ops);
1744 if (ret < 0)
1745 return ret;
1746
1747 m = file->private_data;
1748 m->private = PDE(inode)->data;
1749
1750 return 0;
1751}
1752
1753/*
1754 * set up the iterator to start reading from the server list and return the first item
1755 */
1756static void *nfs_server_list_start(struct seq_file *m, loff_t *_pos)
1757{
David Howells6aaca562006-08-22 20:06:13 -04001758 /* lock the list against modification */
1759 spin_lock(&nfs_client_lock);
Pavel Emelianov259902e2007-07-15 23:39:56 -07001760 return seq_list_start_head(&nfs_client_list, *_pos);
David Howells6aaca562006-08-22 20:06:13 -04001761}
1762
1763/*
1764 * move to next server
1765 */
1766static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos)
1767{
Pavel Emelianov259902e2007-07-15 23:39:56 -07001768 return seq_list_next(v, &nfs_client_list, pos);
David Howells6aaca562006-08-22 20:06:13 -04001769}
1770
1771/*
1772 * clean up after reading from the transports list
1773 */
1774static void nfs_server_list_stop(struct seq_file *p, void *v)
1775{
1776 spin_unlock(&nfs_client_lock);
1777}
1778
1779/*
1780 * display a header line followed by a load of call lines
1781 */
1782static int nfs_server_list_show(struct seq_file *m, void *v)
1783{
1784 struct nfs_client *clp;
1785
1786 /* display header on line 1 */
Pavel Emelianov259902e2007-07-15 23:39:56 -07001787 if (v == &nfs_client_list) {
David Howells6aaca562006-08-22 20:06:13 -04001788 seq_puts(m, "NV SERVER PORT USE HOSTNAME\n");
1789 return 0;
1790 }
1791
1792 /* display one transport per line on subsequent lines */
1793 clp = list_entry(v, struct nfs_client, cl_share_link);
1794
Chuck Lever5d8515c2007-12-10 14:57:16 -05001795 seq_printf(m, "v%u %s %s %3d %s\n",
Trond Myklebust40c553192007-12-14 14:56:07 -05001796 clp->rpc_ops->version,
Chuck Lever5d8515c2007-12-10 14:57:16 -05001797 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR),
1798 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT),
David Howells6aaca562006-08-22 20:06:13 -04001799 atomic_read(&clp->cl_count),
1800 clp->cl_hostname);
1801
1802 return 0;
1803}
1804
1805/*
1806 * open "/proc/fs/nfsfs/volumes" which provides a summary of extant volumes
1807 */
1808static int nfs_volume_list_open(struct inode *inode, struct file *file)
1809{
1810 struct seq_file *m;
1811 int ret;
1812
1813 ret = seq_open(file, &nfs_volume_list_ops);
1814 if (ret < 0)
1815 return ret;
1816
1817 m = file->private_data;
1818 m->private = PDE(inode)->data;
1819
1820 return 0;
1821}
1822
1823/*
1824 * set up the iterator to start reading from the volume list and return the first item
1825 */
1826static void *nfs_volume_list_start(struct seq_file *m, loff_t *_pos)
1827{
David Howells6aaca562006-08-22 20:06:13 -04001828 /* lock the list against modification */
1829 spin_lock(&nfs_client_lock);
Pavel Emelianov259902e2007-07-15 23:39:56 -07001830 return seq_list_start_head(&nfs_volume_list, *_pos);
David Howells6aaca562006-08-22 20:06:13 -04001831}
1832
1833/*
1834 * move to next volume
1835 */
1836static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos)
1837{
Pavel Emelianov259902e2007-07-15 23:39:56 -07001838 return seq_list_next(v, &nfs_volume_list, pos);
David Howells6aaca562006-08-22 20:06:13 -04001839}
1840
1841/*
1842 * clean up after reading from the transports list
1843 */
1844static void nfs_volume_list_stop(struct seq_file *p, void *v)
1845{
1846 spin_unlock(&nfs_client_lock);
1847}
1848
1849/*
1850 * display a header line followed by a load of call lines
1851 */
1852static int nfs_volume_list_show(struct seq_file *m, void *v)
1853{
1854 struct nfs_server *server;
1855 struct nfs_client *clp;
1856 char dev[8], fsid[17];
1857
1858 /* display header on line 1 */
Pavel Emelianov259902e2007-07-15 23:39:56 -07001859 if (v == &nfs_volume_list) {
David Howells5d1acff2009-04-03 16:42:47 +01001860 seq_puts(m, "NV SERVER PORT DEV FSID FSC\n");
David Howells6aaca562006-08-22 20:06:13 -04001861 return 0;
1862 }
1863 /* display one transport per line on subsequent lines */
1864 server = list_entry(v, struct nfs_server, master_link);
1865 clp = server->nfs_client;
1866
1867 snprintf(dev, 8, "%u:%u",
1868 MAJOR(server->s_dev), MINOR(server->s_dev));
1869
1870 snprintf(fsid, 17, "%llx:%llx",
David Howells6daabf12006-08-24 15:44:16 -04001871 (unsigned long long) server->fsid.major,
1872 (unsigned long long) server->fsid.minor);
David Howells6aaca562006-08-22 20:06:13 -04001873
David Howells5d1acff2009-04-03 16:42:47 +01001874 seq_printf(m, "v%u %s %s %-7s %-17s %s\n",
Trond Myklebust40c553192007-12-14 14:56:07 -05001875 clp->rpc_ops->version,
Chuck Lever5d8515c2007-12-10 14:57:16 -05001876 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR),
1877 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT),
David Howells6aaca562006-08-22 20:06:13 -04001878 dev,
David Howells5d1acff2009-04-03 16:42:47 +01001879 fsid,
1880 nfs_server_fscache_state(server));
David Howells6aaca562006-08-22 20:06:13 -04001881
1882 return 0;
1883}
1884
1885/*
1886 * initialise the /proc/fs/nfsfs/ directory
1887 */
1888int __init nfs_fs_proc_init(void)
1889{
1890 struct proc_dir_entry *p;
1891
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -07001892 proc_fs_nfs = proc_mkdir("fs/nfsfs", NULL);
David Howells6aaca562006-08-22 20:06:13 -04001893 if (!proc_fs_nfs)
1894 goto error_0;
1895
David Howells6aaca562006-08-22 20:06:13 -04001896 /* a file of servers with which we're dealing */
Denis V. Lunev34b37232008-04-29 01:02:07 -07001897 p = proc_create("servers", S_IFREG|S_IRUGO,
1898 proc_fs_nfs, &nfs_server_list_fops);
David Howells6aaca562006-08-22 20:06:13 -04001899 if (!p)
1900 goto error_1;
1901
David Howells6aaca562006-08-22 20:06:13 -04001902 /* a file of volumes that we have mounted */
Denis V. Lunev34b37232008-04-29 01:02:07 -07001903 p = proc_create("volumes", S_IFREG|S_IRUGO,
1904 proc_fs_nfs, &nfs_volume_list_fops);
David Howells6aaca562006-08-22 20:06:13 -04001905 if (!p)
1906 goto error_2;
David Howells6aaca562006-08-22 20:06:13 -04001907 return 0;
1908
1909error_2:
1910 remove_proc_entry("servers", proc_fs_nfs);
1911error_1:
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -07001912 remove_proc_entry("fs/nfsfs", NULL);
David Howells6aaca562006-08-22 20:06:13 -04001913error_0:
1914 return -ENOMEM;
1915}
1916
1917/*
1918 * clean up the /proc/fs/nfsfs/ directory
1919 */
1920void nfs_fs_proc_exit(void)
1921{
1922 remove_proc_entry("volumes", proc_fs_nfs);
1923 remove_proc_entry("servers", proc_fs_nfs);
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -07001924 remove_proc_entry("fs/nfsfs", NULL);
David Howells6aaca562006-08-22 20:06:13 -04001925}
1926
1927#endif /* CONFIG_PROC_FS */