Skip to content

Commit

Permalink
btrfs: export bitmap_test_range_all_{set,zero}
Browse files Browse the repository at this point in the history
bitmap_test_range_all_{set,zero} defined in subpage.c are useful for other
components. Move them to misc.h and use them in zoned.c. Also, as
find_next{,_zero}_bit take/return "unsigned long" instead of "unsigned
int", convert the type to "unsigned long".

While at it, also rewrite the "if (...) return true; else return false;"
pattern and add const to the input bitmap.

Signed-off-by: Naohiro Aota <[email protected]>
Reviewed-by: David Sterba <[email protected]>
Signed-off-by: David Sterba <[email protected]>
  • Loading branch information
naota authored and kdave committed Jun 19, 2023
1 parent 88ad95b commit b5345d6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
20 changes: 20 additions & 0 deletions fs/btrfs/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,24 @@ static inline struct rb_node *rb_simple_insert(struct rb_root *root, u64 bytenr,
return NULL;
}

static inline bool bitmap_test_range_all_set(const unsigned long *addr,
unsigned long start,
unsigned long nbits)
{
unsigned long found_zero;

found_zero = find_next_zero_bit(addr, start + nbits, start);
return (found_zero == start + nbits);
}

static inline bool bitmap_test_range_all_zero(const unsigned long *addr,
unsigned long start,
unsigned long nbits)
{
unsigned long found_set;

found_set = find_next_bit(addr, start + nbits, start);
return (found_set == start + nbits);
}

#endif
22 changes: 0 additions & 22 deletions fs/btrfs/subpage.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,28 +367,6 @@ void btrfs_page_end_writer_lock(const struct btrfs_fs_info *fs_info,
unlock_page(page);
}

static bool bitmap_test_range_all_set(unsigned long *addr, unsigned int start,
unsigned int nbits)
{
unsigned int found_zero;

found_zero = find_next_zero_bit(addr, start + nbits, start);
if (found_zero == start + nbits)
return true;
return false;
}

static bool bitmap_test_range_all_zero(unsigned long *addr, unsigned int start,
unsigned int nbits)
{
unsigned int found_set;

found_set = find_next_bit(addr, start + nbits, start);
if (found_set == start + nbits)
return true;
return false;
}

#define subpage_calc_start_bit(fs_info, page, name, start, len) \
({ \
unsigned int start_bit; \
Expand Down
12 changes: 6 additions & 6 deletions fs/btrfs/zoned.c
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ u64 btrfs_find_allocatable_zones(struct btrfs_device *device, u64 hole_start,

/* Check if zones in the region are all empty */
if (btrfs_dev_is_sequential(device, pos) &&
find_next_zero_bit(zinfo->empty_zones, end, begin) != end) {
!bitmap_test_range_all_set(zinfo->empty_zones, begin, nzones)) {
pos += zinfo->zone_size;
continue;
}
Expand Down Expand Up @@ -1156,23 +1156,23 @@ int btrfs_ensure_empty_zones(struct btrfs_device *device, u64 start, u64 size)
struct btrfs_zoned_device_info *zinfo = device->zone_info;
const u8 shift = zinfo->zone_size_shift;
unsigned long begin = start >> shift;
unsigned long end = (start + size) >> shift;
unsigned long nbits = size >> shift;
u64 pos;
int ret;

ASSERT(IS_ALIGNED(start, zinfo->zone_size));
ASSERT(IS_ALIGNED(size, zinfo->zone_size));

if (end > zinfo->nr_zones)
if (begin + nbits > zinfo->nr_zones)
return -ERANGE;

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

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

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

0 comments on commit b5345d6

Please sign in to comment.