Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[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/module.h>
17 #include <linux/init.h>
18
19 #include <linux/time.h>
20 #include <linux/kernel.h>
21 #include <linux/mm.h>
22 #include <linux/string.h>
23 #include <linux/stat.h>
24 #include <linux/errno.h>
25 #include <linux/unistd.h>
26 #include <linux/sunrpc/clnt.h>
27 #include <linux/sunrpc/stats.h>
28 #include <linux/sunrpc/metrics.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 #include <linux/inet.h>
39 #include <linux/nfs_xdr.h>
40 #include <linux/vserver/xid.h>
41
42 #include <asm/system.h>
43 #include <asm/uaccess.h>
44
45 #include "nfs4_fs.h"
46 #include "callback.h"
47 #include "delegation.h"
48 #include "iostat.h"
49 #include "internal.h"
50
51 #define NFSDBG_FACILITY         NFSDBG_VFS
52 #define NFS_PARANOIA 1
53
54 static void nfs_invalidate_inode(struct inode *);
55 static int nfs_update_inode(struct inode *, struct nfs_fattr *);
56
57 static void nfs_zap_acl_cache(struct inode *);
58
59 static kmem_cache_t * nfs_inode_cachep;
60
61 int nfs_write_inode(struct inode *inode, int sync)
62 {
63         int flags = sync ? FLUSH_SYNC : 0;
64         int ret;
65
66         ret = nfs_commit_inode(inode, flags);
67         if (ret < 0)
68                 return ret;
69         return 0;
70 }
71
72 void nfs_clear_inode(struct inode *inode)
73 {
74         struct nfs_inode *nfsi = NFS_I(inode);
75         struct rpc_cred *cred;
76
77         /*
78          * The following should never happen...
79          */
80         BUG_ON(nfs_have_writebacks(inode));
81         BUG_ON (!list_empty(&nfsi->open_files));
82         nfs_zap_acl_cache(inode);
83         cred = nfsi->cache_access.cred;
84         if (cred)
85                 put_rpccred(cred);
86
87         nfs_fscache_release_fh_cookie(NFS_SERVER(inode), nfsi);
88         BUG_ON(atomic_read(&nfsi->data_updates) != 0);
89 }
90
91 /**
92  * nfs_sync_mapping - helper to flush all mmapped dirty data to disk
93  */
94 int nfs_sync_mapping(struct address_space *mapping)
95 {
96         int ret;
97
98         if (mapping->nrpages == 0)
99                 return 0;
100         unmap_mapping_range(mapping, 0, 0, 0);
101         ret = filemap_write_and_wait(mapping);
102         if (ret != 0)
103                 goto out;
104         ret = nfs_wb_all(mapping->host);
105 out:
106         return ret;
107 }
108
109 /*
110  * Invalidate the local caches
111  */
112 static void nfs_zap_caches_locked(struct inode *inode)
113 {
114         struct nfs_inode *nfsi = NFS_I(inode);
115         int mode = inode->i_mode;
116
117         nfs_inc_stats(inode, NFSIOS_ATTRINVALIDATE);
118
119         NFS_ATTRTIMEO(inode) = NFS_MINATTRTIMEO(inode);
120         NFS_ATTRTIMEO_UPDATE(inode) = jiffies;
121
122         memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
123         if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
124                 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
125         else
126                 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
127 }
128
129 void nfs_zap_caches(struct inode *inode)
130 {
131         spin_lock(&inode->i_lock);
132         nfs_zap_caches_locked(inode);
133         spin_unlock(&inode->i_lock);
134
135         nfs_fscache_zap_fh_cookie(NFS_SERVER(inode), NFS_I(inode));
136 }
137
138 static void nfs_zap_acl_cache(struct inode *inode)
139 {
140         void (*clear_acl_cache)(struct inode *);
141
142         clear_acl_cache = NFS_PROTO(inode)->clear_acl_cache;
143         if (clear_acl_cache != NULL)
144                 clear_acl_cache(inode);
145         spin_lock(&inode->i_lock);
146         NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_ACL;
147         spin_unlock(&inode->i_lock);
148 }
149
150 /*
151  * Invalidate, but do not unhash, the inode.
152  * NB: must be called with inode->i_lock held!
153  */
154 static void nfs_invalidate_inode(struct inode *inode)
155 {
156         set_bit(NFS_INO_STALE, &NFS_FLAGS(inode));
157         nfs_zap_caches_locked(inode);
158 }
159
160 struct nfs_find_desc {
161         struct nfs_fh           *fh;
162         struct nfs_fattr        *fattr;
163 };
164
165 /*
166  * In NFSv3 we can have 64bit inode numbers. In order to support
167  * this, and re-exported directories (also seen in NFSv2)
168  * we are forced to allow 2 different inodes to have the same
169  * i_ino.
170  */
171 static int
172 nfs_find_actor(struct inode *inode, void *opaque)
173 {
174         struct nfs_find_desc    *desc = (struct nfs_find_desc *)opaque;
175         struct nfs_fh           *fh = desc->fh;
176         struct nfs_fattr        *fattr = desc->fattr;
177
178         if (NFS_FILEID(inode) != fattr->fileid)
179                 return 0;
180         if (nfs_compare_fh(NFS_FH(inode), fh))
181                 return 0;
182         if (is_bad_inode(inode) || NFS_STALE(inode))
183                 return 0;
184         return 1;
185 }
186
187 static int
188 nfs_init_locked(struct inode *inode, void *opaque)
189 {
190         struct nfs_find_desc    *desc = (struct nfs_find_desc *)opaque;
191         struct nfs_fattr        *fattr = desc->fattr;
192
193         NFS_FILEID(inode) = fattr->fileid;
194         nfs_copy_fh(NFS_FH(inode), desc->fh);
195         return 0;
196 }
197
198 /* Don't use READDIRPLUS on directories that we believe are too large */
199 #define NFS_LIMIT_READDIRPLUS (8*PAGE_SIZE)
200
201 /*
202  * This is our front-end to iget that looks up inodes by file handle
203  * instead of inode number.
204  */
205 struct inode *
206 nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
207 {
208         struct nfs_find_desc desc = {
209                 .fh     = fh,
210                 .fattr  = fattr
211         };
212         struct inode *inode = ERR_PTR(-ENOENT);
213         unsigned long hash;
214         int maycache = 1;
215
216         if ((fattr->valid & NFS_ATTR_FATTR) == 0)
217                 goto out_no_inode;
218
219         if (!fattr->nlink) {
220                 printk("NFS: Buggy server - nlink == 0!\n");
221                 goto out_no_inode;
222         }
223
224         hash = fattr->fileid;
225         if (sizeof(hash) < sizeof(u64))
226                 hash ^= fattr->fileid >> (sizeof(u64) - sizeof(ino_t)) * 8;
227
228         inode = iget5_locked(sb, hash, nfs_find_actor, nfs_init_locked, &desc);
229         if (inode == NULL) {
230                 inode = ERR_PTR(-ENOMEM);
231                 goto out_no_inode;
232         }
233
234         if (inode->i_state & I_NEW) {
235                 struct nfs_inode *nfsi = NFS_I(inode);
236
237                 /* We set i_ino for the few things that still rely on it, such
238                  * as printing messages; stat and filldir use the fileid
239                  * directly since i_ino may not be large enough */
240                 inode->i_ino = fattr->fileid;
241
242                 /* We can't support update_atime(), since the server will reset it */
243                 inode->i_flags |= S_NOATIME|S_NOCMTIME;
244                 inode->i_mode = fattr->mode;
245                 /* Why so? Because we want revalidate for devices/FIFOs, and
246                  * that's precisely what we have in nfs_file_inode_operations.
247                  */
248                 inode->i_op = NFS_SB(sb)->nfs_client->rpc_ops->file_inode_ops;
249                 if (S_ISREG(inode->i_mode)) {
250                         inode->i_fop = &nfs_file_operations;
251                         inode->i_data.a_ops = &nfs_file_aops;
252                         inode->i_data.backing_dev_info = &NFS_SB(sb)->backing_dev_info;
253                 } else if (S_ISDIR(inode->i_mode)) {
254                         inode->i_op = NFS_SB(sb)->nfs_client->rpc_ops->dir_inode_ops;
255                         inode->i_fop = &nfs_dir_operations;
256                         if (nfs_server_capable(inode, NFS_CAP_READDIRPLUS)
257                             && fattr->size <= NFS_LIMIT_READDIRPLUS)
258                                 set_bit(NFS_INO_ADVISE_RDPLUS, &NFS_FLAGS(inode));
259                         /* Deal with crossing mountpoints */
260                         if (!nfs_fsid_equal(&NFS_SB(sb)->fsid, &fattr->fsid)) {
261                                 if (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL)
262                                         inode->i_op = &nfs_referral_inode_operations;
263                                 else
264                                         inode->i_op = &nfs_mountpoint_inode_operations;
265                                 inode->i_fop = NULL;
266                                 maycache = 0;
267                         }
268                 } else if (S_ISLNK(inode->i_mode))
269                         inode->i_op = &nfs_symlink_inode_operations;
270                 else
271                         init_special_inode(inode, inode->i_mode, fattr->rdev);
272
273                 nfsi->read_cache_jiffies = fattr->time_start;
274                 nfsi->last_updated = jiffies;
275                 inode->i_atime = fattr->atime;
276                 inode->i_mtime = fattr->mtime;
277                 inode->i_ctime = fattr->ctime;
278                 if (fattr->valid & NFS_ATTR_FATTR_V4)
279                         nfsi->change_attr = fattr->change_attr;
280                 inode->i_size = nfs_size_to_loff_t(fattr->size);
281                 inode->i_nlink = fattr->nlink;
282                 inode->i_uid = INOXID_UID(XID_TAG(inode), fattr->uid, fattr->gid);
283                 inode->i_gid = INOXID_GID(XID_TAG(inode), fattr->uid, fattr->gid);
284                 inode->i_xid = INOXID_XID(XID_TAG(inode), fattr->uid, fattr->gid, 0);
285                                          /* maybe fattr->xid someday */
286                 if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
287                         /*
288                          * report the blocks in 512byte units
289                          */
290                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
291                 } else {
292                         inode->i_blocks = fattr->du.nfs2.blocks;
293                 }
294                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
295                 nfsi->attrtimeo_timestamp = jiffies;
296                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
297                 nfsi->cache_access.cred = NULL;
298
299                 nfs_fscache_get_fh_cookie(sb, nfsi, maycache);
300
301                 unlock_new_inode(inode);
302         } else
303                 nfs_refresh_inode(inode, fattr);
304         dprintk("NFS: nfs_fhget(%s/%Ld ct=%d)\n",
305                 inode->i_sb->s_id,
306                 (long long)NFS_FILEID(inode),
307                 atomic_read(&inode->i_count));
308
309 out:
310         return inode;
311
312 out_no_inode:
313         dprintk("nfs_fhget: iget failed with error %ld\n", PTR_ERR(inode));
314         goto out;
315 }
316
317 #define NFS_VALID_ATTRS (ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_SIZE|ATTR_ATIME|ATTR_ATIME_SET|ATTR_MTIME|ATTR_MTIME_SET)
318
319 int
320 nfs_setattr(struct dentry *dentry, struct iattr *attr)
321 {
322         struct inode *inode = dentry->d_inode;
323         struct nfs_fattr fattr;
324         int error;
325
326         nfs_inc_stats(inode, NFSIOS_VFSSETATTR);
327
328         if (attr->ia_valid & ATTR_SIZE) {
329                 if (!S_ISREG(inode->i_mode) || attr->ia_size == i_size_read(inode))
330                         attr->ia_valid &= ~ATTR_SIZE;
331         }
332
333         /* Optimization: if the end result is no change, don't RPC */
334         attr->ia_valid &= NFS_VALID_ATTRS;
335         if (attr->ia_valid == 0)
336                 return 0;
337
338         lock_kernel();
339         nfs_begin_data_update(inode);
340         /* Write all dirty data */
341         filemap_write_and_wait(inode->i_mapping);
342         nfs_wb_all(inode);
343         /*
344          * Return any delegations if we're going to change ACLs
345          */
346         if ((attr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0)
347                 nfs_inode_return_delegation(inode);
348         error = NFS_PROTO(inode)->setattr(dentry, &fattr, attr);
349         if (error == 0)
350                 nfs_refresh_inode(inode, &fattr);
351         nfs_end_data_update(inode);
352         unlock_kernel();
353         return error;
354 }
355
356 /**
357  * nfs_setattr_update_inode - Update inode metadata after a setattr call.
358  * @inode: pointer to struct inode
359  * @attr: pointer to struct iattr
360  *
361  * Note: we do this in the *proc.c in order to ensure that
362  *       it works for things like exclusive creates too.
363  */
364 void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr)
365 {
366         if ((attr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0) {
367                 if ((attr->ia_valid & ATTR_MODE) != 0) {
368                         int mode = attr->ia_mode & S_IALLUGO;
369                         mode |= inode->i_mode & ~S_IALLUGO;
370                         inode->i_mode = mode;
371                 }
372                 if ((attr->ia_valid & ATTR_UID) != 0)
373                         inode->i_uid = attr->ia_uid;
374                 if ((attr->ia_valid & ATTR_GID) != 0)
375                         inode->i_gid = attr->ia_gid;
376                 if ((attr->ia_valid & ATTR_XID) && IS_TAGXID(inode))
377                         inode->i_xid = attr->ia_xid;
378                 spin_lock(&inode->i_lock);
379                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
380                 spin_unlock(&inode->i_lock);
381         }
382         if ((attr->ia_valid & ATTR_SIZE) != 0) {
383                 nfs_inc_stats(inode, NFSIOS_SETATTRTRUNC);
384                 inode->i_size = attr->ia_size;
385                 nfs_fscache_set_size(NFS_SERVER(inode), NFS_I(inode), inode->i_size);
386                 vmtruncate(inode, attr->ia_size);
387         }
388 }
389
390 static int nfs_wait_schedule(void *word)
391 {
392         if (signal_pending(current))
393                 return -ERESTARTSYS;
394         schedule();
395         return 0;
396 }
397
398 /*
399  * Wait for the inode to get unlocked.
400  */
401 static int nfs_wait_on_inode(struct inode *inode)
402 {
403         struct rpc_clnt *clnt = NFS_CLIENT(inode);
404         struct nfs_inode *nfsi = NFS_I(inode);
405         sigset_t oldmask;
406         int error;
407
408         rpc_clnt_sigmask(clnt, &oldmask);
409         error = wait_on_bit_lock(&nfsi->flags, NFS_INO_REVALIDATING,
410                                         nfs_wait_schedule, TASK_INTERRUPTIBLE);
411         rpc_clnt_sigunmask(clnt, &oldmask);
412
413         return error;
414 }
415
416 static void nfs_wake_up_inode(struct inode *inode)
417 {
418         struct nfs_inode *nfsi = NFS_I(inode);
419
420         clear_bit(NFS_INO_REVALIDATING, &nfsi->flags);
421         smp_mb__after_clear_bit();
422         wake_up_bit(&nfsi->flags, NFS_INO_REVALIDATING);
423 }
424
425 int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
426 {
427         struct inode *inode = dentry->d_inode;
428         int need_atime = NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATIME;
429         int err;
430
431         /* Flush out writes to the server in order to update c/mtime */
432         nfs_sync_inode_wait(inode, 0, 0, FLUSH_NOCOMMIT);
433
434         /*
435          * We may force a getattr if the user cares about atime.
436          *
437          * Note that we only have to check the vfsmount flags here:
438          *  - NFS always sets S_NOATIME by so checking it would give a
439          *    bogus result
440          *  - NFS never sets MS_NOATIME or MS_NODIRATIME so there is
441          *    no point in checking those.
442          */
443         if ((mnt->mnt_flags & MNT_NOATIME) ||
444             ((mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode)))
445                 need_atime = 0;
446
447         if (need_atime)
448                 err = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
449         else
450                 err = nfs_revalidate_inode(NFS_SERVER(inode), inode);
451         if (!err) {
452                 generic_fillattr(inode, stat);
453                 stat->ino = NFS_FILEID(inode);
454         }
455         return err;
456 }
457
458 static struct nfs_open_context *alloc_nfs_open_context(struct vfsmount *mnt, struct dentry *dentry, struct rpc_cred *cred)
459 {
460         struct nfs_open_context *ctx;
461
462         ctx = (struct nfs_open_context *)kmalloc(sizeof(*ctx), GFP_KERNEL);
463         if (ctx != NULL) {
464                 atomic_set(&ctx->count, 1);
465                 ctx->dentry = dget(dentry);
466                 ctx->vfsmnt = mntget(mnt);
467                 ctx->cred = get_rpccred(cred);
468                 ctx->state = NULL;
469                 ctx->lockowner = current->files;
470                 ctx->error = 0;
471                 ctx->dir_cookie = 0;
472         }
473         return ctx;
474 }
475
476 struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx)
477 {
478         if (ctx != NULL)
479                 atomic_inc(&ctx->count);
480         return ctx;
481 }
482
483 void put_nfs_open_context(struct nfs_open_context *ctx)
484 {
485         if (atomic_dec_and_test(&ctx->count)) {
486                 if (!list_empty(&ctx->list)) {
487                         struct inode *inode = ctx->dentry->d_inode;
488                         spin_lock(&inode->i_lock);
489                         list_del(&ctx->list);
490                         spin_unlock(&inode->i_lock);
491                 }
492                 if (ctx->state != NULL)
493                         nfs4_close_state(ctx->state, ctx->mode);
494                 if (ctx->cred != NULL)
495                         put_rpccred(ctx->cred);
496                 dput(ctx->dentry);
497                 mntput(ctx->vfsmnt);
498                 kfree(ctx);
499         }
500 }
501
502 /*
503  * Ensure that mmap has a recent RPC credential for use when writing out
504  * shared pages
505  */
506 static void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx)
507 {
508         struct inode *inode = filp->f_dentry->d_inode;
509         struct nfs_inode *nfsi = NFS_I(inode);
510
511         filp->private_data = get_nfs_open_context(ctx);
512         spin_lock(&inode->i_lock);
513         list_add(&ctx->list, &nfsi->open_files);
514         spin_unlock(&inode->i_lock);
515 }
516
517 /*
518  * Given an inode, search for an open context with the desired characteristics
519  */
520 struct nfs_open_context *nfs_find_open_context(struct inode *inode, struct rpc_cred *cred, int mode)
521 {
522         struct nfs_inode *nfsi = NFS_I(inode);
523         struct nfs_open_context *pos, *ctx = NULL;
524
525         spin_lock(&inode->i_lock);
526         list_for_each_entry(pos, &nfsi->open_files, list) {
527                 if (cred != NULL && pos->cred != cred)
528                         continue;
529                 if ((pos->mode & mode) == mode) {
530                         ctx = get_nfs_open_context(pos);
531                         break;
532                 }
533         }
534         spin_unlock(&inode->i_lock);
535         return ctx;
536 }
537
538 static void nfs_file_clear_open_context(struct file *filp)
539 {
540         struct inode *inode = filp->f_dentry->d_inode;
541         struct nfs_open_context *ctx = (struct nfs_open_context *)filp->private_data;
542
543         if (ctx) {
544                 filp->private_data = NULL;
545                 spin_lock(&inode->i_lock);
546                 list_move_tail(&ctx->list, &NFS_I(inode)->open_files);
547                 spin_unlock(&inode->i_lock);
548                 put_nfs_open_context(ctx);
549         }
550 }
551
552 /*
553  * These allocate and release file read/write context information.
554  */
555 int nfs_open(struct inode *inode, struct file *filp)
556 {
557         struct nfs_open_context *ctx;
558         struct rpc_cred *cred;
559
560         cred = rpcauth_lookupcred(NFS_CLIENT(inode)->cl_auth, 0);
561         if (IS_ERR(cred))
562                 return PTR_ERR(cred);
563         ctx = alloc_nfs_open_context(filp->f_vfsmnt, filp->f_dentry, cred);
564         put_rpccred(cred);
565         if (ctx == NULL)
566                 return -ENOMEM;
567         ctx->mode = filp->f_mode;
568         nfs_file_set_open_context(filp, ctx);
569         put_nfs_open_context(ctx);
570         if ((filp->f_flags & O_ACCMODE) != O_RDONLY)
571                 nfs_fscache_disable_fh_cookie(inode);
572         return 0;
573 }
574
575 int nfs_release(struct inode *inode, struct file *filp)
576 {
577         nfs_file_clear_open_context(filp);
578         return 0;
579 }
580
581 /*
582  * This function is called whenever some part of NFS notices that
583  * the cached attributes have to be refreshed.
584  */
585 int
586 __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
587 {
588         int              status = -ESTALE;
589         struct nfs_fattr fattr;
590         struct nfs_inode *nfsi = NFS_I(inode);
591
592         dfprintk(PAGECACHE, "NFS: revalidating (%s/%Ld)\n",
593                 inode->i_sb->s_id, (long long)NFS_FILEID(inode));
594
595         nfs_inc_stats(inode, NFSIOS_INODEREVALIDATE);
596         lock_kernel();
597         if (!inode || is_bad_inode(inode))
598                 goto out_nowait;
599         if (NFS_STALE(inode))
600                 goto out_nowait;
601
602         status = nfs_wait_on_inode(inode);
603         if (status < 0)
604                 goto out;
605         if (NFS_STALE(inode)) {
606                 status = -ESTALE;
607                 /* Do we trust the cached ESTALE? */
608                 if (NFS_ATTRTIMEO(inode) != 0) {
609                         if (nfsi->cache_validity & (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ATIME)) {
610                                 /* no */
611                         } else
612                                 goto out;
613                 }
614         }
615
616         status = NFS_PROTO(inode)->getattr(server, NFS_FH(inode), &fattr);
617         if (status != 0) {
618                 dfprintk(PAGECACHE, "nfs_revalidate_inode: (%s/%Ld) getattr failed, error=%d\n",
619                          inode->i_sb->s_id,
620                          (long long)NFS_FILEID(inode), status);
621                 if (status == -ESTALE) {
622                         nfs_zap_caches(inode);
623                         if (!S_ISDIR(inode->i_mode))
624                                 set_bit(NFS_INO_STALE, &NFS_FLAGS(inode));
625                 }
626                 goto out;
627         }
628
629         spin_lock(&inode->i_lock);
630         status = nfs_update_inode(inode, &fattr);
631         if (status) {
632                 spin_unlock(&inode->i_lock);
633                 dfprintk(PAGECACHE, "nfs_revalidate_inode: (%s/%Ld) refresh failed, error=%d\n",
634                          inode->i_sb->s_id,
635                          (long long)NFS_FILEID(inode), status);
636                 goto out;
637         }
638         spin_unlock(&inode->i_lock);
639
640         if (nfsi->cache_validity & NFS_INO_INVALID_ACL)
641                 nfs_zap_acl_cache(inode);
642
643         dfprintk(PAGECACHE, "NFS: (%s/%Ld) revalidation complete\n",
644                 inode->i_sb->s_id,
645                 (long long)NFS_FILEID(inode));
646
647  out:
648         nfs_wake_up_inode(inode);
649
650  out_nowait:
651         unlock_kernel();
652         return status;
653 }
654
655 int nfs_attribute_timeout(struct inode *inode)
656 {
657         struct nfs_inode *nfsi = NFS_I(inode);
658
659         if (nfs_have_delegation(inode, FMODE_READ))
660                 return 0;
661         return time_after(jiffies, nfsi->read_cache_jiffies+nfsi->attrtimeo);
662 }
663
664 /**
665  * nfs_revalidate_inode - Revalidate the inode attributes
666  * @server - pointer to nfs_server struct
667  * @inode - pointer to inode struct
668  *
669  * Updates inode attribute information by retrieving the data from the server.
670  */
671 int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
672 {
673         if (!(NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATTR)
674                         && !nfs_attribute_timeout(inode))
675                 return NFS_STALE(inode) ? -ESTALE : 0;
676         return __nfs_revalidate_inode(server, inode);
677 }
678
679 /**
680  * nfs_revalidate_mapping - Revalidate the pagecache
681  * @inode - pointer to host inode
682  * @mapping - pointer to mapping
683  */
684 int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
685 {
686         struct nfs_inode *nfsi = NFS_I(inode);
687         int ret = 0;
688
689         if (NFS_STALE(inode))
690                 ret = -ESTALE;
691         if ((nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE)
692                         || nfs_attribute_timeout(inode))
693                 ret = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
694
695         if (nfsi->cache_validity & NFS_INO_INVALID_DATA) {
696                 nfs_inc_stats(inode, NFSIOS_DATAINVALIDATE);
697                 if (S_ISREG(inode->i_mode))
698                         nfs_sync_mapping(mapping);
699                 invalidate_inode_pages2(mapping);
700
701                 spin_lock(&inode->i_lock);
702                 nfsi->cache_validity &= ~NFS_INO_INVALID_DATA;
703                 if (S_ISDIR(inode->i_mode)) {
704                         memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
705                         /* This ensures we revalidate child dentries */
706                         nfsi->cache_change_attribute = jiffies;
707                 }
708                 spin_unlock(&inode->i_lock);
709
710                 nfs_fscache_renew_fh_cookie(NFS_SERVER(inode), nfsi);
711
712                 dfprintk(PAGECACHE, "NFS: (%s/%Ld) data cache invalidated\n",
713                                 inode->i_sb->s_id,
714                                 (long long)NFS_FILEID(inode));
715         }
716         return ret;
717 }
718
719 /**
720  * nfs_begin_data_update
721  * @inode - pointer to inode
722  * Declare that a set of operations will update file data on the server
723  */
724 void nfs_begin_data_update(struct inode *inode)
725 {
726         atomic_inc(&NFS_I(inode)->data_updates);
727 }
728
729 /**
730  * nfs_end_data_update
731  * @inode - pointer to inode
732  * Declare end of the operations that will update file data
733  * This will mark the inode as immediately needing revalidation
734  * of its attribute cache.
735  */
736 void nfs_end_data_update(struct inode *inode)
737 {
738         struct nfs_inode *nfsi = NFS_I(inode);
739
740         if (!nfs_have_delegation(inode, FMODE_READ)) {
741                 /* Directories and symlinks: invalidate page cache */
742                 if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) {
743                         spin_lock(&inode->i_lock);
744                         nfsi->cache_validity |= NFS_INO_INVALID_DATA;
745                         spin_unlock(&inode->i_lock);
746                 }
747         }
748         nfsi->cache_change_attribute = jiffies;
749         atomic_dec(&nfsi->data_updates);
750 }
751
752 static void nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr *fattr)
753 {
754         struct nfs_inode *nfsi = NFS_I(inode);
755
756         /* If we have atomic WCC data, we may update some attributes */
757         if ((fattr->valid & NFS_ATTR_WCC) != 0) {
758                 if (timespec_equal(&inode->i_ctime, &fattr->pre_ctime)) {
759                         memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime));
760                         nfsi->cache_change_attribute = jiffies;
761                 }
762                 if (timespec_equal(&inode->i_mtime, &fattr->pre_mtime)) {
763                         memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime));
764                         nfsi->cache_change_attribute = jiffies;
765                 }
766                 if (inode->i_size == fattr->pre_size && nfsi->npages == 0) {
767                         inode->i_size = fattr->size;
768                         nfsi->cache_change_attribute = jiffies;
769                 }
770         }
771 }
772
773 /**
774  * nfs_check_inode_attributes - verify consistency of the inode attribute cache
775  * @inode - pointer to inode
776  * @fattr - updated attributes
777  *
778  * Verifies the attribute cache. If we have just changed the attributes,
779  * so that fattr carries weak cache consistency data, then it may
780  * also update the ctime/mtime/change_attribute.
781  */
782 static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fattr)
783 {
784         struct nfs_inode *nfsi = NFS_I(inode);
785         loff_t cur_size, new_isize;
786         int data_unstable;
787         uid_t uid;
788         gid_t gid;
789         xid_t xid;
790
791
792         /* Has the inode gone and changed behind our back? */
793         if (nfsi->fileid != fattr->fileid
794                         || (inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT)) {
795                 return -EIO;
796         }
797
798         /* Are we in the process of updating data on the server? */
799         data_unstable = nfs_caches_unstable(inode);
800
801         /* Do atomic weak cache consistency updates */
802         nfs_wcc_update_inode(inode, fattr);
803
804         if ((fattr->valid & NFS_ATTR_FATTR_V4) != 0 &&
805                         nfsi->change_attr != fattr->change_attr)
806                 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
807
808         /* Verify a few of the more important attributes */
809         if (!timespec_equal(&inode->i_mtime, &fattr->mtime))
810                 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
811
812         cur_size = i_size_read(inode);
813         new_isize = nfs_size_to_loff_t(fattr->size);
814         if (cur_size != new_isize && nfsi->npages == 0)
815                 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
816
817         uid = INOXID_UID(XID_TAG(inode), fattr->uid, fattr->gid);
818         gid = INOXID_GID(XID_TAG(inode), fattr->uid, fattr->gid);
819         xid = INOXID_XID(XID_TAG(inode), fattr->uid, fattr->gid, 0);
820
821         /* Have any file permissions changed? */
822         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)
823                         || inode->i_uid != uid
824                         || inode->i_gid != gid
825                         || inode->i_xid != xid)
826                 nfsi->cache_validity |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
827
828         /* Has the link count changed? */
829         if (inode->i_nlink != fattr->nlink)
830                 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
831
832         if (!timespec_equal(&inode->i_atime, &fattr->atime))
833                 nfsi->cache_validity |= NFS_INO_INVALID_ATIME;
834
835         nfsi->read_cache_jiffies = fattr->time_start;
836         return 0;
837 }
838
839 /**
840  * nfs_refresh_inode - try to update the inode attribute cache
841  * @inode - pointer to inode
842  * @fattr - updated attributes
843  *
844  * Check that an RPC call that returned attributes has not overlapped with
845  * other recent updates of the inode metadata, then decide whether it is
846  * safe to do a full update of the inode attributes, or whether just to
847  * call nfs_check_inode_attributes.
848  */
849 int nfs_refresh_inode(struct inode *inode, struct nfs_fattr *fattr)
850 {
851         struct nfs_inode *nfsi = NFS_I(inode);
852         int status;
853
854         if ((fattr->valid & NFS_ATTR_FATTR) == 0)
855                 return 0;
856         spin_lock(&inode->i_lock);
857         if (time_after(fattr->time_start, nfsi->last_updated))
858                 status = nfs_update_inode(inode, fattr);
859         else
860                 status = nfs_check_inode_attributes(inode, fattr);
861
862         spin_unlock(&inode->i_lock);
863         return status;
864 }
865
866 /**
867  * nfs_post_op_update_inode - try to update the inode attribute cache
868  * @inode - pointer to inode
869  * @fattr - updated attributes
870  *
871  * After an operation that has changed the inode metadata, mark the
872  * attribute cache as being invalid, then try to update it.
873  */
874 int nfs_post_op_update_inode(struct inode *inode, struct nfs_fattr *fattr)
875 {
876         struct nfs_inode *nfsi = NFS_I(inode);
877         int status = 0;
878
879         spin_lock(&inode->i_lock);
880         if (unlikely((fattr->valid & NFS_ATTR_FATTR) == 0)) {
881                 nfsi->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
882                 goto out;
883         }
884         status = nfs_update_inode(inode, fattr);
885 out:
886         spin_unlock(&inode->i_lock);
887         return status;
888 }
889
890 /*
891  * Many nfs protocol calls return the new file attributes after
892  * an operation.  Here we update the inode to reflect the state
893  * of the server's inode.
894  *
895  * This is a bit tricky because we have to make sure all dirty pages
896  * have been sent off to the server before calling invalidate_inode_pages.
897  * To make sure no other process adds more write requests while we try
898  * our best to flush them, we make them sleep during the attribute refresh.
899  *
900  * A very similar scenario holds for the dir cache.
901  */
902 static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
903 {
904         struct nfs_server *server;
905         struct nfs_inode *nfsi = NFS_I(inode);
906         loff_t cur_isize, new_isize;
907         unsigned int    invalid = 0;
908         int data_stable;
909         uid_t uid;
910         gid_t gid;
911         xid_t xid;
912
913         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
914                         __FUNCTION__, inode->i_sb->s_id, inode->i_ino,
915                         atomic_read(&inode->i_count), fattr->valid);
916
917         if (nfsi->fileid != fattr->fileid)
918                 goto out_fileid;
919
920         /*
921          * Make sure the inode's type hasn't changed.
922          */
923         if ((inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT))
924                 goto out_changed;
925
926         server = NFS_SERVER(inode);
927         /* Update the fsid if and only if this is the root directory */
928         if (inode == inode->i_sb->s_root->d_inode
929                         && !nfs_fsid_equal(&server->fsid, &fattr->fsid))
930                 server->fsid = fattr->fsid;
931
932         /*
933          * Update the read time so we don't revalidate too often.
934          */
935         nfsi->read_cache_jiffies = fattr->time_start;
936         nfsi->last_updated = jiffies;
937
938         /* Are we racing with known updates of the metadata on the server? */
939         data_stable = nfs_verify_change_attribute(inode, fattr->time_start);
940         if (data_stable)
941                 nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_ATIME);
942
943         /* Do atomic weak cache consistency updates */
944         nfs_wcc_update_inode(inode, fattr);
945
946         /* Check if our cached file size is stale */
947         new_isize = nfs_size_to_loff_t(fattr->size);
948         cur_isize = i_size_read(inode);
949         if (new_isize != cur_isize) {
950                 /* Do we perhaps have any outstanding writes? */
951                 if (nfsi->npages == 0) {
952                         /* No, but did we race with nfs_end_data_update()? */
953                         if (data_stable) {
954                                 inode->i_size = new_isize;
955                                 invalid |= NFS_INO_INVALID_DATA;
956                                 nfs_fscache_set_size(NFS_SERVER(inode), nfsi, inode->i_size);
957                         }
958                         invalid |= NFS_INO_INVALID_ATTR;
959                 } else if (new_isize > cur_isize) {
960                         inode->i_size = new_isize;
961                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA;
962                         nfs_fscache_set_size(NFS_SERVER(inode), nfsi, inode->i_size);
963                 }
964                 nfsi->cache_change_attribute = jiffies;
965                 dprintk("NFS: isize change on server for file %s/%ld\n",
966                                 inode->i_sb->s_id, inode->i_ino);
967         }
968
969         /* Check if the mtime agrees */
970         if (!timespec_equal(&inode->i_mtime, &fattr->mtime)) {
971                 memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime));
972                 dprintk("NFS: mtime change on server for file %s/%ld\n",
973                                 inode->i_sb->s_id, inode->i_ino);
974                 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA;
975                 nfsi->cache_change_attribute = jiffies;
976         }
977
978         /* If ctime has changed we should definitely clear access+acl caches */
979         if (!timespec_equal(&inode->i_ctime, &fattr->ctime)) {
980                 invalid |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
981                 memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime));
982                 nfsi->cache_change_attribute = jiffies;
983         }
984         memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
985
986         uid = INOXID_UID(XID_TAG(inode), fattr->uid, fattr->gid);
987         gid = INOXID_GID(XID_TAG(inode), fattr->uid, fattr->gid);
988         xid = INOXID_XID(XID_TAG(inode), fattr->uid, fattr->gid, 0);
989
990         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO) ||
991             inode->i_uid != uid ||
992             inode->i_gid != gid ||
993             inode->i_xid != xid)
994                 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
995
996         inode->i_mode = fattr->mode;
997         inode->i_nlink = fattr->nlink;
998         inode->i_uid = uid;
999         inode->i_gid = gid;
1000         inode->i_xid = xid;
1001
1002         if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
1003                 /*
1004                  * report the blocks in 512byte units
1005                  */
1006                 inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
1007         } else {
1008                 inode->i_blocks = fattr->du.nfs2.blocks;
1009         }
1010
1011         if ((fattr->valid & NFS_ATTR_FATTR_V4) != 0 &&
1012                         nfsi->change_attr != fattr->change_attr) {
1013                 dprintk("NFS: change_attr change on server for file %s/%ld\n",
1014                                 inode->i_sb->s_id, inode->i_ino);
1015                 nfsi->change_attr = fattr->change_attr;
1016                 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
1017                 nfsi->cache_change_attribute = jiffies;
1018         }
1019
1020         /* Update attrtimeo value if we're out of the unstable period */
1021         if (invalid & NFS_INO_INVALID_ATTR) {
1022                 nfs_inc_stats(inode, NFSIOS_ATTRINVALIDATE);
1023                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
1024                 nfsi->attrtimeo_timestamp = jiffies;
1025         } else if (time_after(jiffies, nfsi->attrtimeo_timestamp+nfsi->attrtimeo)) {
1026                 if ((nfsi->attrtimeo <<= 1) > NFS_MAXATTRTIMEO(inode))
1027                         nfsi->attrtimeo = NFS_MAXATTRTIMEO(inode);
1028                 nfsi->attrtimeo_timestamp = jiffies;
1029         }
1030         /* Don't invalidate the data if we were to blame */
1031         if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode)
1032                                 || S_ISLNK(inode->i_mode)))
1033                 invalid &= ~NFS_INO_INVALID_DATA;
1034         if (data_stable)
1035                 invalid &= ~(NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ATIME|NFS_INO_REVAL_PAGECACHE);
1036         if (!nfs_have_delegation(inode, FMODE_READ))
1037                 nfsi->cache_validity |= invalid;
1038
1039         return 0;
1040  out_changed:
1041         /*
1042          * Big trouble! The inode has become a different object.
1043          */
1044 #ifdef NFS_PARANOIA
1045         printk(KERN_DEBUG "%s: inode %ld mode changed, %07o to %07o\n",
1046                         __FUNCTION__, inode->i_ino, inode->i_mode, fattr->mode);
1047 #endif
1048  out_err:
1049         /*
1050          * No need to worry about unhashing the dentry, as the
1051          * lookup validation will know that the inode is bad.
1052          * (But we fall through to invalidate the caches.)
1053          */
1054         nfs_invalidate_inode(inode);
1055         return -ESTALE;
1056
1057  out_fileid:
1058         printk(KERN_ERR "NFS: server %s error: fileid changed\n"
1059                 "fsid %s: expected fileid 0x%Lx, got 0x%Lx\n",
1060                 NFS_SERVER(inode)->nfs_client->cl_hostname, inode->i_sb->s_id,
1061                 (long long)nfsi->fileid, (long long)fattr->fileid);
1062         goto out_err;
1063 }
1064
1065
1066 #ifdef CONFIG_NFS_V4
1067
1068 /*
1069  * Clean out any remaining NFSv4 state that might be left over due
1070  * to open() calls that passed nfs_atomic_lookup, but failed to call
1071  * nfs_open().
1072  */
1073 void nfs4_clear_inode(struct inode *inode)
1074 {
1075         struct nfs_inode *nfsi = NFS_I(inode);
1076
1077         /* If we are holding a delegation, return it! */
1078         nfs_inode_return_delegation(inode);
1079         /* First call standard NFS clear_inode() code */
1080         nfs_clear_inode(inode);
1081         /* Now clear out any remaining state */
1082         while (!list_empty(&nfsi->open_states)) {
1083                 struct nfs4_state *state;
1084                 
1085                 state = list_entry(nfsi->open_states.next,
1086                                 struct nfs4_state,
1087                                 inode_states);
1088                 dprintk("%s(%s/%Ld): found unclaimed NFSv4 state %p\n",
1089                                 __FUNCTION__,
1090                                 inode->i_sb->s_id,
1091                                 (long long)NFS_FILEID(inode),
1092                                 state);
1093                 BUG_ON(atomic_read(&state->count) != 1);
1094                 nfs4_close_state(state, state->state);
1095         }
1096 }
1097 #endif
1098
1099 struct inode *nfs_alloc_inode(struct super_block *sb)
1100 {
1101         struct nfs_inode *nfsi;
1102         nfsi = (struct nfs_inode *)kmem_cache_alloc(nfs_inode_cachep, SLAB_KERNEL);
1103         if (!nfsi)
1104                 return NULL;
1105         nfsi->flags = 0UL;
1106         nfsi->cache_validity = 0UL;
1107         nfsi->cache_change_attribute = jiffies;
1108 #ifdef CONFIG_NFS_V3_ACL
1109         nfsi->acl_access = ERR_PTR(-EAGAIN);
1110         nfsi->acl_default = ERR_PTR(-EAGAIN);
1111 #endif
1112 #ifdef CONFIG_NFS_V4
1113         nfsi->nfs4_acl = NULL;
1114 #endif /* CONFIG_NFS_V4 */
1115         return &nfsi->vfs_inode;
1116 }
1117
1118 void nfs_destroy_inode(struct inode *inode)
1119 {
1120         kmem_cache_free(nfs_inode_cachep, NFS_I(inode));
1121 }
1122
1123 static inline void nfs4_init_once(struct nfs_inode *nfsi)
1124 {
1125 #ifdef CONFIG_NFS_V4
1126         INIT_LIST_HEAD(&nfsi->open_states);
1127         nfsi->delegation = NULL;
1128         nfsi->delegation_state = 0;
1129         init_rwsem(&nfsi->rwsem);
1130 #endif
1131 }
1132
1133 static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
1134 {
1135         struct nfs_inode *nfsi = (struct nfs_inode *) foo;
1136
1137         if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
1138             SLAB_CTOR_CONSTRUCTOR) {
1139                 inode_init_once(&nfsi->vfs_inode);
1140                 spin_lock_init(&nfsi->req_lock);
1141                 INIT_LIST_HEAD(&nfsi->dirty);
1142                 INIT_LIST_HEAD(&nfsi->commit);
1143                 INIT_LIST_HEAD(&nfsi->open_files);
1144                 INIT_RADIX_TREE(&nfsi->nfs_page_tree, GFP_ATOMIC);
1145                 atomic_set(&nfsi->data_updates, 0);
1146                 nfsi->ndirty = 0;
1147                 nfsi->ncommit = 0;
1148                 nfsi->npages = 0;
1149                 nfs4_init_once(nfsi);
1150         }
1151 }
1152  
1153 static int __init nfs_init_inodecache(void)
1154 {
1155         nfs_inode_cachep = kmem_cache_create("nfs_inode_cache",
1156                                              sizeof(struct nfs_inode),
1157                                              0, (SLAB_RECLAIM_ACCOUNT|
1158                                                 SLAB_MEM_SPREAD),
1159                                              init_once, NULL);
1160         if (nfs_inode_cachep == NULL)
1161                 return -ENOMEM;
1162
1163         return 0;
1164 }
1165
1166 static void nfs_destroy_inodecache(void)
1167 {
1168         if (kmem_cache_destroy(nfs_inode_cachep))
1169                 printk(KERN_INFO "nfs_inode_cache: not all structures were freed\n");
1170 }
1171
1172 /*
1173  * Initialize NFS
1174  */
1175 static int __init init_nfs_fs(void)
1176 {
1177         int err;
1178
1179         err = nfs_fscache_register();
1180         if (err < 0)
1181                 goto out6;
1182
1183         err = nfs_fs_proc_init();
1184         if (err)
1185                 goto out5;
1186
1187         err = nfs_init_nfspagecache();
1188         if (err)
1189                 goto out4;
1190
1191         err = nfs_init_inodecache();
1192         if (err)
1193                 goto out3;
1194
1195         err = nfs_init_readpagecache();
1196         if (err)
1197                 goto out2;
1198
1199         err = nfs_init_writepagecache();
1200         if (err)
1201                 goto out1;
1202
1203         err = nfs_init_directcache();
1204         if (err)
1205                 goto out0;
1206
1207 #ifdef CONFIG_PROC_FS
1208         rpc_proc_register(&nfs_rpcstat);
1209 #endif
1210         if ((err = register_nfs_fs()) != 0)
1211                 goto out;
1212         return 0;
1213 out:
1214 #ifdef CONFIG_PROC_FS
1215         rpc_proc_unregister("nfs");
1216 #endif
1217         nfs_destroy_directcache();
1218 out0:
1219         nfs_destroy_writepagecache();
1220 out1:
1221         nfs_destroy_readpagecache();
1222 out2:
1223         nfs_destroy_inodecache();
1224 out3:
1225         nfs_destroy_nfspagecache();
1226 out4:
1227         nfs_fs_proc_exit();
1228 out5:
1229         nfs_fscache_unregister();
1230 out6:
1231         return err;
1232 }
1233
1234 static void __exit exit_nfs_fs(void)
1235 {
1236         nfs_destroy_directcache();
1237         nfs_destroy_writepagecache();
1238         nfs_destroy_readpagecache();
1239         nfs_destroy_inodecache();
1240         nfs_destroy_nfspagecache();
1241         nfs_fscache_unregister();
1242 #ifdef CONFIG_PROC_FS
1243         rpc_proc_unregister("nfs");
1244 #endif
1245         unregister_nfs_fs();
1246         nfs_fs_proc_exit();
1247 }
1248
1249 /* Not quite true; I just maintain it */
1250 MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
1251 MODULE_LICENSE("GPL");
1252
1253 module_init(init_nfs_fs)
1254 module_exit(exit_nfs_fs)