Skip to content

Commit fa6cce0

Browse files
author
Kent Overstreet
committed
bcachefs: bch2_dev_iterate()
New helper for getting refs to devices as we iterate. Signed-off-by: Kent Overstreet <[email protected]>
1 parent cb4d340 commit fa6cce0

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

fs/bcachefs/alloc_background.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ int bch2_bucket_gens_init(struct bch_fs *c)
567567
int bch2_alloc_read(struct bch_fs *c)
568568
{
569569
struct btree_trans *trans = bch2_trans_get(c);
570+
struct bch_dev *ca = NULL;
570571
int ret;
571572

572573
down_read(&c->gc_lock);
@@ -580,16 +581,17 @@ int bch2_alloc_read(struct bch_fs *c)
580581
if (k.k->type != KEY_TYPE_bucket_gens)
581582
continue;
582583

583-
const struct bch_bucket_gens *g = bkey_s_c_to_bucket_gens(k).v;
584-
584+
ca = bch2_dev_iterate(c, ca, k.k->p.inode);
585585
/*
586586
* Not a fsck error because this is checked/repaired by
587587
* bch2_check_alloc_key() which runs later:
588588
*/
589-
if (!bch2_dev_exists(c, k.k->p.inode))
589+
if (!ca) {
590+
bch2_btree_iter_set_pos(&iter, POS(k.k->p.inode + 1, 0));
590591
continue;
592+
}
591593

592-
struct bch_dev *ca = bch2_dev_bkey_exists(c, k.k->p.inode);
594+
const struct bch_bucket_gens *g = bkey_s_c_to_bucket_gens(k).v;
593595

594596
for (u64 b = max_t(u64, ca->mi.first_bucket, start);
595597
b < min_t(u64, ca->mi.nbuckets, end);
@@ -600,21 +602,23 @@ int bch2_alloc_read(struct bch_fs *c)
600602
} else {
601603
ret = for_each_btree_key(trans, iter, BTREE_ID_alloc, POS_MIN,
602604
BTREE_ITER_prefetch, k, ({
605+
ca = bch2_dev_iterate(c, ca, k.k->p.inode);
603606
/*
604607
* Not a fsck error because this is checked/repaired by
605608
* bch2_check_alloc_key() which runs later:
606609
*/
607-
if (!bch2_dev_bucket_exists(c, k.k->p))
610+
if (!ca) {
611+
bch2_btree_iter_set_pos(&iter, POS(k.k->p.inode + 1, 0));
608612
continue;
609-
610-
struct bch_dev *ca = bch2_dev_bkey_exists(c, k.k->p.inode);
613+
}
611614

612615
struct bch_alloc_v4 a;
613616
*bucket_gen(ca, k.k->p.offset) = bch2_alloc_to_v4(k, &a)->gen;
614617
0;
615618
}));
616619
}
617620

621+
bch2_dev_put(ca);
618622
bch2_trans_put(trans);
619623
up_read(&c->gc_lock);
620624

fs/bcachefs/sb-members.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,14 @@ static inline struct bch_dev *bch2_dev_bucket_tryget(struct bch_fs *c, struct bp
262262
return ca;
263263
}
264264

265+
static inline struct bch_dev *bch2_dev_iterate(struct bch_fs *c, struct bch_dev *ca, unsigned dev_idx)
266+
{
267+
if (ca && ca->dev_idx == dev_idx)
268+
return ca;
269+
bch2_dev_put(ca);
270+
return bch2_dev_tryget(c, dev_idx);
271+
}
272+
265273
/* XXX kill, move to struct bch_fs */
266274
static inline struct bch_devs_mask bch2_online_devs(struct bch_fs *c)
267275
{

0 commit comments

Comments
 (0)