xfs: use range primitives for xfs page cache operations
authorDave Chinner <dchinner@redhat.com>
Tue, 24 Aug 2010 02:01:50 +0000 (12:01 +1000)
committerAlex Elder <aelder@sgi.com>
Mon, 18 Oct 2010 20:07:24 +0000 (15:07 -0500)
While XFS passes ranges to operate on from the core code, the
functions being called ignore the either the entire range or the end
of the range. This is historical because when the function were
written linux didn't have the necessary range operations. Update the
functions to use the correct operations.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/xfs/linux-2.6/xfs_fs_subr.c

index 1f279b0..ed88ed1 100644 (file)
@@ -32,10 +32,9 @@ xfs_tosspages(
        xfs_off_t       last,
        int             fiopt)
 {
-       struct address_space *mapping = VFS_I(ip)->i_mapping;
-
-       if (mapping->nrpages)
-               truncate_inode_pages(mapping, first);
+       /* can't toss partial tail pages, so mask them out */
+       last &= ~(PAGE_SIZE - 1);
+       truncate_inode_pages_range(VFS_I(ip)->i_mapping, first, last - 1);
 }
 
 int
@@ -50,12 +49,11 @@ xfs_flushinval_pages(
 
        trace_xfs_pagecache_inval(ip, first, last);
 
-       if (mapping->nrpages) {
-               xfs_iflags_clear(ip, XFS_ITRUNCATED);
-               ret = filemap_write_and_wait(mapping);
-               if (!ret)
-                       truncate_inode_pages(mapping, first);
-       }
+       xfs_iflags_clear(ip, XFS_ITRUNCATED);
+       ret = filemap_write_and_wait_range(mapping, first,
+                               last == -1 ? LLONG_MAX : last);
+       if (!ret)
+               truncate_inode_pages_range(mapping, first, last);
        return -ret;
 }
 
@@ -71,10 +69,9 @@ xfs_flush_pages(
        int             ret = 0;
        int             ret2;
 
-       if (mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) {
-               xfs_iflags_clear(ip, XFS_ITRUNCATED);
-               ret = -filemap_fdatawrite(mapping);
-       }
+       xfs_iflags_clear(ip, XFS_ITRUNCATED);
+       ret = -filemap_fdatawrite_range(mapping, first,
+                               last == -1 ? LLONG_MAX : last);
        if (flags & XBF_ASYNC)
                return ret;
        ret2 = xfs_wait_on_pages(ip, first, last);
@@ -91,7 +88,9 @@ xfs_wait_on_pages(
 {
        struct address_space *mapping = VFS_I(ip)->i_mapping;
 
-       if (mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK))
-               return -filemap_fdatawait(mapping);
+       if (mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK)) {
+               return -filemap_fdatawait_range(mapping, first,
+                                       last == -1 ? ip->i_size - 1 : last);
+       }
        return 0;
 }