Skip to content

Commit 8783856

Browse files
author
Kent Overstreet
committed
bcachefs: ob_dev()
Wrapper around bch2_dev_have_ref() for open_buckets; we do guarantee that the device an open_bucket points to exists. Signed-off-by: Kent Overstreet <[email protected]>
1 parent dbd0408 commit 8783856

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

fs/bcachefs/alloc_foreground.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static void bch2_open_bucket_hash_remove(struct bch_fs *c, struct open_bucket *o
100100

101101
void __bch2_open_bucket_put(struct bch_fs *c, struct open_bucket *ob)
102102
{
103-
struct bch_dev *ca = bch2_dev_bkey_exists(c, ob->dev);
103+
struct bch_dev *ca = ob_dev(c, ob);
104104

105105
if (ob->ec) {
106106
ec_stripe_new_put(c, ob->ec, STRIPE_REF_io);
@@ -684,8 +684,7 @@ static int add_new_bucket(struct bch_fs *c,
684684
unsigned flags,
685685
struct open_bucket *ob)
686686
{
687-
unsigned durability =
688-
bch2_dev_bkey_exists(c, ob->dev)->mi.durability;
687+
unsigned durability = ob_dev(c, ob)->mi.durability;
689688

690689
BUG_ON(*nr_effective >= nr_replicas);
691690

@@ -831,7 +830,7 @@ static bool want_bucket(struct bch_fs *c,
831830
bool *have_cache, bool ec,
832831
struct open_bucket *ob)
833832
{
834-
struct bch_dev *ca = bch2_dev_bkey_exists(c, ob->dev);
833+
struct bch_dev *ca = ob_dev(c, ob);
835834

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

903902
if (want_bucket(c, wp, devs_may_alloc, have_cache, ec, ob)) {
904-
struct bch_dev *ca = bch2_dev_bkey_exists(c, ob->dev);
903+
struct bch_dev *ca = ob_dev(c, ob);
905904
struct bch_dev_usage usage;
906905
u64 avail;
907906

@@ -1286,7 +1285,7 @@ deallocate_extra_replicas(struct bch_fs *c,
12861285
unsigned i;
12871286

12881287
open_bucket_for_each(c, ptrs, ob, i) {
1289-
unsigned d = bch2_dev_bkey_exists(c, ob->dev)->mi.durability;
1288+
unsigned d = ob_dev(c, ob)->mi.durability;
12901289

12911290
if (d && d <= extra_replicas) {
12921291
extra_replicas -= d;
@@ -1443,7 +1442,7 @@ int bch2_alloc_sectors_start_trans(struct btree_trans *trans,
14431442

14441443
struct bch_extent_ptr bch2_ob_ptr(struct bch_fs *c, struct open_bucket *ob)
14451444
{
1446-
struct bch_dev *ca = bch2_dev_bkey_exists(c, ob->dev);
1445+
struct bch_dev *ca = ob_dev(c, ob);
14471446

14481447
return (struct bch_extent_ptr) {
14491448
.type = 1 << BCH_EXTENT_ENTRY_ptr,
@@ -1519,7 +1518,7 @@ void bch2_fs_allocator_foreground_init(struct bch_fs *c)
15191518

15201519
static void bch2_open_bucket_to_text(struct printbuf *out, struct bch_fs *c, struct open_bucket *ob)
15211520
{
1522-
struct bch_dev *ca = bch2_dev_bkey_exists(c, ob->dev);
1521+
struct bch_dev *ca = ob_dev(c, ob);
15231522
unsigned data_type = ob->data_type;
15241523
barrier(); /* READ_ONCE() doesn't work on bitfields */
15251524

fs/bcachefs/alloc_foreground.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ void bch2_dev_stripe_increment(struct bch_dev *, struct dev_stripe_state *);
3030

3131
long bch2_bucket_alloc_new_fs(struct bch_dev *);
3232

33+
static inline struct bch_dev *ob_dev(struct bch_fs *c, struct open_bucket *ob)
34+
{
35+
return bch2_dev_have_ref(c, ob->dev);
36+
}
37+
3338
struct open_bucket *bch2_bucket_alloc(struct bch_fs *, struct bch_dev *,
3439
enum bch_watermark, enum bch_data_type,
3540
struct closure *);
@@ -185,7 +190,7 @@ bch2_alloc_sectors_append_ptrs_inlined(struct bch_fs *c, struct write_point *wp,
185190
wp->sectors_allocated += sectors;
186191

187192
open_bucket_for_each(c, &wp->ptrs, ob, i) {
188-
struct bch_dev *ca = bch2_dev_bkey_exists(c, ob->dev);
193+
struct bch_dev *ca = ob_dev(c, ob);
189194
struct bch_extent_ptr ptr = bch2_ob_ptr(c, ob);
190195

191196
ptr.cached = cached ||

fs/bcachefs/ec.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,16 +1550,13 @@ void bch2_ec_bucket_cancel(struct bch_fs *c, struct open_bucket *ob)
15501550
void *bch2_writepoint_ec_buf(struct bch_fs *c, struct write_point *wp)
15511551
{
15521552
struct open_bucket *ob = ec_open_bucket(c, &wp->ptrs);
1553-
struct bch_dev *ca;
1554-
unsigned offset;
1555-
15561553
if (!ob)
15571554
return NULL;
15581555

15591556
BUG_ON(!ob->ec->new_stripe.data[ob->ec_idx]);
15601557

1561-
ca = bch2_dev_bkey_exists(c, ob->dev);
1562-
offset = ca->mi.bucket_size - ob->sectors_free;
1558+
struct bch_dev *ca = ob_dev(c, ob);
1559+
unsigned offset = ca->mi.bucket_size - ob->sectors_free;
15631560

15641561
return ob->ec->new_stripe.data[ob->ec_idx] + (offset << 9);
15651562
}

fs/bcachefs/sb-members.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,13 @@ static inline bool bucket_valid(const struct bch_dev *ca, u64 b)
195195
return b - ca->mi.first_bucket < ca->mi.nbuckets_minus_first;
196196
}
197197

198+
static inline struct bch_dev *bch2_dev_have_ref(const struct bch_fs *c, unsigned dev)
199+
{
200+
EBUG_ON(!bch2_dev_exists(c, dev));
201+
202+
return rcu_dereference_check(c->devs[dev], 1);
203+
}
204+
198205
/*
199206
* If a key exists that references a device, the device won't be going away and
200207
* we can omit rcu_read_lock():

0 commit comments

Comments
 (0)