From 1fc20730db28f522c8c807386a7cace2f23e9da9 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 29 Aug 2017 17:53:39 +0200 Subject: [PATCH] btrfs-progs: add more error handling to btrfs_free_block_group As btrfs_update_block_group fails when the block group is not found in cache, we can exit btrfs_free_block_group, not much to rollback. The caller will also exit in turn. Signed-off-by: David Sterba --- cmds-check.c | 4 +++- extent-tree.c | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cmds-check.c b/cmds-check.c index 5df46306..7ee81d81 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -9467,7 +9467,9 @@ repair_abort: goto repair_abort; } - btrfs_fix_block_accounting(trans, root); + ret = btrfs_fix_block_accounting(trans, root); + if (ret) + goto repair_abort; ret = btrfs_commit_transaction(trans, root); if (ret) goto repair_abort; diff --git a/extent-tree.c b/extent-tree.c index f1cc4bfe..9c70908a 100644 --- a/extent-tree.c +++ b/extent-tree.c @@ -3840,7 +3840,7 @@ out: int btrfs_fix_block_accounting(struct btrfs_trans_handle *trans, struct btrfs_root *root) { - int ret; + int ret = 0; int slot; u64 start = 0; u64 bytes_used = 0; @@ -3904,13 +3904,16 @@ int btrfs_fix_block_accounting(struct btrfs_trans_handle *trans, bytes_used += fs_info->nodesize; ret = btrfs_update_block_group(trans, root, key.objectid, fs_info->nodesize, 1, 0); - BUG_ON(ret); + if (ret) + goto out; } path.slots[0]++; } btrfs_set_super_bytes_used(root->fs_info->super_copy, bytes_used); + ret = 0; +out: btrfs_release_path(&path); - return 0; + return ret; } static void __get_extent_size(struct btrfs_root *root, struct btrfs_path *path,