Commit d155272b authored by Kent Overstreet's avatar Kent Overstreet
Browse files

bcachefs: bucket_valid()



cut out a branch from doing it the obvious way

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 923ed0ae
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -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)
+1 −0
Original line number Diff line number Diff line
@@ -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"
+9 −5
Original line number Diff line number Diff line
@@ -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);
}
@@ -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++)
@@ -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;
}

@@ -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;
}

+1 −3
Original line number Diff line number Diff line
@@ -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");
	}
}
+2 −0
Original line number Diff line number Diff line
@@ -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