]> git.karo-electronics.de Git - mv-sheeva.git/commitdiff
NFS: Don't let nfs_end_data_update() clobber attribute update information
authorTrond Myklebust <Trond.Myklebust@netapp.com>
Fri, 28 Oct 2005 02:12:39 +0000 (22:12 -0400)
committerTrond Myklebust <Trond.Myklebust@netapp.com>
Fri, 28 Oct 2005 02:12:39 +0000 (22:12 -0400)
 Since we almost always call nfs_end_data_update() after we called
 nfs_refresh_inode(), we now end up marking the inode metadata
 as needing revalidation immediately after having updated it.

 This patch rearranges things so that we mark the inode as needing
 revalidation _before_ we call nfs_refresh_inode() on those operations
 that need it.

Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
fs/nfs/inode.c
fs/nfs/nfs3proc.c
fs/nfs/nfs4proc.c
fs/nfs/proc.c
include/linux/nfs_fs.h

index b7d4f8f13ac257d9f36dca6b2b4fcd76941beae2..6b3156e1535082210b0be7f99f3b3d755caf4535 100644 (file)
@@ -1236,13 +1236,12 @@ void nfs_end_data_update(struct inode *inode)
        struct nfs_inode *nfsi = NFS_I(inode);
 
        if (!nfs_have_delegation(inode, FMODE_READ)) {
-               /* Mark the attribute cache for revalidation */
-               spin_lock(&inode->i_lock);
-               nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
-               /* Directories and symlinks: invalidate page cache too */
-               if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode))
+               /* Directories and symlinks: invalidate page cache */
+               if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) {
+                       spin_lock(&inode->i_lock);
                        nfsi->cache_validity |= NFS_INO_INVALID_DATA;
-               spin_unlock(&inode->i_lock);
+                       spin_unlock(&inode->i_lock);
+               }
        }
        nfsi->cache_change_attribute = jiffies;
        atomic_dec(&nfsi->data_updates);
@@ -1360,6 +1359,33 @@ int nfs_refresh_inode(struct inode *inode, struct nfs_fattr *fattr)
        return status;
 }
 
+/**
+ * nfs_post_op_update_inode - try to update the inode attribute cache
+ * @inode - pointer to inode
+ * @fattr - updated attributes
+ *
+ * After an operation that has changed the inode metadata, mark the
+ * attribute cache as being invalid, then try to update it.
+ */
+int nfs_post_op_update_inode(struct inode *inode, struct nfs_fattr *fattr)
+{
+       struct nfs_inode *nfsi = NFS_I(inode);
+       int status = 0;
+
+       spin_lock(&inode->i_lock);
+       if (unlikely((fattr->valid & NFS_ATTR_FATTR) == 0)) {
+               nfsi->cache_validity |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS;
+               goto out;
+       }
+       status = nfs_update_inode(inode, fattr, fattr->time_start);
+       if (time_after_eq(fattr->time_start, nfsi->cache_change_attribute))
+               nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ATIME|NFS_INO_REVAL_PAGECACHE);
+       nfsi->cache_change_attribute = jiffies;
+out:
+       spin_unlock(&inode->i_lock);
+       return status;
+}
+
 /*
  * Many nfs protocol calls return the new file attributes after
  * an operation.  Here we update the inode to reflect the state
index 4b1b48b139f6aec23082abec8a5f25c6d31fbad3..92c870d19ccdbe61a44d4dcb110c83ef9067e3da 100644 (file)
@@ -266,7 +266,7 @@ static int nfs3_proc_write(struct nfs_write_data *wdata)
        nfs_fattr_init(fattr);
        status = rpc_call_sync(NFS_CLIENT(inode), &msg, rpcflags);
        if (status >= 0)
-               nfs_refresh_inode(inode, fattr);
+               nfs_post_op_update_inode(inode, fattr);
        dprintk("NFS reply write: %d\n", status);
        return status < 0? status : wdata->res.count;
 }
@@ -288,7 +288,7 @@ static int nfs3_proc_commit(struct nfs_write_data *cdata)
        nfs_fattr_init(fattr);
        status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
        if (status >= 0)
-               nfs_refresh_inode(inode, fattr);
+               nfs_post_op_update_inode(inode, fattr);
        dprintk("NFS reply commit: %d\n", status);
        return status;
 }
@@ -332,7 +332,7 @@ again:
        nfs_fattr_init(&dir_attr);
        nfs_fattr_init(&fattr);
        status = rpc_call(NFS_CLIENT(dir), NFS3PROC_CREATE, &arg, &res, 0);
-       nfs_refresh_inode(dir, &dir_attr);
+       nfs_post_op_update_inode(dir, &dir_attr);
 
        /* If the server doesn't support the exclusive creation semantics,
         * try again with simple 'guarded' mode. */
