Skip to content

Commit 01bf5e3

Browse files
author
Kent Overstreet
committed
bcachefs: minor lru fsck fixes
check_lru_key() wasn't using write buffer updates for deleting bad lru entries - dating from before the lru btree used the btree write buffer. And when possibly flushing the btree write buffer (to make sure we're seeing a real inconsistency), we need to be using the modern bch2_btree_write_buffer_maybe_flush(). Signed-off-by: Kent Overstreet <[email protected]>
1 parent 1bea714 commit 01bf5e3

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

fs/bcachefs/lru.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "bcachefs.h"
44
#include "alloc_background.h"
5+
#include "bkey_buf.h"
56
#include "btree_iter.h"
67
#include "btree_update.h"
78
#include "btree_write_buffer.h"
@@ -118,7 +119,7 @@ int bch2_lru_check_set(struct btree_trans *trans,
118119
static int bch2_check_lru_key(struct btree_trans *trans,
119120
struct btree_iter *lru_iter,
120121
struct bkey_s_c lru_k,
121-
struct bpos *last_flushed_pos)
122+
struct bkey_buf *last_flushed)
122123
{
123124
struct bch_fs *c = trans->c;
124125
struct btree_iter iter;
@@ -136,7 +137,7 @@ static int bch2_check_lru_key(struct btree_trans *trans,
136137
trans, lru_entry_to_invalid_bucket,
137138
"lru key points to nonexistent device:bucket %llu:%llu",
138139
alloc_pos.inode, alloc_pos.offset))
139-
return bch2_btree_delete_at(trans, lru_iter, 0);
140+
return bch2_btree_bit_mod_buffered(trans, BTREE_ID_lru, lru_iter->pos, false);
140141

141142
k = bch2_bkey_get_iter(trans, &iter, BTREE_ID_alloc, alloc_pos, 0);
142143
ret = bkey_err(k);
@@ -156,12 +157,9 @@ static int bch2_check_lru_key(struct btree_trans *trans,
156157

157158
if (lru_k.k->type != KEY_TYPE_set ||
158159
lru_pos_time(lru_k.k->p) != idx) {
159-
if (!bpos_eq(*last_flushed_pos, lru_k.k->p)) {
160-
*last_flushed_pos = lru_k.k->p;
161-
ret = bch2_btree_write_buffer_flush_sync(trans) ?:
162-
-BCH_ERR_transaction_restart_write_buffer_flush;
163-
goto out;
164-
}
160+
ret = bch2_btree_write_buffer_maybe_flush(trans, lru_k, last_flushed);
161+
if (ret)
162+
goto err;
165163

166164
if (fsck_err(trans, lru_entry_bad,
167165
"incorrect lru entry: lru %s time %llu\n"
@@ -171,9 +169,8 @@ static int bch2_check_lru_key(struct btree_trans *trans,
171169
lru_pos_time(lru_k.k->p),
172170
(bch2_bkey_val_to_text(&buf1, c, lru_k), buf1.buf),
173171
(bch2_bkey_val_to_text(&buf2, c, k), buf2.buf)))
174-
ret = bch2_btree_delete_at(trans, lru_iter, 0);
172+
ret = bch2_btree_bit_mod_buffered(trans, BTREE_ID_lru, lru_iter->pos, false);
175173
}
176-
out:
177174
err:
178175
fsck_err:
179176
bch2_trans_iter_exit(trans, &iter);
@@ -184,12 +181,18 @@ static int bch2_check_lru_key(struct btree_trans *trans,
184181

185182
int bch2_check_lrus(struct bch_fs *c)
186183
{
187-
struct bpos last_flushed_pos = POS_MIN;
184+
struct bkey_buf last_flushed;
185+
186+
bch2_bkey_buf_init(&last_flushed);
187+
bkey_init(&last_flushed.k->k);
188+
188189
int ret = bch2_trans_run(c,
189190
for_each_btree_key_commit(trans, iter,
190191
BTREE_ID_lru, POS_MIN, BTREE_ITER_prefetch, k,
191192
NULL, NULL, BCH_TRANS_COMMIT_no_enospc|BCH_TRANS_COMMIT_lazy_rw,
192-
bch2_check_lru_key(trans, &iter, k, &last_flushed_pos)));
193+
bch2_check_lru_key(trans, &iter, k, &last_flushed)));
194+
195+
bch2_bkey_buf_exit(&last_flushed, c);
193196
bch_err_fn(c, ret);
194197
return ret;
195198

0 commit comments

Comments
 (0)