Skip to content

Commit 302c980

Browse files
author
Kent Overstreet
committed
bcachefs: extent_ptr_durability() -> bch2_dev_rcu()
Signed-off-by: Kent Overstreet <[email protected]>
1 parent 3793b3f commit 302c980

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

fs/bcachefs/data_update.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ static int __bch2_data_update_index_update(struct btree_trans *trans,
203203

204204
/* Now, drop excess replicas: */
205205
restart_drop_extra_replicas:
206+
207+
rcu_read_lock();
206208
bkey_for_each_ptr_decode(old.k, bch2_bkey_ptrs(bkey_i_to_s(insert)), p, entry) {
207209
unsigned ptr_durability = bch2_extent_ptr_durability(c, &p);
208210

@@ -214,6 +216,7 @@ static int __bch2_data_update_index_update(struct btree_trans *trans,
214216
goto restart_drop_extra_replicas;
215217
}
216218
}
219+
rcu_read_unlock();
217220

218221
/* Finally, add the pointers we just wrote: */
219222
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,
552555
struct bpos bucket = PTR_BUCKET_POS(ca, &p.ptr);
553556
bool locked;
554557

558+
rcu_read_lock();
555559
if (((1U << i) & m->data_opts.rewrite_ptrs)) {
556560
BUG_ON(p.ptr.cached);
557561

@@ -565,6 +569,7 @@ int bch2_data_update_init(struct btree_trans *trans,
565569
bch2_dev_list_add_dev(&m->op.devs_have, p.ptr.dev);
566570
durability_have += bch2_extent_ptr_durability(c, &p);
567571
}
572+
rcu_read_unlock();
568573

569574
/*
570575
* op->csum_type is normally initialized from the fs/file's

fs/bcachefs/extents.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -675,16 +675,16 @@ static inline unsigned __extent_ptr_durability(struct bch_dev *ca, struct extent
675675

676676
unsigned bch2_extent_ptr_desired_durability(struct bch_fs *c, struct extent_ptr_decoded *p)
677677
{
678-
struct bch_dev *ca = bch2_dev_bkey_exists(c, p->ptr.dev);
678+
struct bch_dev *ca = bch2_dev_rcu(c, p->ptr.dev);
679679

680-
return __extent_ptr_durability(ca, p);
680+
return ca ? __extent_ptr_durability(ca, p) : 0;
681681
}
682682

683683
unsigned bch2_extent_ptr_durability(struct bch_fs *c, struct extent_ptr_decoded *p)
684684
{
685-
struct bch_dev *ca = bch2_dev_bkey_exists(c, p->ptr.dev);
685+
struct bch_dev *ca = bch2_dev_rcu(c, p->ptr.dev);
686686

687-
if (ca->mi.state == BCH_MEMBER_STATE_failed)
687+
if (!ca || ca->mi.state == BCH_MEMBER_STATE_failed)
688688
return 0;
689689

690690
return __extent_ptr_durability(ca, p);
@@ -697,8 +697,10 @@ unsigned bch2_bkey_durability(struct bch_fs *c, struct bkey_s_c k)
697697
struct extent_ptr_decoded p;
698698
unsigned durability = 0;
699699

700+
rcu_read_lock();
700701
bkey_for_each_ptr_decode(k.k, ptrs, p, entry)
701702
durability += bch2_extent_ptr_durability(c, &p);
703+
rcu_read_unlock();
702704

703705
return durability;
704706
}
@@ -710,9 +712,11 @@ static unsigned bch2_bkey_durability_safe(struct bch_fs *c, struct bkey_s_c k)
710712
struct extent_ptr_decoded p;
711713
unsigned durability = 0;
712714

715+
rcu_read_lock();
713716
bkey_for_each_ptr_decode(k.k, ptrs, p, entry)
714717
if (p.ptr.dev < c->sb.nr_devices && c->devs[p.ptr.dev])
715718
durability += bch2_extent_ptr_durability(c, &p);
719+
rcu_read_unlock();
716720

717721
return durability;
718722
}

fs/bcachefs/io_write.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1099,12 +1099,17 @@ static bool bch2_extent_is_writeable(struct bch_write_op *op,
10991099
return false;
11001100

11011101
e = bkey_s_c_to_extent(k);
1102+
1103+
rcu_read_lock();
11021104
extent_for_each_ptr_decode(e, p, entry) {
1103-
if (crc_is_encoded(p.crc) || p.has_ec)
1105+
if (crc_is_encoded(p.crc) || p.has_ec) {
1106+
rcu_read_unlock();
11041107
return false;
1108+
}
11051109

11061110
replicas += bch2_extent_ptr_durability(c, &p);
11071111
}
1112+
rcu_read_unlock();
11081113

11091114
return replicas >= op->opts.data_replicas;
11101115
}

fs/bcachefs/move.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,7 @@ static bool drop_extra_replicas_pred(struct bch_fs *c, void *arg,
10331033
struct extent_ptr_decoded p;
10341034
unsigned i = 0;
10351035

1036+
rcu_read_lock();
10361037
bkey_for_each_ptr_decode(k.k, bch2_bkey_ptrs_c(k), p, entry) {
10371038
unsigned d = bch2_extent_ptr_durability(c, &p);
10381039

@@ -1043,6 +1044,7 @@ static bool drop_extra_replicas_pred(struct bch_fs *c, void *arg,
10431044

10441045
i++;
10451046
}
1047+
rcu_read_unlock();
10461048

10471049
return data_opts->kill_ptrs != 0;
10481050
}

0 commit comments

Comments
 (0)