Commit 805ddc20 authored by Kent Overstreet's avatar Kent Overstreet
Browse files

bcachefs: bch2_dev_rcu_noerror()



bch2_dev_rcu() now properly errors if the device is invalid

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent b99a94fd
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ enum bch_validate_flags;
static inline bool bch2_dev_bucket_exists(struct bch_fs *c, struct bpos pos)
{
	rcu_read_lock();
	struct bch_dev *ca = bch2_dev_rcu(c, pos.inode);
	struct bch_dev *ca = bch2_dev_rcu_noerror(c, pos.inode);
	bool ret = ca && bucket_valid(ca, pos.offset);
	rcu_read_unlock();
	return ret;
+3 −3
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ int bch2_backpointer_validate(struct bch_fs *c, struct bkey_s_c k,
	struct bkey_s_c_backpointer bp = bkey_s_c_to_backpointer(k);

	rcu_read_lock();
	struct bch_dev *ca = bch2_dev_rcu(c, bp.k->p.inode);
	struct bch_dev *ca = bch2_dev_rcu_noerror(c, bp.k->p.inode);
	if (!ca) {
		/* these will be caught by fsck */
		rcu_read_unlock();
@@ -89,7 +89,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)
{
	rcu_read_lock();
	struct bch_dev *ca = bch2_dev_rcu(c, k.k->p.inode);
	struct bch_dev *ca = bch2_dev_rcu_noerror(c, k.k->p.inode);
	if (ca) {
		struct bpos bucket = bp_pos_to_bucket(ca, k.k->p);
		rcu_read_unlock();
@@ -673,7 +673,7 @@ static int check_extent_to_backpointers(struct btree_trans *trans,
			continue;

		rcu_read_lock();
		struct bch_dev *ca = bch2_dev_rcu(c, p.ptr.dev);
		struct bch_dev *ca = bch2_dev_rcu_noerror(c, p.ptr.dev);
		if (ca)
			bch2_extent_ptr_to_bp(c, ca, btree, level, k, p, entry, &bucket_pos, &bp);
		rcu_read_unlock();
+1 −1
Original line number Diff line number Diff line
@@ -281,7 +281,7 @@ int bch2_check_fix_ptrs(struct btree_trans *trans,
			goto err;

		rcu_read_lock();
		bch2_bkey_drop_ptrs(bkey_i_to_s(new), ptr, !bch2_dev_rcu(c, ptr->dev));
		bch2_bkey_drop_ptrs(bkey_i_to_s(new), ptr, !bch2_dev_exists(c, ptr->dev));
		rcu_read_unlock();

		if (level) {
+3 −2
Original line number Diff line number Diff line
@@ -1021,7 +1021,7 @@ void bch2_extent_ptr_to_text(struct printbuf *out, struct bch_fs *c, const struc
{
	out->atomic++;
	rcu_read_lock();
	struct bch_dev *ca = bch2_dev_rcu(c, ptr->dev);
	struct bch_dev *ca = bch2_dev_rcu_noerror(c, ptr->dev);
	if (!ca) {
		prt_printf(out, "ptr: %u:%llu gen %u%s", ptr->dev,
			   (u64) ptr->offset, ptr->gen,
@@ -1125,8 +1125,9 @@ static int extent_ptr_validate(struct bch_fs *c,
{
	int ret = 0;

	/* bad pointers are repaired by check_fix_ptrs(): */
	rcu_read_lock();
	struct bch_dev *ca = bch2_dev_rcu(c, ptr->dev);
	struct bch_dev *ca = bch2_dev_rcu_noerror(c, ptr->dev);
	if (!ca) {
		rcu_read_unlock();
		return 0;
+1 −1
Original line number Diff line number Diff line
@@ -795,7 +795,7 @@ bool bch2_have_enough_devs(struct bch_fs *c, struct bch_devs_mask devs,
		for (unsigned i = 0; i < e->nr_devs; i++) {
			nr_online += test_bit(e->devs[i], devs.d);

			struct bch_dev *ca = bch2_dev_rcu(c, e->devs[i]);
			struct bch_dev *ca = bch2_dev_rcu_noerror(c, e->devs[i]);
			nr_failed += !ca || ca->mi.state == BCH_MEMBER_STATE_failed;
		}
		rcu_read_unlock();
Loading