summaryrefslogtreecommitdiff
path: root/fs/bcachefs/btree_iter.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2021-02-07 18:52:13 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:08:53 -0400
commit2b2c1a89cef6d19fc5a0995e550a67b1701d8bed (patch)
tree81e1ee37ca99e2ece90cd0076db060898ae8c549 /fs/bcachefs/btree_iter.c
parenteaf798317aa8fe3c8417ae1414c0b0bc58748881 (diff)
downloadlwn-2b2c1a89cef6d19fc5a0995e550a67b1701d8bed.tar.gz
lwn-2b2c1a89cef6d19fc5a0995e550a67b1701d8bed.zip
bcachefs: Simplify btree_iter_(next|prev)_leaf()
There's no good reason for these functions to not be using bch2_btree_iter_set_pos(). Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/btree_iter.c')
-rw-r--r--fs/bcachefs/btree_iter.c27
1 files changed, 9 insertions, 18 deletions
diff --git a/fs/bcachefs/btree_iter.c b/fs/bcachefs/btree_iter.c
index 196f346f0544..431b1e8bebc7 100644
--- a/fs/bcachefs/btree_iter.c
+++ b/fs/bcachefs/btree_iter.c
@@ -1554,38 +1554,29 @@ void bch2_btree_iter_set_pos(struct btree_iter *iter, struct bpos new_pos)
static inline bool btree_iter_set_pos_to_next_leaf(struct btree_iter *iter)
{
- struct btree_iter_level *l = &iter->l[0];
- bool ret;
-
- bkey_init(&iter->k);
- iter->k.p = iter->pos = l->b->key.k.p;
+ struct bpos next_pos = iter->l[0].b->key.k.p;
+ bool ret = bkey_cmp(next_pos, POS_MAX) != 0;
- ret = bkey_cmp(iter->pos, POS_MAX) != 0;
if (ret && !(iter->flags & BTREE_ITER_IS_EXTENTS))
- iter->k.p = iter->pos = bkey_successor(iter->pos);
+ next_pos = bkey_successor(next_pos);
- btree_iter_pos_changed(iter, 1);
+ bch2_btree_iter_set_pos(iter, next_pos);
return ret;
}
static inline bool btree_iter_set_pos_to_prev_leaf(struct btree_iter *iter)
{
- struct btree_iter_level *l = &iter->l[0];
- bool ret;
-
- bkey_init(&iter->k);
- iter->k.p = iter->pos = l->b->data->min_key;
- iter->uptodate = BTREE_ITER_NEED_TRAVERSE;
+ struct bpos next_pos = iter->l[0].b->data->min_key;
+ bool ret = bkey_cmp(next_pos, POS_MIN) != 0;
- ret = bkey_cmp(iter->pos, POS_MIN) != 0;
if (ret) {
- iter->k.p = iter->pos = bkey_predecessor(iter->pos);
+ next_pos = bkey_predecessor(next_pos);
if (iter->flags & BTREE_ITER_IS_EXTENTS)
- iter->k.p = iter->pos = bkey_predecessor(iter->pos);
+ next_pos = bkey_predecessor(next_pos);
}
- btree_iter_pos_changed(iter, -1);
+ bch2_btree_iter_set_pos(iter, next_pos);
return ret;
}