NFS: Fix over-conservative attribute invalidation in nfs_update_inode()
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / fs / nfs / inode.c
index bd9f5a8365923ca12566af9ffa12848892987efa..721e511f8ba9896523ac8682c025b9dc83ceca11 100644 (file)
@@ -431,7 +431,7 @@ int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
 
        /* Flush out writes to the server in order to update c/mtime */
        if (S_ISREG(inode->i_mode))
-               nfs_sync_mapping_range(inode->i_mapping, 0, 0, FLUSH_NOCOMMIT);
+               nfs_wb_nocommit(inode);
 
        /*
         * We may force a getattr if the user cares about atime.
@@ -450,8 +450,10 @@ int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
                err = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
        else
                err = nfs_revalidate_inode(NFS_SERVER(inode), inode);
-       if (!err)
+       if (!err) {
                generic_fillattr(inode, stat);
+               stat->ino = NFS_FILEID(inode);
+       }
        return err;
 }
 
@@ -461,14 +463,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;
 }
@@ -482,21 +484,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);
 }
 
 /*
@@ -538,7 +538,7 @@ struct nfs_open_context *nfs_find_open_context(struct inode *inode, struct rpc_c
 static void nfs_file_clear_open_context(struct file *filp)
 {
        struct inode *inode = filp->f_path.dentry->d_inode;
-       struct nfs_open_context *ctx = (struct nfs_open_context *)filp->private_data;
+       struct nfs_open_context *ctx = nfs_file_open_context(filp);
 
        if (ctx) {
                filp->private_data = NULL;
@@ -656,7 +656,7 @@ int nfs_attribute_timeout(struct inode *inode)
 
        if (nfs_have_delegation(inode, FMODE_READ))
                return 0;
-       return time_after(jiffies, nfsi->read_cache_jiffies+nfsi->attrtimeo);
+       return !time_in_range(jiffies, nfsi->read_cache_jiffies, nfsi->read_cache_jiffies + nfsi->attrtimeo);
 }
 
 /**
@@ -961,8 +961,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;
 
@@ -978,8 +978,8 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
 
        /* Are we racing with known updates of the metadata on the server? */
        data_stable = nfs_verify_change_attribute(inode, fattr->time_start);
-       if (data_stable)
-               nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_ATIME);
+       nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ATIME
+                       | NFS_INO_REVAL_PAGECACHE);
 
        /* Do atomic weak cache consistency updates */
        nfs_wcc_update_inode(inode, fattr);
@@ -1055,19 +1055,20 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
                nfs_inc_stats(inode, NFSIOS_ATTRINVALIDATE);
                nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
                nfsi->attrtimeo_timestamp = now;
-       } else if (time_after(now, nfsi->attrtimeo_timestamp+nfsi->attrtimeo)) {
+       } else if (!time_in_range(now, nfsi->attrtimeo_timestamp, nfsi->attrtimeo_timestamp + nfsi->attrtimeo)) {
                if ((nfsi->attrtimeo <<= 1) > NFS_MAXATTRTIMEO(inode))
                        nfsi->attrtimeo = NFS_MAXATTRTIMEO(inode);
                nfsi->attrtimeo_timestamp = now;
        }
+       invalid &= ~NFS_INO_INVALID_ATTR;
        /* Don't invalidate the data if we were to blame */
        if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode)
                                || S_ISLNK(inode->i_mode)))
                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:
@@ -1103,27 +1104,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
 
@@ -1165,27 +1149,23 @@ static void init_once(void * foo, struct kmem_cache * cachep, unsigned long flag
        struct nfs_inode *nfsi = (struct nfs_inode *) foo;
 
        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);
 }
+
 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;