Skip to content

Commit 59bbf62

Browse files
committed
btrfs: remaining BTRFS_PATH_AUTO_FREE conversions
Do the remaining btrfs_path conversion to the auto cleaning, this seems to be the last one. Most of the conversions are trivial, only adding the declaration and removing the freeing, or changing the goto patterns to return. There are some functions with many changes, like __btrfs_free_extent(), btrfs_remove_from_free_space_tree() or btrfs_add_to_free_space_tree() but it still follows the same pattern. Signed-off-by: David Sterba <dsterba@suse.com>
1 parent fce0a90 commit 59bbf62

File tree

12 files changed

+105
-176
lines changed

12 files changed

+105
-176
lines changed

fs/btrfs/block-group.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
10651065
struct btrfs_chunk_map *map)
10661066
{
10671067
struct btrfs_fs_info *fs_info = trans->fs_info;
1068-
struct btrfs_path *path;
1068+
BTRFS_PATH_AUTO_FREE(path);
10691069
struct btrfs_block_group *block_group;
10701070
struct btrfs_free_cluster *cluster;
10711071
struct inode *inode;
@@ -1305,7 +1305,6 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
13051305
btrfs_put_block_group(block_group);
13061306
if (remove_rsv)
13071307
btrfs_dec_delayed_refs_rsv_bg_updates(fs_info);
1308-
btrfs_free_path(path);
13091308
return ret;
13101309
}
13111310

fs/btrfs/dir-item.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans,
112112
int ret = 0;
113113
int ret2 = 0;
114114
struct btrfs_root *root = dir->root;
115-
struct btrfs_path *path;
115+
BTRFS_PATH_AUTO_FREE(path);
116116
struct btrfs_dir_item *dir_item;
117117
struct extent_buffer *leaf;
118118
unsigned long name_ptr;
@@ -164,7 +164,6 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans,
164164
ret2 = btrfs_insert_delayed_dir_index(trans, name->name, name->len, dir,
165165
&disk_key, type, index);
166166
out_free:
167-
btrfs_free_path(path);
168167
if (ret)
169168
return ret;
170169
if (ret2)

fs/btrfs/extent-tree.c

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3085,7 +3085,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
30853085
{
30863086
struct btrfs_fs_info *info = trans->fs_info;
30873087
struct btrfs_key key;
3088-
struct btrfs_path *path;
3088+
BTRFS_PATH_AUTO_FREE(path);
30893089
struct btrfs_root *extent_root;
30903090
struct extent_buffer *leaf;
30913091
struct btrfs_extent_item *ei;
@@ -3120,7 +3120,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
31203120
node->bytenr, refs_to_drop);
31213121
ret = -EINVAL;
31223122
btrfs_abort_transaction(trans, ret);
3123-
goto out;
3123+
return ret;
31243124
}
31253125

31263126
if (is_data)
@@ -3165,15 +3165,14 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
31653165
abort_and_dump(trans, path,
31663166
"invalid iref slot %u, no EXTENT/METADATA_ITEM found but has inline extent ref",
31673167
path->slots[0]);
3168-
ret = -EUCLEAN;
3169-
goto out;
3168+
return -EUCLEAN;
31703169
}
31713170
/* Must be SHARED_* item, remove the backref first */
31723171
ret = remove_extent_backref(trans, extent_root, path,
31733172
NULL, refs_to_drop, is_data);
31743173
if (unlikely(ret)) {
31753174
btrfs_abort_transaction(trans, ret);
3176-
goto out;
3175+
return ret;
31773176
}
31783177
btrfs_release_path(path);
31793178

@@ -3222,7 +3221,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
32223221
}
32233222
if (unlikely(ret < 0)) {
32243223
btrfs_abort_transaction(trans, ret);
3225-
goto out;
3224+
return ret;
32263225
}
32273226
extent_slot = path->slots[0];
32283227
}
@@ -3231,10 +3230,10 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
32313230
"unable to find ref byte nr %llu parent %llu root %llu owner %llu offset %llu slot %d",
32323231
bytenr, node->parent, node->ref_root, owner_objectid,
32333232
owner_offset, path->slots[0]);
3234-
goto out;
3233+
return ret;
32353234
} else {
32363235
btrfs_abort_transaction(trans, ret);
3237-
goto out;
3236+
return ret;
32383237
}
32393238

