blob: 12941a8a6d75245134fff12fa8e33acd7ce0dd13 [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
13#include <linux/config.h>
14#include <linux/module.h>
15#include <linux/init.h>
16
17#include <linux/time.h>
18#include <linux/kernel.h>
19#include <linux/mm.h>
20#include <linux/string.h>
21#include <linux/stat.h>
22#include <linux/errno.h>
23#include <linux/unistd.h>
24#include <linux/sunrpc/clnt.h>
25#include <linux/sunrpc/stats.h>
26#include <linux/sunrpc/metrics.h>
27#include <linux/nfs_fs.h>
28#include <linux/nfs_mount.h>
29#include <linux/nfs4_mount.h>
30#include <linux/lockd/bind.h>
31#include <linux/smp_lock.h>
32#include <linux/seq_file.h>
33#include <linux/mount.h>
34#include <linux/nfs_idmap.h>
35#include <linux/vfs.h>
36#include <linux/inet.h>
37#include <linux/nfs_xdr.h>
38
39#include <asm/system.h>
40
41#include "nfs4_fs.h"
42#include "callback.h"
43#include "delegation.h"
44#include "iostat.h"
45#include "internal.h"
46
47#define NFSDBG_FACILITY NFSDBG_CLIENT
48
49static DEFINE_SPINLOCK(nfs_client_lock);
50static LIST_HEAD(nfs_client_list);
David Howells54ceac42006-08-22 20:06:13 -040051static LIST_HEAD(nfs_volume_list);
David Howells24c8dbb2006-08-22 20:06:10 -040052static DECLARE_WAIT_QUEUE_HEAD(nfs_client_active_wq);
53
54/*
David Howells5006a762006-08-22 20:06:12 -040055 * RPC cruft for NFS
56 */
57static struct rpc_version *nfs_version[5] = {
58 [2] = &nfs_version2,
59#ifdef CONFIG_NFS_V3
60 [3] = &nfs_version3,
61#endif
62#ifdef CONFIG_NFS_V4
63 [4] = &nfs_version4,
64#endif
65};
66
67struct rpc_program nfs_program = {
68 .name = "nfs",
69 .number = NFS_PROGRAM,
70 .nrvers = ARRAY_SIZE(nfs_version),
71 .version = nfs_version,
72 .stats = &nfs_rpcstat,
73 .pipe_dir_name = "/nfs",
74};
75
76struct rpc_stat nfs_rpcstat = {
77 .program = &nfs_program
78};
79
80
81#ifdef CONFIG_NFS_V3_ACL
82static struct rpc_stat nfsacl_rpcstat = { &nfsacl_program };
83static struct rpc_version * nfsacl_version[] = {
84 [3] = &nfsacl_version3,
85};
86
87struct rpc_program nfsacl_program = {
88 .name = "nfsacl",
89 .number = NFS_ACL_PROGRAM,
90 .nrvers = ARRAY_SIZE(nfsacl_version),
91 .version = nfsacl_version,
92 .stats = &nfsacl_rpcstat,
93};
94#endif /* CONFIG_NFS_V3_ACL */
95
96/*
David Howells24c8dbb2006-08-22 20:06:10 -040097 * Allocate a shared client record
98 *
99 * Since these are allocated/deallocated very rarely, we don't
100 * bother putting them in a slab cache...
101 */
102static struct nfs_client *nfs_alloc_client(const char *hostname,
103 const struct sockaddr_in *addr,
104 int nfsversion)
105{
106 struct nfs_client *clp;
107 int error;
108
109 if ((clp = kzalloc(sizeof(*clp), GFP_KERNEL)) == NULL)
110 goto error_0;
111
112 error = rpciod_up();
113 if (error < 0) {
114 dprintk("%s: couldn't start rpciod! Error = %d\n",
115 __FUNCTION__, error);
David Howells24c8dbb2006-08-22 20:06:10 -0400116 goto error_1;
117 }
Trond Myklebust9c5bf382006-08-22 20:06:14 -0400118 __set_bit(NFS_CS_RPCIOD, &clp->cl_res_state);
David Howells24c8dbb2006-08-22 20:06:10 -0400119
120 if (nfsversion == 4) {
121 if (nfs_callback_up() < 0)
122 goto error_2;
123 __set_bit(NFS_CS_CALLBACK, &clp->cl_res_state);
124 }
125
126 atomic_set(&clp->cl_count, 1);
127 clp->cl_cons_state = NFS_CS_INITING;
128
129 clp->cl_nfsversion = nfsversion;
130 memcpy(&clp->cl_addr, addr, sizeof(clp->cl_addr));
131
132 if (hostname) {
133 clp->cl_hostname = kstrdup(hostname, GFP_KERNEL);
134 if (!clp->cl_hostname)
135 goto error_3;
136 }
137
138 INIT_LIST_HEAD(&clp->cl_superblocks);
139 clp->cl_rpcclient = ERR_PTR(-EINVAL);
140
141#ifdef CONFIG_NFS_V4
142 init_rwsem(&clp->cl_sem);
143 INIT_LIST_HEAD(&clp->cl_delegations);
144 INIT_LIST_HEAD(&clp->cl_state_owners);
145 INIT_LIST_HEAD(&clp->cl_unused);
146 spin_lock_init(&clp->cl_lock);
147 INIT_WORK(&clp->cl_renewd, nfs4_renew_state, clp);
148 rpc_init_wait_queue(&clp->cl_rpcwaitq, "NFS client");
149 clp->cl_boot_time = CURRENT_TIME;
150 clp->cl_state = 1 << NFS4CLNT_LEASE_EXPIRED;
151#endif
152
153 return clp;
154
155error_3:
Trond Myklebust9c5bf382006-08-22 20:06:14 -0400156 if (__test_and_clear_bit(NFS_CS_CALLBACK, &clp->cl_res_state))
157 nfs_callback_down();
David Howells24c8dbb2006-08-22 20:06:10 -0400158error_2:
159 rpciod_down();
160 __clear_bit(NFS_CS_RPCIOD, &clp->cl_res_state);
161error_1:
162 kfree(clp);
163error_0:
164 return NULL;
165}
166
167/*
168 * Destroy a shared client record
169 */
170static void nfs_free_client(struct nfs_client *clp)
171{
172 dprintk("--> nfs_free_client(%d)\n", clp->cl_nfsversion);
173
174#ifdef CONFIG_NFS_V4
175 if (__test_and_clear_bit(NFS_CS_IDMAP, &clp->cl_res_state)) {
176 while (!list_empty(&clp->cl_unused)) {
177 struct nfs4_state_owner *sp;
178
179 sp = list_entry(clp->cl_unused.next,
180 struct nfs4_state_owner,
181 so_list);
182 list_del(&sp->so_list);
183 kfree(sp);
184 }
185 BUG_ON(!list_empty(&clp->cl_state_owners));
186 nfs_idmap_delete(clp);
187 }
188#endif
189
190 /* -EIO all pending I/O */
191 if (!IS_ERR(clp->cl_rpcclient))
192 rpc_shutdown_client(clp->cl_rpcclient);
193
194 if (__test_and_clear_bit(NFS_CS_CALLBACK, &clp->cl_res_state))
195 nfs_callback_down();
196
197 if (__test_and_clear_bit(NFS_CS_RPCIOD, &clp->cl_res_state))
Trond Myklebust9c5bf382006-08-22 20:06:14 -0400198 rpciod_down();
David Howells24c8dbb2006-08-22 20:06:10 -0400199
200 kfree(clp->cl_hostname);
201 kfree(clp);
202
203 dprintk("<-- nfs_free_client()\n");
204}
205
206/*
207 * Release a reference to a shared client record
208 */
209void nfs_put_client(struct nfs_client *clp)
210{
David Howells27ba8512006-07-30 14:40:56 -0400211 if (!clp)
212 return;
213
David Howells24c8dbb2006-08-22 20:06:10 -0400214 dprintk("--> nfs_put_client({%d})\n", atomic_read(&clp->cl_count));
215
216 if (atomic_dec_and_lock(&clp->cl_count, &nfs_client_lock)) {
217 list_del(&clp->cl_share_link);
218 spin_unlock(&nfs_client_lock);
219
220 BUG_ON(!list_empty(&clp->cl_superblocks));
221
222 nfs_free_client(clp);
223 }
224}
225
226/*
227 * Find a client by address
228 * - caller must hold nfs_client_lock
229 */
230static struct nfs_client *__nfs_find_client(const struct sockaddr_in *addr, int nfsversion)
231{
232 struct nfs_client *clp;
233
234 list_for_each_entry(clp, &nfs_client_list, cl_share_link) {
235 /* Different NFS versions cannot share the same nfs_client */
236 if (clp->cl_nfsversion != nfsversion)
237 continue;
238
239 if (memcmp(&clp->cl_addr.sin_addr, &addr->sin_addr,
240 sizeof(clp->cl_addr.sin_addr)) != 0)
241 continue;
242
243 if (clp->cl_addr.sin_port == addr->sin_port)
244 goto found;
245 }
246
247 return NULL;
248
249found:
250 atomic_inc(&clp->cl_count);
251 return clp;
252}
253
254/*
255 * Find a client by IP address and protocol version
256 * - returns NULL if no such client
257 */
258struct nfs_client *nfs_find_client(const struct sockaddr_in *addr, int nfsversion)
259{
260 struct nfs_client *clp;
261
262 spin_lock(&nfs_client_lock);
263 clp = __nfs_find_client(addr, nfsversion);
264 spin_unlock(&nfs_client_lock);
265
266 BUG_ON(clp->cl_cons_state == 0);
267
268 return clp;
269}
270
271/*
272 * Look up a client by IP address and protocol version
273 * - creates a new record if one doesn't yet exist
274 */
David Howells54ceac42006-08-22 20:06:13 -0400275static struct nfs_client *nfs_get_client(const char *hostname,
276 const struct sockaddr_in *addr,
277 int nfsversion)
David Howells24c8dbb2006-08-22 20:06:10 -0400278{
279 struct nfs_client *clp, *new = NULL;
280 int error;
281
282 dprintk("--> nfs_get_client(%s,"NIPQUAD_FMT":%d,%d)\n",
283 hostname ?: "", NIPQUAD(addr->sin_addr),
284 addr->sin_port, nfsversion);
285
286 /* see if the client already exists */
287 do {
288 spin_lock(&nfs_client_lock);
289
290 clp = __nfs_find_client(addr, nfsversion);
291 if (clp)
292 goto found_client;
293 if (new)
294 goto install_client;
295
296 spin_unlock(&nfs_client_lock);
297
298 new = nfs_alloc_client(hostname, addr, nfsversion);
299 } while (new);
300
301 return ERR_PTR(-ENOMEM);
302
303 /* install a new client and return with it unready */
304install_client:
305 clp = new;
306 list_add(&clp->cl_share_link, &nfs_client_list);
307 spin_unlock(&nfs_client_lock);
308 dprintk("--> nfs_get_client() = %p [new]\n", clp);
309 return clp;
310
311 /* found an existing client
312 * - make sure it's ready before returning
313 */
314found_client:
315 spin_unlock(&nfs_client_lock);
316
317 if (new)
318 nfs_free_client(new);
319
320 if (clp->cl_cons_state == NFS_CS_INITING) {
321 DECLARE_WAITQUEUE(myself, current);
322
323 add_wait_queue(&nfs_client_active_wq, &myself);
324
325 for (;;) {
326 set_current_state(TASK_INTERRUPTIBLE);
327 if (signal_pending(current) ||
328 clp->cl_cons_state > NFS_CS_READY)
329 break;
330 schedule();
331 }
332
333 remove_wait_queue(&nfs_client_active_wq, &myself);
334
335 if (signal_pending(current)) {
336 nfs_put_client(clp);
337 return ERR_PTR(-ERESTARTSYS);
338 }
339 }
340
341 if (clp->cl_cons_state < NFS_CS_READY) {
342 error = clp->cl_cons_state;
343 nfs_put_client(clp);
344 return ERR_PTR(error);
345 }
346
David Howells54ceac42006-08-22 20:06:13 -0400347 BUG_ON(clp->cl_cons_state != NFS_CS_READY);
348
David Howells24c8dbb2006-08-22 20:06:10 -0400349 dprintk("--> nfs_get_client() = %p [share]\n", clp);
350 return clp;
351}
352
353/*
354 * Mark a server as ready or failed
355 */
David Howells54ceac42006-08-22 20:06:13 -0400356static void nfs_mark_client_ready(struct nfs_client *clp, int state)
David Howells24c8dbb2006-08-22 20:06:10 -0400357{
358 clp->cl_cons_state = state;
359 wake_up_all(&nfs_client_active_wq);
360}
David Howells5006a762006-08-22 20:06:12 -0400361
362/*
363 * Initialise the timeout values for a connection
364 */
365static void nfs_init_timeout_values(struct rpc_timeout *to, int proto,
366 unsigned int timeo, unsigned int retrans)
367{
368 to->to_initval = timeo * HZ / 10;
369 to->to_retries = retrans;
370 if (!to->to_retries)
371 to->to_retries = 2;
372
373 switch (proto) {
374 case IPPROTO_TCP:
375 if (!to->to_initval)
376 to->to_initval = 60 * HZ;
377 if (to->to_initval > NFS_MAX_TCP_TIMEOUT)
378 to->to_initval = NFS_MAX_TCP_TIMEOUT;
379 to->to_increment = to->to_initval;
380 to->to_maxval = to->to_initval + (to->to_increment * to->to_retries);
381 to->to_exponential = 0;
382 break;
383 case IPPROTO_UDP:
384 default:
385 if (!to->to_initval)
386 to->to_initval = 11 * HZ / 10;
387 if (to->to_initval > NFS_MAX_UDP_TIMEOUT)
388 to->to_initval = NFS_MAX_UDP_TIMEOUT;
389 to->to_maxval = NFS_MAX_UDP_TIMEOUT;
390 to->to_exponential = 1;
391 break;
392 }
393}
394
395/*
396 * Create an RPC client handle
397 */
David Howells54ceac42006-08-22 20:06:13 -0400398static int nfs_create_rpc_client(struct nfs_client *clp, int proto,
399 unsigned int timeo,
400 unsigned int retrans,
401 rpc_authflavor_t flavor)
David Howells5006a762006-08-22 20:06:12 -0400402{
403 struct rpc_timeout timeparms;
David Howells5006a762006-08-22 20:06:12 -0400404 struct rpc_clnt *clnt = NULL;
Chuck Lever41877d22006-08-22 20:06:20 -0400405 struct rpc_create_args args = {
406 .protocol = proto,
407 .address = (struct sockaddr *)&clp->cl_addr,
408 .addrsize = sizeof(clp->cl_addr),
409 .timeout = &timeparms,
410 .servername = clp->cl_hostname,
411 .program = &nfs_program,
412 .version = clp->rpc_ops->version,
413 .authflavor = flavor,
414 };
David Howells5006a762006-08-22 20:06:12 -0400415
416 if (!IS_ERR(clp->cl_rpcclient))
417 return 0;
418
419 nfs_init_timeout_values(&timeparms, proto, timeo, retrans);
420 clp->retrans_timeo = timeparms.to_initval;
421 clp->retrans_count = timeparms.to_retries;
422
Chuck Lever41877d22006-08-22 20:06:20 -0400423 clnt = rpc_create(&args);
David Howells5006a762006-08-22 20:06:12 -0400424 if (IS_ERR(clnt)) {
425 dprintk("%s: cannot create RPC client. Error = %ld\n",
426 __FUNCTION__, PTR_ERR(clnt));
427 return PTR_ERR(clnt);
428 }
429
David Howells5006a762006-08-22 20:06:12 -0400430 clp->cl_rpcclient = clnt;
431 return 0;
432}
David Howells54ceac42006-08-22 20:06:13 -0400433
434/*
435 * Version 2 or 3 client destruction
436 */
437static void nfs_destroy_server(struct nfs_server *server)
438{
439 if (!IS_ERR(server->client_acl))
440 rpc_shutdown_client(server->client_acl);
441
442 if (!(server->flags & NFS_MOUNT_NONLM))
443 lockd_down(); /* release rpc.lockd */
444}
445
446/*
447 * Version 2 or 3 lockd setup
448 */
449static int nfs_start_lockd(struct nfs_server *server)
450{
451 int error = 0;
452
453 if (server->nfs_client->cl_nfsversion > 3)
454 goto out;
455 if (server->flags & NFS_MOUNT_NONLM)
456 goto out;
457 error = lockd_up();
458 if (error < 0)
459 server->flags |= NFS_MOUNT_NONLM;
460 else
461 server->destroy = nfs_destroy_server;
462out:
463 return error;
464}
465
466/*
467 * Initialise an NFSv3 ACL client connection
468 */
469#ifdef CONFIG_NFS_V3_ACL
470static void nfs_init_server_aclclient(struct nfs_server *server)
471{
472 if (server->nfs_client->cl_nfsversion != 3)
473 goto out_noacl;
474 if (server->flags & NFS_MOUNT_NOACL)
475 goto out_noacl;
476
477 server->client_acl = rpc_bind_new_program(server->client, &nfsacl_program, 3);
478 if (IS_ERR(server->client_acl))
479 goto out_noacl;
480
481 /* No errors! Assume that Sun nfsacls are supported */
482 server->caps |= NFS_CAP_ACLS;
483 return;
484
485out_noacl:
486 server->caps &= ~NFS_CAP_ACLS;
487}
488#else
489static inline void nfs_init_server_aclclient(struct nfs_server *server)
490{
491 server->flags &= ~NFS_MOUNT_NOACL;
492 server->caps &= ~NFS_CAP_ACLS;
493}
494#endif
495
496/*
497 * Create a general RPC client
498 */
499static int nfs_init_server_rpcclient(struct nfs_server *server, rpc_authflavor_t pseudoflavour)
500{
501 struct nfs_client *clp = server->nfs_client;
502
503 server->client = rpc_clone_client(clp->cl_rpcclient);
504 if (IS_ERR(server->client)) {
505 dprintk("%s: couldn't create rpc_client!\n", __FUNCTION__);
506 return PTR_ERR(server->client);
507 }
508
509 if (pseudoflavour != clp->cl_rpcclient->cl_auth->au_flavor) {
510 struct rpc_auth *auth;
511
512 auth = rpcauth_create(pseudoflavour, server->client);
513 if (IS_ERR(auth)) {
514 dprintk("%s: couldn't create credcache!\n", __FUNCTION__);
515 return PTR_ERR(auth);
516 }
517 }
518 server->client->cl_softrtry = 0;
519 if (server->flags & NFS_MOUNT_SOFT)
520 server->client->cl_softrtry = 1;
521
522 server->client->cl_intr = 0;
523 if (server->flags & NFS4_MOUNT_INTR)
524 server->client->cl_intr = 1;
525
526 return 0;
527}
528
529/*
530 * Initialise an NFS2 or NFS3 client
531 */
532static int nfs_init_client(struct nfs_client *clp, const struct nfs_mount_data *data)
533{
534 int proto = (data->flags & NFS_MOUNT_TCP) ? IPPROTO_TCP : IPPROTO_UDP;
535 int error;
536
537 if (clp->cl_cons_state == NFS_CS_READY) {
538 /* the client is already initialised */
539 dprintk("<-- nfs_init_client() = 0 [already %p]\n", clp);
540 return 0;
541 }
542
543 /* Check NFS protocol revision and initialize RPC op vector */
544 clp->rpc_ops = &nfs_v2_clientops;
545#ifdef CONFIG_NFS_V3
546 if (clp->cl_nfsversion == 3)
547 clp->rpc_ops = &nfs_v3_clientops;
548#endif
549 /*
550 * Create a client RPC handle for doing FSSTAT with UNIX auth only
551 * - RFC 2623, sec 2.3.2
552 */
553 error = nfs_create_rpc_client(clp, proto, data->timeo, data->retrans,
554 RPC_AUTH_UNIX);
555 if (error < 0)
556 goto error;
557 nfs_mark_client_ready(clp, NFS_CS_READY);
558 return 0;
559
560error:
561 nfs_mark_client_ready(clp, error);
562 dprintk("<-- nfs_init_client() = xerror %d\n", error);
563 return error;
564}
565
566/*
567 * Create a version 2 or 3 client
568 */
569static int nfs_init_server(struct nfs_server *server, const struct nfs_mount_data *data)
570{
571 struct nfs_client *clp;
572 int error, nfsvers = 2;
573
574 dprintk("--> nfs_init_server()\n");
575
576#ifdef CONFIG_NFS_V3
577 if (data->flags & NFS_MOUNT_VER3)
578 nfsvers = 3;
579#endif
580
581 /* Allocate or find a client reference we can use */
582 clp = nfs_get_client(data->hostname, &data->addr, nfsvers);
583 if (IS_ERR(clp)) {
584 dprintk("<-- nfs_init_server() = error %ld\n", PTR_ERR(clp));
585 return PTR_ERR(clp);
586 }
587
588 error = nfs_init_client(clp, data);
589 if (error < 0)
590 goto error;
591
592 server->nfs_client = clp;
593
594 /* Initialise the client representation from the mount data */
595 server->flags = data->flags & NFS_MOUNT_FLAGMASK;
596
597 if (data->rsize)
598 server->rsize = nfs_block_size(data->rsize, NULL);
599 if (data->wsize)
600 server->wsize = nfs_block_size(data->wsize, NULL);
601
602 server->acregmin = data->acregmin * HZ;
603 server->acregmax = data->acregmax * HZ;
604 server->acdirmin = data->acdirmin * HZ;
605 server->acdirmax = data->acdirmax * HZ;
606
607 /* Start lockd here, before we might error out */
608 error = nfs_start_lockd(server);
609 if (error < 0)
610 goto error;
611
612 error = nfs_init_server_rpcclient(server, data->pseudoflavor);
613 if (error < 0)
614 goto error;
615
616 server->namelen = data->namlen;
617 /* Create a client RPC handle for the NFSv3 ACL management interface */
618 nfs_init_server_aclclient(server);
619 if (clp->cl_nfsversion == 3) {
620 if (server->namelen == 0 || server->namelen > NFS3_MAXNAMLEN)
621 server->namelen = NFS3_MAXNAMLEN;
622 server->caps |= NFS_CAP_READDIRPLUS;
623 } else {
624 if (server->namelen == 0 || server->namelen > NFS2_MAXNAMLEN)
625 server->namelen = NFS2_MAXNAMLEN;
626 }
627
628 dprintk("<-- nfs_init_server() = 0 [new %p]\n", clp);
629 return 0;
630
631error:
632 server->nfs_client = NULL;
633 nfs_put_client(clp);
634 dprintk("<-- nfs_init_server() = xerror %d\n", error);
635 return error;
636}
637
638/*
639 * Load up the server record from information gained in an fsinfo record
640 */
641static void nfs_server_set_fsinfo(struct nfs_server *server, struct nfs_fsinfo *fsinfo)
642{
643 unsigned long max_rpc_payload;
644
645 /* Work out a lot of parameters */
646 if (server->rsize == 0)
647 server->rsize = nfs_block_size(fsinfo->rtpref, NULL);
648 if (server->wsize == 0)
649 server->wsize = nfs_block_size(fsinfo->wtpref, NULL);
650
651 if (fsinfo->rtmax >= 512 && server->rsize > fsinfo->rtmax)
652 server->rsize = nfs_block_size(fsinfo->rtmax, NULL);
653 if (fsinfo->wtmax >= 512 && server->wsize > fsinfo->wtmax)
654 server->wsize = nfs_block_size(fsinfo->wtmax, NULL);
655
656 max_rpc_payload = nfs_block_size(rpc_max_payload(server->client), NULL);
657 if (server->rsize > max_rpc_payload)
658 server->rsize = max_rpc_payload;
659 if (server->rsize > NFS_MAX_FILE_IO_SIZE)
660 server->rsize = NFS_MAX_FILE_IO_SIZE;
661 server->rpages = (server->rsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
662 server->backing_dev_info.ra_pages = server->rpages * NFS_MAX_READAHEAD;
663
664 if (server->wsize > max_rpc_payload)
665 server->wsize = max_rpc_payload;
666 if (server->wsize > NFS_MAX_FILE_IO_SIZE)
667 server->wsize = NFS_MAX_FILE_IO_SIZE;
668 server->wpages = (server->wsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
669 server->wtmult = nfs_block_bits(fsinfo->wtmult, NULL);
670
671 server->dtsize = nfs_block_size(fsinfo->dtpref, NULL);
672 if (server->dtsize > PAGE_CACHE_SIZE)
673 server->dtsize = PAGE_CACHE_SIZE;
674 if (server->dtsize > server->rsize)
675 server->dtsize = server->rsize;
676
677 if (server->flags & NFS_MOUNT_NOAC) {
678 server->acregmin = server->acregmax = 0;
679 server->acdirmin = server->acdirmax = 0;
680 }
681
682 server->maxfilesize = fsinfo->maxfilesize;
683
684 /* We're airborne Set socket buffersize */
685 rpc_setbufsize(server->client, server->wsize + 100, server->rsize + 100);
686}
687
688/*
689 * Probe filesystem information, including the FSID on v2/v3
690 */
691static int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *mntfh, struct nfs_fattr *fattr)
692{
693 struct nfs_fsinfo fsinfo;
694 struct nfs_client *clp = server->nfs_client;
695 int error;
696
697 dprintk("--> nfs_probe_fsinfo()\n");
698
699 if (clp->rpc_ops->set_capabilities != NULL) {
700 error = clp->rpc_ops->set_capabilities(server, mntfh);
701 if (error < 0)
702 goto out_error;
703 }
704
705 fsinfo.fattr = fattr;
706 nfs_fattr_init(fattr);
707 error = clp->rpc_ops->fsinfo(server, mntfh, &fsinfo);
708 if (error < 0)
709 goto out_error;
710
711 nfs_server_set_fsinfo(server, &fsinfo);
712
713 /* Get some general file system info */
714 if (server->namelen == 0) {
715 struct nfs_pathconf pathinfo;
716
717 pathinfo.fattr = fattr;
718 nfs_fattr_init(fattr);
719
720 if (clp->rpc_ops->pathconf(server, mntfh, &pathinfo) >= 0)
721 server->namelen = pathinfo.max_namelen;
722 }
723
724 dprintk("<-- nfs_probe_fsinfo() = 0\n");
725 return 0;
726
727out_error:
728 dprintk("nfs_probe_fsinfo: error = %d\n", -error);
729 return error;
730}
731
732/*
733 * Copy useful information when duplicating a server record
734 */
735static void nfs_server_copy_userdata(struct nfs_server *target, struct nfs_server *source)
736{
737 target->flags = source->flags;
738 target->acregmin = source->acregmin;
739 target->acregmax = source->acregmax;
740 target->acdirmin = source->acdirmin;
741 target->acdirmax = source->acdirmax;
742 target->caps = source->caps;
743}
744
745/*
746 * Allocate and initialise a server record
747 */
748static struct nfs_server *nfs_alloc_server(void)
749{
750 struct nfs_server *server;
751
752 server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL);
753 if (!server)
754 return NULL;
755
756 server->client = server->client_acl = ERR_PTR(-EINVAL);
757
758 /* Zero out the NFS state stuff */
759 INIT_LIST_HEAD(&server->client_link);
760 INIT_LIST_HEAD(&server->master_link);
761
762 server->io_stats = nfs_alloc_iostats();
763 if (!server->io_stats) {
764 kfree(server);
765 return NULL;
766 }
767
768 return server;
769}
770
771/*
772 * Free up a server record
773 */
774void nfs_free_server(struct nfs_server *server)
775{
776 dprintk("--> nfs_free_server()\n");
777
778 spin_lock(&nfs_client_lock);
779 list_del(&server->client_link);
780 list_del(&server->master_link);
781 spin_unlock(&nfs_client_lock);
782
783 if (server->destroy != NULL)
784 server->destroy(server);
785 if (!IS_ERR(server->client))
786 rpc_shutdown_client(server->client);
787
788 nfs_put_client(server->nfs_client);
789
790 nfs_free_iostats(server->io_stats);
791 kfree(server);
792 nfs_release_automount_timer();
793 dprintk("<-- nfs_free_server()\n");
794}
795
796/*
797 * Create a version 2 or 3 volume record
798 * - keyed on server and FSID
799 */
800struct nfs_server *nfs_create_server(const struct nfs_mount_data *data,
801 struct nfs_fh *mntfh)
802{
803 struct nfs_server *server;
804 struct nfs_fattr fattr;
805 int error;
806
807 server = nfs_alloc_server();
808 if (!server)
809 return ERR_PTR(-ENOMEM);
810
811 /* Get a client representation */
812 error = nfs_init_server(server, data);
813 if (error < 0)
814 goto error;
815
816 BUG_ON(!server->nfs_client);
817 BUG_ON(!server->nfs_client->rpc_ops);
818 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
819
820 /* Probe the root fh to retrieve its FSID */
821 error = nfs_probe_fsinfo(server, mntfh, &fattr);
822 if (error < 0)
823 goto error;
824 if (!(fattr.valid & NFS_ATTR_FATTR)) {
825 error = server->nfs_client->rpc_ops->getattr(server, mntfh, &fattr);
826 if (error < 0) {
827 dprintk("nfs_create_server: getattr error = %d\n", -error);
828 goto error;
829 }
830 }
831 memcpy(&server->fsid, &fattr.fsid, sizeof(server->fsid));
832
833 dprintk("Server FSID: %llx:%llx\n", server->fsid.major, server->fsid.minor);
834
835 BUG_ON(!server->nfs_client);
836 BUG_ON(!server->nfs_client->rpc_ops);
837 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
838
839 spin_lock(&nfs_client_lock);
840 list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks);
841 list_add_tail(&server->master_link, &nfs_volume_list);
842 spin_unlock(&nfs_client_lock);
843
844 server->mount_time = jiffies;
845 return server;
846
847error:
848 nfs_free_server(server);
849 return ERR_PTR(error);
850}
851
852#ifdef CONFIG_NFS_V4
853/*
854 * Initialise an NFS4 client record
855 */
856static int nfs4_init_client(struct nfs_client *clp,
857 int proto, int timeo, int retrans,
858 rpc_authflavor_t authflavour)
859{
860 int error;
861
862 if (clp->cl_cons_state == NFS_CS_READY) {
863 /* the client is initialised already */
864 dprintk("<-- nfs4_init_client() = 0 [already %p]\n", clp);
865 return 0;
866 }
867
868 /* Check NFS protocol revision and initialize RPC op vector */
869 clp->rpc_ops = &nfs_v4_clientops;
870
871 error = nfs_create_rpc_client(clp, proto, timeo, retrans, authflavour);
872 if (error < 0)
873 goto error;
874
875 error = nfs_idmap_new(clp);
876 if (error < 0) {
877 dprintk("%s: failed to create idmapper. Error = %d\n",
878 __FUNCTION__, error);
David Howells54ceac42006-08-22 20:06:13 -0400879 goto error;
880 }
Trond Myklebust9c5bf382006-08-22 20:06:14 -0400881 __set_bit(NFS_CS_IDMAP, &clp->cl_res_state);
David Howells54ceac42006-08-22 20:06:13 -0400882
883 nfs_mark_client_ready(clp, NFS_CS_READY);
884 return 0;
885
886error:
887 nfs_mark_client_ready(clp, error);
888 dprintk("<-- nfs4_init_client() = xerror %d\n", error);
889 return error;
890}
891
892/*
893 * Set up an NFS4 client
894 */
895static int nfs4_set_client(struct nfs_server *server,
896 const char *hostname, const struct sockaddr_in *addr,
897 rpc_authflavor_t authflavour,
898 int proto, int timeo, int retrans)
899{
900 struct nfs_client *clp;
901 int error;
902
903 dprintk("--> nfs4_set_client()\n");
904
905 /* Allocate or find a client reference we can use */
906 clp = nfs_get_client(hostname, addr, 4);
907 if (IS_ERR(clp)) {
908 error = PTR_ERR(clp);
909 goto error;
910 }
911 error = nfs4_init_client(clp, proto, timeo, retrans, authflavour);
912 if (error < 0)
913 goto error_put;
914
915 server->nfs_client = clp;
916 dprintk("<-- nfs4_set_client() = 0 [new %p]\n", clp);
917 return 0;
918
919error_put:
920 nfs_put_client(clp);
921error:
922 dprintk("<-- nfs4_set_client() = xerror %d\n", error);
923 return error;
924}
925
926/*
927 * Create a version 4 volume record
928 */
929static int nfs4_init_server(struct nfs_server *server,
930 const struct nfs4_mount_data *data, rpc_authflavor_t authflavour)
931{
932 int error;
933
934 dprintk("--> nfs4_init_server()\n");
935
936 /* Initialise the client representation from the mount data */
937 server->flags = data->flags & NFS_MOUNT_FLAGMASK;
938 server->caps |= NFS_CAP_ATOMIC_OPEN;
939
940 if (data->rsize)
941 server->rsize = nfs_block_size(data->rsize, NULL);
942 if (data->wsize)
943 server->wsize = nfs_block_size(data->wsize, NULL);
944
945 server->acregmin = data->acregmin * HZ;
946 server->acregmax = data->acregmax * HZ;
947 server->acdirmin = data->acdirmin * HZ;
948 server->acdirmax = data->acdirmax * HZ;
949
950 error = nfs_init_server_rpcclient(server, authflavour);
951
952 /* Done */
953 dprintk("<-- nfs4_init_server() = %d\n", error);
954 return error;
955}
956
957/*
958 * Create a version 4 volume record
959 * - keyed on server and FSID
960 */
961struct nfs_server *nfs4_create_server(const struct nfs4_mount_data *data,
962 const char *hostname,
963 const struct sockaddr_in *addr,
964 const char *mntpath,
965 const char *ip_addr,
966 rpc_authflavor_t authflavour,
967 struct nfs_fh *mntfh)
968{
969 struct nfs_fattr fattr;
970 struct nfs_server *server;
971 int error;
972
973 dprintk("--> nfs4_create_server()\n");
974
975 server = nfs_alloc_server();
976 if (!server)
977 return ERR_PTR(-ENOMEM);
978
979 /* Get a client record */
980 error = nfs4_set_client(server, hostname, addr, authflavour,
981 data->proto, data->timeo, data->retrans);
982 if (error < 0)
983 goto error;
984
985 /* set up the general RPC client */
986 error = nfs4_init_server(server, data, authflavour);
987 if (error < 0)
988 goto error;
989
990 BUG_ON(!server->nfs_client);
991 BUG_ON(!server->nfs_client->rpc_ops);
992 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
993
994 /* Probe the root fh to retrieve its FSID */
995 error = nfs4_path_walk(server, mntfh, mntpath);
996 if (error < 0)
997 goto error;
998
999 dprintk("Server FSID: %llx:%llx\n", server->fsid.major, server->fsid.minor);
1000 dprintk("Mount FH: %d\n", mntfh->size);
1001
1002 error = nfs_probe_fsinfo(server, mntfh, &fattr);
1003 if (error < 0)
1004 goto error;
1005
1006 BUG_ON(!server->nfs_client);
1007 BUG_ON(!server->nfs_client->rpc_ops);
1008 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
1009
1010 spin_lock(&nfs_client_lock);
1011 list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks);
1012 list_add_tail(&server->master_link, &nfs_volume_list);
1013 spin_unlock(&nfs_client_lock);
1014
1015 server->mount_time = jiffies;
1016 dprintk("<-- nfs4_create_server() = %p\n", server);
1017 return server;
1018
1019error:
1020 nfs_free_server(server);
1021 dprintk("<-- nfs4_create_server() = error %d\n", error);
1022 return ERR_PTR(error);
1023}
1024
1025/*
1026 * Create an NFS4 referral server record
1027 */
1028struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data,
1029 struct nfs_fh *fh)
1030{
1031 struct nfs_client *parent_client;
1032 struct nfs_server *server, *parent_server;
1033 struct nfs_fattr fattr;
1034 int error;
1035
1036 dprintk("--> nfs4_create_referral_server()\n");
1037
1038 server = nfs_alloc_server();
1039 if (!server)
1040 return ERR_PTR(-ENOMEM);
1041
1042 parent_server = NFS_SB(data->sb);
1043 parent_client = parent_server->nfs_client;
1044
1045 /* Get a client representation.
1046 * Note: NFSv4 always uses TCP, */
1047 error = nfs4_set_client(server, data->hostname, data->addr,
1048 data->authflavor,
1049 parent_server->client->cl_xprt->prot,
1050 parent_client->retrans_timeo,
1051 parent_client->retrans_count);
1052
1053 /* Initialise the client representation from the parent server */
1054 nfs_server_copy_userdata(server, parent_server);
1055 server->caps |= NFS_CAP_ATOMIC_OPEN;
1056
1057 error = nfs_init_server_rpcclient(server, data->authflavor);
1058 if (error < 0)
1059 goto error;
1060
1061 BUG_ON(!server->nfs_client);
1062 BUG_ON(!server->nfs_client->rpc_ops);
1063 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
1064
1065 /* probe the filesystem info for this server filesystem */
1066 error = nfs_probe_fsinfo(server, fh, &fattr);
1067 if (error < 0)
1068 goto error;
1069
1070 dprintk("Referral FSID: %llx:%llx\n",
1071 server->fsid.major, server->fsid.minor);
1072
1073 spin_lock(&nfs_client_lock);
1074 list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks);
1075 list_add_tail(&server->master_link, &nfs_volume_list);
1076 spin_unlock(&nfs_client_lock);
1077
1078 server->mount_time = jiffies;
1079
1080 dprintk("<-- nfs_create_referral_server() = %p\n", server);
1081 return server;
1082
1083error:
1084 nfs_free_server(server);
1085 dprintk("<-- nfs4_create_referral_server() = error %d\n", error);
1086 return ERR_PTR(error);
1087}
1088
1089#endif /* CONFIG_NFS_V4 */
1090
1091/*
1092 * Clone an NFS2, NFS3 or NFS4 server record
1093 */
1094struct nfs_server *nfs_clone_server(struct nfs_server *source,
1095 struct nfs_fh *fh,
1096 struct nfs_fattr *fattr)
1097{
1098 struct nfs_server *server;
1099 struct nfs_fattr fattr_fsinfo;
1100 int error;
1101
1102 dprintk("--> nfs_clone_server(,%llx:%llx,)\n",
1103 fattr->fsid.major, fattr->fsid.minor);
1104
1105 server = nfs_alloc_server();
1106 if (!server)
1107 return ERR_PTR(-ENOMEM);
1108
1109 /* Copy data from the source */
1110 server->nfs_client = source->nfs_client;
1111 atomic_inc(&server->nfs_client->cl_count);
1112 nfs_server_copy_userdata(server, source);
1113
1114 server->fsid = fattr->fsid;
1115
1116 error = nfs_init_server_rpcclient(server, source->client->cl_auth->au_flavor);
1117 if (error < 0)
1118 goto out_free_server;
1119 if (!IS_ERR(source->client_acl))
1120 nfs_init_server_aclclient(server);
1121
1122 /* probe the filesystem info for this server filesystem */
1123 error = nfs_probe_fsinfo(server, fh, &fattr_fsinfo);
1124 if (error < 0)
1125 goto out_free_server;
1126
1127 dprintk("Cloned FSID: %llx:%llx\n",
1128 server->fsid.major, server->fsid.minor);
1129
1130 error = nfs_start_lockd(server);
1131 if (error < 0)
1132 goto out_free_server;
1133
1134 spin_lock(&nfs_client_lock);
1135 list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks);
1136 list_add_tail(&server->master_link, &nfs_volume_list);
1137 spin_unlock(&nfs_client_lock);
1138
1139 server->mount_time = jiffies;
1140
1141 dprintk("<-- nfs_clone_server() = %p\n", server);
1142 return server;
1143
1144out_free_server:
1145 nfs_free_server(server);
1146 dprintk("<-- nfs_clone_server() = error %d\n", error);
1147 return ERR_PTR(error);
1148}
David Howells6aaca562006-08-22 20:06:13 -04001149
1150#ifdef CONFIG_PROC_FS
1151static struct proc_dir_entry *proc_fs_nfs;
1152
1153static int nfs_server_list_open(struct inode *inode, struct file *file);
1154static void *nfs_server_list_start(struct seq_file *p, loff_t *pos);
1155static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos);
1156static void nfs_server_list_stop(struct seq_file *p, void *v);
1157static int nfs_server_list_show(struct seq_file *m, void *v);
1158
1159static struct seq_operations nfs_server_list_ops = {
1160 .start = nfs_server_list_start,
1161 .next = nfs_server_list_next,
1162 .stop = nfs_server_list_stop,
1163 .show = nfs_server_list_show,
1164};
1165
1166static struct file_operations nfs_server_list_fops = {
1167 .open = nfs_server_list_open,
1168 .read = seq_read,
1169 .llseek = seq_lseek,
1170 .release = seq_release,
1171};
1172
1173static int nfs_volume_list_open(struct inode *inode, struct file *file);
1174static void *nfs_volume_list_start(struct seq_file *p, loff_t *pos);
1175static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos);
1176static void nfs_volume_list_stop(struct seq_file *p, void *v);
1177static int nfs_volume_list_show(struct seq_file *m, void *v);
1178
1179static struct seq_operations nfs_volume_list_ops = {
1180 .start = nfs_volume_list_start,
1181 .next = nfs_volume_list_next,
1182 .stop = nfs_volume_list_stop,
1183 .show = nfs_volume_list_show,
1184};
1185
1186static struct file_operations nfs_volume_list_fops = {
1187 .open = nfs_volume_list_open,
1188 .read = seq_read,
1189 .llseek = seq_lseek,
1190 .release = seq_release,
1191};
1192
1193/*
1194 * open "/proc/fs/nfsfs/servers" which provides a summary of servers with which
1195 * we're dealing
1196 */
1197static int nfs_server_list_open(struct inode *inode, struct file *file)
1198{
1199 struct seq_file *m;
1200 int ret;
1201
1202 ret = seq_open(file, &nfs_server_list_ops);
1203 if (ret < 0)
1204 return ret;
1205
1206 m = file->private_data;
1207 m->private = PDE(inode)->data;
1208
1209 return 0;
1210}
1211
1212/*
1213 * set up the iterator to start reading from the server list and return the first item
1214 */
1215static void *nfs_server_list_start(struct seq_file *m, loff_t *_pos)
1216{
1217 struct list_head *_p;
1218 loff_t pos = *_pos;
1219
1220 /* lock the list against modification */
1221 spin_lock(&nfs_client_lock);
1222
1223 /* allow for the header line */
1224 if (!pos)
1225 return SEQ_START_TOKEN;
1226 pos--;
1227
1228 /* find the n'th element in the list */
1229 list_for_each(_p, &nfs_client_list)
1230 if (!pos--)
1231 break;
1232
1233 return _p != &nfs_client_list ? _p : NULL;
1234}
1235
1236/*
1237 * move to next server
1238 */
1239static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos)
1240{
1241 struct list_head *_p;
1242
1243 (*pos)++;
1244
1245 _p = v;
1246 _p = (v == SEQ_START_TOKEN) ? nfs_client_list.next : _p->next;
1247
1248 return _p != &nfs_client_list ? _p : NULL;
1249}
1250
1251/*
1252 * clean up after reading from the transports list
1253 */
1254static void nfs_server_list_stop(struct seq_file *p, void *v)
1255{
1256 spin_unlock(&nfs_client_lock);
1257}
1258
1259/*
1260 * display a header line followed by a load of call lines
1261 */
1262static int nfs_server_list_show(struct seq_file *m, void *v)
1263{
1264 struct nfs_client *clp;
1265
1266 /* display header on line 1 */
1267 if (v == SEQ_START_TOKEN) {
1268 seq_puts(m, "NV SERVER PORT USE HOSTNAME\n");
1269 return 0;
1270 }
1271
1272 /* display one transport per line on subsequent lines */
1273 clp = list_entry(v, struct nfs_client, cl_share_link);
1274
1275 seq_printf(m, "v%d %02x%02x%02x%02x %4hx %3d %s\n",
1276 clp->cl_nfsversion,
1277 NIPQUAD(clp->cl_addr.sin_addr),
1278 ntohs(clp->cl_addr.sin_port),
1279 atomic_read(&clp->cl_count),
1280 clp->cl_hostname);
1281
1282 return 0;
1283}
1284
1285/*
1286 * open "/proc/fs/nfsfs/volumes" which provides a summary of extant volumes
1287 */
1288static int nfs_volume_list_open(struct inode *inode, struct file *file)
1289{
1290 struct seq_file *m;
1291 int ret;
1292
1293 ret = seq_open(file, &nfs_volume_list_ops);
1294 if (ret < 0)
1295 return ret;
1296
1297 m = file->private_data;
1298 m->private = PDE(inode)->data;
1299
1300 return 0;
1301}
1302
1303/*
1304 * set up the iterator to start reading from the volume list and return the first item
1305 */
1306static void *nfs_volume_list_start(struct seq_file *m, loff_t *_pos)
1307{
1308 struct list_head *_p;
1309 loff_t pos = *_pos;
1310
1311 /* lock the list against modification */
1312 spin_lock(&nfs_client_lock);
1313
1314 /* allow for the header line */
1315 if (!pos)
1316 return SEQ_START_TOKEN;
1317 pos--;
1318
1319 /* find the n'th element in the list */
1320 list_for_each(_p, &nfs_volume_list)
1321 if (!pos--)
1322 break;
1323
1324 return _p != &nfs_volume_list ? _p : NULL;
1325}
1326
1327/*
1328 * move to next volume
1329 */
1330static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos)
1331{
1332 struct list_head *_p;
1333
1334 (*pos)++;
1335
1336 _p = v;
1337 _p = (v == SEQ_START_TOKEN) ? nfs_volume_list.next : _p->next;
1338
1339 return _p != &nfs_volume_list ? _p : NULL;
1340}
1341
1342/*
1343 * clean up after reading from the transports list
1344 */
1345static void nfs_volume_list_stop(struct seq_file *p, void *v)
1346{
1347 spin_unlock(&nfs_client_lock);
1348}
1349
1350/*
1351 * display a header line followed by a load of call lines
1352 */
1353static int nfs_volume_list_show(struct seq_file *m, void *v)
1354{
1355 struct nfs_server *server;
1356 struct nfs_client *clp;
1357 char dev[8], fsid[17];
1358
1359 /* display header on line 1 */
1360 if (v == SEQ_START_TOKEN) {
1361 seq_puts(m, "NV SERVER PORT DEV FSID\n");
1362 return 0;
1363 }
1364 /* display one transport per line on subsequent lines */
1365 server = list_entry(v, struct nfs_server, master_link);
1366 clp = server->nfs_client;
1367
1368 snprintf(dev, 8, "%u:%u",
1369 MAJOR(server->s_dev), MINOR(server->s_dev));
1370
1371 snprintf(fsid, 17, "%llx:%llx",
1372 server->fsid.major, server->fsid.minor);
1373
1374 seq_printf(m, "v%d %02x%02x%02x%02x %4hx %-7s %-17s\n",
1375 clp->cl_nfsversion,
1376 NIPQUAD(clp->cl_addr.sin_addr),
1377 ntohs(clp->cl_addr.sin_port),
1378 dev,
1379 fsid);
1380
1381 return 0;
1382}
1383
1384/*
1385 * initialise the /proc/fs/nfsfs/ directory
1386 */
1387int __init nfs_fs_proc_init(void)
1388{
1389 struct proc_dir_entry *p;
1390
1391 proc_fs_nfs = proc_mkdir("nfsfs", proc_root_fs);
1392 if (!proc_fs_nfs)
1393 goto error_0;
1394
1395 proc_fs_nfs->owner = THIS_MODULE;
1396
1397 /* a file of servers with which we're dealing */
1398 p = create_proc_entry("servers", S_IFREG|S_IRUGO, proc_fs_nfs);
1399 if (!p)
1400 goto error_1;
1401
1402 p->proc_fops = &nfs_server_list_fops;
1403 p->owner = THIS_MODULE;
1404
1405 /* a file of volumes that we have mounted */
1406 p = create_proc_entry("volumes", S_IFREG|S_IRUGO, proc_fs_nfs);
1407 if (!p)
1408 goto error_2;
1409
1410 p->proc_fops = &nfs_volume_list_fops;
1411 p->owner = THIS_MODULE;
1412 return 0;
1413
1414error_2:
1415 remove_proc_entry("servers", proc_fs_nfs);
1416error_1:
1417 remove_proc_entry("nfsfs", proc_root_fs);
1418error_0:
1419 return -ENOMEM;
1420}
1421
1422/*
1423 * clean up the /proc/fs/nfsfs/ directory
1424 */
1425void nfs_fs_proc_exit(void)
1426{
1427 remove_proc_entry("volumes", proc_fs_nfs);
1428 remove_proc_entry("servers", proc_fs_nfs);
1429 remove_proc_entry("nfsfs", proc_root_fs);
1430}
1431
1432#endif /* CONFIG_PROC_FS */