@@ -5187,8 +5187,16 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
parent = ins.objectid;
flags |= BTRFS_BLOCK_FLAG_FULL_BACKREF;
owning_root = reloc_src_root;
- } else
- BUG_ON(parent > 0);
+ } else {
+ if (unlikely(parent > 0)) {
+ /*
+ * Other roots than reloc tree don't expect start
+ * offset of a parent block.
+ */
+ ret = -EUCLEAN;
+ goto out_free_reserved;
+ }
+ }
if (root_objectid != BTRFS_TREE_LOG_OBJECTID) {
extent_op = btrfs_alloc_delayed_extent_op();
Change a BUG_ON to a proper error handling, here it checks that a root other than reloc tree does not see a non-zero offset. This is set by btrfs_force_cow_block() and is a special case so the check makes sure it's not accidentally set by other callers. Signed-off-by: David Sterba <dsterba@suse.com> --- fs/btrfs/extent-tree.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)