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