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