mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-13 14:14:37 +00:00
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. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
5b8a9227f8
commit
01a0108f01
1 changed files with 14 additions and 3 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue