btrfs-progs: add more error handling to btrfs_free_block_group
authorDavid Sterba <dsterba@suse.com>
Tue, 29 Aug 2017 15:53:39 +0000 (17:53 +0200)
committerDavid Sterba <dsterba@suse.com>
Fri, 8 Sep 2017 14:15:05 +0000 (16:15 +0200)
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 <dsterba@suse.com>
cmds-check.c
extent-tree.c

index 5df4630..7ee81d8 100644 (file)
@@ -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;
index f1cc4bf..9c70908 100644 (file)
@@ -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,