Loading fs/bcachefs/alloc_background.h +1 −2 Original line number Diff line number Diff line Loading @@ -21,8 +21,7 @@ static inline bool bch2_dev_bucket_exists(struct bch_fs *c, struct bpos pos) return false; ca = bch_dev_bkey_exists(c, pos.inode); return pos.offset >= ca->mi.first_bucket && pos.offset < ca->mi.nbuckets; return bucket_valid(ca, pos.offset); } static inline u64 bucket_to_u64(struct bpos bucket) Loading fs/bcachefs/bcachefs.h +1 −0 Original line number Diff line number Diff line Loading @@ -470,6 +470,7 @@ enum bch_time_stats { #include "quota_types.h" #include "rebalance_types.h" #include "replicas_types.h" #include "sb-members_types.h" #include "subvolume_types.h" #include "super_types.h" #include "thread_with_file_types.h" Loading fs/bcachefs/buckets.h +9 −5 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ #include "extents.h" #include "sb-members.h" static inline size_t sector_to_bucket(const struct bch_dev *ca, sector_t s) static inline u64 sector_to_bucket(const struct bch_dev *ca, sector_t s) { return div_u64(s, ca->mi.bucket_size); } Loading @@ -30,12 +30,16 @@ static inline sector_t bucket_remainder(const struct bch_dev *ca, sector_t s) return remainder; } static inline size_t sector_to_bucket_and_offset(const struct bch_dev *ca, sector_t s, u32 *offset) static inline u64 sector_to_bucket_and_offset(const struct bch_dev *ca, sector_t s, u32 *offset) { return div_u64_rem(s, ca->mi.bucket_size, offset); } static inline bool bucket_valid(const struct bch_dev *ca, u64 b) { return b - ca->mi.first_bucket < ca->mi.nbuckets_minus_first; } #define for_each_bucket(_b, _buckets) \ for (_b = (_buckets)->b + (_buckets)->first_bucket; \ _b < (_buckets)->b + (_buckets)->nbuckets; _b++) Loading Loading @@ -94,7 +98,7 @@ static inline struct bucket *gc_bucket(struct bch_dev *ca, size_t b) { struct bucket_array *buckets = gc_bucket_array(ca); BUG_ON(b < buckets->first_bucket || b >= buckets->nbuckets); BUG_ON(!bucket_valid(ca, b)); return buckets->b + b; } Loading @@ -111,7 +115,7 @@ static inline u8 *bucket_gen(struct bch_dev *ca, size_t b) { struct bucket_gens *gens = bucket_gens(ca); BUG_ON(b < gens->first_bucket || b >= gens->nbuckets); BUG_ON(!bucket_valid(ca, b)); return gens->b + b; } Loading fs/bcachefs/extents.c +1 −3 Original line number Diff line number Diff line Loading @@ -998,9 +998,7 @@ void bch2_extent_ptr_to_text(struct printbuf *out, struct bch_fs *c, const struc prt_str(out, " cached"); if (ptr->unwritten) prt_str(out, " unwritten"); if (b >= ca->mi.first_bucket && b < ca->mi.nbuckets && ptr_stale(ca, ptr)) if (bucket_valid(ca, b) && ptr_stale(ca, ptr)) prt_printf(out, " stale"); } } Loading fs/bcachefs/sb-members.h +2 −0 Original line number Diff line number Diff line Loading @@ -210,6 +210,8 @@ static inline struct bch_member_cpu bch2_mi_to_cpu(struct bch_member *mi) { return (struct bch_member_cpu) { .nbuckets = le64_to_cpu(mi->nbuckets), .nbuckets_minus_first = le64_to_cpu(mi->nbuckets) - le16_to_cpu(mi->first_bucket), .first_bucket = le16_to_cpu(mi->first_bucket), .bucket_size = le16_to_cpu(mi->bucket_size), .group = BCH_MEMBER_GROUP(mi), Loading Loading
fs/bcachefs/alloc_background.h +1 −2 Original line number Diff line number Diff line Loading @@ -21,8 +21,7 @@ static inline bool bch2_dev_bucket_exists(struct bch_fs *c, struct bpos pos) return false; ca = bch_dev_bkey_exists(c, pos.inode); return pos.offset >= ca->mi.first_bucket && pos.offset < ca->mi.nbuckets; return bucket_valid(ca, pos.offset); } static inline u64 bucket_to_u64(struct bpos bucket) Loading
fs/bcachefs/bcachefs.h +1 −0 Original line number Diff line number Diff line Loading @@ -470,6 +470,7 @@ enum bch_time_stats { #include "quota_types.h" #include "rebalance_types.h" #include "replicas_types.h" #include "sb-members_types.h" #include "subvolume_types.h" #include "super_types.h" #include "thread_with_file_types.h" Loading
fs/bcachefs/buckets.h +9 −5 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ #include "extents.h" #include "sb-members.h" static inline size_t sector_to_bucket(const struct bch_dev *ca, sector_t s) static inline u64 sector_to_bucket(const struct bch_dev *ca, sector_t s) { return div_u64(s, ca->mi.bucket_size); } Loading @@ -30,12 +30,16 @@ static inline sector_t bucket_remainder(const struct bch_dev *ca, sector_t s) return remainder; } static inline size_t sector_to_bucket_and_offset(const struct bch_dev *ca, sector_t s, u32 *offset) static inline u64 sector_to_bucket_and_offset(const struct bch_dev *ca, sector_t s, u32 *offset) { return div_u64_rem(s, ca->mi.bucket_size, offset); } static inline bool bucket_valid(const struct bch_dev *ca, u64 b) { return b - ca->mi.first_bucket < ca->mi.nbuckets_minus_first; } #define for_each_bucket(_b, _buckets) \ for (_b = (_buckets)->b + (_buckets)->first_bucket; \ _b < (_buckets)->b + (_buckets)->nbuckets; _b++) Loading Loading @@ -94,7 +98,7 @@ static inline struct bucket *gc_bucket(struct bch_dev *ca, size_t b) { struct bucket_array *buckets = gc_bucket_array(ca); BUG_ON(b < buckets->first_bucket || b >= buckets->nbuckets); BUG_ON(!bucket_valid(ca, b)); return buckets->b + b; } Loading @@ -111,7 +115,7 @@ static inline u8 *bucket_gen(struct bch_dev *ca, size_t b) { struct bucket_gens *gens = bucket_gens(ca); BUG_ON(b < gens->first_bucket || b >= gens->nbuckets); BUG_ON(!bucket_valid(ca, b)); return gens->b + b; } Loading
fs/bcachefs/extents.c +1 −3 Original line number Diff line number Diff line Loading @@ -998,9 +998,7 @@ void bch2_extent_ptr_to_text(struct printbuf *out, struct bch_fs *c, const struc prt_str(out, " cached"); if (ptr->unwritten) prt_str(out, " unwritten"); if (b >= ca->mi.first_bucket && b < ca->mi.nbuckets && ptr_stale(ca, ptr)) if (bucket_valid(ca, b) && ptr_stale(ca, ptr)) prt_printf(out, " stale"); } } Loading
fs/bcachefs/sb-members.h +2 −0 Original line number Diff line number Diff line Loading @@ -210,6 +210,8 @@ static inline struct bch_member_cpu bch2_mi_to_cpu(struct bch_member *mi) { return (struct bch_member_cpu) { .nbuckets = le64_to_cpu(mi->nbuckets), .nbuckets_minus_first = le64_to_cpu(mi->nbuckets) - le16_to_cpu(mi->first_bucket), .first_bucket = le16_to_cpu(mi->first_bucket), .bucket_size = le16_to_cpu(mi->bucket_size), .group = BCH_MEMBER_GROUP(mi), Loading