]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
btrfs: replace BUG_ON() with error handling at update_ref_for_cow()
authorFilipe Manana <fdmanana@suse.com>
Tue, 18 Jun 2024 14:55:16 +0000 (15:55 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 12 Sep 2024 09:11:37 +0000 (11:11 +0200)
[ Upstream commit b56329a782314fde5b61058e2a25097af7ccb675 ]

Instead of a BUG_ON() just return an error, log an error message and
abort the transaction in case we find an extent buffer belonging to the
relocation tree that doesn't have the full backref flag set. This is
unexpected and should never happen (save for bugs or a potential bad
memory).

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/btrfs/ctree.c

index 118ad4d2cbbe264ad1ab3d4ac46d85aa4802ae38..2eb4e03080ac9b34e7dc2288e149bb701cc03e27 100644 (file)
@@ -451,8 +451,16 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans,
        }
 
        owner = btrfs_header_owner(buf);
-       BUG_ON(owner == BTRFS_TREE_RELOC_OBJECTID &&
-              !(flags & BTRFS_BLOCK_FLAG_FULL_BACKREF));
+       if (unlikely(owner == BTRFS_TREE_RELOC_OBJECTID &&
+                    !(flags & BTRFS_BLOCK_FLAG_FULL_BACKREF))) {
+               btrfs_crit(fs_info,
+"found tree block at bytenr %llu level %d root %llu refs %llu flags %llx without full backref flag set",
+                          buf->start, btrfs_header_level(buf),
+                          btrfs_root_id(root), refs, flags);
+               ret = -EUCLEAN;
+               btrfs_abort_transaction(trans, ret);
+               return ret;
+       }
 
        if (refs > 1) {
                if ((owner == root->root_key.objectid ||