bcachefs: Journal initialization fixes
authorKent Overstreet <kent.overstreet@gmail.com>
Mon, 20 Dec 2021 21:55:49 +0000 (16:55 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:19 +0000 (17:09 -0400)
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 <kent.overstreet@gmail.com>
fs/bcachefs/journal.c

index d27d65a..7c5ce5b 100644 (file)
@@ -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);