bcachefs: pass last_seq into fs_journal_start()
authorKent Overstreet <kent.overstreet@linux.dev>
Fri, 13 Jun 2025 19:15:09 +0000 (15:15 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Mon, 16 Jun 2025 02:11:56 +0000 (22:11 -0400)
Prep work for journal rewind, where the seq we're replaying from may be
different than the last journal entry's last_seq.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/journal.c
fs/bcachefs/journal.h
fs/bcachefs/recovery.c

index dda802a656cf5434daf80bbb60b9cba0750f57e9..df71af0013ba2835071234dd5a9b53d8390e13c2 100644 (file)
@@ -1474,14 +1474,13 @@ void bch2_fs_journal_stop(struct journal *j)
                clear_bit(JOURNAL_running, &j->flags);
 }
 
-int bch2_fs_journal_start(struct journal *j, u64 cur_seq)
+int bch2_fs_journal_start(struct journal *j, u64 last_seq, u64 cur_seq)
 {
        struct bch_fs *c = container_of(j, struct bch_fs, journal);
        struct journal_entry_pin_list *p;
        struct journal_replay *i, **_i;
        struct genradix_iter iter;
        bool had_entries = false;
-       u64 last_seq = cur_seq, nr, seq;
 
        /*
         *
@@ -1495,17 +1494,11 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq)
                return -EINVAL;
        }
 
-       genradix_for_each_reverse(&c->journal_entries, iter, _i) {
-               i = *_i;
-
-               if (journal_replay_ignore(i))
-                       continue;
+       /* Clean filesystem? */
+       if (!last_seq)
+               last_seq = cur_seq;
 
-               last_seq = le64_to_cpu(i->j.last_seq);
-               break;
-       }
-
-       nr = cur_seq - last_seq;
+       u64 nr = cur_seq - last_seq;
 
        /*
         * Extra fudge factor, in case we crashed when the journal pin fifo was
@@ -1532,6 +1525,7 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq)
        j->pin.back             = cur_seq;
        atomic64_set(&j->seq, cur_seq - 1);
 
+       u64 seq;
        fifo_for_each_entry_ptr(p, &j->pin, seq)
                journal_pin_list_init(p, 1);
 
index 83734fe4331feca9358089b8d709543bafef5ce2..977907038d98d0f2709e5d35952b4e79019e2644 100644 (file)
@@ -453,7 +453,7 @@ int bch2_fs_journal_alloc(struct bch_fs *);
 void bch2_dev_journal_stop(struct journal *, struct bch_dev *);
 
 void bch2_fs_journal_stop(struct journal *);
-int bch2_fs_journal_start(struct journal *, u64);
+int bch2_fs_journal_start(struct journal *, u64, u64);
 void bch2_journal_set_replay_done(struct journal *);
 
 void bch2_dev_journal_exit(struct bch_dev *);
index 0b21fa6ff062bacf24f6834b323b4614c95cd9d7..6aef8b1018209c7e618e44d62a0a9e5cf1c302b1 100644 (file)
@@ -965,7 +965,7 @@ use_clean:
 
        ret =   bch2_journal_log_msg(c, "starting journal at entry %llu, replaying %llu-%llu",
                                     journal_seq, last_seq, blacklist_seq - 1) ?:
-               bch2_fs_journal_start(&c->journal, journal_seq);
+               bch2_fs_journal_start(&c->journal, last_seq, journal_seq);
        if (ret)
                goto err;
 
@@ -1181,7 +1181,7 @@ int bch2_fs_initialize(struct bch_fs *c)
         * journal_res_get() will crash if called before this has
         * set up the journal.pin FIFO and journal.cur pointer:
         */
-       ret = bch2_fs_journal_start(&c->journal, 1);
+       ret = bch2_fs_journal_start(&c->journal, 1, 1);
        if (ret)
                goto err;