]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
btrfs: convert BUG_ON in btrfs_reloc_cow_block() to proper error handling
authorJosef Bacik <josef@toxicpanda.com>
Thu, 3 Oct 2024 15:43:03 +0000 (11:43 -0400)
committerDavid Sterba <dsterba@suse.com>
Mon, 13 Jan 2025 13:53:14 +0000 (14:53 +0100)
This BUG_ON is meant to catch backref cache problems, but these can
arise from either bugs in the backref cache or corruption in the extent
tree.  Fix it to be a proper error.

Reviewed-by: Boris Burkov <boris@bur.io>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/relocation.c

index db8b42f674b7c817256b02b868a726ebd0ab12aa..ab2de2d1b2beed3cabb15611900e2b86e78f33d4 100644 (file)
@@ -4405,8 +4405,18 @@ int btrfs_reloc_cow_block(struct btrfs_trans_handle *trans,
                WARN_ON(!first_cow && level == 0);
 
                node = rc->backref_cache.path[level];
-               BUG_ON(node->bytenr != buf->start &&
-                      node->new_bytenr != buf->start);
+
+               /*
+                * If node->bytenr != buf->start and node->new_bytenr !=
+                * buf->start then we've got the wrong backref node for what we
+                * expected to see here and the cache is incorrect.
+                */
+               if (unlikely(node->bytenr != buf->start && node->new_bytenr != buf->start)) {
+                       btrfs_err(fs_info,
+"bytenr %llu was found but our backref cache was expecting %llu or %llu",
+                                 buf->start, node->bytenr, node->new_bytenr);
+                       return -EUCLEAN;
+               }
 
                btrfs_backref_drop_node_buffer(node);
                atomic_inc(&cow->refs);