Skip to content

Commit

Permalink
btrfs: zoned: fix wrong use of bitops API in btrfs_ensure_empty_zones
Browse files Browse the repository at this point in the history
commit 631003e upstream.

find_next_bit and find_next_zero_bit take @SiZe as the second parameter and
@offset as the third parameter. They are specified opposite in
btrfs_ensure_empty_zones(). Thanks to the later loop, it never failed to
detect the empty zones. Fix them and (maybe) return the result a bit
faster.

Note: the naming is a bit confusing, size has two meanings here, bitmap
and our range size.

Fixes: 1cd6121 ("btrfs: zoned: implement zoned chunk allocator")
CC: stable@vger.kernel.org # 5.15+
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
naota authored and gregkh committed May 17, 2023
1 parent bcd7aa2 commit 8583cc1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions fs/btrfs/zoned.c
Original file line number Diff line number Diff line change
Expand Up @@ -1163,12 +1163,12 @@ int btrfs_ensure_empty_zones(struct btrfs_device *device, u64 start, u64 size)
return -ERANGE;

/* All the zones are conventional */
if (find_next_bit(zinfo->seq_zones, begin, end) == end)
if (find_next_bit(zinfo->seq_zones, end, begin) == end)
return 0;

/* All the zones are sequential and empty */
if (find_next_zero_bit(zinfo->seq_zones, begin, end) == end &&
find_next_zero_bit(zinfo->empty_zones, begin, end) == end)
if (find_next_zero_bit(zinfo->seq_zones, end, begin) == end &&
find_next_zero_bit(zinfo->empty_zones, end, begin) == end)
return 0;

for (pos = start; pos < start + size; pos += zinfo->zone_size) {
Expand Down

0 comments on commit 8583cc1

Please sign in to comment.