Skip to content

Commit 2111f39

Browse files
author
Kent Overstreet
committed
bcachefs: Fix race between btree writes and metadata drop
btree writes update the btree node key after every write, in order to update sectors_written, and they also might need to drop pointers if one of the writes failed in a replicated btree node. But the btree node might also have had a pointer dropped while the write was in flight, by bch2_dev_metadata_drop(), and thus there was a bug where the btree node write would ovewrite the btree node's key with what it had at the start of the write. Fix this by dropping pointers not currently in the btree node key. Signed-off-by: Kent Overstreet <[email protected]>
1 parent ef0beeb commit 2111f39

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

fs/bcachefs/btree_update_interior.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,6 +2270,10 @@ int bch2_btree_node_update_key_get_iter(struct btree_trans *trans,
22702270

22712271
BUG_ON(!btree_node_hashed(b));
22722272

2273+
struct bch_extent_ptr *ptr;
2274+
bch2_bkey_drop_ptrs(bkey_i_to_s(new_key), ptr,
2275+
!bch2_bkey_has_device(bkey_i_to_s(&b->key), ptr->dev));
2276+
22732277
ret = bch2_btree_node_update_key(trans, &iter, b, new_key,
22742278
commit_flags, skip_triggers);
22752279
out:

0 commit comments

Comments
 (0)