]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
btrfs: fix raid stripe search missing entries at leaf boundaries
authorrobbieko <robbieko@synology.com>
Mon, 13 Apr 2026 06:52:33 +0000 (14:52 +0800)
committerDavid Sterba <dsterba@suse.com>
Tue, 21 Apr 2026 02:02:21 +0000 (04:02 +0200)
commit2aef5cb1dcf9b3e1be3895a6477dc065e618aab8
tree0b3b5f9cc16bad605c8bafaccab94cebc69dc389
parent513f8a52eed880ea525dbb139b2127bd9bb793f1
btrfs: fix raid stripe search missing entries at leaf boundaries

In btrfs_delete_raid_extent(), the search key uses offset=0. When the
target stripe entry is the first item on a leaf, btrfs_search_slot()
may land on the previous leaf and decrementing the slot from nritems
still points to the wrong entry, causing the stripe extent to be
silently missed.

Fix this by searching with offset=(u64)-1 instead. Since no real stripe
entry has this offset, btrfs_search_slot() always returns 1 with the
slot pointing past the last matching objectid entry. Then unconditionally
decrement the slot with a proper slots[0]==0 early-exit check to handle
the case where no matching entry exists.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: robbieko <robbieko@synology.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/raid-stripe-tree.c