From: Sun YangKai <sunk67188@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Sun YangKai <sunk67188@gmail.com>
Subject: [PATCH 3/4] btrfs: cleanup btrfs_search_slot_for_read()
Date: Tue, 9 Dec 2025 11:27:20 +0800 [thread overview]
Message-ID: <20251209033747.31010-4-sunk67188@gmail.com> (raw)
In-Reply-To: <20251209033747.31010-1-sunk67188@gmail.com>
Now @return_any is not used by any caller, remove it and related logic.
@for_read is used as boolean, so convert it from int to bool.
No functional change.
Signed-off-by: Sun YangKai <sunk67188@gmail.com>
---
fs/btrfs/ctree.c | 47 ++++++--------------------------------
fs/btrfs/ctree.h | 3 +--
fs/btrfs/free-space-tree.c | 2 +-
fs/btrfs/qgroup.c | 10 ++++----
fs/btrfs/send.c | 12 +++++-----
5 files changed, 20 insertions(+), 54 deletions(-)
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index ee6e5c393873..bb886f9508e2 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -2439,22 +2439,14 @@ static int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path)
* instead the next or previous item should be returned.
* When find_higher is true, the next higher item is returned, the next lower
* otherwise.
- * When return_any and find_higher are both true, and no higher item is found,
- * return the next lower instead.
- * When return_any is true and find_higher is false, and no lower item is found,
- * return the next higher instead.
- * It returns 0 if any item is found, 1 if none is found (tree empty), and
- * < 0 on error
+ * It returns 0 if any item is found, 1 if none is found and < 0 on error
*/
int btrfs_search_slot_for_read(struct btrfs_root *root,
const struct btrfs_key *key,
- struct btrfs_path *p, int find_higher,
- int return_any)
+ struct btrfs_path *p, bool find_higher)
{
int ret;
- struct extent_buffer *leaf;
-again:
ret = btrfs_search_slot(NULL, root, key, p, 0, 0);
if (ret <= 0)
return ret;
@@ -2465,47 +2457,22 @@ int btrfs_search_slot_for_read(struct btrfs_root *root,
* to the first free slot in the previous leaf, i.e. at an invalid
* item.
*/
- leaf = p->nodes[0];
-
if (find_higher) {
- if (p->slots[0] >= btrfs_header_nritems(leaf)) {
- ret = btrfs_next_leaf(root, p);
- if (ret <= 0)
- return ret;
- if (!return_any)
- return 1;
- /*
- * no higher item found, return the next
- * lower instead
- */
- return_any = 0;
- find_higher = 0;
- btrfs_release_path(p);
- goto again;
- }
+ if (p->slots[0] >= btrfs_header_nritems(p->nodes[0]))
+ return btrfs_next_leaf(root, p);
} else {
if (p->slots[0] == 0) {
ret = btrfs_prev_leaf(root, p);
if (ret < 0)
return ret;
if (!ret) {
- leaf = p->nodes[0];
- if (p->slots[0] == btrfs_header_nritems(leaf))
+ if (p->slots[0] == btrfs_header_nritems(p->nodes[0]))
p->slots[0]--;
return 0;
}
- if (!return_any)
- return 1;
- /*
- * no lower item found, return the next
- * higher instead
- */
- return_any = 0;
- find_higher = 1;
- btrfs_release_path(p);
- goto again;
+ return 1;
} else {
- --p->slots[0];
+ p->slots[0]--;
}
}
return 0;
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 692370fc07b2..4b7b8ce7e211 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -595,8 +595,7 @@ int btrfs_search_old_slot(struct btrfs_root *root, const struct btrfs_key *key,
struct btrfs_path *p, u64 time_seq);
int btrfs_search_slot_for_read(struct btrfs_root *root,
const struct btrfs_key *key,
- struct btrfs_path *p, int find_higher,
- int return_any);
+ struct btrfs_path *p, bool find_higher);
void btrfs_release_path(struct btrfs_path *p);
struct btrfs_path *btrfs_alloc_path(void);
void btrfs_free_path(struct btrfs_path *p);
diff --git a/fs/btrfs/free-space-tree.c b/fs/btrfs/free-space-tree.c
index 1ad2ad384b9e..88c46950f5d2 100644
--- a/fs/btrfs/free-space-tree.c
+++ b/fs/btrfs/free-space-tree.c
@@ -1089,7 +1089,7 @@ static int populate_free_space_tree(struct btrfs_trans_handle *trans,
key.offset = 0;
extent_root = btrfs_extent_root(trans->fs_info, key.objectid);
- ret = btrfs_search_slot_for_read(extent_root, &key, path, 1, 0);
+ ret = btrfs_search_slot_for_read(extent_root, &key, path, true);
if (ret < 0)
goto out_locked;
/*
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index d780980e6790..bd458ba537ba 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -415,7 +415,7 @@ int btrfs_read_qgroup_config(struct btrfs_fs_info *fs_info)
key.objectid = 0;
key.type = 0;
key.offset = 0;
- ret = btrfs_search_slot_for_read(quota_root, &key, path, 1, 0);
+ ret = btrfs_search_slot_for_read(quota_root, &key, path, true);
if (ret)
goto out;
@@ -530,7 +530,7 @@ int btrfs_read_qgroup_config(struct btrfs_fs_info *fs_info)
key.objectid = 0;
key.type = BTRFS_QGROUP_RELATION_KEY;
key.offset = 0;
- ret = btrfs_search_slot_for_read(quota_root, &key, path, 1, 0);
+ ret = btrfs_search_slot_for_read(quota_root, &key, path, true);
if (ret)
goto out;
while (1) {
@@ -1088,7 +1088,7 @@ int btrfs_quota_enable(struct btrfs_fs_info *fs_info,
key.offset = 0;
btrfs_release_path(path);
- ret = btrfs_search_slot_for_read(tree_root, &key, path, 1, 0);
+ ret = btrfs_search_slot_for_read(tree_root, &key, path, true);
if (ret > 0)
goto out_add_root;
if (unlikely(ret < 0)) {
@@ -1130,7 +1130,7 @@ int btrfs_quota_enable(struct btrfs_fs_info *fs_info,
goto out_free_path;
}
ret = btrfs_search_slot_for_read(tree_root, &found_key,
- path, 1, 0);
+ path, true);
if (unlikely(ret < 0)) {
btrfs_abort_transaction(trans, ret);
goto out_free_path;
@@ -3692,7 +3692,7 @@ static int qgroup_rescan_leaf(struct btrfs_trans_handle *trans,
fs_info->qgroup_rescan_progress.objectid);
ret = btrfs_search_slot_for_read(extent_root,
&fs_info->qgroup_rescan_progress,
- path, 1, 0);
+ path, true);
btrfs_debug(fs_info,
"current progress key " BTRFS_KEY_FMT ", search_slot ret %d",
diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index eae596b80ec0..471e81a8e844 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -1234,7 +1234,7 @@ static int get_inode_path(struct btrfs_root *root,
key.type = BTRFS_INODE_REF_KEY;
key.offset = 0;
- ret = btrfs_search_slot_for_read(root, &key, p, 1, 0);
+ ret = btrfs_search_slot_for_read(root, &key, p, true);
if (ret < 0)
return ret;
if (ret)
@@ -1979,7 +1979,7 @@ static int get_first_ref(struct btrfs_root *root, u64 ino,
key.type = BTRFS_INODE_REF_KEY;
key.offset = 0;
- ret = btrfs_search_slot_for_read(root, &key, path, 1, 0);
+ ret = btrfs_search_slot_for_read(root, &key, path, true);
if (ret < 0)
return ret;
if (!ret)
@@ -2475,7 +2475,7 @@ static int send_subvol_begin(struct send_ctx *sctx)
key.offset = 0;
ret = btrfs_search_slot_for_read(send_root->fs_info->tree_root,
- &key, path, 1, 0);
+ &key, path, true);
if (ret < 0)
return ret;
if (ret)
@@ -6195,7 +6195,7 @@ static int is_extent_unchanged(struct send_ctx *sctx,
key.objectid = ekey->objectid;
key.type = BTRFS_EXTENT_DATA_KEY;
key.offset = ekey->offset;
- ret = btrfs_search_slot_for_read(sctx->parent_root, &key, path, 0, 0);
+ ret = btrfs_search_slot_for_read(sctx->parent_root, &key, path, false);
if (ret < 0)
return ret;
if (ret)
@@ -6320,7 +6320,7 @@ static int get_last_extent(struct send_ctx *sctx, u64 offset)
key.objectid = sctx->cur_ino;
key.type = BTRFS_EXTENT_DATA_KEY;
key.offset = offset;
- ret = btrfs_search_slot_for_read(root, &key, path, 0, 0);
+ ret = btrfs_search_slot_for_read(root, &key, path, false);
if (ret < 0)
return ret;
ASSERT(ret == 0);
@@ -7288,7 +7288,7 @@ static int full_send_tree(struct send_ctx *sctx)
sctx->last_reloc_trans = fs_info->last_reloc_trans;
up_read(&fs_info->commit_root_sem);
- ret = btrfs_search_slot_for_read(send_root, &key, path, 1, 0);
+ ret = btrfs_search_slot_for_read(send_root, &key, path, true);
if (ret < 0)
return ret;
if (ret)
--
2.51.2
next prev parent reply other threads:[~2025-12-09 3:38 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-09 3:27 [PATCH 0/4] btrfs: some cleanups for two ctree functions Sun YangKai
2025-12-09 3:27 ` [PATCH 1/4] btrfs: don't set @return_any for btrfs_search_slot_for_read in btrfs_read_qgroup_config Sun YangKai
2025-12-09 3:27 ` [PATCH 2/4] btrfs: don't set return_any @return_any for btrfs_search_slot_for_read in get_last_extent() Sun YangKai
2025-12-09 3:27 ` Sun YangKai [this message]
2025-12-09 3:27 ` [PATCH 4/4] btrfs: ctree: cleanup btrfs_prev_leaf() Sun YangKai
2025-12-09 4:05 ` Sun Yangkai
2025-12-09 12:05 ` Filipe Manana
2025-12-09 12:27 ` Sun Yangkai
2026-02-07 8:50 ` Sun YangKai
2026-02-07 10:18 ` Qu Wenruo
2026-02-07 15:07 ` Sun YangKai
2025-12-09 13:57 ` Sun Yangkai
2025-12-09 14:04 ` Sun Yangkai
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=20251209033747.31010-4-sunk67188@gmail.com \
--to=sunk67188@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.