Commit 6e26c442 authored by Nikolay Borisov's avatar Nikolay Borisov Committed by David Sterba

btrfs: make cow_file_range take btrfs_inode

All its children functions take btrfs_inode so convert it to taking
btrfs_inode.
Signed-off-by: default avatarNikolay Borisov <nborisov@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent e7fbf604
...@@ -80,7 +80,7 @@ struct kmem_cache *btrfs_free_space_bitmap_cachep; ...@@ -80,7 +80,7 @@ struct kmem_cache *btrfs_free_space_bitmap_cachep;
static int btrfs_setsize(struct inode *inode, struct iattr *attr); static int btrfs_setsize(struct inode *inode, struct iattr *attr);
static int btrfs_truncate(struct inode *inode, bool skip_writeback); static int btrfs_truncate(struct inode *inode, bool skip_writeback);
static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent); static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent);
static noinline int cow_file_range(struct inode *inode, static noinline int cow_file_range(struct btrfs_inode *inode,
struct page *locked_page, struct page *locked_page,
u64 start, u64 end, int *page_started, u64 start, u64 end, int *page_started,
unsigned long *nr_written, int unlock); unsigned long *nr_written, int unlock);
...@@ -789,7 +789,8 @@ static noinline void submit_compressed_extents(struct async_chunk *async_chunk) ...@@ -789,7 +789,8 @@ static noinline void submit_compressed_extents(struct async_chunk *async_chunk)
unsigned long nr_written = 0; unsigned long nr_written = 0;
/* allocate blocks */ /* allocate blocks */
ret = cow_file_range(inode, async_chunk->locked_page, ret = cow_file_range(BTRFS_I(inode),
async_chunk->locked_page,
async_extent->start, async_extent->start,
async_extent->start + async_extent->start +
async_extent->ram_size - 1, async_extent->ram_size - 1,
...@@ -976,13 +977,13 @@ static u64 get_extent_allocation_hint(struct btrfs_inode *inode, u64 start, ...@@ -976,13 +977,13 @@ static u64 get_extent_allocation_hint(struct btrfs_inode *inode, u64 start,
* required to start IO on it. It may be clean and already done with * required to start IO on it. It may be clean and already done with
* IO when we return. * IO when we return.
*/ */
static noinline int cow_file_range(struct inode *inode, static noinline int cow_file_range(struct btrfs_inode *inode,
struct page *locked_page, struct page *locked_page,
u64 start, u64 end, int *page_started, u64 start, u64 end, int *page_started,
unsigned long *nr_written, int unlock) unsigned long *nr_written, int unlock)
{ {
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct btrfs_root *root = inode->root;
struct btrfs_root *root = BTRFS_I(inode)->root; struct btrfs_fs_info *fs_info = root->fs_info;
u64 alloc_hint = 0; u64 alloc_hint = 0;
u64 num_bytes; u64 num_bytes;
unsigned long ram_size; unsigned long ram_size;
...@@ -996,7 +997,7 @@ static noinline int cow_file_range(struct inode *inode, ...@@ -996,7 +997,7 @@ static noinline int cow_file_range(struct inode *inode,
bool extent_reserved = false; bool extent_reserved = false;
int ret = 0; int ret = 0;
if (btrfs_is_free_space_inode(BTRFS_I(inode))) { if (btrfs_is_free_space_inode(inode)) {
WARN_ON_ONCE(1); WARN_ON_ONCE(1);
ret = -EINVAL; ret = -EINVAL;
goto out_unlock; goto out_unlock;
...@@ -1006,11 +1007,11 @@ static noinline int cow_file_range(struct inode *inode, ...@@ -1006,11 +1007,11 @@ static noinline int cow_file_range(struct inode *inode,
num_bytes = max(blocksize, num_bytes); num_bytes = max(blocksize, num_bytes);
ASSERT(num_bytes <= btrfs_super_total_bytes(fs_info->super_copy)); ASSERT(num_bytes <= btrfs_super_total_bytes(fs_info->super_copy));
inode_should_defrag(BTRFS_I(inode), start, end, num_bytes, SZ_64K); inode_should_defrag(inode, start, end, num_bytes, SZ_64K);
if (start == 0) { if (start == 0) {
/* lets try to make an inline extent */ /* lets try to make an inline extent */
ret = cow_file_range_inline(BTRFS_I(inode), start, end, 0, ret = cow_file_range_inline(inode, start, end, 0,
BTRFS_COMPRESS_NONE, NULL); BTRFS_COMPRESS_NONE, NULL);
if (ret == 0) { if (ret == 0) {
/* /*
...@@ -1019,8 +1020,7 @@ static noinline int cow_file_range(struct inode *inode, ...@@ -1019,8 +1020,7 @@ static noinline int cow_file_range(struct inode *inode,
* our outstanding extent for clearing delalloc for this * our outstanding extent for clearing delalloc for this
* range. * range.
*/ */
extent_clear_unlock_delalloc(BTRFS_I(inode), start, end, extent_clear_unlock_delalloc(inode, start, end, NULL,
NULL,
EXTENT_LOCKED | EXTENT_DELALLOC | EXTENT_LOCKED | EXTENT_DELALLOC |
EXTENT_DELALLOC_NEW | EXTENT_DEFRAG | EXTENT_DELALLOC_NEW | EXTENT_DEFRAG |
EXTENT_DO_ACCOUNTING, PAGE_UNLOCK | EXTENT_DO_ACCOUNTING, PAGE_UNLOCK |
...@@ -1035,10 +1035,8 @@ static noinline int cow_file_range(struct inode *inode, ...@@ -1035,10 +1035,8 @@ static noinline int cow_file_range(struct inode *inode,
} }
} }
alloc_hint = get_extent_allocation_hint(BTRFS_I(inode), start, alloc_hint = get_extent_allocation_hint(inode, start, num_bytes);
num_bytes); btrfs_drop_extent_cache(inode, start, start + num_bytes - 1, 0);
btrfs_drop_extent_cache(BTRFS_I(inode), start,
start + num_bytes - 1, 0);
/* /*
* Relocation relies on the relocated extents to have exactly the same * Relocation relies on the relocated extents to have exactly the same
...@@ -1067,7 +1065,7 @@ static noinline int cow_file_range(struct inode *inode, ...@@ -1067,7 +1065,7 @@ static noinline int cow_file_range(struct inode *inode,
extent_reserved = true; extent_reserved = true;
ram_size = ins.offset; ram_size = ins.offset;
em = create_io_em(BTRFS_I(inode), start, ins.offset, /* len */ em = create_io_em(inode, start, ins.offset, /* len */
start, /* orig_start */ start, /* orig_start */
ins.objectid, /* block_start */ ins.objectid, /* block_start */
ins.offset, /* block_len */ ins.offset, /* block_len */
...@@ -1081,15 +1079,14 @@ static noinline int cow_file_range(struct inode *inode, ...@@ -1081,15 +1079,14 @@ static noinline int cow_file_range(struct inode *inode,
} }
free_extent_map(em); free_extent_map(em);
ret = btrfs_add_ordered_extent(BTRFS_I(inode), start, ret = btrfs_add_ordered_extent(inode, start, ins.objectid,
ins.objectid, ram_size, ram_size, cur_alloc_size, 0);
cur_alloc_size, 0);
if (ret) if (ret)
goto out_drop_extent_cache; goto out_drop_extent_cache;
if (root->root_key.objectid == if (root->root_key.objectid ==
BTRFS_DATA_RELOC_TREE_OBJECTID) { BTRFS_DATA_RELOC_TREE_OBJECTID) {
ret = btrfs_reloc_clone_csums(BTRFS_I(inode), start, ret = btrfs_reloc_clone_csums(inode, start,
cur_alloc_size); cur_alloc_size);
/* /*
* Only drop cache here, and process as normal. * Only drop cache here, and process as normal.
...@@ -1103,7 +1100,7 @@ static noinline int cow_file_range(struct inode *inode, ...@@ -1103,7 +1100,7 @@ static noinline int cow_file_range(struct inode *inode,
* skip current ordered extent. * skip current ordered extent.
*/ */
if (ret) if (ret)
btrfs_drop_extent_cache(BTRFS_I(inode), start, btrfs_drop_extent_cache(inode, start,
start + ram_size - 1, 0); start + ram_size - 1, 0);
} }
...@@ -1119,8 +1116,7 @@ static noinline int cow_file_range(struct inode *inode, ...@@ -1119,8 +1116,7 @@ static noinline int cow_file_range(struct inode *inode,
page_ops = unlock ? PAGE_UNLOCK : 0; page_ops = unlock ? PAGE_UNLOCK : 0;
page_ops |= PAGE_SET_PRIVATE2; page_ops |= PAGE_SET_PRIVATE2;
extent_clear_unlock_delalloc(BTRFS_I(inode), start, extent_clear_unlock_delalloc(inode, start, start + ram_size - 1,
start + ram_size - 1,
locked_page, locked_page,
EXTENT_LOCKED | EXTENT_DELALLOC, EXTENT_LOCKED | EXTENT_DELALLOC,
page_ops); page_ops);
...@@ -1144,7 +1140,7 @@ static noinline int cow_file_range(struct inode *inode, ...@@ -1144,7 +1140,7 @@ static noinline int cow_file_range(struct inode *inode,
return ret; return ret;
out_drop_extent_cache: out_drop_extent_cache:
btrfs_drop_extent_cache(BTRFS_I(inode), start, start + ram_size - 1, 0); btrfs_drop_extent_cache(inode, start, start + ram_size - 1, 0);
out_reserve: out_reserve:
btrfs_dec_block_group_reservations(fs_info, ins.objectid); btrfs_dec_block_group_reservations(fs_info, ins.objectid);
btrfs_free_reserved_extent(fs_info, ins.objectid, ins.offset, 1); btrfs_free_reserved_extent(fs_info, ins.objectid, ins.offset, 1);
...@@ -1164,7 +1160,7 @@ static noinline int cow_file_range(struct inode *inode, ...@@ -1164,7 +1160,7 @@ static noinline int cow_file_range(struct inode *inode,
* it the flag EXTENT_CLEAR_DATA_RESV. * it the flag EXTENT_CLEAR_DATA_RESV.
*/ */
if (extent_reserved) { if (extent_reserved) {
extent_clear_unlock_delalloc(BTRFS_I(inode), start, extent_clear_unlock_delalloc(inode, start,
start + cur_alloc_size - 1, start + cur_alloc_size - 1,
locked_page, locked_page,
clear_bits, clear_bits,
...@@ -1173,7 +1169,7 @@ static noinline int cow_file_range(struct inode *inode, ...@@ -1173,7 +1169,7 @@ static noinline int cow_file_range(struct inode *inode,
if (start >= end) if (start >= end)
goto out; goto out;
} }
extent_clear_unlock_delalloc(BTRFS_I(inode), start, end, locked_page, extent_clear_unlock_delalloc(inode, start, end, locked_page,
clear_bits | EXTENT_CLEAR_DATA_RESV, clear_bits | EXTENT_CLEAR_DATA_RESV,
page_ops); page_ops);
goto out; goto out;
...@@ -1441,8 +1437,8 @@ static int fallback_to_cow(struct inode *inode, struct page *locked_page, ...@@ -1441,8 +1437,8 @@ static int fallback_to_cow(struct inode *inode, struct page *locked_page,
0, 0, NULL); 0, 0, NULL);
} }
return cow_file_range(inode, locked_page, start, end, page_started, return cow_file_range(BTRFS_I(inode), locked_page, start, end,
nr_written, 1); page_started, nr_written, 1);
} }
/* /*
...@@ -1838,7 +1834,7 @@ int btrfs_run_delalloc_range(struct inode *inode, struct page *locked_page, ...@@ -1838,7 +1834,7 @@ int btrfs_run_delalloc_range(struct inode *inode, struct page *locked_page,
page_started, 0, nr_written); page_started, 0, nr_written);
} else if (!inode_can_compress(inode) || } else if (!inode_can_compress(inode) ||
!inode_need_compress(inode, start, end)) { !inode_need_compress(inode, start, end)) {
ret = cow_file_range(inode, locked_page, start, end, ret = cow_file_range(BTRFS_I(inode), locked_page, start, end,
page_started, nr_written, 1); page_started, nr_written, 1);
} else { } else {
set_bit(BTRFS_INODE_HAS_ASYNC_EXTENT, set_bit(BTRFS_INODE_HAS_ASYNC_EXTENT,
......
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