Message ID | bab3ffe3255379a63b07c4c11ea1a52e1a904f68.1682062222.git.naohiro.aota@wdc.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | btrfs: export bitmap_test_range_all_{set,zero} | expand |
On 4/21/23 16:31, Naohiro Aota wrote: > From: Naohiro Aota <naohiro.aota@wdc.com> > > 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". > > Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> > --- > fs/btrfs/misc.h | 22 ++++++++++++++++++++++ > fs/btrfs/subpage.c | 22 ---------------------- > fs/btrfs/zoned.c | 12 ++++++------ > 3 files changed, 28 insertions(+), 28 deletions(-) > > diff --git a/fs/btrfs/misc.h b/fs/btrfs/misc.h > index 768583a440e1..6f574c291342 100644 > --- a/fs/btrfs/misc.h > +++ b/fs/btrfs/misc.h > @@ -143,4 +143,26 @@ static inline struct rb_node *rb_simple_insert(struct rb_root *root, u64 bytenr, > return NULL; > } > > +static inline bool bitmap_test_range_all_set(unsigned long *addr, unsigned long start, Long line. > + unsigned long nbits) > +{ > + unsigned long found_zero; > + > + found_zero = find_next_zero_bit(addr, start + nbits, start); > + if (found_zero == start + nbits) > + return true; > + return false; Why not: return find_next_zero_bit(addr, start + nbits, start) == start + nbits; Simpler... > +} > + > +static inline bool bitmap_test_range_all_zero(unsigned long *addr, unsigned long start, Long line. > + unsigned long nbits) > +{ > + unsigned long found_set; > + > + found_set = find_next_bit(addr, start + nbits, start); > + if (found_set == start + nbits) > + return true; > + return false; return find_next_bit(addr, start + nbits, start) == start + nbits; > +} > + > #endif > diff --git a/fs/btrfs/subpage.c b/fs/btrfs/subpage.c > index dd46b978ac2c..045117ca0ddc 100644 > --- a/fs/btrfs/subpage.c > +++ b/fs/btrfs/subpage.c > @@ -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; \ > diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c > index d51057608fc3..858a59d39b38 100644 > --- a/fs/btrfs/zoned.c > +++ b/fs/btrfs/zoned.c > @@ -1058,7 +1058,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; > } > @@ -1157,23 +1157,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->seq_zones, begin, nbits)) > return 0; > > for (pos = start; pos < start + size; pos += zinfo->zone_size) {
On Fri, Apr 21, 2023 at 04:31:34PM +0900, Naohiro Aota wrote: > From: Naohiro Aota <naohiro.aota@wdc.com> > > 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". > > Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> I thought this patch didn't change the behavior. But, actually, with this patch, IOs on zoned mode soon fail. I'll debug and post v2, with Damien's comments addressed.
On Fri, Apr 21, 2023 at 04:49:06PM +0900, Damien Le Moal wrote: > On 4/21/23 16:31, Naohiro Aota wrote: > > From: Naohiro Aota <naohiro.aota@wdc.com> > > + found_zero = find_next_zero_bit(addr, start + nbits, start); > > + if (found_zero == start + nbits) > > + return true; > > + return false; > > Why not: > > return find_next_zero_bit(addr, start + nbits, start) == start + nbits; > > Simpler... Depends on local coding style habits, I find overloading line like that less readable so I'll undo that change in the applied patche.
diff --git a/fs/btrfs/misc.h b/fs/btrfs/misc.h index 768583a440e1..6f574c291342 100644 --- a/fs/btrfs/misc.h +++ b/fs/btrfs/misc.h @@ -143,4 +143,26 @@ static inline struct rb_node *rb_simple_insert(struct rb_root *root, u64 bytenr, return NULL; } +static inline bool bitmap_test_range_all_set(unsigned long *addr, unsigned long start, + unsigned long nbits) +{ + unsigned long found_zero; + + found_zero = find_next_zero_bit(addr, start + nbits, start); + if (found_zero == start + nbits) + return true; + return false; +} + +static inline bool bitmap_test_range_all_zero(unsigned long *addr, unsigned long start, + unsigned long nbits) +{ + unsigned long found_set; + + found_set = find_next_bit(addr, start + nbits, start); + if (found_set == start + nbits) + return true; + return false; +} + #endif diff --git a/fs/btrfs/subpage.c b/fs/btrfs/subpage.c index dd46b978ac2c..045117ca0ddc 100644 --- a/fs/btrfs/subpage.c +++ b/fs/btrfs/subpage.c @@ -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; \ diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index d51057608fc3..858a59d39b38 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1058,7 +1058,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; } @@ -1157,23 +1157,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->seq_zones, begin, nbits)) return 0; for (pos = start; pos < start + size; pos += zinfo->zone_size) {