@@ -103,23 +103,35 @@ static inline int accounting_pos_cmp(const void *_l, const void *_r)
103
103
return bpos_cmp (* l , * r );
104
104
}
105
105
106
- int bch2_accounting_mem_insert (struct bch_fs * , struct bkey_s_c_accounting , bool );
106
+ enum bch_accounting_mode {
107
+ BCH_ACCOUNTING_normal ,
108
+ BCH_ACCOUNTING_gc ,
109
+ BCH_ACCOUNTING_read ,
110
+ };
111
+
112
+ int bch2_accounting_mem_insert (struct bch_fs * , struct bkey_s_c_accounting , enum bch_accounting_mode );
107
113
void bch2_accounting_mem_gc (struct bch_fs * );
108
114
109
115
/*
110
116
* Update in memory counters so they match the btree update we're doing; called
111
117
* from transaction commit path
112
118
*/
113
- static inline int bch2_accounting_mem_mod_locked (struct btree_trans * trans , struct bkey_s_c_accounting a , bool gc , bool read )
119
+ static inline int bch2_accounting_mem_mod_locked (struct btree_trans * trans ,
120
+ struct bkey_s_c_accounting a ,
121
+ enum bch_accounting_mode mode )
114
122
{
115
123
struct bch_fs * c = trans -> c ;
124
+ struct bch_accounting_mem * acc = & c -> accounting ;
116
125
struct disk_accounting_pos acc_k ;
117
126
bpos_to_disk_accounting_pos (& acc_k , a .k -> p );
127
+ bool gc = mode == BCH_ACCOUNTING_gc ;
128
+
129
+ EBUG_ON (gc && !acc -> gc_running );
118
130
119
131
if (acc_k .type == BCH_DISK_ACCOUNTING_inum )
120
132
return 0 ;
121
133
122
- if (! gc && ! read ) {
134
+ if (mode == BCH_ACCOUNTING_normal ) {
123
135
switch (acc_k .type ) {
124
136
case BCH_DISK_ACCOUNTING_persistent_reserved :
125
137
trans -> fs_usage_delta .reserved += acc_k .persistent_reserved .nr_replicas * a .v -> d [0 ];
@@ -140,14 +152,11 @@ static inline int bch2_accounting_mem_mod_locked(struct btree_trans *trans, stru
140
152
}
141
153
}
142
154
143
- struct bch_accounting_mem * acc = & c -> accounting ;
144
155
unsigned idx ;
145
156
146
- EBUG_ON (gc && !acc -> gc_running );
147
-
148
157
while ((idx = eytzinger0_find (acc -> k .data , acc -> k .nr , sizeof (acc -> k .data [0 ]),
149
158
accounting_pos_cmp , & a .k -> p )) >= acc -> k .nr ) {
150
- int ret = bch2_accounting_mem_insert (c , a , gc );
159
+ int ret = bch2_accounting_mem_insert (c , a , mode );
151
160
if (ret )
152
161
return ret ;
153
162
}
@@ -164,7 +173,7 @@ static inline int bch2_accounting_mem_mod_locked(struct btree_trans *trans, stru
164
173
static inline int bch2_accounting_mem_add (struct btree_trans * trans , struct bkey_s_c_accounting a , bool gc )
165
174
{
166
175
percpu_down_read (& trans -> c -> mark_lock );
167
- int ret = bch2_accounting_mem_mod_locked (trans , a , gc , false );
176
+ int ret = bch2_accounting_mem_mod_locked (trans , a , gc ? BCH_ACCOUNTING_gc : BCH_ACCOUNTING_normal );
168
177
percpu_up_read (& trans -> c -> mark_lock );
169
178
return ret ;
170
179
}
0 commit comments