bcachefs: Fix btree node merge -> split operations
authorKent Overstreet <kent.overstreet@gmail.com>
Fri, 11 Dec 2020 17:02:48 +0000 (12:02 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:49 +0000 (17:08 -0400)
If a btree node merger is followed by a split or compact of the parent
node, we could end up with the parent btree node iterator pointing to
the whiteout inserted by the btree node merge operation - the fix is to
ensure that interior btree node iterators always point to the first non
whiteout.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_iter.c

index 239d7c5deddc542ed71507f8e7ad9a154aefa33a..c0333ee94463f45b7f041516a49e681612f60828 100644 (file)
@@ -902,6 +902,13 @@ static inline void __btree_iter_init(struct btree_iter *iter,
 
        bch2_btree_node_iter_init(&l->iter, l->b, &pos);
 
+       /*
+        * Iterators to interior nodes should always be pointed at the first non
+        * whiteout:
+        */
+       if (level)
+               bch2_btree_node_iter_peek(&l->iter, l->b);
+
        btree_iter_set_dirty(iter, BTREE_ITER_NEED_PEEK);
 }