This probably can't happen even with a corrupt file system, because we
would have failed much earlier on than here.  However there's no reason
we can't just check and bail out as appropriate, so do that and convert
the correctness BUG_ON() to an ASSERT().

Reviewed-by: Qu Wenruo <[email protected]>
Signed-off-by: Josef Bacik <[email protected]>
---
 fs/btrfs/relocation.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 39d5cb9360a2..56f1fce7c746 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -1880,8 +1880,14 @@ int prepare_to_merge(struct reloc_control *rc, int err)
 
                root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset,
                                false);
-               BUG_ON(IS_ERR(root));
-               BUG_ON(root->reloc_root != reloc_root);
+               if (IS_ERR(root)) {
+                       list_add(&reloc_root->root_list, &reloc_roots);
+                       btrfs_abort_transaction(trans, (int)PTR_ERR(root));
+                       if (!err)
+                               err = PTR_ERR(root);
+                       break;
+               }
+               ASSERT(root->reloc_root == reloc_root);
 
                /*
                 * set reference count to 1, so btrfs_recover_relocation
-- 
2.26.2

Reply via email to