bcachefs: x-macroize journal flags enums
authorKent Overstreet <kent.overstreet@linux.dev>
Tue, 30 Apr 2024 10:20:37 +0000 (06:20 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Wed, 8 May 2024 21:29:22 +0000 (17:29 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_iter.c
fs/bcachefs/btree_key_cache.c
fs/bcachefs/btree_trans_commit.c
fs/bcachefs/btree_update.c
fs/bcachefs/btree_update_interior.c
fs/bcachefs/journal.c
fs/bcachefs/journal.h
fs/bcachefs/journal_io.c
fs/bcachefs/journal_reclaim.c
fs/bcachefs/journal_types.h
fs/bcachefs/super.c

index 7f0eb5d396a234f7f968e35295f134123c744d48..5bf98cb8b15da6ba885158e7ea90bc7d0f47801e 100644 (file)
@@ -3170,7 +3170,7 @@ got_trans:
        trans->locking_wait.task = current;
        trans->locked           = true;
        trans->journal_replay_not_finished =
-               unlikely(!test_bit(JOURNAL_REPLAY_DONE, &c->journal.flags)) &&
+               unlikely(!test_bit(JOURNAL_replay_done, &c->journal.flags)) &&
                atomic_inc_not_zero(&c->journal_keys.ref);
        trans->nr_paths         = ARRAY_SIZE(trans->_paths);
        trans->paths_allocated  = trans->_paths_allocated;
index 69e5f08db374cc80b4dc31d3039cfd2922362d3a..75f5e6fe46349f0ed0a2d3b3b4611883d69b6700 100644 (file)
@@ -648,7 +648,7 @@ static int btree_key_cache_flush_pos(struct btree_trans *trans,
                commit_flags |= BCH_WATERMARK_reclaim;
 
        if (ck->journal.seq != journal_last_seq(j) ||
-           !test_bit(JOURNAL_SPACE_LOW, &c->journal.flags))
+           !test_bit(JOURNAL_space_low, &c->journal.flags))
                commit_flags |= BCH_TRANS_COMMIT_no_journal_res;
 
        ret   = bch2_btree_iter_traverse(&b_iter) ?:
index 0bf7c70da4175ab1a36a82dd3f08ca2723df79d6..a219a87e9ef07928f30ae636271172f37a7931cf 100644 (file)
@@ -337,7 +337,7 @@ static inline void btree_insert_entry_checks(struct btree_trans *trans,
        EBUG_ON(!i->level &&
                btree_type_has_snapshots(i->btree_id) &&
                !(i->flags & BTREE_UPDATE_internal_snapshot_node) &&
-               test_bit(JOURNAL_REPLAY_DONE, &trans->c->journal.flags) &&
+               test_bit(JOURNAL_replay_done, &trans->c->journal.flags) &&
                i->k->k.p.snapshot &&
                bch2_snapshot_is_internal_node(trans->c, i->k->k.p.snapshot) > 0);
 }
index ee10c1f845b80a29d57ef530f030e5919f6da54a..f3c645a43dcbaee9a65814d43663077d9660e04f 100644 (file)
@@ -849,7 +849,7 @@ __bch2_fs_log_msg(struct bch_fs *c, unsigned commit_flags, const char *fmt,
        if (ret)
                goto err;
 
-       if (!test_bit(JOURNAL_RUNNING, &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 1febab152bfadff83d9980bd7a83f1d441c4cf74..2e8b092a18206497f0cdbe6a2de438c33339633f 100644 (file)
@@ -1157,12 +1157,12 @@ bch2_btree_update_start(struct btree_trans *trans, struct btree_path *path,
        flags |= watermark;
 
        if (watermark < BCH_WATERMARK_reclaim &&
-           test_bit(JOURNAL_SPACE_LOW, &c->journal.flags)) {
+           test_bit(JOURNAL_space_low, &c->journal.flags)) {
                if (flags & BCH_TRANS_COMMIT_journal_reclaim)
                        return ERR_PTR(-BCH_ERR_journal_reclaim_would_deadlock);
 
                ret = drop_locks_do(trans,
-                       ({ wait_event(c->journal.wait, !test_bit(JOURNAL_SPACE_LOW, &c->journal.flags)); 0; }));
+                       ({ wait_event(c->journal.wait, !test_bit(JOURNAL_space_low, &c->journal.flags)); 0; }));
                if (ret)
                        return ERR_PTR(ret);
        }
@@ -1362,7 +1362,7 @@ static void bch2_insert_fixup_btree_ptr(struct btree_update *as,
        BUG_ON(insert->k.type == KEY_TYPE_btree_ptr_v2 &&
               !btree_ptr_sectors_written(insert));
 
-       if (unlikely(!test_bit(JOURNAL_REPLAY_DONE, &c->journal.flags)))
+       if (unlikely(!test_bit(JOURNAL_replay_done, &c->journal.flags)))
                bch2_journal_key_overwritten(c, b->c.btree_id, b->c.level, insert->k.p);
 
        if (bch2_bkey_invalid(c, bkey_i_to_s_c(insert),
index 4d03a77f1e837790a3d739d497e3e06063f6a663..c984cdc2795d38be07a9e0ac4a52401bb1df9848 100644 (file)
@@ -1182,11 +1182,11 @@ void bch2_fs_journal_stop(struct journal *j)
        cancel_delayed_work_sync(&j->write_work);
 
        BUG_ON(!bch2_journal_error(j) &&
-              test_bit(JOURNAL_REPLAY_DONE, &j->flags) &&
+              test_bit(JOURNAL_replay_done, &j->flags) &&
               j->last_empty_seq != journal_cur_seq(j));
 
        if (!bch2_journal_error(j))
-               clear_bit(JOURNAL_RUNNING, &j->flags);
+               clear_bit(JOURNAL_running, &j->flags);
 }
 
 int bch2_fs_journal_start(struct journal *j, u64 cur_seq)
@@ -1260,7 +1260,7 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq)
 
        spin_lock(&j->lock);
 
-       set_bit(JOURNAL_RUNNING, &j->flags);
+       set_bit(JOURNAL_running, &j->flags);
        j->last_flush_write = jiffies;
 
        j->reservations.idx = j->reservations.unwritten_idx = journal_cur_seq(j);
@@ -1401,6 +1401,13 @@ int bch2_fs_journal_init(struct journal *j)
 
 /* debug: */
 
+static const char * const bch2_journal_flags_strs[] = {
+#define x(n)   #n,
+       JOURNAL_FLAGS()
+#undef x
+       NULL
+};
+
 void __bch2_journal_debug_to_text(struct printbuf *out, struct journal *j)
 {
        struct bch_fs *c = container_of(j, struct bch_fs, journal);
@@ -1415,6 +1422,9 @@ void __bch2_journal_debug_to_text(struct printbuf *out, struct journal *j)
        rcu_read_lock();
        s = READ_ONCE(j->reservations);
 
+       prt_printf(out, "flags:\t");
+       prt_bitflags(out, bch2_journal_flags_strs, j->flags);
+       prt_newline(out);
        prt_printf(out, "dirty journal entries:\t%llu/%llu\n",  fifo_used(&j->pin), j->pin.size);
        prt_printf(out, "seq:\t%llu\n",                         journal_cur_seq(j));
        prt_printf(out, "seq_ondisk:\t%llu\n",                  j->seq_ondisk);
@@ -1453,10 +1463,6 @@ void __bch2_journal_debug_to_text(struct printbuf *out, struct journal *j)
        prt_printf(out, "unwritten entries:\n");
        bch2_journal_bufs_to_text(out, j);
 
-       prt_printf(out,
-              "replay done:\t%i\n",
-              test_bit(JOURNAL_REPLAY_DONE,    &j->flags));
-
        prt_printf(out, "space:\n");
        printbuf_indent_add(out, 2);
        prt_printf(out, "discarded\t%u:%u\n",
index 4b8c709bc317bddbf709db2dc668afad08133a99..fd1f7cdaa8bc62d9f156ab4371628cc75f0a3d12 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_RUNNING, &j->flags));
+       EBUG_ON(!test_bit(JOURNAL_running, &j->flags));
 
        res->u64s = u64s;
 
@@ -418,8 +418,8 @@ struct bch_dev;
 
 static inline void bch2_journal_set_replay_done(struct journal *j)
 {
-       BUG_ON(!test_bit(JOURNAL_RUNNING, &j->flags));
-       set_bit(JOURNAL_REPLAY_DONE, &j->flags);
+       BUG_ON(!test_bit(JOURNAL_running, &j->flags));
+       set_bit(JOURNAL_replay_done, &j->flags);
 }
 
 void bch2_journal_unblock(struct journal *);
index dec50e7a8cb41b3ad7060c3a307195f4681c57c8..e76eb98af74a20508911c07c17c10f1ca7620443 100644 (file)
@@ -1954,14 +1954,14 @@ static int bch2_journal_write_pick_flush(struct journal *j, struct journal_buf *
         * So if we're in an error state, and we're still starting up, we don't
         * write anything at all.
         */
-       if (error && test_bit(JOURNAL_NEED_FLUSH_WRITE, &j->flags))
+       if (error && test_bit(JOURNAL_need_flush_write, &j->flags))
                return -EIO;
 
        if (error ||
            w->noflush ||
            (!w->must_flush &&
             (jiffies - j->last_flush_write) < msecs_to_jiffies(c->opts.journal_flush_delay) &&
-            test_bit(JOURNAL_MAY_SKIP_FLUSH, &j->flags))) {
+            test_bit(JOURNAL_may_skip_flush, &j->flags))) {
                w->noflush = true;
                SET_JSET_NO_FLUSH(w->data, true);
                w->data->last_seq       = 0;
@@ -1972,7 +1972,7 @@ static int bch2_journal_write_pick_flush(struct journal *j, struct journal_buf *
                w->must_flush = true;
                j->last_flush_write = jiffies;
                j->nr_flush_writes++;
-               clear_bit(JOURNAL_NEED_FLUSH_WRITE, &j->flags);
+               clear_bit(JOURNAL_need_flush_write, &j->flags);
        }
 
        return 0;
index a0c9f7ac611df42cf8a89209a7ab8ea1544a096a..79be0eaddfa0d14b1273b8cb8ef42449d79e3485 100644 (file)
@@ -67,7 +67,7 @@ void bch2_journal_set_watermark(struct journal *j)
            track_event_change(&c->times[BCH_TIME_blocked_write_buffer_full], low_on_wb))
                trace_and_count(c, journal_full, c);
 
-       mod_bit(JOURNAL_SPACE_LOW, &j->flags, low_on_space || low_on_pin);
+       mod_bit(JOURNAL_space_low, &j->flags, low_on_space || low_on_pin);
 
        swap(watermark, j->watermark);
        if (watermark > j->watermark)
@@ -225,9 +225,9 @@ void bch2_journal_space_available(struct journal *j)
             j->space[journal_space_clean_ondisk].total) &&
            (clean - clean_ondisk <= total / 8) &&
            (clean_ondisk * 2 > clean))
-               set_bit(JOURNAL_MAY_SKIP_FLUSH, &j->flags);
+               set_bit(JOURNAL_may_skip_flush, &j->flags);
        else
-               clear_bit(JOURNAL_MAY_SKIP_FLUSH, &j->flags);
+               clear_bit(JOURNAL_may_skip_flush, &j->flags);
 
        bch2_journal_set_watermark(j);
 out:
@@ -818,7 +818,7 @@ static int journal_flush_done(struct journal *j, u64 seq_to_flush,
         * If journal replay hasn't completed, the unreplayed journal entries
         * hold refs on their corresponding sequence numbers
         */
-       ret = !test_bit(JOURNAL_REPLAY_DONE, &j->flags) ||
+       ret = !test_bit(JOURNAL_replay_done, &j->flags) ||
                journal_last_seq(j) > seq_to_flush ||
                !fifo_used(&j->pin);
 
@@ -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_RUNNING, &j->flags))
+       if (!test_bit(JOURNAL_running, &j->flags))
                return false;
 
        closure_wait_event(&j->async_wait,
index 45c1c48f49179a779e3eb27e7ac82c561dd4cfd9..19183fcf7ad7fd031ba263da226ecb21e9d04685 100644 (file)
@@ -129,12 +129,17 @@ enum journal_space_from {
        journal_space_nr,
 };
 
+#define JOURNAL_FLAGS()                        \
+       x(replay_done)                  \
+       x(running)                      \
+       x(may_skip_flush)               \
+       x(need_flush_write)             \
+       x(space_low)
+
 enum journal_flags {
-       JOURNAL_REPLAY_DONE,
-       JOURNAL_RUNNING,
-       JOURNAL_MAY_SKIP_FLUSH,
-       JOURNAL_NEED_FLUSH_WRITE,
-       JOURNAL_SPACE_LOW,
+#define x(n)   JOURNAL_##n,
+       JOURNAL_FLAGS()
+#undef x
 };
 
 /* Reasons we may fail to get a journal reservation: */
index 6c6087039781e417141cc6def15f499bb5f15760..5af8450098fdc83db4e50d488eedf42644cc5138 100644 (file)
@@ -284,7 +284,7 @@ static void __bch2_fs_read_only(struct bch_fs *c)
        bch_verbose(c, "flushing journal and stopping allocators complete, journal seq %llu",
                    journal_cur_seq(&c->journal));
 
-       if (test_bit(JOURNAL_REPLAY_DONE, &c->journal.flags) &&
+       if (test_bit(JOURNAL_replay_done, &c->journal.flags) &&
            !test_bit(BCH_FS_emergency_ro, &c->flags))
                set_bit(BCH_FS_clean_shutdown, &c->flags);
 
@@ -466,8 +466,8 @@ static int __bch2_fs_read_write(struct bch_fs *c, bool early)
         * overwriting whatever was there previously, and there must always be
         * 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);
+       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);