Skip to content

Commit cf3da2d

Browse files
author
Kent Overstreet
committed
bcachefs: Handle -BCH_ERR_need_mark_replicas in gc
Locking considerations (possibly no longer relevant?) mean that when an accounting update needs a new superblock replicas entry to be created, it's deferred to the transaction commit error path. But accounting updates for gc/fcsk aren't done from the transaction commit path - so we need to handle -BCH_ERR_btree_insert_need_mark_replicas locally. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 861cd0f commit cf3da2d

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

fs/bcachefs/disk_accounting.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ static inline void accounting_key_init(struct bkey_i *k, struct disk_accounting_
7979
memcpy_u64s_small(acc->v.d, d, nr);
8080
}
8181

82+
static int bch2_accounting_update_sb_one(struct bch_fs *, struct bpos);
83+
8284
int bch2_disk_accounting_mod(struct btree_trans *trans,
8385
struct disk_accounting_pos *k,
8486
s64 *d, unsigned nr, bool gc)
@@ -96,9 +98,16 @@ int bch2_disk_accounting_mod(struct btree_trans *trans,
9698

9799
accounting_key_init(&k_i.k, k, d, nr);
98100

99-
return likely(!gc)
100-
? bch2_trans_update_buffered(trans, BTREE_ID_accounting, &k_i.k)
101-
: bch2_accounting_mem_add(trans, bkey_i_to_s_c_accounting(&k_i.k), true);
101+
if (unlikely(gc)) {
102+
int ret = bch2_accounting_mem_add(trans, bkey_i_to_s_c_accounting(&k_i.k), true);
103+
if (ret == -BCH_ERR_btree_insert_need_mark_replicas)
104+
ret = drop_locks_do(trans,
105+
bch2_accounting_update_sb_one(trans->c, disk_accounting_pos_to_bpos(k))) ?:
106+
bch2_accounting_mem_add(trans, bkey_i_to_s_c_accounting(&k_i.k), true);
107+
return ret;
108+
} else {
109+
return bch2_trans_update_buffered(trans, BTREE_ID_accounting, &k_i.k);
110+
}
102111
}
103112

104113
int bch2_mod_dev_cached_sectors(struct btree_trans *trans,

0 commit comments

Comments
 (0)