@@ -324,7 +324,8 @@ int bch2_accounting_mem_insert(struct bch_fs *c, struct bkey_s_c_accounting a,
324
324
{
325
325
struct bch_replicas_padded r ;
326
326
327
- if (accounting_to_replicas (& r .e , a .k -> p ) &&
327
+ if (mode != BCH_ACCOUNTING_read &&
328
+ accounting_to_replicas (& r .e , a .k -> p ) &&
328
329
!bch2_replicas_marked_locked (c , & r .e ))
329
330
return - BCH_ERR_btree_insert_need_mark_replicas ;
330
331
@@ -592,7 +593,6 @@ int bch2_gc_accounting_done(struct bch_fs *c)
592
593
static int accounting_read_key (struct btree_trans * trans , struct bkey_s_c k )
593
594
{
594
595
struct bch_fs * c = trans -> c ;
595
- struct printbuf buf = PRINTBUF ;
596
596
597
597
if (k .k -> type != KEY_TYPE_accounting )
598
598
return 0 ;
@@ -601,22 +601,6 @@ static int accounting_read_key(struct btree_trans *trans, struct bkey_s_c k)
601
601
int ret = bch2_accounting_mem_mod_locked (trans , bkey_s_c_to_accounting (k ),
602
602
BCH_ACCOUNTING_read );
603
603
percpu_up_read (& c -> mark_lock );
604
-
605
- if (bch2_accounting_key_is_zero (bkey_s_c_to_accounting (k )) &&
606
- ret == - BCH_ERR_btree_insert_need_mark_replicas )
607
- ret = 0 ;
608
-
609
- struct disk_accounting_pos acc ;
610
- bpos_to_disk_accounting_pos (& acc , k .k -> p );
611
-
612
- if (fsck_err_on (ret == - BCH_ERR_btree_insert_need_mark_replicas ,
613
- trans , accounting_replicas_not_marked ,
614
- "accounting not marked in superblock replicas\n %s" ,
615
- (bch2_accounting_key_to_text (& buf , & acc ),
616
- buf .buf )))
617
- ret = bch2_accounting_update_sb_one (c , k .k -> p );
618
- fsck_err :
619
- printbuf_exit (& buf );
620
604
return ret ;
621
605
}
622
606
@@ -628,6 +612,7 @@ int bch2_accounting_read(struct bch_fs *c)
628
612
{
629
613
struct bch_accounting_mem * acc = & c -> accounting ;
630
614
struct btree_trans * trans = bch2_trans_get (c );
615
+ struct printbuf buf = PRINTBUF ;
631
616
632
617
int ret = for_each_btree_key (trans , iter ,
633
618
BTREE_ID_accounting , POS_MIN ,
@@ -678,6 +663,30 @@ int bch2_accounting_read(struct bch_fs *c)
678
663
keys -> gap = keys -> nr = dst - keys -> data ;
679
664
680
665
percpu_down_read (& c -> mark_lock );
666
+ for (unsigned i = 0 ; i < acc -> k .nr ; i ++ ) {
667
+ u64 v [BCH_ACCOUNTING_MAX_COUNTERS ];
668
+ bch2_accounting_mem_read_counters (acc , i , v , ARRAY_SIZE (v ), false);
669
+
670
+ if (bch2_is_zero (v , sizeof (v [0 ]) * acc -> k .data [i ].nr_counters ))
671
+ continue ;
672
+
673
+ struct bch_replicas_padded r ;
674
+
675
+ if (!accounting_to_replicas (& r .e , acc -> k .data [i ].pos ))
676
+ continue ;
677
+
678
+ struct disk_accounting_pos k ;
679
+ bpos_to_disk_accounting_pos (& k , acc -> k .data [i ].pos );
680
+
681
+ if (fsck_err_on (!bch2_replicas_marked_locked (c , & r .e ),
682
+ trans , accounting_replicas_not_marked ,
683
+ "accounting not marked in superblock replicas\n %s" ,
684
+ (printbuf_reset (& buf ),
685
+ bch2_accounting_key_to_text (& buf , & k ),
686
+ buf .buf )))
687
+ ret = bch2_accounting_update_sb_one (c , acc -> k .data [i ].pos );
688
+ }
689
+
681
690
preempt_disable ();
682
691
struct bch_fs_usage_base * usage = this_cpu_ptr (c -> usage );
683
692
@@ -713,8 +722,10 @@ int bch2_accounting_read(struct bch_fs *c)
713
722
}
714
723
}
715
724
preempt_enable ();
725
+ fsck_err :
716
726
percpu_up_read (& c -> mark_lock );
717
727
err :
728
+ printbuf_exit (& buf );
718
729
bch2_trans_put (trans );
719
730
bch_err_fn (c , ret );
720
731
return ret ;
0 commit comments