Commit 2f724563 authored by Kent Overstreet's avatar Kent Overstreet
Browse files

bcachefs: member helper cleanups



Some renaming for better consistency

bch2_member_exists	-> bch2_member_alive
bch2_dev_exists		-> bch2_member_exists
bch2_dev_exsits2	-> bch2_dev_exists
bch_dev_locked		-> bch2_dev_locked
bch_dev_bkey_exists	-> bch2_dev_bkey_exists

new helper - bch2_dev_safe

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent d155272b
Loading
Loading
Loading
Loading
+16 −16
Original line number Diff line number Diff line
@@ -576,10 +576,10 @@ int bch2_alloc_read(struct bch_fs *c)
			 * Not a fsck error because this is checked/repaired by
			 * bch2_check_alloc_key() which runs later:
			 */
			if (!bch2_dev_exists2(c, k.k->p.inode))
			if (!bch2_dev_exists(c, k.k->p.inode))
				continue;

			struct bch_dev *ca = bch_dev_bkey_exists(c, k.k->p.inode);
			struct bch_dev *ca = bch2_dev_bkey_exists(c, k.k->p.inode);

			for (u64 b = max_t(u64, ca->mi.first_bucket, start);
			     b < min_t(u64, ca->mi.nbuckets, end);
@@ -597,7 +597,7 @@ int bch2_alloc_read(struct bch_fs *c)
			if (!bch2_dev_bucket_exists(c, k.k->p))
				continue;

			struct bch_dev *ca = bch_dev_bkey_exists(c, k.k->p.inode);
			struct bch_dev *ca = bch2_dev_bkey_exists(c, k.k->p.inode);

			struct bch_alloc_v4 a;
			*bucket_gen(ca, k.k->p.offset) = bch2_alloc_to_v4(k, &a)->gen;
@@ -620,7 +620,7 @@ static int bch2_bucket_do_index(struct btree_trans *trans,
				bool set)
{
	struct bch_fs *c = trans->c;
	struct bch_dev *ca = bch_dev_bkey_exists(c, alloc_k.k->p.inode);
	struct bch_dev *ca = bch2_dev_bkey_exists(c, alloc_k.k->p.inode);
	struct btree_iter iter;
	struct bkey_s_c old;
	struct bkey_i *k;
@@ -733,7 +733,7 @@ int bch2_trigger_alloc(struct btree_trans *trans,
				       "alloc key for invalid device or bucket"))
		return -EIO;

	struct bch_dev *ca = bch_dev_bkey_exists(c, new.k->p.inode);
	struct bch_dev *ca = bch2_dev_bkey_exists(c, new.k->p.inode);

	struct bch_alloc_v4 old_a_convert;
	const struct bch_alloc_v4 *old_a = bch2_alloc_to_v4(old, &old_a_convert);
@@ -781,7 +781,7 @@ int bch2_trigger_alloc(struct btree_trans *trans,
		}

		new_a->fragmentation_lru = alloc_lru_idx_fragmentation(*new_a,
						bch_dev_bkey_exists(c, new.k->p.inode));
						bch2_dev_bkey_exists(c, new.k->p.inode));
		if (old_a->fragmentation_lru != new_a->fragmentation_lru) {
			ret = bch2_lru_change(trans,
					BCH_LRU_FRAGMENTATION_START,
@@ -955,8 +955,8 @@ static bool next_bucket(struct bch_fs *c, struct bpos *bucket)
	if (bch2_dev_bucket_exists(c, *bucket))
		return true;

	if (bch2_dev_exists2(c, bucket->inode)) {
		ca = bch_dev_bkey_exists(c, bucket->inode);
	if (bch2_dev_exists(c, bucket->inode)) {
		ca = bch2_dev_bkey_exists(c, bucket->inode);

		if (bucket->offset < ca->mi.first_bucket) {
			bucket->offset = ca->mi.first_bucket;
@@ -997,7 +997,7 @@ static struct bkey_s_c bch2_get_key_or_real_bucket_hole(struct btree_iter *iter,
		}

		if (!bch2_dev_bucket_exists(c, k.k->p)) {
			struct bch_dev *ca = bch_dev_bkey_exists(c, bucket.inode);
			struct bch_dev *ca = bch2_dev_bkey_exists(c, bucket.inode);

			bch2_key_resize(hole, ca->mi.nbuckets - bucket.offset);
		}
@@ -1030,7 +1030,7 @@ int bch2_check_alloc_key(struct btree_trans *trans,
			alloc_k.k->p.inode, alloc_k.k->p.offset))
		return bch2_btree_delete_at(trans, alloc_iter, 0);

	ca = bch_dev_bkey_exists(c, alloc_k.k->p.inode);
	ca = bch2_dev_bkey_exists(c, alloc_k.k->p.inode);
	if (!ca->mi.freespace_initialized)
		return 0;

@@ -1149,7 +1149,7 @@ int bch2_check_alloc_hole_freespace(struct btree_trans *trans,
	struct printbuf buf = PRINTBUF;
	int ret;

	ca = bch_dev_bkey_exists(c, start.inode);
	ca = bch2_dev_bkey_exists(c, start.inode);
	if (!ca->mi.freespace_initialized)
		return 0;

@@ -1339,7 +1339,7 @@ int bch2_check_bucket_gens_key(struct btree_trans *trans,
	bkey_reassemble(&g.k_i, k);

	/* if no bch_dev, skip out whether we repair or not */
	dev_exists = bch2_dev_exists2(c, k.k->p.inode);
	dev_exists = bch2_dev_exists(c, k.k->p.inode);
	if (!dev_exists) {
		if (fsck_err_on(!dev_exists, c,
				bucket_gens_to_invalid_dev,
@@ -1350,7 +1350,7 @@ int bch2_check_bucket_gens_key(struct btree_trans *trans,
		goto out;
	}

	ca = bch_dev_bkey_exists(c, k.k->p.inode);
	ca = bch2_dev_bkey_exists(c, k.k->p.inode);
	if (fsck_err_on(end <= ca->mi.first_bucket ||
			start >= ca->mi.nbuckets, c,
			bucket_gens_to_invalid_buckets,
@@ -1669,7 +1669,7 @@ static int bch2_discard_one_bucket(struct btree_trans *trans,
	bool discard_locked = false;
	int ret = 0;

	ca = bch_dev_bkey_exists(c, pos.inode);
	ca = bch2_dev_bkey_exists(c, pos.inode);

	if (!percpu_ref_tryget(&ca->io_ref)) {
		bch2_btree_iter_set_pos(need_discard_iter, POS(pos.inode + 1, 0));
@@ -1852,7 +1852,7 @@ static void bch2_do_discards_fast_work(struct work_struct *work)
			if (i->snapshot)
				continue;

			ca = bch_dev_bkey_exists(c, i->inode);
			ca = bch2_dev_bkey_exists(c, i->inode);

			if (!percpu_ref_tryget(&ca->io_ref)) {
				darray_remove_item(&c->discard_buckets_in_flight, i);
@@ -1893,7 +1893,7 @@ static void bch2_do_discards_fast_work(struct work_struct *work)

static void bch2_discard_one_bucket_fast(struct bch_fs *c, struct bpos bucket)
{
	struct bch_dev *ca = bch_dev_bkey_exists(c, bucket.inode);
	struct bch_dev *ca = bch2_dev_bkey_exists(c, bucket.inode);

	if (!percpu_ref_is_dying(&ca->io_ref) &&
	    !discard_in_flight_add(c, bucket) &&
+2 −2
Original line number Diff line number Diff line
@@ -17,10 +17,10 @@ static inline bool bch2_dev_bucket_exists(struct bch_fs *c, struct bpos pos)
{
	struct bch_dev *ca;

	if (!bch2_dev_exists2(c, pos.inode))
	if (!bch2_dev_exists(c, pos.inode))
		return false;

	ca = bch_dev_bkey_exists(c, pos.inode);
	ca = bch2_dev_bkey_exists(c, pos.inode);
	return bucket_valid(ca, pos.offset);
}

+7 −7
Original line number Diff line number Diff line
@@ -100,7 +100,7 @@ static void bch2_open_bucket_hash_remove(struct bch_fs *c, struct open_bucket *o

void __bch2_open_bucket_put(struct bch_fs *c, struct open_bucket *ob)
{
	struct bch_dev *ca = bch_dev_bkey_exists(c, ob->dev);
	struct bch_dev *ca = bch2_dev_bkey_exists(c, ob->dev);

	if (ob->ec) {
		ec_stripe_new_put(c, ob->ec, STRIPE_REF_io);
@@ -679,7 +679,7 @@ static int add_new_bucket(struct bch_fs *c,
			   struct open_bucket *ob)
{
	unsigned durability =
		bch_dev_bkey_exists(c, ob->dev)->mi.durability;
		bch2_dev_bkey_exists(c, ob->dev)->mi.durability;

	BUG_ON(*nr_effective >= nr_replicas);

@@ -836,7 +836,7 @@ static bool want_bucket(struct bch_fs *c,
			bool *have_cache, bool ec,
			struct open_bucket *ob)
{
	struct bch_dev *ca = bch_dev_bkey_exists(c, ob->dev);
	struct bch_dev *ca = bch2_dev_bkey_exists(c, ob->dev);

	if (!test_bit(ob->dev, devs_may_alloc->d))
		return false;
@@ -906,7 +906,7 @@ static int bucket_alloc_set_partial(struct bch_fs *c,
		struct open_bucket *ob = c->open_buckets + c->open_buckets_partial[i];

		if (want_bucket(c, wp, devs_may_alloc, have_cache, ec, ob)) {
			struct bch_dev *ca = bch_dev_bkey_exists(c, ob->dev);
			struct bch_dev *ca = bch2_dev_bkey_exists(c, ob->dev);
			struct bch_dev_usage usage;
			u64 avail;

@@ -1291,7 +1291,7 @@ deallocate_extra_replicas(struct bch_fs *c,
	unsigned i;

	open_bucket_for_each(c, ptrs, ob, i) {
		unsigned d = bch_dev_bkey_exists(c, ob->dev)->mi.durability;
		unsigned d = bch2_dev_bkey_exists(c, ob->dev)->mi.durability;

		if (d && d <= extra_replicas) {
			extra_replicas -= d;
@@ -1444,7 +1444,7 @@ int bch2_alloc_sectors_start_trans(struct btree_trans *trans,

struct bch_extent_ptr bch2_ob_ptr(struct bch_fs *c, struct open_bucket *ob)
{
	struct bch_dev *ca = bch_dev_bkey_exists(c, ob->dev);
	struct bch_dev *ca = bch2_dev_bkey_exists(c, ob->dev);

	return (struct bch_extent_ptr) {
		.type	= 1 << BCH_EXTENT_ENTRY_ptr,
@@ -1520,7 +1520,7 @@ void bch2_fs_allocator_foreground_init(struct bch_fs *c)

static void bch2_open_bucket_to_text(struct printbuf *out, struct bch_fs *c, struct open_bucket *ob)
{
	struct bch_dev *ca = bch_dev_bkey_exists(c, ob->dev);
	struct bch_dev *ca = bch2_dev_bkey_exists(c, ob->dev);
	unsigned data_type = ob->data_type;
	barrier(); /* READ_ONCE() doesn't work on bitfields */

+1 −1
Original line number Diff line number Diff line
@@ -184,7 +184,7 @@ bch2_alloc_sectors_append_ptrs_inlined(struct bch_fs *c, struct write_point *wp,
	wp->sectors_allocated	+= sectors;

	open_bucket_for_each(c, &wp->ptrs, ob, i) {
		struct bch_dev *ca = bch_dev_bkey_exists(c, ob->dev);
		struct bch_dev *ca = bch2_dev_bkey_exists(c, ob->dev);
		struct bch_extent_ptr ptr = bch2_ob_ptr(c, ob);

		ptr.cached = cached ||
+5 −5
Original line number Diff line number Diff line
@@ -46,10 +46,10 @@ int bch2_backpointer_invalid(struct bch_fs *c, struct bkey_s_c k,
	struct bkey_s_c_backpointer bp = bkey_s_c_to_backpointer(k);

	/* these will be caught by fsck */
	if (!bch2_dev_exists2(c, bp.k->p.inode))
	if (!bch2_dev_exists(c, bp.k->p.inode))
		return 0;

	struct bch_dev *ca = bch_dev_bkey_exists(c, bp.k->p.inode);
	struct bch_dev *ca = bch2_dev_bkey_exists(c, bp.k->p.inode);
	struct bpos bucket = bp_pos_to_bucket(c, bp.k->p);
	int ret = 0;

@@ -75,7 +75,7 @@ void bch2_backpointer_to_text(struct printbuf *out, const struct bch_backpointer

void bch2_backpointer_k_to_text(struct printbuf *out, struct bch_fs *c, struct bkey_s_c k)
{
	if (bch2_dev_exists2(c, k.k->p.inode)) {
	if (bch2_dev_exists(c, k.k->p.inode)) {
		prt_str(out, "bucket=");
		bch2_bpos_to_text(out, bp_pos_to_bucket(c, k.k->p));
		prt_str(out, " ");
@@ -366,7 +366,7 @@ static int bch2_check_btree_backpointer(struct btree_trans *trans, struct btree_
	struct printbuf buf = PRINTBUF;
	int ret = 0;

	if (fsck_err_on(!bch2_dev_exists2(c, k.k->p.inode), c,
	if (fsck_err_on(!bch2_dev_exists(c, k.k->p.inode), c,
			backpointer_to_missing_device,
			"backpointer for missing device:\n%s",
			(bch2_bkey_val_to_text(&buf, c, k), buf.buf))) {
@@ -459,7 +459,7 @@ static int check_extent_checksum(struct btree_trans *trans,

	bytes = p.crc.compressed_size << 9;

	struct bch_dev *ca = bch_dev_bkey_exists(c, dev);
	struct bch_dev *ca = bch2_dev_bkey_exists(c, dev);
	if (!bch2_dev_get_ioref(ca, READ))
		return false;

Loading