Skip to content

Commit e4c3b2d

Browse files
Liu Bokdave
authored andcommitted
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: Liu Bo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent f72ad18 commit e4c3b2d

File tree

3 files changed

+16
-47
lines changed

3 files changed

+16
-47
lines changed

fs/btrfs/ctree.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2584,8 +2584,7 @@ int btrfs_pin_extent_for_log_replay(struct btrfs_fs_info *fs_info,
25842584
u64 bytenr, u64 num_bytes);
25852585
int btrfs_exclude_logged_extents(struct btrfs_fs_info *fs_info,
25862586
struct extent_buffer *eb);
2587-
int btrfs_cross_ref_exist(struct btrfs_trans_handle *trans,
2588-
struct btrfs_root *root,
2587+
int btrfs_cross_ref_exist(struct btrfs_root *root,
25892588
u64 objectid, u64 offset, u64 bytenr);
25902589
struct btrfs_block_group_cache *btrfs_lookup_block_group(
25912590
struct btrfs_fs_info *info,

fs/btrfs/extent-tree.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3028,18 +3028,22 @@ int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans,
30283028
return ret;
30293029
}
30303030

3031-
static noinline int check_delayed_ref(struct btrfs_trans_handle *trans,
3032-
struct btrfs_root *root,
3031+
static noinline int check_delayed_ref(struct btrfs_root *root,
30333032
struct btrfs_path *path,
30343033
u64 objectid, u64 offset, u64 bytenr)
30353034
{
30363035
struct btrfs_delayed_ref_head *head;
30373036
struct btrfs_delayed_ref_node *ref;
30383037
struct btrfs_delayed_data_ref *data_ref;
30393038
struct btrfs_delayed_ref_root *delayed_refs;
3039+
struct btrfs_transaction *cur_trans;
30403040
int ret = 0;
30413041

3042-
delayed_refs = &trans->transaction->delayed_refs;
3042+
cur_trans = root->fs_info->running_transaction;
3043+
if (!cur_trans)
3044+
return 0;
3045+
3046+
delayed_refs = &cur_trans->delayed_refs;
30433047
spin_lock(&delayed_refs->lock);
30443048
head = btrfs_find_delayed_ref_head(delayed_refs, bytenr);
30453049
if (!head) {
@@ -3090,8 +3094,7 @@ static noinline int check_delayed_ref(struct btrfs_trans_handle *trans,
30903094
return ret;
30913095
}
30923096

3093-
static noinline int check_committed_ref(struct btrfs_trans_handle *trans,
3094-
struct btrfs_root *root,
3097+
static noinline int check_committed_ref(struct btrfs_root *root,
30953098
struct btrfs_path *path,
30963099
u64 objectid, u64 offset, u64 bytenr)
30973100
{
@@ -3162,9 +3165,8 @@ static noinline int check_committed_ref(struct btrfs_trans_handle *trans,
31623165
return ret;
31633166
}
31643167

3165-
int btrfs_cross_ref_exist(struct btrfs_trans_handle *trans,
3166-
struct btrfs_root *root,
3167-
u64 objectid, u64 offset, u64 bytenr)
3168+
int btrfs_cross_ref_exist(struct btrfs_root *root, u64 objectid, u64 offset,
3169+
u64 bytenr)
31683170
{
31693171
struct btrfs_path *path;
31703172
int ret;
@@ -3175,12 +3177,12 @@ int btrfs_cross_ref_exist(struct btrfs_trans_handle *trans,
31753177
return -ENOENT;
31763178

31773179
do {
3178-
ret = check_committed_ref(trans, root, path, objectid,
3180+
ret = check_committed_ref(root, path, objectid,
31793181
offset, bytenr);
31803182
if (ret && ret != -ENOENT)
31813183
goto out;
31823184

3183-
ret2 = check_delayed_ref(trans, root, path, objectid,
3185+
ret2 = check_delayed_ref(root, path, objectid,
31843186
offset, bytenr);
31853187
} while (ret2 == -EAGAIN);
31863188

fs/btrfs/inode.c

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,6 @@ static noinline int run_delalloc_nocow(struct inode *inode,
12471247
{
12481248
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
12491249
struct btrfs_root *root = BTRFS_I(inode)->root;
1250-
struct btrfs_trans_handle *trans;
12511250
struct extent_buffer *leaf;
12521251
struct btrfs_path *path;
12531252
struct btrfs_file_extent_item *fi;
@@ -1283,30 +1282,10 @@ static noinline int run_delalloc_nocow(struct inode *inode,
12831282

12841283
nolock = btrfs_is_free_space_inode(inode);
12851284

1286-
if (nolock)
1287-
trans = btrfs_join_transaction_nolock(root);
1288-
else
1289-
trans = btrfs_join_transaction(root);
1290-
1291-
if (IS_ERR(trans)) {
1292-
extent_clear_unlock_delalloc(inode, start, end, end,
1293-
locked_page,
1294-
EXTENT_LOCKED | EXTENT_DELALLOC |
1295-
EXTENT_DO_ACCOUNTING |
1296-
EXTENT_DEFRAG, PAGE_UNLOCK |
1297-
PAGE_CLEAR_DIRTY |
1298-
PAGE_SET_WRITEBACK |
1299-
PAGE_END_WRITEBACK);
1300-
btrfs_free_path(path);
1301-
return PTR_ERR(trans);
1302-
}
1303-
1304-
trans->block_rsv = &fs_info->delalloc_block_rsv;
1305-
13061285
cow_start = (u64)-1;
13071286
cur_offset = start;
13081287
while (1) {
1309-
ret = btrfs_lookup_file_extent(trans, root, path, ino,
1288+
ret = btrfs_lookup_file_extent(NULL, root, path, ino,
13101289
cur_offset, 0);
13111290
if (ret < 0)
13121291
goto error;
@@ -1379,7 +1358,7 @@ static noinline int run_delalloc_nocow(struct inode *inode,
13791358
goto out_check;
13801359
if (btrfs_extent_readonly(fs_info, disk_bytenr))
13811360
goto out_check;
1382-
if (btrfs_cross_ref_exist(trans, root, ino,
1361+
if (btrfs_cross_ref_exist(root, ino,
13831362
found_key.offset -
13841363
extent_offset, disk_bytenr))
13851364
goto out_check;
@@ -1531,10 +1510,6 @@ static noinline int run_delalloc_nocow(struct inode *inode,
15311510
}
15321511

15331512
error:
1534-
err = btrfs_end_transaction(trans);
1535-
if (!ret)
1536-
ret = err;
1537-
15381513
if (ret && cur_offset < end)
15391514
extent_clear_unlock_delalloc(inode, cur_offset, end, end,
15401515
locked_page, EXTENT_LOCKED |
@@ -7290,7 +7265,6 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
72907265
u64 *ram_bytes)
72917266
{
72927267
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
7293-
struct btrfs_trans_handle *trans;
72947268
struct btrfs_path *path;
72957269
int ret;
72967270
struct extent_buffer *leaf;
@@ -7393,15 +7367,9 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
73937367
* look for other files referencing this extent, if we
73947368
* find any we must cow
73957369
*/
7396-
trans = btrfs_join_transaction(root);
7397-
if (IS_ERR(trans)) {
7398-
ret = 0;
7399-
goto out;
7400-
}
74017370

7402-
ret = btrfs_cross_ref_exist(trans, root, btrfs_ino(BTRFS_I(inode)),
7371+
ret = btrfs_cross_ref_exist(root, btrfs_ino(BTRFS_I(inode)),
74037372
key.offset - backref_offset, disk_bytenr);
7404-
btrfs_end_transaction(trans);
74057373
if (ret) {
74067374
ret = 0;
74077375
goto out;

0 commit comments

Comments
 (0)