bcachefs: New assertion for writing to the journal after shutdown
authorKent Overstreet <kent.overstreet@linux.dev>
Wed, 21 Feb 2024 02:17:15 +0000 (21:17 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Wed, 8 May 2024 21:29:18 +0000 (17:29 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_update.c
fs/bcachefs/journal.c
fs/bcachefs/journal.h
fs/bcachefs/journal_reclaim.c
fs/bcachefs/journal_types.h
fs/bcachefs/super.c

index 8e47e260eba59b09097fd07b1d9063a0e665a812..c46ee4c813ae21613109a89794f291b2fc325396 100644 (file)
@@ -852,7 +852,7 @@ __bch2_fs_log_msg(struct bch_fs *c, unsigned commit_flags, const char *fmt,
        if (ret)
                goto err;
 
-       if (!test_bit(JOURNAL_STARTED, &c->journal.flags)) {
+       if (!test_bit(JOURNAL_RUNNING, &c->journal.flags)) {
                ret = darray_make_room(&c->journal.early_journal_entries, jset_u64s(u64s));
                if (ret)
                        goto err;
index c40b5c40d63ffe4327a4b817bdfd90be5df4ed84..d302d8e8367800c40b1b59e1254031487e5a4308 100644 (file)
@@ -1177,12 +1177,14 @@ void bch2_fs_journal_stop(struct journal *j)
        bch2_journal_meta(j);
 
        journal_quiesce(j);
+       cancel_delayed_work_sync(&j->write_work);
 
        BUG_ON(!bch2_journal_error(j) &&
               test_bit(JOURNAL_REPLAY_DONE, &j->flags) &&
               j->last_empty_seq != journal_cur_seq(j));
 
-       cancel_delayed_work_sync(&j->write_work);
+       if (!bch2_journal_error(j))
+               clear_bit(JOURNAL_RUNNING, &j->flags);
 }
 
 int bch2_fs_journal_start(struct journal *j, u64 cur_seq)
@@ -1256,7 +1258,7 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq)
 
        spin_lock(&j->lock);
 
-       set_bit(JOURNAL_STARTED, &j->flags);
+       set_bit(JOURNAL_RUNNING, &j->flags);
        j->last_flush_write = jiffies;
 
        j->reservations.idx = j->reservations.unwritten_idx = journal_cur_seq(j);
index 7c7528f839c567f5d1398cbdf890a5433818253d..4b8c709bc317bddbf709db2dc668afad08133a99 100644 (file)
@@ -372,7 +372,7 @@ static inline int bch2_journal_res_get(struct journal *j, struct journal_res *re
        int ret;
 
        EBUG_ON(res->ref);
-       EBUG_ON(!test_bit(JOURNAL_STARTED, &j->flags));
+       EBUG_ON(!test_bit(JOURNAL_RUNNING, &j->flags));
 
        res->u64s = u64s;
 
@@ -418,7 +418,7 @@ struct bch_dev;
 
 static inline void bch2_journal_set_replay_done(struct journal *j)
 {
-       BUG_ON(!test_bit(JOURNAL_STARTED, &j->flags));
+       BUG_ON(!test_bit(JOURNAL_RUNNING, &j->flags));
        set_bit(JOURNAL_REPLAY_DONE, &j->flags);
 }
 
index 04a577848b015cd900a1a040ec0565ffb2f69811..a0c9f7ac611df42cf8a89209a7ab8ea1544a096a 100644 (file)
@@ -833,7 +833,7 @@ bool bch2_journal_flush_pins(struct journal *j, u64 seq_to_flush)
        /* time_stats this */
        bool did_work = false;
 
-       if (!test_bit(JOURNAL_STARTED, &j->flags))
+       if (!test_bit(JOURNAL_RUNNING, &j->flags))
                return false;
 
        closure_wait_event(&j->async_wait,
index b5161b5d76a00874ed9ed88a0969927f2cfc9dbe..08debe6bfeeff47a92f7a64d612c5bed91a1c404 100644 (file)
@@ -131,7 +131,7 @@ enum journal_space_from {
 
 enum journal_flags {
        JOURNAL_REPLAY_DONE,
-       JOURNAL_STARTED,
+       JOURNAL_RUNNING,
        JOURNAL_MAY_SKIP_FLUSH,
        JOURNAL_NEED_FLUSH_WRITE,
        JOURNAL_SPACE_LOW,
index dddf57ec4511f3562592bce4c5c59988c9eed352..ca2f3debd7fd6037b3f79e8ef01d8f8b77a2011f 100644 (file)
@@ -468,6 +468,7 @@ static int __bch2_fs_read_write(struct bch_fs *c, bool early)
         * at least one non-flush write in the journal or recovery will fail:
         */
        set_bit(JOURNAL_NEED_FLUSH_WRITE, &c->journal.flags);
+       set_bit(JOURNAL_RUNNING, &c->journal.flags);
 
        for_each_rw_member(c, ca)
                bch2_dev_allocator_add(c, ca);