32403239
leaf = path->nodes[0];
@@ -3245,7 +3244,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
32453244
"unexpected extent item size, has %u expect >= %zu",
32463245
item_size, sizeof(*ei));
32473246
btrfs_abort_transaction(trans, ret);
3248-
goto out;
3247+
return ret;
32493248
}
32503249
ei = btrfs_item_ptr(leaf, extent_slot,
32513250
struct btrfs_extent_item);
@@ -3259,8 +3258,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
32593258
key.objectid, key.type, key.offset,
32603259
path->slots[0], owner_objectid, item_size,
32613260
sizeof(*ei) + sizeof(*bi));
3262-
ret = -EUCLEAN;
3263-
goto out;
3261+
return -EUCLEAN;
32643262
}
32653263
bi = (struct btrfs_tree_block_info *)(ei + 1);
32663264
WARN_ON(owner_objectid != btrfs_tree_block_level(leaf, bi));
@@ -3271,8 +3269,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
32713269
abort_and_dump(trans, path,
32723270
"trying to drop %d refs but we only have %llu for bytenr %llu slot %u",
32733271
refs_to_drop, refs, bytenr, path->slots[0]);
3274-
ret = -EUCLEAN;
3275-
goto out;
3272+
return -EUCLEAN;
32763273
}
32773274
refs -= refs_to_drop;
32783275

