]> www.infradead.org Git - linux.git/commitdiff
bcachefs: Flush journal immediately after replay if we did early repair
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 28 Mar 2024 06:36:10 +0000 (02:36 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Mon, 1 Apr 2024 00:36:12 +0000 (20:36 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/recovery.c

index f9e2b011f6d4fbcb567746568ac65db7047575a9..dbedb5fd1dde540ae3a51990ab9bb32b1b7e9256 100644 (file)
@@ -189,6 +189,7 @@ int bch2_journal_replay(struct bch_fs *c)
        u64 start_seq   = c->journal_replay_seq_start;
        u64 end_seq     = c->journal_replay_seq_start;
        struct btree_trans *trans = bch2_trans_get(c);
+       bool immediate_flush = false;
        int ret = 0;
 
        if (keys->nr) {
@@ -210,6 +211,13 @@ int bch2_journal_replay(struct bch_fs *c)
        darray_for_each(*keys, k) {
                cond_resched();
 
+               /*
+                * k->allocated means the key wasn't read in from the journal,
+                * rather it was from early repair code
+                */
+               if (k->allocated)
+                       immediate_flush = true;
+
                /* Skip fastpath if we're low on space in the journal */
                ret = c->journal.watermark ? -1 :
                        commit_do(trans, NULL, NULL,
@@ -269,6 +277,12 @@ int bch2_journal_replay(struct bch_fs *c)
 
        bch2_journal_set_replay_done(j);
 
+       /* if we did any repair, flush it immediately */
+       if (immediate_flush) {
+               bch2_journal_flush_all_pins(&c->journal);
+               ret = bch2_journal_meta(&c->journal);
+       }
+
        if (keys->nr)
                bch2_journal_log_msg(c, "journal replay finished");
 err:
@@ -778,6 +792,12 @@ use_clean:
 
        clear_bit(BCH_FS_fsck_running, &c->flags);
 
+       /* fsync if we fixed errors */
+       if (test_bit(BCH_FS_errors_fixed, &c->flags)) {
+               bch2_journal_flush_all_pins(&c->journal);
+               bch2_journal_meta(&c->journal);
+       }
+
        /* If we fixed errors, verify that fs is actually clean now: */
        if (IS_ENABLED(CONFIG_BCACHEFS_DEBUG) &&
            test_bit(BCH_FS_errors_fixed, &c->flags) &&