btrfs: make run_delalloc_nocow take btrfs_inode

It only really uses btrfs_inode.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Nikolay Borisov 2020-06-03 08:55:21 +03:00 committed by David Sterba
parent 8ba96f3dd6
commit 968322c8c6

View File

@ -1444,28 +1444,27 @@ static int fallback_to_cow(struct btrfs_inode *inode, struct page *locked_page,
* If no cow copies or snapshots exist, we write directly to the existing * If no cow copies or snapshots exist, we write directly to the existing
* blocks on disk * blocks on disk
*/ */
static noinline int run_delalloc_nocow(struct inode *inode, static noinline int run_delalloc_nocow(struct btrfs_inode *inode,
struct page *locked_page, struct page *locked_page,
const u64 start, const u64 end, const u64 start, const u64 end,
int *page_started, int force, int *page_started, int force,
unsigned long *nr_written) unsigned long *nr_written)
{ {
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct btrfs_fs_info *fs_info = inode->root->fs_info;
struct btrfs_root *root = BTRFS_I(inode)->root; struct btrfs_root *root = inode->root;
struct btrfs_path *path; struct btrfs_path *path;
u64 cow_start = (u64)-1; u64 cow_start = (u64)-1;
u64 cur_offset = start; u64 cur_offset = start;
int ret; int ret;
bool check_prev = true; bool check_prev = true;
const bool freespace_inode = btrfs_is_free_space_inode(BTRFS_I(inode)); const bool freespace_inode = btrfs_is_free_space_inode(inode);
u64 ino = btrfs_ino(BTRFS_I(inode)); u64 ino = btrfs_ino(inode);
bool nocow = false; bool nocow = false;
u64 disk_bytenr = 0; u64 disk_bytenr = 0;
path = btrfs_alloc_path(); path = btrfs_alloc_path();
if (!path) { if (!path) {
extent_clear_unlock_delalloc(BTRFS_I(inode), start, end, extent_clear_unlock_delalloc(inode, start, end, locked_page,
locked_page,
EXTENT_LOCKED | EXTENT_DELALLOC | EXTENT_LOCKED | EXTENT_DELALLOC |
EXTENT_DO_ACCOUNTING | EXTENT_DO_ACCOUNTING |
EXTENT_DEFRAG, PAGE_UNLOCK | EXTENT_DEFRAG, PAGE_UNLOCK |
@ -1685,7 +1684,7 @@ static noinline int run_delalloc_nocow(struct inode *inode,
* NOCOW, following one which needs to be COW'ed * NOCOW, following one which needs to be COW'ed
*/ */
if (cow_start != (u64)-1) { if (cow_start != (u64)-1) {
ret = fallback_to_cow(BTRFS_I(inode), locked_page, ret = fallback_to_cow(inode, locked_page,
cow_start, found_key.offset - 1, cow_start, found_key.offset - 1,
page_started, nr_written); page_started, nr_written);
if (ret) if (ret)
@ -1697,7 +1696,7 @@ static noinline int run_delalloc_nocow(struct inode *inode,
u64 orig_start = found_key.offset - extent_offset; u64 orig_start = found_key.offset - extent_offset;
struct extent_map *em; struct extent_map *em;
em = create_io_em(BTRFS_I(inode), cur_offset, num_bytes, em = create_io_em(inode, cur_offset, num_bytes,
orig_start, orig_start,
disk_bytenr, /* block_start */ disk_bytenr, /* block_start */
num_bytes, /* block_len */ num_bytes, /* block_len */
@ -1709,19 +1708,18 @@ static noinline int run_delalloc_nocow(struct inode *inode,
goto error; goto error;
} }
free_extent_map(em); free_extent_map(em);
ret = btrfs_add_ordered_extent(BTRFS_I(inode), cur_offset, ret = btrfs_add_ordered_extent(inode, cur_offset,
disk_bytenr, num_bytes, disk_bytenr, num_bytes,
num_bytes, num_bytes,
BTRFS_ORDERED_PREALLOC); BTRFS_ORDERED_PREALLOC);
if (ret) { if (ret) {
btrfs_drop_extent_cache(BTRFS_I(inode), btrfs_drop_extent_cache(inode, cur_offset,
cur_offset,
cur_offset + num_bytes - 1, cur_offset + num_bytes - 1,
0); 0);
goto error; goto error;
} }
} else { } else {
ret = btrfs_add_ordered_extent(BTRFS_I(inode), cur_offset, ret = btrfs_add_ordered_extent(inode, cur_offset,
disk_bytenr, num_bytes, disk_bytenr, num_bytes,
num_bytes, num_bytes,
BTRFS_ORDERED_NOCOW); BTRFS_ORDERED_NOCOW);
@ -1740,10 +1738,10 @@ static noinline int run_delalloc_nocow(struct inode *inode,
* extent_clear_unlock_delalloc() in error handler * extent_clear_unlock_delalloc() in error handler
* from freeing metadata of created ordered extent. * from freeing metadata of created ordered extent.
*/ */
ret = btrfs_reloc_clone_csums(BTRFS_I(inode), cur_offset, ret = btrfs_reloc_clone_csums(inode, cur_offset,
num_bytes); num_bytes);
extent_clear_unlock_delalloc(BTRFS_I(inode), cur_offset, extent_clear_unlock_delalloc(inode, cur_offset,
cur_offset + num_bytes - 1, cur_offset + num_bytes - 1,
locked_page, EXTENT_LOCKED | locked_page, EXTENT_LOCKED |
EXTENT_DELALLOC | EXTENT_DELALLOC |
@ -1769,8 +1767,8 @@ static noinline int run_delalloc_nocow(struct inode *inode,
if (cow_start != (u64)-1) { if (cow_start != (u64)-1) {
cur_offset = end; cur_offset = end;
ret = fallback_to_cow(BTRFS_I(inode), locked_page, cow_start, ret = fallback_to_cow(inode, locked_page, cow_start, end,
end, page_started, nr_written); page_started, nr_written);
if (ret) if (ret)
goto error; goto error;
} }
@ -1780,7 +1778,7 @@ static noinline int run_delalloc_nocow(struct inode *inode,
btrfs_dec_nocow_writers(fs_info, disk_bytenr); btrfs_dec_nocow_writers(fs_info, disk_bytenr);
if (ret && cur_offset < end) if (ret && cur_offset < end)
extent_clear_unlock_delalloc(BTRFS_I(inode), cur_offset, end, extent_clear_unlock_delalloc(inode, cur_offset, end,
locked_page, EXTENT_LOCKED | locked_page, EXTENT_LOCKED |
EXTENT_DELALLOC | EXTENT_DEFRAG | EXTENT_DELALLOC | EXTENT_DEFRAG |
EXTENT_DO_ACCOUNTING, PAGE_UNLOCK | EXTENT_DO_ACCOUNTING, PAGE_UNLOCK |
@ -1823,10 +1821,10 @@ int btrfs_run_delalloc_range(struct inode *inode, struct page *locked_page,
int force_cow = need_force_cow(inode, start, end); int force_cow = need_force_cow(inode, start, end);
if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATACOW && !force_cow) { if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATACOW && !force_cow) {
ret = run_delalloc_nocow(inode, locked_page, start, end, ret = run_delalloc_nocow(BTRFS_I(inode), locked_page, start, end,
page_started, 1, nr_written); page_started, 1, nr_written);
} else if (BTRFS_I(inode)->flags & BTRFS_INODE_PREALLOC && !force_cow) { } else if (BTRFS_I(inode)->flags & BTRFS_INODE_PREALLOC && !force_cow) {
ret = run_delalloc_nocow(inode, locked_page, start, end, ret = run_delalloc_nocow(BTRFS_I(inode), locked_page, start, end,
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)) {