Skip to content

Commit 89962af

Browse files
fdmananakdave
authored andcommitted
btrfs: always abort transaction on failure to add block group to free space tree
Only one of the callers of __add_block_group_free_space() aborts the transaction if the call fails, while the others don't do it and it's either never done up the call chain or much higher in the call chain. So make sure we abort the transaction at __add_block_group_free_space() if it fails, which brings a couple benefits: 1) If some call chain never aborts the transaction, we avoid having some metadata inconsistency because BLOCK_GROUP_FLAG_NEEDS_FREE_SPACE is cleared when we enter __add_block_group_free_space() and therefore __add_block_group_free_space() is never called again to add the block group items to the free space tree, since the function is only called when that flag is set in a block group; 2) If the call chain already aborts the transaction, then we get a better trace that points to the exact step from __add_block_group_free_space() which failed, which is better for analysis. So abort the transaction at __add_block_group_free_space() if any of its steps fails. Reviewed-by: Boris Burkov <boris@bur.io> Signed-off-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 3ca8273 commit 89962af

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

fs/btrfs/free-space-tree.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,12 +1431,17 @@ static int __add_block_group_free_space(struct btrfs_trans_handle *trans,
14311431
set_bit(BLOCK_GROUP_FLAG_FREE_SPACE_ADDED, &block_group->runtime_flags);
14321432

14331433
ret = add_new_free_space_info(trans, block_group, path);
1434-
if (ret)
1434+
if (ret) {
1435+
btrfs_abort_transaction(trans, ret);
14351436
return ret;
1437+
}
14361438

1437-
return __add_to_free_space_tree(trans, block_group, path,
1438-
block_group->start,
1439-
block_group->length);
1439+
ret = __add_to_free_space_tree(trans, block_group, path,
1440+
block_group->start, block_group->length);
1441+
if (ret)
1442+
btrfs_abort_transaction(trans, ret);
1443+
1444+
return 0;
14401445
}
14411446

14421447
int add_block_group_free_space(struct btrfs_trans_handle *trans,
@@ -1461,9 +1466,6 @@ int add_block_group_free_space(struct btrfs_trans_handle *trans,
14611466
}
14621467

14631468
ret = __add_block_group_free_space(trans, block_group, path);
1464-
if (ret)
1465-
btrfs_abort_transaction(trans, ret);
1466-
14671469
out:
14681470
btrfs_free_path(path);
14691471
mutex_unlock(&block_group->free_space_lock);

0 commit comments

Comments
 (0)