Skip to content

Commit beccf29

Browse files
author
Kent Overstreet
committed
bcachefs: Fix a race in btree_update_nodes_written()
One btree update might have terminated in a node update, and then while it is in flight another btree update might free that original node. This race has to be handled in btree_update_nodes_written() - we were missing a READ_ONCE(). Signed-off-by: Kent Overstreet <[email protected]>
1 parent 9b31152 commit beccf29

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

fs/bcachefs/btree_update_interior.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -704,9 +704,13 @@ static void btree_update_nodes_written(struct btree_update *as)
704704
bch2_fs_fatal_err_on(ret && !bch2_journal_error(&c->journal), c,
705705
"%s", bch2_err_str(ret));
706706
err:
707-
if (as->b) {
708-
709-
b = as->b;
707+
/*
708+
* We have to be careful because another thread might be getting ready
709+
* to free as->b and calling btree_update_reparent() on us - we'll
710+
* recheck under btree_update_lock below:
711+
*/
712+
b = READ_ONCE(as->b);
713+
if (b) {
710714
btree_path_idx_t path_idx = get_unlocked_mut_path(trans,
711715
as->btree_id, b->c.level, b->key.k.p);
712716
struct btree_path *path = trans->paths + path_idx;

0 commit comments

Comments
 (0)