@@ -724,9 +724,7 @@ static int __trigger_extent(struct btree_trans *trans,
724724 .replicas .nr_required = 1 ,
725725 };
726726
727- struct disk_accounting_pos acct_compression_key = {
728- .type = BCH_DISK_ACCOUNTING_compression ,
729- };
727+ unsigned cur_compression_type = 0 ;
730728 u64 compression_acct [3 ] = { 1 , 0 , 0 };
731729
732730 bkey_for_each_ptr_decode (k .k , ptrs , p , entry ) {
@@ -760,13 +758,13 @@ static int __trigger_extent(struct btree_trans *trans,
760758 acc_replicas_key .replicas .nr_required = 0 ;
761759 }
762760
763- if (acct_compression_key . compression . type &&
764- acct_compression_key . compression . type != p .crc .compression_type ) {
761+ if (cur_compression_type &&
762+ cur_compression_type != p .crc .compression_type ) {
765763 if (flags & BTREE_TRIGGER_overwrite )
766764 bch2_u64s_neg (compression_acct , ARRAY_SIZE (compression_acct ));
767765
768- ret = bch2_disk_accounting_mod (trans , & acct_compression_key , compression_acct ,
769- ARRAY_SIZE ( compression_acct ), gc );
766+ ret = bch2_disk_accounting_mod2 (trans , gc , compression_acct ,
767+ compression , cur_compression_type );
770768 if (ret )
771769 return ret ;
772770
@@ -775,7 +773,7 @@ static int __trigger_extent(struct btree_trans *trans,
775773 compression_acct [2 ] = 0 ;
776774 }
777775
778- acct_compression_key . compression . type = p .crc .compression_type ;
776+ cur_compression_type = p .crc .compression_type ;
779777 if (p .crc .compression_type ) {
780778 compression_acct [1 ] += p .crc .uncompressed_size ;
781779 compression_acct [2 ] += p .crc .compressed_size ;
@@ -789,45 +787,34 @@ static int __trigger_extent(struct btree_trans *trans,
789787 }
790788
791789 if (acc_replicas_key .replicas .nr_devs && !level && k .k -> p .snapshot ) {
792- struct disk_accounting_pos acc_snapshot_key = {
793- .type = BCH_DISK_ACCOUNTING_snapshot ,
794- .snapshot .id = k .k -> p .snapshot ,
795- };
796- ret = bch2_disk_accounting_mod (trans , & acc_snapshot_key , replicas_sectors , 1 , gc );
790+ ret = bch2_disk_accounting_mod2_nr (trans , gc , replicas_sectors , 1 , snapshot , k .k -> p .snapshot );
797791 if (ret )
798792 return ret ;
799793 }
800794
801- if (acct_compression_key . compression . type ) {
795+ if (cur_compression_type ) {
802796 if (flags & BTREE_TRIGGER_overwrite )
803797 bch2_u64s_neg (compression_acct , ARRAY_SIZE (compression_acct ));
804798
805- ret = bch2_disk_accounting_mod (trans , & acct_compression_key , compression_acct ,
806- ARRAY_SIZE ( compression_acct ), gc );
799+ ret = bch2_disk_accounting_mod2 (trans , gc , compression_acct ,
800+ compression , cur_compression_type );
807801 if (ret )
808802 return ret ;
809803 }
810804
811805 if (level ) {
812- struct disk_accounting_pos acc_btree_key = {
813- .type = BCH_DISK_ACCOUNTING_btree ,
814- .btree .id = btree_id ,
815- };
816- ret = bch2_disk_accounting_mod (trans , & acc_btree_key , replicas_sectors , 1 , gc );
806+ ret = bch2_disk_accounting_mod2_nr (trans , gc , replicas_sectors , 1 , btree , btree_id );
817807 if (ret )
818808 return ret ;
819809 } else {
820810 bool insert = !(flags & BTREE_TRIGGER_overwrite );
821- struct disk_accounting_pos acc_inum_key = {
822- .type = BCH_DISK_ACCOUNTING_inum ,
823- .inum .inum = k .k -> p .inode ,
824- };
811+
825812 s64 v [3 ] = {
826813 insert ? 1 : -1 ,
827814 insert ? k .k -> size : - ((s64 ) k .k -> size ),
828815 * replicas_sectors ,
829816 };
830- ret = bch2_disk_accounting_mod (trans , & acc_inum_key , v , ARRAY_SIZE ( v ), gc );
817+ ret = bch2_disk_accounting_mod2 (trans , gc , v , inum , k . k -> p . inode );
831818 if (ret )
832819 return ret ;
833820 }
@@ -876,15 +863,15 @@ int bch2_trigger_extent(struct btree_trans *trans,
876863 }
877864
878865 int need_rebalance_delta = 0 ;
879- s64 need_rebalance_sectors_delta = 0 ;
866+ s64 need_rebalance_sectors_delta [ 1 ] = { 0 } ;
880867
881868 s64 s = bch2_bkey_sectors_need_rebalance (c , old );
882869 need_rebalance_delta -= s != 0 ;
883- need_rebalance_sectors_delta -= s ;
870+ need_rebalance_sectors_delta [ 0 ] -= s ;
884871
885872 s = bch2_bkey_sectors_need_rebalance (c , new .s_c );
886873 need_rebalance_delta += s != 0 ;
887- need_rebalance_sectors_delta += s ;
874+ need_rebalance_sectors_delta [ 0 ] += s ;
888875
889876 if ((flags & BTREE_TRIGGER_transactional ) && need_rebalance_delta ) {
890877 int ret = bch2_btree_bit_mod_buffered (trans , BTREE_ID_rebalance_work ,
@@ -893,12 +880,9 @@ int bch2_trigger_extent(struct btree_trans *trans,
893880 return ret ;
894881 }
895882
896- if (need_rebalance_sectors_delta ) {
897- struct disk_accounting_pos acc = {
898- .type = BCH_DISK_ACCOUNTING_rebalance_work ,
899- };
900- int ret = bch2_disk_accounting_mod (trans , & acc , & need_rebalance_sectors_delta , 1 ,
901- flags & BTREE_TRIGGER_gc );
883+ if (need_rebalance_sectors_delta [0 ]) {
884+ int ret = bch2_disk_accounting_mod2 (trans , flags & BTREE_TRIGGER_gc ,
885+ need_rebalance_sectors_delta , rebalance_work );
902886 if (ret )
903887 return ret ;
904888 }
@@ -914,17 +898,13 @@ static int __trigger_reservation(struct btree_trans *trans,
914898 enum btree_iter_update_trigger_flags flags )
915899{
916900 if (flags & (BTREE_TRIGGER_transactional |BTREE_TRIGGER_gc )) {
917- s64 sectors = k .k -> size ;
901+ s64 sectors [ 1 ] = { k .k -> size } ;
918902
919903 if (flags & BTREE_TRIGGER_overwrite )
920- sectors = - sectors ;
921-
922- struct disk_accounting_pos acc = {
923- .type = BCH_DISK_ACCOUNTING_persistent_reserved ,
924- .persistent_reserved .nr_replicas = bkey_s_c_to_reservation (k ).v -> nr_replicas ,
925- };
904+ sectors [0 ] = - sectors [0 ];
926905
927- return bch2_disk_accounting_mod (trans , & acc , & sectors , 1 , flags & BTREE_TRIGGER_gc );
906+ return bch2_disk_accounting_mod2 (trans , flags & BTREE_TRIGGER_gc , sectors ,
907+ persistent_reserved , bkey_s_c_to_reservation (k ).v -> nr_replicas );
928908 }
929909
930910 return 0 ;
0 commit comments