]> err.no Git - linux-2.6/commitdiff
[PATCH] NFS: Cleanup of caching code, and slight optimization of writes.
authorTrond Myklebust <Trond.Myklebust@netapp.com>
Wed, 22 Jun 2005 17:16:30 +0000 (17:16 +0000)
committerTrond Myklebust <Trond.Myklebust@netapp.com>
Wed, 22 Jun 2005 20:07:37 +0000 (16:07 -0400)
 Unless we're doing O_APPEND writes, we really don't care about revalidating
 the file length. Just make sure that we catch any page cache invalidations.

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

index a606708264edb9802bef65b19240b1d049cbc643..40436857ed42d88263fb7d9a9ae450db7c2e414e 100644 (file)
@@ -333,9 +333,15 @@ nfs_file_write(struct kiocb *iocb, const char __user *buf, size_t count, loff_t
        result = -EBUSY;
        if (IS_SWAPFILE(inode))
                goto out_swapfile;
-       result = nfs_revalidate_inode(NFS_SERVER(inode), inode);
-       if (result)
-               goto out;
+       /*
+        * O_APPEND implies that we must revalidate the file length.
+        */
+       if (iocb->ki_filp->f_flags & O_APPEND) {
+               result = nfs_revalidate_file_size(inode, iocb->ki_filp);
+               if (result)
+                       goto out;
+       } else
+               nfs_revalidate_mapping(inode, iocb->ki_filp->f_mapping);
 
        result = count;
        if (!count)
index b2d16758ced86a6d5f608a3932927aea12000b81..a3922f4cc0a88e7837c0e594d60cf6f321dbd49a 100644 (file)
@@ -1062,21 +1062,7 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
        if (verifier == nfsi->cache_change_attribute)
                nfsi->flags &= ~(NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ATIME);
        /* Do the page cache invalidation */
-       if (flags & NFS_INO_INVALID_DATA) {
-               if (S_ISREG(inode->i_mode)) {
-                       if (filemap_fdatawrite(inode->i_mapping) == 0)
-                               filemap_fdatawait(inode->i_mapping);
-                       nfs_wb_all(inode);
-               }
-               nfsi->flags &= ~NFS_INO_INVALID_DATA;
-               invalidate_inode_pages2(inode->i_mapping);
-               memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
-               dfprintk(PAGECACHE, "NFS: (%s/%Ld) data cache invalidated\n",
-                               inode->i_sb->s_id,
-                               (long long)NFS_FILEID(inode));
-               /* This ensures we revalidate dentries */
-               nfsi->cache_change_attribute++;
-       }
+       nfs_revalidate_mapping(inode, inode->i_mapping);
        if (flags & NFS_INO_INVALID_ACL)
                nfs_zap_acl_cache(inode);
        dfprintk(PAGECACHE, "NFS: (%s/%Ld) revalidation complete\n",
@@ -1115,6 +1101,34 @@ int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
        return __nfs_revalidate_inode(server, inode);
 }
 
+/**
+ * nfs_revalidate_mapping - Revalidate the pagecache
+ * @inode - pointer to host inode
+ * @mapping - pointer to mapping
+ */
+void nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
+{
+       struct nfs_inode *nfsi = NFS_I(inode);
+
+       if (nfsi->flags & NFS_INO_INVALID_DATA) {
+               if (S_ISREG(inode->i_mode)) {
+                       if (filemap_fdatawrite(mapping) == 0)
+                               filemap_fdatawait(mapping);
+                       nfs_wb_all(inode);
+               }
+               invalidate_inode_pages2(mapping);
+               nfsi->flags &= ~NFS_INO_INVALID_DATA;
+               if (S_ISDIR(inode->i_mode)) {
+                       memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
+                       /* This ensures we revalidate child dentries */
+                       nfsi->cache_change_attribute++;
+               }
+               dfprintk(PAGECACHE, "NFS: (%s/%Ld) data cache invalidated\n",
+                               inode->i_sb->s_id,
+                               (long long)NFS_FILEID(inode));
+       }
+}
+
 /**
  * nfs_begin_data_update
  * @inode - pointer to inode
index 211266c56ce537d9df63c281f97e45121e3ffa6f..443103c13e53c3c3509b9f6691dca57e59fd65a4 100644 (file)
@@ -289,6 +289,7 @@ extern int nfs_release(struct inode *, struct file *);
 extern int nfs_attribute_timeout(struct inode *inode);
 extern int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode);
 extern int __nfs_revalidate_inode(struct nfs_server *, struct inode *);
+extern void nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping);
 extern int nfs_setattr(struct dentry *, struct iattr *);
 extern void nfs_begin_attr_update(struct inode *);
 extern void nfs_end_attr_update(struct inode *);