bcachefs: Kill bch2_btree_iter_peek_cached()

It's now been rolled into bch2_btree_iter_peek_slot()

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
This commit is contained in:
Kent Overstreet 2021-06-10 20:15:50 -04:00 committed by Kent Overstreet
parent 45c2e33f79
commit 953ee28a3e
4 changed files with 42 additions and 66 deletions

View File

@ -1824,35 +1824,54 @@ struct bkey_s_c bch2_btree_iter_prev(struct btree_iter *iter)
struct bkey_s_c bch2_btree_iter_peek_slot(struct btree_iter *iter) struct bkey_s_c bch2_btree_iter_peek_slot(struct btree_iter *iter)
{ {
struct bpos search_key = btree_iter_search_key(iter); struct bpos search_key;
struct bkey_s_c k; struct bkey_s_c k;
int ret; int ret;
EBUG_ON(btree_iter_type(iter) != BTREE_ITER_KEYS); EBUG_ON(btree_iter_type(iter) != BTREE_ITER_KEYS &&
btree_iter_type(iter) != BTREE_ITER_CACHED);
bch2_btree_iter_verify(iter); bch2_btree_iter_verify(iter);
bch2_btree_iter_verify_entry_exit(iter); bch2_btree_iter_verify_entry_exit(iter);
btree_iter_set_search_pos(iter, search_key);
/* extents can't span inode numbers: */ /* extents can't span inode numbers: */
if ((iter->flags & BTREE_ITER_IS_EXTENTS) && if ((iter->flags & BTREE_ITER_IS_EXTENTS) &&
iter->pos.offset == KEY_OFFSET_MAX) { unlikely(iter->pos.offset == KEY_OFFSET_MAX)) {
if (iter->pos.inode == KEY_INODE_MAX) if (iter->pos.inode == KEY_INODE_MAX)
return bkey_s_c_null; return bkey_s_c_null;
bch2_btree_iter_set_pos(iter, bpos_nosnap_successor(iter->pos)); bch2_btree_iter_set_pos(iter, bpos_nosnap_successor(iter->pos));
} }
search_key = btree_iter_search_key(iter);
btree_iter_set_search_pos(iter, search_key);
ret = btree_iter_traverse(iter); ret = btree_iter_traverse(iter);
if (unlikely(ret)) if (unlikely(ret))
return bkey_s_c_err(ret); return bkey_s_c_err(ret);
if (!(iter->flags & BTREE_ITER_IS_EXTENTS)) { if (btree_iter_type(iter) == BTREE_ITER_CACHED ||
struct bkey_i *next_update = btree_trans_peek_updates(iter, search_key); !(iter->flags & BTREE_ITER_IS_EXTENTS)) {
struct bkey_i *next_update;
struct bkey_cached *ck;
k = btree_iter_level_peek_all(iter, &iter->l[0]); switch (btree_iter_type(iter)) {
EBUG_ON(k.k && bkey_deleted(k.k) && bkey_cmp(k.k->p, iter->pos) == 0); case BTREE_ITER_KEYS:
k = btree_iter_level_peek_all(iter, &iter->l[0]);
EBUG_ON(k.k && bkey_deleted(k.k) && bkey_cmp(k.k->p, iter->pos) == 0);
break;
case BTREE_ITER_CACHED:
ck = (void *) iter->l[0].b;
EBUG_ON(iter->btree_id != ck->key.btree_id ||
bkey_cmp(iter->pos, ck->key.pos));
BUG_ON(!ck->valid);
k = bkey_i_to_s_c(ck->k);
break;
case BTREE_ITER_NODES:
BUG();
}
next_update = btree_trans_peek_updates(iter, search_key);
if (next_update && if (next_update &&
(!k.k || bpos_cmp(next_update->k.p, k.k->p) <= 0)) { (!k.k || bpos_cmp(next_update->k.p, k.k->p) <= 0)) {
iter->k = next_update->k; iter->k = next_update->k;
@ -1929,34 +1948,6 @@ struct bkey_s_c bch2_btree_iter_prev_slot(struct btree_iter *iter)
return bch2_btree_iter_peek_slot(iter); return bch2_btree_iter_peek_slot(iter);
} }
struct bkey_s_c bch2_btree_iter_peek_cached(struct btree_iter *iter)
{
struct bkey_i *next_update;
struct bkey_cached *ck;
int ret;
EBUG_ON(btree_iter_type(iter) != BTREE_ITER_CACHED);
bch2_btree_iter_verify(iter);
next_update = btree_trans_peek_updates(iter, iter->pos);
if (next_update && !bpos_cmp(next_update->k.p, iter->pos))
return bkey_i_to_s_c(next_update);
ret = btree_iter_traverse(iter);
if (unlikely(ret))
return bkey_s_c_err(ret);
ck = (void *) iter->l[0].b;
EBUG_ON(iter->btree_id != ck->key.btree_id ||
bkey_cmp(iter->pos, ck->key.pos));
BUG_ON(!ck->valid);
iter->should_be_locked = true;
return bkey_i_to_s_c(ck->k);
}
static inline void bch2_btree_iter_init(struct btree_trans *trans, static inline void bch2_btree_iter_init(struct btree_trans *trans,
struct btree_iter *iter, enum btree_id btree_id) struct btree_iter *iter, enum btree_id btree_id)
{ {

View File

@ -160,8 +160,6 @@ struct bkey_s_c bch2_btree_iter_peek_slot(struct btree_iter *);
struct bkey_s_c bch2_btree_iter_next_slot(struct btree_iter *); struct bkey_s_c bch2_btree_iter_next_slot(struct btree_iter *);
struct bkey_s_c bch2_btree_iter_prev_slot(struct btree_iter *); struct bkey_s_c bch2_btree_iter_prev_slot(struct btree_iter *);
struct bkey_s_c bch2_btree_iter_peek_cached(struct btree_iter *);
bool bch2_btree_iter_advance(struct btree_iter *); bool bch2_btree_iter_advance(struct btree_iter *);
bool bch2_btree_iter_rewind(struct btree_iter *); bool bch2_btree_iter_rewind(struct btree_iter *);
@ -224,12 +222,9 @@ static inline int bch2_trans_cond_resched(struct btree_trans *trans)
static inline struct bkey_s_c __bch2_btree_iter_peek(struct btree_iter *iter, static inline struct bkey_s_c __bch2_btree_iter_peek(struct btree_iter *iter,
unsigned flags) unsigned flags)
{ {
if ((flags & BTREE_ITER_TYPE) == BTREE_ITER_CACHED) return flags & BTREE_ITER_SLOTS
return bch2_btree_iter_peek_cached(iter); ? bch2_btree_iter_peek_slot(iter)
else : bch2_btree_iter_peek(iter);
return flags & BTREE_ITER_SLOTS
? bch2_btree_iter_peek_slot(iter)
: bch2_btree_iter_peek(iter);
} }
static inline struct bkey_s_c __bch2_btree_iter_next(struct btree_iter *iter, static inline struct bkey_s_c __bch2_btree_iter_next(struct btree_iter *iter,

View File

@ -1917,17 +1917,10 @@ int bch2_trans_mark_update(struct btree_trans *trans,
if (!btree_node_type_needs_gc(iter->btree_id)) if (!btree_node_type_needs_gc(iter->btree_id))
return 0; return 0;
if (btree_iter_type(iter) != BTREE_ITER_CACHED) { old = bch2_btree_iter_peek_slot(iter);
old = bch2_btree_iter_peek_slot(iter); ret = bkey_err(old);
ret = bkey_err(old); if (ret)
if (ret) return ret;
return ret;
} else {
struct bkey_cached *ck = (void *) iter->l[0].b;
BUG_ON(!ck->valid);
old = bkey_i_to_s_c(ck->k);
}
if (old.k->type == new->k.type && if (old.k->type == new->k.type &&
!btree_node_type_is_extents(iter->btree_id)) { !btree_node_type_is_extents(iter->btree_id)) {

View File

@ -302,7 +302,7 @@ struct btree_iter *bch2_inode_peek(struct btree_trans *trans,
iter = bch2_trans_get_iter(trans, BTREE_ID_inodes, POS(0, inum), iter = bch2_trans_get_iter(trans, BTREE_ID_inodes, POS(0, inum),
BTREE_ITER_CACHED|flags); BTREE_ITER_CACHED|flags);
k = bch2_btree_iter_peek_cached(iter); k = bch2_btree_iter_peek_slot(iter);
ret = bkey_err(k); ret = bkey_err(k);
if (ret) if (ret)
goto err; goto err;
@ -600,15 +600,12 @@ int bch2_inode_rm(struct bch_fs *c, u64 inode_nr, bool cached)
retry: retry:
bch2_trans_begin(&trans); bch2_trans_begin(&trans);
if (cached) { iter = bch2_trans_get_iter(&trans, BTREE_ID_inodes, POS(0, inode_nr),
iter = bch2_trans_get_iter(&trans, BTREE_ID_inodes, POS(0, inode_nr), (cached
BTREE_ITER_CACHED|BTREE_ITER_INTENT); ? BTREE_ITER_CACHED
k = bch2_btree_iter_peek_cached(iter); : BTREE_ITER_SLOTS)|
} else { BTREE_ITER_INTENT);
iter = bch2_trans_get_iter(&trans, BTREE_ID_inodes, POS(0, inode_nr), k = bch2_btree_iter_peek_slot(iter);
BTREE_ITER_SLOTS|BTREE_ITER_INTENT);
k = bch2_btree_iter_peek_slot(iter);
}
ret = bkey_err(k); ret = bkey_err(k);
if (ret) if (ret)