linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: Use next_leaf instead of next_item when slots > nritems
@ 2021-07-13 13:58 Marcos Paulo de Souza
  2021-07-22 19:53 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: Marcos Paulo de Souza @ 2021-07-13 13:58 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba, Marcos Paulo de Souza

After calling btrfs_search_slot is a common pratice to check if the
slot found isn't bigger than number of slots in the current leaf, and if
so, search for the same key in the next leaf by calling btrfs_next_leaf,
which calls btrfs_next_old_leaf to do the job.

Calling btrfs_next_item in the same situation would end up in the same
code flow, since

* btrfs_next_item
  * btrfs_next_old_item
    * if slot >= nritems(curr_leaf)
      btrfs_next_old_leaf

Change btrfs_verify_dev_extents and calculate_emulated_zone_size
functions to use btrfs_next_leaf in the same situation.

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
 Please let me know if I'm missing something obvious here, but all other places
 who check for slot >= nritems are calling next_leaf...

 I found this code while checking all btrfs_search_slot users.

 fs/btrfs/volumes.c | 2 +-
 fs/btrfs/zoned.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index c6c14315b1c9..d57ad0c9bb99 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -8143,7 +8143,7 @@ int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info)
 		goto out;
 
 	if (path->slots[0] >= btrfs_header_nritems(path->nodes[0])) {
-		ret = btrfs_next_item(root, path);
+		ret = btrfs_next_leaf(root, path);
 		if (ret < 0)
 			goto out;
 		/* No dev extents at all? Not good */
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index 6cefdaf89461..882f5946e262 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -245,7 +245,7 @@ static int calculate_emulated_zone_size(struct btrfs_fs_info *fs_info)
 		goto out;
 
 	if (path->slots[0] >= btrfs_header_nritems(path->nodes[0])) {
-		ret = btrfs_next_item(root, path);
+		ret = btrfs_next_leaf(root, path);
 		if (ret < 0)
 			goto out;
 		/* No dev extents at all? Not good */
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] btrfs: Use next_leaf instead of next_item when slots > nritems
  2021-07-13 13:58 [PATCH] btrfs: Use next_leaf instead of next_item when slots > nritems Marcos Paulo de Souza
@ 2021-07-22 19:53 ` David Sterba
  0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2021-07-22 19:53 UTC (permalink / raw)
  To: Marcos Paulo de Souza; +Cc: linux-btrfs, dsterba

On Tue, Jul 13, 2021 at 10:58:03AM -0300, Marcos Paulo de Souza wrote:
> After calling btrfs_search_slot is a common pratice to check if the
> slot found isn't bigger than number of slots in the current leaf, and if
> so, search for the same key in the next leaf by calling btrfs_next_leaf,
> which calls btrfs_next_old_leaf to do the job.
> 
> Calling btrfs_next_item in the same situation would end up in the same
> code flow, since
> 
> * btrfs_next_item
>   * btrfs_next_old_item
>     * if slot >= nritems(curr_leaf)
>       btrfs_next_old_leaf
> 
> Change btrfs_verify_dev_extents and calculate_emulated_zone_size
> functions to use btrfs_next_leaf in the same situation.
> 
> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
> ---
>  Please let me know if I'm missing something obvious here, but all other places
>  who check for slot >= nritems are calling next_leaf...

Yeah it should be next_leaf, the next_item increments the slot but at
that time it is already above nritems and it gets reset to 0 once the
pointer is moved to the next leaf.

Added to misc-next, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-07-22 19:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-13 13:58 [PATCH] btrfs: Use next_leaf instead of next_item when slots > nritems Marcos Paulo de Souza
2021-07-22 19:53 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).