Merge to Fedora kernel-2.6.7-1.492
[linux-2.6.git] / fs / nfs / inode.c
1 /*
2  *  linux/fs/nfs/inode.c
3  *
4  *  Copyright (C) 1992  Rick Sladkey
5  *
6  *  nfs inode and superblock handling functions
7  *
8  *  Modularised by Alan Cox <Alan.Cox@linux.org>, while hacking some
9  *  experimental NFS changes. Modularisation taken straight from SYS5 fs.
10  *
11  *  Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
12  *  J.S.Peatfield@damtp.cam.ac.uk
13  *
14  */
15
16 #include <linux/config.h>
17 #include <linux/module.h>
18 #include <linux/init.h>
19
20 #include <linux/time.h>
21 #include <linux/kernel.h>
22 #include <linux/mm.h>
23 #include <linux/string.h>
24 #include <linux/stat.h>
25 #include <linux/errno.h>
26 #include <linux/unistd.h>
27 #include <linux/sunrpc/clnt.h>
28 #include <linux/sunrpc/stats.h>
29 #include <linux/nfs_fs.h>
30 #include <linux/nfs_mount.h>
31 #include <linux/nfs4_mount.h>
32 #include <linux/lockd/bind.h>
33 #include <linux/smp_lock.h>
34 #include <linux/seq_file.h>
35 #include <linux/mount.h>
36 #include <linux/nfs_idmap.h>
37 #include <linux/vfs.h>
38
39 #include <asm/system.h>
40 #include <asm/uaccess.h>
41
42 #define NFSDBG_FACILITY         NFSDBG_VFS
43 #define NFS_PARANOIA 1
44
45 /* Maximum number of readahead requests
46  * FIXME: this should really be a sysctl so that users may tune it to suit
47  *        their needs. People that do NFS over a slow network, might for
48  *        instance want to reduce it to something closer to 1 for improved
49  *        interactive response.
50  */
51 #define NFS_MAX_READAHEAD       (RPC_DEF_SLOT_TABLE - 1)
52
53 static void nfs_invalidate_inode(struct inode *);
54 static int nfs_update_inode(struct inode *, struct nfs_fattr *, unsigned long);
55
56 static struct inode *nfs_alloc_inode(struct super_block *sb);
57 static void nfs_destroy_inode(struct inode *);
58 static void nfs_write_inode(struct inode *,int);
59 static void nfs_delete_inode(struct inode *);
60 static void nfs_put_super(struct super_block *);
61 static void nfs_clear_inode(struct inode *);
62 static void nfs_umount_begin(struct super_block *);
63 static int  nfs_statfs(struct super_block *, struct kstatfs *);
64 static int  nfs_show_options(struct seq_file *, struct vfsmount *);
65
66 static struct super_operations nfs_sops = { 
67         .alloc_inode    = nfs_alloc_inode,
68         .destroy_inode  = nfs_destroy_inode,
69         .write_inode    = nfs_write_inode,
70         .delete_inode   = nfs_delete_inode,
71         .put_super      = nfs_put_super,
72         .statfs         = nfs_statfs,
73         .clear_inode    = nfs_clear_inode,
74         .umount_begin   = nfs_umount_begin,
75         .show_options   = nfs_show_options,
76 };
77
78 /*
79  * RPC cruft for NFS
80  */
81 struct rpc_stat                 nfs_rpcstat = {
82         .program                = &nfs_program
83 };
84 static struct rpc_version *     nfs_version[] = {
85         NULL,
86         NULL,
87         &nfs_version2,
88 #if defined(CONFIG_NFS_V3)
89         &nfs_version3,
90 #elif defined(CONFIG_NFS_V4)
91         NULL,
92 #endif
93 #if defined(CONFIG_NFS_V4)
94         &nfs_version4,
95 #endif
96 };
97
98 struct rpc_program              nfs_program = {
99         .name                   = "nfs",
100         .number                 = NFS_PROGRAM,
101         .nrvers                 = sizeof(nfs_version) / sizeof(nfs_version[0]),
102         .version                = nfs_version,
103         .stats                  = &nfs_rpcstat,
104         .pipe_dir_name          = "/nfs",
105 };
106
107 static inline unsigned long
108 nfs_fattr_to_ino_t(struct nfs_fattr *fattr)
109 {
110         return nfs_fileid_to_ino_t(fattr->fileid);
111 }
112
113 static void
114 nfs_write_inode(struct inode *inode, int sync)
115 {
116         int flags = sync ? FLUSH_WAIT : 0;
117
118         nfs_commit_inode(inode, 0, 0, flags);
119 }
120
121 static void
122 nfs_delete_inode(struct inode * inode)
123 {
124         dprintk("NFS: delete_inode(%s/%ld)\n", inode->i_sb->s_id, inode->i_ino);
125
126         /*
127          * The following can never actually happen...
128          */
129         if (nfs_have_writebacks(inode)) {
130                 printk(KERN_ERR "nfs_delete_inode: inode %ld has pending RPC requests\n", inode->i_ino);
131         }
132
133         clear_inode(inode);
134 }
135
136 /*
137  * For the moment, the only task for the NFS clear_inode method is to
138  * release the mmap credential
139  */
140 static void
141 nfs_clear_inode(struct inode *inode)
142 {
143         struct nfs_inode *nfsi = NFS_I(inode);
144         struct rpc_cred *cred = nfsi->mm_cred;
145
146         if (cred)
147                 put_rpccred(cred);
148         cred = nfsi->cache_access.cred;
149         if (cred)
150                 put_rpccred(cred);
151         BUG_ON(atomic_read(&nfsi->data_updates) != 0);
152 }
153
154 void
155 nfs_put_super(struct super_block *sb)
156 {
157         struct nfs_server *server = NFS_SB(sb);
158
159         nfs4_renewd_prepare_shutdown(server);
160
161         if (server->client != NULL)
162                 rpc_shutdown_client(server->client);
163         if (server->client_sys != NULL)
164                 rpc_shutdown_client(server->client_sys);
165
166         if (!(server->flags & NFS_MOUNT_NONLM))
167                 lockd_down();   /* release rpc.lockd */
168         rpciod_down();          /* release rpciod */
169
170         destroy_nfsv4_state(server);
171
172         kfree(server->hostname);
173 }
174
175 void
176 nfs_umount_begin(struct super_block *sb)
177 {
178         struct nfs_server *server = NFS_SB(sb);
179         struct rpc_clnt *rpc;
180
181         /* -EIO all pending I/O */
182         if ((rpc = server->client) != NULL)
183                 rpc_killall_tasks(rpc);
184 }
185
186
187 static inline unsigned long
188 nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
189 {
190         /* make sure blocksize is a power of two */
191         if ((bsize & (bsize - 1)) || nrbitsp) {
192                 unsigned char   nrbits;
193
194                 for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
195                         ;
196                 bsize = 1 << nrbits;
197                 if (nrbitsp)
198                         *nrbitsp = nrbits;
199         }
200
201         return bsize;
202 }
203
204 /*
205  * Calculate the number of 512byte blocks used.
206  */
207 static inline unsigned long
208 nfs_calc_block_size(u64 tsize)
209 {
210         loff_t used = (tsize + 511) >> 9;
211         return (used > ULONG_MAX) ? ULONG_MAX : used;
212 }
213
214 /*
215  * Compute and set NFS server blocksize
216  */
217 static inline unsigned long
218 nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
219 {
220         if (bsize < 1024)
221                 bsize = NFS_DEF_FILE_IO_BUFFER_SIZE;
222         else if (bsize >= NFS_MAX_FILE_IO_BUFFER_SIZE)
223                 bsize = NFS_MAX_FILE_IO_BUFFER_SIZE;
224
225         return nfs_block_bits(bsize, nrbitsp);
226 }
227
228 /*
229  * Obtain the root inode of the file system.
230  */
231 static struct inode *
232 nfs_get_root(struct super_block *sb, struct nfs_fh *rootfh, struct nfs_fsinfo *fsinfo)
233 {
234         struct nfs_server       *server = NFS_SB(sb);
235         struct inode *rooti;
236         int                     error;
237
238         error = server->rpc_ops->getroot(server, rootfh, fsinfo);
239         if (error < 0) {
240                 dprintk("nfs_get_root: getattr error = %d\n", -error);
241                 return ERR_PTR(error);
242         }
243
244         rooti = nfs_fhget(sb, rootfh, fsinfo->fattr);
245         if (!rooti)
246                 return ERR_PTR(-ENOMEM);
247         return rooti;
248 }
249
250 /*
251  * Do NFS version-independent mount processing, and sanity checking
252  */
253 static int
254 nfs_sb_init(struct super_block *sb, rpc_authflavor_t authflavor)
255 {
256         struct nfs_server       *server;
257         struct inode            *root_inode;
258         struct nfs_fattr        fattr;
259         struct nfs_fsinfo       fsinfo = {
260                                         .fattr = &fattr,
261                                 };
262         struct nfs_pathconf pathinfo = {
263                         .fattr = &fattr,
264         };
265         int no_root_error = 0;
266
267         /* We probably want something more informative here */
268         snprintf(sb->s_id, sizeof(sb->s_id), "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
269
270         server = NFS_SB(sb);
271
272         sb->s_magic      = NFS_SUPER_MAGIC;
273
274         root_inode = nfs_get_root(sb, &server->fh, &fsinfo);
275         /* Did getting the root inode fail? */
276         if (IS_ERR(root_inode)) {
277                 no_root_error = PTR_ERR(root_inode);
278                 goto out_no_root;
279         }
280         sb->s_root = d_alloc_root(root_inode);
281         if (!sb->s_root) {
282                 no_root_error = -ENOMEM;
283                 goto out_no_root;
284         }
285         sb->s_root->d_op = server->rpc_ops->dentry_ops;
286
287         /* Get some general file system info */
288         if (server->namelen == 0 &&
289             server->rpc_ops->pathconf(server, &server->fh, &pathinfo) >= 0)
290                 server->namelen = pathinfo.max_namelen;
291         /* Work out a lot of parameters */
292         if (server->rsize == 0)
293                 server->rsize = nfs_block_size(fsinfo.rtpref, NULL);
294         if (server->wsize == 0)
295                 server->wsize = nfs_block_size(fsinfo.wtpref, NULL);
296         if (sb->s_blocksize == 0) {
297                 if (fsinfo.wtmult == 0) {
298                         sb->s_blocksize = 512;
299                         sb->s_blocksize_bits = 9;
300                 } else
301                         sb->s_blocksize = nfs_block_bits(fsinfo.wtmult,
302                                                          &sb->s_blocksize_bits);
303         }
304
305         if (fsinfo.rtmax >= 512 && server->rsize > fsinfo.rtmax)
306                 server->rsize = nfs_block_size(fsinfo.rtmax, NULL);
307         if (fsinfo.wtmax >= 512 && server->wsize > fsinfo.wtmax)
308                 server->wsize = nfs_block_size(fsinfo.wtmax, NULL);
309
310         server->rpages = (server->rsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
311         if (server->rpages > NFS_READ_MAXIOV) {
312                 server->rpages = NFS_READ_MAXIOV;
313                 server->rsize = server->rpages << PAGE_CACHE_SHIFT;
314         }
315
316         server->wpages = (server->wsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
317         if (server->wpages > NFS_WRITE_MAXIOV) {
318                 server->wpages = NFS_WRITE_MAXIOV;
319                 server->wsize = server->wpages << PAGE_CACHE_SHIFT;
320         }
321
322         server->dtsize = nfs_block_size(fsinfo.dtpref, NULL);
323         if (server->dtsize > PAGE_CACHE_SIZE)
324                 server->dtsize = PAGE_CACHE_SIZE;
325         if (server->dtsize > server->rsize)
326                 server->dtsize = server->rsize;
327
328         if (server->flags & NFS_MOUNT_NOAC) {
329                 server->acregmin = server->acregmax = 0;
330                 server->acdirmin = server->acdirmax = 0;
331                 sb->s_flags |= MS_SYNCHRONOUS;
332         }
333         server->backing_dev_info.ra_pages = server->rpages * NFS_MAX_READAHEAD;
334
335         sb->s_maxbytes = fsinfo.maxfilesize;
336         if (sb->s_maxbytes > MAX_LFS_FILESIZE) 
337                 sb->s_maxbytes = MAX_LFS_FILESIZE; 
338
339         /* We're airborne Set socket buffersize */
340         rpc_setbufsize(server->client, server->wsize + 100, server->rsize + 100);
341         return 0;
342         /* Yargs. It didn't work out. */
343 out_no_root:
344         dprintk("nfs_sb_init: get root inode failed: errno %d\n", -no_root_error);
345         if (!IS_ERR(root_inode))
346                 iput(root_inode);
347         return no_root_error;
348 }
349
350 /*
351  * Create an RPC client handle.
352  */
353 static struct rpc_clnt *
354 nfs_create_client(struct nfs_server *server, const struct nfs_mount_data *data)
355 {
356         struct rpc_timeout      timeparms;
357         struct rpc_xprt         *xprt = NULL;
358         struct rpc_clnt         *clnt = NULL;
359         int                     tcp   = (data->flags & NFS_MOUNT_TCP);
360
361         /* Initialize timeout values */
362         timeparms.to_initval = data->timeo * HZ / 10;
363         timeparms.to_retries = data->retrans;
364         timeparms.to_maxval  = tcp ? RPC_MAX_TCP_TIMEOUT : RPC_MAX_UDP_TIMEOUT;
365         timeparms.to_exponential = 1;
366
367         if (!timeparms.to_initval)
368                 timeparms.to_initval = (tcp ? 600 : 11) * HZ / 10;
369         if (!timeparms.to_retries)
370                 timeparms.to_retries = 5;
371
372         /* create transport and client */
373         xprt = xprt_create_proto(tcp ? IPPROTO_TCP : IPPROTO_UDP,
374                                  &server->addr, &timeparms);
375         if (IS_ERR(xprt)) {
376                 printk(KERN_WARNING "NFS: cannot create RPC transport.\n");
377                 return (struct rpc_clnt *)xprt;
378         }
379         clnt = rpc_create_client(xprt, server->hostname, &nfs_program,
380                                  server->rpc_ops->version, data->pseudoflavor);
381         if (IS_ERR(clnt)) {
382                 printk(KERN_WARNING "NFS: cannot create RPC client.\n");
383                 goto out_fail;
384         }
385
386         clnt->cl_intr     = (server->flags & NFS_MOUNT_INTR) ? 1 : 0;
387         clnt->cl_softrtry = (server->flags & NFS_MOUNT_SOFT) ? 1 : 0;
388         clnt->cl_droppriv = (server->flags & NFS_MOUNT_BROKEN_SUID) ? 1 : 0;
389         clnt->cl_chatty   = 1;
390
391         return clnt;
392
393 out_fail:
394         xprt_destroy(xprt);
395         return clnt;
396 }
397
398 /*
399  * The way this works is that the mount process passes a structure
400  * in the data argument which contains the server's IP address
401  * and the root file handle obtained from the server's mount
402  * daemon. We stash these away in the private superblock fields.
403  */
404 static int
405 nfs_fill_super(struct super_block *sb, struct nfs_mount_data *data, int silent)
406 {
407         struct nfs_server       *server;
408         int                     err = -EIO;
409         rpc_authflavor_t        authflavor;
410
411         server           = NFS_SB(sb);
412         sb->s_blocksize_bits = 0;
413         sb->s_blocksize = 0;
414         if (data->bsize)
415                 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
416         if (data->rsize)
417                 server->rsize = nfs_block_size(data->rsize, NULL);
418         if (data->wsize)
419                 server->wsize = nfs_block_size(data->wsize, NULL);
420         server->flags    = data->flags & NFS_MOUNT_FLAGMASK;
421
422         server->acregmin = data->acregmin*HZ;
423         server->acregmax = data->acregmax*HZ;
424         server->acdirmin = data->acdirmin*HZ;
425         server->acdirmax = data->acdirmax*HZ;
426
427         server->namelen  = data->namlen;
428         server->hostname = kmalloc(strlen(data->hostname) + 1, GFP_KERNEL);
429         if (!server->hostname)
430                 goto out_fail;
431         strcpy(server->hostname, data->hostname);
432
433         /* Check NFS protocol revision and initialize RPC op vector
434          * and file handle pool. */
435         if (server->flags & NFS_MOUNT_VER3) {
436 #ifdef CONFIG_NFS_V3
437                 server->rpc_ops = &nfs_v3_clientops;
438                 server->caps |= NFS_CAP_READDIRPLUS;
439                 if (data->version < 4) {
440                         printk(KERN_NOTICE "NFS: NFSv3 not supported by mount program.\n");
441                         goto out_fail;
442                 }
443 #else
444                 printk(KERN_NOTICE "NFS: NFSv3 not supported.\n");
445                 goto out_fail;
446 #endif
447         } else {
448                 server->rpc_ops = &nfs_v2_clientops;
449         }
450
451         /* Fill in pseudoflavor for mount version < 5 */
452         if (!(data->flags & NFS_MOUNT_SECFLAVOUR))
453                 data->pseudoflavor = RPC_AUTH_UNIX;
454         authflavor = data->pseudoflavor;        /* save for sb_init() */
455         /* XXX maybe we want to add a server->pseudoflavor field */
456
457         /* Create RPC client handles */
458         server->client = nfs_create_client(server, data);
459         if (IS_ERR(server->client))
460                 goto out_fail;
461         /* RFC 2623, sec 2.3.2 */
462         if (authflavor != RPC_AUTH_UNIX) {
463                 server->client_sys = rpc_clone_client(server->client);
464                 if (server->client_sys == NULL)
465                         goto out_shutdown;
466                 if (!rpcauth_create(RPC_AUTH_UNIX, server->client_sys))
467                         goto out_shutdown;
468         } else {
469                 atomic_inc(&server->client->cl_count);
470                 server->client_sys = server->client;
471         }
472
473         /* Fire up rpciod if not yet running */
474         if (rpciod_up() != 0) {
475                 printk(KERN_WARNING "NFS: couldn't start rpciod!\n");
476                 goto out_shutdown;
477         }
478
479         sb->s_op = &nfs_sops;
480         err = nfs_sb_init(sb, authflavor);
481         if (err != 0)
482                 goto out_noinit;
483
484         if (server->flags & NFS_MOUNT_VER3) {
485                 if (server->namelen == 0 || server->namelen > NFS3_MAXNAMLEN)
486                         server->namelen = NFS3_MAXNAMLEN;
487         } else {
488                 if (server->namelen == 0 || server->namelen > NFS2_MAXNAMLEN)
489                         server->namelen = NFS2_MAXNAMLEN;
490         }
491
492         /* Check whether to start the lockd process */
493         if (!(server->flags & NFS_MOUNT_NONLM))
494                 lockd_up();
495         return 0;
496 out_noinit:
497         rpciod_down();
498 out_shutdown:
499         if (server->client)
500                 rpc_shutdown_client(server->client);
501         if (server->client_sys)
502                 rpc_shutdown_client(server->client_sys);
503 out_fail:
504         if (server->hostname)
505                 kfree(server->hostname);
506         return err;
507 }
508
509 static int
510 nfs_statfs(struct super_block *sb, struct kstatfs *buf)
511 {
512         struct nfs_server *server = NFS_SB(sb);
513         unsigned char blockbits;
514         unsigned long blockres;
515         struct nfs_fh *rootfh = NFS_FH(sb->s_root->d_inode);
516         struct nfs_fattr fattr;
517         struct nfs_fsstat res = {
518                         .fattr = &fattr,
519         };
520         int error;
521
522         lock_kernel();
523
524         error = server->rpc_ops->statfs(server, rootfh, &res);
525         buf->f_type = NFS_SUPER_MAGIC;
526         if (error < 0)
527                 goto out_err;
528
529         buf->f_bsize = sb->s_blocksize;
530         blockbits = sb->s_blocksize_bits;
531         blockres = (1 << blockbits) - 1;
532         buf->f_blocks = (res.tbytes + blockres) >> blockbits;
533         buf->f_bfree = (res.fbytes + blockres) >> blockbits;
534         buf->f_bavail = (res.abytes + blockres) >> blockbits;
535         buf->f_files = res.tfiles;
536         buf->f_ffree = res.afiles;
537
538         buf->f_namelen = server->namelen;
539  out:
540         unlock_kernel();
541
542         return 0;
543
544  out_err:
545         printk(KERN_WARNING "nfs_statfs: statfs error = %d\n", -error);
546         buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1;
547         goto out;
548
549 }
550
551 static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
552 {
553         static struct proc_nfs_info {
554                 int flag;
555                 char *str;
556                 char *nostr;
557         } nfs_info[] = {
558                 { NFS_MOUNT_SOFT, ",soft", ",hard" },
559                 { NFS_MOUNT_INTR, ",intr", "" },
560                 { NFS_MOUNT_POSIX, ",posix", "" },
561                 { NFS_MOUNT_TCP, ",tcp", ",udp" },
562                 { NFS_MOUNT_NOCTO, ",nocto", "" },
563                 { NFS_MOUNT_NOAC, ",noac", "" },
564                 { NFS_MOUNT_NONLM, ",nolock", ",lock" },
565                 { NFS_MOUNT_BROKEN_SUID, ",broken_suid", "" },
566                 { 0, NULL, NULL }
567         };
568         struct proc_nfs_info *nfs_infop;
569         struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
570
571         seq_printf(m, ",v%d", nfss->rpc_ops->version);
572         seq_printf(m, ",rsize=%d", nfss->rsize);
573         seq_printf(m, ",wsize=%d", nfss->wsize);
574         if (nfss->acregmin != 3*HZ)
575                 seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
576         if (nfss->acregmax != 60*HZ)
577                 seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
578         if (nfss->acdirmin != 30*HZ)
579                 seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ);
580         if (nfss->acdirmax != 60*HZ)
581                 seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ);
582         for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
583                 if (nfss->flags & nfs_infop->flag)
584                         seq_puts(m, nfs_infop->str);
585                 else
586                         seq_puts(m, nfs_infop->nostr);
587         }
588         seq_puts(m, ",addr=");
589         seq_escape(m, nfss->hostname, " \t\n\\");
590         return 0;
591 }
592
593 /*
594  * Invalidate the local caches
595  */
596 void
597 nfs_zap_caches(struct inode *inode)
598 {
599         struct nfs_inode *nfsi = NFS_I(inode);
600         int mode = inode->i_mode;
601
602         NFS_ATTRTIMEO(inode) = NFS_MINATTRTIMEO(inode);
603         NFS_ATTRTIMEO_UPDATE(inode) = jiffies;
604
605         memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
606         if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
607                 nfsi->flags |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA;
608         else
609                 nfsi->flags |= NFS_INO_INVALID_ATTR;
610 }
611
612 /*
613  * Invalidate, but do not unhash, the inode
614  */
615 static void
616 nfs_invalidate_inode(struct inode *inode)
617 {
618         umode_t save_mode = inode->i_mode;
619
620         make_bad_inode(inode);
621         inode->i_mode = save_mode;
622         nfs_zap_caches(inode);
623 }
624
625 struct nfs_find_desc {
626         struct nfs_fh           *fh;
627         struct nfs_fattr        *fattr;
628 };
629
630 /*
631  * In NFSv3 we can have 64bit inode numbers. In order to support
632  * this, and re-exported directories (also seen in NFSv2)
633  * we are forced to allow 2 different inodes to have the same
634  * i_ino.
635  */
636 static int
637 nfs_find_actor(struct inode *inode, void *opaque)
638 {
639         struct nfs_find_desc    *desc = (struct nfs_find_desc *)opaque;
640         struct nfs_fh           *fh = desc->fh;
641         struct nfs_fattr        *fattr = desc->fattr;
642
643         if (NFS_FILEID(inode) != fattr->fileid)
644                 return 0;
645         if (memcmp(NFS_FH(inode), fh, sizeof(struct nfs_fh)) != 0)
646                 return 0;
647         if (is_bad_inode(inode))
648                 return 0;
649         return 1;
650 }
651
652 static int
653 nfs_init_locked(struct inode *inode, void *opaque)
654 {
655         struct nfs_find_desc    *desc = (struct nfs_find_desc *)opaque;
656         struct nfs_fh           *fh = desc->fh;
657         struct nfs_fattr        *fattr = desc->fattr;
658
659         NFS_FILEID(inode) = fattr->fileid;
660         memcpy(NFS_FH(inode), fh, sizeof(struct nfs_fh));
661         return 0;
662 }
663
664 /* Don't use READDIRPLUS on directories that we believe are too large */
665 #define NFS_LIMIT_READDIRPLUS (8*PAGE_SIZE)
666
667 /*
668  * This is our front-end to iget that looks up inodes by file handle
669  * instead of inode number.
670  */
671 struct inode *
672 nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
673 {
674         struct nfs_find_desc desc = {
675                 .fh     = fh,
676                 .fattr  = fattr
677         };
678         struct inode *inode = NULL;
679         unsigned long hash;
680
681         if ((fattr->valid & NFS_ATTR_FATTR) == 0)
682                 goto out_no_inode;
683
684         if (!fattr->nlink) {
685                 printk("NFS: Buggy server - nlink == 0!\n");
686                 goto out_no_inode;
687         }
688
689         hash = nfs_fattr_to_ino_t(fattr);
690
691         if (!(inode = iget5_locked(sb, hash, nfs_find_actor, nfs_init_locked, &desc)))
692                 goto out_no_inode;
693
694         if (inode->i_state & I_NEW) {
695                 struct nfs_inode *nfsi = NFS_I(inode);
696
697                 /* We set i_ino for the few things that still rely on it,
698                  * such as stat(2) */
699                 inode->i_ino = hash;
700
701                 /* We can't support update_atime(), since the server will reset it */
702                 inode->i_flags |= S_NOATIME|S_NOCMTIME;
703                 inode->i_mode = fattr->mode;
704                 /* Why so? Because we want revalidate for devices/FIFOs, and
705                  * that's precisely what we have in nfs_file_inode_operations.
706                  */
707                 inode->i_op = &nfs_file_inode_operations;
708                 if (S_ISREG(inode->i_mode)) {
709                         inode->i_fop = &nfs_file_operations;
710                         inode->i_data.a_ops = &nfs_file_aops;
711                         inode->i_data.backing_dev_info = &NFS_SB(sb)->backing_dev_info;
712                 } else if (S_ISDIR(inode->i_mode)) {
713                         inode->i_op = NFS_SB(sb)->rpc_ops->dir_inode_ops;
714                         inode->i_fop = &nfs_dir_operations;
715                         if (nfs_server_capable(inode, NFS_CAP_READDIRPLUS)
716                             && fattr->size <= NFS_LIMIT_READDIRPLUS)
717                                 NFS_FLAGS(inode) |= NFS_INO_ADVISE_RDPLUS;
718                 } else if (S_ISLNK(inode->i_mode))
719                         inode->i_op = &nfs_symlink_inode_operations;
720                 else
721                         init_special_inode(inode, inode->i_mode, fattr->rdev);
722
723                 nfsi->read_cache_jiffies = fattr->timestamp;
724                 inode->i_atime = fattr->atime;
725                 inode->i_mtime = fattr->mtime;
726                 inode->i_ctime = fattr->ctime;
727                 if (fattr->valid & NFS_ATTR_FATTR_V4)
728                         nfsi->change_attr = fattr->change_attr;
729                 inode->i_size = nfs_size_to_loff_t(fattr->size);
730                 inode->i_nlink = fattr->nlink;
731                 inode->i_uid = fattr->uid;
732                 inode->i_gid = fattr->gid;
733                 if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
734                         /*
735                          * report the blocks in 512byte units
736                          */
737                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
738                         inode->i_blksize = inode->i_sb->s_blocksize;
739                 } else {
740                         inode->i_blocks = fattr->du.nfs2.blocks;
741                         inode->i_blksize = fattr->du.nfs2.blocksize;
742                 }
743                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
744                 nfsi->attrtimeo_timestamp = jiffies;
745                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
746                 nfsi->cache_access.cred = NULL;
747
748                 unlock_new_inode(inode);
749         } else
750                 nfs_refresh_inode(inode, fattr);
751         dprintk("NFS: nfs_fhget(%s/%Ld ct=%d)\n",
752                 inode->i_sb->s_id,
753                 (long long)NFS_FILEID(inode),
754                 atomic_read(&inode->i_count));
755
756 out:
757         return inode;
758
759 out_no_inode:
760         printk("nfs_fhget: iget failed\n");
761         goto out;
762 }
763
764 #define NFS_VALID_ATTRS (ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_SIZE|ATTR_ATIME|ATTR_ATIME_SET|ATTR_MTIME|ATTR_MTIME_SET)
765
766 int
767 nfs_setattr(struct dentry *dentry, struct iattr *attr)
768 {
769         struct inode *inode = dentry->d_inode;
770         struct nfs_fattr fattr;
771         int error;
772
773         if (attr->ia_valid & ATTR_SIZE) {
774                 if (!S_ISREG(inode->i_mode) || attr->ia_size == i_size_read(inode))
775                         attr->ia_valid &= ~ATTR_SIZE;
776         }
777
778         /* Optimization: if the end result is no change, don't RPC */
779         attr->ia_valid &= NFS_VALID_ATTRS;
780         if (attr->ia_valid == 0)
781                 return 0;
782
783         lock_kernel();
784         nfs_begin_data_update(inode);
785         /* Write all dirty data if we're changing file permissions or size */
786         if ((attr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_SIZE)) != 0) {
787                 if (filemap_fdatawrite(inode->i_mapping) == 0)
788                         filemap_fdatawait(inode->i_mapping);
789                 nfs_wb_all(inode);
790         }
791         error = NFS_PROTO(inode)->setattr(dentry, &fattr, attr);
792         if (error == 0) {
793                 nfs_refresh_inode(inode, &fattr);
794                 if ((attr->ia_valid & ATTR_MODE) != 0) {
795                         int mode;
796                         mode = inode->i_mode & ~S_IALLUGO;
797                         mode |= attr->ia_mode & S_IALLUGO;
798                         inode->i_mode = mode;
799                 }
800                 if ((attr->ia_valid & ATTR_UID) != 0)
801                         inode->i_uid = attr->ia_uid;
802                 if ((attr->ia_valid & ATTR_GID) != 0)
803                         inode->i_gid = attr->ia_gid;
804                 if ((attr->ia_valid & ATTR_SIZE) != 0) {
805                         inode->i_size = attr->ia_size;
806                         vmtruncate(inode, attr->ia_size);
807                 }
808         }
809         if ((attr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0) {
810                 struct rpc_cred **cred = &NFS_I(inode)->cache_access.cred;
811                 if (*cred) {
812                         put_rpccred(*cred);
813                         *cred = NULL;
814                 }
815         }
816         nfs_end_data_update(inode);
817         unlock_kernel();
818         return error;
819 }
820
821 /*
822  * Wait for the inode to get unlocked.
823  * (Used for NFS_INO_LOCKED and NFS_INO_REVALIDATING).
824  */
825 int
826 nfs_wait_on_inode(struct inode *inode, int flag)
827 {
828         struct rpc_clnt *clnt = NFS_CLIENT(inode);
829         struct nfs_inode *nfsi = NFS_I(inode);
830
831         int error;
832         if (!(NFS_FLAGS(inode) & flag))
833                 return 0;
834         atomic_inc(&inode->i_count);
835         error = nfs_wait_event(clnt, nfsi->nfs_i_wait,
836                                 !(NFS_FLAGS(inode) & flag));
837         iput(inode);
838         return error;
839 }
840
841 int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
842 {
843         struct inode *inode = dentry->d_inode;
844         struct nfs_inode *nfsi = NFS_I(inode);
845         int need_atime = nfsi->flags & NFS_INO_INVALID_ATIME;
846         int err;
847
848         if (__IS_FLG(inode, MS_NOATIME))
849                 need_atime = 0;
850         else if (__IS_FLG(inode, MS_NODIRATIME) && S_ISDIR(inode->i_mode))
851                 need_atime = 0;
852         /* We may force a getattr if the user cares about atime */
853         if (need_atime)
854                 err = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
855         else
856                 err = nfs_revalidate_inode(NFS_SERVER(inode), inode);
857         if (!err)
858                 generic_fillattr(inode, stat);
859         return err;
860 }
861
862 /*
863  * Ensure that mmap has a recent RPC credential for use when writing out
864  * shared pages
865  */
866 void
867 nfs_set_mmcred(struct inode *inode, struct rpc_cred *cred)
868 {
869         struct rpc_cred **p = &NFS_I(inode)->mm_cred,
870                         *oldcred = *p;
871
872         *p = get_rpccred(cred);
873         if (oldcred)
874                 put_rpccred(oldcred);
875 }
876
877 /*
878  * These are probably going to contain hooks for
879  * allocating and releasing RPC credentials for
880  * the file. I'll have to think about Tronds patch
881  * a bit more..
882  */
883 int nfs_open(struct inode *inode, struct file *filp)
884 {
885         struct rpc_auth *auth;
886         struct rpc_cred *cred;
887
888         auth = NFS_CLIENT(inode)->cl_auth;
889         cred = rpcauth_lookupcred(auth, 0);
890         filp->private_data = cred;
891         if ((filp->f_mode & FMODE_WRITE) != 0) {
892                 nfs_set_mmcred(inode, cred);
893                 nfs_begin_data_update(inode);
894         }
895         return 0;
896 }
897
898 int nfs_release(struct inode *inode, struct file *filp)
899 {
900         struct rpc_cred *cred;
901
902         lock_kernel();
903         if ((filp->f_mode & FMODE_WRITE) != 0)
904                 nfs_end_data_update(inode);
905         cred = nfs_file_cred(filp);
906         if (cred)
907                 put_rpccred(cred);
908         unlock_kernel();
909         return 0;
910 }
911
912 /*
913  * This function is called whenever some part of NFS notices that
914  * the cached attributes have to be refreshed.
915  */
916 int
917 __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
918 {
919         int              status = -ESTALE;
920         struct nfs_fattr fattr;
921         struct nfs_inode *nfsi = NFS_I(inode);
922         unsigned long verifier;
923         unsigned int flags;
924
925         dfprintk(PAGECACHE, "NFS: revalidating (%s/%Ld)\n",
926                 inode->i_sb->s_id, (long long)NFS_FILEID(inode));
927
928         lock_kernel();
929         if (!inode || is_bad_inode(inode))
930                 goto out_nowait;
931         if (NFS_STALE(inode) && inode != inode->i_sb->s_root->d_inode)
932                 goto out_nowait;
933
934         while (NFS_REVALIDATING(inode)) {
935                 status = nfs_wait_on_inode(inode, NFS_INO_REVALIDATING);
936                 if (status < 0)
937                         goto out_nowait;
938                 if (NFS_SERVER(inode)->flags & NFS_MOUNT_NOAC)
939                         continue;
940                 if (NFS_FLAGS(inode) & (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ATIME))
941                         continue;
942                 status = NFS_STALE(inode) ? -ESTALE : 0;
943                 goto out_nowait;
944         }
945         NFS_FLAGS(inode) |= NFS_INO_REVALIDATING;
946
947         /* Protect against RPC races by saving the change attribute */
948         verifier = nfs_save_change_attribute(inode);
949         status = NFS_PROTO(inode)->getattr(inode, &fattr);
950         if (status) {
951                 dfprintk(PAGECACHE, "nfs_revalidate_inode: (%s/%Ld) getattr failed, error=%d\n",
952                          inode->i_sb->s_id,
953                          (long long)NFS_FILEID(inode), status);
954                 if (status == -ESTALE) {
955                         NFS_FLAGS(inode) |= NFS_INO_STALE;
956                         if (inode != inode->i_sb->s_root->d_inode)
957                                 remove_inode_hash(inode);
958                 }
959                 goto out;
960         }
961
962         status = nfs_update_inode(inode, &fattr, verifier);
963         if (status) {
964                 dfprintk(PAGECACHE, "nfs_revalidate_inode: (%s/%Ld) refresh failed, error=%d\n",
965                          inode->i_sb->s_id,
966                          (long long)NFS_FILEID(inode), status);
967                 goto out;
968         }
969         flags = nfsi->flags;
970         /*
971          * We may need to keep the attributes marked as invalid if
972          * we raced with nfs_end_attr_update().
973          */
974         if (verifier == nfsi->cache_change_attribute)
975                 nfsi->flags &= ~(NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ATIME);
976         /* Do the page cache invalidation */
977         if (flags & NFS_INO_INVALID_DATA) {
978                 if (S_ISREG(inode->i_mode)) {
979                         if (filemap_fdatawrite(inode->i_mapping) == 0)
980                                 filemap_fdatawait(inode->i_mapping);
981                         nfs_wb_all(inode);
982                 }
983                 nfsi->flags &= ~NFS_INO_INVALID_DATA;
984                 invalidate_inode_pages2(inode->i_mapping);
985                 memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
986                 dfprintk(PAGECACHE, "NFS: (%s/%Ld) data cache invalidated\n",
987                                 inode->i_sb->s_id,
988                                 (long long)NFS_FILEID(inode));
989                 /* This ensures we revalidate dentries */
990                 nfsi->cache_change_attribute++;
991         }
992         dfprintk(PAGECACHE, "NFS: (%s/%Ld) revalidation complete\n",
993                 inode->i_sb->s_id,
994                 (long long)NFS_FILEID(inode));
995
996         NFS_FLAGS(inode) &= ~NFS_INO_STALE;
997 out:
998         NFS_FLAGS(inode) &= ~NFS_INO_REVALIDATING;
999         wake_up(&nfsi->nfs_i_wait);
1000  out_nowait:
1001         unlock_kernel();
1002         return status;
1003 }
1004
1005 /**
1006  * nfs_begin_data_update
1007  * @inode - pointer to inode
1008  * Declare that a set of operations will update file data on the server
1009  */
1010 void nfs_begin_data_update(struct inode *inode)
1011 {
1012         atomic_inc(&NFS_I(inode)->data_updates);
1013 }
1014
1015 /**
1016  * nfs_end_data_update
1017  * @inode - pointer to inode
1018  * Declare end of the operations that will update file data
1019  * This will mark the inode as immediately needing revalidation
1020  * of its attribute cache.
1021  */
1022 void nfs_end_data_update(struct inode *inode)
1023 {
1024         struct nfs_inode *nfsi = NFS_I(inode);
1025
1026         /* Mark the attribute cache for revalidation */
1027         nfsi->flags |= NFS_INO_INVALID_ATTR;
1028         /* Directories and symlinks: invalidate page cache too */
1029         if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode))
1030                 nfsi->flags |= NFS_INO_INVALID_DATA;
1031         nfsi->cache_change_attribute ++;
1032         atomic_dec(&nfsi->data_updates);
1033 }
1034
1035 /**
1036  * nfs_end_data_update_defer
1037  * @inode - pointer to inode
1038  * Declare end of the operations that will update file data
1039  * This will defer marking the inode as needing revalidation
1040  * unless there are no other pending updates.
1041  */
1042 void nfs_end_data_update_defer(struct inode *inode)
1043 {
1044         struct nfs_inode *nfsi = NFS_I(inode);
1045
1046         if (atomic_dec_and_test(&nfsi->data_updates)) {
1047                 /* Mark the attribute cache for revalidation */
1048                 nfsi->flags |= NFS_INO_INVALID_ATTR;
1049                 /* Directories and symlinks: invalidate page cache too */
1050                 if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode))
1051                         nfsi->flags |= NFS_INO_INVALID_DATA;
1052                 nfsi->cache_change_attribute ++;
1053         }
1054 }
1055
1056 /**
1057  * nfs_refresh_inode - verify consistency of the inode attribute cache
1058  * @inode - pointer to inode
1059  * @fattr - updated attributes
1060  *
1061  * Verifies the attribute cache. If we have just changed the attributes,
1062  * so that fattr carries weak cache consistency data, then it may
1063  * also update the ctime/mtime/change_attribute.
1064  */
1065 int nfs_refresh_inode(struct inode *inode, struct nfs_fattr *fattr)
1066 {
1067         struct nfs_inode *nfsi = NFS_I(inode);
1068         loff_t cur_size, new_isize;
1069         int data_unstable;
1070
1071         /* Are we in the process of updating data on the server? */
1072         data_unstable = nfs_caches_unstable(inode);
1073
1074         if (fattr->valid & NFS_ATTR_FATTR_V4) {
1075                 if ((fattr->valid & NFS_ATTR_PRE_CHANGE) != 0
1076                                 && nfsi->change_attr == fattr->pre_change_attr)
1077                         nfsi->change_attr = fattr->change_attr;
1078                 if (!data_unstable && nfsi->change_attr != fattr->change_attr)
1079                         nfsi->flags |= NFS_INO_INVALID_ATTR;
1080         }
1081
1082         if ((fattr->valid & NFS_ATTR_FATTR) == 0)
1083                 return 0;
1084
1085         /* Has the inode gone and changed behind our back? */
1086         if (nfsi->fileid != fattr->fileid
1087                         || (inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT))
1088                 return -EIO;
1089
1090         cur_size = i_size_read(inode);
1091         new_isize = nfs_size_to_loff_t(fattr->size);
1092
1093         /* If we have atomic WCC data, we may update some attributes */
1094         if ((fattr->valid & NFS_ATTR_WCC) != 0) {
1095                 if (timespec_equal(&inode->i_ctime, &fattr->pre_ctime))
1096                         memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime));
1097                 if (timespec_equal(&inode->i_mtime, &fattr->pre_mtime))
1098                         memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime));
1099         }
1100
1101         /* Verify a few of the more important attributes */
1102         if (!data_unstable) {
1103                 if (!timespec_equal(&inode->i_mtime, &fattr->mtime)
1104                                 || cur_size != new_isize)
1105                         nfsi->flags |= NFS_INO_INVALID_ATTR;
1106         } else if (S_ISREG(inode->i_mode) && new_isize > cur_size)
1107                         nfsi->flags |= NFS_INO_INVALID_ATTR;
1108
1109         /* Have any file permissions changed? */
1110         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)
1111                         || inode->i_uid != fattr->uid
1112                         || inode->i_gid != fattr->gid)
1113                 nfsi->flags |= NFS_INO_INVALID_ATTR;
1114
1115         /* Has the link count changed? */
1116         if (inode->i_nlink != fattr->nlink)
1117                 nfsi->flags |= NFS_INO_INVALID_ATTR;
1118
1119         if (!timespec_equal(&inode->i_atime, &fattr->atime))
1120                 nfsi->flags |= NFS_INO_INVALID_ATIME;
1121
1122         nfsi->read_cache_jiffies = fattr->timestamp;
1123         return 0;
1124 }
1125
1126 /*
1127  * Many nfs protocol calls return the new file attributes after
1128  * an operation.  Here we update the inode to reflect the state
1129  * of the server's inode.
1130  *
1131  * This is a bit tricky because we have to make sure all dirty pages
1132  * have been sent off to the server before calling invalidate_inode_pages.
1133  * To make sure no other process adds more write requests while we try
1134  * our best to flush them, we make them sleep during the attribute refresh.
1135  *
1136  * A very similar scenario holds for the dir cache.
1137  */
1138 static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr, unsigned long verifier)
1139 {
1140         struct nfs_inode *nfsi = NFS_I(inode);
1141         __u64           new_size;
1142         loff_t          new_isize;
1143         unsigned int    invalid = 0;
1144         loff_t          cur_isize;
1145         int data_unstable;
1146
1147         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
1148                         __FUNCTION__, inode->i_sb->s_id, inode->i_ino,
1149                         atomic_read(&inode->i_count), fattr->valid);
1150
1151         if ((fattr->valid & NFS_ATTR_FATTR) == 0)
1152                 return 0;
1153
1154         if (nfsi->fileid != fattr->fileid) {
1155                 printk(KERN_ERR "%s: inode number mismatch\n"
1156                        "expected (%s/0x%Lx), got (%s/0x%Lx)\n",
1157                        __FUNCTION__,
1158                        inode->i_sb->s_id, (long long)nfsi->fileid,
1159                        inode->i_sb->s_id, (long long)fattr->fileid);
1160                 goto out_err;
1161         }
1162
1163         /*
1164          * Make sure the inode's type hasn't changed.
1165          */
1166         if ((inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT))
1167                 goto out_changed;
1168
1169         /*
1170          * Update the read time so we don't revalidate too often.
1171          */
1172         nfsi->read_cache_jiffies = fattr->timestamp;
1173
1174         /* Are we racing with known updates of the metadata on the server? */
1175         data_unstable = ! nfs_verify_change_attribute(inode, verifier);
1176
1177         /* Check if the file size agrees */
1178         new_size = fattr->size;
1179         new_isize = nfs_size_to_loff_t(fattr->size);
1180         cur_isize = i_size_read(inode);
1181         if (cur_isize != new_size) {
1182 #ifdef NFS_DEBUG_VERBOSE
1183                 printk(KERN_DEBUG "NFS: isize change on %s/%ld\n", inode->i_sb->s_id, inode->i_ino);
1184 #endif
1185                 /*
1186                  * If we have pending writebacks, things can get
1187                  * messy.
1188                  */
1189                 if (S_ISREG(inode->i_mode) && data_unstable) {
1190                         if (new_isize > cur_isize) {
1191                                 inode->i_size = new_isize;
1192                                 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA;
1193                         }
1194                 } else {
1195                         inode->i_size = new_isize;
1196                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA;
1197                 }
1198         }
1199
1200         /*
1201          * Note: we don't check inode->i_mtime since pipes etc.
1202          *       can change this value in VFS without requiring a
1203          *       cache revalidation.
1204          */
1205         if (!timespec_equal(&inode->i_mtime, &fattr->mtime)) {
1206                 memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime));
1207 #ifdef NFS_DEBUG_VERBOSE
1208                 printk(KERN_DEBUG "NFS: mtime change on %s/%ld\n", inode->i_sb->s_id, inode->i_ino);
1209 #endif
1210                 if (!data_unstable)
1211                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA;
1212         }
1213
1214         if ((fattr->valid & NFS_ATTR_FATTR_V4)
1215             && nfsi->change_attr != fattr->change_attr) {
1216 #ifdef NFS_DEBUG_VERBOSE
1217                 printk(KERN_DEBUG "NFS: change_attr change on %s/%ld\n",
1218                        inode->i_sb->s_id, inode->i_ino);
1219 #endif
1220                 nfsi->change_attr = fattr->change_attr;
1221                 if (!data_unstable)
1222                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA;
1223         }
1224
1225         memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime));
1226         memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
1227
1228         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO) ||
1229             inode->i_uid != fattr->uid ||
1230             inode->i_gid != fattr->gid) {
1231                 struct rpc_cred **cred = &NFS_I(inode)->cache_access.cred;
1232                 if (*cred) {
1233                         put_rpccred(*cred);
1234                         *cred = NULL;
1235                 }
1236                 invalid |= NFS_INO_INVALID_ATTR;
1237         }
1238
1239         inode->i_mode = fattr->mode;
1240         inode->i_nlink = fattr->nlink;
1241         inode->i_uid = fattr->uid;
1242         inode->i_gid = fattr->gid;
1243
1244         if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
1245                 /*
1246                  * report the blocks in 512byte units
1247                  */
1248                 inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
1249                 inode->i_blksize = inode->i_sb->s_blocksize;
1250         } else {
1251                 inode->i_blocks = fattr->du.nfs2.blocks;
1252                 inode->i_blksize = fattr->du.nfs2.blocksize;
1253         }
1254
1255         /* Update attrtimeo value if we're out of the unstable period */
1256         if (invalid & NFS_INO_INVALID_ATTR) {
1257                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
1258                 nfsi->attrtimeo_timestamp = jiffies;
1259         } else if (time_after(jiffies, nfsi->attrtimeo_timestamp+nfsi->attrtimeo)) {
1260                 if ((nfsi->attrtimeo <<= 1) > NFS_MAXATTRTIMEO(inode))
1261                         nfsi->attrtimeo = NFS_MAXATTRTIMEO(inode);
1262                 nfsi->attrtimeo_timestamp = jiffies;
1263         }
1264         /* Don't invalidate the data if we were to blame */
1265         if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode)
1266                                 || S_ISLNK(inode->i_mode)))
1267                 invalid &= ~NFS_INO_INVALID_DATA;
1268         nfsi->flags |= invalid;
1269
1270         return 0;
1271  out_changed:
1272         /*
1273          * Big trouble! The inode has become a different object.
1274          */
1275 #ifdef NFS_PARANOIA
1276         printk(KERN_DEBUG "%s: inode %ld mode changed, %07o to %07o\n",
1277                         __FUNCTION__, inode->i_ino, inode->i_mode, fattr->mode);
1278 #endif
1279         /*
1280          * No need to worry about unhashing the dentry, as the
1281          * lookup validation will know that the inode is bad.
1282          * (But we fall through to invalidate the caches.)
1283          */
1284         nfs_invalidate_inode(inode);
1285  out_err:
1286         return -EIO;
1287 }
1288
1289 /*
1290  * File system information
1291  */
1292
1293 static int nfs_set_super(struct super_block *s, void *data)
1294 {
1295         s->s_fs_info = data;
1296         return set_anon_super(s, data);
1297 }
1298  
1299 static int nfs_compare_super(struct super_block *sb, void *data)
1300 {
1301         struct nfs_server *server = data;
1302         struct nfs_server *old = NFS_SB(sb);
1303
1304         if (old->addr.sin_addr.s_addr != server->addr.sin_addr.s_addr)
1305                 return 0;
1306         if (old->addr.sin_port != server->addr.sin_port)
1307                 return 0;
1308         return !memcmp(&old->fh, &server->fh, sizeof(struct nfs_fh));
1309 }
1310
1311 static struct super_block *nfs_get_sb(struct file_system_type *fs_type,
1312         int flags, const char *dev_name, void *raw_data)
1313 {
1314         int error;
1315         struct nfs_server *server;
1316         struct super_block *s;
1317         struct nfs_fh *root;
1318         struct nfs_mount_data *data = raw_data;
1319
1320         if (!data) {
1321                 printk("nfs_read_super: missing data argument\n");
1322                 return ERR_PTR(-EINVAL);
1323         }
1324
1325         server = kmalloc(sizeof(struct nfs_server), GFP_KERNEL);
1326         if (!server)
1327                 return ERR_PTR(-ENOMEM);
1328         memset(server, 0, sizeof(struct nfs_server));
1329         /* Zero out the NFS state stuff */
1330         init_nfsv4_state(server);
1331
1332         root = &server->fh;
1333         memcpy(root, &data->root, sizeof(*root));
1334         if (root->size < sizeof(root->data))
1335                 memset(root->data+root->size, 0, sizeof(root->data)-root->size);
1336
1337         if (data->version != NFS_MOUNT_VERSION) {
1338                 printk("nfs warning: mount version %s than kernel\n",
1339                         data->version < NFS_MOUNT_VERSION ? "older" : "newer");
1340                 if (data->version < 2)
1341                         data->namlen = 0;
1342                 if (data->version < 3)
1343                         data->bsize  = 0;
1344                 if (data->version < 4) {
1345                         data->flags &= ~NFS_MOUNT_VER3;
1346                         memset(root, 0, sizeof(*root));
1347                         root->size = NFS2_FHSIZE;
1348                         memcpy(root->data, data->old_root.data, NFS2_FHSIZE);
1349                 }
1350                 if (data->version < 5)
1351                         data->flags &= ~NFS_MOUNT_SECFLAVOUR;
1352         }
1353
1354         if (root->size > sizeof(root->data)) {
1355                 printk("nfs_get_sb: invalid root filehandle\n");
1356                 kfree(server);
1357                 return ERR_PTR(-EINVAL);
1358         }
1359         /* We now require that the mount process passes the remote address */
1360         memcpy(&server->addr, &data->addr, sizeof(server->addr));
1361         if (server->addr.sin_addr.s_addr == INADDR_ANY) {
1362                 printk("NFS: mount program didn't pass remote address!\n");
1363                 kfree(server);
1364                 return ERR_PTR(-EINVAL);
1365         }
1366
1367         s = sget(fs_type, nfs_compare_super, nfs_set_super, server);
1368
1369         if (IS_ERR(s) || s->s_root) {
1370                 kfree(server);
1371                 return s;
1372         }
1373
1374         s->s_flags = flags;
1375
1376         error = nfs_fill_super(s, data, flags & MS_VERBOSE ? 1 : 0);
1377         if (error) {
1378                 up_write(&s->s_umount);
1379                 deactivate_super(s);
1380                 return ERR_PTR(error);
1381         }
1382         s->s_flags |= MS_ACTIVE;
1383         return s;
1384 }
1385
1386 static void nfs_kill_super(struct super_block *s)
1387 {
1388         struct nfs_server *server = NFS_SB(s);
1389         kill_anon_super(s);
1390         kfree(server);
1391 }
1392
1393 static struct file_system_type nfs_fs_type = {
1394         .owner          = THIS_MODULE,
1395         .name           = "nfs",
1396         .get_sb         = nfs_get_sb,
1397         .kill_sb        = nfs_kill_super,
1398         .fs_flags       = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
1399 };
1400
1401 #ifdef CONFIG_NFS_V4
1402
1403 static void nfs4_clear_inode(struct inode *);
1404
1405 static struct super_operations nfs4_sops = { 
1406         .alloc_inode    = nfs_alloc_inode,
1407         .destroy_inode  = nfs_destroy_inode,
1408         .write_inode    = nfs_write_inode,
1409         .delete_inode   = nfs_delete_inode,
1410         .put_super      = nfs_put_super,
1411         .statfs         = nfs_statfs,
1412         .clear_inode    = nfs4_clear_inode,
1413         .umount_begin   = nfs_umount_begin,
1414         .show_options   = nfs_show_options,
1415 };
1416
1417 /*
1418  * Clean out any remaining NFSv4 state that might be left over due
1419  * to open() calls that passed nfs_atomic_lookup, but failed to call
1420  * nfs_open().
1421  */
1422 static void nfs4_clear_inode(struct inode *inode)
1423 {
1424         struct nfs_inode *nfsi = NFS_I(inode);
1425
1426         while (!list_empty(&nfsi->open_states)) {
1427                 struct nfs4_state *state;
1428                 
1429                 state = list_entry(nfsi->open_states.next,
1430                                 struct nfs4_state,
1431                                 inode_states);
1432                 dprintk("%s(%s/%Ld): found unclaimed NFSv4 state %p\n",
1433                                 __FUNCTION__,
1434                                 inode->i_sb->s_id,
1435                                 (long long)NFS_FILEID(inode),
1436                                 state);
1437                 BUG_ON(atomic_read(&state->count) != 1);
1438                 nfs4_close_state(state, state->state);
1439         }
1440         /* Now call standard NFS clear_inode() code */
1441         nfs_clear_inode(inode);
1442 }
1443
1444
1445 static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data, int silent)
1446 {
1447         struct nfs_server *server;
1448         struct nfs4_client *clp = NULL;
1449         struct rpc_xprt *xprt = NULL;
1450         struct rpc_clnt *clnt = NULL;
1451         struct rpc_timeout timeparms;
1452         rpc_authflavor_t authflavour;
1453         int proto, err = -EIO;
1454
1455         sb->s_blocksize_bits = 0;
1456         sb->s_blocksize = 0;
1457         server = NFS_SB(sb);
1458         if (data->rsize != 0)
1459                 server->rsize = nfs_block_size(data->rsize, NULL);
1460         if (data->wsize != 0)
1461                 server->wsize = nfs_block_size(data->wsize, NULL);
1462         server->flags = data->flags & NFS_MOUNT_FLAGMASK;
1463
1464         /* NFSv4 doesn't use NLM locking */
1465         server->flags |= NFS_MOUNT_NONLM;
1466
1467         server->acregmin = data->acregmin*HZ;
1468         server->acregmax = data->acregmax*HZ;
1469         server->acdirmin = data->acdirmin*HZ;
1470         server->acdirmax = data->acdirmax*HZ;
1471
1472         server->rpc_ops = &nfs_v4_clientops;
1473         /* Initialize timeout values */
1474
1475         timeparms.to_initval = data->timeo * HZ / 10;
1476         timeparms.to_retries = data->retrans;
1477         timeparms.to_exponential = 1;
1478         if (!timeparms.to_retries)
1479                 timeparms.to_retries = 5;
1480
1481         proto = data->proto;
1482         /* Which IP protocol do we use? */
1483         switch (proto) {
1484         case IPPROTO_TCP:
1485                 timeparms.to_maxval  = RPC_MAX_TCP_TIMEOUT;
1486                 if (!timeparms.to_initval)
1487                         timeparms.to_initval = 600 * HZ / 10;
1488                 break;
1489         case IPPROTO_UDP:
1490                 timeparms.to_maxval  = RPC_MAX_UDP_TIMEOUT;
1491                 if (!timeparms.to_initval)
1492                         timeparms.to_initval = 11 * HZ / 10;
1493                 break;
1494         default:
1495                 return -EINVAL;
1496         }
1497
1498         clp = nfs4_get_client(&server->addr.sin_addr);
1499         if (!clp) {
1500                 printk(KERN_WARNING "NFS: failed to create NFS4 client.\n");
1501                 goto out_fail;
1502         }
1503
1504         /* Now create transport and client */
1505         authflavour = RPC_AUTH_UNIX;
1506         if (data->auth_flavourlen != 0) {
1507                 if (data->auth_flavourlen > 1)
1508                         printk(KERN_INFO "NFS: cannot yet deal with multiple auth flavours.\n");
1509                 if (copy_from_user(&authflavour, data->auth_flavours, sizeof(authflavour))) {
1510                         err = -EFAULT;
1511                         goto out_fail;
1512                 }
1513         }
1514
1515         down_write(&clp->cl_sem);
1516         if (clp->cl_rpcclient == NULL) {
1517                 xprt = xprt_create_proto(proto, &server->addr, &timeparms);
1518                 if (IS_ERR(xprt)) {
1519                         up_write(&clp->cl_sem);
1520                         printk(KERN_WARNING "NFS: cannot create RPC transport.\n");
1521                         err = PTR_ERR(xprt);
1522                         goto out_fail;
1523                 }
1524                 clnt = rpc_create_client(xprt, server->hostname, &nfs_program,
1525                                 server->rpc_ops->version, authflavour);
1526                 if (IS_ERR(clnt)) {
1527                         up_write(&clp->cl_sem);
1528                         printk(KERN_WARNING "NFS: cannot create RPC client.\n");
1529                         xprt_destroy(xprt);
1530                         err = PTR_ERR(clnt);
1531                         goto out_fail;
1532                 }
1533                 clnt->cl_chatty   = 1;
1534                 clp->cl_rpcclient = clnt;
1535                 clp->cl_cred = rpcauth_lookupcred(clnt->cl_auth, 0);
1536                 memcpy(clp->cl_ipaddr, server->ip_addr, sizeof(clp->cl_ipaddr));
1537                 nfs_idmap_new(clp);
1538         }
1539         if (list_empty(&clp->cl_superblocks))
1540                 clear_bit(NFS4CLNT_OK, &clp->cl_state);
1541         list_add_tail(&server->nfs4_siblings, &clp->cl_superblocks);
1542         clnt = rpc_clone_client(clp->cl_rpcclient);
1543         if (!IS_ERR(clnt))
1544                         server->nfs4_state = clp;
1545         up_write(&clp->cl_sem);
1546         clp = NULL;
1547
1548         if (IS_ERR(clnt)) {
1549                 printk(KERN_WARNING "NFS: cannot create RPC client.\n");
1550                 err = PTR_ERR(clnt);
1551                 goto out_remove_list;
1552         }
1553
1554         clnt->cl_intr     = (server->flags & NFS4_MOUNT_INTR) ? 1 : 0;
1555         clnt->cl_softrtry = (server->flags & NFS4_MOUNT_SOFT) ? 1 : 0;
1556         server->client    = clnt;
1557
1558         err = -ENOMEM;
1559         if (server->nfs4_state->cl_idmap == NULL) {
1560                 printk(KERN_WARNING "NFS: failed to create idmapper.\n");
1561                 goto out_shutdown;
1562         }
1563
1564         if (clnt->cl_auth->au_flavor != authflavour) {
1565                 if (rpcauth_create(authflavour, clnt) == NULL) {
1566                         printk(KERN_WARNING "NFS: couldn't create credcache!\n");
1567                         goto out_shutdown;
1568                 }
1569         }
1570
1571         /* Fire up rpciod if not yet running */
1572         if (rpciod_up() != 0) {
1573                 printk(KERN_WARNING "NFS: couldn't start rpciod!\n");
1574                 goto out_shutdown;
1575         }
1576
1577         sb->s_op = &nfs4_sops;
1578         err = nfs_sb_init(sb, authflavour);
1579         if (err == 0)
1580                 return 0;
1581         rpciod_down();
1582 out_shutdown:
1583         rpc_shutdown_client(server->client);
1584 out_remove_list:
1585         down_write(&server->nfs4_state->cl_sem);
1586         list_del_init(&server->nfs4_siblings);
1587         up_write(&server->nfs4_state->cl_sem);
1588         destroy_nfsv4_state(server);
1589 out_fail:
1590         if (clp)
1591                 nfs4_put_client(clp);
1592         return err;
1593 }
1594
1595 static int nfs4_compare_super(struct super_block *sb, void *data)
1596 {
1597         struct nfs_server *server = data;
1598         struct nfs_server *old = NFS_SB(sb);
1599
1600         if (strcmp(server->hostname, old->hostname) != 0)
1601                 return 0;
1602         if (strcmp(server->mnt_path, old->mnt_path) != 0)
1603                 return 0;
1604         return 1;
1605 }
1606
1607 static void *
1608 nfs_copy_user_string(char *dst, struct nfs_string *src, int maxlen)
1609 {
1610         void *p = NULL;
1611
1612         if (!src->len)
1613                 return ERR_PTR(-EINVAL);
1614         if (src->len < maxlen)
1615                 maxlen = src->len;
1616         if (dst == NULL) {
1617                 p = dst = kmalloc(maxlen + 1, GFP_KERNEL);
1618                 if (p == NULL)
1619                         return ERR_PTR(-ENOMEM);
1620         }
1621         if (copy_from_user(dst, src->data, maxlen)) {
1622                 if (p != NULL)
1623                         kfree(p);
1624                 return ERR_PTR(-EFAULT);
1625         }
1626         dst[maxlen] = '\0';
1627         return dst;
1628 }
1629
1630 static struct super_block *nfs4_get_sb(struct file_system_type *fs_type,
1631         int flags, const char *dev_name, void *raw_data)
1632 {
1633         int error;
1634         struct nfs_server *server;
1635         struct super_block *s;
1636         struct nfs4_mount_data *data = raw_data;
1637         void *p;
1638
1639         if (!data) {
1640                 printk("nfs_read_super: missing data argument\n");
1641                 return ERR_PTR(-EINVAL);
1642         }
1643
1644         server = kmalloc(sizeof(struct nfs_server), GFP_KERNEL);
1645         if (!server)
1646                 return ERR_PTR(-ENOMEM);
1647         memset(server, 0, sizeof(struct nfs_server));
1648         /* Zero out the NFS state stuff */
1649         init_nfsv4_state(server);
1650
1651         if (data->version != NFS4_MOUNT_VERSION) {
1652                 printk("nfs warning: mount version %s than kernel\n",
1653                         data->version < NFS4_MOUNT_VERSION ? "older" : "newer");
1654         }
1655
1656         p = nfs_copy_user_string(NULL, &data->hostname, 256);
1657         if (IS_ERR(p))
1658                 goto out_err;
1659         server->hostname = p;
1660
1661         p = nfs_copy_user_string(NULL, &data->mnt_path, 1024);
1662         if (IS_ERR(p))
1663                 goto out_err;
1664         server->mnt_path = p;
1665
1666         p = nfs_copy_user_string(server->ip_addr, &data->client_addr,
1667                         sizeof(server->ip_addr) - 1);
1668         if (IS_ERR(p))
1669                 goto out_err;
1670
1671         /* We now require that the mount process passes the remote address */
1672         if (data->host_addrlen != sizeof(server->addr)) {
1673                 s = ERR_PTR(-EINVAL);
1674                 goto out_free;
1675         }
1676         if (copy_from_user(&server->addr, data->host_addr, sizeof(server->addr))) {
1677                 s = ERR_PTR(-EFAULT);
1678                 goto out_free;
1679         }
1680         if (server->addr.sin_family != AF_INET ||
1681             server->addr.sin_addr.s_addr == INADDR_ANY) {
1682                 printk("NFS: mount program didn't pass remote IP address!\n");
1683                 s = ERR_PTR(-EINVAL);
1684                 goto out_free;
1685         }
1686
1687         s = sget(fs_type, nfs4_compare_super, nfs_set_super, server);
1688
1689         if (IS_ERR(s) || s->s_root)
1690                 goto out_free;
1691
1692         s->s_flags = flags;
1693
1694         error = nfs4_fill_super(s, data, flags & MS_VERBOSE ? 1 : 0);
1695         if (error) {
1696                 up_write(&s->s_umount);
1697                 deactivate_super(s);
1698                 return ERR_PTR(error);
1699         }
1700         s->s_flags |= MS_ACTIVE;
1701         return s;
1702 out_err:
1703         s = (struct super_block *)p;
1704 out_free:
1705         if (server->mnt_path)
1706                 kfree(server->mnt_path);
1707         if (server->hostname)
1708                 kfree(server->hostname);
1709         kfree(server);
1710         return s;
1711 }
1712
1713 static struct file_system_type nfs4_fs_type = {
1714         .owner          = THIS_MODULE,
1715         .name           = "nfs4",
1716         .get_sb         = nfs4_get_sb,
1717         .kill_sb        = nfs_kill_super,
1718         .fs_flags       = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
1719 };
1720
1721 #define nfs4_zero_state(nfsi) \
1722         do { \
1723                 INIT_LIST_HEAD(&(nfsi)->open_states); \
1724         } while(0)
1725 #define register_nfs4fs() register_filesystem(&nfs4_fs_type)
1726 #define unregister_nfs4fs() unregister_filesystem(&nfs4_fs_type)
1727 #else
1728 #define nfs4_zero_state(nfsi) \
1729         do { } while (0)
1730 #define register_nfs4fs() (0)
1731 #define unregister_nfs4fs()
1732 #endif
1733
1734 extern int nfs_init_nfspagecache(void);
1735 extern void nfs_destroy_nfspagecache(void);
1736 extern int nfs_init_readpagecache(void);
1737 extern int nfs_destroy_readpagecache(void);
1738 extern int nfs_init_writepagecache(void);
1739 extern int nfs_destroy_writepagecache(void);
1740
1741 static kmem_cache_t * nfs_inode_cachep;
1742
1743 static struct inode *nfs_alloc_inode(struct super_block *sb)
1744 {
1745         struct nfs_inode *nfsi;
1746         nfsi = (struct nfs_inode *)kmem_cache_alloc(nfs_inode_cachep, SLAB_KERNEL);
1747         if (!nfsi)
1748                 return NULL;
1749         nfsi->flags = 0;
1750         nfsi->mm_cred = NULL;
1751         nfs4_zero_state(nfsi);
1752         return &nfsi->vfs_inode;
1753 }
1754
1755 static void nfs_destroy_inode(struct inode *inode)
1756 {
1757         kmem_cache_free(nfs_inode_cachep, NFS_I(inode));
1758 }
1759
1760 static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
1761 {
1762         struct nfs_inode *nfsi = (struct nfs_inode *) foo;
1763
1764         if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
1765             SLAB_CTOR_CONSTRUCTOR) {
1766                 inode_init_once(&nfsi->vfs_inode);
1767                 INIT_LIST_HEAD(&nfsi->dirty);
1768                 INIT_LIST_HEAD(&nfsi->commit);
1769                 INIT_RADIX_TREE(&nfsi->nfs_page_tree, GFP_ATOMIC);
1770                 atomic_set(&nfsi->data_updates, 0);
1771                 nfsi->ndirty = 0;
1772                 nfsi->ncommit = 0;
1773                 nfsi->npages = 0;
1774                 init_waitqueue_head(&nfsi->nfs_i_wait);
1775         }
1776 }
1777  
1778 int nfs_init_inodecache(void)
1779 {
1780         nfs_inode_cachep = kmem_cache_create("nfs_inode_cache",
1781                                              sizeof(struct nfs_inode),
1782                                              0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
1783                                              init_once, NULL);
1784         if (nfs_inode_cachep == NULL)
1785                 return -ENOMEM;
1786
1787         return 0;
1788 }
1789
1790 void nfs_destroy_inodecache(void)
1791 {
1792         if (kmem_cache_destroy(nfs_inode_cachep))
1793                 printk(KERN_INFO "nfs_inode_cache: not all structures were freed\n");
1794 }
1795
1796 /*
1797  * Initialize NFS
1798  */
1799 static int __init init_nfs_fs(void)
1800 {
1801         int err;
1802
1803         err = nfs_init_nfspagecache();
1804         if (err)
1805                 goto out4;
1806
1807         err = nfs_init_inodecache();
1808         if (err)
1809                 goto out3;
1810
1811         err = nfs_init_readpagecache();
1812         if (err)
1813                 goto out2;
1814
1815         err = nfs_init_writepagecache();
1816         if (err)
1817                 goto out1;
1818
1819 #ifdef CONFIG_PROC_FS
1820         rpc_proc_register(&nfs_rpcstat);
1821 #endif
1822         err = register_filesystem(&nfs_fs_type);
1823         if (err)
1824                 goto out;
1825         if ((err = register_nfs4fs()) != 0)
1826                 goto out;
1827         return 0;
1828 out:
1829         rpc_proc_unregister("nfs");
1830         nfs_destroy_writepagecache();
1831 out1:
1832         nfs_destroy_readpagecache();
1833 out2:
1834         nfs_destroy_inodecache();
1835 out3:
1836         nfs_destroy_nfspagecache();
1837 out4:
1838         return err;
1839 }
1840
1841 static void __exit exit_nfs_fs(void)
1842 {
1843         nfs_destroy_writepagecache();
1844         nfs_destroy_readpagecache();
1845         nfs_destroy_inodecache();
1846         nfs_destroy_nfspagecache();
1847 #ifdef CONFIG_PROC_FS
1848         rpc_proc_unregister("nfs");
1849 #endif
1850         unregister_filesystem(&nfs_fs_type);
1851         unregister_nfs4fs();
1852 }
1853
1854 /* Not quite true; I just maintain it */
1855 MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
1856 MODULE_LICENSE("GPL");
1857
1858 module_init(init_nfs_fs)
1859 module_exit(exit_nfs_fs)