@@ -403,7 +403,7 @@ nfs3_proc_remove(struct inode *dir, struct qstr *name)
        dprintk("NFS call  remove %s\n", name->name);
        nfs_fattr_init(&dir_attr);
        status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
-       nfs_refresh_inode(dir, &dir_attr);
+       nfs_post_op_update_inode(dir, &dir_attr);
        dprintk("NFS reply remove: %d\n", status);
        return status;
 }
@@ -439,7 +439,7 @@ nfs3_proc_unlink_done(struct dentry *dir, struct rpc_task *task)
                return 1;
        if (msg->rpc_argp) {
                dir_attr = (struct nfs_fattr*)msg->rpc_resp;
-               nfs_refresh_inode(dir->d_inode, dir_attr);
+               nfs_post_op_update_inode(dir->d_inode, dir_attr);
                kfree(msg->rpc_argp);
        }
        return 0;
@@ -468,8 +468,8 @@ nfs3_proc_rename(struct inode *old_dir, struct qstr *old_name,
        nfs_fattr_init(&old_dir_attr);
        nfs_fattr_init(&new_dir_attr);
        status = rpc_call(NFS_CLIENT(old_dir), NFS3PROC_RENAME, &arg, &res, 0);
-       nfs_refresh_inode(old_dir, &old_dir_attr);
-       nfs_refresh_inode(new_dir, &new_dir_attr);
+       nfs_post_op_update_inode(old_dir, &old_dir_attr);
+       nfs_post_op_update_inode(new_dir, &new_dir_attr);
        dprintk("NFS reply rename: %d\n", status);
        return status;
 }
@@ -494,8 +494,8 @@ nfs3_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
        nfs_fattr_init(&dir_attr);
        nfs_fattr_init(&fattr);
        status = rpc_call(NFS_CLIENT(inode), NFS3PROC_LINK, &arg, &res, 0);
-       nfs_refresh_inode(dir, &dir_attr);
-       nfs_refresh_inode(inode, &fattr);
+       nfs_post_op_update_inode(dir, &dir_attr);
+       nfs_post_op_update_inode(inode, &fattr);
        dprintk("NFS reply link: %d\n", status);
        return status;
 }
@@ -527,7 +527,7 @@ nfs3_proc_symlink(struct inode *dir, struct qstr *name, struct qstr *path,
        nfs_fattr_init(&dir_attr);
        nfs_fattr_init(fattr);
        status = rpc_call(NFS_CLIENT(dir), NFS3PROC_SYMLINK, &arg, &res, 0);
-       nfs_refresh_inode(dir, &dir_attr);
+       nfs_post_op_update_inode(dir, &dir_attr);
        dprintk("NFS reply symlink: %d\n", status);
        return status;
 }
@@ -558,7 +558,7 @@ nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
        nfs_fattr_init(&dir_attr);
        nfs_fattr_init(&fattr);
        status = rpc_call(NFS_CLIENT(dir), NFS3PROC_MKDIR, &arg, &res, 0);
-       nfs_refresh_inode(dir, &dir_attr);
+       nfs_post_op_update_inode(dir, &dir_attr);
        if (status != 0)
                goto out;
        status = nfs_instantiate(dentry, &fhandle, &fattr);
@@ -584,7 +584,7 @@ nfs3_proc_rmdir(struct inode *dir, struct qstr *name)
        dprintk("NFS call  rmdir %s\n", name->name);
        nfs_fattr_init(&dir_attr);
        status = rpc_call(NFS_CLIENT(dir), NFS3PROC_RMDIR, &arg, &dir_attr, 0);
