From: David Sterba <dsterba@suse.cz>
To: robbieko <robbieko@synology.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 2/6] btrfs: fix raid stripe search missing entries at leaf boundaries
Date: Mon, 13 Apr 2026 21:09:02 +0200 [thread overview]
Message-ID: <20260413190902.GI12792@twin.jikos.cz> (raw)
In-Reply-To: <20260413065249.2320122-3-robbieko@synology.com>
On Mon, Apr 13, 2026 at 02:52:33PM +0800, robbieko wrote:
> 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.
>
> Signed-off-by: robbieko <robbieko@synology.com>
> ---
> fs/btrfs/raid-stripe-tree.c | 18 +++++++++++++++---
> 1 file changed, 15 insertions(+), 3 deletions(-)
>
> diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c
> index 5c519e161331..d35efe74aa1b 100644
> --- a/fs/btrfs/raid-stripe-tree.c
> +++ b/fs/btrfs/raid-stripe-tree.c
> @@ -98,14 +98,26 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le
> while (1) {
> key.objectid = start;
> key.type = BTRFS_RAID_STRIPE_KEY;
> - key.offset = 0;
> + key.offset = (u64)-1;
>
> ret = btrfs_search_slot(trans, stripe_root, &key, path, -1, 1);
> if (ret < 0)
> break;
>
> - if (path->slots[0] == btrfs_header_nritems(path->nodes[0]))
> - path->slots[0]--;
> + /*
> + * Search with offset=(u64)-1 ensures we land on the correct
> + * leaf even when the target entry is the first item on a leaf.
> + * Since no real entry has offset=(u64)-1, ret is always 1 and
This would be good to handle, not just assumed. A corruption or fuzzed
image inserting the unexpected key with offset will continue while it
should not. Handled as an EUCLEAN, like it's in many other places after
searching for tree items. I'm not sure if it's 100% covered everywhere
but this case fits the pattern.
next prev parent reply other threads:[~2026-04-13 19:09 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-13 6:52 [PATCH 0/6] btrfs: fix multiple bugs in raid-stripe-tree deletion path robbieko
2026-04-13 6:52 ` [PATCH 1/6] btrfs: copy devid in btrfs_partially_delete_raid_extent() robbieko
2026-04-13 9:14 ` Johannes Thumshirn
2026-04-13 6:52 ` [PATCH 2/6] btrfs: fix raid stripe search missing entries at leaf boundaries robbieko
2026-04-13 10:02 ` Johannes Thumshirn
2026-04-13 19:09 ` David Sterba [this message]
2026-04-13 6:52 ` [PATCH 3/6] btrfs: fix wrong min_objectid in btrfs_previous_item() call robbieko
2026-04-13 9:43 ` Johannes Thumshirn
2026-04-13 6:52 ` [PATCH 4/6] btrfs: replace ASSERT with proper error handling in stripe lookup fallback robbieko
2026-04-13 9:49 ` Johannes Thumshirn
2026-04-13 19:06 ` David Sterba
2026-04-13 6:52 ` [PATCH 5/6] btrfs: handle -EAGAIN from btrfs_duplicate_item and refresh stale leaf pointer robbieko
2026-04-13 9:54 ` Johannes Thumshirn
2026-04-13 6:52 ` [PATCH 6/6] btrfs: check return value of btrfs_partially_delete_raid_extent() robbieko
2026-04-13 10:00 ` Johannes Thumshirn
2026-04-13 9:11 ` [PATCH 0/6] btrfs: fix multiple bugs in raid-stripe-tree deletion path Johannes Thumshirn
2026-04-13 19:16 ` David Sterba
2026-04-17 2:18 ` David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260413190902.GI12792@twin.jikos.cz \
--to=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
--cc=robbieko@synology.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox