From 8511632d44a5846f8edc387e90858ae208715574 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Mon, 20 Dec 2021 16:55:49 -0500 Subject: [PATCH] bcachefs: Journal initialization fixes This fixes a rare bug when mounting & unmounting RO - flushing a clean filesystem that never went RO should be a no op. Signed-off-by: Kent Overstreet --- fs/bcachefs/journal.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/bcachefs/journal.c b/fs/bcachefs/journal.c index d27d65a17e43..7c5ce5b47493 100644 --- a/fs/bcachefs/journal.c +++ b/fs/bcachefs/journal.c @@ -989,10 +989,14 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq, j->replay_journal_seq = last_seq; j->replay_journal_seq_end = cur_seq; j->last_seq_ondisk = last_seq; + j->flushed_seq_ondisk = cur_seq - 1; j->pin.front = last_seq; j->pin.back = cur_seq; atomic64_set(&j->seq, cur_seq - 1); + if (list_empty(journal_entries)) + j->last_empty_seq = cur_seq - 1; + fifo_for_each_entry_ptr(p, &j->pin, seq) journal_pin_list_init(p, 1); @@ -1005,6 +1009,9 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq, if (seq < last_seq) continue; + if (journal_entry_empty(&i->j)) + j->last_empty_seq = le64_to_cpu(i->j.seq); + p = journal_seq_pin(j, seq); p->devs.nr = 0; @@ -1012,6 +1019,9 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq, bch2_dev_list_add_dev(&p->devs, i->ptrs[ptr].dev); } + if (list_empty(journal_entries)) + j->last_empty_seq = cur_seq; + spin_lock(&j->lock); set_bit(JOURNAL_STARTED, &j->flags);