Btrfs: factor page private preparations into a helper
authorChristoph Hellwig <hch@lst.de>
Mon, 17 Sep 2007 15:25:58 +0000 (11:25 -0400)
committerChris Mason <chris.mason@oracle.com>
Thu, 25 Sep 2008 15:03:56 +0000 (11:03 -0400)
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
fs/btrfs/extent_map.c
fs/btrfs/extent_map.h
fs/btrfs/file.c
fs/btrfs/inode.c

index ab5bde31b6875001bf846eacce6b98a8a864800c..0ab368e091f95df88e9cdba7622f901d306ceb5e 100644 (file)
@@ -1379,6 +1379,16 @@ static int submit_extent_page(int rw, struct extent_map_tree *tree,
        return ret;
 }
 
+void set_page_extent_mapped(struct page *page)
+{
+       if (!PagePrivate(page)) {
+               SetPagePrivate(page);
+               WARN_ON(!page->mapping->a_ops->invalidatepage);
+               set_page_private(page, 1);
+               page_cache_get(page);
+       }
+}
+
 /*
  * basic readpage implementation.  Locked extent state structs are inserted
  * into the tree that are removed when the IO is done (by the end_io
@@ -1405,12 +1415,7 @@ int extent_read_full_page(struct extent_map_tree *tree, struct page *page,
        size_t iosize;
        size_t blocksize = inode->i_sb->s_blocksize;
 
-       if (!PagePrivate(page)) {
-               SetPagePrivate(page);
-               WARN_ON(!page->mapping->a_ops->invalidatepage);
-               set_page_private(page, 1);
-               page_cache_get(page);
-       }
+       set_page_extent_mapped(page);
 
        end = page_end;
        lock_extent(tree, start, end, GFP_NOFS);
@@ -1531,12 +1536,7 @@ int extent_write_full_page(struct extent_map_tree *tree, struct page *page,
                               PAGE_CACHE_SIZE - offset, KM_USER0);
        }
 
-       if (!PagePrivate(page)) {
-               SetPagePrivate(page);
-               set_page_private(page, 1);
-               WARN_ON(!page->mapping->a_ops->invalidatepage);
-               page_cache_get(page);
-       }
+       set_page_extent_mapped(page);
 
        lock_extent(tree, start, page_end, GFP_NOFS);
        nr_delalloc = find_lock_delalloc_range(tree, start, page_end + 1,
@@ -1672,13 +1672,7 @@ int extent_commit_write(struct extent_map_tree *tree,
 {
        loff_t pos = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to;
 
-       if (!PagePrivate(page)) {
-               SetPagePrivate(page);
-               set_page_private(page, 1);
-               WARN_ON(!page->mapping->a_ops->invalidatepage);
-               page_cache_get(page);
-       }
-
+       set_page_extent_mapped(page);
        set_page_dirty(page);
 
        if (pos > inode->i_size) {
@@ -1709,12 +1703,8 @@ int extent_prepare_write(struct extent_map_tree *tree,
        int ret = 0;
        int isnew;
 
-       if (!PagePrivate(page)) {
-               SetPagePrivate(page);
-               set_page_private(page, 1);
-               WARN_ON(!page->mapping->a_ops->invalidatepage);
-               page_cache_get(page);
-       }
+       set_page_extent_mapped(page);
+
        block_start = (page_start + from) & ~((u64)blocksize - 1);
        block_end = (page_start + to - 1) | (blocksize - 1);
        orig_block_start = block_start;
index 40b53ee274fb2d79e45117abed4a7839929ed8b7..d913ce01248dfb5e056b0217a95a2c19683495ef 100644 (file)
@@ -105,4 +105,5 @@ sector_t extent_bmap(struct address_space *mapping, sector_t iblock,
 int set_range_dirty(struct extent_map_tree *tree, u64 start, u64 end);
 int set_state_private(struct extent_map_tree *tree, u64 start, u64 private);
 int get_state_private(struct extent_map_tree *tree, u64 start, u64 *private);
+void set_page_extent_mapped(struct page *page);
 #endif
index 698eaea612f1e3f82e0d28039a3b3901e43cad1e..4cc459c943ecede0487183a97bfd44f5a4c7cf80 100644 (file)
@@ -543,12 +543,7 @@ static int prepare_pages(struct btrfs_root *root,
                }
                cancel_dirty_page(pages[i], PAGE_CACHE_SIZE);
                wait_on_page_writeback(pages[i]);
-               if (!PagePrivate(pages[i])) {
-                       SetPagePrivate(pages[i]);
-                       set_page_private(pages[i], 1);
-                       WARN_ON(!pages[i]->mapping->a_ops->invalidatepage);
-                       page_cache_get(pages[i]);
-               }
+               set_page_extent_mapped(pages[i]);
                WARN_ON(!PageLocked(pages[i]));
        }
        return 0;
index 88b3ef20be69d230cbf5f9a5723f065c762c0ab9..0df325f89d62bf9cef3861a440da57d86ec46667 100644 (file)
@@ -652,12 +652,7 @@ static int btrfs_cow_one_page(struct inode *inode, struct page *page,
        u64 page_start = page->index << PAGE_CACHE_SHIFT;
        u64 page_end = page_start + PAGE_CACHE_SIZE - 1;
 
-       if (!PagePrivate(page)) {
-               SetPagePrivate(page);
-               set_page_private(page, 1);
-               WARN_ON(!page->mapping->a_ops->invalidatepage);
-               page_cache_get(page);
-       }
+       set_page_extent_mapped(page);
 
        lock_extent(em_tree, page_start, page_end, GFP_NOFS);
        set_extent_delalloc(&BTRFS_I(inode)->extent_tree, page_start,