-       nfs_refresh_inode(dir, &dir_attr);
+       nfs_post_op_update_inode(dir, &dir_attr);
        dprintk("NFS reply rmdir: %d\n", status);
        return status;
 }
@@ -679,7 +679,7 @@ nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
        nfs_fattr_init(&dir_attr);
        nfs_fattr_init(&fattr);
        status = rpc_call(NFS_CLIENT(dir), NFS3PROC_MKNOD, &arg, &res, 0);
-       nfs_refresh_inode(dir, &dir_attr);
+       nfs_post_op_update_inode(dir, &dir_attr);
        if (status != 0)
                goto out;
        status = nfs_instantiate(dentry, &fh, &fattr);
@@ -775,7 +775,7 @@ nfs3_write_done(struct rpc_task *task)
                return;
        data = (struct nfs_write_data *)task->tk_calldata;
        if (task->tk_status >= 0)
-               nfs_refresh_inode(data->inode, data->res.fattr);
+               nfs_post_op_update_inode(data->inode, data->res.fattr);
        nfs_writeback_done(task);
 }
 
@@ -819,7 +819,7 @@ nfs3_commit_done(struct rpc_task *task)
                return;
        data = (struct nfs_write_data *)task->tk_calldata;
        if (task->tk_status >= 0)
-               nfs_refresh_inode(data->inode, data->res.fattr);
+               nfs_post_op_update_inode(data->inode, data->res.fattr);
        nfs_commit_done(task);
 }
 
index 2a759e8e387c85012c0bd137f786601f32d171e9..3274f2d354f3a409f71271641429756386906ab3 100644 (file)
@@ -187,8 +187,11 @@ static void update_changeattr(struct inode *inode, struct nfs4_change_info *cinf
 {
        struct nfs_inode *nfsi = NFS_I(inode);
 
+       spin_lock(&inode->i_lock);
+       nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
        if (cinfo->before == nfsi->change_attr && cinfo->atomic)
                nfsi->change_attr = cinfo->after;
+       spin_unlock(&inode->i_lock);
 }
 
 /* Helper for asynchronous RPC calls */
index 5ef28f08f424ef9bc262eecb10401c5f6f094e7d..a48a003242c006c94f8823fdc081d3c03289289e 100644 (file)
@@ -206,7 +206,7 @@ static int nfs_proc_write(struct nfs_write_data *wdata)
        nfs_fattr_init(fattr);
        status = rpc_call_sync(NFS_CLIENT(inode), &msg, flags);
        if (status >= 0) {
-               nfs_refresh_inode(inode, fattr);
+               nfs_post_op_update_inode(inode, fattr);
                wdata->res.count = wdata->args.count;
                wdata->verf.committed = NFS_FILE_SYNC;
        }
@@ -275,6 +275,7 @@ nfs_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
 
        nfs_fattr_init(&fattr);
        status = rpc_call(NFS_CLIENT(dir), NFSPROC_CREATE, &arg, &res, 0);
+       nfs_mark_for_revalidate(dir);
 
        if (status == -EINVAL && S_ISFIFO(mode)) {
                sattr->ia_mode = mode;
@@ -305,6 +306,7 @@ nfs_proc_remove(struct inode *dir, struct qstr *name)
 
        dprintk("NFS call  remove %s\n", name->name);
        status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
+       nfs_mark_for_revalidate(dir);
 
        dprintk("NFS reply remove: %d\n", status);
        return status;
@@ -331,8 +333,10 @@ nfs_proc_unlink_done(struct dentry *dir, struct rpc_task *task)
 {
        struct rpc_message *msg = &task->tk_msg;
        
-       if (msg->rpc_argp)
+       if (msg->rpc_argp) {
+               nfs_mark_for_revalidate(dir->d_inode);
                kfree(msg->rpc_argp);
+       }
        return 0;
 }
 
@@ -352,6 +356,8 @@ nfs_proc_rename(struct inode *old_dir, struct qstr *old_name,
 
        dprintk("NFS call  rename %s -> %s\n", old_name->name, new_name->name);
        status = rpc_call(NFS_CLIENT(old_dir), NFSPROC_RENAME, &arg, NULL, 0);
+       nfs_mark_for_revalidate(old_dir);
+       nfs_mark_for_revalidate(new_dir);
        dprintk("NFS reply rename: %d\n", status);
        return status;
 }
@@ -369,6 +375,7 @@ nfs_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
 
        dprintk("NFS call  link %s\n", name->name);
        status = rpc_call(NFS_CLIENT(inode), NFSPROC_LINK, &arg, NULL, 0);
+       nfs_mark_for_revalidate(dir);
        dprintk("NFS reply link: %d\n", status);
        return status;
 }
@@ -394,6 +401,7 @@ nfs_proc_symlink(struct inode *dir, struct qstr *name, struct qstr *path,
        nfs_fattr_init(fattr);
        fhandle->size = 0;
        status = rpc_call(NFS_CLIENT(dir), NFSPROC_SYMLINK, &arg, NULL, 0);
+       nfs_mark_for_revalidate(dir);
        dprintk("NFS reply symlink: %d\n", status);
        return status;
 }
@@ -418,6 +426,7 @@ nfs_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
        dprintk("NFS call  mkdir %s\n", dentry->d_name.name);
        nfs_fattr_init(&fattr);
        status = rpc_call(NFS_CLIENT(dir), NFSPROC_MKDIR, &arg, &res, 0);
+       nfs_mark_for_revalidate(dir);
        if (status == 0)
                status = nfs_instantiate(dentry, &fhandle, &fattr);
        dprintk("NFS reply mkdir: %d\n", status);
@@ -436,6 +445,7 @@ nfs_proc_rmdir(struct inode *dir, struct qstr *name)
 
        dprintk("NFS call  rmdir %s\n", name->name);
        status = rpc_call(NFS_CLIENT(dir), NFSPROC_RMDIR, &arg, NULL, 0);
+       nfs_mark_for_revalidate(dir);
        dprintk("NFS reply rmdir: %d\n", status);
        return status;
 }
