bcachefs: Key cache now works for snapshots btrees

This switches btree_key_cache_fill() to use a btree iterator, not a
btree path, so that it can search for keys in previous snapshots.

We also add another iterator flag, BTREE_ITER_KEY_CACHE_FILL, to avoid
recursion back into the key cache.

This will allow us to re-enable the key cache for inodes in the next
patch.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2022-11-22 20:15:33 -05:00
parent 087e53c255
commit 1617d56dc9
4 changed files with 15 additions and 10 deletions

View file

@ -1855,6 +1855,10 @@ struct bkey_s_c btree_trans_peek_key_cache(struct btree_iter *iter, struct bpos
struct bkey_s_c k;
int ret;
if ((iter->flags & BTREE_ITER_KEY_CACHE_FILL) &&
bpos_eq(iter->pos, pos))
return bkey_s_c_null;
if (!bch2_btree_key_cache_find(c, iter->btree_id, pos))
return bkey_s_c_null;

View file

@ -370,20 +370,20 @@ static int btree_key_cache_fill(struct btree_trans *trans,
struct btree_path *ck_path,
struct bkey_cached *ck)
{
struct btree_path *path;
struct btree_iter iter;
struct bkey_s_c k;
unsigned new_u64s = 0;
struct bkey_i *new_k = NULL;
struct bkey u;
int ret;
path = bch2_path_get(trans, ck->key.btree_id, ck->key.pos, 0, 0, 0);
ret = bch2_btree_path_traverse(trans, path, 0);
bch2_trans_iter_init(trans, &iter, ck->key.btree_id, ck->key.pos,
BTREE_ITER_KEY_CACHE_FILL|
BTREE_ITER_CACHED_NOFILL);
k = bch2_btree_iter_peek_slot(&iter);
ret = bkey_err(k);
if (ret)
goto err;
k = bch2_btree_path_peek_slot(path, &u);
if (!bch2_btree_node_relock(trans, ck_path, 0)) {
trace_and_count(trans->c, trans_restart_relock_key_cache_fill, trans, _THIS_IP_, ck_path);
ret = btree_trans_restart(trans, BCH_ERR_transaction_restart_key_cache_raced);
@ -431,9 +431,9 @@ static int btree_key_cache_fill(struct btree_trans *trans,
bch2_btree_node_unlock_write(trans, ck_path, ck_path->l[0].b);
/* We're not likely to need this iterator again: */
path->preserve = false;
set_btree_iter_dontneed(&iter);
err:
bch2_path_put(trans, path, 0);
bch2_trans_iter_exit(trans, &iter);
return ret;
}

View file

@ -208,6 +208,7 @@ struct btree_node_iter {
#define BTREE_ITER_FILTER_SNAPSHOTS (1 << 12)
#define BTREE_ITER_NOPRESERVE (1 << 13)
#define BTREE_ITER_CACHED_NOFILL (1 << 14)
#define BTREE_ITER_KEY_CACHE_FILL (1 << 15)
enum btree_path_uptodate {
BTREE_ITER_UPTODATE = 0,

View file

@ -684,8 +684,8 @@ int bch2_inode_rm(struct bch_fs *c, subvol_inum inum)
if (!bkey_is_inode(k.k)) {
bch2_fs_inconsistent(trans.c,
"inode %llu not found when deleting",
inum.inum);
"inode %llu:%u not found when deleting",
inum.inum, snapshot);
ret = -EIO;
goto err;
}