summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2018-11-29 03:24:06 -0500
committerKent Overstreet <kent.overstreet@gmail.com>2018-12-27 11:38:34 -0500
commit86358bbbd4a5e4cc0e7fb9dba30114027a778864 (patch)
tree370005845bf86f8b4278cc4eaa3ec73182c1042b
parentc68f2bdab5f8ab88ef21d65e358a5c0909b6c23c (diff)
bcachefs: Fix a btree iter usage error
previously, if the code traversed to the next btree node, that could return an error (due to lock restarts) - which was not being checked for. fix is to rework it so it never iterates past the current leaf node, and pops an assertion if it ever sees an error.
-rw-r--r--fs/bcachefs/fs-io.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/fs/bcachefs/fs-io.c b/fs/bcachefs/fs-io.c
index 34cfd5d6224e..d90161a103cf 100644
--- a/fs/bcachefs/fs-io.c
+++ b/fs/bcachefs/fs-io.c
@@ -242,9 +242,15 @@ static s64 sum_sector_overwrites(struct bkey_i *new, struct btree_iter *_iter,
bch2_btree_iter_link(_iter, &iter);
bch2_btree_iter_copy(&iter, _iter);
- for_each_btree_key_continue(&iter, BTREE_ITER_SLOTS, old) {
- if (bkey_cmp(new->k.p, bkey_start_pos(old.k)) <= 0)
- break;
+ old = bch2_btree_iter_peek_slot(&iter);
+
+ while (1) {
+ /*
+ * should not be possible to get an error here, since we're
+ * carefully not advancing past @new and thus whatever leaf node
+ * @_iter currently points to:
+ */
+ BUG_ON(btree_iter_err(old));
if (allocating &&
!bch2_extent_is_fully_allocated(old))
@@ -256,6 +262,11 @@ static s64 sum_sector_overwrites(struct bkey_i *new, struct btree_iter *_iter,
bkey_start_offset(old.k))) *
(bkey_extent_is_allocation(&new->k) -
bkey_extent_is_allocation(old.k));
+
+ if (bkey_cmp(old.k->p, new->k.p) >= 0)
+ break;
+
+ old = bch2_btree_iter_next_slot(&iter);
}
bch2_btree_iter_unlink(&iter);