Skip to content

Commit 1ba6f48

Browse files
author
Kent Overstreet
committed
bcachefs: Fix nested transaction restart handling in bch2_bucket_gens_init()
Nested transaction restart handling is typically best avoided; when the inner context handles a transaction restart it invalidates the outer transaction context, so we need to make sure to return a transaction_restart_nested error. This code wasn't doing that, and hit the assertion in for_each_btree_key() that checks for that via trans->restart_count. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 3becdd4 commit 1ba6f48

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

fs/bcachefs/alloc_background.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -532,13 +532,13 @@ int bch2_bucket_gens_init(struct bch_fs *c)
532532
u8 gen = bch2_alloc_to_v4(k, &a)->gen;
533533
unsigned offset;
534534
struct bpos pos = alloc_gens_pos(iter.pos, &offset);
535+
int ret2 = 0;
535536

536537
if (have_bucket_gens_key && bkey_cmp(iter.pos, pos)) {
537-
ret = commit_do(trans, NULL, NULL,
538-
BCH_TRANS_COMMIT_no_enospc,
539-
bch2_btree_insert_trans(trans, BTREE_ID_bucket_gens, &g.k_i, 0));
540-
if (ret)
541-
break;
538+
ret2 = bch2_btree_insert_trans(trans, BTREE_ID_bucket_gens, &g.k_i, 0) ?:
539+
bch2_trans_commit(trans, NULL, NULL, BCH_TRANS_COMMIT_no_enospc);
540+
if (ret2)
541+
goto iter_err;
542542
have_bucket_gens_key = false;
543543
}
544544

@@ -549,7 +549,8 @@ int bch2_bucket_gens_init(struct bch_fs *c)
549549
}
550550

551551
g.v.gens[offset] = gen;
552-
0;
552+
iter_err:
553+
ret2;
553554
}));
554555

555556
if (have_bucket_gens_key && !ret)

0 commit comments

Comments
 (0)