bcachefs: extent_ptr_durability() -> bch2_dev_rcu()

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2024-04-30 20:54:20 -04:00
parent 3793b3f91f
commit 302c980a81
4 changed files with 21 additions and 5 deletions

View File

@ -203,6 +203,8 @@ restart_drop_conflicting_replicas:
/* Now, drop excess replicas: */
restart_drop_extra_replicas:
rcu_read_lock();
bkey_for_each_ptr_decode(old.k, bch2_bkey_ptrs(bkey_i_to_s(insert)), p, entry) {
unsigned ptr_durability = bch2_extent_ptr_durability(c, &p);
@ -214,6 +216,7 @@ restart_drop_extra_replicas:
goto restart_drop_extra_replicas;
}
}
rcu_read_unlock();
/* Finally, add the pointers we just wrote: */
extent_for_each_ptr_decode(extent_i_to_s(new), p, entry)
@ -552,6 +555,7 @@ int bch2_data_update_init(struct btree_trans *trans,
struct bpos bucket = PTR_BUCKET_POS(ca, &p.ptr);
bool locked;
rcu_read_lock();
if (((1U << i) & m->data_opts.rewrite_ptrs)) {
BUG_ON(p.ptr.cached);
@ -565,6 +569,7 @@ int bch2_data_update_init(struct btree_trans *trans,
bch2_dev_list_add_dev(&m->op.devs_have, p.ptr.dev);
durability_have += bch2_extent_ptr_durability(c, &p);
}
rcu_read_unlock();
/*
* op->csum_type is normally initialized from the fs/file's

View File

@ -675,16 +675,16 @@ static inline unsigned __extent_ptr_durability(struct bch_dev *ca, struct extent
unsigned bch2_extent_ptr_desired_durability(struct bch_fs *c, struct extent_ptr_decoded *p)
{
struct bch_dev *ca = bch2_dev_bkey_exists(c, p->ptr.dev);
struct bch_dev *ca = bch2_dev_rcu(c, p->ptr.dev);
return __extent_ptr_durability(ca, p);
return ca ? __extent_ptr_durability(ca, p) : 0;
}
unsigned bch2_extent_ptr_durability(struct bch_fs *c, struct extent_ptr_decoded *p)
{
struct bch_dev *ca = bch2_dev_bkey_exists(c, p->ptr.dev);
struct bch_dev *ca = bch2_dev_rcu(c, p->ptr.dev);
if (ca->mi.state == BCH_MEMBER_STATE_failed)
if (!ca || ca->mi.state == BCH_MEMBER_STATE_failed)
return 0;
return __extent_ptr_durability(ca, p);
@ -697,8 +697,10 @@ unsigned bch2_bkey_durability(struct bch_fs *c, struct bkey_s_c k)
struct extent_ptr_decoded p;
unsigned durability = 0;
rcu_read_lock();
bkey_for_each_ptr_decode(k.k, ptrs, p, entry)
durability += bch2_extent_ptr_durability(c, &p);
rcu_read_unlock();
return durability;
}
@ -710,9 +712,11 @@ static unsigned bch2_bkey_durability_safe(struct bch_fs *c, struct bkey_s_c k)
struct extent_ptr_decoded p;
unsigned durability = 0;
rcu_read_lock();
bkey_for_each_ptr_decode(k.k, ptrs, p, entry)
if (p.ptr.dev < c->sb.nr_devices && c->devs[p.ptr.dev])
durability += bch2_extent_ptr_durability(c, &p);
rcu_read_unlock();
return durability;
}

View File

@ -1099,12 +1099,17 @@ static bool bch2_extent_is_writeable(struct bch_write_op *op,
return false;
e = bkey_s_c_to_extent(k);
rcu_read_lock();
extent_for_each_ptr_decode(e, p, entry) {
if (crc_is_encoded(p.crc) || p.has_ec)
if (crc_is_encoded(p.crc) || p.has_ec) {
rcu_read_unlock();
return false;
}
replicas += bch2_extent_ptr_durability(c, &p);
}
rcu_read_unlock();
return replicas >= op->opts.data_replicas;
}

View File

@ -1033,6 +1033,7 @@ static bool drop_extra_replicas_pred(struct bch_fs *c, void *arg,
struct extent_ptr_decoded p;
unsigned i = 0;
rcu_read_lock();
bkey_for_each_ptr_decode(k.k, bch2_bkey_ptrs_c(k), p, entry) {
unsigned d = bch2_extent_ptr_durability(c, &p);
@ -1043,6 +1044,7 @@ static bool drop_extra_replicas_pred(struct bch_fs *c, void *arg,
i++;
}
rcu_read_unlock();
return data_opts->kill_ptrs != 0;
}