* [PATCH] btrfs: fix end of tree detection when searching for data extent ref
@ 2024-05-14 15:26 fdmanana
2024-05-14 16:22 ` David Sterba
2024-05-14 22:20 ` Qu Wenruo
0 siblings, 2 replies; 3+ messages in thread
From: fdmanana @ 2024-05-14 15:26 UTC (permalink / raw)
To: linux-btrfs
From: Filipe Manana <fdmanana@suse.com>
At lookup_extent_data_ref() we are incorrectly checking if we are at the
last slot of the last leaf in the extent tree. We are returning -ENOENT
if btrfs_next_leaf() returns a value greater than 1, but btrfs_next_leaf()
never returns anything greater than 1:
1) It returns < 0 on error;
2) 0 if there is a next leaf (or a new item was added to the end of the
current leaf after releasing the path);
3) 1 if there are no more leaves (and no new items were added to the last
leaf after releasing the path).
So fix this by checking if the return value is greater than zero instead
of being greater than one.
Fixes: 1618aa3c2e01 ("btrfs: simplify return variables in lookup_extent_data_ref()")
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
fs/btrfs/extent-tree.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 47d48233b592..3774c191e36d 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -477,7 +477,7 @@ static noinline int lookup_extent_data_ref(struct btrfs_trans_handle *trans,
if (path->slots[0] >= nritems) {
ret = btrfs_next_leaf(root, path);
if (ret) {
- if (ret > 1)
+ if (ret > 0)
return -ENOENT;
return ret;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] btrfs: fix end of tree detection when searching for data extent ref
2024-05-14 15:26 [PATCH] btrfs: fix end of tree detection when searching for data extent ref fdmanana
@ 2024-05-14 16:22 ` David Sterba
2024-05-14 22:20 ` Qu Wenruo
1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2024-05-14 16:22 UTC (permalink / raw)
To: fdmanana; +Cc: linux-btrfs
On Tue, May 14, 2024 at 04:26:52PM +0100, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
>
> At lookup_extent_data_ref() we are incorrectly checking if we are at the
> last slot of the last leaf in the extent tree. We are returning -ENOENT
> if btrfs_next_leaf() returns a value greater than 1, but btrfs_next_leaf()
> never returns anything greater than 1:
>
> 1) It returns < 0 on error;
>
> 2) 0 if there is a next leaf (or a new item was added to the end of the
> current leaf after releasing the path);
>
> 3) 1 if there are no more leaves (and no new items were added to the last
> leaf after releasing the path).
>
> So fix this by checking if the return value is greater than zero instead
> of being greater than one.
>
> Fixes: 1618aa3c2e01 ("btrfs: simplify return variables in lookup_extent_data_ref()")
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] btrfs: fix end of tree detection when searching for data extent ref
2024-05-14 15:26 [PATCH] btrfs: fix end of tree detection when searching for data extent ref fdmanana
2024-05-14 16:22 ` David Sterba
@ 2024-05-14 22:20 ` Qu Wenruo
1 sibling, 0 replies; 3+ messages in thread
From: Qu Wenruo @ 2024-05-14 22:20 UTC (permalink / raw)
To: fdmanana, linux-btrfs
在 2024/5/15 00:56, fdmanana@kernel.org 写道:
> From: Filipe Manana <fdmanana@suse.com>
>
> At lookup_extent_data_ref() we are incorrectly checking if we are at the
> last slot of the last leaf in the extent tree. We are returning -ENOENT
> if btrfs_next_leaf() returns a value greater than 1, but btrfs_next_leaf()
> never returns anything greater than 1:
>
> 1) It returns < 0 on error;
>
> 2) 0 if there is a next leaf (or a new item was added to the end of the
> current leaf after releasing the path);
>
> 3) 1 if there are no more leaves (and no new items were added to the last
> leaf after releasing the path).
>
> So fix this by checking if the return value is greater than zero instead
> of being greater than one.
>
> Fixes: 1618aa3c2e01 ("btrfs: simplify return variables in lookup_extent_data_ref()")
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Thanks,
Qu
> ---
> fs/btrfs/extent-tree.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> index 47d48233b592..3774c191e36d 100644
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -477,7 +477,7 @@ static noinline int lookup_extent_data_ref(struct btrfs_trans_handle *trans,
> if (path->slots[0] >= nritems) {
> ret = btrfs_next_leaf(root, path);
> if (ret) {
> - if (ret > 1)
> + if (ret > 0)
> return -ENOENT;
> return ret;
> }
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-05-14 22:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-14 15:26 [PATCH] btrfs: fix end of tree detection when searching for data extent ref fdmanana
2024-05-14 16:22 ` David Sterba
2024-05-14 22:20 ` Qu Wenruo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox