OSDN Git Service

btrfs: introduce btrfs_for_each_slot iterator macro
authorGabriel Niebler <gniebler@suse.com>
Wed, 9 Mar 2022 13:50:38 +0000 (14:50 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 16 May 2022 15:03:07 +0000 (17:03 +0200)
commit62142be363ae902c948729eeb35851ddf34b317d
tree4eb2dc666a801f98b6a015e7b1b0b37bd14f9e5e
parente360d2f5810434d44ee61b47437ecd5e66528a5a
btrfs: introduce btrfs_for_each_slot iterator macro

There is a common pattern when searching for a key in btrfs:

* Call btrfs_search_slot to find the slot for the key
* Enter an endless loop:
  * If the found slot is larger than the no. of items in the current
    leaf, check the next leaf
  * If it's still not found in the next leaf, terminate the loop
  * Otherwise do something with the found key
  * Increment the current slot and continue

To reduce code duplication, we can replace this code pattern with an
iterator macro, similar to the existing for_each_X macros found
elsewhere in the kernel.  This also makes the code easier to understand
for newcomers by putting a name to the encapsulated functionality.

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Signed-off-by: Gabriel Niebler <gniebler@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ctree.c
fs/btrfs/ctree.h