blob: 7d108753af81e9783ab1465c8bb9986452a6cf00 [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>
Al Viro40401532012-02-13 03:58:52 +000039#include <linux/idr.h>
Trond Myklebust3b0d3f92008-01-03 13:28:58 -050040#include <net/ipv6.h>
David Howells24c8dbb2006-08-22 20:06:10 -040041#include <linux/nfs_xdr.h>
Andy Adamson0b5b7ae2009-04-01 09:23:15 -040042#include <linux/sunrpc/bc_xprt.h>
Stanislav Kinsbursky6b131682012-01-23 17:26:05 +000043#include <linux/nsproxy.h>
44#include <linux/pid_namespace.h>
David Howells24c8dbb2006-08-22 20:06:10 -040045
David Howells24c8dbb2006-08-22 20:06:10 -040046
47#include "nfs4_fs.h"
48#include "callback.h"
49#include "delegation.h"
50#include "iostat.h"
51#include "internal.h"
David Howells14727282009-04-03 16:42:42 +010052#include "fscache.h"
Ricardo Labiaga85e174b2010-10-20 00:17:58 -040053#include "pnfs.h"
Stanislav Kinsbursky6b131682012-01-23 17:26:05 +000054#include "netns.h"
David Howells24c8dbb2006-08-22 20:06:10 -040055
56#define NFSDBG_FACILITY NFSDBG_CLIENT
57
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
Andy Adamsonf4eecd52011-01-06 02:04:30 +000060
61/*
62 * Get a unique NFSv4.0 callback identifier which will be used
63 * by the V4.0 callback service to lookup the nfs_client struct
64 */
65static int nfs_get_cb_ident_idr(struct nfs_client *clp, int minorversion)
66{
67 int ret = 0;
Chuck Lever73ea6662012-05-21 22:44:50 -040068 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Andy Adamsonf4eecd52011-01-06 02:04:30 +000069
70 if (clp->rpc_ops->version != 4 || minorversion != 0)
71 return ret;
72retry:
Stanislav Kinsbursky28cd1b32012-01-23 17:26:22 +000073 if (!idr_pre_get(&nn->cb_ident_idr, GFP_KERNEL))
Andy Adamsonf4eecd52011-01-06 02:04:30 +000074 return -ENOMEM;
Stanislav Kinsburskydc030852012-01-23 17:26:31 +000075 spin_lock(&nn->nfs_client_lock);
Stanislav Kinsbursky28cd1b32012-01-23 17:26:22 +000076 ret = idr_get_new(&nn->cb_ident_idr, clp, &clp->cl_cb_ident);
Stanislav Kinsburskydc030852012-01-23 17:26:31 +000077 spin_unlock(&nn->nfs_client_lock);
Andy Adamsonf4eecd52011-01-06 02:04:30 +000078 if (ret == -EAGAIN)
79 goto retry;
80 return ret;
81}
82#endif /* CONFIG_NFS_V4 */
David Howells24c8dbb2006-08-22 20:06:10 -040083
84/*
Trond Myklebustb064eca22011-02-22 15:44:32 -080085 * Turn off NFSv4 uid/gid mapping when using AUTH_SYS
86 */
Rusty Russell90ab5ee2012-01-13 09:32:20 +103087static bool nfs4_disable_idmapping = true;
Trond Myklebustb064eca22011-02-22 15:44:32 -080088
89/*
David Howells5006a762006-08-22 20:06:12 -040090 * RPC cruft for NFS
91 */
Trond Myklebusta613fa12012-01-20 13:53:56 -050092static const struct rpc_version *nfs_version[5] = {
Bryan Schumaker2ba68002012-05-10 16:47:19 -040093#ifdef CONFIG_NFS_V2
David Howells5006a762006-08-22 20:06:12 -040094 [2] = &nfs_version2,
Bryan Schumaker2ba68002012-05-10 16:47:19 -040095#endif
David Howells5006a762006-08-22 20:06:12 -040096#ifdef CONFIG_NFS_V3
97 [3] = &nfs_version3,
98#endif
99#ifdef CONFIG_NFS_V4
100 [4] = &nfs_version4,
101#endif
102};
103
Trond Myklebusta613fa12012-01-20 13:53:56 -0500104const struct rpc_program nfs_program = {
David Howells5006a762006-08-22 20:06:12 -0400105 .name = "nfs",
106 .number = NFS_PROGRAM,
107 .nrvers = ARRAY_SIZE(nfs_version),
108 .version = nfs_version,
109 .stats = &nfs_rpcstat,
Jim Reesfe0a9b72011-07-30 20:52:42 -0400110 .pipe_dir_name = NFS_PIPE_DIRNAME,
David Howells5006a762006-08-22 20:06:12 -0400111};
112
113struct rpc_stat nfs_rpcstat = {
114 .program = &nfs_program
115};
116
117
118#ifdef CONFIG_NFS_V3_ACL
119static struct rpc_stat nfsacl_rpcstat = { &nfsacl_program };
Trond Myklebusta613fa12012-01-20 13:53:56 -0500120static const struct rpc_version *nfsacl_version[] = {
David Howells5006a762006-08-22 20:06:12 -0400121 [3] = &nfsacl_version3,
122};
123
Trond Myklebusta613fa12012-01-20 13:53:56 -0500124const struct rpc_program nfsacl_program = {
David Howells5006a762006-08-22 20:06:12 -0400125 .name = "nfsacl",
126 .number = NFS_ACL_PROGRAM,
127 .nrvers = ARRAY_SIZE(nfsacl_version),
128 .version = nfsacl_version,
129 .stats = &nfsacl_rpcstat,
130};
131#endif /* CONFIG_NFS_V3_ACL */
132
Trond Myklebust3a498022007-12-14 14:56:04 -0500133struct nfs_client_initdata {
Chuck Lever4bf590e2012-05-21 22:46:07 -0400134 unsigned long init_flags;
Trond Myklebust3a498022007-12-14 14:56:04 -0500135 const char *hostname;
Chuck Leverd7422c42007-12-10 14:58:51 -0500136 const struct sockaddr *addr;
Chuck Lever6e4cffd2007-12-10 14:58:15 -0500137 size_t addrlen;
Trond Myklebust40c553192007-12-14 14:56:07 -0500138 const struct nfs_rpc_ops *rpc_ops;
Trond Myklebust59dca3b2008-01-03 16:29:06 -0500139 int proto;
Benny Halevy5aae4a92009-04-01 09:21:50 -0400140 u32 minorversion;
Stanislav Kinsburskye50a7a12012-01-10 16:12:46 +0400141 struct net *net;
Trond Myklebust3a498022007-12-14 14:56:04 -0500142};
143
David Howells5006a762006-08-22 20:06:12 -0400144/*
David Howells24c8dbb2006-08-22 20:06:10 -0400145 * Allocate a shared client record
146 *
147 * Since these are allocated/deallocated very rarely, we don't
148 * bother putting them in a slab cache...
149 */
Trond Myklebust3a498022007-12-14 14:56:04 -0500150static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init)
David Howells24c8dbb2006-08-22 20:06:10 -0400151{
152 struct nfs_client *clp;
Trond Myklebust7c67db32008-04-07 20:50:11 -0400153 struct rpc_cred *cred;
Chuck Levera21bdd92009-06-17 18:02:10 -0700154 int err = -ENOMEM;
David Howells24c8dbb2006-08-22 20:06:10 -0400155
156 if ((clp = kzalloc(sizeof(*clp), GFP_KERNEL)) == NULL)
157 goto error_0;
158
Trond Myklebust40c553192007-12-14 14:56:07 -0500159 clp->rpc_ops = cl_init->rpc_ops;
160
David Howells24c8dbb2006-08-22 20:06:10 -0400161 atomic_set(&clp->cl_count, 1);
162 clp->cl_cons_state = NFS_CS_INITING;
163
Chuck Lever6e4cffd2007-12-10 14:58:15 -0500164 memcpy(&clp->cl_addr, cl_init->addr, cl_init->addrlen);
165 clp->cl_addrlen = cl_init->addrlen;
David Howells24c8dbb2006-08-22 20:06:10 -0400166
Trond Myklebust3a498022007-12-14 14:56:04 -0500167 if (cl_init->hostname) {
Chuck Levera21bdd92009-06-17 18:02:10 -0700168 err = -ENOMEM;
Trond Myklebust3a498022007-12-14 14:56:04 -0500169 clp->cl_hostname = kstrdup(cl_init->hostname, GFP_KERNEL);
David Howells24c8dbb2006-08-22 20:06:10 -0400170 if (!clp->cl_hostname)
Benny Halevy71468512009-04-01 09:22:56 -0400171 goto error_cleanup;
David Howells24c8dbb2006-08-22 20:06:10 -0400172 }
173
174 INIT_LIST_HEAD(&clp->cl_superblocks);
175 clp->cl_rpcclient = ERR_PTR(-EINVAL);
176
Trond Myklebust59dca3b2008-01-03 16:29:06 -0500177 clp->cl_proto = cl_init->proto;
Chuck Lever73ea6662012-05-21 22:44:50 -0400178 clp->cl_net = get_net(cl_init->net);
Trond Myklebust59dca3b2008-01-03 16:29:06 -0500179
David Howells24c8dbb2006-08-22 20:06:10 -0400180#ifdef CONFIG_NFS_V4
Andy Adamsonf4eecd52011-01-06 02:04:30 +0000181 err = nfs_get_cb_ident_idr(clp, cl_init->minorversion);
182 if (err)
183 goto error_cleanup;
184
David Howells24c8dbb2006-08-22 20:06:10 -0400185 spin_lock_init(&clp->cl_lock);
David Howells65f27f32006-11-22 14:55:48 +0000186 INIT_DELAYED_WORK(&clp->cl_renewd, nfs4_renew_state);
David Howells24c8dbb2006-08-22 20:06:10 -0400187 rpc_init_wait_queue(&clp->cl_rpcwaitq, "NFS client");
David Howells24c8dbb2006-08-22 20:06:10 -0400188 clp->cl_state = 1 << NFS4CLNT_LEASE_EXPIRED;
Benny Halevy5aae4a92009-04-01 09:21:50 -0400189 clp->cl_minorversion = cl_init->minorversion;
Trond Myklebust97dc1352010-06-16 09:52:26 -0400190 clp->cl_mvops = nfs_v4_minor_ops[cl_init->minorversion];
David Howells24c8dbb2006-08-22 20:06:10 -0400191#endif
Trond Myklebust68c97152012-01-03 13:22:46 -0500192 cred = rpc_lookup_machine_cred("*");
Trond Myklebust7c67db32008-04-07 20:50:11 -0400193 if (!IS_ERR(cred))
194 clp->cl_machine_cred = cred;
David Howells14727282009-04-03 16:42:42 +0100195 nfs_fscache_get_client_cookie(clp);
196
David Howells24c8dbb2006-08-22 20:06:10 -0400197 return clp;
198
Benny Halevy71468512009-04-01 09:22:56 -0400199error_cleanup:
David Howells24c8dbb2006-08-22 20:06:10 -0400200 kfree(clp);
201error_0:
Chuck Levera21bdd92009-06-17 18:02:10 -0700202 return ERR_PTR(err);
David Howells24c8dbb2006-08-22 20:06:10 -0400203}
204
Trond Myklebust5dd31772006-08-24 01:03:05 -0400205#ifdef CONFIG_NFS_V4
Andy Adamson557134a2009-04-01 09:21:53 -0400206#ifdef CONFIG_NFS_V4_1
Andy Adamsonea005282011-01-06 02:04:29 +0000207static void nfs4_shutdown_session(struct nfs_client *clp)
208{
Trond Myklebust7df529a2012-02-26 17:34:22 -0500209 if (nfs4_has_session(clp)) {
210 nfs4_deviceid_purge_client(clp);
Andy Adamson557134a2009-04-01 09:21:53 -0400211 nfs4_destroy_session(clp->cl_session);
Trond Myklebust66245532012-05-25 17:18:09 -0400212 nfs4_destroy_clientid(clp);
Trond Myklebust7df529a2012-02-26 17:34:22 -0500213 }
214
Andy Adamson557134a2009-04-01 09:21:53 -0400215}
Andy Adamsonea005282011-01-06 02:04:29 +0000216#else /* CONFIG_NFS_V4_1 */
217static void nfs4_shutdown_session(struct nfs_client *clp)
218{
219}
220#endif /* CONFIG_NFS_V4_1 */
Andy Adamson557134a2009-04-01 09:21:53 -0400221
222/*
Alexandros Batsakis888ef2e2010-02-05 03:45:03 -0800223 * Destroy the NFS4 callback service
224 */
225static void nfs4_destroy_callback(struct nfs_client *clp)
226{
227 if (__test_and_clear_bit(NFS_CS_CALLBACK, &clp->cl_res_state))
Trond Myklebust97dc1352010-06-16 09:52:26 -0400228 nfs_callback_down(clp->cl_mvops->minor_version);
Alexandros Batsakis888ef2e2010-02-05 03:45:03 -0800229}
230
231static void nfs4_shutdown_client(struct nfs_client *clp)
232{
233 if (__test_and_clear_bit(NFS_CS_RENEWD, &clp->cl_res_state))
234 nfs4_kill_renewd(clp);
Andy Adamsonea005282011-01-06 02:04:29 +0000235 nfs4_shutdown_session(clp);
Alexandros Batsakis888ef2e2010-02-05 03:45:03 -0800236 nfs4_destroy_callback(clp);
237 if (__test_and_clear_bit(NFS_CS_IDMAP, &clp->cl_res_state))
238 nfs_idmap_delete(clp);
239
240 rpc_destroy_wait_queue(&clp->cl_rpcwaitq);
Chuck Leveracdeb692012-05-21 22:46:16 -0400241 kfree(clp->cl_serverowner);
Chuck Lever79d4e1f2012-05-21 22:44:31 -0400242 kfree(clp->cl_serverscope);
Chuck Lever59155542012-05-21 22:44:41 -0400243 kfree(clp->cl_implid);
Alexandros Batsakis888ef2e2010-02-05 03:45:03 -0800244}
Andy Adamsonf4eecd52011-01-06 02:04:30 +0000245
246/* idr_remove_all is not needed as all id's are removed by nfs_put_client */
Stanislav Kinsbursky28cd1b32012-01-23 17:26:22 +0000247void nfs_cleanup_cb_ident_idr(struct net *net)
Andy Adamsonf4eecd52011-01-06 02:04:30 +0000248{
Stanislav Kinsbursky28cd1b32012-01-23 17:26:22 +0000249 struct nfs_net *nn = net_generic(net, nfs_net_id);
250
251 idr_destroy(&nn->cb_ident_idr);
Andy Adamsonf4eecd52011-01-06 02:04:30 +0000252}
253
254/* nfs_client_lock held */
255static void nfs_cb_idr_remove_locked(struct nfs_client *clp)
256{
Chuck Lever73ea6662012-05-21 22:44:50 -0400257 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Stanislav Kinsbursky28cd1b32012-01-23 17:26:22 +0000258
Andy Adamsonf4eecd52011-01-06 02:04:30 +0000259 if (clp->cl_cb_ident)
Stanislav Kinsbursky28cd1b32012-01-23 17:26:22 +0000260 idr_remove(&nn->cb_ident_idr, clp->cl_cb_ident);
Andy Adamsonf4eecd52011-01-06 02:04:30 +0000261}
262
Fred Isamanf7e89172011-01-06 11:36:32 +0000263static void pnfs_init_server(struct nfs_server *server)
264{
265 rpc_init_wait_queue(&server->roc_rpcwaitq, "pNFS ROC");
266}
267
Chuck Lever0aaaf5c2011-12-06 16:13:48 -0500268static void nfs4_destroy_server(struct nfs_server *server)
269{
270 nfs4_purge_state_owners(server);
271}
272
Alexandros Batsakis888ef2e2010-02-05 03:45:03 -0800273#else
274static void nfs4_shutdown_client(struct nfs_client *clp)
275{
276}
Andy Adamsonf4eecd52011-01-06 02:04:30 +0000277
Stanislav Kinsbursky28cd1b32012-01-23 17:26:22 +0000278void nfs_cleanup_cb_ident_idr(struct net *net)
Andy Adamsonf4eecd52011-01-06 02:04:30 +0000279{
280}
281
282static void nfs_cb_idr_remove_locked(struct nfs_client *clp)
283{
284}
Fred Isamanf7e89172011-01-06 11:36:32 +0000285
286static void pnfs_init_server(struct nfs_server *server)
287{
288}
289
Alexandros Batsakis888ef2e2010-02-05 03:45:03 -0800290#endif /* CONFIG_NFS_V4 */
291
292/*
David Howells24c8dbb2006-08-22 20:06:10 -0400293 * Destroy a shared client record
294 */
295static void nfs_free_client(struct nfs_client *clp)
296{
Trond Myklebust40c553192007-12-14 14:56:07 -0500297 dprintk("--> nfs_free_client(%u)\n", clp->rpc_ops->version);
David Howells24c8dbb2006-08-22 20:06:10 -0400298
Trond Myklebust5dd31772006-08-24 01:03:05 -0400299 nfs4_shutdown_client(clp);
David Howells24c8dbb2006-08-22 20:06:10 -0400300
David Howells14727282009-04-03 16:42:42 +0100301 nfs_fscache_release_client_cookie(clp);
302
David Howells24c8dbb2006-08-22 20:06:10 -0400303 /* -EIO all pending I/O */
304 if (!IS_ERR(clp->cl_rpcclient))
305 rpc_shutdown_client(clp->cl_rpcclient);
306
Trond Myklebust7c67db32008-04-07 20:50:11 -0400307 if (clp->cl_machine_cred != NULL)
308 put_rpccred(clp->cl_machine_cred);
309
Chuck Lever73ea6662012-05-21 22:44:50 -0400310 put_net(clp->cl_net);
David Howells24c8dbb2006-08-22 20:06:10 -0400311 kfree(clp->cl_hostname);
312 kfree(clp);
313
314 dprintk("<-- nfs_free_client()\n");
315}
316
317/*
318 * Release a reference to a shared client record
319 */
320void nfs_put_client(struct nfs_client *clp)
321{
Stanislav Kinsburskydc030852012-01-23 17:26:31 +0000322 struct nfs_net *nn;
323
David Howells27ba8512006-07-30 14:40:56 -0400324 if (!clp)
325 return;
326
David Howells24c8dbb2006-08-22 20:06:10 -0400327 dprintk("--> nfs_put_client({%d})\n", atomic_read(&clp->cl_count));
Chuck Lever73ea6662012-05-21 22:44:50 -0400328 nn = net_generic(clp->cl_net, nfs_net_id);
David Howells24c8dbb2006-08-22 20:06:10 -0400329
Stanislav Kinsburskydc030852012-01-23 17:26:31 +0000330 if (atomic_dec_and_lock(&clp->cl_count, &nn->nfs_client_lock)) {
David Howells24c8dbb2006-08-22 20:06:10 -0400331 list_del(&clp->cl_share_link);
Andy Adamsonf4eecd52011-01-06 02:04:30 +0000332 nfs_cb_idr_remove_locked(clp);
Stanislav Kinsburskydc030852012-01-23 17:26:31 +0000333 spin_unlock(&nn->nfs_client_lock);
David Howells24c8dbb2006-08-22 20:06:10 -0400334
335 BUG_ON(!list_empty(&clp->cl_superblocks));
336
337 nfs_free_client(clp);
338 }
339}
Andy Adamson16b374c2010-10-20 00:18:04 -0400340EXPORT_SYMBOL_GPL(nfs_put_client);
David Howells24c8dbb2006-08-22 20:06:10 -0400341
Trond Myklebust9082a5c2008-12-23 15:21:53 -0500342#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
Trond Myklebust9f4c8992009-03-12 14:51:32 -0400343/*
344 * Test if two ip6 socket addresses refer to the same socket by
345 * comparing relevant fields. The padding bytes specifically, are not
346 * compared. sin6_flowinfo is not compared because it only affects QoS
347 * and sin6_scope_id is only compared if the address is "link local"
348 * because "link local" addresses need only be unique to a specific
349 * link. Conversely, ordinary unicast addresses might have different
350 * sin6_scope_id.
351 *
352 * The caller should ensure both socket addresses are AF_INET6.
353 */
Chuck Lever3c8c45d2009-03-18 20:48:14 -0400354static int nfs_sockaddr_match_ipaddr6(const struct sockaddr *sa1,
355 const struct sockaddr *sa2)
Trond Myklebust9f4c8992009-03-12 14:51:32 -0400356{
Chuck Lever3c8c45d2009-03-18 20:48:14 -0400357 const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sa1;
358 const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sa2;
Trond Myklebust9f4c8992009-03-12 14:51:32 -0400359
Mi Jinlongb9dd3ab2011-10-12 15:09:34 +0800360 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
Trond Myklebust9f4c8992009-03-12 14:51:32 -0400361 return 0;
Mi Jinlongb9dd3ab2011-10-12 15:09:34 +0800362 else if (ipv6_addr_type(&sin1->sin6_addr) & IPV6_ADDR_LINKLOCAL)
363 return sin1->sin6_scope_id == sin2->sin6_scope_id;
Trond Myklebust3b0d3f92008-01-03 13:28:58 -0500364
Mi Jinlongb9dd3ab2011-10-12 15:09:34 +0800365 return 1;
Trond Myklebust3b0d3f92008-01-03 13:28:58 -0500366}
Chuck Lever3c8c45d2009-03-18 20:48:14 -0400367#else /* !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE) */
368static int nfs_sockaddr_match_ipaddr6(const struct sockaddr *sa1,
369 const struct sockaddr *sa2)
Trond Myklebust9f4c8992009-03-12 14:51:32 -0400370{
371 return 0;
372}
Trond Myklebust9082a5c2008-12-23 15:21:53 -0500373#endif
Trond Myklebust3b0d3f92008-01-03 13:28:58 -0500374
David Howells24c8dbb2006-08-22 20:06:10 -0400375/*
Ian Dalld7371c42009-03-10 20:33:22 -0400376 * Test if two ip4 socket addresses refer to the same socket, by
377 * comparing relevant fields. The padding bytes specifically, are
378 * not compared.
379 *
380 * The caller should ensure both socket addresses are AF_INET.
381 */
Chuck Lever3c8c45d2009-03-18 20:48:14 -0400382static int nfs_sockaddr_match_ipaddr4(const struct sockaddr *sa1,
383 const struct sockaddr *sa2)
384{
385 const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sa1;
386 const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sa2;
387
388 return sin1->sin_addr.s_addr == sin2->sin_addr.s_addr;
389}
390
391static int nfs_sockaddr_cmp_ip6(const struct sockaddr *sa1,
392 const struct sockaddr *sa2)
393{
394 const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sa1;
395 const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sa2;
396
397 return nfs_sockaddr_match_ipaddr6(sa1, sa2) &&
398 (sin1->sin6_port == sin2->sin6_port);
399}
400
Trond Myklebust9f4c8992009-03-12 14:51:32 -0400401static int nfs_sockaddr_cmp_ip4(const struct sockaddr *sa1,
402 const struct sockaddr *sa2)
Ian Dalld7371c42009-03-10 20:33:22 -0400403{
Chuck Lever3c8c45d2009-03-18 20:48:14 -0400404 const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sa1;
405 const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sa2;
Trond Myklebust9f4c8992009-03-12 14:51:32 -0400406
Chuck Lever3c8c45d2009-03-18 20:48:14 -0400407 return nfs_sockaddr_match_ipaddr4(sa1, sa2) &&
408 (sin1->sin_port == sin2->sin_port);
Ian Dalld7371c42009-03-10 20:33:22 -0400409}
410
Bryan Schumaker4b7c8dd2012-03-12 11:28:24 -0400411#if defined(CONFIG_NFS_V4_1)
Ian Dalld7371c42009-03-10 20:33:22 -0400412/*
Ian Dalld7371c42009-03-10 20:33:22 -0400413 * Test if two socket addresses represent the same actual socket,
Chuck Lever3c8c45d2009-03-18 20:48:14 -0400414 * by comparing (only) relevant fields, excluding the port number.
415 */
416static int nfs_sockaddr_match_ipaddr(const struct sockaddr *sa1,
417 const struct sockaddr *sa2)
418{
419 if (sa1->sa_family != sa2->sa_family)
420 return 0;
421
422 switch (sa1->sa_family) {
423 case AF_INET:
424 return nfs_sockaddr_match_ipaddr4(sa1, sa2);
425 case AF_INET6:
426 return nfs_sockaddr_match_ipaddr6(sa1, sa2);
427 }
428 return 0;
429}
Bryan Schumaker4b7c8dd2012-03-12 11:28:24 -0400430#endif /* CONFIG_NFS_V4_1 */
Chuck Lever3c8c45d2009-03-18 20:48:14 -0400431
432/*
433 * Test if two socket addresses represent the same actual socket,
434 * by comparing (only) relevant fields, including the port number.
Ian Dalld7371c42009-03-10 20:33:22 -0400435 */
436static int nfs_sockaddr_cmp(const struct sockaddr *sa1,
437 const struct sockaddr *sa2)
438{
439 if (sa1->sa_family != sa2->sa_family)
440 return 0;
441
442 switch (sa1->sa_family) {
443 case AF_INET:
Trond Myklebust9f4c8992009-03-12 14:51:32 -0400444 return nfs_sockaddr_cmp_ip4(sa1, sa2);
Ian Dalld7371c42009-03-10 20:33:22 -0400445 case AF_INET6:
Trond Myklebust9f4c8992009-03-12 14:51:32 -0400446 return nfs_sockaddr_cmp_ip6(sa1, sa2);
Ian Dalld7371c42009-03-10 20:33:22 -0400447 }
448 return 0;
449}
450
Bryan Schumaker4b7c8dd2012-03-12 11:28:24 -0400451#if defined(CONFIG_NFS_V4_1)
Andy Adamsonc36fca52011-01-06 02:04:32 +0000452/* Common match routine for v4.0 and v4.1 callback services */
Trond Myklebust17280172012-03-11 13:11:00 -0400453static bool nfs4_cb_match_client(const struct sockaddr *addr,
454 struct nfs_client *clp, u32 minorversion)
Trond Myklebustc81468a2007-12-14 14:56:05 -0500455{
Andy Adamsonc36fca52011-01-06 02:04:32 +0000456 struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr;
Trond Myklebustc81468a2007-12-14 14:56:05 -0500457
Andy Adamsonc36fca52011-01-06 02:04:32 +0000458 /* Don't match clients that failed to initialise */
459 if (!(clp->cl_cons_state == NFS_CS_READY ||
460 clp->cl_cons_state == NFS_CS_SESSION_INITING))
461 return false;
Trond Myklebust3b0d3f92008-01-03 13:28:58 -0500462
Trond Myklebust54ac4712012-05-23 13:26:10 -0400463 smp_rmb();
464
Andy Adamsonc36fca52011-01-06 02:04:32 +0000465 /* Match the version and minorversion */
466 if (clp->rpc_ops->version != 4 ||
467 clp->cl_minorversion != minorversion)
468 return false;
Trond Myklebustc81468a2007-12-14 14:56:05 -0500469
Andy Adamsonc36fca52011-01-06 02:04:32 +0000470 /* Match only the IP address, not the port number */
471 if (!nfs_sockaddr_match_ipaddr(addr, clap))
472 return false;
Trond Myklebustc81468a2007-12-14 14:56:05 -0500473
Andy Adamsonc36fca52011-01-06 02:04:32 +0000474 return true;
Trond Myklebust3fbd67a2008-01-26 01:06:40 -0500475}
Bryan Schumaker4b7c8dd2012-03-12 11:28:24 -0400476#endif /* CONFIG_NFS_V4_1 */
Trond Myklebust3fbd67a2008-01-26 01:06:40 -0500477
478/*
Trond Myklebustc81468a2007-12-14 14:56:05 -0500479 * Find an nfs_client on the list that matches the initialisation data
480 * that is supplied.
481 */
482static struct nfs_client *nfs_match_client(const struct nfs_client_initdata *data)
David Howells24c8dbb2006-08-22 20:06:10 -0400483{
484 struct nfs_client *clp;
Ian Dalld7371c42009-03-10 20:33:22 -0400485 const struct sockaddr *sap = data->addr;
Stanislav Kinsbursky6b131682012-01-23 17:26:05 +0000486 struct nfs_net *nn = net_generic(data->net, nfs_net_id);
David Howells24c8dbb2006-08-22 20:06:10 -0400487
Stanislav Kinsbursky6b131682012-01-23 17:26:05 +0000488 list_for_each_entry(clp, &nn->nfs_client_list, cl_share_link) {
Ian Dalld7371c42009-03-10 20:33:22 -0400489 const struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr;
Trond Myklebust13bbc062006-10-19 23:28:40 -0700490 /* Don't match clients that failed to initialise properly */
491 if (clp->cl_cons_state < 0)
492 continue;
493
David Howells24c8dbb2006-08-22 20:06:10 -0400494 /* Different NFS versions cannot share the same nfs_client */
Trond Myklebust40c553192007-12-14 14:56:07 -0500495 if (clp->rpc_ops != data->rpc_ops)
David Howells24c8dbb2006-08-22 20:06:10 -0400496 continue;
497
Trond Myklebust59dca3b2008-01-03 16:29:06 -0500498 if (clp->cl_proto != data->proto)
499 continue;
Benny Halevy5aae4a92009-04-01 09:21:50 -0400500 /* Match nfsv4 minorversion */
501 if (clp->cl_minorversion != data->minorversion)
502 continue;
Trond Myklebustc81468a2007-12-14 14:56:05 -0500503 /* Match the full socket address */
Ian Dalld7371c42009-03-10 20:33:22 -0400504 if (!nfs_sockaddr_cmp(sap, clap))
David Howells24c8dbb2006-08-22 20:06:10 -0400505 continue;
506
Trond Myklebustc81468a2007-12-14 14:56:05 -0500507 atomic_inc(&clp->cl_count);
508 return clp;
David Howells24c8dbb2006-08-22 20:06:10 -0400509 }
David Howells24c8dbb2006-08-22 20:06:10 -0400510 return NULL;
David Howells24c8dbb2006-08-22 20:06:10 -0400511}
512
Trond Myklebust4697bd52012-05-23 13:24:36 -0400513static bool nfs_client_init_is_complete(const struct nfs_client *clp)
514{
515 return clp->cl_cons_state != NFS_CS_INITING;
516}
517
518int nfs_wait_client_init_complete(const struct nfs_client *clp)
519{
520 return wait_event_killable(nfs_client_active_wq,
521 nfs_client_init_is_complete(clp));
522}
523
David Howells24c8dbb2006-08-22 20:06:10 -0400524/*
Chuck Leverf4117032012-05-21 22:45:50 -0400525 * Found an existing client. Make sure it's ready before returning.
526 */
527static struct nfs_client *
528nfs_found_client(const struct nfs_client_initdata *cl_init,
529 struct nfs_client *clp)
530{
531 int error;
532
Trond Myklebust4697bd52012-05-23 13:24:36 -0400533 error = nfs_wait_client_init_complete(clp);
Chuck Leverf4117032012-05-21 22:45:50 -0400534 if (error < 0) {
535 nfs_put_client(clp);
536 return ERR_PTR(-ERESTARTSYS);
537 }
538
539 if (clp->cl_cons_state < NFS_CS_READY) {
540 error = clp->cl_cons_state;
541 nfs_put_client(clp);
542 return ERR_PTR(error);
543 }
544
Trond Myklebust54ac4712012-05-23 13:26:10 -0400545 smp_rmb();
546
Chuck Leverf4117032012-05-21 22:45:50 -0400547 BUG_ON(clp->cl_cons_state != NFS_CS_READY);
548
549 dprintk("<-- %s found nfs_client %p for %s\n",
550 __func__, clp, cl_init->hostname ?: "");
551 return clp;
552}
553
554/*
David Howells24c8dbb2006-08-22 20:06:10 -0400555 * Look up a client by IP address and protocol version
556 * - creates a new record if one doesn't yet exist
557 */
Andy Adamson45a52a02011-03-01 01:34:08 +0000558static struct nfs_client *
559nfs_get_client(const struct nfs_client_initdata *cl_init,
560 const struct rpc_timeout *timeparms,
561 const char *ip_addr,
Chuck Lever4bf590e2012-05-21 22:46:07 -0400562 rpc_authflavor_t authflavour)
David Howells24c8dbb2006-08-22 20:06:10 -0400563{
564 struct nfs_client *clp, *new = NULL;
Stanislav Kinsbursky6b131682012-01-23 17:26:05 +0000565 struct nfs_net *nn = net_generic(cl_init->net, nfs_net_id);
David Howells24c8dbb2006-08-22 20:06:10 -0400566
Chuck Leverd7422c42007-12-10 14:58:51 -0500567 dprintk("--> nfs_get_client(%s,v%u)\n",
568 cl_init->hostname ?: "", cl_init->rpc_ops->version);
David Howells24c8dbb2006-08-22 20:06:10 -0400569
570 /* see if the client already exists */
571 do {
Stanislav Kinsburskydc030852012-01-23 17:26:31 +0000572 spin_lock(&nn->nfs_client_lock);
David Howells24c8dbb2006-08-22 20:06:10 -0400573
Trond Myklebustc81468a2007-12-14 14:56:05 -0500574 clp = nfs_match_client(cl_init);
Chuck Leverf4117032012-05-21 22:45:50 -0400575 if (clp) {
576 spin_unlock(&nn->nfs_client_lock);
577 if (new)
578 nfs_free_client(new);
579 return nfs_found_client(cl_init, clp);
580 }
Chuck Lever8cab4c32012-05-21 22:45:59 -0400581 if (new) {
582 list_add(&new->cl_share_link, &nn->nfs_client_list);
583 spin_unlock(&nn->nfs_client_lock);
Chuck Lever4bf590e2012-05-21 22:46:07 -0400584 new->cl_flags = cl_init->init_flags;
Chuck Lever8cab4c32012-05-21 22:45:59 -0400585 return cl_init->rpc_ops->init_client(new,
586 timeparms, ip_addr,
Chuck Lever4bf590e2012-05-21 22:46:07 -0400587 authflavour);
Chuck Lever8cab4c32012-05-21 22:45:59 -0400588 }
David Howells24c8dbb2006-08-22 20:06:10 -0400589
Stanislav Kinsburskydc030852012-01-23 17:26:31 +0000590 spin_unlock(&nn->nfs_client_lock);
David Howells24c8dbb2006-08-22 20:06:10 -0400591
Trond Myklebust3a498022007-12-14 14:56:04 -0500592 new = nfs_alloc_client(cl_init);
Chuck Levera21bdd92009-06-17 18:02:10 -0700593 } while (!IS_ERR(new));
David Howells24c8dbb2006-08-22 20:06:10 -0400594
Chuck Leverf4117032012-05-21 22:45:50 -0400595 dprintk("<-- nfs_get_client() Failed to find %s (%ld)\n",
596 cl_init->hostname ?: "", PTR_ERR(new));
Chuck Levera21bdd92009-06-17 18:02:10 -0700597 return new;
David Howells24c8dbb2006-08-22 20:06:10 -0400598}
599
600/*
601 * Mark a server as ready or failed
602 */
Andy Adamson76db6d92009-04-01 09:22:38 -0400603void nfs_mark_client_ready(struct nfs_client *clp, int state)
David Howells24c8dbb2006-08-22 20:06:10 -0400604{
Trond Myklebust54ac4712012-05-23 13:26:10 -0400605 smp_wmb();
David Howells24c8dbb2006-08-22 20:06:10 -0400606 clp->cl_cons_state = state;
607 wake_up_all(&nfs_client_active_wq);
608}
David Howells5006a762006-08-22 20:06:12 -0400609
610/*
611 * Initialise the timeout values for a connection
612 */
613static void nfs_init_timeout_values(struct rpc_timeout *to, int proto,
614 unsigned int timeo, unsigned int retrans)
615{
616 to->to_initval = timeo * HZ / 10;
617 to->to_retries = retrans;
David Howells5006a762006-08-22 20:06:12 -0400618
619 switch (proto) {
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400620 case XPRT_TRANSPORT_TCP:
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400621 case XPRT_TRANSPORT_RDMA:
Trond Myklebust259875e2008-07-02 14:43:47 -0400622 if (to->to_retries == 0)
623 to->to_retries = NFS_DEF_TCP_RETRANS;
Trond Myklebust7a3e3e12007-12-20 16:03:57 -0500624 if (to->to_initval == 0)
Trond Myklebust259875e2008-07-02 14:43:47 -0400625 to->to_initval = NFS_DEF_TCP_TIMEO * HZ / 10;
David Howells5006a762006-08-22 20:06:12 -0400626 if (to->to_initval > NFS_MAX_TCP_TIMEOUT)
627 to->to_initval = NFS_MAX_TCP_TIMEOUT;
628 to->to_increment = to->to_initval;
629 to->to_maxval = to->to_initval + (to->to_increment * to->to_retries);
Trond Myklebust7a3e3e12007-12-20 16:03:57 -0500630 if (to->to_maxval > NFS_MAX_TCP_TIMEOUT)
631 to->to_maxval = NFS_MAX_TCP_TIMEOUT;
632 if (to->to_maxval < to->to_initval)
633 to->to_maxval = to->to_initval;
David Howells5006a762006-08-22 20:06:12 -0400634 to->to_exponential = 0;
635 break;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400636 case XPRT_TRANSPORT_UDP:
Trond Myklebust259875e2008-07-02 14:43:47 -0400637 if (to->to_retries == 0)
638 to->to_retries = NFS_DEF_UDP_RETRANS;
David Howells5006a762006-08-22 20:06:12 -0400639 if (!to->to_initval)
Trond Myklebust259875e2008-07-02 14:43:47 -0400640 to->to_initval = NFS_DEF_UDP_TIMEO * HZ / 10;
David Howells5006a762006-08-22 20:06:12 -0400641 if (to->to_initval > NFS_MAX_UDP_TIMEOUT)
642 to->to_initval = NFS_MAX_UDP_TIMEOUT;
643 to->to_maxval = NFS_MAX_UDP_TIMEOUT;
644 to->to_exponential = 1;
645 break;
Trond Myklebust259875e2008-07-02 14:43:47 -0400646 default:
647 BUG();
David Howells5006a762006-08-22 20:06:12 -0400648 }
649}
650
651/*
652 * Create an RPC client handle
653 */
Trond Myklebust59dca3b2008-01-03 16:29:06 -0500654static int nfs_create_rpc_client(struct nfs_client *clp,
Trond Myklebust33170232007-12-20 16:03:59 -0500655 const struct rpc_timeout *timeparms,
Chuck Lever4bf590e2012-05-21 22:46:07 -0400656 rpc_authflavor_t flavor)
David Howells5006a762006-08-22 20:06:12 -0400657{
David Howells5006a762006-08-22 20:06:12 -0400658 struct rpc_clnt *clnt = NULL;
Chuck Lever41877d22006-08-22 20:06:20 -0400659 struct rpc_create_args args = {
Chuck Lever73ea6662012-05-21 22:44:50 -0400660 .net = clp->cl_net,
Trond Myklebust59dca3b2008-01-03 16:29:06 -0500661 .protocol = clp->cl_proto,
Chuck Lever41877d22006-08-22 20:06:20 -0400662 .address = (struct sockaddr *)&clp->cl_addr,
Chuck Lever6e4cffd2007-12-10 14:58:15 -0500663 .addrsize = clp->cl_addrlen,
Trond Myklebust33170232007-12-20 16:03:59 -0500664 .timeout = timeparms,
Chuck Lever41877d22006-08-22 20:06:20 -0400665 .servername = clp->cl_hostname,
666 .program = &nfs_program,
667 .version = clp->rpc_ops->version,
668 .authflavor = flavor,
669 };
David Howells5006a762006-08-22 20:06:12 -0400670
Chuck Lever4bf590e2012-05-21 22:46:07 -0400671 if (test_bit(NFS_CS_DISCRTRY, &clp->cl_flags))
Chuck Lever4a01b8a2008-12-23 15:21:35 -0500672 args.flags |= RPC_CLNT_CREATE_DISCRTRY;
Chuck Lever4bf590e2012-05-21 22:46:07 -0400673 if (test_bit(NFS_CS_NORESVPORT, &clp->cl_flags))
Chuck Lever4a01b8a2008-12-23 15:21:35 -0500674 args.flags |= RPC_CLNT_CREATE_NONPRIVPORT;
675
David Howells5006a762006-08-22 20:06:12 -0400676 if (!IS_ERR(clp->cl_rpcclient))
677 return 0;
678
Chuck Lever41877d22006-08-22 20:06:20 -0400679 clnt = rpc_create(&args);
David Howells5006a762006-08-22 20:06:12 -0400680 if (IS_ERR(clnt)) {
681 dprintk("%s: cannot create RPC client. Error = %ld\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -0700682 __func__, PTR_ERR(clnt));
David Howells5006a762006-08-22 20:06:12 -0400683 return PTR_ERR(clnt);
684 }
685
David Howells5006a762006-08-22 20:06:12 -0400686 clp->cl_rpcclient = clnt;
687 return 0;
688}
David Howells54ceac42006-08-22 20:06:13 -0400689
690/*
691 * Version 2 or 3 client destruction
692 */
693static void nfs_destroy_server(struct nfs_server *server)
694{
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400695 if (!(server->flags & NFS_MOUNT_LOCAL_FLOCK) ||
696 !(server->flags & NFS_MOUNT_LOCAL_FCNTL))
Chuck Lever9289e7f2008-01-11 17:09:52 -0500697 nlmclnt_done(server->nlm_host);
David Howells54ceac42006-08-22 20:06:13 -0400698}
699
700/*
701 * Version 2 or 3 lockd setup
702 */
703static int nfs_start_lockd(struct nfs_server *server)
704{
Chuck Lever9289e7f2008-01-11 17:09:52 -0500705 struct nlm_host *host;
706 struct nfs_client *clp = server->nfs_client;
Chuck Lever883bb162008-01-15 16:04:20 -0500707 struct nlmclnt_initdata nlm_init = {
708 .hostname = clp->cl_hostname,
709 .address = (struct sockaddr *)&clp->cl_addr,
710 .addrlen = clp->cl_addrlen,
Chuck Lever883bb162008-01-15 16:04:20 -0500711 .nfs_version = clp->rpc_ops->version,
Chuck Lever0cb26592008-12-23 15:21:38 -0500712 .noresvport = server->flags & NFS_MOUNT_NORESVPORT ?
713 1 : 0,
Chuck Lever73ea6662012-05-21 22:44:50 -0400714 .net = clp->cl_net,
Chuck Lever883bb162008-01-15 16:04:20 -0500715 };
David Howells54ceac42006-08-22 20:06:13 -0400716
Chuck Lever883bb162008-01-15 16:04:20 -0500717 if (nlm_init.nfs_version > 3)
Chuck Lever9289e7f2008-01-11 17:09:52 -0500718 return 0;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400719 if ((server->flags & NFS_MOUNT_LOCAL_FLOCK) &&
720 (server->flags & NFS_MOUNT_LOCAL_FCNTL))
Chuck Lever9289e7f2008-01-11 17:09:52 -0500721 return 0;
722
Trond Myklebust8a6e5de2009-09-23 14:36:37 -0400723 switch (clp->cl_proto) {
724 default:
725 nlm_init.protocol = IPPROTO_TCP;
726 break;
727 case XPRT_TRANSPORT_UDP:
728 nlm_init.protocol = IPPROTO_UDP;
729 }
730
Chuck Lever883bb162008-01-15 16:04:20 -0500731 host = nlmclnt_init(&nlm_init);
Chuck Lever9289e7f2008-01-11 17:09:52 -0500732 if (IS_ERR(host))
733 return PTR_ERR(host);
734
735 server->nlm_host = host;
736 server->destroy = nfs_destroy_server;
737 return 0;
David Howells54ceac42006-08-22 20:06:13 -0400738}
739
740/*
741 * Initialise an NFSv3 ACL client connection
742 */
743#ifdef CONFIG_NFS_V3_ACL
744static void nfs_init_server_aclclient(struct nfs_server *server)
745{
Trond Myklebust40c553192007-12-14 14:56:07 -0500746 if (server->nfs_client->rpc_ops->version != 3)
David Howells54ceac42006-08-22 20:06:13 -0400747 goto out_noacl;
748 if (server->flags & NFS_MOUNT_NOACL)
749 goto out_noacl;
750
751 server->client_acl = rpc_bind_new_program(server->client, &nfsacl_program, 3);
752 if (IS_ERR(server->client_acl))
753 goto out_noacl;
754
755 /* No errors! Assume that Sun nfsacls are supported */
756 server->caps |= NFS_CAP_ACLS;
757 return;
758
759out_noacl:
760 server->caps &= ~NFS_CAP_ACLS;
761}
762#else
763static inline void nfs_init_server_aclclient(struct nfs_server *server)
764{
765 server->flags &= ~NFS_MOUNT_NOACL;
766 server->caps &= ~NFS_CAP_ACLS;
767}
768#endif
769
770/*
771 * Create a general RPC client
772 */
Trond Myklebust33170232007-12-20 16:03:59 -0500773static int nfs_init_server_rpcclient(struct nfs_server *server,
774 const struct rpc_timeout *timeo,
775 rpc_authflavor_t pseudoflavour)
David Howells54ceac42006-08-22 20:06:13 -0400776{
777 struct nfs_client *clp = server->nfs_client;
778
779 server->client = rpc_clone_client(clp->cl_rpcclient);
780 if (IS_ERR(server->client)) {
Harvey Harrison3110ff82008-05-02 13:42:44 -0700781 dprintk("%s: couldn't create rpc_client!\n", __func__);
David Howells54ceac42006-08-22 20:06:13 -0400782 return PTR_ERR(server->client);
783 }
784
Trond Myklebust33170232007-12-20 16:03:59 -0500785 memcpy(&server->client->cl_timeout_default,
786 timeo,
787 sizeof(server->client->cl_timeout_default));
788 server->client->cl_timeout = &server->client->cl_timeout_default;
789
David Howells54ceac42006-08-22 20:06:13 -0400790 if (pseudoflavour != clp->cl_rpcclient->cl_auth->au_flavor) {
791 struct rpc_auth *auth;
792
793 auth = rpcauth_create(pseudoflavour, server->client);
794 if (IS_ERR(auth)) {
Harvey Harrison3110ff82008-05-02 13:42:44 -0700795 dprintk("%s: couldn't create credcache!\n", __func__);
David Howells54ceac42006-08-22 20:06:13 -0400796 return PTR_ERR(auth);
797 }
798 }
799 server->client->cl_softrtry = 0;
800 if (server->flags & NFS_MOUNT_SOFT)
801 server->client->cl_softrtry = 1;
802
David Howells54ceac42006-08-22 20:06:13 -0400803 return 0;
804}
805
Chuck Lever8cab4c32012-05-21 22:45:59 -0400806/**
807 * nfs_init_client - Initialise an NFS2 or NFS3 client
808 *
809 * @clp: nfs_client to initialise
810 * @timeparms: timeout parameters for underlying RPC transport
811 * @ip_addr: IP presentation address (not used)
812 * @authflavor: authentication flavor for underlying RPC transport
Chuck Lever8cab4c32012-05-21 22:45:59 -0400813 *
814 * Returns pointer to an NFS client, or an ERR_PTR value.
David Howells54ceac42006-08-22 20:06:13 -0400815 */
Chuck Lever8cab4c32012-05-21 22:45:59 -0400816struct nfs_client *nfs_init_client(struct nfs_client *clp,
817 const struct rpc_timeout *timeparms,
Chuck Lever4bf590e2012-05-21 22:46:07 -0400818 const char *ip_addr, rpc_authflavor_t authflavour)
David Howells54ceac42006-08-22 20:06:13 -0400819{
David Howells54ceac42006-08-22 20:06:13 -0400820 int error;
821
822 if (clp->cl_cons_state == NFS_CS_READY) {
823 /* the client is already initialised */
824 dprintk("<-- nfs_init_client() = 0 [already %p]\n", clp);
Chuck Lever8cab4c32012-05-21 22:45:59 -0400825 return clp;
David Howells54ceac42006-08-22 20:06:13 -0400826 }
827
David Howells54ceac42006-08-22 20:06:13 -0400828 /*
829 * Create a client RPC handle for doing FSSTAT with UNIX auth only
830 * - RFC 2623, sec 2.3.2
831 */
Chuck Lever4bf590e2012-05-21 22:46:07 -0400832 error = nfs_create_rpc_client(clp, timeparms, RPC_AUTH_UNIX);
David Howells54ceac42006-08-22 20:06:13 -0400833 if (error < 0)
834 goto error;
835 nfs_mark_client_ready(clp, NFS_CS_READY);
Chuck Lever8cab4c32012-05-21 22:45:59 -0400836 return clp;
David Howells54ceac42006-08-22 20:06:13 -0400837
838error:
839 nfs_mark_client_ready(clp, error);
Chuck Lever8cab4c32012-05-21 22:45:59 -0400840 nfs_put_client(clp);
David Howells54ceac42006-08-22 20:06:13 -0400841 dprintk("<-- nfs_init_client() = xerror %d\n", error);
Chuck Lever8cab4c32012-05-21 22:45:59 -0400842 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -0400843}
844
845/*
846 * Create a version 2 or 3 client
847 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -0400848static int nfs_init_server(struct nfs_server *server,
849 const struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -0400850{
Trond Myklebust3a498022007-12-14 14:56:04 -0500851 struct nfs_client_initdata cl_init = {
852 .hostname = data->nfs_server.hostname,
Chuck Leverd7422c42007-12-10 14:58:51 -0500853 .addr = (const struct sockaddr *)&data->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -0500854 .addrlen = data->nfs_server.addrlen,
Bryan Schumaker2ba68002012-05-10 16:47:19 -0400855 .rpc_ops = NULL,
Trond Myklebust59dca3b2008-01-03 16:29:06 -0500856 .proto = data->nfs_server.protocol,
Stanislav Kinsburskye50a7a12012-01-10 16:12:46 +0400857 .net = data->net,
Trond Myklebust3a498022007-12-14 14:56:04 -0500858 };
Trond Myklebust33170232007-12-20 16:03:59 -0500859 struct rpc_timeout timeparms;
David Howells54ceac42006-08-22 20:06:13 -0400860 struct nfs_client *clp;
Trond Myklebust3a498022007-12-14 14:56:04 -0500861 int error;
David Howells54ceac42006-08-22 20:06:13 -0400862
863 dprintk("--> nfs_init_server()\n");
864
Bryan Schumaker2ba68002012-05-10 16:47:19 -0400865 switch (data->version) {
866#ifdef CONFIG_NFS_V2
867 case 2:
868 cl_init.rpc_ops = &nfs_v2_clientops;
869 break;
David Howells54ceac42006-08-22 20:06:13 -0400870#endif
Bryan Schumaker2ba68002012-05-10 16:47:19 -0400871#ifdef CONFIG_NFS_V3
872 case 3:
873 cl_init.rpc_ops = &nfs_v3_clientops;
874 break;
875#endif
876 default:
877 return -EPROTONOSUPPORT;
878 }
David Howells54ceac42006-08-22 20:06:13 -0400879
Andy Adamson45a52a02011-03-01 01:34:08 +0000880 nfs_init_timeout_values(&timeparms, data->nfs_server.protocol,
881 data->timeo, data->retrans);
Chuck Lever4bf590e2012-05-21 22:46:07 -0400882 if (data->flags & NFS_MOUNT_NORESVPORT)
883 set_bit(NFS_CS_NORESVPORT, &cl_init.init_flags);
Andy Adamson45a52a02011-03-01 01:34:08 +0000884
David Howells54ceac42006-08-22 20:06:13 -0400885 /* Allocate or find a client reference we can use */
Chuck Lever4bf590e2012-05-21 22:46:07 -0400886 clp = nfs_get_client(&cl_init, &timeparms, NULL, RPC_AUTH_UNIX);
David Howells54ceac42006-08-22 20:06:13 -0400887 if (IS_ERR(clp)) {
888 dprintk("<-- nfs_init_server() = error %ld\n", PTR_ERR(clp));
889 return PTR_ERR(clp);
890 }
891
David Howells54ceac42006-08-22 20:06:13 -0400892 server->nfs_client = clp;
893
894 /* Initialise the client representation from the mount data */
Trond Myklebustff3525a2008-08-15 16:59:14 -0400895 server->flags = data->flags;
David Howellsb797cac2009-04-03 16:42:48 +0100896 server->options = data->options;
Trond Myklebust62ab460c2009-08-09 15:06:19 -0400897 server->caps |= NFS_CAP_HARDLINKS|NFS_CAP_SYMLINKS|NFS_CAP_FILEID|
898 NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER|NFS_CAP_OWNER_GROUP|
Trond Myklebust3a1556e2012-04-27 13:48:18 -0400899 NFS_CAP_ATIME|NFS_CAP_CTIME|NFS_CAP_MTIME|NFS_CAP_CHANGE_ATTR;
David Howells54ceac42006-08-22 20:06:13 -0400900
901 if (data->rsize)
902 server->rsize = nfs_block_size(data->rsize, NULL);
903 if (data->wsize)
904 server->wsize = nfs_block_size(data->wsize, NULL);
905
906 server->acregmin = data->acregmin * HZ;
907 server->acregmax = data->acregmax * HZ;
908 server->acdirmin = data->acdirmin * HZ;
909 server->acdirmax = data->acdirmax * HZ;
910
911 /* Start lockd here, before we might error out */
912 error = nfs_start_lockd(server);
913 if (error < 0)
914 goto error;
915
Chuck Leverf22d6d72008-03-14 14:10:22 -0400916 server->port = data->nfs_server.port;
917
Trond Myklebust33170232007-12-20 16:03:59 -0500918 error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]);
David Howells54ceac42006-08-22 20:06:13 -0400919 if (error < 0)
920 goto error;
921
Chuck Lever3f8400d2008-03-14 14:10:30 -0400922 /* Preserve the values of mount_server-related mount options */
923 if (data->mount_server.addrlen) {
924 memcpy(&server->mountd_address, &data->mount_server.address,
925 data->mount_server.addrlen);
926 server->mountd_addrlen = data->mount_server.addrlen;
927 }
928 server->mountd_version = data->mount_server.version;
929 server->mountd_port = data->mount_server.port;
930 server->mountd_protocol = data->mount_server.protocol;
931
David Howells54ceac42006-08-22 20:06:13 -0400932 server->namelen = data->namlen;
933 /* Create a client RPC handle for the NFSv3 ACL management interface */
934 nfs_init_server_aclclient(server);
David Howells54ceac42006-08-22 20:06:13 -0400935 dprintk("<-- nfs_init_server() = 0 [new %p]\n", clp);
936 return 0;
937
938error:
939 server->nfs_client = NULL;
940 nfs_put_client(clp);
941 dprintk("<-- nfs_init_server() = xerror %d\n", error);
942 return error;
943}
944
945/*
946 * Load up the server record from information gained in an fsinfo record
947 */
Benny Halevy738fd0f32011-07-30 20:52:36 -0400948static void nfs_server_set_fsinfo(struct nfs_server *server,
949 struct nfs_fh *mntfh,
950 struct nfs_fsinfo *fsinfo)
David Howells54ceac42006-08-22 20:06:13 -0400951{
952 unsigned long max_rpc_payload;
953
954 /* Work out a lot of parameters */
955 if (server->rsize == 0)
956 server->rsize = nfs_block_size(fsinfo->rtpref, NULL);
957 if (server->wsize == 0)
958 server->wsize = nfs_block_size(fsinfo->wtpref, NULL);
959
960 if (fsinfo->rtmax >= 512 && server->rsize > fsinfo->rtmax)
961 server->rsize = nfs_block_size(fsinfo->rtmax, NULL);
962 if (fsinfo->wtmax >= 512 && server->wsize > fsinfo->wtmax)
963 server->wsize = nfs_block_size(fsinfo->wtmax, NULL);
964
965 max_rpc_payload = nfs_block_size(rpc_max_payload(server->client), NULL);
966 if (server->rsize > max_rpc_payload)
967 server->rsize = max_rpc_payload;
968 if (server->rsize > NFS_MAX_FILE_IO_SIZE)
969 server->rsize = NFS_MAX_FILE_IO_SIZE;
970 server->rpages = (server->rsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
Peter Zijlstrae0bf68d2007-10-16 23:25:46 -0700971
Jens Axboed9938312009-06-12 14:45:52 +0200972 server->backing_dev_info.name = "nfs";
David Howells54ceac42006-08-22 20:06:13 -0400973 server->backing_dev_info.ra_pages = server->rpages * NFS_MAX_READAHEAD;
974
975 if (server->wsize > max_rpc_payload)
976 server->wsize = max_rpc_payload;
977 if (server->wsize > NFS_MAX_FILE_IO_SIZE)
978 server->wsize = NFS_MAX_FILE_IO_SIZE;
979 server->wpages = (server->wsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
Fred Isamandae100c2011-07-30 20:52:37 -0400980 server->pnfs_blksize = fsinfo->blksize;
Benny Halevy738fd0f32011-07-30 20:52:36 -0400981 set_pnfs_layoutdriver(server, mntfh, fsinfo->layouttype);
Ricardo Labiaga85e174b2010-10-20 00:17:58 -0400982
David Howells54ceac42006-08-22 20:06:13 -0400983 server->wtmult = nfs_block_bits(fsinfo->wtmult, NULL);
984
985 server->dtsize = nfs_block_size(fsinfo->dtpref, NULL);
Bryan Schumaker56e4ebf2010-10-20 15:44:37 -0400986 if (server->dtsize > PAGE_CACHE_SIZE * NFS_MAX_READDIR_PAGES)
987 server->dtsize = PAGE_CACHE_SIZE * NFS_MAX_READDIR_PAGES;
David Howells54ceac42006-08-22 20:06:13 -0400988 if (server->dtsize > server->rsize)
989 server->dtsize = server->rsize;
990
991 if (server->flags & NFS_MOUNT_NOAC) {
992 server->acregmin = server->acregmax = 0;
993 server->acdirmin = server->acdirmax = 0;
994 }
995
996 server->maxfilesize = fsinfo->maxfilesize;
997
Ricardo Labiaga6b967242010-10-12 16:30:05 -0700998 server->time_delta = fsinfo->time_delta;
999
David Howells54ceac42006-08-22 20:06:13 -04001000 /* We're airborne Set socket buffersize */
1001 rpc_setbufsize(server->client, server->wsize + 100, server->rsize + 100);
1002}
1003
1004/*
1005 * Probe filesystem information, including the FSID on v2/v3
1006 */
1007static int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *mntfh, struct nfs_fattr *fattr)
1008{
1009 struct nfs_fsinfo fsinfo;
1010 struct nfs_client *clp = server->nfs_client;
1011 int error;
1012
1013 dprintk("--> nfs_probe_fsinfo()\n");
1014
1015 if (clp->rpc_ops->set_capabilities != NULL) {
1016 error = clp->rpc_ops->set_capabilities(server, mntfh);
1017 if (error < 0)
1018 goto out_error;
1019 }
1020
1021 fsinfo.fattr = fattr;
Ricardo Labiaga85e174b2010-10-20 00:17:58 -04001022 fsinfo.layouttype = 0;
David Howells54ceac42006-08-22 20:06:13 -04001023 error = clp->rpc_ops->fsinfo(server, mntfh, &fsinfo);
1024 if (error < 0)
1025 goto out_error;
1026
Benny Halevy738fd0f32011-07-30 20:52:36 -04001027 nfs_server_set_fsinfo(server, mntfh, &fsinfo);
David Howells54ceac42006-08-22 20:06:13 -04001028
1029 /* Get some general file system info */
1030 if (server->namelen == 0) {
1031 struct nfs_pathconf pathinfo;
1032
1033 pathinfo.fattr = fattr;
1034 nfs_fattr_init(fattr);
1035
1036 if (clp->rpc_ops->pathconf(server, mntfh, &pathinfo) >= 0)
1037 server->namelen = pathinfo.max_namelen;
1038 }
1039
1040 dprintk("<-- nfs_probe_fsinfo() = 0\n");
1041 return 0;
1042
1043out_error:
1044 dprintk("nfs_probe_fsinfo: error = %d\n", -error);
1045 return error;
1046}
1047
1048/*
1049 * Copy useful information when duplicating a server record
1050 */
1051static void nfs_server_copy_userdata(struct nfs_server *target, struct nfs_server *source)
1052{
1053 target->flags = source->flags;
Chuck Lever356e76b2010-04-22 15:35:56 -04001054 target->rsize = source->rsize;
1055 target->wsize = source->wsize;
David Howells54ceac42006-08-22 20:06:13 -04001056 target->acregmin = source->acregmin;
1057 target->acregmax = source->acregmax;
1058 target->acdirmin = source->acdirmin;
1059 target->acdirmax = source->acdirmax;
1060 target->caps = source->caps;
David Howells2df54802009-09-23 14:36:39 -04001061 target->options = source->options;
David Howells54ceac42006-08-22 20:06:13 -04001062}
1063
Chuck Leverfca52382010-12-24 01:32:32 +00001064static void nfs_server_insert_lists(struct nfs_server *server)
1065{
1066 struct nfs_client *clp = server->nfs_client;
Chuck Lever73ea6662012-05-21 22:44:50 -04001067 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Chuck Leverfca52382010-12-24 01:32:32 +00001068
Stanislav Kinsburskydc030852012-01-23 17:26:31 +00001069 spin_lock(&nn->nfs_client_lock);
Chuck Leverfca52382010-12-24 01:32:32 +00001070 list_add_tail_rcu(&server->client_link, &clp->cl_superblocks);
Stanislav Kinsburskyc25d32b2012-01-23 17:26:14 +00001071 list_add_tail(&server->master_link, &nn->nfs_volume_list);
Andy Adamsond3b4c9d2011-03-01 01:34:10 +00001072 clear_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state);
Stanislav Kinsburskydc030852012-01-23 17:26:31 +00001073 spin_unlock(&nn->nfs_client_lock);
Chuck Leverfca52382010-12-24 01:32:32 +00001074
1075}
1076
1077static void nfs_server_remove_lists(struct nfs_server *server)
1078{
Andy Adamsond3b4c9d2011-03-01 01:34:10 +00001079 struct nfs_client *clp = server->nfs_client;
Trond Myklebust4c03ae42012-02-07 00:05:11 -05001080 struct nfs_net *nn;
Andy Adamsond3b4c9d2011-03-01 01:34:10 +00001081
Trond Myklebust4c03ae42012-02-07 00:05:11 -05001082 if (clp == NULL)
1083 return;
Chuck Lever73ea6662012-05-21 22:44:50 -04001084 nn = net_generic(clp->cl_net, nfs_net_id);
Stanislav Kinsburskydc030852012-01-23 17:26:31 +00001085 spin_lock(&nn->nfs_client_lock);
Chuck Leverfca52382010-12-24 01:32:32 +00001086 list_del_rcu(&server->client_link);
Trond Myklebust4c03ae42012-02-07 00:05:11 -05001087 if (list_empty(&clp->cl_superblocks))
Andy Adamsond3b4c9d2011-03-01 01:34:10 +00001088 set_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state);
Chuck Leverfca52382010-12-24 01:32:32 +00001089 list_del(&server->master_link);
Stanislav Kinsburskydc030852012-01-23 17:26:31 +00001090 spin_unlock(&nn->nfs_client_lock);
Chuck Leverfca52382010-12-24 01:32:32 +00001091
1092 synchronize_rcu();
1093}
1094
David Howells54ceac42006-08-22 20:06:13 -04001095/*
1096 * Allocate and initialise a server record
1097 */
1098static struct nfs_server *nfs_alloc_server(void)
1099{
1100 struct nfs_server *server;
1101
1102 server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL);
1103 if (!server)
1104 return NULL;
1105
1106 server->client = server->client_acl = ERR_PTR(-EINVAL);
1107
1108 /* Zero out the NFS state stuff */
1109 INIT_LIST_HEAD(&server->client_link);
1110 INIT_LIST_HEAD(&server->master_link);
Chuck Leverd3978bb2010-12-24 01:33:04 +00001111 INIT_LIST_HEAD(&server->delegations);
Weston Andros Adamson6382a442011-06-01 16:44:44 -04001112 INIT_LIST_HEAD(&server->layouts);
Chuck Lever0aaaf5c2011-12-06 16:13:48 -05001113 INIT_LIST_HEAD(&server->state_owners_lru);
David Howells54ceac42006-08-22 20:06:13 -04001114
Steve Dicksonef818a22007-11-08 04:05:04 -05001115 atomic_set(&server->active, 0);
1116
David Howells54ceac42006-08-22 20:06:13 -04001117 server->io_stats = nfs_alloc_iostats();
1118 if (!server->io_stats) {
1119 kfree(server);
1120 return NULL;
1121 }
1122
Jens Axboe48d07642009-09-21 09:59:39 +02001123 if (bdi_init(&server->backing_dev_info)) {
1124 nfs_free_iostats(server->io_stats);
1125 kfree(server);
1126 return NULL;
1127 }
1128
Trond Myklebust9157c312012-01-17 22:04:24 -05001129 ida_init(&server->openowner_id);
Trond Myklebustd2d7ce22012-01-17 22:04:25 -05001130 ida_init(&server->lockowner_id);
Fred Isamanf7e89172011-01-06 11:36:32 +00001131 pnfs_init_server(server);
1132
David Howells54ceac42006-08-22 20:06:13 -04001133 return server;
1134}
1135
1136/*
1137 * Free up a server record
1138 */
1139void nfs_free_server(struct nfs_server *server)
1140{
1141 dprintk("--> nfs_free_server()\n");
1142
Chuck Leverfca52382010-12-24 01:32:32 +00001143 nfs_server_remove_lists(server);
Ricardo Labiaga85e174b2010-10-20 00:17:58 -04001144 unset_pnfs_layoutdriver(server);
David Howells54ceac42006-08-22 20:06:13 -04001145
1146 if (server->destroy != NULL)
1147 server->destroy(server);
Trond Myklebust5cef3382007-12-11 22:01:56 -05001148
1149 if (!IS_ERR(server->client_acl))
1150 rpc_shutdown_client(server->client_acl);
David Howells54ceac42006-08-22 20:06:13 -04001151 if (!IS_ERR(server->client))
1152 rpc_shutdown_client(server->client);
1153
1154 nfs_put_client(server->nfs_client);
1155
Trond Myklebustd2d7ce22012-01-17 22:04:25 -05001156 ida_destroy(&server->lockowner_id);
Trond Myklebust9157c312012-01-17 22:04:24 -05001157 ida_destroy(&server->openowner_id);
David Howells54ceac42006-08-22 20:06:13 -04001158 nfs_free_iostats(server->io_stats);
Peter Zijlstrae0bf68d2007-10-16 23:25:46 -07001159 bdi_destroy(&server->backing_dev_info);
David Howells54ceac42006-08-22 20:06:13 -04001160 kfree(server);
1161 nfs_release_automount_timer();
1162 dprintk("<-- nfs_free_server()\n");
1163}
1164
1165/*
1166 * Create a version 2 or 3 volume record
1167 * - keyed on server and FSID
1168 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001169struct nfs_server *nfs_create_server(const struct nfs_parsed_mount_data *data,
David Howells54ceac42006-08-22 20:06:13 -04001170 struct nfs_fh *mntfh)
1171{
1172 struct nfs_server *server;
Trond Myklebustfbca7792010-04-16 16:22:46 -04001173 struct nfs_fattr *fattr;
David Howells54ceac42006-08-22 20:06:13 -04001174 int error;
1175
1176 server = nfs_alloc_server();
1177 if (!server)
1178 return ERR_PTR(-ENOMEM);
1179
Trond Myklebustfbca7792010-04-16 16:22:46 -04001180 error = -ENOMEM;
1181 fattr = nfs_alloc_fattr();
1182 if (fattr == NULL)
1183 goto error;
1184
David Howells54ceac42006-08-22 20:06:13 -04001185 /* Get a client representation */
1186 error = nfs_init_server(server, data);
1187 if (error < 0)
1188 goto error;
1189
1190 BUG_ON(!server->nfs_client);
1191 BUG_ON(!server->nfs_client->rpc_ops);
1192 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
1193
1194 /* Probe the root fh to retrieve its FSID */
Trond Myklebustfbca7792010-04-16 16:22:46 -04001195 error = nfs_probe_fsinfo(server, mntfh, fattr);
David Howells54ceac42006-08-22 20:06:13 -04001196 if (error < 0)
1197 goto error;
Trond Myklebust54af3bb2007-09-28 12:27:41 -04001198 if (server->nfs_client->rpc_ops->version == 3) {
1199 if (server->namelen == 0 || server->namelen > NFS3_MAXNAMLEN)
1200 server->namelen = NFS3_MAXNAMLEN;
1201 if (!(data->flags & NFS_MOUNT_NORDIRPLUS))
1202 server->caps |= NFS_CAP_READDIRPLUS;
1203 } else {
1204 if (server->namelen == 0 || server->namelen > NFS2_MAXNAMLEN)
1205 server->namelen = NFS2_MAXNAMLEN;
1206 }
1207
Trond Myklebustfbca7792010-04-16 16:22:46 -04001208 if (!(fattr->valid & NFS_ATTR_FATTR)) {
1209 error = server->nfs_client->rpc_ops->getattr(server, mntfh, fattr);
David Howells54ceac42006-08-22 20:06:13 -04001210 if (error < 0) {
1211 dprintk("nfs_create_server: getattr error = %d\n", -error);
1212 goto error;
1213 }
1214 }
Trond Myklebustfbca7792010-04-16 16:22:46 -04001215 memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid));
David Howells54ceac42006-08-22 20:06:13 -04001216
David Howells6daabf12006-08-24 15:44:16 -04001217 dprintk("Server FSID: %llx:%llx\n",
1218 (unsigned long long) server->fsid.major,
1219 (unsigned long long) server->fsid.minor);
David Howells54ceac42006-08-22 20:06:13 -04001220
Chuck Leverfca52382010-12-24 01:32:32 +00001221 nfs_server_insert_lists(server);
David Howells54ceac42006-08-22 20:06:13 -04001222 server->mount_time = jiffies;
Trond Myklebustfbca7792010-04-16 16:22:46 -04001223 nfs_free_fattr(fattr);
David Howells54ceac42006-08-22 20:06:13 -04001224 return server;
1225
1226error:
Trond Myklebustfbca7792010-04-16 16:22:46 -04001227 nfs_free_fattr(fattr);
David Howells54ceac42006-08-22 20:06:13 -04001228 nfs_free_server(server);
1229 return ERR_PTR(error);
1230}
1231
1232#ifdef CONFIG_NFS_V4
1233/*
Andy Adamsonc36fca52011-01-06 02:04:32 +00001234 * NFSv4.0 callback thread helper
1235 *
Andy Adamsonc36fca52011-01-06 02:04:32 +00001236 * Find a client by callback identifier
1237 */
1238struct nfs_client *
Stanislav Kinsbursky28cd1b32012-01-23 17:26:22 +00001239nfs4_find_client_ident(struct net *net, int cb_ident)
Andy Adamsonc36fca52011-01-06 02:04:32 +00001240{
1241 struct nfs_client *clp;
Stanislav Kinsbursky28cd1b32012-01-23 17:26:22 +00001242 struct nfs_net *nn = net_generic(net, nfs_net_id);
Andy Adamsonc36fca52011-01-06 02:04:32 +00001243
Stanislav Kinsburskydc030852012-01-23 17:26:31 +00001244 spin_lock(&nn->nfs_client_lock);
Stanislav Kinsbursky28cd1b32012-01-23 17:26:22 +00001245 clp = idr_find(&nn->cb_ident_idr, cb_ident);
Andy Adamsonc36fca52011-01-06 02:04:32 +00001246 if (clp)
1247 atomic_inc(&clp->cl_count);
Stanislav Kinsburskydc030852012-01-23 17:26:31 +00001248 spin_unlock(&nn->nfs_client_lock);
Andy Adamsonc36fca52011-01-06 02:04:32 +00001249 return clp;
1250}
1251
1252#if defined(CONFIG_NFS_V4_1)
1253/*
1254 * NFSv4.1 callback thread helper
1255 * For CB_COMPOUND calls, find a client by IP address, protocol version,
1256 * minorversion, and sessionID
1257 *
Andy Adamsonc36fca52011-01-06 02:04:32 +00001258 * Returns NULL if no such client
1259 */
1260struct nfs_client *
Stanislav Kinsburskyc7add9a2012-01-26 15:11:49 +04001261nfs4_find_client_sessionid(struct net *net, const struct sockaddr *addr,
Andy Adamson778be232011-01-25 15:38:01 +00001262 struct nfs4_sessionid *sid)
Andy Adamsonc36fca52011-01-06 02:04:32 +00001263{
1264 struct nfs_client *clp;
Stanislav Kinsburskyc7add9a2012-01-26 15:11:49 +04001265 struct nfs_net *nn = net_generic(net, nfs_net_id);
Andy Adamsonc36fca52011-01-06 02:04:32 +00001266
Stanislav Kinsburskydc030852012-01-23 17:26:31 +00001267 spin_lock(&nn->nfs_client_lock);
Stanislav Kinsbursky6b131682012-01-23 17:26:05 +00001268 list_for_each_entry(clp, &nn->nfs_client_list, cl_share_link) {
Andy Adamsonc36fca52011-01-06 02:04:32 +00001269 if (nfs4_cb_match_client(addr, clp, 1) == false)
1270 continue;
1271
1272 if (!nfs4_has_session(clp))
1273 continue;
1274
Andy Adamson778be232011-01-25 15:38:01 +00001275 /* Match sessionid*/
1276 if (memcmp(clp->cl_session->sess_id.data,
1277 sid->data, NFS4_MAX_SESSIONID_LEN) != 0)
Andy Adamsonc36fca52011-01-06 02:04:32 +00001278 continue;
1279
1280 atomic_inc(&clp->cl_count);
Stanislav Kinsburskydc030852012-01-23 17:26:31 +00001281 spin_unlock(&nn->nfs_client_lock);
Andy Adamsonc36fca52011-01-06 02:04:32 +00001282 return clp;
1283 }
Stanislav Kinsburskydc030852012-01-23 17:26:31 +00001284 spin_unlock(&nn->nfs_client_lock);
Andy Adamsonc36fca52011-01-06 02:04:32 +00001285 return NULL;
1286}
1287
1288#else /* CONFIG_NFS_V4_1 */
1289
1290struct nfs_client *
Stanislav Kinsburskyb6d1e832012-02-07 19:53:19 +04001291nfs4_find_client_sessionid(struct net *net, const struct sockaddr *addr,
Andy Adamson778be232011-01-25 15:38:01 +00001292 struct nfs4_sessionid *sid)
Andy Adamsonc36fca52011-01-06 02:04:32 +00001293{
1294 return NULL;
1295}
1296#endif /* CONFIG_NFS_V4_1 */
1297
1298/*
Benny Halevy9bdaa862009-04-01 09:22:55 -04001299 * Initialize the NFS4 callback service
1300 */
1301static int nfs4_init_callback(struct nfs_client *clp)
1302{
1303 int error;
1304
1305 if (clp->rpc_ops->version == 4) {
Trond Myklebust2446ab62012-03-01 17:00:56 -05001306 struct rpc_xprt *xprt;
1307
1308 xprt = rcu_dereference_raw(clp->cl_rpcclient->cl_xprt);
1309
Andy Adamson0b5b7ae2009-04-01 09:23:15 -04001310 if (nfs4_has_session(clp)) {
Trond Myklebust2446ab62012-03-01 17:00:56 -05001311 error = xprt_setup_backchannel(xprt,
Andy Adamson0b5b7ae2009-04-01 09:23:15 -04001312 NFS41_BC_MIN_CALLBACKS);
1313 if (error < 0)
1314 return error;
1315 }
1316
Trond Myklebust2446ab62012-03-01 17:00:56 -05001317 error = nfs_callback_up(clp->cl_mvops->minor_version, xprt);
Benny Halevy9bdaa862009-04-01 09:22:55 -04001318 if (error < 0) {
1319 dprintk("%s: failed to start callback. Error = %d\n",
1320 __func__, error);
1321 return error;
1322 }
1323 __set_bit(NFS_CS_CALLBACK, &clp->cl_res_state);
1324 }
1325 return 0;
1326}
1327
1328/*
Andy Adamson557134a2009-04-01 09:21:53 -04001329 * Initialize the minor version specific parts of an NFS4 client record
1330 */
1331static int nfs4_init_client_minor_version(struct nfs_client *clp)
1332{
1333#if defined(CONFIG_NFS_V4_1)
Trond Myklebust97dc1352010-06-16 09:52:26 -04001334 if (clp->cl_mvops->minor_version) {
Andy Adamson557134a2009-04-01 09:21:53 -04001335 struct nfs4_session *session = NULL;
1336 /*
1337 * Create the session and mark it expired.
1338 * When a SEQUENCE operation encounters the expired session
1339 * it will do session recovery to initialize it.
1340 */
1341 session = nfs4_alloc_session(clp);
1342 if (!session)
1343 return -ENOMEM;
1344
1345 clp->cl_session = session;
Trond Myklebustfe74ba32010-06-16 09:52:27 -04001346 /*
1347 * The create session reply races with the server back
1348 * channel probe. Mark the client NFS_CS_SESSION_INITING
1349 * so that the client back channel can find the
1350 * nfs_client struct
1351 */
Trond Myklebust4697bd52012-05-23 13:24:36 -04001352 nfs_mark_client_ready(clp, NFS_CS_SESSION_INITING);
Andy Adamson557134a2009-04-01 09:21:53 -04001353 }
1354#endif /* CONFIG_NFS_V4_1 */
1355
Benny Halevy71468512009-04-01 09:22:56 -04001356 return nfs4_init_callback(clp);
Andy Adamson557134a2009-04-01 09:21:53 -04001357}
1358
Chuck Lever8cab4c32012-05-21 22:45:59 -04001359/**
1360 * nfs4_init_client - Initialise an NFS4 client record
1361 *
1362 * @clp: nfs_client to initialise
1363 * @timeparms: timeout parameters for underlying RPC transport
1364 * @ip_addr: callback IP address in presentation format
1365 * @authflavor: authentication flavor for underlying RPC transport
Chuck Lever8cab4c32012-05-21 22:45:59 -04001366 *
1367 * Returns pointer to an NFS client, or an ERR_PTR value.
David Howells54ceac42006-08-22 20:06:13 -04001368 */
Chuck Lever8cab4c32012-05-21 22:45:59 -04001369struct nfs_client *nfs4_init_client(struct nfs_client *clp,
1370 const struct rpc_timeout *timeparms,
1371 const char *ip_addr,
Chuck Lever4bf590e2012-05-21 22:46:07 -04001372 rpc_authflavor_t authflavour)
David Howells54ceac42006-08-22 20:06:13 -04001373{
Chuck Lever31b8e2a2012-03-01 17:01:23 -05001374 char buf[INET6_ADDRSTRLEN + 1];
David Howells54ceac42006-08-22 20:06:13 -04001375 int error;
1376
1377 if (clp->cl_cons_state == NFS_CS_READY) {
1378 /* the client is initialised already */
1379 dprintk("<-- nfs4_init_client() = 0 [already %p]\n", clp);
Chuck Lever8cab4c32012-05-21 22:45:59 -04001380 return clp;
David Howells54ceac42006-08-22 20:06:13 -04001381 }
1382
1383 /* Check NFS protocol revision and initialize RPC op vector */
1384 clp->rpc_ops = &nfs_v4_clientops;
1385
Chuck Lever4bf590e2012-05-21 22:46:07 -04001386 __set_bit(NFS_CS_DISCRTRY, &clp->cl_flags);
1387 error = nfs_create_rpc_client(clp, timeparms, authflavour);
David Howells54ceac42006-08-22 20:06:13 -04001388 if (error < 0)
1389 goto error;
Chuck Lever31b8e2a2012-03-01 17:01:23 -05001390
1391 /* If no clientaddr= option was specified, find a usable cb address */
1392 if (ip_addr == NULL) {
1393 struct sockaddr_storage cb_addr;
1394 struct sockaddr *sap = (struct sockaddr *)&cb_addr;
1395
1396 error = rpc_localaddr(clp->cl_rpcclient, sap, sizeof(cb_addr));
1397 if (error < 0)
1398 goto error;
1399 error = rpc_ntop(sap, buf, sizeof(buf));
1400 if (error < 0)
1401 goto error;
1402 ip_addr = (const char *)buf;
1403 }
Ben Hutchingsf4373bf2009-10-06 15:42:18 -04001404 strlcpy(clp->cl_ipaddr, ip_addr, sizeof(clp->cl_ipaddr));
David Howells54ceac42006-08-22 20:06:13 -04001405
1406 error = nfs_idmap_new(clp);
1407 if (error < 0) {
1408 dprintk("%s: failed to create idmapper. Error = %d\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07001409 __func__, error);
David Howells54ceac42006-08-22 20:06:13 -04001410 goto error;
1411 }
Trond Myklebust9c5bf382006-08-22 20:06:14 -04001412 __set_bit(NFS_CS_IDMAP, &clp->cl_res_state);
David Howells54ceac42006-08-22 20:06:13 -04001413
Andy Adamson557134a2009-04-01 09:21:53 -04001414 error = nfs4_init_client_minor_version(clp);
1415 if (error < 0)
1416 goto error;
1417
Andy Adamson76db6d92009-04-01 09:22:38 -04001418 if (!nfs4_has_session(clp))
1419 nfs_mark_client_ready(clp, NFS_CS_READY);
Chuck Lever8cab4c32012-05-21 22:45:59 -04001420 return clp;
David Howells54ceac42006-08-22 20:06:13 -04001421
1422error:
1423 nfs_mark_client_ready(clp, error);
Chuck Lever8cab4c32012-05-21 22:45:59 -04001424 nfs_put_client(clp);
David Howells54ceac42006-08-22 20:06:13 -04001425 dprintk("<-- nfs4_init_client() = xerror %d\n", error);
Chuck Lever8cab4c32012-05-21 22:45:59 -04001426 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04001427}
1428
1429/*
1430 * Set up an NFS4 client
1431 */
1432static int nfs4_set_client(struct nfs_server *server,
Chuck Leverdcecae02007-12-10 14:58:59 -05001433 const char *hostname,
1434 const struct sockaddr *addr,
1435 const size_t addrlen,
J. Bruce Fields7d9ac062006-10-19 23:28:39 -07001436 const char *ip_addr,
David Howells54ceac42006-08-22 20:06:13 -04001437 rpc_authflavor_t authflavour,
Benny Halevy94a417f2009-04-01 09:21:49 -04001438 int proto, const struct rpc_timeout *timeparms,
Stanislav Kinsburskye50a7a12012-01-10 16:12:46 +04001439 u32 minorversion, struct net *net)
David Howells54ceac42006-08-22 20:06:13 -04001440{
Trond Myklebust3a498022007-12-14 14:56:04 -05001441 struct nfs_client_initdata cl_init = {
1442 .hostname = hostname,
Chuck Leverdcecae02007-12-10 14:58:59 -05001443 .addr = addr,
1444 .addrlen = addrlen,
Trond Myklebust40c553192007-12-14 14:56:07 -05001445 .rpc_ops = &nfs_v4_clientops,
Trond Myklebust59dca3b2008-01-03 16:29:06 -05001446 .proto = proto,
Benny Halevy5aae4a92009-04-01 09:21:50 -04001447 .minorversion = minorversion,
Stanislav Kinsburskye50a7a12012-01-10 16:12:46 +04001448 .net = net,
Trond Myklebust3a498022007-12-14 14:56:04 -05001449 };
David Howells54ceac42006-08-22 20:06:13 -04001450 struct nfs_client *clp;
1451 int error;
1452
1453 dprintk("--> nfs4_set_client()\n");
1454
Chuck Lever4bf590e2012-05-21 22:46:07 -04001455 if (server->flags & NFS_MOUNT_NORESVPORT)
1456 set_bit(NFS_CS_NORESVPORT, &cl_init.init_flags);
1457
David Howells54ceac42006-08-22 20:06:13 -04001458 /* Allocate or find a client reference we can use */
Chuck Lever4bf590e2012-05-21 22:46:07 -04001459 clp = nfs_get_client(&cl_init, timeparms, ip_addr, authflavour);
David Howells54ceac42006-08-22 20:06:13 -04001460 if (IS_ERR(clp)) {
1461 error = PTR_ERR(clp);
1462 goto error;
1463 }
David Howells54ceac42006-08-22 20:06:13 -04001464
Andy Adamsond6fb79d2011-03-01 01:34:11 +00001465 /*
1466 * Query for the lease time on clientid setup or renewal
1467 *
1468 * Note that this will be set on nfs_clients that were created
1469 * only for the DS role and did not set this bit, but now will
1470 * serve a dual role.
1471 */
1472 set_bit(NFS_CS_CHECK_LEASE_TIME, &clp->cl_res_state);
1473
David Howells54ceac42006-08-22 20:06:13 -04001474 server->nfs_client = clp;
1475 dprintk("<-- nfs4_set_client() = 0 [new %p]\n", clp);
1476 return 0;
David Howells54ceac42006-08-22 20:06:13 -04001477error:
1478 dprintk("<-- nfs4_set_client() = xerror %d\n", error);
1479 return error;
1480}
1481
Andy Adamsond83217c2011-03-01 01:34:17 +00001482/*
1483 * Set up a pNFS Data Server client.
1484 *
1485 * Return any existing nfs_client that matches server address,port,version
1486 * and minorversion.
1487 *
1488 * For a new nfs_client, use a soft mount (default), a low retrans and a
1489 * low timeout interval so that if a connection is lost, we retry through
1490 * the MDS.
1491 */
1492struct nfs_client *nfs4_set_ds_client(struct nfs_client* mds_clp,
Andy Adamson98fc6852012-04-27 17:53:45 -04001493 const struct sockaddr *ds_addr, int ds_addrlen,
1494 int ds_proto, unsigned int ds_timeo, unsigned int ds_retrans)
Andy Adamsond83217c2011-03-01 01:34:17 +00001495{
1496 struct nfs_client_initdata cl_init = {
1497 .addr = ds_addr,
1498 .addrlen = ds_addrlen,
1499 .rpc_ops = &nfs_v4_clientops,
1500 .proto = ds_proto,
1501 .minorversion = mds_clp->cl_minorversion,
Chuck Lever73ea6662012-05-21 22:44:50 -04001502 .net = mds_clp->cl_net,
Andy Adamsond83217c2011-03-01 01:34:17 +00001503 };
Andy Adamson98fc6852012-04-27 17:53:45 -04001504 struct rpc_timeout ds_timeout;
Andy Adamsond83217c2011-03-01 01:34:17 +00001505 struct nfs_client *clp;
1506
1507 /*
1508 * Set an authflavor equual to the MDS value. Use the MDS nfs_client
1509 * cl_ipaddr so as to use the same EXCHANGE_ID co_ownerid as the MDS
1510 * (section 13.1 RFC 5661).
1511 */
Andy Adamson98fc6852012-04-27 17:53:45 -04001512 nfs_init_timeout_values(&ds_timeout, ds_proto, ds_timeo, ds_retrans);
Andy Adamsond83217c2011-03-01 01:34:17 +00001513 clp = nfs_get_client(&cl_init, &ds_timeout, mds_clp->cl_ipaddr,
Chuck Lever4bf590e2012-05-21 22:46:07 -04001514 mds_clp->cl_rpcclient->cl_auth->au_flavor);
Andy Adamsond83217c2011-03-01 01:34:17 +00001515
1516 dprintk("<-- %s %p\n", __func__, clp);
1517 return clp;
1518}
Trond Myklebust94b134a2011-07-13 19:26:49 -04001519EXPORT_SYMBOL_GPL(nfs4_set_ds_client);
Andy Adamson557134a2009-04-01 09:21:53 -04001520
1521/*
Andy Adamson96b09e02009-04-01 09:22:33 -04001522 * Session has been established, and the client marked ready.
1523 * Set the mount rsize and wsize with negotiated fore channel
1524 * attributes which will be bound checked in nfs_server_set_fsinfo.
1525 */
1526static void nfs4_session_set_rwsize(struct nfs_server *server)
1527{
1528#ifdef CONFIG_NFS_V4_1
Alexandros Batsakis2449ea22009-12-05 13:36:55 -05001529 struct nfs4_session *sess;
1530 u32 server_resp_sz;
1531 u32 server_rqst_sz;
1532
Andy Adamson96b09e02009-04-01 09:22:33 -04001533 if (!nfs4_has_session(server->nfs_client))
1534 return;
Alexandros Batsakis2449ea22009-12-05 13:36:55 -05001535 sess = server->nfs_client->cl_session;
1536 server_resp_sz = sess->fc_attrs.max_resp_sz - nfs41_maxread_overhead;
1537 server_rqst_sz = sess->fc_attrs.max_rqst_sz - nfs41_maxwrite_overhead;
1538
1539 if (server->rsize > server_resp_sz)
1540 server->rsize = server_resp_sz;
1541 if (server->wsize > server_rqst_sz)
1542 server->wsize = server_rqst_sz;
Andy Adamson96b09e02009-04-01 09:22:33 -04001543#endif /* CONFIG_NFS_V4_1 */
1544}
1545
Trond Myklebust44950b62010-06-17 11:45:12 -04001546static int nfs4_server_common_setup(struct nfs_server *server,
1547 struct nfs_fh *mntfh)
1548{
1549 struct nfs_fattr *fattr;
1550 int error;
1551
1552 BUG_ON(!server->nfs_client);
1553 BUG_ON(!server->nfs_client->rpc_ops);
1554 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
1555
Andy Adamson94de8b22011-03-01 01:34:12 +00001556 /* data servers support only a subset of NFSv4.1 */
1557 if (is_ds_only_client(server->nfs_client))
1558 return -EPROTONOSUPPORT;
1559
Trond Myklebust44950b62010-06-17 11:45:12 -04001560 fattr = nfs_alloc_fattr();
1561 if (fattr == NULL)
1562 return -ENOMEM;
1563
1564 /* We must ensure the session is initialised first */
1565 error = nfs4_init_session(server);
1566 if (error < 0)
1567 goto out;
1568
1569 /* Probe the root fh to retrieve its FSID and filehandle */
1570 error = nfs4_get_rootfh(server, mntfh);
1571 if (error < 0)
1572 goto out;
1573
1574 dprintk("Server FSID: %llx:%llx\n",
1575 (unsigned long long) server->fsid.major,
1576 (unsigned long long) server->fsid.minor);
1577 dprintk("Mount FH: %d\n", mntfh->size);
1578
1579 nfs4_session_set_rwsize(server);
1580
1581 error = nfs_probe_fsinfo(server, mntfh, fattr);
1582 if (error < 0)
1583 goto out;
1584
1585 if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN)
1586 server->namelen = NFS4_MAXNAMLEN;
1587
Chuck Leverfca52382010-12-24 01:32:32 +00001588 nfs_server_insert_lists(server);
Trond Myklebust44950b62010-06-17 11:45:12 -04001589 server->mount_time = jiffies;
Chuck Lever0aaaf5c2011-12-06 16:13:48 -05001590 server->destroy = nfs4_destroy_server;
Trond Myklebust44950b62010-06-17 11:45:12 -04001591out:
1592 nfs_free_fattr(fattr);
1593 return error;
1594}
1595
Andy Adamson96b09e02009-04-01 09:22:33 -04001596/*
David Howells54ceac42006-08-22 20:06:13 -04001597 * Create a version 4 volume record
1598 */
1599static int nfs4_init_server(struct nfs_server *server,
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001600 const struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001601{
Trond Myklebust33170232007-12-20 16:03:59 -05001602 struct rpc_timeout timeparms;
David Howells54ceac42006-08-22 20:06:13 -04001603 int error;
1604
1605 dprintk("--> nfs4_init_server()\n");
1606
Trond Myklebust33170232007-12-20 16:03:59 -05001607 nfs_init_timeout_values(&timeparms, data->nfs_server.protocol,
1608 data->timeo, data->retrans);
1609
Chuck Lever542fcc32008-12-23 15:21:36 -05001610 /* Initialise the client representation from the mount data */
1611 server->flags = data->flags;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001612 server->caps |= NFS_CAP_ATOMIC_OPEN|NFS_CAP_CHANGE_ATTR|NFS_CAP_POSIX_LOCK;
1613 if (!(data->flags & NFS_MOUNT_NORDIRPLUS))
1614 server->caps |= NFS_CAP_READDIRPLUS;
David Howellsb797cac2009-04-03 16:42:48 +01001615 server->options = data->options;
Chuck Lever542fcc32008-12-23 15:21:36 -05001616
Trond Myklebust33170232007-12-20 16:03:59 -05001617 /* Get a client record */
1618 error = nfs4_set_client(server,
1619 data->nfs_server.hostname,
1620 (const struct sockaddr *)&data->nfs_server.address,
1621 data->nfs_server.addrlen,
1622 data->client_address,
1623 data->auth_flavors[0],
1624 data->nfs_server.protocol,
Benny Halevy94a417f2009-04-01 09:21:49 -04001625 &timeparms,
Stanislav Kinsburskye50a7a12012-01-10 16:12:46 +04001626 data->minorversion,
1627 data->net);
Trond Myklebust33170232007-12-20 16:03:59 -05001628 if (error < 0)
1629 goto error;
1630
Trond Myklebustb064eca22011-02-22 15:44:32 -08001631 /*
1632 * Don't use NFS uid/gid mapping if we're using AUTH_SYS or lower
1633 * authentication.
1634 */
1635 if (nfs4_disable_idmapping && data->auth_flavors[0] == RPC_AUTH_UNIX)
1636 server->caps |= NFS_CAP_UIDGID_NOMAP;
1637
David Howells54ceac42006-08-22 20:06:13 -04001638 if (data->rsize)
1639 server->rsize = nfs_block_size(data->rsize, NULL);
1640 if (data->wsize)
1641 server->wsize = nfs_block_size(data->wsize, NULL);
1642
1643 server->acregmin = data->acregmin * HZ;
1644 server->acregmax = data->acregmax * HZ;
1645 server->acdirmin = data->acdirmin * HZ;
1646 server->acdirmax = data->acdirmax * HZ;
1647
Chuck Leverf22d6d72008-03-14 14:10:22 -04001648 server->port = data->nfs_server.port;
1649
Trond Myklebust33170232007-12-20 16:03:59 -05001650 error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]);
David Howells54ceac42006-08-22 20:06:13 -04001651
Trond Myklebust33170232007-12-20 16:03:59 -05001652error:
David Howells54ceac42006-08-22 20:06:13 -04001653 /* Done */
1654 dprintk("<-- nfs4_init_server() = %d\n", error);
1655 return error;
1656}
1657
1658/*
1659 * Create a version 4 volume record
1660 * - keyed on server and FSID
1661 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001662struct nfs_server *nfs4_create_server(const struct nfs_parsed_mount_data *data,
David Howells54ceac42006-08-22 20:06:13 -04001663 struct nfs_fh *mntfh)
1664{
David Howells54ceac42006-08-22 20:06:13 -04001665 struct nfs_server *server;
1666 int error;
1667
1668 dprintk("--> nfs4_create_server()\n");
1669
1670 server = nfs_alloc_server();
1671 if (!server)
1672 return ERR_PTR(-ENOMEM);
1673
David Howells54ceac42006-08-22 20:06:13 -04001674 /* set up the general RPC client */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001675 error = nfs4_init_server(server, data);
David Howells54ceac42006-08-22 20:06:13 -04001676 if (error < 0)
1677 goto error;
1678
Trond Myklebust44950b62010-06-17 11:45:12 -04001679 error = nfs4_server_common_setup(server, mntfh);
Trond Myklebustfccba802009-07-21 16:48:07 -04001680 if (error < 0)
1681 goto error;
Andy Adamson557134a2009-04-01 09:21:53 -04001682
David Howells54ceac42006-08-22 20:06:13 -04001683 dprintk("<-- nfs4_create_server() = %p\n", server);
1684 return server;
1685
1686error:
1687 nfs_free_server(server);
1688 dprintk("<-- nfs4_create_server() = error %d\n", error);
1689 return ERR_PTR(error);
1690}
1691
1692/*
1693 * Create an NFS4 referral server record
1694 */
1695struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data,
Trond Myklebustf2d0d852007-02-02 14:46:09 -08001696 struct nfs_fh *mntfh)
David Howells54ceac42006-08-22 20:06:13 -04001697{
1698 struct nfs_client *parent_client;
1699 struct nfs_server *server, *parent_server;
David Howells54ceac42006-08-22 20:06:13 -04001700 int error;
1701
1702 dprintk("--> nfs4_create_referral_server()\n");
1703
1704 server = nfs_alloc_server();
1705 if (!server)
1706 return ERR_PTR(-ENOMEM);
1707
1708 parent_server = NFS_SB(data->sb);
1709 parent_client = parent_server->nfs_client;
1710
Chuck Lever542fcc32008-12-23 15:21:36 -05001711 /* Initialise the client representation from the parent server */
1712 nfs_server_copy_userdata(server, parent_server);
Trond Myklebust62ab460c2009-08-09 15:06:19 -04001713 server->caps |= NFS_CAP_ATOMIC_OPEN|NFS_CAP_CHANGE_ATTR;
Chuck Lever542fcc32008-12-23 15:21:36 -05001714
David Howells54ceac42006-08-22 20:06:13 -04001715 /* Get a client representation.
1716 * Note: NFSv4 always uses TCP, */
Chuck Leverdcecae02007-12-10 14:58:59 -05001717 error = nfs4_set_client(server, data->hostname,
Chuck Lever6677d092007-12-10 14:59:06 -05001718 data->addr,
1719 data->addrlen,
Chuck Leverdcecae02007-12-10 14:58:59 -05001720 parent_client->cl_ipaddr,
1721 data->authflavor,
Trond Myklebust2446ab62012-03-01 17:00:56 -05001722 rpc_protocol(parent_server->client),
Benny Halevy94a417f2009-04-01 09:21:49 -04001723 parent_server->client->cl_timeout,
Stanislav Kinsburskye50a7a12012-01-10 16:12:46 +04001724 parent_client->cl_mvops->minor_version,
Chuck Lever73ea6662012-05-21 22:44:50 -04001725 parent_client->cl_net);
andros@citi.umich.edu297de4f2006-08-29 12:19:41 -04001726 if (error < 0)
1727 goto error;
David Howells54ceac42006-08-22 20:06:13 -04001728
Trond Myklebust33170232007-12-20 16:03:59 -05001729 error = nfs_init_server_rpcclient(server, parent_server->client->cl_timeout, data->authflavor);
David Howells54ceac42006-08-22 20:06:13 -04001730 if (error < 0)
1731 goto error;
1732
Trond Myklebust44950b62010-06-17 11:45:12 -04001733 error = nfs4_server_common_setup(server, mntfh);
Trond Myklebustf2d0d852007-02-02 14:46:09 -08001734 if (error < 0)
1735 goto error;
1736
David Howells54ceac42006-08-22 20:06:13 -04001737 dprintk("<-- nfs_create_referral_server() = %p\n", server);
1738 return server;
1739
1740error:
1741 nfs_free_server(server);
1742 dprintk("<-- nfs4_create_referral_server() = error %d\n", error);
1743 return ERR_PTR(error);
1744}
1745
1746#endif /* CONFIG_NFS_V4 */
1747
1748/*
1749 * Clone an NFS2, NFS3 or NFS4 server record
1750 */
1751struct nfs_server *nfs_clone_server(struct nfs_server *source,
1752 struct nfs_fh *fh,
Bryan Schumaker7e6eb682012-04-27 13:27:42 -04001753 struct nfs_fattr *fattr,
1754 rpc_authflavor_t flavor)
David Howells54ceac42006-08-22 20:06:13 -04001755{
1756 struct nfs_server *server;
Trond Myklebustfbca7792010-04-16 16:22:46 -04001757 struct nfs_fattr *fattr_fsinfo;
David Howells54ceac42006-08-22 20:06:13 -04001758 int error;
1759
1760 dprintk("--> nfs_clone_server(,%llx:%llx,)\n",
David Howells6daabf12006-08-24 15:44:16 -04001761 (unsigned long long) fattr->fsid.major,
1762 (unsigned long long) fattr->fsid.minor);
David Howells54ceac42006-08-22 20:06:13 -04001763
1764 server = nfs_alloc_server();
1765 if (!server)
1766 return ERR_PTR(-ENOMEM);
1767
Trond Myklebustfbca7792010-04-16 16:22:46 -04001768 error = -ENOMEM;
1769 fattr_fsinfo = nfs_alloc_fattr();
1770 if (fattr_fsinfo == NULL)
1771 goto out_free_server;
1772
David Howells54ceac42006-08-22 20:06:13 -04001773 /* Copy data from the source */
1774 server->nfs_client = source->nfs_client;
Chuck Lever0aaaf5c2011-12-06 16:13:48 -05001775 server->destroy = source->destroy;
David Howells54ceac42006-08-22 20:06:13 -04001776 atomic_inc(&server->nfs_client->cl_count);
1777 nfs_server_copy_userdata(server, source);
1778
1779 server->fsid = fattr->fsid;
1780
Trond Myklebust33170232007-12-20 16:03:59 -05001781 error = nfs_init_server_rpcclient(server,
1782 source->client->cl_timeout,
Bryan Schumaker7e6eb682012-04-27 13:27:42 -04001783 flavor);
David Howells54ceac42006-08-22 20:06:13 -04001784 if (error < 0)
1785 goto out_free_server;
1786 if (!IS_ERR(source->client_acl))
1787 nfs_init_server_aclclient(server);
1788
1789 /* probe the filesystem info for this server filesystem */
Trond Myklebustfbca7792010-04-16 16:22:46 -04001790 error = nfs_probe_fsinfo(server, fh, fattr_fsinfo);
David Howells54ceac42006-08-22 20:06:13 -04001791 if (error < 0)
1792 goto out_free_server;
1793
Trond Myklebust54af3bb2007-09-28 12:27:41 -04001794 if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN)
1795 server->namelen = NFS4_MAXNAMLEN;
1796
David Howells54ceac42006-08-22 20:06:13 -04001797 dprintk("Cloned FSID: %llx:%llx\n",
David Howells6daabf12006-08-24 15:44:16 -04001798 (unsigned long long) server->fsid.major,
1799 (unsigned long long) server->fsid.minor);
David Howells54ceac42006-08-22 20:06:13 -04001800
1801 error = nfs_start_lockd(server);
1802 if (error < 0)
1803 goto out_free_server;
1804
Chuck Leverfca52382010-12-24 01:32:32 +00001805 nfs_server_insert_lists(server);
David Howells54ceac42006-08-22 20:06:13 -04001806 server->mount_time = jiffies;
1807
Trond Myklebustfbca7792010-04-16 16:22:46 -04001808 nfs_free_fattr(fattr_fsinfo);
David Howells54ceac42006-08-22 20:06:13 -04001809 dprintk("<-- nfs_clone_server() = %p\n", server);
1810 return server;
1811
1812out_free_server:
Trond Myklebustfbca7792010-04-16 16:22:46 -04001813 nfs_free_fattr(fattr_fsinfo);
David Howells54ceac42006-08-22 20:06:13 -04001814 nfs_free_server(server);
1815 dprintk("<-- nfs_clone_server() = error %d\n", error);
1816 return ERR_PTR(error);
1817}
David Howells6aaca562006-08-22 20:06:13 -04001818
Stanislav Kinsbursky6b131682012-01-23 17:26:05 +00001819void nfs_clients_init(struct net *net)
1820{
1821 struct nfs_net *nn = net_generic(net, nfs_net_id);
1822
1823 INIT_LIST_HEAD(&nn->nfs_client_list);
Stanislav Kinsburskyc25d32b2012-01-23 17:26:14 +00001824 INIT_LIST_HEAD(&nn->nfs_volume_list);
Stanislav Kinsbursky28cd1b32012-01-23 17:26:22 +00001825#ifdef CONFIG_NFS_V4
1826 idr_init(&nn->cb_ident_idr);
1827#endif
Trond Myklebust4c03ae42012-02-07 00:05:11 -05001828 spin_lock_init(&nn->nfs_client_lock);
Chuck Leverf0920752012-05-21 22:45:41 -04001829 nn->boot_time = CURRENT_TIME;
Stanislav Kinsbursky6b131682012-01-23 17:26:05 +00001830}
1831
David Howells6aaca562006-08-22 20:06:13 -04001832#ifdef CONFIG_PROC_FS
1833static struct proc_dir_entry *proc_fs_nfs;
1834
1835static int nfs_server_list_open(struct inode *inode, struct file *file);
1836static void *nfs_server_list_start(struct seq_file *p, loff_t *pos);
1837static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos);
1838static void nfs_server_list_stop(struct seq_file *p, void *v);
1839static int nfs_server_list_show(struct seq_file *m, void *v);
1840
James Morris88e9d342009-09-22 16:43:43 -07001841static const struct seq_operations nfs_server_list_ops = {
David Howells6aaca562006-08-22 20:06:13 -04001842 .start = nfs_server_list_start,
1843 .next = nfs_server_list_next,
1844 .stop = nfs_server_list_stop,
1845 .show = nfs_server_list_show,
1846};
1847
Arjan van de Ven00977a52007-02-12 00:55:34 -08001848static const struct file_operations nfs_server_list_fops = {
David Howells6aaca562006-08-22 20:06:13 -04001849 .open = nfs_server_list_open,
1850 .read = seq_read,
1851 .llseek = seq_lseek,
1852 .release = seq_release,
Denis V. Lunev34b37232008-04-29 01:02:07 -07001853 .owner = THIS_MODULE,
David Howells6aaca562006-08-22 20:06:13 -04001854};
1855
1856static int nfs_volume_list_open(struct inode *inode, struct file *file);
1857static void *nfs_volume_list_start(struct seq_file *p, loff_t *pos);
1858static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos);
1859static void nfs_volume_list_stop(struct seq_file *p, void *v);
1860static int nfs_volume_list_show(struct seq_file *m, void *v);
1861
James Morris88e9d342009-09-22 16:43:43 -07001862static const struct seq_operations nfs_volume_list_ops = {
David Howells6aaca562006-08-22 20:06:13 -04001863 .start = nfs_volume_list_start,
1864 .next = nfs_volume_list_next,
1865 .stop = nfs_volume_list_stop,
1866 .show = nfs_volume_list_show,
1867};
1868
Arjan van de Ven00977a52007-02-12 00:55:34 -08001869static const struct file_operations nfs_volume_list_fops = {
David Howells6aaca562006-08-22 20:06:13 -04001870 .open = nfs_volume_list_open,
1871 .read = seq_read,
1872 .llseek = seq_lseek,
1873 .release = seq_release,
Denis V. Lunev34b37232008-04-29 01:02:07 -07001874 .owner = THIS_MODULE,
David Howells6aaca562006-08-22 20:06:13 -04001875};
1876
1877/*
1878 * open "/proc/fs/nfsfs/servers" which provides a summary of servers with which
1879 * we're dealing
1880 */
1881static int nfs_server_list_open(struct inode *inode, struct file *file)
1882{
1883 struct seq_file *m;
1884 int ret;
Stanislav Kinsbursky6b131682012-01-23 17:26:05 +00001885 struct pid_namespace *pid_ns = file->f_dentry->d_sb->s_fs_info;
1886 struct net *net = pid_ns->child_reaper->nsproxy->net_ns;
David Howells6aaca562006-08-22 20:06:13 -04001887
1888 ret = seq_open(file, &nfs_server_list_ops);
1889 if (ret < 0)
1890 return ret;
1891
1892 m = file->private_data;
Stanislav Kinsbursky6b131682012-01-23 17:26:05 +00001893 m->private = net;
David Howells6aaca562006-08-22 20:06:13 -04001894
1895 return 0;
1896}
1897
1898/*
1899 * set up the iterator to start reading from the server list and return the first item
1900 */
1901static void *nfs_server_list_start(struct seq_file *m, loff_t *_pos)
1902{
Stanislav Kinsbursky6b131682012-01-23 17:26:05 +00001903 struct nfs_net *nn = net_generic(m->private, nfs_net_id);
1904
David Howells6aaca562006-08-22 20:06:13 -04001905 /* lock the list against modification */
Stanislav Kinsburskydc030852012-01-23 17:26:31 +00001906 spin_lock(&nn->nfs_client_lock);
Stanislav Kinsbursky6b131682012-01-23 17:26:05 +00001907 return seq_list_start_head(&nn->nfs_client_list, *_pos);
David Howells6aaca562006-08-22 20:06:13 -04001908}
1909
1910/*
1911 * move to next server
1912 */
1913static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos)
1914{
Stanislav Kinsbursky6b131682012-01-23 17:26:05 +00001915 struct nfs_net *nn = net_generic(p->private, nfs_net_id);
1916
1917 return seq_list_next(v, &nn->nfs_client_list, pos);
David Howells6aaca562006-08-22 20:06:13 -04001918}
1919
1920/*
1921 * clean up after reading from the transports list
1922 */
1923static void nfs_server_list_stop(struct seq_file *p, void *v)
1924{
Stanislav Kinsburskydc030852012-01-23 17:26:31 +00001925 struct nfs_net *nn = net_generic(p->private, nfs_net_id);
1926
1927 spin_unlock(&nn->nfs_client_lock);
David Howells6aaca562006-08-22 20:06:13 -04001928}
1929
1930/*
1931 * display a header line followed by a load of call lines
1932 */
1933static int nfs_server_list_show(struct seq_file *m, void *v)
1934{
1935 struct nfs_client *clp;
Stanislav Kinsbursky6b131682012-01-23 17:26:05 +00001936 struct nfs_net *nn = net_generic(m->private, nfs_net_id);
David Howells6aaca562006-08-22 20:06:13 -04001937
1938 /* display header on line 1 */
Stanislav Kinsbursky6b131682012-01-23 17:26:05 +00001939 if (v == &nn->nfs_client_list) {
David Howells6aaca562006-08-22 20:06:13 -04001940 seq_puts(m, "NV SERVER PORT USE HOSTNAME\n");
1941 return 0;
1942 }
1943
1944 /* display one transport per line on subsequent lines */
1945 clp = list_entry(v, struct nfs_client, cl_share_link);
1946
Malahal Naineni940aab42011-09-20 17:27:14 -07001947 /* Check if the client is initialized */
1948 if (clp->cl_cons_state != NFS_CS_READY)
1949 return 0;
1950
Trond Myklebust2446ab62012-03-01 17:00:56 -05001951 rcu_read_lock();
Chuck Lever5d8515c2007-12-10 14:57:16 -05001952 seq_printf(m, "v%u %s %s %3d %s\n",
Trond Myklebust40c553192007-12-14 14:56:07 -05001953 clp->rpc_ops->version,
Chuck Lever5d8515c2007-12-10 14:57:16 -05001954 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR),
1955 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT),
David Howells6aaca562006-08-22 20:06:13 -04001956 atomic_read(&clp->cl_count),
1957 clp->cl_hostname);
Trond Myklebust2446ab62012-03-01 17:00:56 -05001958 rcu_read_unlock();
David Howells6aaca562006-08-22 20:06:13 -04001959
1960 return 0;
1961}
1962
1963/*
1964 * open "/proc/fs/nfsfs/volumes" which provides a summary of extant volumes
1965 */
1966static int nfs_volume_list_open(struct inode *inode, struct file *file)
1967{
1968 struct seq_file *m;
1969 int ret;
Stanislav Kinsburskyc25d32b2012-01-23 17:26:14 +00001970 struct pid_namespace *pid_ns = file->f_dentry->d_sb->s_fs_info;
1971 struct net *net = pid_ns->child_reaper->nsproxy->net_ns;
David Howells6aaca562006-08-22 20:06:13 -04001972
1973 ret = seq_open(file, &nfs_volume_list_ops);
1974 if (ret < 0)
1975 return ret;
1976
1977 m = file->private_data;
Stanislav Kinsburskyc25d32b2012-01-23 17:26:14 +00001978 m->private = net;
David Howells6aaca562006-08-22 20:06:13 -04001979
1980 return 0;
1981}
1982
1983/*
1984 * set up the iterator to start reading from the volume list and return the first item
1985 */
1986static void *nfs_volume_list_start(struct seq_file *m, loff_t *_pos)
1987{
Stanislav Kinsburskyc25d32b2012-01-23 17:26:14 +00001988 struct nfs_net *nn = net_generic(m->private, nfs_net_id);
1989
David Howells6aaca562006-08-22 20:06:13 -04001990 /* lock the list against modification */
Stanislav Kinsburskydc030852012-01-23 17:26:31 +00001991 spin_lock(&nn->nfs_client_lock);
Stanislav Kinsburskyc25d32b2012-01-23 17:26:14 +00001992 return seq_list_start_head(&nn->nfs_volume_list, *_pos);
David Howells6aaca562006-08-22 20:06:13 -04001993}
1994
1995/*
1996 * move to next volume
1997 */
1998static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos)
1999{
Stanislav Kinsburskyc25d32b2012-01-23 17:26:14 +00002000 struct nfs_net *nn = net_generic(p->private, nfs_net_id);
2001
2002 return seq_list_next(v, &nn->nfs_volume_list, pos);
David Howells6aaca562006-08-22 20:06:13 -04002003}
2004
2005/*
2006 * clean up after reading from the transports list
2007 */
2008static void nfs_volume_list_stop(struct seq_file *p, void *v)
2009{
Stanislav Kinsburskydc030852012-01-23 17:26:31 +00002010 struct nfs_net *nn = net_generic(p->private, nfs_net_id);
2011
2012 spin_unlock(&nn->nfs_client_lock);
David Howells6aaca562006-08-22 20:06:13 -04002013}
2014
2015/*
2016 * display a header line followed by a load of call lines
2017 */
2018static int nfs_volume_list_show(struct seq_file *m, void *v)
2019{
2020 struct nfs_server *server;
2021 struct nfs_client *clp;
2022 char dev[8], fsid[17];
Stanislav Kinsburskyc25d32b2012-01-23 17:26:14 +00002023 struct nfs_net *nn = net_generic(m->private, nfs_net_id);
David Howells6aaca562006-08-22 20:06:13 -04002024
2025 /* display header on line 1 */
Stanislav Kinsburskyc25d32b2012-01-23 17:26:14 +00002026 if (v == &nn->nfs_volume_list) {
David Howells5d1acff2009-04-03 16:42:47 +01002027 seq_puts(m, "NV SERVER PORT DEV FSID FSC\n");
David Howells6aaca562006-08-22 20:06:13 -04002028 return 0;
2029 }
2030 /* display one transport per line on subsequent lines */
2031 server = list_entry(v, struct nfs_server, master_link);
2032 clp = server->nfs_client;
2033
2034 snprintf(dev, 8, "%u:%u",
2035 MAJOR(server->s_dev), MINOR(server->s_dev));
2036
2037 snprintf(fsid, 17, "%llx:%llx",
David Howells6daabf12006-08-24 15:44:16 -04002038 (unsigned long long) server->fsid.major,
2039 (unsigned long long) server->fsid.minor);
David Howells6aaca562006-08-22 20:06:13 -04002040
Trond Myklebust2446ab62012-03-01 17:00:56 -05002041 rcu_read_lock();
David Howells5d1acff2009-04-03 16:42:47 +01002042 seq_printf(m, "v%u %s %s %-7s %-17s %s\n",
Trond Myklebust40c553192007-12-14 14:56:07 -05002043 clp->rpc_ops->version,
Chuck Lever5d8515c2007-12-10 14:57:16 -05002044 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR),
2045 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT),
David Howells6aaca562006-08-22 20:06:13 -04002046 dev,
David Howells5d1acff2009-04-03 16:42:47 +01002047 fsid,
2048 nfs_server_fscache_state(server));
Trond Myklebust2446ab62012-03-01 17:00:56 -05002049 rcu_read_unlock();
David Howells6aaca562006-08-22 20:06:13 -04002050
2051 return 0;
2052}
2053
2054/*
2055 * initialise the /proc/fs/nfsfs/ directory
2056 */
2057int __init nfs_fs_proc_init(void)
2058{
2059 struct proc_dir_entry *p;
2060
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -07002061 proc_fs_nfs = proc_mkdir("fs/nfsfs", NULL);
David Howells6aaca562006-08-22 20:06:13 -04002062 if (!proc_fs_nfs)
2063 goto error_0;
2064
David Howells6aaca562006-08-22 20:06:13 -04002065 /* a file of servers with which we're dealing */
Denis V. Lunev34b37232008-04-29 01:02:07 -07002066 p = proc_create("servers", S_IFREG|S_IRUGO,
2067 proc_fs_nfs, &nfs_server_list_fops);
David Howells6aaca562006-08-22 20:06:13 -04002068 if (!p)
2069 goto error_1;
2070
David Howells6aaca562006-08-22 20:06:13 -04002071 /* a file of volumes that we have mounted */
Denis V. Lunev34b37232008-04-29 01:02:07 -07002072 p = proc_create("volumes", S_IFREG|S_IRUGO,
2073 proc_fs_nfs, &nfs_volume_list_fops);
David Howells6aaca562006-08-22 20:06:13 -04002074 if (!p)
2075 goto error_2;
David Howells6aaca562006-08-22 20:06:13 -04002076 return 0;
2077
2078error_2:
2079 remove_proc_entry("servers", proc_fs_nfs);
2080error_1:
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -07002081 remove_proc_entry("fs/nfsfs", NULL);
David Howells6aaca562006-08-22 20:06:13 -04002082error_0:
2083 return -ENOMEM;
2084}
2085
2086/*
2087 * clean up the /proc/fs/nfsfs/ directory
2088 */
2089void nfs_fs_proc_exit(void)
2090{
2091 remove_proc_entry("volumes", proc_fs_nfs);
2092 remove_proc_entry("servers", proc_fs_nfs);
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -07002093 remove_proc_entry("fs/nfsfs", NULL);
David Howells6aaca562006-08-22 20:06:13 -04002094}
2095
2096#endif /* CONFIG_PROC_FS */
Trond Myklebustb064eca22011-02-22 15:44:32 -08002097
2098module_param(nfs4_disable_idmapping, bool, 0644);
2099MODULE_PARM_DESC(nfs4_disable_idmapping,
2100 "Turn off NFSv4 idmapping when using 'sec=sys'");