@@ -3288,8 +3285,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
32883285
abort_and_dump(trans, path,
32893286
"invalid iref, got inlined extent ref but no EXTENT/METADATA_ITEM found, slot %u",
32903287
path->slots[0]);
3291-
ret = -EUCLEAN;
3292-
goto out;
3288+
return -EUCLEAN;
32933289
}
32943290
} else {
32953291
btrfs_set_extent_refs(leaf, ei, refs);
@@ -3299,7 +3295,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
32993295
iref, refs_to_drop, is_data);
33003296
if (unlikely(ret)) {
33013297
btrfs_abort_transaction(trans, ret);
3302-
goto out;
3298+
return ret;
33033299
}
33043300
}
33053301
} else {
@@ -3319,17 +3315,15 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
33193315
"invalid refs_to_drop, current refs %u refs_to_drop %u slot %u",
33203316
extent_data_ref_count(path, iref),
33213317
refs_to_drop, path->slots[0]);
3322-
ret = -EUCLEAN;
3323-
goto out;
3318+
return -EUCLEAN;
33243319
}
33253320
if (iref) {
33263321
if (unlikely(path->slots[0] != extent_slot)) {
33273322
abort_and_dump(trans, path,
33283323
"invalid iref, extent item key " BTRFS_KEY_FMT " slot %u doesn't have wanted iref",
33293324
BTRFS_KEY_FMT_VALUE(&key),
33303325
path->slots[0]);
3331-
ret = -EUCLEAN;
3332-
goto out;
3326+
return -EUCLEAN;
33333327
}
33343328
} else {
33353329
/*
@@ -3342,8 +3336,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
33423336
abort_and_dump(trans, path,
33433337
"invalid SHARED_* item slot %u, previous item is not EXTENT/METADATA_ITEM",
33443338
path->slots[0]);
3345-
ret = -EUCLEAN;
3346-
goto out;
3339+
return -EUCLEAN;
33473340
}
33483341
path->slots[0] = extent_slot;
33493342
num_to_del = 2;
@@ -3364,16 +3357,14 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
33643357
num_to_del);
33653358
if (unlikely(ret)) {
33663359
btrfs_abort_transaction(trans, ret);
3367-
goto out;
3360+
return ret;
33683361
}
33693362
btrfs_release_path(path);
33703363

33713364
ret = do_free_extent_accounting(trans, bytenr, &delta);
33723365
}
33733366
btrfs_release_path(path);
33743367

3375-
out:
3376-
btrfs_free_path(path);
33773368
return ret;
33783369
}
33793370

fs/btrfs/free-space-tree.c

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ int btrfs_remove_from_free_space_tree(struct btrfs_trans_handle *trans,
833833
u64 start, u64 size)
834834
{
835835
struct btrfs_block_group *block_group;
836-
struct btrfs_path *path;
836+
BTRFS_PATH_AUTO_FREE(path);
837837
int ret;
838838

839839
if (!btrfs_fs_compat_ro(trans->fs_info, FREE_SPACE_TREE))
@@ -843,15 +843,15 @@ int btrfs_remove_from_free_space_tree(struct btrfs_trans_handle *trans,
843843
if (unlikely(!path)) {
844844
ret = -ENOMEM;
845845
btrfs_abort_transaction(trans, ret);
846-
goto out;
846+
return ret;
847847
}
848848

849849
block_group = btrfs_lookup_block_group(trans->fs_info, start);
850850
if (unlikely(!block_group)) {
851851
DEBUG_WARN("no block group found for start=%llu", start);
852852
ret = -ENOENT;
853853
btrfs_abort_transaction(trans, ret);
854-
goto out;
854+
return ret;
855855
}
856856

857857
mutex_lock(&block_group->free_space_lock);
@@ -861,8 +861,7 @@ int btrfs_remove_from_free_space_tree(struct btrfs_trans_handle *trans,
861861
btrfs_abort_transaction(trans, ret);
862862

863863
btrfs_put_block_group(block_group);
864-
out:
865-
btrfs_free_path(path);
864+
866865
return ret;
867866
}
868867

@@ -1015,7 +1014,7 @@ int btrfs_add_to_free_space_tree(struct btrfs_trans_handle *trans,
10151014
u64 start, u64 size)
10161015
{
10171016
struct btrfs_block_group *block_group;
1018-
struct btrfs_path *path;
1017+
BTRFS_PATH_AUTO_FREE(path);
10191018
int ret;
10201019

10211020
if (!btrfs_fs_compat_ro(trans->fs_info, FREE_SPACE_TREE))
@@ -1025,15 +1024,15 @@ int btrfs_add_to_free_space_tree(struct btrfs_trans_handle *trans,
10251024
if (unlikely(!path)) {
10261025
ret = -ENOMEM;
10271026
btrfs_abort_transaction(trans, ret);
1028-
goto out;
1027+
return ret;
10291028
}
10301029

10311030
block_group = btrfs_lookup_block_group(trans->fs_info, start);
10321031
if (unlikely(!block_group)) {
10331032
DEBUG_WARN("no block group found for start=%llu", start);
10341033
ret = -ENOENT;
10351034
btrfs_abort_transaction(trans, ret);
1036-
goto out;
1035+
return ret;
10371036
}
10381037

10391038
mutex_lock(&block_group->free_space_lock);
@@ -1043,8 +1042,7 @@ int btrfs_add_to_free_space_tree(struct btrfs_trans_handle *trans,
10431042
btrfs_abort_transaction(trans, ret);
10441043

10451044
btrfs_put_block_group(block_group);
1046-
out:
1047-
btrfs_free_path(path);
1045+
10481046
return ret;
10491047
}
10501048

@@ -1458,7 +1456,7 @@ int btrfs_remove_block_group_free_space(struct btrfs_trans_handle *trans,
14581456
struct btrfs_block_group *block_group)
14591457
{
14601458
struct btrfs_root *root = btrfs_free_space_root(block_group);
1461-
struct btrfs_path *path;
1459+
BTRFS_PATH_AUTO_FREE(path);
14621460
struct btrfs_key key, found_key;
14631461
struct extent_buffer *leaf;
14641462
u64 start, end;
@@ -1477,7 +1475,7 @@ int btrfs_remove_block_group_free_space(struct btrfs_trans_handle *trans,
14771475
if (unlikely(!path)) {
14781476
ret = -ENOMEM;
14791477
btrfs_abort_transaction(trans, ret);
1480-
goto out;
1478+
return ret;
14811479
}
14821480

14831481
start = block_group->start;
@@ -1491,7 +1489,7 @@ int btrfs_remove_block_group_free_space(struct btrfs_trans_handle *trans,
14911489
ret = btrfs_search_prev_slot(trans, root, &key, path, -1, 1);
14921490
if (unlikely(ret)) {
14931491
btrfs_abort_transaction(trans, ret);
1494-
goto out;
1492+
return ret;
14951493
}
14961494

14971495
leaf = path->nodes[0];
@@ -1522,14 +1520,13 @@ int btrfs_remove_block_group_free_space(struct btrfs_trans_handle *trans,
15221520
ret = btrfs_del_items(trans, root, path, path->slots[0], nr);
15231521
if (unlikely(ret)) {
15241522
btrfs_abort_transaction(trans, ret);
1525-
goto out;
1523+
return ret;
15261524
}
15271525
btrfs_release_path(path);
15281526
}
15291527

15301528
ret = 0;
1531-
out:
1532-
btrfs_free_path(path);
1529+
15331530
return ret;
15341531
}
15351532

fs/btrfs/inode-item.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
444444
struct btrfs_truncate_control *control)
445445
{
446446
struct btrfs_fs_info *fs_info = root->fs_info;
447-
struct btrfs_path *path;
447+
BTRFS_PATH_AUTO_FREE(path);
448448
struct extent_buffer *leaf;
449449
struct btrfs_file_extent_item *fi;
450450
struct btrfs_key key;
@@ -730,6 +730,5 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
730730
if (!ret && control->last_size > new_size)
731731
control->last_size = new_size;
732732

733-
btrfs_free_path(path);
734733
return ret;
735734
}

fs/btrfs/inode.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4462,7 +4462,7 @@ static int btrfs_unlink_subvol(struct btrfs_trans_handle *trans,
44624462
{
44634463
struct btrfs_root *root = dir->root;
44644464
struct btrfs_inode *inode = BTRFS_I(d_inode(dentry));
4465-
struct btrfs_path *path;
4465+
BTRFS_PATH_AUTO_FREE(path);
44664466
struct extent_buffer *leaf;
44674467
struct btrfs_dir_item *di;
44684468
struct btrfs_key key;
@@ -4555,7 +4555,6 @@ static int btrfs_unlink_subvol(struct btrfs_trans_handle *trans,
45554555
if (ret)
45564556
btrfs_abort_transaction(trans, ret);
45574557
out:
4558-
btrfs_free_path(path);
45594558
fscrypt_free_filename(&fname);
45604559
return ret;
45614560
}

0 commit comments

Comments
 (0)