Skip to content

Commit 4fe0eee

Browse files
author
Kent Overstreet
committed
bcachefs: Flush journal immediately after replay if we did early repair
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent af855a5 commit 4fe0eee

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

fs/bcachefs/recovery.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ int bch2_journal_replay(struct bch_fs *c)
189189
u64 start_seq = c->journal_replay_seq_start;
190190
u64 end_seq = c->journal_replay_seq_start;
191191
struct btree_trans *trans = bch2_trans_get(c);
192+
bool immediate_flush = false;
192193
int ret = 0;
193194

194195
if (keys->nr) {
@@ -210,6 +211,13 @@ int bch2_journal_replay(struct bch_fs *c)
210211
darray_for_each(*keys, k) {
211212
cond_resched();
212213

214+
/*
215+
* k->allocated means the key wasn't read in from the journal,
216+
* rather it was from early repair code
217+
*/
218+
if (k->allocated)
219+
immediate_flush = true;
220+
213221
/* Skip fastpath if we're low on space in the journal */
214222
ret = c->journal.watermark ? -1 :
215223
commit_do(trans, NULL, NULL,
@@ -269,6 +277,12 @@ int bch2_journal_replay(struct bch_fs *c)
269277

270278
bch2_journal_set_replay_done(j);
271279

280+
/* if we did any repair, flush it immediately */
281+
if (immediate_flush) {
282+
bch2_journal_flush_all_pins(&c->journal);
283+
ret = bch2_journal_meta(&c->journal);
284+
}
285+
272286
if (keys->nr)
273287
bch2_journal_log_msg(c, "journal replay finished");
274288
err:
@@ -778,6 +792,12 @@ int bch2_fs_recovery(struct bch_fs *c)
778792

779793
clear_bit(BCH_FS_fsck_running, &c->flags);
780794

795+
/* fsync if we fixed errors */
796+
if (test_bit(BCH_FS_errors_fixed, &c->flags)) {
797+
bch2_journal_flush_all_pins(&c->journal);
798+
bch2_journal_meta(&c->journal);
799+
}
800+
781801
/* If we fixed errors, verify that fs is actually clean now: */
782802
if (IS_ENABLED(CONFIG_BCACHEFS_DEBUG) &&
783803
test_bit(BCH_FS_errors_fixed, &c->flags) &&

0 commit comments

Comments
 (0)