knfsd: 64 bit ino support for NFS server
[safe/jmp/linux-2.6] / fs / nfs / inode.c
index af53c02..71a49c3 100644 (file)
@@ -15,7 +15,7 @@
 
 #include <linux/module.h>
 #include <linux/init.h>
-
+#include <linux/sched.h>
 #include <linux/time.h>
 #include <linux/kernel.h>
 #include <linux/mm.h>
@@ -48,7 +48,6 @@
 #include "internal.h"
 
 #define NFSDBG_FACILITY                NFSDBG_VFS
-#define NFS_PARANOIA 1
 
 static void nfs_invalidate_inode(struct inode *);
 static int nfs_update_inode(struct inode *, struct nfs_fattr *);
@@ -341,8 +340,10 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr)
        lock_kernel();
        nfs_begin_data_update(inode);
        /* Write all dirty data */
-       filemap_write_and_wait(inode->i_mapping);
-       nfs_wb_all(inode);
+       if (S_ISREG(inode->i_mode)) {
+               filemap_write_and_wait(inode->i_mapping);
+               nfs_wb_all(inode);
+       }
        /*
         * Return any delegations if we're going to change ACLs
         */
@@ -429,7 +430,8 @@ int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
        int err;
 
        /* Flush out writes to the server in order to update c/mtime */
