From c72f687a1ff1801b404fab804fdddcaf034e6ef4 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Tue, 11 Oct 2022 04:32:41 -0400 Subject: bcachefs: Use for_each_btree_key_upto() more consistently It's important that in BTREE_ITER_FILTER_SNAPSHOTS mode we always use peek_upto() and provide an end for the interval we're searching for - otherwise, when we hit the end of the inode the next inode be in a different subvolume and not have any keys in the current snapshot, and we'd iterate over arbitrarily many keys before returning one. Signed-off-by: Kent Overstreet --- fs/bcachefs/reflink.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'fs/bcachefs/reflink.c') diff --git a/fs/bcachefs/reflink.c b/fs/bcachefs/reflink.c index 08c98ac03c13..130ecc3a05c6 100644 --- a/fs/bcachefs/reflink.c +++ b/fs/bcachefs/reflink.c @@ -251,13 +251,9 @@ static struct bkey_s_c get_next_src(struct btree_iter *iter, struct bpos end) struct bkey_s_c k; int ret; - for_each_btree_key_continue_norestart(*iter, 0, k, ret) { - if (bkey_ge(iter->pos, end)) - break; - + for_each_btree_key_upto_continue_norestart(*iter, end, 0, k, ret) if (bkey_extent_is_data(k.k)) return k; - } if (bkey_ge(iter->pos, end)) bch2_btree_iter_set_pos(iter, end); -- cgit v1.2.3