summaryrefslogtreecommitdiff
path: root/fs/bcachefs/lru.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2022-07-17 07:44:19 +0300
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-23 00:09:36 +0300
commit1615505cdf2c681c72ca7ab742c9a3fd39fccfe3 (patch)
treef50348debac6de03454e0cc46f7574a7094b6b36 /fs/bcachefs/lru.c
parentca91f40ff79f432772660b1d10e04cfc71214458 (diff)
downloadlinux-1615505cdf2c681c72ca7ab742c9a3fd39fccfe3.tar.xz
bcachefs: Convert bch2_check_lrus() to for_each_btree_key_commit()
The new for_each_btree_key2() macro handles transaction retries, allowing us to avoid nested transactions - which we want to avoid since they're tricky to do completely correctly and upcoming assertions are going to be checking for that. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Diffstat (limited to 'fs/bcachefs/lru.c')
-rw-r--r--fs/bcachefs/lru.c27
1 files changed, 7 insertions, 20 deletions
diff --git a/fs/bcachefs/lru.c b/fs/bcachefs/lru.c
index 94ecb3a39760..53e607d72274 100644
--- a/fs/bcachefs/lru.c
+++ b/fs/bcachefs/lru.c
@@ -130,25 +130,18 @@ int bch2_lru_change(struct btree_trans *trans, u64 id, u64 idx,
}
static int bch2_check_lru_key(struct btree_trans *trans,
- struct btree_iter *lru_iter)
+ struct btree_iter *lru_iter,
+ struct bkey_s_c lru_k)
{
struct bch_fs *c = trans->c;
struct btree_iter iter;
- struct bkey_s_c lru_k, k;
+ struct bkey_s_c k;
struct bch_alloc_v4 a;
struct printbuf buf1 = PRINTBUF;
struct printbuf buf2 = PRINTBUF;
struct bpos alloc_pos;
int ret;
- lru_k = bch2_btree_iter_peek(lru_iter);
- if (!lru_k.k)
- return 0;
-
- ret = bkey_err(lru_k);
- if (ret)
- return ret;
-
alloc_pos = POS(lru_k.k->p.inode,
le64_to_cpu(bkey_s_c_to_lru(lru_k).v->idx));
@@ -202,16 +195,10 @@ int bch2_check_lrus(struct bch_fs *c)
bch2_trans_init(&trans, c, 0, 0);
- for_each_btree_key(&trans, iter, BTREE_ID_lru, POS_MIN,
- BTREE_ITER_PREFETCH, k, ret) {
- ret = commit_do(&trans, NULL, NULL,
- BTREE_INSERT_NOFAIL|
- BTREE_INSERT_LAZY_RW,
- bch2_check_lru_key(&trans, &iter));
- if (ret)
- break;
- }
- bch2_trans_iter_exit(&trans, &iter);
+ ret = for_each_btree_key_commit(&trans, iter,
+ BTREE_ID_lru, POS_MIN, BTREE_ITER_PREFETCH, k,
+ NULL, NULL, BTREE_INSERT_NOFAIL|BTREE_INSERT_LAZY_RW,
+ bch2_check_lru_key(&trans, &iter, k));
bch2_trans_exit(&trans);
return ret;