-       nfs_sync_mapping_range(inode->i_mapping, 0, 0, FLUSH_NOCOMMIT);
+       if (S_ISREG(inode->i_mode))
+               nfs_sync_mapping_range(inode->i_mapping, 0, 0, FLUSH_NOCOMMIT);
 
        /*
         * We may force a getattr if the user cares about atime.
@@ -459,14 +461,14 @@ static struct nfs_open_context *alloc_nfs_open_context(struct vfsmount *mnt, str
 
        ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
        if (ctx != NULL) {
-               atomic_set(&ctx->count, 1);
-               ctx->dentry = dget(dentry);
-               ctx->vfsmnt = mntget(mnt);
+               ctx->path.dentry = dget(dentry);
+               ctx->path.mnt = mntget(mnt);
                ctx->cred = get_rpccred(cred);
                ctx->state = NULL;
                ctx->lockowner = current->files;
                ctx->error = 0;
                ctx->dir_cookie = 0;
+               atomic_set(&ctx->count, 1);
        }
        return ctx;
 }
@@ -480,21 +482,19 @@ struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx)
 
 void put_nfs_open_context(struct nfs_open_context *ctx)
 {
-       if (atomic_dec_and_test(&ctx->count)) {
-               if (!list_empty(&ctx->list)) {
-                       struct inode *inode = ctx->dentry->d_inode;
-                       spin_lock(&inode->i_lock);
-                       list_del(&ctx->list);
-                       spin_unlock(&inode->i_lock);
-               }
-               if (ctx->state != NULL)
-                       nfs4_close_state(ctx->state, ctx->mode);
-               if (ctx->cred != NULL)
-                       put_rpccred(ctx->cred);
-               dput(ctx->dentry);
-               mntput(ctx->vfsmnt);
-               kfree(ctx);
-       }
+       struct inode *inode = ctx->path.dentry->d_inode;
+
+       if (!atomic_dec_and_lock(&ctx->count, &inode->i_lock))
+               return;
+       list_del(&ctx->list);
+       spin_unlock(&inode->i_lock);
+       if (ctx->state != NULL)
+               nfs4_close_state(&ctx->path, ctx->state, ctx->mode);
+       if (ctx->cred != NULL)
+               put_rpccred(ctx->cred);
+       dput(ctx->path.dentry);
+       mntput(ctx->path.mnt);
+       kfree(ctx);
 }
 
 /*
@@ -959,8 +959,8 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
                goto out_changed;
 
        server = NFS_SERVER(inode);
-       /* Update the fsid if and only if this is the root directory */
-       if (inode == inode->i_sb->s_root->d_inode
+       /* Update the fsid? */
+       if (S_ISDIR(inode->i_mode)
                        && !nfs_fsid_equal(&server->fsid, &fattr->fsid))
                server->fsid = fattr->fsid;
 
@@ -1064,18 +1064,18 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
                invalid &= ~NFS_INO_INVALID_DATA;
        if (data_stable)
                invalid &= ~(NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ATIME|NFS_INO_REVAL_PAGECACHE);
-       if (!nfs_have_delegation(inode, FMODE_READ))
+       if (!nfs_have_delegation(inode, FMODE_READ) ||
+                       (nfsi->cache_validity & NFS_INO_REVAL_FORCED))
                nfsi->cache_validity |= invalid;
+       nfsi->cache_validity &= ~NFS_INO_REVAL_FORCED;
 
        return 0;
  out_changed:
        /*
         * Big trouble! The inode has become a different object.
         */
-#ifdef NFS_PARANOIA
        printk(KERN_DEBUG "%s: inode %ld mode changed, %07o to %07o\n",
                        __FUNCTION__, inode->i_ino, inode->i_mode, fattr->mode);
-#endif
  out_err:
        /*
         * No need to worry about unhashing the dentry, as the
@@ -1103,27 +1103,10 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
  */
 void nfs4_clear_inode(struct inode *inode)
 {
-       struct nfs_inode *nfsi = NFS_I(inode);
-
        /* If we are holding a delegation, return it! */
        nfs_inode_return_delegation(inode);
        /* First call standard NFS clear_inode() code */
        nfs_clear_inode(inode);
-       /* Now clear out any remaining state */
-       while (!list_empty(&nfsi->open_states)) {
-               struct nfs4_state *state;
-               
-               state = list_entry(nfsi->open_states.next,
-                               struct nfs4_state,
-                               inode_states);
-               dprintk("%s(%s/%Ld): found unclaimed NFSv4 state %p\n",
-                               __FUNCTION__,
-                               inode->i_sb->s_id,
-                               (long long)NFS_FILEID(inode),
-                               state);
-               BUG_ON(atomic_read(&state->count) != 1);
-               nfs4_close_state(state, state->state);
-       }
 }
 #endif
 
@@ -1164,31 +1147,24 @@ static void init_once(void * foo, struct kmem_cache * cachep, unsigned long flag
 {
        struct nfs_inode *nfsi = (struct nfs_inode *) foo;
 
-       if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
-           SLAB_CTOR_CONSTRUCTOR) {
-               inode_init_once(&nfsi->vfs_inode);
-               spin_lock_init(&nfsi->req_lock);
-               INIT_LIST_HEAD(&nfsi->dirty);
-               INIT_LIST_HEAD(&nfsi->commit);
-               INIT_LIST_HEAD(&nfsi->open_files);
-               INIT_LIST_HEAD(&nfsi->access_cache_entry_lru);
-               INIT_LIST_HEAD(&nfsi->access_cache_inode_lru);
-               INIT_RADIX_TREE(&nfsi->nfs_page_tree, GFP_ATOMIC);
-               atomic_set(&nfsi->data_updates, 0);
-               nfsi->ndirty = 0;
-               nfsi->ncommit = 0;
-               nfsi->npages = 0;
-               nfs4_init_once(nfsi);
-       }
+       inode_init_once(&nfsi->vfs_inode);
+       INIT_LIST_HEAD(&nfsi->open_files);
+       INIT_LIST_HEAD(&nfsi->access_cache_entry_lru);
+       INIT_LIST_HEAD(&nfsi->access_cache_inode_lru);
+       INIT_RADIX_TREE(&nfsi->nfs_page_tree, GFP_ATOMIC);
+       atomic_set(&nfsi->data_updates, 0);
+       nfsi->ncommit = 0;
+       nfsi->npages = 0;
+       nfs4_init_once(nfsi);
 }
+
 static int __init nfs_init_inodecache(void)
 {
        nfs_inode_cachep = kmem_cache_create("nfs_inode_cache",
                                             sizeof(struct nfs_inode),
                                             0, (SLAB_RECLAIM_ACCOUNT|
                                                SLAB_MEM_SPREAD),
-                                            init_once, NULL);
+                                            init_once);
        if (nfs_inode_cachep == NULL)
                return -ENOMEM;