diff options
author | David Sterba <dsterba@suse.com> | 2023-09-12 01:09:23 +0200 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2023-10-12 16:44:14 +0200 |
commit | 99be1a66e1fe6c62fbd7c1b0c50ea38c33ffdd5a (patch) | |
tree | 4d83e0ee8336713d3455a43aac36159cb2d5e74b /fs/btrfs/extent-io-tree.c | |
parent | 6422b4cd959d4b796146c4b7746c26eb17783579 (diff) | |
download | linux-99be1a66e1fe6c62fbd7c1b0c50ea38c33ffdd5a.tar.gz linux-99be1a66e1fe6c62fbd7c1b0c50ea38c33ffdd5a.tar.bz2 linux-99be1a66e1fe6c62fbd7c1b0c50ea38c33ffdd5a.zip |
btrfs: add specific helper for range bit test exists
The existing helper test_range_bit works in two ways, checks if the whole
range contains all the bits, or stop on the first occurrence. By adding
a specific helper for the latter case, the inner loop can be simplified
and contains fewer conditionals, making it a bit faster.
There's no caller that uses the cached state pointer so this reduces the
argument count further.
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/extent-io-tree.c')
-rw-r--r-- | fs/btrfs/extent-io-tree.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/fs/btrfs/extent-io-tree.c b/fs/btrfs/extent-io-tree.c index ff8e117a1ace..02414cc86def 100644 --- a/fs/btrfs/extent-io-tree.c +++ b/fs/btrfs/extent-io-tree.c @@ -1640,6 +1640,37 @@ search: } /* + * Check if the single @bit exists in the given range. + */ +bool test_range_bit_exists(struct extent_io_tree *tree, u64 start, u64 end, u32 bit) +{ + struct extent_state *state = NULL; + bool bitset = false; + + ASSERT(is_power_of_2(bit)); + + spin_lock(&tree->lock); + state = tree_search(tree, start); + while (state && start <= end) { + if (state->start > end) + break; + + if (state->state & bit) { + bitset = true; + break; + } + + /* If state->end is (u64)-1, start will overflow to 0 */ + start = state->end + 1; + if (start > end || start == 0) + break; + state = next_state(state); + } + spin_unlock(&tree->lock); + return bitset; +} + +/* * Search a range in the state tree for a given mask. If 'filled' == 1, this * returns 1 only if every extent in the tree has the bits set. Otherwise, 1 * is returned if any bit in the range is found set. |