* [PATCH 1/4] btrfs: remove redundant level argument from read_block_for_search()
2024-10-16 14:20 [PATCH 0/4] btrfs: some cleanups around read_block_for_search() fdmanana
@ 2024-10-16 14:20 ` fdmanana
2024-10-16 14:20 ` [PATCH 2/4] btrfs: simplify arguments for btrfs_verify_level_key() fdmanana
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: fdmanana @ 2024-10-16 14:20 UTC (permalink / raw)
To: linux-btrfs
From: Filipe Manana <fdmanana@suse.com>
The level parameter passed to read_block_for_search() always matches the
level of the extent buffer passed in the "eb_ret" parameter, which we are
also extracting into the "parent_level" local variable.
So remove the level parameter and instead use the "parent_level" variable
which in fact has a better (it's the level of the parent node from which
we are reading a child node/leaf).
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
fs/btrfs/ctree.c | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 4f34208126f7..428c5650559a 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -1508,7 +1508,7 @@ static noinline void unlock_up(struct btrfs_path *path, int level,
*/
static int
read_block_for_search(struct btrfs_root *root, struct btrfs_path *p,
- struct extent_buffer **eb_ret, int level, int slot,
+ struct extent_buffer **eb_ret, int slot,
const struct btrfs_key *key)
{
struct btrfs_fs_info *fs_info = root->fs_info;
@@ -1542,7 +1542,7 @@ read_block_for_search(struct btrfs_root *root, struct btrfs_path *p,
tmp = find_extent_buffer(fs_info, blocknr);
if (tmp) {
if (p->reada == READA_FORWARD_ALWAYS)
- reada_for_search(fs_info, p, level, slot, key->objectid);
+ reada_for_search(fs_info, p, parent_level, slot, key->objectid);
/* first we do an atomic uptodate check */
if (btrfs_buffer_uptodate(tmp, gen, 1) > 0) {
@@ -1568,7 +1568,7 @@ read_block_for_search(struct btrfs_root *root, struct btrfs_path *p,
}
if (!p->skip_locking) {
- btrfs_unlock_up_safe(p, level + 1);
+ btrfs_unlock_up_safe(p, parent_level + 1);
tmp_locked = true;
btrfs_tree_read_lock(tmp);
btrfs_release_path(p);
@@ -1595,12 +1595,12 @@ read_block_for_search(struct btrfs_root *root, struct btrfs_path *p,
}
if (!p->skip_locking) {
- btrfs_unlock_up_safe(p, level + 1);
+ btrfs_unlock_up_safe(p, parent_level + 1);
ret = -EAGAIN;
}
if (p->reada != READA_NONE)
- reada_for_search(fs_info, p, level, slot, key->objectid);
+ reada_for_search(fs_info, p, parent_level, slot, key->objectid);
tmp = btrfs_find_create_tree_block(fs_info, blocknr, check.owner_root, check.level);
if (IS_ERR(tmp)) {
@@ -2236,7 +2236,7 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root,
goto done;
}
- err = read_block_for_search(root, p, &b, level, slot, key);
+ err = read_block_for_search(root, p, &b, slot, key);
if (err == -EAGAIN && !p->nowait)
goto again;
if (err) {
@@ -2363,7 +2363,7 @@ int btrfs_search_old_slot(struct btrfs_root *root, const struct btrfs_key *key,
goto done;
}
- err = read_block_for_search(root, p, &b, level, slot, key);
+ err = read_block_for_search(root, p, &b, slot, key);
if (err == -EAGAIN && !p->nowait)
goto again;
if (err) {
@@ -4969,8 +4969,7 @@ int btrfs_next_old_leaf(struct btrfs_root *root, struct btrfs_path *path,
}
next = c;
- ret = read_block_for_search(root, path, &next, level,
- slot, &key);
+ ret = read_block_for_search(root, path, &next, slot, &key);
if (ret == -EAGAIN && !path->nowait)
goto again;
@@ -5013,8 +5012,7 @@ int btrfs_next_old_leaf(struct btrfs_root *root, struct btrfs_path *path,
if (!level)
break;
- ret = read_block_for_search(root, path, &next, level,
- 0, &key);
+ ret = read_block_for_search(root, path, &next, 0, &key);
if (ret == -EAGAIN && !path->nowait)
goto again;
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 2/4] btrfs: simplify arguments for btrfs_verify_level_key()
2024-10-16 14:20 [PATCH 0/4] btrfs: some cleanups around read_block_for_search() fdmanana
2024-10-16 14:20 ` [PATCH 1/4] btrfs: remove redundant level argument from read_block_for_search() fdmanana
@ 2024-10-16 14:20 ` fdmanana
2024-10-16 14:20 ` [PATCH 3/4] btrfs: remove redundant initialization from btrfs_readahead_tree_block() fdmanana
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: fdmanana @ 2024-10-16 14:20 UTC (permalink / raw)
To: linux-btrfs
From: Filipe Manana <fdmanana@suse.com>
The only caller of btrfs_verify_level_key() is read_block_for_search() and
it's passing 3 arguments to it that can be extracted from its on stack
variable of type struct btrfs_tree_parent_check.
So change btrfs_verify_level_key() to accept an argument of type
struct btrfs_tree_parent_check instead of level, first key and parent
transid arguments.
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
fs/btrfs/ctree.c | 3 +--
fs/btrfs/tree-checker.c | 16 ++++++++--------
fs/btrfs/tree-checker.h | 4 ++--
3 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 428c5650559a..f68a9b586079 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -1551,8 +1551,7 @@ read_block_for_search(struct btrfs_root *root, struct btrfs_path *p,
* being cached, read from scrub, or have multiple
* parents (shared tree blocks).
*/
- if (btrfs_verify_level_key(tmp,
- parent_level - 1, &check.first_key, gen)) {
+ if (btrfs_verify_level_key(tmp, &check)) {
ret = -EUCLEAN;
goto out;
}
diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c
index 7b50263723bc..148d8cefa40e 100644
--- a/fs/btrfs/tree-checker.c
+++ b/fs/btrfs/tree-checker.c
@@ -2183,8 +2183,8 @@ int btrfs_check_eb_owner(const struct extent_buffer *eb, u64 root_owner)
return 0;
}
-int btrfs_verify_level_key(struct extent_buffer *eb, int level,
- struct btrfs_key *first_key, u64 parent_transid)
+int btrfs_verify_level_key(struct extent_buffer *eb,
+ const struct btrfs_tree_parent_check *check)
{
struct btrfs_fs_info *fs_info = eb->fs_info;
int found_level;
@@ -2192,16 +2192,16 @@ int btrfs_verify_level_key(struct extent_buffer *eb, int level,
int ret;
found_level = btrfs_header_level(eb);
- if (found_level != level) {
+ if (found_level != check->level) {
WARN(IS_ENABLED(CONFIG_BTRFS_DEBUG),
KERN_ERR "BTRFS: tree level check failed\n");
btrfs_err(fs_info,
"tree level mismatch detected, bytenr=%llu level expected=%u has=%u",
- eb->start, level, found_level);
+ eb->start, check->level, found_level);
return -EIO;
}
- if (!first_key)
+ if (!check->has_first_key)
return 0;
/*
@@ -2226,15 +2226,15 @@ int btrfs_verify_level_key(struct extent_buffer *eb, int level,
btrfs_node_key_to_cpu(eb, &found_key, 0);
else
btrfs_item_key_to_cpu(eb, &found_key, 0);
- ret = btrfs_comp_cpu_keys(first_key, &found_key);
+ ret = btrfs_comp_cpu_keys(&check->first_key, &found_key);
if (ret) {
WARN(IS_ENABLED(CONFIG_BTRFS_DEBUG),
KERN_ERR "BTRFS: tree first key check failed\n");
btrfs_err(fs_info,
"tree first key mismatch detected, bytenr=%llu parent_transid=%llu key expected=(%llu,%u,%llu) has=(%llu,%u,%llu)",
- eb->start, parent_transid, first_key->objectid,
- first_key->type, first_key->offset,
+ eb->start, check->transid, check->first_key.objectid,
+ check->first_key.type, check->first_key.offset,
found_key.objectid, found_key.type,
found_key.offset);
}
diff --git a/fs/btrfs/tree-checker.h b/fs/btrfs/tree-checker.h
index 01669cfa6578..db67f96cbe4b 100644
--- a/fs/btrfs/tree-checker.h
+++ b/fs/btrfs/tree-checker.h
@@ -69,7 +69,7 @@ int btrfs_check_node(struct extent_buffer *node);
int btrfs_check_chunk_valid(struct extent_buffer *leaf,
struct btrfs_chunk *chunk, u64 logical);
int btrfs_check_eb_owner(const struct extent_buffer *eb, u64 root_owner);
-int btrfs_verify_level_key(struct extent_buffer *eb, int level,
- struct btrfs_key *first_key, u64 parent_transid);
+int btrfs_verify_level_key(struct extent_buffer *eb,
+ const struct btrfs_tree_parent_check *check);
#endif
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 3/4] btrfs: remove redundant initialization from btrfs_readahead_tree_block()
2024-10-16 14:20 [PATCH 0/4] btrfs: some cleanups around read_block_for_search() fdmanana
2024-10-16 14:20 ` [PATCH 1/4] btrfs: remove redundant level argument from read_block_for_search() fdmanana
2024-10-16 14:20 ` [PATCH 2/4] btrfs: simplify arguments for btrfs_verify_level_key() fdmanana
@ 2024-10-16 14:20 ` fdmanana
2024-10-16 15:49 ` David Sterba
2024-10-16 14:20 ` [PATCH 4/4] btrfs: remove local generation variable from read_block_for_search() fdmanana
2024-10-16 16:00 ` [PATCH 0/4] btrfs: some cleanups around read_block_for_search() David Sterba
4 siblings, 1 reply; 8+ messages in thread
From: fdmanana @ 2024-10-16 14:20 UTC (permalink / raw)
To: linux-btrfs
From: Filipe Manana <fdmanana@suse.com>
It's pointless to initialize the has_first_key field of the stack local
btrfs_tree_parent_check structure since it all fields not explicitly
initialized are zeroed out, plus it's a bit odd because the field is
of type bool and we are assigning 0 instead of false to it (however it's
not incorrect since 0 is converted to false). Just remove the explicit
initialization due to its redundancy.
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
fs/btrfs/extent_io.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 09c0d18a7b5a..0a0c84eb1c42 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -4285,7 +4285,6 @@ void btrfs_readahead_tree_block(struct btrfs_fs_info *fs_info,
u64 bytenr, u64 owner_root, u64 gen, int level)
{
struct btrfs_tree_parent_check check = {
- .has_first_key = 0,
.level = level,
.transid = gen
};
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 3/4] btrfs: remove redundant initialization from btrfs_readahead_tree_block()
2024-10-16 14:20 ` [PATCH 3/4] btrfs: remove redundant initialization from btrfs_readahead_tree_block() fdmanana
@ 2024-10-16 15:49 ` David Sterba
2024-10-16 16:41 ` Filipe Manana
0 siblings, 1 reply; 8+ messages in thread
From: David Sterba @ 2024-10-16 15:49 UTC (permalink / raw)
To: fdmanana; +Cc: linux-btrfs
On Wed, Oct 16, 2024 at 03:20:22PM +0100, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
>
> It's pointless to initialize the has_first_key field of the stack local
> btrfs_tree_parent_check structure since it all fields not explicitly
> initialized are zeroed out, plus it's a bit odd because the field is
> of type bool and we are assigning 0 instead of false to it (however it's
> not incorrect since 0 is converted to false). Just remove the explicit
> initialization due to its redundancy.
Makes sense, I've noticed there's one more to remove from
btrfs_qgroup_trace_subtree() you can squash it to this patch too.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3/4] btrfs: remove redundant initialization from btrfs_readahead_tree_block()
2024-10-16 15:49 ` David Sterba
@ 2024-10-16 16:41 ` Filipe Manana
0 siblings, 0 replies; 8+ messages in thread
From: Filipe Manana @ 2024-10-16 16:41 UTC (permalink / raw)
To: dsterba; +Cc: linux-btrfs
On Wed, Oct 16, 2024 at 4:49 PM David Sterba <dsterba@suse.cz> wrote:
>
> On Wed, Oct 16, 2024 at 03:20:22PM +0100, fdmanana@kernel.org wrote:
> > From: Filipe Manana <fdmanana@suse.com>
> >
> > It's pointless to initialize the has_first_key field of the stack local
> > btrfs_tree_parent_check structure since it all fields not explicitly
> > initialized are zeroed out, plus it's a bit odd because the field is
> > of type bool and we are assigning 0 instead of false to it (however it's
> > not incorrect since 0 is converted to false). Just remove the explicit
> > initialization due to its redundancy.
>
> Makes sense, I've noticed there's one more to remove from
> btrfs_qgroup_trace_subtree() you can squash it to this patch too.
Ah yes, done and added to for-next. Thanks.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 4/4] btrfs: remove local generation variable from read_block_for_search()
2024-10-16 14:20 [PATCH 0/4] btrfs: some cleanups around read_block_for_search() fdmanana
` (2 preceding siblings ...)
2024-10-16 14:20 ` [PATCH 3/4] btrfs: remove redundant initialization from btrfs_readahead_tree_block() fdmanana
@ 2024-10-16 14:20 ` fdmanana
2024-10-16 16:00 ` [PATCH 0/4] btrfs: some cleanups around read_block_for_search() David Sterba
4 siblings, 0 replies; 8+ messages in thread
From: fdmanana @ 2024-10-16 14:20 UTC (permalink / raw)
To: linux-btrfs
From: Filipe Manana <fdmanana@suse.com>
It's reduntant to have the 'gen' variable since we already have the same
value in the local btrfs_tree_parent_check structure. So remove it and
instead use the structure's field.
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
fs/btrfs/ctree.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index f68a9b586079..148648ea1c8b 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -1514,7 +1514,6 @@ read_block_for_search(struct btrfs_root *root, struct btrfs_path *p,
struct btrfs_fs_info *fs_info = root->fs_info;
struct btrfs_tree_parent_check check = { 0 };
u64 blocknr;
- u64 gen;
struct extent_buffer *tmp = NULL;
int ret = 0;
int parent_level;
@@ -1524,12 +1523,11 @@ read_block_for_search(struct btrfs_root *root, struct btrfs_path *p,
bool path_released = false;
blocknr = btrfs_node_blockptr(*eb_ret, slot);
- gen = btrfs_node_ptr_generation(*eb_ret, slot);
parent_level = btrfs_header_level(*eb_ret);
btrfs_node_key_to_cpu(*eb_ret, &check.first_key, slot);
check.has_first_key = true;
check.level = parent_level - 1;
- check.transid = gen;
+ check.transid = btrfs_node_ptr_generation(*eb_ret, slot);
check.owner_root = btrfs_root_id(root);
/*
@@ -1545,7 +1543,7 @@ read_block_for_search(struct btrfs_root *root, struct btrfs_path *p,
reada_for_search(fs_info, p, parent_level, slot, key->objectid);
/* first we do an atomic uptodate check */
- if (btrfs_buffer_uptodate(tmp, gen, 1) > 0) {
+ if (btrfs_buffer_uptodate(tmp, check.transid, 1) > 0) {
/*
* Do extra check for first_key, eb can be stale due to
* being cached, read from scrub, or have multiple
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 0/4] btrfs: some cleanups around read_block_for_search()
2024-10-16 14:20 [PATCH 0/4] btrfs: some cleanups around read_block_for_search() fdmanana
` (3 preceding siblings ...)
2024-10-16 14:20 ` [PATCH 4/4] btrfs: remove local generation variable from read_block_for_search() fdmanana
@ 2024-10-16 16:00 ` David Sterba
4 siblings, 0 replies; 8+ messages in thread
From: David Sterba @ 2024-10-16 16:00 UTC (permalink / raw)
To: fdmanana; +Cc: linux-btrfs
On Wed, Oct 16, 2024 at 03:20:19PM +0100, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
>
> A set of cleanups around read_block_for_search() and btrfs_verify_level_key(),
> mostly simplify arguments and remove redundant arguments and variables.
>
> Filipe Manana (4):
> btrfs: remove redundant level argument from read_block_for_search()
> btrfs: simplify arguments for btrfs_verify_level_key()
> btrfs: remove redundant initialization from btrfs_readahead_tree_block()
> btrfs: remove local generation variable from read_block_for_search()
Reviewed-by: David Sterba <dsterba@suse.com>
^ permalink raw reply [flat|nested] 8+ messages in thread