diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2023-12-17 00:57:37 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2024-01-01 11:47:44 -0500 |
commit | c558c577cbea95d8a8efc161cad93bab344a61d0 (patch) | |
tree | dc1aadc7080539565ba00a6d4ec6d62f4520b31a /fs | |
parent | 359e89add5b89fb467f08391ab9d80ba6e775295 (diff) | |
download | lwn-c558c577cbea95d8a8efc161cad93bab344a61d0.tar.gz lwn-c558c577cbea95d8a8efc161cad93bab344a61d0.zip |
bcachefs: bch2_btree_trans_peek_slot_updates
refactoring the BTREE_ITER_WITH_UPDATES code, prep for removing the flag
and making it always-on
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/bcachefs/btree_iter.c | 46 |
1 files changed, 15 insertions, 31 deletions
diff --git a/fs/bcachefs/btree_iter.c b/fs/bcachefs/btree_iter.c index a5a0c8e77930..d9a9e84a2a28 100644 --- a/fs/bcachefs/btree_iter.c +++ b/fs/bcachefs/btree_iter.c @@ -1921,32 +1921,16 @@ void bch2_btree_trans_peek_updates(struct btree_trans *trans, struct btree_iter } static noinline -struct bkey_i *__bch2_btree_trans_peek_updates(struct btree_iter *iter) -{ - struct btree_trans *trans = iter->trans; - struct bkey_i *ret = NULL; - - trans_for_each_update(trans, i) { - if (i->btree_id < iter->btree_id) - continue; - if (i->btree_id > iter->btree_id) - break; - if (bpos_lt(i->k->k.p, btree_iter_path(trans, iter)->pos)) - continue; - if (i->key_cache_already_flushed) - continue; - if (!ret || bpos_lt(i->k->k.p, ret->k.p)) - ret = i->k; - } - - return ret; -} - -static inline struct bkey_i *btree_trans_peek_updates(struct btree_iter *iter) +void bch2_btree_trans_peek_slot_updates(struct btree_trans *trans, struct btree_iter *iter, + struct bkey_s_c *k) { - return iter->flags & BTREE_ITER_WITH_UPDATES - ? __bch2_btree_trans_peek_updates(iter) - : NULL; + trans_for_each_update(trans, i) + if (!i->key_cache_already_flushed && + i->btree_id == iter->btree_id && + bpos_eq(i->k->k.p, iter->pos)) { + iter->k = i->k->k; + *k = bkey_i_to_s_c(i->k); + } } static struct bkey_i *bch2_btree_journal_peek(struct btree_trans *trans, @@ -2478,13 +2462,13 @@ struct bkey_s_c bch2_btree_iter_peek_slot(struct btree_iter *iter) if ((iter->flags & BTREE_ITER_CACHED) || !(iter->flags & (BTREE_ITER_IS_EXTENTS|BTREE_ITER_FILTER_SNAPSHOTS))) { - struct bkey_i *next_update; + k = bkey_s_c_null; - if ((next_update = btree_trans_peek_updates(iter)) && - bpos_eq(next_update->k.p, iter->pos)) { - iter->k = next_update->k; - k = bkey_i_to_s_c(next_update); - goto out; + if (unlikely((iter->flags & BTREE_ITER_WITH_UPDATES) && + trans->nr_updates)) { + bch2_btree_trans_peek_slot_updates(trans, iter, &k); + if (k.k) + goto out; } if (unlikely(iter->flags & BTREE_ITER_WITH_JOURNAL) && |