Commit e4c3b2dc authored by Liu Bo's avatar Liu Bo Committed by David Sterba

Btrfs: kill trans in run_delalloc_nocow and btrfs_cross_ref_exist

run_delalloc_nocow has used trans in two places where they don't
actually need @trans.

For btrfs_lookup_file_extent, we search for file extents without COWing
anything, and for btrfs_cross_ref_exist, the only place where we need
@trans is deferencing it in order to get running_transaction which we
could easily get from the global fs_info.
Signed-off-by: default avatarLiu Bo <bo.li.liu@oracle.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent f72ad18e
...@@ -2584,8 +2584,7 @@ int btrfs_pin_extent_for_log_replay(struct btrfs_fs_info *fs_info, ...@@ -2584,8 +2584,7 @@ int btrfs_pin_extent_for_log_replay(struct btrfs_fs_info *fs_info,
u64 bytenr, u64 num_bytes); u64 bytenr, u64 num_bytes);
int btrfs_exclude_logged_extents(struct btrfs_fs_info *fs_info, int btrfs_exclude_logged_extents(struct btrfs_fs_info *fs_info,
struct extent_buffer *eb); struct extent_buffer *eb);
int btrfs_cross_ref_exist(struct btrfs_trans_handle *trans, int btrfs_cross_ref_exist(struct btrfs_root *root,
struct btrfs_root *root,
u64 objectid, u64 offset, u64 bytenr); u64 objectid, u64 offset, u64 bytenr);
struct btrfs_block_group_cache *btrfs_lookup_block_group( struct btrfs_block_group_cache *btrfs_lookup_block_group(
struct btrfs_fs_info *info, struct btrfs_fs_info *info,
......
...@@ -3028,8 +3028,7 @@ int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans, ...@@ -3028,8 +3028,7 @@ int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans,
return ret; return ret;
} }
static noinline int check_delayed_ref(struct btrfs_trans_handle *trans, static noinline int check_delayed_ref(struct btrfs_root *root,
struct btrfs_root *root,
struct btrfs_path *path, struct btrfs_path *path,
u64 objectid, u64 offset, u64 bytenr) u64 objectid, u64 offset, u64 bytenr)
{ {
...@@ -3037,9 +3036,14 @@ static noinline int check_delayed_ref(struct btrfs_trans_handle *trans, ...@@ -3037,9 +3036,14 @@ static noinline int check_delayed_ref(struct btrfs_trans_handle *trans,
struct btrfs_delayed_ref_node *ref; struct btrfs_delayed_ref_node *ref;
struct btrfs_delayed_data_ref *data_ref; struct btrfs_delayed_data_ref *data_ref;
struct btrfs_delayed_ref_root *delayed_refs; struct btrfs_delayed_ref_root *delayed_refs;
struct btrfs_transaction *cur_trans;
int ret = 0; int ret = 0;
delayed_refs = &trans->transaction->delayed_refs; cur_trans = root->fs_info->running_transaction;
if (!cur_trans)
return 0;
delayed_refs = &cur_trans->delayed_refs;
spin_lock(&delayed_refs->lock); spin_lock(&delayed_refs->lock);
head = btrfs_find_delayed_ref_head(delayed_refs, bytenr); head = btrfs_find_delayed_ref_head(delayed_refs, bytenr);
if (!head) { if (!head) {
...@@ -3090,8 +3094,7 @@ static noinline int check_delayed_ref(struct btrfs_trans_handle *trans, ...@@ -3090,8 +3094,7 @@ static noinline int check_delayed_ref(struct btrfs_trans_handle *trans,
return ret; return ret;
} }
static noinline int check_committed_ref(struct btrfs_trans_handle *trans, static noinline int check_committed_ref(struct btrfs_root *root,
struct btrfs_root *root,
struct btrfs_path *path, struct btrfs_path *path,
u64 objectid, u64 offset, u64 bytenr) u64 objectid, u64 offset, u64 bytenr)
{ {
...@@ -3162,9 +3165,8 @@ static noinline int check_committed_ref(struct btrfs_trans_handle *trans, ...@@ -3162,9 +3165,8 @@ static noinline int check_committed_ref(struct btrfs_trans_handle *trans,
return ret; return ret;
} }
int btrfs_cross_ref_exist(struct btrfs_trans_handle *trans, int btrfs_cross_ref_exist(struct btrfs_root *root, u64 objectid, u64 offset,
struct btrfs_root *root, u64 bytenr)
u64 objectid, u64 offset, u64 bytenr)
{ {
struct btrfs_path *path; struct btrfs_path *path;
int ret; int ret;
...@@ -3175,12 +3177,12 @@ int btrfs_cross_ref_exist(struct btrfs_trans_handle *trans, ...@@ -3175,12 +3177,12 @@ int btrfs_cross_ref_exist(struct btrfs_trans_handle *trans,
return -ENOENT; return -ENOENT;
do { do {
ret = check_committed_ref(trans, root, path, objectid, ret = check_committed_ref(root, path, objectid,
offset, bytenr); offset, bytenr);
if (ret && ret != -ENOENT) if (ret && ret != -ENOENT)
goto out; goto out;
ret2 = check_delayed_ref(trans, root, path, objectid, ret2 = check_delayed_ref(root, path, objectid,
offset, bytenr); offset, bytenr);
} while (ret2 == -EAGAIN); } while (ret2 == -EAGAIN);
......
...@@ -1247,7 +1247,6 @@ static noinline int run_delalloc_nocow(struct inode *inode, ...@@ -1247,7 +1247,6 @@ static noinline int run_delalloc_nocow(struct inode *inode,
{ {
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
struct btrfs_root *root = BTRFS_I(inode)->root; struct btrfs_root *root = BTRFS_I(inode)->root;
struct btrfs_trans_handle *trans;
struct extent_buffer *leaf; struct extent_buffer *leaf;
struct btrfs_path *path; struct btrfs_path *path;
struct btrfs_file_extent_item *fi; struct btrfs_file_extent_item *fi;
...@@ -1283,30 +1282,10 @@ static noinline int run_delalloc_nocow(struct inode *inode, ...@@ -1283,30 +1282,10 @@ static noinline int run_delalloc_nocow(struct inode *inode,
nolock = btrfs_is_free_space_inode(inode); nolock = btrfs_is_free_space_inode(inode);
if (nolock)
trans = btrfs_join_transaction_nolock(root);
else
trans = btrfs_join_transaction(root);
if (IS_ERR(trans)) {
extent_clear_unlock_delalloc(inode, start, end, end,
locked_page,
EXTENT_LOCKED | EXTENT_DELALLOC |
EXTENT_DO_ACCOUNTING |
EXTENT_DEFRAG, PAGE_UNLOCK |
PAGE_CLEAR_DIRTY |
PAGE_SET_WRITEBACK |
PAGE_END_WRITEBACK);
btrfs_free_path(path);
return PTR_ERR(trans);
}
trans->block_rsv = &fs_info->delalloc_block_rsv;
cow_start = (u64)-1; cow_start = (u64)-1;
cur_offset = start; cur_offset = start;
while (1) { while (1) {
ret = btrfs_lookup_file_extent(trans, root, path, ino, ret = btrfs_lookup_file_extent(NULL, root, path, ino,
cur_offset, 0); cur_offset, 0);
if (ret < 0) if (ret < 0)
goto error; goto error;
...@@ -1379,7 +1358,7 @@ static noinline int run_delalloc_nocow(struct inode *inode, ...@@ -1379,7 +1358,7 @@ static noinline int run_delalloc_nocow(struct inode *inode,
goto out_check; goto out_check;
if (btrfs_extent_readonly(fs_info, disk_bytenr)) if (btrfs_extent_readonly(fs_info, disk_bytenr))
goto out_check; goto out_check;
if (btrfs_cross_ref_exist(trans, root, ino, if (btrfs_cross_ref_exist(root, ino,
found_key.offset - found_key.offset -
extent_offset, disk_bytenr)) extent_offset, disk_bytenr))
goto out_check; goto out_check;
...@@ -1531,10 +1510,6 @@ static noinline int run_delalloc_nocow(struct inode *inode, ...@@ -1531,10 +1510,6 @@ static noinline int run_delalloc_nocow(struct inode *inode,
} }
error: error:
err = btrfs_end_transaction(trans);
if (!ret)
ret = err;
if (ret && cur_offset < end) if (ret && cur_offset < end)
extent_clear_unlock_delalloc(inode, cur_offset, end, end, extent_clear_unlock_delalloc(inode, cur_offset, end, end,
locked_page, EXTENT_LOCKED | locked_page, EXTENT_LOCKED |
...@@ -7290,7 +7265,6 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len, ...@@ -7290,7 +7265,6 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
u64 *ram_bytes) u64 *ram_bytes)
{ {
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
struct btrfs_trans_handle *trans;
struct btrfs_path *path; struct btrfs_path *path;
int ret; int ret;
struct extent_buffer *leaf; struct extent_buffer *leaf;
...@@ -7393,15 +7367,9 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len, ...@@ -7393,15 +7367,9 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
* look for other files referencing this extent, if we * look for other files referencing this extent, if we
* find any we must cow * find any we must cow
*/ */
trans = btrfs_join_transaction(root);
if (IS_ERR(trans)) {
ret = 0;
goto out;
}
ret = btrfs_cross_ref_exist(trans, root, btrfs_ino(BTRFS_I(inode)), ret = btrfs_cross_ref_exist(root, btrfs_ino(BTRFS_I(inode)),
key.offset - backref_offset, disk_bytenr); key.offset - backref_offset, disk_bytenr);
btrfs_end_transaction(trans);
if (ret) { if (ret) {
ret = 0; ret = 0;
goto out; goto out;
......
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