@@ -579,7 +589,7 @@ nfs_write_done(struct rpc_task *task)
        struct nfs_write_data *data = (struct nfs_write_data *) task->tk_calldata;
 
        if (task->tk_status >= 0)
-               nfs_refresh_inode(data->inode, data->res.fattr);
+               nfs_post_op_update_inode(data->inode, data->res.fattr);
        nfs_writeback_done(task);
 }
 
index faeaad666ca85a572800b1a1808a7edc5f45fcc7..325fe7ae49bb7be58270b261c52640de10085535 100644 (file)
@@ -241,13 +241,17 @@ static inline int nfs_caches_unstable(struct inode *inode)
        return atomic_read(&NFS_I(inode)->data_updates) != 0;
 }
 
+static inline void nfs_mark_for_revalidate(struct inode *inode)
+{
+       spin_lock(&inode->i_lock);
+       NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS;
+       spin_unlock(&inode->i_lock);
+}
+
 static inline void NFS_CACHEINV(struct inode *inode)
 {
-       if (!nfs_caches_unstable(inode)) {
-               spin_lock(&inode->i_lock);
-               NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS;
-               spin_unlock(&inode->i_lock);
-       }
+       if (!nfs_caches_unstable(inode))
+               nfs_mark_for_revalidate(inode);
 }
 
 static inline int nfs_server_capable(struct inode *inode, int cap)
@@ -291,6 +295,7 @@ extern void nfs_zap_caches(struct inode *);
 extern struct inode *nfs_fhget(struct super_block *, struct nfs_fh *,
                                struct nfs_fattr *);
 extern int nfs_refresh_inode(struct inode *, struct nfs_fattr *);
+extern int nfs_post_op_update_inode(struct inode *inode, struct nfs_fattr *fattr);
 extern int nfs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
 extern int nfs_permission(struct inode *, int, struct nameidata *);
 extern int nfs_access_get_cached(struct inode *, struct rpc_cred *, struct nfs_access_entry *);