blob: 70b6d9e8517d5330de3ca41c7d1ff5f69112130f [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>
38#include <net/ipv6.h>
David Howells24c8dbb2006-08-22 20:06:10 -040039#include <linux/nfs_xdr.h>
40
41#include <asm/system.h>
42
43#include "nfs4_fs.h"
44#include "callback.h"
45#include "delegation.h"
46#include "iostat.h"
47#include "internal.h"
48
49#define NFSDBG_FACILITY NFSDBG_CLIENT
50
51static DEFINE_SPINLOCK(nfs_client_lock);
52static LIST_HEAD(nfs_client_list);
David Howells54ceac42006-08-22 20:06:13 -040053static LIST_HEAD(nfs_volume_list);
David Howells24c8dbb2006-08-22 20:06:10 -040054static DECLARE_WAIT_QUEUE_HEAD(nfs_client_active_wq);
55
56/*
David Howells5006a762006-08-22 20:06:12 -040057 * RPC cruft for NFS
58 */
59static struct rpc_version *nfs_version[5] = {
60 [2] = &nfs_version2,
61#ifdef CONFIG_NFS_V3
62 [3] = &nfs_version3,
63#endif
64#ifdef CONFIG_NFS_V4
65 [4] = &nfs_version4,
66#endif
67};
68
69struct rpc_program nfs_program = {
70 .name = "nfs",
71 .number = NFS_PROGRAM,
72 .nrvers = ARRAY_SIZE(nfs_version),
73 .version = nfs_version,
74 .stats = &nfs_rpcstat,
75 .pipe_dir_name = "/nfs",
76};
77
78struct rpc_stat nfs_rpcstat = {
79 .program = &nfs_program
80};
81
82
83#ifdef CONFIG_NFS_V3_ACL
84static struct rpc_stat nfsacl_rpcstat = { &nfsacl_program };
85static struct rpc_version * nfsacl_version[] = {
86 [3] = &nfsacl_version3,
87};
88
89struct rpc_program nfsacl_program = {
90 .name = "nfsacl",
91 .number = NFS_ACL_PROGRAM,
92 .nrvers = ARRAY_SIZE(nfsacl_version),
93 .version = nfsacl_version,
94 .stats = &nfsacl_rpcstat,
95};
96#endif /* CONFIG_NFS_V3_ACL */
97
Trond Myklebust3a498022007-12-14 14:56:04 -050098struct nfs_client_initdata {
99 const char *hostname;
Chuck Leverd7422c42007-12-10 14:58:51 -0500100 const struct sockaddr *addr;
Chuck Lever6e4cffd2007-12-10 14:58:15 -0500101 size_t addrlen;
Trond Myklebust40c553192007-12-14 14:56:07 -0500102 const struct nfs_rpc_ops *rpc_ops;
Trond Myklebust59dca3b2008-01-03 16:29:06 -0500103 int proto;
Trond Myklebust3a498022007-12-14 14:56:04 -0500104};
105
David Howells5006a762006-08-22 20:06:12 -0400106/*
David Howells24c8dbb2006-08-22 20:06:10 -0400107 * Allocate a shared client record
108 *
109 * Since these are allocated/deallocated very rarely, we don't
110 * bother putting them in a slab cache...
111 */
Trond Myklebust3a498022007-12-14 14:56:04 -0500112static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init)
David Howells24c8dbb2006-08-22 20:06:10 -0400113{
114 struct nfs_client *clp;
Trond Myklebust7c67db32008-04-07 20:50:11 -0400115 struct rpc_cred *cred;
David Howells24c8dbb2006-08-22 20:06:10 -0400116
117 if ((clp = kzalloc(sizeof(*clp), GFP_KERNEL)) == NULL)
118 goto error_0;
119
Trond Myklebust40c553192007-12-14 14:56:07 -0500120 clp->rpc_ops = cl_init->rpc_ops;
121
122 if (cl_init->rpc_ops->version == 4) {
David Howells24c8dbb2006-08-22 20:06:10 -0400123 if (nfs_callback_up() < 0)
124 goto error_2;
125 __set_bit(NFS_CS_CALLBACK, &clp->cl_res_state);
126 }
127
128 atomic_set(&clp->cl_count, 1);
129 clp->cl_cons_state = NFS_CS_INITING;
130
Chuck Lever6e4cffd2007-12-10 14:58:15 -0500131 memcpy(&clp->cl_addr, cl_init->addr, cl_init->addrlen);
132 clp->cl_addrlen = cl_init->addrlen;
David Howells24c8dbb2006-08-22 20:06:10 -0400133
Trond Myklebust3a498022007-12-14 14:56:04 -0500134 if (cl_init->hostname) {
135 clp->cl_hostname = kstrdup(cl_init->hostname, GFP_KERNEL);
David Howells24c8dbb2006-08-22 20:06:10 -0400136 if (!clp->cl_hostname)
137 goto error_3;
138 }
139
140 INIT_LIST_HEAD(&clp->cl_superblocks);
141 clp->cl_rpcclient = ERR_PTR(-EINVAL);
142
Trond Myklebust59dca3b2008-01-03 16:29:06 -0500143 clp->cl_proto = cl_init->proto;
144
David Howells24c8dbb2006-08-22 20:06:10 -0400145#ifdef CONFIG_NFS_V4
146 init_rwsem(&clp->cl_sem);
147 INIT_LIST_HEAD(&clp->cl_delegations);
David Howells24c8dbb2006-08-22 20:06:10 -0400148 spin_lock_init(&clp->cl_lock);
David Howells65f27f32006-11-22 14:55:48 +0000149 INIT_DELAYED_WORK(&clp->cl_renewd, nfs4_renew_state);
David Howells24c8dbb2006-08-22 20:06:10 -0400150 rpc_init_wait_queue(&clp->cl_rpcwaitq, "NFS client");
151 clp->cl_boot_time = CURRENT_TIME;
152 clp->cl_state = 1 << NFS4CLNT_LEASE_EXPIRED;
153#endif
Trond Myklebust7c67db32008-04-07 20:50:11 -0400154 cred = rpc_lookup_machine_cred();
155 if (!IS_ERR(cred))
156 clp->cl_machine_cred = cred;
David Howells24c8dbb2006-08-22 20:06:10 -0400157
158 return clp;
159
160error_3:
Trond Myklebust9c5bf382006-08-22 20:06:14 -0400161 if (__test_and_clear_bit(NFS_CS_CALLBACK, &clp->cl_res_state))
162 nfs_callback_down();
David Howells24c8dbb2006-08-22 20:06:10 -0400163error_2:
David Howells24c8dbb2006-08-22 20:06:10 -0400164 kfree(clp);
165error_0:
166 return NULL;
167}
168
Trond Myklebust5dd31772006-08-24 01:03:05 -0400169static void nfs4_shutdown_client(struct nfs_client *clp)
170{
171#ifdef CONFIG_NFS_V4
172 if (__test_and_clear_bit(NFS_CS_RENEWD, &clp->cl_res_state))
173 nfs4_kill_renewd(clp);
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400174 BUG_ON(!RB_EMPTY_ROOT(&clp->cl_state_owners));
Trond Myklebust5dd31772006-08-24 01:03:05 -0400175 if (__test_and_clear_bit(NFS_CS_IDMAP, &clp->cl_res_state))
176 nfs_idmap_delete(clp);
Trond Myklebustf6a1cc82008-02-22 17:06:55 -0500177
178 rpc_destroy_wait_queue(&clp->cl_rpcwaitq);
Trond Myklebust5dd31772006-08-24 01:03:05 -0400179#endif
180}
181
David Howells24c8dbb2006-08-22 20:06:10 -0400182/*
183 * Destroy a shared client record
184 */
185static void nfs_free_client(struct nfs_client *clp)
186{
Trond Myklebust40c553192007-12-14 14:56:07 -0500187 dprintk("--> nfs_free_client(%u)\n", clp->rpc_ops->version);
David Howells24c8dbb2006-08-22 20:06:10 -0400188
Trond Myklebust5dd31772006-08-24 01:03:05 -0400189 nfs4_shutdown_client(clp);
David Howells24c8dbb2006-08-22 20:06:10 -0400190
191 /* -EIO all pending I/O */
192 if (!IS_ERR(clp->cl_rpcclient))
193 rpc_shutdown_client(clp->cl_rpcclient);
194
195 if (__test_and_clear_bit(NFS_CS_CALLBACK, &clp->cl_res_state))
196 nfs_callback_down();
197
Trond Myklebust7c67db32008-04-07 20:50:11 -0400198 if (clp->cl_machine_cred != NULL)
199 put_rpccred(clp->cl_machine_cred);
200
David Howells24c8dbb2006-08-22 20:06:10 -0400201 kfree(clp->cl_hostname);
202 kfree(clp);
203
204 dprintk("<-- nfs_free_client()\n");
205}
206
207/*
208 * Release a reference to a shared client record
209 */
210void nfs_put_client(struct nfs_client *clp)
211{
David Howells27ba8512006-07-30 14:40:56 -0400212 if (!clp)
213 return;
214
David Howells24c8dbb2006-08-22 20:06:10 -0400215 dprintk("--> nfs_put_client({%d})\n", atomic_read(&clp->cl_count));
216
217 if (atomic_dec_and_lock(&clp->cl_count, &nfs_client_lock)) {
218 list_del(&clp->cl_share_link);
219 spin_unlock(&nfs_client_lock);
220
221 BUG_ON(!list_empty(&clp->cl_superblocks));
222
223 nfs_free_client(clp);
224 }
225}
226
Trond Myklebust3b0d3f92008-01-03 13:28:58 -0500227static int nfs_sockaddr_match_ipaddr4(const struct sockaddr_in *sa1,
228 const struct sockaddr_in *sa2)
229{
230 return sa1->sin_addr.s_addr == sa2->sin_addr.s_addr;
231}
232
233static int nfs_sockaddr_match_ipaddr6(const struct sockaddr_in6 *sa1,
234 const struct sockaddr_in6 *sa2)
235{
236 return ipv6_addr_equal(&sa1->sin6_addr, &sa2->sin6_addr);
237}
238
239static int nfs_sockaddr_match_ipaddr(const struct sockaddr *sa1,
240 const struct sockaddr *sa2)
241{
242 switch (sa1->sa_family) {
243 case AF_INET:
244 return nfs_sockaddr_match_ipaddr4((const struct sockaddr_in *)sa1,
245 (const struct sockaddr_in *)sa2);
246 case AF_INET6:
247 return nfs_sockaddr_match_ipaddr6((const struct sockaddr_in6 *)sa1,
248 (const struct sockaddr_in6 *)sa2);
249 }
250 BUG();
251}
252
David Howells24c8dbb2006-08-22 20:06:10 -0400253/*
Trond Myklebustc81468a2007-12-14 14:56:05 -0500254 * Find a client by IP address and protocol version
255 * - returns NULL if no such client
David Howells24c8dbb2006-08-22 20:06:10 -0400256 */
Chuck Leverff052642007-12-10 14:58:44 -0500257struct nfs_client *nfs_find_client(const struct sockaddr *addr, u32 nfsversion)
Trond Myklebustc81468a2007-12-14 14:56:05 -0500258{
259 struct nfs_client *clp;
260
261 spin_lock(&nfs_client_lock);
262 list_for_each_entry(clp, &nfs_client_list, cl_share_link) {
Trond Myklebust3b0d3f92008-01-03 13:28:58 -0500263 struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr;
264
Trond Myklebustc81468a2007-12-14 14:56:05 -0500265 /* Don't match clients that failed to initialise properly */
266 if (clp->cl_cons_state != NFS_CS_READY)
267 continue;
268
269 /* Different NFS versions cannot share the same nfs_client */
Trond Myklebust40c553192007-12-14 14:56:07 -0500270 if (clp->rpc_ops->version != nfsversion)
Trond Myklebustc81468a2007-12-14 14:56:05 -0500271 continue;
272
Trond Myklebust3b0d3f92008-01-03 13:28:58 -0500273 if (addr->sa_family != clap->sa_family)
274 continue;
Trond Myklebustc81468a2007-12-14 14:56:05 -0500275 /* Match only the IP address, not the port number */
Trond Myklebust3b0d3f92008-01-03 13:28:58 -0500276 if (!nfs_sockaddr_match_ipaddr(addr, clap))
Trond Myklebustc81468a2007-12-14 14:56:05 -0500277 continue;
278
279 atomic_inc(&clp->cl_count);
280 spin_unlock(&nfs_client_lock);
281 return clp;
282 }
283 spin_unlock(&nfs_client_lock);
284 return NULL;
285}
286
287/*
Trond Myklebust3fbd67a2008-01-26 01:06:40 -0500288 * Find a client by IP address and protocol version
289 * - returns NULL if no such client
290 */
291struct nfs_client *nfs_find_client_next(struct nfs_client *clp)
292{
293 struct sockaddr *sap = (struct sockaddr *)&clp->cl_addr;
294 u32 nfsvers = clp->rpc_ops->version;
295
296 spin_lock(&nfs_client_lock);
297 list_for_each_entry_continue(clp, &nfs_client_list, cl_share_link) {
298 struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr;
299
300 /* Don't match clients that failed to initialise properly */
301 if (clp->cl_cons_state != NFS_CS_READY)
302 continue;
303
304 /* Different NFS versions cannot share the same nfs_client */
305 if (clp->rpc_ops->version != nfsvers)
306 continue;
307
308 if (sap->sa_family != clap->sa_family)
309 continue;
310 /* Match only the IP address, not the port number */
311 if (!nfs_sockaddr_match_ipaddr(sap, clap))
312 continue;
313
314 atomic_inc(&clp->cl_count);
315 spin_unlock(&nfs_client_lock);
316 return clp;
317 }
318 spin_unlock(&nfs_client_lock);
319 return NULL;
320}
321
322/*
Trond Myklebustc81468a2007-12-14 14:56:05 -0500323 * Find an nfs_client on the list that matches the initialisation data
324 * that is supplied.
325 */
326static struct nfs_client *nfs_match_client(const struct nfs_client_initdata *data)
David Howells24c8dbb2006-08-22 20:06:10 -0400327{
328 struct nfs_client *clp;
329
330 list_for_each_entry(clp, &nfs_client_list, cl_share_link) {
Trond Myklebust13bbc062006-10-19 23:28:40 -0700331 /* Don't match clients that failed to initialise properly */
332 if (clp->cl_cons_state < 0)
333 continue;
334
David Howells24c8dbb2006-08-22 20:06:10 -0400335 /* Different NFS versions cannot share the same nfs_client */
Trond Myklebust40c553192007-12-14 14:56:07 -0500336 if (clp->rpc_ops != data->rpc_ops)
David Howells24c8dbb2006-08-22 20:06:10 -0400337 continue;
338
Trond Myklebust59dca3b2008-01-03 16:29:06 -0500339 if (clp->cl_proto != data->proto)
340 continue;
341
Trond Myklebustc81468a2007-12-14 14:56:05 -0500342 /* Match the full socket address */
343 if (memcmp(&clp->cl_addr, data->addr, sizeof(clp->cl_addr)) != 0)
David Howells24c8dbb2006-08-22 20:06:10 -0400344 continue;
345
Trond Myklebustc81468a2007-12-14 14:56:05 -0500346 atomic_inc(&clp->cl_count);
347 return clp;
David Howells24c8dbb2006-08-22 20:06:10 -0400348 }
David Howells24c8dbb2006-08-22 20:06:10 -0400349 return NULL;
David Howells24c8dbb2006-08-22 20:06:10 -0400350}
351
352/*
353 * Look up a client by IP address and protocol version
354 * - creates a new record if one doesn't yet exist
355 */
Trond Myklebust3a498022007-12-14 14:56:04 -0500356static struct nfs_client *nfs_get_client(const struct nfs_client_initdata *cl_init)
David Howells24c8dbb2006-08-22 20:06:10 -0400357{
358 struct nfs_client *clp, *new = NULL;
359 int error;
360
Chuck Leverd7422c42007-12-10 14:58:51 -0500361 dprintk("--> nfs_get_client(%s,v%u)\n",
362 cl_init->hostname ?: "", cl_init->rpc_ops->version);
David Howells24c8dbb2006-08-22 20:06:10 -0400363
364 /* see if the client already exists */
365 do {
366 spin_lock(&nfs_client_lock);
367
Trond Myklebustc81468a2007-12-14 14:56:05 -0500368 clp = nfs_match_client(cl_init);
David Howells24c8dbb2006-08-22 20:06:10 -0400369 if (clp)
370 goto found_client;
371 if (new)
372 goto install_client;
373
374 spin_unlock(&nfs_client_lock);
375
Trond Myklebust3a498022007-12-14 14:56:04 -0500376 new = nfs_alloc_client(cl_init);
David Howells24c8dbb2006-08-22 20:06:10 -0400377 } while (new);
378
379 return ERR_PTR(-ENOMEM);
380
381 /* install a new client and return with it unready */
382install_client:
383 clp = new;
384 list_add(&clp->cl_share_link, &nfs_client_list);
385 spin_unlock(&nfs_client_lock);
386 dprintk("--> nfs_get_client() = %p [new]\n", clp);
387 return clp;
388
389 /* found an existing client
390 * - make sure it's ready before returning
391 */
392found_client:
393 spin_unlock(&nfs_client_lock);
394
395 if (new)
396 nfs_free_client(new);
397
Matthew Wilcox150030b2007-12-06 16:24:39 -0500398 error = wait_event_killable(nfs_client_active_wq,
Trond Myklebust0bae89e2006-10-08 14:33:24 -0400399 clp->cl_cons_state != NFS_CS_INITING);
400 if (error < 0) {
401 nfs_put_client(clp);
402 return ERR_PTR(-ERESTARTSYS);
David Howells24c8dbb2006-08-22 20:06:10 -0400403 }
404
405 if (clp->cl_cons_state < NFS_CS_READY) {
406 error = clp->cl_cons_state;
407 nfs_put_client(clp);
408 return ERR_PTR(error);
409 }
410
David Howells54ceac42006-08-22 20:06:13 -0400411 BUG_ON(clp->cl_cons_state != NFS_CS_READY);
412
David Howells24c8dbb2006-08-22 20:06:10 -0400413 dprintk("--> nfs_get_client() = %p [share]\n", clp);
414 return clp;
415}
416
417/*
418 * Mark a server as ready or failed
419 */
David Howells54ceac42006-08-22 20:06:13 -0400420static void nfs_mark_client_ready(struct nfs_client *clp, int state)
David Howells24c8dbb2006-08-22 20:06:10 -0400421{
422 clp->cl_cons_state = state;
423 wake_up_all(&nfs_client_active_wq);
424}
David Howells5006a762006-08-22 20:06:12 -0400425
426/*
427 * Initialise the timeout values for a connection
428 */
429static void nfs_init_timeout_values(struct rpc_timeout *to, int proto,
430 unsigned int timeo, unsigned int retrans)
431{
432 to->to_initval = timeo * HZ / 10;
433 to->to_retries = retrans;
David Howells5006a762006-08-22 20:06:12 -0400434
435 switch (proto) {
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400436 case XPRT_TRANSPORT_TCP:
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400437 case XPRT_TRANSPORT_RDMA:
Trond Myklebust259875e2008-07-02 14:43:47 -0400438 if (to->to_retries == 0)
439 to->to_retries = NFS_DEF_TCP_RETRANS;
Trond Myklebust7a3e3e12007-12-20 16:03:57 -0500440 if (to->to_initval == 0)
Trond Myklebust259875e2008-07-02 14:43:47 -0400441 to->to_initval = NFS_DEF_TCP_TIMEO * HZ / 10;
David Howells5006a762006-08-22 20:06:12 -0400442 if (to->to_initval > NFS_MAX_TCP_TIMEOUT)
443 to->to_initval = NFS_MAX_TCP_TIMEOUT;
444 to->to_increment = to->to_initval;
445 to->to_maxval = to->to_initval + (to->to_increment * to->to_retries);
Trond Myklebust7a3e3e12007-12-20 16:03:57 -0500446 if (to->to_maxval > NFS_MAX_TCP_TIMEOUT)
447 to->to_maxval = NFS_MAX_TCP_TIMEOUT;
448 if (to->to_maxval < to->to_initval)
449 to->to_maxval = to->to_initval;
David Howells5006a762006-08-22 20:06:12 -0400450 to->to_exponential = 0;
451 break;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400452 case XPRT_TRANSPORT_UDP:
Trond Myklebust259875e2008-07-02 14:43:47 -0400453 if (to->to_retries == 0)
454 to->to_retries = NFS_DEF_UDP_RETRANS;
David Howells5006a762006-08-22 20:06:12 -0400455 if (!to->to_initval)
Trond Myklebust259875e2008-07-02 14:43:47 -0400456 to->to_initval = NFS_DEF_UDP_TIMEO * HZ / 10;
David Howells5006a762006-08-22 20:06:12 -0400457 if (to->to_initval > NFS_MAX_UDP_TIMEOUT)
458 to->to_initval = NFS_MAX_UDP_TIMEOUT;
459 to->to_maxval = NFS_MAX_UDP_TIMEOUT;
460 to->to_exponential = 1;
461 break;
Trond Myklebust259875e2008-07-02 14:43:47 -0400462 default:
463 BUG();
David Howells5006a762006-08-22 20:06:12 -0400464 }
465}
466
467/*
468 * Create an RPC client handle
469 */
Trond Myklebust59dca3b2008-01-03 16:29:06 -0500470static int nfs_create_rpc_client(struct nfs_client *clp,
Trond Myklebust33170232007-12-20 16:03:59 -0500471 const struct rpc_timeout *timeparms,
472 rpc_authflavor_t flavor,
Chuck Lever4a01b8a2008-12-23 15:21:35 -0500473 int discrtry, int noresvport)
David Howells5006a762006-08-22 20:06:12 -0400474{
David Howells5006a762006-08-22 20:06:12 -0400475 struct rpc_clnt *clnt = NULL;
Chuck Lever41877d22006-08-22 20:06:20 -0400476 struct rpc_create_args args = {
Trond Myklebust59dca3b2008-01-03 16:29:06 -0500477 .protocol = clp->cl_proto,
Chuck Lever41877d22006-08-22 20:06:20 -0400478 .address = (struct sockaddr *)&clp->cl_addr,
Chuck Lever6e4cffd2007-12-10 14:58:15 -0500479 .addrsize = clp->cl_addrlen,
Trond Myklebust33170232007-12-20 16:03:59 -0500480 .timeout = timeparms,
Chuck Lever41877d22006-08-22 20:06:20 -0400481 .servername = clp->cl_hostname,
482 .program = &nfs_program,
483 .version = clp->rpc_ops->version,
484 .authflavor = flavor,
485 };
David Howells5006a762006-08-22 20:06:12 -0400486
Chuck Lever4a01b8a2008-12-23 15:21:35 -0500487 if (discrtry)
488 args.flags |= RPC_CLNT_CREATE_DISCRTRY;
489 if (noresvport)
490 args.flags |= RPC_CLNT_CREATE_NONPRIVPORT;
491
David Howells5006a762006-08-22 20:06:12 -0400492 if (!IS_ERR(clp->cl_rpcclient))
493 return 0;
494
Chuck Lever41877d22006-08-22 20:06:20 -0400495 clnt = rpc_create(&args);
David Howells5006a762006-08-22 20:06:12 -0400496 if (IS_ERR(clnt)) {
497 dprintk("%s: cannot create RPC client. Error = %ld\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -0700498 __func__, PTR_ERR(clnt));
David Howells5006a762006-08-22 20:06:12 -0400499 return PTR_ERR(clnt);
500 }
501
David Howells5006a762006-08-22 20:06:12 -0400502 clp->cl_rpcclient = clnt;
503 return 0;
504}
David Howells54ceac42006-08-22 20:06:13 -0400505
506/*
507 * Version 2 or 3 client destruction
508 */
509static void nfs_destroy_server(struct nfs_server *server)
510{
David Howells54ceac42006-08-22 20:06:13 -0400511 if (!(server->flags & NFS_MOUNT_NONLM))
Chuck Lever9289e7f2008-01-11 17:09:52 -0500512 nlmclnt_done(server->nlm_host);
David Howells54ceac42006-08-22 20:06:13 -0400513}
514
515/*
516 * Version 2 or 3 lockd setup
517 */
518static int nfs_start_lockd(struct nfs_server *server)
519{
Chuck Lever9289e7f2008-01-11 17:09:52 -0500520 struct nlm_host *host;
521 struct nfs_client *clp = server->nfs_client;
Chuck Lever883bb162008-01-15 16:04:20 -0500522 struct nlmclnt_initdata nlm_init = {
523 .hostname = clp->cl_hostname,
524 .address = (struct sockaddr *)&clp->cl_addr,
525 .addrlen = clp->cl_addrlen,
526 .protocol = server->flags & NFS_MOUNT_TCP ?
527 IPPROTO_TCP : IPPROTO_UDP,
528 .nfs_version = clp->rpc_ops->version,
Chuck Lever0cb26592008-12-23 15:21:38 -0500529 .noresvport = server->flags & NFS_MOUNT_NORESVPORT ?
530 1 : 0,
Chuck Lever883bb162008-01-15 16:04:20 -0500531 };
David Howells54ceac42006-08-22 20:06:13 -0400532
Chuck Lever883bb162008-01-15 16:04:20 -0500533 if (nlm_init.nfs_version > 3)
Chuck Lever9289e7f2008-01-11 17:09:52 -0500534 return 0;
David Howells54ceac42006-08-22 20:06:13 -0400535 if (server->flags & NFS_MOUNT_NONLM)
Chuck Lever9289e7f2008-01-11 17:09:52 -0500536 return 0;
537
Chuck Lever883bb162008-01-15 16:04:20 -0500538 host = nlmclnt_init(&nlm_init);
Chuck Lever9289e7f2008-01-11 17:09:52 -0500539 if (IS_ERR(host))
540 return PTR_ERR(host);
541
542 server->nlm_host = host;
543 server->destroy = nfs_destroy_server;
544 return 0;
David Howells54ceac42006-08-22 20:06:13 -0400545}
546
547/*
548 * Initialise an NFSv3 ACL client connection
549 */
550#ifdef CONFIG_NFS_V3_ACL
551static void nfs_init_server_aclclient(struct nfs_server *server)
552{
Trond Myklebust40c553192007-12-14 14:56:07 -0500553 if (server->nfs_client->rpc_ops->version != 3)
David Howells54ceac42006-08-22 20:06:13 -0400554 goto out_noacl;
555 if (server->flags & NFS_MOUNT_NOACL)
556 goto out_noacl;
557
558 server->client_acl = rpc_bind_new_program(server->client, &nfsacl_program, 3);
559 if (IS_ERR(server->client_acl))
560 goto out_noacl;
561
562 /* No errors! Assume that Sun nfsacls are supported */
563 server->caps |= NFS_CAP_ACLS;
564 return;
565
566out_noacl:
567 server->caps &= ~NFS_CAP_ACLS;
568}
569#else
570static inline void nfs_init_server_aclclient(struct nfs_server *server)
571{
572 server->flags &= ~NFS_MOUNT_NOACL;
573 server->caps &= ~NFS_CAP_ACLS;
574}
575#endif
576
577/*
578 * Create a general RPC client
579 */
Trond Myklebust33170232007-12-20 16:03:59 -0500580static int nfs_init_server_rpcclient(struct nfs_server *server,
581 const struct rpc_timeout *timeo,
582 rpc_authflavor_t pseudoflavour)
David Howells54ceac42006-08-22 20:06:13 -0400583{
584 struct nfs_client *clp = server->nfs_client;
585
586 server->client = rpc_clone_client(clp->cl_rpcclient);
587 if (IS_ERR(server->client)) {
Harvey Harrison3110ff82008-05-02 13:42:44 -0700588 dprintk("%s: couldn't create rpc_client!\n", __func__);
David Howells54ceac42006-08-22 20:06:13 -0400589 return PTR_ERR(server->client);
590 }
591
Trond Myklebust33170232007-12-20 16:03:59 -0500592 memcpy(&server->client->cl_timeout_default,
593 timeo,
594 sizeof(server->client->cl_timeout_default));
595 server->client->cl_timeout = &server->client->cl_timeout_default;
596
David Howells54ceac42006-08-22 20:06:13 -0400597 if (pseudoflavour != clp->cl_rpcclient->cl_auth->au_flavor) {
598 struct rpc_auth *auth;
599
600 auth = rpcauth_create(pseudoflavour, server->client);
601 if (IS_ERR(auth)) {
Harvey Harrison3110ff82008-05-02 13:42:44 -0700602 dprintk("%s: couldn't create credcache!\n", __func__);
David Howells54ceac42006-08-22 20:06:13 -0400603 return PTR_ERR(auth);
604 }
605 }
606 server->client->cl_softrtry = 0;
607 if (server->flags & NFS_MOUNT_SOFT)
608 server->client->cl_softrtry = 1;
609
David Howells54ceac42006-08-22 20:06:13 -0400610 return 0;
611}
612
613/*
614 * Initialise an NFS2 or NFS3 client
615 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -0400616static int nfs_init_client(struct nfs_client *clp,
Trond Myklebust33170232007-12-20 16:03:59 -0500617 const struct rpc_timeout *timeparms,
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -0400618 const struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -0400619{
David Howells54ceac42006-08-22 20:06:13 -0400620 int error;
621
622 if (clp->cl_cons_state == NFS_CS_READY) {
623 /* the client is already initialised */
624 dprintk("<-- nfs_init_client() = 0 [already %p]\n", clp);
625 return 0;
626 }
627
David Howells54ceac42006-08-22 20:06:13 -0400628 /*
629 * Create a client RPC handle for doing FSSTAT with UNIX auth only
630 * - RFC 2623, sec 2.3.2
631 */
Chuck Leverd7403512008-12-23 15:21:37 -0500632 error = nfs_create_rpc_client(clp, timeparms, RPC_AUTH_UNIX,
633 0, data->flags & NFS_MOUNT_NORESVPORT);
David Howells54ceac42006-08-22 20:06:13 -0400634 if (error < 0)
635 goto error;
636 nfs_mark_client_ready(clp, NFS_CS_READY);
637 return 0;
638
639error:
640 nfs_mark_client_ready(clp, error);
641 dprintk("<-- nfs_init_client() = xerror %d\n", error);
642 return error;
643}
644
645/*
646 * Create a version 2 or 3 client
647 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -0400648static int nfs_init_server(struct nfs_server *server,
649 const struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -0400650{
Trond Myklebust3a498022007-12-14 14:56:04 -0500651 struct nfs_client_initdata cl_init = {
652 .hostname = data->nfs_server.hostname,
Chuck Leverd7422c42007-12-10 14:58:51 -0500653 .addr = (const struct sockaddr *)&data->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -0500654 .addrlen = data->nfs_server.addrlen,
Trond Myklebust40c553192007-12-14 14:56:07 -0500655 .rpc_ops = &nfs_v2_clientops,
Trond Myklebust59dca3b2008-01-03 16:29:06 -0500656 .proto = data->nfs_server.protocol,
Trond Myklebust3a498022007-12-14 14:56:04 -0500657 };
Trond Myklebust33170232007-12-20 16:03:59 -0500658 struct rpc_timeout timeparms;
David Howells54ceac42006-08-22 20:06:13 -0400659 struct nfs_client *clp;
Trond Myklebust3a498022007-12-14 14:56:04 -0500660 int error;
David Howells54ceac42006-08-22 20:06:13 -0400661
662 dprintk("--> nfs_init_server()\n");
663
664#ifdef CONFIG_NFS_V3
665 if (data->flags & NFS_MOUNT_VER3)
Trond Myklebust40c553192007-12-14 14:56:07 -0500666 cl_init.rpc_ops = &nfs_v3_clientops;
David Howells54ceac42006-08-22 20:06:13 -0400667#endif
668
669 /* Allocate or find a client reference we can use */
Trond Myklebust3a498022007-12-14 14:56:04 -0500670 clp = nfs_get_client(&cl_init);
David Howells54ceac42006-08-22 20:06:13 -0400671 if (IS_ERR(clp)) {
672 dprintk("<-- nfs_init_server() = error %ld\n", PTR_ERR(clp));
673 return PTR_ERR(clp);
674 }
675
Trond Myklebust33170232007-12-20 16:03:59 -0500676 nfs_init_timeout_values(&timeparms, data->nfs_server.protocol,
677 data->timeo, data->retrans);
678 error = nfs_init_client(clp, &timeparms, data);
David Howells54ceac42006-08-22 20:06:13 -0400679 if (error < 0)
680 goto error;
681
682 server->nfs_client = clp;
683
684 /* Initialise the client representation from the mount data */
Trond Myklebustff3525a2008-08-15 16:59:14 -0400685 server->flags = data->flags;
David Howells54ceac42006-08-22 20:06:13 -0400686
687 if (data->rsize)
688 server->rsize = nfs_block_size(data->rsize, NULL);
689 if (data->wsize)
690 server->wsize = nfs_block_size(data->wsize, NULL);
691
692 server->acregmin = data->acregmin * HZ;
693 server->acregmax = data->acregmax * HZ;
694 server->acdirmin = data->acdirmin * HZ;
695 server->acdirmax = data->acdirmax * HZ;
696
697 /* Start lockd here, before we might error out */
698 error = nfs_start_lockd(server);
699 if (error < 0)
700 goto error;
701
Chuck Leverf22d6d72008-03-14 14:10:22 -0400702 server->port = data->nfs_server.port;
703
Trond Myklebust33170232007-12-20 16:03:59 -0500704 error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]);
David Howells54ceac42006-08-22 20:06:13 -0400705 if (error < 0)
706 goto error;
707
Chuck Lever3f8400d2008-03-14 14:10:30 -0400708 /* Preserve the values of mount_server-related mount options */
709 if (data->mount_server.addrlen) {
710 memcpy(&server->mountd_address, &data->mount_server.address,
711 data->mount_server.addrlen);
712 server->mountd_addrlen = data->mount_server.addrlen;
713 }
714 server->mountd_version = data->mount_server.version;
715 server->mountd_port = data->mount_server.port;
716 server->mountd_protocol = data->mount_server.protocol;
717
David Howells54ceac42006-08-22 20:06:13 -0400718 server->namelen = data->namlen;
719 /* Create a client RPC handle for the NFSv3 ACL management interface */
720 nfs_init_server_aclclient(server);
David Howells54ceac42006-08-22 20:06:13 -0400721 dprintk("<-- nfs_init_server() = 0 [new %p]\n", clp);
722 return 0;
723
724error:
725 server->nfs_client = NULL;
726 nfs_put_client(clp);
727 dprintk("<-- nfs_init_server() = xerror %d\n", error);
728 return error;
729}
730
731/*
732 * Load up the server record from information gained in an fsinfo record
733 */
734static void nfs_server_set_fsinfo(struct nfs_server *server, struct nfs_fsinfo *fsinfo)
735{
736 unsigned long max_rpc_payload;
737
738 /* Work out a lot of parameters */
739 if (server->rsize == 0)
740 server->rsize = nfs_block_size(fsinfo->rtpref, NULL);
741 if (server->wsize == 0)
742 server->wsize = nfs_block_size(fsinfo->wtpref, NULL);
743
744 if (fsinfo->rtmax >= 512 && server->rsize > fsinfo->rtmax)
745 server->rsize = nfs_block_size(fsinfo->rtmax, NULL);
746 if (fsinfo->wtmax >= 512 && server->wsize > fsinfo->wtmax)
747 server->wsize = nfs_block_size(fsinfo->wtmax, NULL);
748
749 max_rpc_payload = nfs_block_size(rpc_max_payload(server->client), NULL);
750 if (server->rsize > max_rpc_payload)
751 server->rsize = max_rpc_payload;
752 if (server->rsize > NFS_MAX_FILE_IO_SIZE)
753 server->rsize = NFS_MAX_FILE_IO_SIZE;
754 server->rpages = (server->rsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
Peter Zijlstrae0bf68d2007-10-16 23:25:46 -0700755
David Howells54ceac42006-08-22 20:06:13 -0400756 server->backing_dev_info.ra_pages = server->rpages * NFS_MAX_READAHEAD;
757
758 if (server->wsize > max_rpc_payload)
759 server->wsize = max_rpc_payload;
760 if (server->wsize > NFS_MAX_FILE_IO_SIZE)
761 server->wsize = NFS_MAX_FILE_IO_SIZE;
762 server->wpages = (server->wsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
763 server->wtmult = nfs_block_bits(fsinfo->wtmult, NULL);
764
765 server->dtsize = nfs_block_size(fsinfo->dtpref, NULL);
766 if (server->dtsize > PAGE_CACHE_SIZE)
767 server->dtsize = PAGE_CACHE_SIZE;
768 if (server->dtsize > server->rsize)
769 server->dtsize = server->rsize;
770
771 if (server->flags & NFS_MOUNT_NOAC) {
772 server->acregmin = server->acregmax = 0;
773 server->acdirmin = server->acdirmax = 0;
774 }
775
776 server->maxfilesize = fsinfo->maxfilesize;
777
778 /* We're airborne Set socket buffersize */
779 rpc_setbufsize(server->client, server->wsize + 100, server->rsize + 100);
780}
781
782/*
783 * Probe filesystem information, including the FSID on v2/v3
784 */
785static int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *mntfh, struct nfs_fattr *fattr)
786{
787 struct nfs_fsinfo fsinfo;
788 struct nfs_client *clp = server->nfs_client;
789 int error;
790
791 dprintk("--> nfs_probe_fsinfo()\n");
792
793 if (clp->rpc_ops->set_capabilities != NULL) {
794 error = clp->rpc_ops->set_capabilities(server, mntfh);
795 if (error < 0)
796 goto out_error;
797 }
798
799 fsinfo.fattr = fattr;
800 nfs_fattr_init(fattr);
801 error = clp->rpc_ops->fsinfo(server, mntfh, &fsinfo);
802 if (error < 0)
803 goto out_error;
804
805 nfs_server_set_fsinfo(server, &fsinfo);
Peter Zijlstrae0bf68d2007-10-16 23:25:46 -0700806 error = bdi_init(&server->backing_dev_info);
807 if (error)
808 goto out_error;
809
David Howells54ceac42006-08-22 20:06:13 -0400810
811 /* Get some general file system info */
812 if (server->namelen == 0) {
813 struct nfs_pathconf pathinfo;
814
815 pathinfo.fattr = fattr;
816 nfs_fattr_init(fattr);
817
818 if (clp->rpc_ops->pathconf(server, mntfh, &pathinfo) >= 0)
819 server->namelen = pathinfo.max_namelen;
820 }
821
822 dprintk("<-- nfs_probe_fsinfo() = 0\n");
823 return 0;
824
825out_error:
826 dprintk("nfs_probe_fsinfo: error = %d\n", -error);
827 return error;
828}
829
830/*
831 * Copy useful information when duplicating a server record
832 */
833static void nfs_server_copy_userdata(struct nfs_server *target, struct nfs_server *source)
834{
835 target->flags = source->flags;
836 target->acregmin = source->acregmin;
837 target->acregmax = source->acregmax;
838 target->acdirmin = source->acdirmin;
839 target->acdirmax = source->acdirmax;
840 target->caps = source->caps;
841}
842
843/*
844 * Allocate and initialise a server record
845 */
846static struct nfs_server *nfs_alloc_server(void)
847{
848 struct nfs_server *server;
849
850 server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL);
851 if (!server)
852 return NULL;
853
854 server->client = server->client_acl = ERR_PTR(-EINVAL);
855
856 /* Zero out the NFS state stuff */
857 INIT_LIST_HEAD(&server->client_link);
858 INIT_LIST_HEAD(&server->master_link);
859
Steve Dicksonef818a22007-11-08 04:05:04 -0500860 atomic_set(&server->active, 0);
861
David Howells54ceac42006-08-22 20:06:13 -0400862 server->io_stats = nfs_alloc_iostats();
863 if (!server->io_stats) {
864 kfree(server);
865 return NULL;
866 }
867
868 return server;
869}
870
871/*
872 * Free up a server record
873 */
874void nfs_free_server(struct nfs_server *server)
875{
876 dprintk("--> nfs_free_server()\n");
877
878 spin_lock(&nfs_client_lock);
879 list_del(&server->client_link);
880 list_del(&server->master_link);
881 spin_unlock(&nfs_client_lock);
882
883 if (server->destroy != NULL)
884 server->destroy(server);
Trond Myklebust5cef3382007-12-11 22:01:56 -0500885
886 if (!IS_ERR(server->client_acl))
887 rpc_shutdown_client(server->client_acl);
David Howells54ceac42006-08-22 20:06:13 -0400888 if (!IS_ERR(server->client))
889 rpc_shutdown_client(server->client);
890
891 nfs_put_client(server->nfs_client);
892
893 nfs_free_iostats(server->io_stats);
Peter Zijlstrae0bf68d2007-10-16 23:25:46 -0700894 bdi_destroy(&server->backing_dev_info);
David Howells54ceac42006-08-22 20:06:13 -0400895 kfree(server);
896 nfs_release_automount_timer();
897 dprintk("<-- nfs_free_server()\n");
898}
899
900/*
901 * Create a version 2 or 3 volume record
902 * - keyed on server and FSID
903 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -0400904struct nfs_server *nfs_create_server(const struct nfs_parsed_mount_data *data,
David Howells54ceac42006-08-22 20:06:13 -0400905 struct nfs_fh *mntfh)
906{
907 struct nfs_server *server;
908 struct nfs_fattr fattr;
909 int error;
910
911 server = nfs_alloc_server();
912 if (!server)
913 return ERR_PTR(-ENOMEM);
914
915 /* Get a client representation */
916 error = nfs_init_server(server, data);
917 if (error < 0)
918 goto error;
919
920 BUG_ON(!server->nfs_client);
921 BUG_ON(!server->nfs_client->rpc_ops);
922 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
923
924 /* Probe the root fh to retrieve its FSID */
925 error = nfs_probe_fsinfo(server, mntfh, &fattr);
926 if (error < 0)
927 goto error;
Trond Myklebust54af3bb2007-09-28 12:27:41 -0400928 if (server->nfs_client->rpc_ops->version == 3) {
929 if (server->namelen == 0 || server->namelen > NFS3_MAXNAMLEN)
930 server->namelen = NFS3_MAXNAMLEN;
931 if (!(data->flags & NFS_MOUNT_NORDIRPLUS))
932 server->caps |= NFS_CAP_READDIRPLUS;
933 } else {
934 if (server->namelen == 0 || server->namelen > NFS2_MAXNAMLEN)
935 server->namelen = NFS2_MAXNAMLEN;
936 }
937
David Howells54ceac42006-08-22 20:06:13 -0400938 if (!(fattr.valid & NFS_ATTR_FATTR)) {
939 error = server->nfs_client->rpc_ops->getattr(server, mntfh, &fattr);
940 if (error < 0) {
941 dprintk("nfs_create_server: getattr error = %d\n", -error);
942 goto error;
943 }
944 }
945 memcpy(&server->fsid, &fattr.fsid, sizeof(server->fsid));
946
David Howells6daabf12006-08-24 15:44:16 -0400947 dprintk("Server FSID: %llx:%llx\n",
948 (unsigned long long) server->fsid.major,
949 (unsigned long long) server->fsid.minor);
David Howells54ceac42006-08-22 20:06:13 -0400950
951 BUG_ON(!server->nfs_client);
952 BUG_ON(!server->nfs_client->rpc_ops);
953 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
954
955 spin_lock(&nfs_client_lock);
956 list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks);
957 list_add_tail(&server->master_link, &nfs_volume_list);
958 spin_unlock(&nfs_client_lock);
959
960 server->mount_time = jiffies;
961 return server;
962
963error:
964 nfs_free_server(server);
965 return ERR_PTR(error);
966}
967
968#ifdef CONFIG_NFS_V4
969/*
970 * Initialise an NFS4 client record
971 */
972static int nfs4_init_client(struct nfs_client *clp,
Trond Myklebust33170232007-12-20 16:03:59 -0500973 const struct rpc_timeout *timeparms,
J. Bruce Fields7d9ac062006-10-19 23:28:39 -0700974 const char *ip_addr,
Chuck Leverd7403512008-12-23 15:21:37 -0500975 rpc_authflavor_t authflavour,
976 int flags)
David Howells54ceac42006-08-22 20:06:13 -0400977{
978 int error;
979
980 if (clp->cl_cons_state == NFS_CS_READY) {
981 /* the client is initialised already */
982 dprintk("<-- nfs4_init_client() = 0 [already %p]\n", clp);
983 return 0;
984 }
985
986 /* Check NFS protocol revision and initialize RPC op vector */
987 clp->rpc_ops = &nfs_v4_clientops;
988
Trond Myklebust59dca3b2008-01-03 16:29:06 -0500989 error = nfs_create_rpc_client(clp, timeparms, authflavour,
Chuck Leverd7403512008-12-23 15:21:37 -0500990 1, flags & NFS_MOUNT_NORESVPORT);
David Howells54ceac42006-08-22 20:06:13 -0400991 if (error < 0)
992 goto error;
J. Bruce Fields7d9ac062006-10-19 23:28:39 -0700993 memcpy(clp->cl_ipaddr, ip_addr, sizeof(clp->cl_ipaddr));
David Howells54ceac42006-08-22 20:06:13 -0400994
995 error = nfs_idmap_new(clp);
996 if (error < 0) {
997 dprintk("%s: failed to create idmapper. Error = %d\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -0700998 __func__, error);
David Howells54ceac42006-08-22 20:06:13 -0400999 goto error;
1000 }
Trond Myklebust9c5bf382006-08-22 20:06:14 -04001001 __set_bit(NFS_CS_IDMAP, &clp->cl_res_state);
David Howells54ceac42006-08-22 20:06:13 -04001002
1003 nfs_mark_client_ready(clp, NFS_CS_READY);
1004 return 0;
1005
1006error:
1007 nfs_mark_client_ready(clp, error);
1008 dprintk("<-- nfs4_init_client() = xerror %d\n", error);
1009 return error;
1010}
1011
1012/*
1013 * Set up an NFS4 client
1014 */
1015static int nfs4_set_client(struct nfs_server *server,
Chuck Leverdcecae02007-12-10 14:58:59 -05001016 const char *hostname,
1017 const struct sockaddr *addr,
1018 const size_t addrlen,
J. Bruce Fields7d9ac062006-10-19 23:28:39 -07001019 const char *ip_addr,
David Howells54ceac42006-08-22 20:06:13 -04001020 rpc_authflavor_t authflavour,
Trond Myklebust33170232007-12-20 16:03:59 -05001021 int proto, const struct rpc_timeout *timeparms)
David Howells54ceac42006-08-22 20:06:13 -04001022{
Trond Myklebust3a498022007-12-14 14:56:04 -05001023 struct nfs_client_initdata cl_init = {
1024 .hostname = hostname,
Chuck Leverdcecae02007-12-10 14:58:59 -05001025 .addr = addr,
1026 .addrlen = addrlen,
Trond Myklebust40c553192007-12-14 14:56:07 -05001027 .rpc_ops = &nfs_v4_clientops,
Trond Myklebust59dca3b2008-01-03 16:29:06 -05001028 .proto = proto,
Trond Myklebust3a498022007-12-14 14:56:04 -05001029 };
David Howells54ceac42006-08-22 20:06:13 -04001030 struct nfs_client *clp;
1031 int error;
1032
1033 dprintk("--> nfs4_set_client()\n");
1034
1035 /* Allocate or find a client reference we can use */
Trond Myklebust3a498022007-12-14 14:56:04 -05001036 clp = nfs_get_client(&cl_init);
David Howells54ceac42006-08-22 20:06:13 -04001037 if (IS_ERR(clp)) {
1038 error = PTR_ERR(clp);
1039 goto error;
1040 }
Chuck Leverd7403512008-12-23 15:21:37 -05001041 error = nfs4_init_client(clp, timeparms, ip_addr, authflavour,
1042 server->flags);
David Howells54ceac42006-08-22 20:06:13 -04001043 if (error < 0)
1044 goto error_put;
1045
1046 server->nfs_client = clp;
1047 dprintk("<-- nfs4_set_client() = 0 [new %p]\n", clp);
1048 return 0;
1049
1050error_put:
1051 nfs_put_client(clp);
1052error:
1053 dprintk("<-- nfs4_set_client() = xerror %d\n", error);
1054 return error;
1055}
1056
1057/*
1058 * Create a version 4 volume record
1059 */
1060static int nfs4_init_server(struct nfs_server *server,
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001061 const struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001062{
Trond Myklebust33170232007-12-20 16:03:59 -05001063 struct rpc_timeout timeparms;
David Howells54ceac42006-08-22 20:06:13 -04001064 int error;
1065
1066 dprintk("--> nfs4_init_server()\n");
1067
Trond Myklebust33170232007-12-20 16:03:59 -05001068 nfs_init_timeout_values(&timeparms, data->nfs_server.protocol,
1069 data->timeo, data->retrans);
1070
Chuck Lever542fcc32008-12-23 15:21:36 -05001071 /* Initialise the client representation from the mount data */
1072 server->flags = data->flags;
1073 server->caps |= NFS_CAP_ATOMIC_OPEN;
1074
Trond Myklebust33170232007-12-20 16:03:59 -05001075 /* Get a client record */
1076 error = nfs4_set_client(server,
1077 data->nfs_server.hostname,
1078 (const struct sockaddr *)&data->nfs_server.address,
1079 data->nfs_server.addrlen,
1080 data->client_address,
1081 data->auth_flavors[0],
1082 data->nfs_server.protocol,
1083 &timeparms);
1084 if (error < 0)
1085 goto error;
1086
David Howells54ceac42006-08-22 20:06:13 -04001087 if (data->rsize)
1088 server->rsize = nfs_block_size(data->rsize, NULL);
1089 if (data->wsize)
1090 server->wsize = nfs_block_size(data->wsize, NULL);
1091
1092 server->acregmin = data->acregmin * HZ;
1093 server->acregmax = data->acregmax * HZ;
1094 server->acdirmin = data->acdirmin * HZ;
1095 server->acdirmax = data->acdirmax * HZ;
1096
Chuck Leverf22d6d72008-03-14 14:10:22 -04001097 server->port = data->nfs_server.port;
1098
Trond Myklebust33170232007-12-20 16:03:59 -05001099 error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]);
David Howells54ceac42006-08-22 20:06:13 -04001100
Trond Myklebust33170232007-12-20 16:03:59 -05001101error:
David Howells54ceac42006-08-22 20:06:13 -04001102 /* Done */
1103 dprintk("<-- nfs4_init_server() = %d\n", error);
1104 return error;
1105}
1106
1107/*
1108 * Create a version 4 volume record
1109 * - keyed on server and FSID
1110 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001111struct nfs_server *nfs4_create_server(const struct nfs_parsed_mount_data *data,
David Howells54ceac42006-08-22 20:06:13 -04001112 struct nfs_fh *mntfh)
1113{
1114 struct nfs_fattr fattr;
1115 struct nfs_server *server;
1116 int error;
1117
1118 dprintk("--> nfs4_create_server()\n");
1119
1120 server = nfs_alloc_server();
1121 if (!server)
1122 return ERR_PTR(-ENOMEM);
1123
David Howells54ceac42006-08-22 20:06:13 -04001124 /* set up the general RPC client */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001125 error = nfs4_init_server(server, data);
David Howells54ceac42006-08-22 20:06:13 -04001126 if (error < 0)
1127 goto error;
1128
1129 BUG_ON(!server->nfs_client);
1130 BUG_ON(!server->nfs_client->rpc_ops);
1131 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
1132
1133 /* Probe the root fh to retrieve its FSID */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001134 error = nfs4_path_walk(server, mntfh, data->nfs_server.export_path);
David Howells54ceac42006-08-22 20:06:13 -04001135 if (error < 0)
1136 goto error;
1137
David Howells6daabf12006-08-24 15:44:16 -04001138 dprintk("Server FSID: %llx:%llx\n",
1139 (unsigned long long) server->fsid.major,
1140 (unsigned long long) server->fsid.minor);
David Howells54ceac42006-08-22 20:06:13 -04001141 dprintk("Mount FH: %d\n", mntfh->size);
1142
1143 error = nfs_probe_fsinfo(server, mntfh, &fattr);
1144 if (error < 0)
1145 goto error;
1146
Trond Myklebust54af3bb2007-09-28 12:27:41 -04001147 if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN)
1148 server->namelen = NFS4_MAXNAMLEN;
1149
David Howells54ceac42006-08-22 20:06:13 -04001150 BUG_ON(!server->nfs_client);
1151 BUG_ON(!server->nfs_client->rpc_ops);
1152 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
1153
1154 spin_lock(&nfs_client_lock);
1155 list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks);
1156 list_add_tail(&server->master_link, &nfs_volume_list);
1157 spin_unlock(&nfs_client_lock);
1158
1159 server->mount_time = jiffies;
1160 dprintk("<-- nfs4_create_server() = %p\n", server);
1161 return server;
1162
1163error:
1164 nfs_free_server(server);
1165 dprintk("<-- nfs4_create_server() = error %d\n", error);
1166 return ERR_PTR(error);
1167}
1168
1169/*
1170 * Create an NFS4 referral server record
1171 */
1172struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data,
Trond Myklebustf2d0d852007-02-02 14:46:09 -08001173 struct nfs_fh *mntfh)
David Howells54ceac42006-08-22 20:06:13 -04001174{
1175 struct nfs_client *parent_client;
1176 struct nfs_server *server, *parent_server;
1177 struct nfs_fattr fattr;
1178 int error;
1179
1180 dprintk("--> nfs4_create_referral_server()\n");
1181
1182 server = nfs_alloc_server();
1183 if (!server)
1184 return ERR_PTR(-ENOMEM);
1185
1186 parent_server = NFS_SB(data->sb);
1187 parent_client = parent_server->nfs_client;
1188
Chuck Lever542fcc32008-12-23 15:21:36 -05001189 /* Initialise the client representation from the parent server */
1190 nfs_server_copy_userdata(server, parent_server);
1191 server->caps |= NFS_CAP_ATOMIC_OPEN;
1192
David Howells54ceac42006-08-22 20:06:13 -04001193 /* Get a client representation.
1194 * Note: NFSv4 always uses TCP, */
Chuck Leverdcecae02007-12-10 14:58:59 -05001195 error = nfs4_set_client(server, data->hostname,
Chuck Lever6677d092007-12-10 14:59:06 -05001196 data->addr,
1197 data->addrlen,
Chuck Leverdcecae02007-12-10 14:58:59 -05001198 parent_client->cl_ipaddr,
1199 data->authflavor,
1200 parent_server->client->cl_xprt->prot,
Trond Myklebust33170232007-12-20 16:03:59 -05001201 parent_server->client->cl_timeout);
andros@citi.umich.edu297de4f2006-08-29 12:19:41 -04001202 if (error < 0)
1203 goto error;
David Howells54ceac42006-08-22 20:06:13 -04001204
Trond Myklebust33170232007-12-20 16:03:59 -05001205 error = nfs_init_server_rpcclient(server, parent_server->client->cl_timeout, data->authflavor);
David Howells54ceac42006-08-22 20:06:13 -04001206 if (error < 0)
1207 goto error;
1208
1209 BUG_ON(!server->nfs_client);
1210 BUG_ON(!server->nfs_client->rpc_ops);
1211 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
1212
Trond Myklebustf2d0d852007-02-02 14:46:09 -08001213 /* Probe the root fh to retrieve its FSID and filehandle */
1214 error = nfs4_path_walk(server, mntfh, data->mnt_path);
1215 if (error < 0)
1216 goto error;
1217
David Howells54ceac42006-08-22 20:06:13 -04001218 /* probe the filesystem info for this server filesystem */
Trond Myklebustf2d0d852007-02-02 14:46:09 -08001219 error = nfs_probe_fsinfo(server, mntfh, &fattr);
David Howells54ceac42006-08-22 20:06:13 -04001220 if (error < 0)
1221 goto error;
1222
Trond Myklebust54af3bb2007-09-28 12:27:41 -04001223 if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN)
1224 server->namelen = NFS4_MAXNAMLEN;
1225
David Howells54ceac42006-08-22 20:06:13 -04001226 dprintk("Referral FSID: %llx:%llx\n",
David Howells6daabf12006-08-24 15:44:16 -04001227 (unsigned long long) server->fsid.major,
1228 (unsigned long long) server->fsid.minor);
David Howells54ceac42006-08-22 20:06:13 -04001229
1230 spin_lock(&nfs_client_lock);
1231 list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks);
1232 list_add_tail(&server->master_link, &nfs_volume_list);
1233 spin_unlock(&nfs_client_lock);
1234
1235 server->mount_time = jiffies;
1236
1237 dprintk("<-- nfs_create_referral_server() = %p\n", server);
1238 return server;
1239
1240error:
1241 nfs_free_server(server);
1242 dprintk("<-- nfs4_create_referral_server() = error %d\n", error);
1243 return ERR_PTR(error);
1244}
1245
1246#endif /* CONFIG_NFS_V4 */
1247
1248/*
1249 * Clone an NFS2, NFS3 or NFS4 server record
1250 */
1251struct nfs_server *nfs_clone_server(struct nfs_server *source,
1252 struct nfs_fh *fh,
1253 struct nfs_fattr *fattr)
1254{
1255 struct nfs_server *server;
1256 struct nfs_fattr fattr_fsinfo;
1257 int error;
1258
1259 dprintk("--> nfs_clone_server(,%llx:%llx,)\n",
David Howells6daabf12006-08-24 15:44:16 -04001260 (unsigned long long) fattr->fsid.major,
1261 (unsigned long long) fattr->fsid.minor);
David Howells54ceac42006-08-22 20:06:13 -04001262
1263 server = nfs_alloc_server();
1264 if (!server)
1265 return ERR_PTR(-ENOMEM);
1266
1267 /* Copy data from the source */
1268 server->nfs_client = source->nfs_client;
1269 atomic_inc(&server->nfs_client->cl_count);
1270 nfs_server_copy_userdata(server, source);
1271
1272 server->fsid = fattr->fsid;
1273
Trond Myklebust33170232007-12-20 16:03:59 -05001274 error = nfs_init_server_rpcclient(server,
1275 source->client->cl_timeout,
1276 source->client->cl_auth->au_flavor);
David Howells54ceac42006-08-22 20:06:13 -04001277 if (error < 0)
1278 goto out_free_server;
1279 if (!IS_ERR(source->client_acl))
1280 nfs_init_server_aclclient(server);
1281
1282 /* probe the filesystem info for this server filesystem */
1283 error = nfs_probe_fsinfo(server, fh, &fattr_fsinfo);
1284 if (error < 0)
1285 goto out_free_server;
1286
Trond Myklebust54af3bb2007-09-28 12:27:41 -04001287 if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN)
1288 server->namelen = NFS4_MAXNAMLEN;
1289
David Howells54ceac42006-08-22 20:06:13 -04001290 dprintk("Cloned FSID: %llx:%llx\n",
David Howells6daabf12006-08-24 15:44:16 -04001291 (unsigned long long) server->fsid.major,
1292 (unsigned long long) server->fsid.minor);
David Howells54ceac42006-08-22 20:06:13 -04001293
1294 error = nfs_start_lockd(server);
1295 if (error < 0)
1296 goto out_free_server;
1297
1298 spin_lock(&nfs_client_lock);
1299 list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks);
1300 list_add_tail(&server->master_link, &nfs_volume_list);
1301 spin_unlock(&nfs_client_lock);
1302
1303 server->mount_time = jiffies;
1304
1305 dprintk("<-- nfs_clone_server() = %p\n", server);
1306 return server;
1307
1308out_free_server:
1309 nfs_free_server(server);
1310 dprintk("<-- nfs_clone_server() = error %d\n", error);
1311 return ERR_PTR(error);
1312}
David Howells6aaca562006-08-22 20:06:13 -04001313
1314#ifdef CONFIG_PROC_FS
1315static struct proc_dir_entry *proc_fs_nfs;
1316
1317static int nfs_server_list_open(struct inode *inode, struct file *file);
1318static void *nfs_server_list_start(struct seq_file *p, loff_t *pos);
1319static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos);
1320static void nfs_server_list_stop(struct seq_file *p, void *v);
1321static int nfs_server_list_show(struct seq_file *m, void *v);
1322
1323static struct seq_operations nfs_server_list_ops = {
1324 .start = nfs_server_list_start,
1325 .next = nfs_server_list_next,
1326 .stop = nfs_server_list_stop,
1327 .show = nfs_server_list_show,
1328};
1329
Arjan van de Ven00977a52007-02-12 00:55:34 -08001330static const struct file_operations nfs_server_list_fops = {
David Howells6aaca562006-08-22 20:06:13 -04001331 .open = nfs_server_list_open,
1332 .read = seq_read,
1333 .llseek = seq_lseek,
1334 .release = seq_release,
Denis V. Lunev34b37232008-04-29 01:02:07 -07001335 .owner = THIS_MODULE,
David Howells6aaca562006-08-22 20:06:13 -04001336};
1337
1338static int nfs_volume_list_open(struct inode *inode, struct file *file);
1339static void *nfs_volume_list_start(struct seq_file *p, loff_t *pos);
1340static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos);
1341static void nfs_volume_list_stop(struct seq_file *p, void *v);
1342static int nfs_volume_list_show(struct seq_file *m, void *v);
1343
1344static struct seq_operations nfs_volume_list_ops = {
1345 .start = nfs_volume_list_start,
1346 .next = nfs_volume_list_next,
1347 .stop = nfs_volume_list_stop,
1348 .show = nfs_volume_list_show,
1349};
1350
Arjan van de Ven00977a52007-02-12 00:55:34 -08001351static const struct file_operations nfs_volume_list_fops = {
David Howells6aaca562006-08-22 20:06:13 -04001352 .open = nfs_volume_list_open,
1353 .read = seq_read,
1354 .llseek = seq_lseek,
1355 .release = seq_release,
Denis V. Lunev34b37232008-04-29 01:02:07 -07001356 .owner = THIS_MODULE,
David Howells6aaca562006-08-22 20:06:13 -04001357};
1358
1359/*
1360 * open "/proc/fs/nfsfs/servers" which provides a summary of servers with which
1361 * we're dealing
1362 */
1363static int nfs_server_list_open(struct inode *inode, struct file *file)
1364{
1365 struct seq_file *m;
1366 int ret;
1367
1368 ret = seq_open(file, &nfs_server_list_ops);
1369 if (ret < 0)
1370 return ret;
1371
1372 m = file->private_data;
1373 m->private = PDE(inode)->data;
1374
1375 return 0;
1376}
1377
1378/*
1379 * set up the iterator to start reading from the server list and return the first item
1380 */
1381static void *nfs_server_list_start(struct seq_file *m, loff_t *_pos)
1382{
David Howells6aaca562006-08-22 20:06:13 -04001383 /* lock the list against modification */
1384 spin_lock(&nfs_client_lock);
Pavel Emelianov259902e2007-07-15 23:39:56 -07001385 return seq_list_start_head(&nfs_client_list, *_pos);
David Howells6aaca562006-08-22 20:06:13 -04001386}
1387
1388/*
1389 * move to next server
1390 */
1391static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos)
1392{
Pavel Emelianov259902e2007-07-15 23:39:56 -07001393 return seq_list_next(v, &nfs_client_list, pos);
David Howells6aaca562006-08-22 20:06:13 -04001394}
1395
1396/*
1397 * clean up after reading from the transports list
1398 */
1399static void nfs_server_list_stop(struct seq_file *p, void *v)
1400{
1401 spin_unlock(&nfs_client_lock);
1402}
1403
1404/*
1405 * display a header line followed by a load of call lines
1406 */
1407static int nfs_server_list_show(struct seq_file *m, void *v)
1408{
1409 struct nfs_client *clp;
1410
1411 /* display header on line 1 */
Pavel Emelianov259902e2007-07-15 23:39:56 -07001412 if (v == &nfs_client_list) {
David Howells6aaca562006-08-22 20:06:13 -04001413 seq_puts(m, "NV SERVER PORT USE HOSTNAME\n");
1414 return 0;
1415 }
1416
1417 /* display one transport per line on subsequent lines */
1418 clp = list_entry(v, struct nfs_client, cl_share_link);
1419
Chuck Lever5d8515c2007-12-10 14:57:16 -05001420 seq_printf(m, "v%u %s %s %3d %s\n",
Trond Myklebust40c553192007-12-14 14:56:07 -05001421 clp->rpc_ops->version,
Chuck Lever5d8515c2007-12-10 14:57:16 -05001422 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR),
1423 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT),
David Howells6aaca562006-08-22 20:06:13 -04001424 atomic_read(&clp->cl_count),
1425 clp->cl_hostname);
1426
1427 return 0;
1428}
1429
1430/*
1431 * open "/proc/fs/nfsfs/volumes" which provides a summary of extant volumes
1432 */
1433static int nfs_volume_list_open(struct inode *inode, struct file *file)
1434{
1435 struct seq_file *m;
1436 int ret;
1437
1438 ret = seq_open(file, &nfs_volume_list_ops);
1439 if (ret < 0)
1440 return ret;
1441
1442 m = file->private_data;
1443 m->private = PDE(inode)->data;
1444
1445 return 0;
1446}
1447
1448/*
1449 * set up the iterator to start reading from the volume list and return the first item
1450 */
1451static void *nfs_volume_list_start(struct seq_file *m, loff_t *_pos)
1452{
David Howells6aaca562006-08-22 20:06:13 -04001453 /* lock the list against modification */
1454 spin_lock(&nfs_client_lock);
Pavel Emelianov259902e2007-07-15 23:39:56 -07001455 return seq_list_start_head(&nfs_volume_list, *_pos);
David Howells6aaca562006-08-22 20:06:13 -04001456}
1457
1458/*
1459 * move to next volume
1460 */
1461static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos)
1462{
Pavel Emelianov259902e2007-07-15 23:39:56 -07001463 return seq_list_next(v, &nfs_volume_list, pos);
David Howells6aaca562006-08-22 20:06:13 -04001464}
1465
1466/*
1467 * clean up after reading from the transports list
1468 */
1469static void nfs_volume_list_stop(struct seq_file *p, void *v)
1470{
1471 spin_unlock(&nfs_client_lock);
1472}
1473
1474/*
1475 * display a header line followed by a load of call lines
1476 */
1477static int nfs_volume_list_show(struct seq_file *m, void *v)
1478{
1479 struct nfs_server *server;
1480 struct nfs_client *clp;
1481 char dev[8], fsid[17];
1482
1483 /* display header on line 1 */
Pavel Emelianov259902e2007-07-15 23:39:56 -07001484 if (v == &nfs_volume_list) {
David Howells6aaca562006-08-22 20:06:13 -04001485 seq_puts(m, "NV SERVER PORT DEV FSID\n");
1486 return 0;
1487 }
1488 /* display one transport per line on subsequent lines */
1489 server = list_entry(v, struct nfs_server, master_link);
1490 clp = server->nfs_client;
1491
1492 snprintf(dev, 8, "%u:%u",
1493 MAJOR(server->s_dev), MINOR(server->s_dev));
1494
1495 snprintf(fsid, 17, "%llx:%llx",
David Howells6daabf12006-08-24 15:44:16 -04001496 (unsigned long long) server->fsid.major,
1497 (unsigned long long) server->fsid.minor);
David Howells6aaca562006-08-22 20:06:13 -04001498
Chuck Lever5d8515c2007-12-10 14:57:16 -05001499 seq_printf(m, "v%u %s %s %-7s %-17s\n",
Trond Myklebust40c553192007-12-14 14:56:07 -05001500 clp->rpc_ops->version,
Chuck Lever5d8515c2007-12-10 14:57:16 -05001501 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR),
1502 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT),
David Howells6aaca562006-08-22 20:06:13 -04001503 dev,
1504 fsid);
1505
1506 return 0;
1507}
1508
1509/*
1510 * initialise the /proc/fs/nfsfs/ directory
1511 */
1512int __init nfs_fs_proc_init(void)
1513{
1514 struct proc_dir_entry *p;
1515
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -07001516 proc_fs_nfs = proc_mkdir("fs/nfsfs", NULL);
David Howells6aaca562006-08-22 20:06:13 -04001517 if (!proc_fs_nfs)
1518 goto error_0;
1519
1520 proc_fs_nfs->owner = THIS_MODULE;
1521
1522 /* a file of servers with which we're dealing */
Denis V. Lunev34b37232008-04-29 01:02:07 -07001523 p = proc_create("servers", S_IFREG|S_IRUGO,
1524 proc_fs_nfs, &nfs_server_list_fops);
David Howells6aaca562006-08-22 20:06:13 -04001525 if (!p)
1526 goto error_1;
1527
David Howells6aaca562006-08-22 20:06:13 -04001528 /* a file of volumes that we have mounted */
Denis V. Lunev34b37232008-04-29 01:02:07 -07001529 p = proc_create("volumes", S_IFREG|S_IRUGO,
1530 proc_fs_nfs, &nfs_volume_list_fops);
David Howells6aaca562006-08-22 20:06:13 -04001531 if (!p)
1532 goto error_2;
David Howells6aaca562006-08-22 20:06:13 -04001533 return 0;
1534
1535error_2:
1536 remove_proc_entry("servers", proc_fs_nfs);
1537error_1:
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -07001538 remove_proc_entry("fs/nfsfs", NULL);
David Howells6aaca562006-08-22 20:06:13 -04001539error_0:
1540 return -ENOMEM;
1541}
1542
1543/*
1544 * clean up the /proc/fs/nfsfs/ directory
1545 */
1546void nfs_fs_proc_exit(void)
1547{
1548 remove_proc_entry("volumes", proc_fs_nfs);
1549 remove_proc_entry("servers", proc_fs_nfs);
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -07001550 remove_proc_entry("fs/nfsfs", NULL);
David Howells6aaca562006-08-22 20:06:13 -04001551}
1552
1553#endif /* CONFIG_PROC_FS */