Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=70ca88521fc7bee8ef0fc22033a439d4b9a2c70d
Commit:     70ca88521fc7bee8ef0fc22033a439d4b9a2c70d
Parent:     b64e8a5ef758888cb42b7c105dcfaaf51aab1baf
Author:     Trond Myklebust <[EMAIL PROTECTED]>
AuthorDate: Sun Sep 30 15:21:24 2007 -0400
Committer:  Trond Myklebust <[EMAIL PROTECTED]>
CommitDate: Tue Oct 9 17:19:15 2007 -0400

    NFS: Fake up 'wcc' attributes to prevent cache invalidation after write
    
    NFSv2 and v4 don't offer weak cache consistency attributes on WRITE calls.
    In NFSv3, returning wcc data is optional. In all cases, we want to prevent
    the client from invalidating our cached data whenever ->write_done()
    attempts to update the inode attributes.
    
    Signed-off-by: Trond Myklebust <[EMAIL PROTECTED]>
---
 fs/nfs/inode.c          |   34 ++++++++++++++++++++++++++++++++++
 fs/nfs/nfs3proc.c       |    2 +-
 fs/nfs/nfs4proc.c       |    2 +-
 fs/nfs/proc.c           |    2 +-
 include/linux/nfs_fs.h  |    1 +
 include/linux/nfs_xdr.h |    3 ++-
 6 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 23feb9e..c5f4e05 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -793,6 +793,12 @@ static void nfs_wcc_update_inode(struct inode *inode, 
struct nfs_fattr *fattr)
 {
        struct nfs_inode *nfsi = NFS_I(inode);
 
+       if ((fattr->valid & NFS_ATTR_WCC_V4) != 0 &&
+                       nfsi->change_attr == fattr->pre_change_attr) {
+               nfsi->change_attr = fattr->change_attr;
+               if (S_ISDIR(inode->i_mode))
+                       nfsi->cache_validity |= NFS_INO_INVALID_DATA;
+       }
        /* If we have atomic WCC data, we may update some attributes */
        if ((fattr->valid & NFS_ATTR_WCC) != 0) {
                if (timespec_equal(&inode->i_ctime, &fattr->pre_ctime))
@@ -923,6 +929,34 @@ out:
        return status;
 }
 
+/**
+ * nfs_post_op_update_inode_force_wcc - 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. Fake up
+ * weak cache consistency data, if none exist.
+ *
+ * This function is mainly designed to be used by the ->write_done() functions.
+ */
+int nfs_post_op_update_inode_force_wcc(struct inode *inode, struct nfs_fattr 
*fattr)
+{
+       if ((fattr->valid & NFS_ATTR_FATTR_V4) != 0 &&
+                       (fattr->valid & NFS_ATTR_WCC_V4) == 0) {
+               fattr->pre_change_attr = NFS_I(inode)->change_attr;
+               fattr->valid |= NFS_ATTR_WCC_V4;
+       }
+       if ((fattr->valid & NFS_ATTR_FATTR) != 0 &&
+                       (fattr->valid & NFS_ATTR_WCC) == 0) {
+               memcpy(&fattr->pre_ctime, &inode->i_ctime, 
sizeof(fattr->pre_ctime));
+               memcpy(&fattr->pre_mtime, &inode->i_mtime, 
sizeof(fattr->pre_mtime));
+               fattr->pre_size = inode->i_size;
+               fattr->valid |= NFS_ATTR_WCC;
+       }
+       return nfs_post_op_update_inode(inode, fattr);
+}
+
 /*
  * Many nfs protocol calls return the new file attributes after
  * an operation.  Here we update the inode to reflect the state
diff --git a/fs/nfs/nfs3proc.c b/fs/nfs/nfs3proc.c
index fc6b119..ce1fb99 100644
--- a/fs/nfs/nfs3proc.c
+++ b/fs/nfs/nfs3proc.c
@@ -750,7 +750,7 @@ static int nfs3_write_done(struct rpc_task *task, struct 
nfs_write_data *data)
        if (nfs3_async_handle_jukebox(task, data->inode))
                return -EAGAIN;
        if (task->tk_status >= 0)
-               nfs_post_op_update_inode(data->inode, data->res.fattr);
+               nfs_post_op_update_inode_force_wcc(data->inode, 
data->res.fattr);
        return 0;
 }
 
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index d311984..796bc8e 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -2427,7 +2427,7 @@ static int nfs4_write_done(struct rpc_task *task, struct 
nfs_write_data *data)
        }
        if (task->tk_status >= 0) {
                renew_lease(NFS_SERVER(inode), data->timestamp);
-               nfs_post_op_update_inode(inode, data->res.fattr);
+               nfs_post_op_update_inode_force_wcc(inode, data->res.fattr);
        }
        return 0;
 }
diff --git a/fs/nfs/proc.c b/fs/nfs/proc.c
index ec3ede8..97669ed 100644
--- a/fs/nfs/proc.c
+++ b/fs/nfs/proc.c
@@ -579,7 +579,7 @@ static void nfs_proc_read_setup(struct nfs_read_data *data)
 static int nfs_write_done(struct rpc_task *task, struct nfs_write_data *data)
 {
        if (task->tk_status >= 0)
-               nfs_post_op_update_inode(data->inode, data->res.fattr);
+               nfs_post_op_update_inode_force_wcc(data->inode, 
data->res.fattr);
        return 0;
 }
 
diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h
index 63850a8..9449286 100644
--- a/include/linux/nfs_fs.h
+++ b/include/linux/nfs_fs.h
@@ -293,6 +293,7 @@ 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_post_op_update_inode_force_wcc(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_open(struct inode *, struct file *);
diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h
index 0303201..daab252 100644
--- a/include/linux/nfs_xdr.h
+++ b/include/linux/nfs_xdr.h
@@ -62,7 +62,8 @@ struct nfs_fattr {
 #define NFS_ATTR_FATTR         0x0002          /* post-op attributes */
 #define NFS_ATTR_FATTR_V3      0x0004          /* NFSv3 attributes */
 #define NFS_ATTR_FATTR_V4      0x0008          /* NFSv4 change attribute */
-#define NFS_ATTR_FATTR_V4_REFERRAL     0x0010          /* NFSv4 referral */
+#define NFS_ATTR_WCC_V4                0x0010          /* pre-op change 
attribute */
+#define NFS_ATTR_FATTR_V4_REFERRAL     0x0020          /* NFSv4 referral */
 
 /*
  * Info on the file system
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to