@@ -567,6 +567,7 @@ int bch2_bucket_gens_init(struct bch_fs *c)
567
567
int bch2_alloc_read (struct bch_fs * c )
568
568
{
569
569
struct btree_trans * trans = bch2_trans_get (c );
570
+ struct bch_dev * ca = NULL ;
570
571
int ret ;
571
572
572
573
down_read (& c -> gc_lock );
@@ -580,16 +581,17 @@ int bch2_alloc_read(struct bch_fs *c)
580
581
if (k .k -> type != KEY_TYPE_bucket_gens )
581
582
continue ;
582
583
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 );
585
585
/*
586
586
* Not a fsck error because this is checked/repaired by
587
587
* bch2_check_alloc_key() which runs later:
588
588
*/
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 ));
590
591
continue ;
592
+ }
591
593
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 ;
593
595
594
596
for (u64 b = max_t (u64 , ca -> mi .first_bucket , start );
595
597
b < min_t (u64 , ca -> mi .nbuckets , end );
@@ -600,21 +602,23 @@ int bch2_alloc_read(struct bch_fs *c)
600
602
} else {
601
603
ret = for_each_btree_key (trans , iter , BTREE_ID_alloc , POS_MIN ,
602
604
BTREE_ITER_prefetch , k , ({
605
+ ca = bch2_dev_iterate (c , ca , k .k -> p .inode );
603
606
/*
604
607
* Not a fsck error because this is checked/repaired by
605
608
* bch2_check_alloc_key() which runs later:
606
609
*/
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 ));
608
612
continue ;
609
-
610
- struct bch_dev * ca = bch2_dev_bkey_exists (c , k .k -> p .inode );
613
+ }
611
614
612
615
struct bch_alloc_v4 a ;
613
616
* bucket_gen (ca , k .k -> p .offset ) = bch2_alloc_to_v4 (k , & a )-> gen ;
614
617
0 ;
615
618
}));
616
619
}
617
620
621
+ bch2_dev_put (ca );
618
622
bch2_trans_put (trans );
619
623
up_read (& c -> gc_lock );
620
624
0 commit comments