Commit 359e89ad authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: bch2_btree_trans_peek_prev_updates

bch2_btree_iter_peek_prev() now supports BTREE_ITER_WITH_UPDATES
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent eb686359
...@@ -1887,6 +1887,22 @@ inline bool bch2_btree_iter_rewind(struct btree_iter *iter) ...@@ -1887,6 +1887,22 @@ inline bool bch2_btree_iter_rewind(struct btree_iter *iter)
return ret; return ret;
} }
static noinline
void bch2_btree_trans_peek_prev_updates(struct btree_trans *trans, struct btree_iter *iter,
struct bkey_s_c *k)
{
struct bpos end = path_l(btree_iter_path(trans, iter))->b->data->min_key;
trans_for_each_update(trans, i)
if (!i->key_cache_already_flushed &&
i->btree_id == iter->btree_id &&
bpos_le(i->k->k.p, iter->pos) &&
bpos_ge(i->k->k.p, k->k ? k->k->p : end)) {
iter->k = i->k->k;
*k = bkey_i_to_s_c(i->k);
}
}
static noinline static noinline
void bch2_btree_trans_peek_updates(struct btree_trans *trans, struct btree_iter *iter, void bch2_btree_trans_peek_updates(struct btree_trans *trans, struct btree_iter *iter,
struct bkey_s_c *k) struct bkey_s_c *k)
...@@ -2302,7 +2318,6 @@ struct bkey_s_c bch2_btree_iter_peek_prev(struct btree_iter *iter) ...@@ -2302,7 +2318,6 @@ struct bkey_s_c bch2_btree_iter_peek_prev(struct btree_iter *iter)
EBUG_ON(btree_iter_path(trans, iter)->cached || EBUG_ON(btree_iter_path(trans, iter)->cached ||
btree_iter_path(trans, iter)->level); btree_iter_path(trans, iter)->level);
EBUG_ON(iter->flags & BTREE_ITER_WITH_UPDATES);
if (iter->flags & BTREE_ITER_WITH_JOURNAL) if (iter->flags & BTREE_ITER_WITH_JOURNAL)
return bkey_s_c_err(-EIO); return bkey_s_c_err(-EIO);
...@@ -2335,6 +2350,10 @@ struct bkey_s_c bch2_btree_iter_peek_prev(struct btree_iter *iter) ...@@ -2335,6 +2350,10 @@ struct bkey_s_c bch2_btree_iter_peek_prev(struct btree_iter *iter)
: bpos_gt(k.k->p, search_key))) : bpos_gt(k.k->p, search_key)))
k = btree_path_level_prev(trans, path, &path->l[0], &iter->k); k = btree_path_level_prev(trans, path, &path->l[0], &iter->k);
if (unlikely((iter->flags & BTREE_ITER_WITH_UPDATES) &&
trans->nr_updates))
bch2_btree_trans_peek_prev_updates(trans, iter, &k);
if (likely(k.k)) { if (likely(k.k)) {
if (iter->flags & BTREE_ITER_FILTER_SNAPSHOTS) { if (iter->flags & BTREE_ITER_FILTER_SNAPSHOTS) {
if (k.k->p.snapshot == iter->snapshot) if (k.k->p.snapshot == iter->snapshot)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment