Commit 34bfaf15 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by David Sterba

btrfs: pass an ordered_extent to btrfs_reloc_clone_csums

Both callers of btrfs_reloc_clone_csums allocate the ordered_extent that
btrfs_reloc_clone_csums operates on.  Switch them to use
btrfs_alloc_ordered_extent instead of btrfs_add_ordered_extent and
pass the ordered_extent to btrfs_reloc_clone_csums instead of doing an
extra lookup.
Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 3daea5fd
...@@ -1494,6 +1494,8 @@ static noinline int cow_file_range(struct btrfs_inode *inode, ...@@ -1494,6 +1494,8 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
min_alloc_size = fs_info->sectorsize; min_alloc_size = fs_info->sectorsize;
while (num_bytes > 0) { while (num_bytes > 0) {
struct btrfs_ordered_extent *ordered;
cur_alloc_size = num_bytes; cur_alloc_size = num_bytes;
ret = btrfs_reserve_extent(root, cur_alloc_size, cur_alloc_size, ret = btrfs_reserve_extent(root, cur_alloc_size, cur_alloc_size,
min_alloc_size, 0, alloc_hint, min_alloc_size, 0, alloc_hint,
...@@ -1518,16 +1520,18 @@ static noinline int cow_file_range(struct btrfs_inode *inode, ...@@ -1518,16 +1520,18 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
} }
free_extent_map(em); free_extent_map(em);
ret = btrfs_add_ordered_extent(inode, start, ram_size, ram_size, ordered = btrfs_alloc_ordered_extent(inode, start, ram_size,
ins.objectid, cur_alloc_size, 0, ram_size, ins.objectid, cur_alloc_size,
1 << BTRFS_ORDERED_REGULAR, 0, 1 << BTRFS_ORDERED_REGULAR,
BTRFS_COMPRESS_NONE); BTRFS_COMPRESS_NONE);
if (ret) if (IS_ERR(ordered)) {
ret = PTR_ERR(ordered);
goto out_drop_extent_cache; goto out_drop_extent_cache;
}
if (btrfs_is_data_reloc_root(root)) { if (btrfs_is_data_reloc_root(root)) {
ret = btrfs_reloc_clone_csums(inode, start, ret = btrfs_reloc_clone_csums(ordered);
cur_alloc_size);
/* /*
* Only drop cache here, and process as normal. * Only drop cache here, and process as normal.
* *
...@@ -1544,6 +1548,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode, ...@@ -1544,6 +1548,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
start + ram_size - 1, start + ram_size - 1,
false); false);
} }
btrfs_put_ordered_extent(ordered);
btrfs_dec_block_group_reservations(fs_info, ins.objectid); btrfs_dec_block_group_reservations(fs_info, ins.objectid);
...@@ -2133,6 +2138,7 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode, ...@@ -2133,6 +2138,7 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode,
nocow_args.writeback_path = true; nocow_args.writeback_path = true;
while (1) { while (1) {
struct btrfs_ordered_extent *ordered;
struct btrfs_key found_key; struct btrfs_key found_key;
struct btrfs_file_extent_item *fi; struct btrfs_file_extent_item *fi;
struct extent_buffer *leaf; struct extent_buffer *leaf;
...@@ -2298,18 +2304,19 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode, ...@@ -2298,18 +2304,19 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode,
free_extent_map(em); free_extent_map(em);
} }
ret = btrfs_add_ordered_extent(inode, cur_offset, ordered = btrfs_alloc_ordered_extent(inode, cur_offset,
nocow_args.num_bytes, nocow_args.num_bytes, nocow_args.num_bytes, nocow_args.num_bytes,
nocow_args.disk_bytenr, nocow_args.num_bytes, 0, nocow_args.disk_bytenr, nocow_args.num_bytes, 0,
is_prealloc is_prealloc
? (1 << BTRFS_ORDERED_PREALLOC) ? (1 << BTRFS_ORDERED_PREALLOC)
: (1 << BTRFS_ORDERED_NOCOW), : (1 << BTRFS_ORDERED_NOCOW),
BTRFS_COMPRESS_NONE); BTRFS_COMPRESS_NONE);
if (ret) { if (IS_ERR(ordered)) {
if (is_prealloc) { if (is_prealloc) {
btrfs_drop_extent_map_range(inode, cur_offset, btrfs_drop_extent_map_range(inode, cur_offset,
nocow_end, false); nocow_end, false);
} }
ret = PTR_ERR(ordered);
goto error; goto error;
} }
...@@ -2324,8 +2331,8 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode, ...@@ -2324,8 +2331,8 @@ static noinline int run_delalloc_nocow(struct btrfs_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(inode, cur_offset, ret = btrfs_reloc_clone_csums(ordered);
nocow_args.num_bytes); btrfs_put_ordered_extent(ordered);
extent_clear_unlock_delalloc(inode, cur_offset, nocow_end, extent_clear_unlock_delalloc(inode, cur_offset, nocow_end,
locked_page, EXTENT_LOCKED | locked_page, EXTENT_LOCKED |
......
...@@ -4342,29 +4342,25 @@ int btrfs_recover_relocation(struct btrfs_fs_info *fs_info) ...@@ -4342,29 +4342,25 @@ int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
* cloning checksum properly handles the nodatasum extents. * cloning checksum properly handles the nodatasum extents.
* it also saves CPU time to re-calculate the checksum. * it also saves CPU time to re-calculate the checksum.
*/ */
int btrfs_reloc_clone_csums(struct btrfs_inode *inode, u64 file_pos, u64 len) int btrfs_reloc_clone_csums(struct btrfs_ordered_extent *ordered)
{ {
struct btrfs_inode *inode = BTRFS_I(ordered->inode);
struct btrfs_fs_info *fs_info = inode->root->fs_info; struct btrfs_fs_info *fs_info = inode->root->fs_info;
struct btrfs_root *csum_root; u64 disk_bytenr = ordered->file_offset + inode->index_cnt;
struct btrfs_ordered_sum *sums; struct btrfs_root *csum_root = btrfs_csum_root(fs_info, disk_bytenr);
struct btrfs_ordered_extent *ordered;
int ret;
u64 disk_bytenr;
u64 new_bytenr;
LIST_HEAD(list); LIST_HEAD(list);
int ret;
ordered = btrfs_lookup_ordered_extent(inode, file_pos);
BUG_ON(ordered->file_offset != file_pos || ordered->num_bytes != len);
disk_bytenr = file_pos + inode->index_cnt;
csum_root = btrfs_csum_root(fs_info, disk_bytenr);
ret = btrfs_lookup_csums_list(csum_root, disk_bytenr, ret = btrfs_lookup_csums_list(csum_root, disk_bytenr,
disk_bytenr + len - 1, &list, 0, false); disk_bytenr + ordered->num_bytes - 1,
&list, 0, false);
if (ret) if (ret)
goto out; return ret;
while (!list_empty(&list)) { while (!list_empty(&list)) {
sums = list_entry(list.next, struct btrfs_ordered_sum, list); struct btrfs_ordered_sum *sums =
list_entry(list.next, struct btrfs_ordered_sum, list);
list_del_init(&sums->list); list_del_init(&sums->list);
/* /*
...@@ -4379,14 +4375,11 @@ int btrfs_reloc_clone_csums(struct btrfs_inode *inode, u64 file_pos, u64 len) ...@@ -4379,14 +4375,11 @@ int btrfs_reloc_clone_csums(struct btrfs_inode *inode, u64 file_pos, u64 len)
* disk_len vs real len like with real inodes since it's all * disk_len vs real len like with real inodes since it's all
* disk length. * disk length.
*/ */
new_bytenr = ordered->disk_bytenr + sums->logical - disk_bytenr; sums->logical = ordered->disk_bytenr + sums->logical - disk_bytenr;
sums->logical = new_bytenr;
btrfs_add_ordered_sum(ordered, sums); btrfs_add_ordered_sum(ordered, sums);
} }
out:
btrfs_put_ordered_extent(ordered); return 0;
return ret;
} }
int btrfs_reloc_cow_block(struct btrfs_trans_handle *trans, int btrfs_reloc_cow_block(struct btrfs_trans_handle *trans,
......
...@@ -8,7 +8,7 @@ int btrfs_init_reloc_root(struct btrfs_trans_handle *trans, struct btrfs_root *r ...@@ -8,7 +8,7 @@ int btrfs_init_reloc_root(struct btrfs_trans_handle *trans, struct btrfs_root *r
int btrfs_update_reloc_root(struct btrfs_trans_handle *trans, int btrfs_update_reloc_root(struct btrfs_trans_handle *trans,
struct btrfs_root *root); struct btrfs_root *root);
int btrfs_recover_relocation(struct btrfs_fs_info *fs_info); int btrfs_recover_relocation(struct btrfs_fs_info *fs_info);
int btrfs_reloc_clone_csums(struct btrfs_inode *inode, u64 file_pos, u64 len); int btrfs_reloc_clone_csums(struct btrfs_ordered_extent *ordered);
int btrfs_reloc_cow_block(struct btrfs_trans_handle *trans, int btrfs_reloc_cow_block(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct extent_buffer *buf, struct btrfs_root *root, struct extent_buffer *buf,
struct extent_buffer *cow); struct extent_buffer *cow);
......
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