public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: Sun YangKai <sunk67188@gmail.com>, linux-btrfs@vger.kernel.org
Cc: fdmanana@kernel.org
Subject: Re: [PATCH v2 4/4] btrfs: ctree: cleanup btrfs_prev_leaf()
Date: Sun, 8 Feb 2026 13:43:53 +1030	[thread overview]
Message-ID: <7d712cd2-21b1-471e-917f-c39d351bc8d6@suse.com> (raw)
In-Reply-To: <ed9925c6-3664-4158-87ef-48e7316a7128@gmail.com>



在 2026/2/8 13:12, Sun YangKai 写道:

> 
> Sorry, I got a little confused here. When btrfs_search_slot() returns an 
> empty leaf, path->slots[0] will be 0 and btrfs_prev_leaf() will return 
> 1. Therefore, if btrfs_prev_leaf() returns 0, the leaf we get should 
> always be non-empty. Which part of this reasoning is incorrect? Or maybe 
> I don't get what you want to say.

Because the old btrfs_prev_leaf() can return 0 if the tree got emptied 
before btrfs_search_slot() call, if you're doing a cleanup, just don't 
change that behavior.

If you think this behavior is not correct, do it in another patch and 
explain it correctly.

>>
>> Although the change is mostly fine, if you want to keep the existing 
>> behavior, you should return 0 for empty tree to keep the old behavior.
> 
> I've not thought about the empty tree case before. But I think the 
> previous behavior in empty tree case is not proper and I don't want to 
> keep the old behavior in this case.

Then it's no longer a cleanup, and you're mixing a cleanup with a 
behavior change.

> All callers is doing
> path->slots[0]-- if btrfs_prev_leaf() returns 0 and it will cause an 
> unexpected underflow although they'll check if nritems is 0 later.

They all have proper nritems check or the tree will never be empty.

For extent tree it will never be empty, at least without extent-tree-v2 
feature.
So btrfs_previous_extent_item() should never hit an empty tree.

For btrfs_search_slot_for_read() the qgroup callers are never blindly 
decreasing slots[0], for send callers the subvolume tree will never be 
empty.

Thus all your underflow argument makes no sense.

If you don't like this behavior, again change it in a dedicated patch, 
not mixing it into the so called "cleanup" patch.


      reply	other threads:[~2026-02-08  3:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-11  7:22 [PATCH v2 0/4] btrfs: some cleanups for two ctree functions Sun YangKai
2025-12-11  7:22 ` [PATCH v2 1/4] btrfs: don't set @return_any for btrfs_search_slot_for_read in btrfs_read_qgroup_config Sun YangKai
2025-12-11  7:22 ` [PATCH v2 2/4] btrfs: don't set return_any @return_any for btrfs_search_slot_for_read in get_last_extent() Sun YangKai
2025-12-11  7:22 ` [PATCH v2 3/4] btrfs: cleanup btrfs_search_slot_for_read() Sun YangKai
2025-12-11  7:22 ` [PATCH v2 4/4] btrfs: ctree: cleanup btrfs_prev_leaf() Sun YangKai
2026-02-07 23:09   ` Qu Wenruo
2026-02-08  2:42     ` Sun YangKai
2026-02-08  3:13       ` Qu Wenruo [this message]

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=7d712cd2-21b1-471e-917f-c39d351bc8d6@suse.com \
    --to=wqu@suse.com \
    --cc=fdmanana@kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=sunk67188@gmail.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