Skip to content

Commit d8b5059

Browse files
author
Kent Overstreet
committed
bcachefs: fix restart handling in bch2_alloc_write_key()
This is ugly: We may discover in alloc_write_key that the data type we calculated is wrong, because BCH_DATA_need_discard is checked/set elsewhere, and the disk accounting counters we calculated need to be updated. But bch2_alloc_key_to_dev_counters(..., BTREE_TRIGGER_gc) is not safe w.r.t. transaction restarts, so we need to propagate the fixup back to our gc state in case we take a transaction restart. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 7ee4be9 commit d8b5059

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

fs/bcachefs/btree_gc.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,12 +820,22 @@ static int bch2_alloc_write_key(struct btree_trans *trans,
820820
* fix that here:
821821
*/
822822
alloc_data_type_set(&gc, gc.data_type);
823-
824823
if (gc.data_type != old_gc.data_type ||
825824
gc.dirty_sectors != old_gc.dirty_sectors) {
826825
ret = bch2_alloc_key_to_dev_counters(trans, ca, &old_gc, &gc, BTREE_TRIGGER_gc);
827826
if (ret)
828827
return ret;
828+
829+
/*
830+
* Ugly: alloc_key_to_dev_counters(..., BTREE_TRIGGER_gc) is not
831+
* safe w.r.t. transaction restarts, so fixup the gc_bucket so
832+
* we don't run it twice:
833+
*/
834+
percpu_down_read(&c->mark_lock);
835+
struct bucket *gc_m = gc_bucket(ca, iter->pos.offset);
836+
gc_m->data_type = gc.data_type;
837+
gc_m->dirty_sectors = gc.dirty_sectors;
838+
percpu_up_read(&c->mark_lock);
829839
}
830840

831841
if (fsck_err_on(new.data_type != gc.data_type,

0 commit comments

Comments
 (0)