Commit c2790a2e authored by Josef Bacik's avatar Josef Bacik Committed by Chris Mason

Btrfs: cleanup arguments to extent_clear_unlock_delalloc

This patch removes the io_tree argument for extent_clear_unlock_delalloc since
we always use &BTRFS_I(inode)->io_tree, and it separates out the extent tree
operations from the page operations.  This way we just pass in the extent bits
we want to clear and then pass in the operations we want done to the pages.
This is because I'm going to fix what extent bits we clear in some cases and
rather than add a bunch of new flags we'll just use the actual extent bits we
want to clear.  Thanks,
Signed-off-by: default avatarJosef Bacik <jbacik@fusionio.com>
Signed-off-by: default avatarChris Mason <chris.mason@fusionio.com>
parent 8068a47e
...@@ -1678,31 +1678,21 @@ static noinline u64 find_lock_delalloc_range(struct inode *inode, ...@@ -1678,31 +1678,21 @@ static noinline u64 find_lock_delalloc_range(struct inode *inode,
return found; return found;
} }
int extent_clear_unlock_delalloc(struct inode *inode, int extent_clear_unlock_delalloc(struct inode *inode, u64 start, u64 end,
struct extent_io_tree *tree, struct page *locked_page,
u64 start, u64 end, struct page *locked_page, unsigned long clear_bits,
unsigned long op) unsigned long page_ops)
{ {
struct extent_io_tree *tree = &BTRFS_I(inode)->io_tree;
int ret; int ret;
struct page *pages[16]; struct page *pages[16];
unsigned long index = start >> PAGE_CACHE_SHIFT; unsigned long index = start >> PAGE_CACHE_SHIFT;
unsigned long end_index = end >> PAGE_CACHE_SHIFT; unsigned long end_index = end >> PAGE_CACHE_SHIFT;
unsigned long nr_pages = end_index - index + 1; unsigned long nr_pages = end_index - index + 1;
int i; int i;
unsigned long clear_bits = 0;
if (op & EXTENT_CLEAR_UNLOCK)
clear_bits |= EXTENT_LOCKED;
if (op & EXTENT_CLEAR_DIRTY)
clear_bits |= EXTENT_DIRTY;
if (op & EXTENT_CLEAR_DELALLOC)
clear_bits |= EXTENT_DELALLOC;
clear_extent_bit(tree, start, end, clear_bits, 1, 0, NULL, GFP_NOFS); clear_extent_bit(tree, start, end, clear_bits, 1, 0, NULL, GFP_NOFS);
if (!(op & (EXTENT_CLEAR_UNLOCK_PAGE | EXTENT_CLEAR_DIRTY | if (page_ops == 0)
EXTENT_SET_WRITEBACK | EXTENT_END_WRITEBACK |
EXTENT_SET_PRIVATE2)))
return 0; return 0;
while (nr_pages > 0) { while (nr_pages > 0) {
...@@ -1711,20 +1701,20 @@ int extent_clear_unlock_delalloc(struct inode *inode, ...@@ -1711,20 +1701,20 @@ int extent_clear_unlock_delalloc(struct inode *inode,
nr_pages, ARRAY_SIZE(pages)), pages); nr_pages, ARRAY_SIZE(pages)), pages);
for (i = 0; i < ret; i++) { for (i = 0; i < ret; i++) {
if (op & EXTENT_SET_PRIVATE2) if (page_ops & PAGE_SET_PRIVATE2)
SetPagePrivate2(pages[i]); SetPagePrivate2(pages[i]);
if (pages[i] == locked_page) { if (pages[i] == locked_page) {
page_cache_release(pages[i]); page_cache_release(pages[i]);
continue; continue;
} }
if (op & EXTENT_CLEAR_DIRTY) if (page_ops & PAGE_CLEAR_DIRTY)
clear_page_dirty_for_io(pages[i]); clear_page_dirty_for_io(pages[i]);
if (op & EXTENT_SET_WRITEBACK) if (page_ops & PAGE_SET_WRITEBACK)
set_page_writeback(pages[i]); set_page_writeback(pages[i]);
if (op & EXTENT_END_WRITEBACK) if (page_ops & PAGE_END_WRITEBACK)
end_page_writeback(pages[i]); end_page_writeback(pages[i]);
if (op & EXTENT_CLEAR_UNLOCK_PAGE) if (page_ops & PAGE_UNLOCK)
unlock_page(pages[i]); unlock_page(pages[i]);
page_cache_release(pages[i]); page_cache_release(pages[i]);
} }
......
...@@ -44,14 +44,11 @@ ...@@ -44,14 +44,11 @@
#define EXTENT_BUFFER_DUMMY 9 #define EXTENT_BUFFER_DUMMY 9
/* these are flags for extent_clear_unlock_delalloc */ /* these are flags for extent_clear_unlock_delalloc */
#define EXTENT_CLEAR_UNLOCK_PAGE 0x1 #define PAGE_UNLOCK (1 << 0)
#define EXTENT_CLEAR_UNLOCK 0x2 #define PAGE_CLEAR_DIRTY (1 << 1)
#define EXTENT_CLEAR_DELALLOC 0x4 #define PAGE_SET_WRITEBACK (1 << 2)
#define EXTENT_CLEAR_DIRTY 0x8 #define PAGE_END_WRITEBACK (1 << 3)
#define EXTENT_SET_WRITEBACK 0x10 #define PAGE_SET_PRIVATE2 (1 << 4)
#define EXTENT_END_WRITEBACK 0x20
#define EXTENT_SET_PRIVATE2 0x40
#define EXTENT_CLEAR_ACCOUNTING 0x80
/* /*
* page->private values. Every page that is controlled by the extent * page->private values. Every page that is controlled by the extent
...@@ -328,10 +325,10 @@ int map_private_extent_buffer(struct extent_buffer *eb, unsigned long offset, ...@@ -328,10 +325,10 @@ int map_private_extent_buffer(struct extent_buffer *eb, unsigned long offset,
unsigned long *map_len); unsigned long *map_len);
int extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end); int extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end);
int extent_range_redirty_for_io(struct inode *inode, u64 start, u64 end); int extent_range_redirty_for_io(struct inode *inode, u64 start, u64 end);
int extent_clear_unlock_delalloc(struct inode *inode, int extent_clear_unlock_delalloc(struct inode *inode, u64 start, u64 end,
struct extent_io_tree *tree, struct page *locked_page,
u64 start, u64 end, struct page *locked_page, unsigned long bits_to_clear,
unsigned long op); unsigned long page_ops);
struct bio * struct bio *
btrfs_bio_alloc(struct block_device *bdev, u64 first_sector, int nr_vecs, btrfs_bio_alloc(struct block_device *bdev, u64 first_sector, int nr_vecs,
gfp_t gfp_flags); gfp_t gfp_flags);
......
...@@ -489,13 +489,13 @@ static noinline int compress_file_range(struct inode *inode, ...@@ -489,13 +489,13 @@ static noinline int compress_file_range(struct inode *inode,
* we don't need to create any more async work items. * we don't need to create any more async work items.
* Unlock and free up our temp pages. * Unlock and free up our temp pages.
*/ */
extent_clear_unlock_delalloc(inode, extent_clear_unlock_delalloc(inode, start, end, NULL,
&BTRFS_I(inode)->io_tree, EXTENT_DIRTY |
start, end, NULL, EXTENT_DELALLOC,
EXTENT_CLEAR_UNLOCK_PAGE | EXTENT_CLEAR_DIRTY | PAGE_UNLOCK |
EXTENT_CLEAR_DELALLOC | PAGE_CLEAR_DIRTY |
EXTENT_SET_WRITEBACK | EXTENT_END_WRITEBACK); PAGE_SET_WRITEBACK |
PAGE_END_WRITEBACK);
btrfs_end_transaction(trans, root); btrfs_end_transaction(trans, root);
goto free_pages_out; goto free_pages_out;
} }
...@@ -592,13 +592,10 @@ static noinline int compress_file_range(struct inode *inode, ...@@ -592,13 +592,10 @@ static noinline int compress_file_range(struct inode *inode,
goto out; goto out;
cleanup_and_out: cleanup_and_out:
extent_clear_unlock_delalloc(inode, &BTRFS_I(inode)->io_tree, extent_clear_unlock_delalloc(inode, start, end, NULL,
start, end, NULL, EXTENT_DIRTY | EXTENT_DELALLOC,
EXTENT_CLEAR_UNLOCK_PAGE | PAGE_UNLOCK | PAGE_CLEAR_DIRTY |
EXTENT_CLEAR_DIRTY | PAGE_SET_WRITEBACK | PAGE_END_WRITEBACK);
EXTENT_CLEAR_DELALLOC |
EXTENT_SET_WRITEBACK |
EXTENT_END_WRITEBACK);
if (!trans || IS_ERR(trans)) if (!trans || IS_ERR(trans))
btrfs_error(root->fs_info, ret, "Failed to join transaction"); btrfs_error(root->fs_info, ret, "Failed to join transaction");
else else
...@@ -770,16 +767,12 @@ static noinline int submit_compressed_extents(struct inode *inode, ...@@ -770,16 +767,12 @@ static noinline int submit_compressed_extents(struct inode *inode,
/* /*
* clear dirty, set writeback and unlock the pages. * clear dirty, set writeback and unlock the pages.
*/ */
extent_clear_unlock_delalloc(inode, extent_clear_unlock_delalloc(inode, async_extent->start,
&BTRFS_I(inode)->io_tree,
async_extent->start,
async_extent->start + async_extent->start +
async_extent->ram_size - 1, async_extent->ram_size - 1,
NULL, EXTENT_CLEAR_UNLOCK_PAGE | NULL, EXTENT_LOCKED | EXTENT_DELALLOC |
EXTENT_CLEAR_UNLOCK | EXTENT_DIRTY, PAGE_UNLOCK | PAGE_CLEAR_DIRTY |
EXTENT_CLEAR_DELALLOC | PAGE_SET_WRITEBACK);
EXTENT_CLEAR_DIRTY | EXTENT_SET_WRITEBACK);
ret = btrfs_submit_compressed_write(inode, ret = btrfs_submit_compressed_write(inode,
async_extent->start, async_extent->start,
async_extent->ram_size, async_extent->ram_size,
...@@ -798,16 +791,13 @@ static noinline int submit_compressed_extents(struct inode *inode, ...@@ -798,16 +791,13 @@ static noinline int submit_compressed_extents(struct inode *inode,
out_free_reserve: out_free_reserve:
btrfs_free_reserved_extent(root, ins.objectid, ins.offset); btrfs_free_reserved_extent(root, ins.objectid, ins.offset);
out_free: out_free:
extent_clear_unlock_delalloc(inode, &BTRFS_I(inode)->io_tree, extent_clear_unlock_delalloc(inode, async_extent->start,
async_extent->start,
async_extent->start + async_extent->start +
async_extent->ram_size - 1, async_extent->ram_size - 1,
NULL, EXTENT_CLEAR_UNLOCK_PAGE | NULL, EXTENT_LOCKED | EXTENT_DELALLOC |
EXTENT_CLEAR_UNLOCK | EXTENT_DIRTY, PAGE_UNLOCK |
EXTENT_CLEAR_DELALLOC | PAGE_CLEAR_DIRTY | PAGE_SET_WRITEBACK |
EXTENT_CLEAR_DIRTY | PAGE_END_WRITEBACK);
EXTENT_SET_WRITEBACK |
EXTENT_END_WRITEBACK);
kfree(async_extent); kfree(async_extent);
goto again; goto again;
} }
...@@ -892,15 +882,11 @@ static noinline int __cow_file_range(struct btrfs_trans_handle *trans, ...@@ -892,15 +882,11 @@ static noinline int __cow_file_range(struct btrfs_trans_handle *trans,
ret = cow_file_range_inline(trans, root, inode, ret = cow_file_range_inline(trans, root, inode,
start, end, 0, 0, NULL); start, end, 0, 0, NULL);
if (ret == 0) { if (ret == 0) {
extent_clear_unlock_delalloc(inode, extent_clear_unlock_delalloc(inode, start, end, NULL,
&BTRFS_I(inode)->io_tree, EXTENT_LOCKED | EXTENT_DELALLOC |
start, end, NULL, EXTENT_DIRTY, PAGE_UNLOCK |
EXTENT_CLEAR_UNLOCK_PAGE | PAGE_CLEAR_DIRTY | PAGE_SET_WRITEBACK |
EXTENT_CLEAR_UNLOCK | PAGE_END_WRITEBACK);
EXTENT_CLEAR_DELALLOC |
EXTENT_CLEAR_DIRTY |
EXTENT_SET_WRITEBACK |
EXTENT_END_WRITEBACK);
*nr_written = *nr_written + *nr_written = *nr_written +
(end - start + PAGE_CACHE_SIZE) / PAGE_CACHE_SIZE; (end - start + PAGE_CACHE_SIZE) / PAGE_CACHE_SIZE;
...@@ -990,13 +976,13 @@ static noinline int __cow_file_range(struct btrfs_trans_handle *trans, ...@@ -990,13 +976,13 @@ static noinline int __cow_file_range(struct btrfs_trans_handle *trans,
* Do set the Private2 bit so we know this page was properly * Do set the Private2 bit so we know this page was properly
* setup for writepage * setup for writepage
*/ */
op = unlock ? EXTENT_CLEAR_UNLOCK_PAGE : 0; op = unlock ? PAGE_UNLOCK : 0;
op |= EXTENT_CLEAR_UNLOCK | EXTENT_CLEAR_DELALLOC | op |= PAGE_SET_PRIVATE2;
EXTENT_SET_PRIVATE2;
extent_clear_unlock_delalloc(inode, &BTRFS_I(inode)->io_tree, extent_clear_unlock_delalloc(inode, start,
start, start + ram_size - 1, start + ram_size - 1, locked_page,
locked_page, op); EXTENT_LOCKED | EXTENT_DELALLOC,
op);
disk_num_bytes -= cur_alloc_size; disk_num_bytes -= cur_alloc_size;
num_bytes -= cur_alloc_size; num_bytes -= cur_alloc_size;
alloc_hint = ins.objectid + ins.offset; alloc_hint = ins.objectid + ins.offset;
...@@ -1008,16 +994,11 @@ static noinline int __cow_file_range(struct btrfs_trans_handle *trans, ...@@ -1008,16 +994,11 @@ static noinline int __cow_file_range(struct btrfs_trans_handle *trans,
out_reserve: out_reserve:
btrfs_free_reserved_extent(root, ins.objectid, ins.offset); btrfs_free_reserved_extent(root, ins.objectid, ins.offset);
out_unlock: out_unlock:
extent_clear_unlock_delalloc(inode, extent_clear_unlock_delalloc(inode, start, end, locked_page,
&BTRFS_I(inode)->io_tree, EXTENT_LOCKED | EXTENT_DIRTY |
start, end, locked_page, EXTENT_DELALLOC, PAGE_UNLOCK |
EXTENT_CLEAR_UNLOCK_PAGE | PAGE_CLEAR_DIRTY | PAGE_SET_WRITEBACK |
EXTENT_CLEAR_UNLOCK | PAGE_END_WRITEBACK);
EXTENT_CLEAR_DELALLOC |
EXTENT_CLEAR_DIRTY |
EXTENT_SET_WRITEBACK |
EXTENT_END_WRITEBACK);
goto out; goto out;
} }
...@@ -1033,15 +1014,12 @@ static noinline int cow_file_range(struct inode *inode, ...@@ -1033,15 +1014,12 @@ static noinline int cow_file_range(struct inode *inode,
trans = btrfs_join_transaction(root); trans = btrfs_join_transaction(root);
if (IS_ERR(trans)) { if (IS_ERR(trans)) {
extent_clear_unlock_delalloc(inode, extent_clear_unlock_delalloc(inode, start, end, locked_page,
&BTRFS_I(inode)->io_tree, EXTENT_LOCKED | EXTENT_DELALLOC |
start, end, locked_page, EXTENT_DIRTY, PAGE_UNLOCK |
EXTENT_CLEAR_UNLOCK_PAGE | PAGE_CLEAR_DIRTY |
EXTENT_CLEAR_UNLOCK | PAGE_SET_WRITEBACK |
EXTENT_CLEAR_DELALLOC | PAGE_END_WRITEBACK);
EXTENT_CLEAR_DIRTY |
EXTENT_SET_WRITEBACK |
EXTENT_END_WRITEBACK);
return PTR_ERR(trans); return PTR_ERR(trans);
} }
trans->block_rsv = &root->fs_info->delalloc_block_rsv; trans->block_rsv = &root->fs_info->delalloc_block_rsv;
...@@ -1221,15 +1199,12 @@ static noinline int run_delalloc_nocow(struct inode *inode, ...@@ -1221,15 +1199,12 @@ static noinline int run_delalloc_nocow(struct inode *inode,
path = btrfs_alloc_path(); path = btrfs_alloc_path();
if (!path) { if (!path) {
extent_clear_unlock_delalloc(inode, extent_clear_unlock_delalloc(inode, start, end, locked_page,
&BTRFS_I(inode)->io_tree, EXTENT_LOCKED | EXTENT_DELALLOC |
start, end, locked_page, EXTENT_DIRTY, PAGE_UNLOCK |
EXTENT_CLEAR_UNLOCK_PAGE | PAGE_CLEAR_DIRTY |
EXTENT_CLEAR_UNLOCK | PAGE_SET_WRITEBACK |
EXTENT_CLEAR_DELALLOC | PAGE_END_WRITEBACK);
EXTENT_CLEAR_DIRTY |
EXTENT_SET_WRITEBACK |
EXTENT_END_WRITEBACK);
return -ENOMEM; return -ENOMEM;
} }
...@@ -1241,15 +1216,12 @@ static noinline int run_delalloc_nocow(struct inode *inode, ...@@ -1241,15 +1216,12 @@ static noinline int run_delalloc_nocow(struct inode *inode,
trans = btrfs_join_transaction(root); trans = btrfs_join_transaction(root);
if (IS_ERR(trans)) { if (IS_ERR(trans)) {
extent_clear_unlock_delalloc(inode, extent_clear_unlock_delalloc(inode, start, end, locked_page,
&BTRFS_I(inode)->io_tree, EXTENT_LOCKED | EXTENT_DELALLOC |
start, end, locked_page, EXTENT_DIRTY, PAGE_UNLOCK |
EXTENT_CLEAR_UNLOCK_PAGE | PAGE_CLEAR_DIRTY |
EXTENT_CLEAR_UNLOCK | PAGE_SET_WRITEBACK |
EXTENT_CLEAR_DELALLOC | PAGE_END_WRITEBACK);
EXTENT_CLEAR_DIRTY |
EXTENT_SET_WRITEBACK |
EXTENT_END_WRITEBACK);
btrfs_free_path(path); btrfs_free_path(path);
return PTR_ERR(trans); return PTR_ERR(trans);
} }
...@@ -1428,11 +1400,11 @@ static noinline int run_delalloc_nocow(struct inode *inode, ...@@ -1428,11 +1400,11 @@ static noinline int run_delalloc_nocow(struct inode *inode,
} }
} }
extent_clear_unlock_delalloc(inode, &BTRFS_I(inode)->io_tree, extent_clear_unlock_delalloc(inode, cur_offset,
cur_offset, cur_offset + num_bytes - 1, cur_offset + num_bytes - 1,
locked_page, EXTENT_CLEAR_UNLOCK_PAGE | locked_page, EXTENT_LOCKED |
EXTENT_CLEAR_UNLOCK | EXTENT_CLEAR_DELALLOC | EXTENT_DELALLOC, PAGE_UNLOCK |
EXTENT_SET_PRIVATE2); PAGE_SET_PRIVATE2);
cur_offset = extent_end; cur_offset = extent_end;
if (cur_offset > end) if (cur_offset > end)
break; break;
...@@ -1460,16 +1432,12 @@ static noinline int run_delalloc_nocow(struct inode *inode, ...@@ -1460,16 +1432,12 @@ static noinline int run_delalloc_nocow(struct inode *inode,
ret = err; ret = err;
if (ret && cur_offset < end) if (ret && cur_offset < end)
extent_clear_unlock_delalloc(inode, extent_clear_unlock_delalloc(inode, cur_offset, end,
&BTRFS_I(inode)->io_tree, locked_page, EXTENT_LOCKED |
cur_offset, end, locked_page, EXTENT_DELALLOC | EXTENT_DIRTY,
EXTENT_CLEAR_UNLOCK_PAGE | PAGE_UNLOCK | PAGE_CLEAR_DIRTY |
EXTENT_CLEAR_UNLOCK | PAGE_SET_WRITEBACK |
EXTENT_CLEAR_DELALLOC | PAGE_END_WRITEBACK);
EXTENT_CLEAR_DIRTY |
EXTENT_SET_WRITEBACK |
EXTENT_END_WRITEBACK);
btrfs_free_path(path); btrfs_free_path(path);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment