bcachefs: x-macroize journal flags enums

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2024-04-30 06:20:37 -04:00
parent 3a718c0647
commit b895c70326
11 changed files with 44 additions and 33 deletions

View File

@ -3170,7 +3170,7 @@ got_trans:
trans->locking_wait.task = current; trans->locking_wait.task = current;
trans->locked = true; trans->locked = true;
trans->journal_replay_not_finished = 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); atomic_inc_not_zero(&c->journal_keys.ref);
trans->nr_paths = ARRAY_SIZE(trans->_paths); trans->nr_paths = ARRAY_SIZE(trans->_paths);
trans->paths_allocated = trans->_paths_allocated; trans->paths_allocated = trans->_paths_allocated;

View File

@ -648,7 +648,7 @@ static int btree_key_cache_flush_pos(struct btree_trans *trans,
commit_flags |= BCH_WATERMARK_reclaim; commit_flags |= BCH_WATERMARK_reclaim;
if (ck->journal.seq != journal_last_seq(j) || 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; commit_flags |= BCH_TRANS_COMMIT_no_journal_res;
ret = bch2_btree_iter_traverse(&b_iter) ?: ret = bch2_btree_iter_traverse(&b_iter) ?:

View File

@ -337,7 +337,7 @@ static inline void btree_insert_entry_checks(struct btree_trans *trans,
EBUG_ON(!i->level && EBUG_ON(!i->level &&
btree_type_has_snapshots(i->btree_id) && btree_type_has_snapshots(i->btree_id) &&
!(i->flags & BTREE_UPDATE_internal_snapshot_node) && !(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 && i->k->k.p.snapshot &&
bch2_snapshot_is_internal_node(trans->c, i->k->k.p.snapshot) > 0); bch2_snapshot_is_internal_node(trans->c, i->k->k.p.snapshot) > 0);
} }

View File

@ -849,7 +849,7 @@ __bch2_fs_log_msg(struct bch_fs *c, unsigned commit_flags, const char *fmt,
if (ret) if (ret)
goto err; 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)); ret = darray_make_room(&c->journal.early_journal_entries, jset_u64s(u64s));
if (ret) if (ret)
goto err; goto err;

View File

@ -1157,12 +1157,12 @@ bch2_btree_update_start(struct btree_trans *trans, struct btree_path *path,
flags |= watermark; flags |= watermark;
if (watermark < BCH_WATERMARK_reclaim && 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) if (flags & BCH_TRANS_COMMIT_journal_reclaim)
return ERR_PTR(-BCH_ERR_journal_reclaim_would_deadlock); return ERR_PTR(-BCH_ERR_journal_reclaim_would_deadlock);
ret = drop_locks_do(trans, 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) if (ret)
return ERR_PTR(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 && BUG_ON(insert->k.type == KEY_TYPE_btree_ptr_v2 &&
!btree_ptr_sectors_written(insert)); !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); 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), if (bch2_bkey_invalid(c, bkey_i_to_s_c(insert),

View File

@ -1182,11 +1182,11 @@ void bch2_fs_journal_stop(struct journal *j)
cancel_delayed_work_sync(&j->write_work); cancel_delayed_work_sync(&j->write_work);
BUG_ON(!bch2_journal_error(j) && 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)); j->last_empty_seq != journal_cur_seq(j));
if (!bch2_journal_error(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) 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); spin_lock(&j->lock);
set_bit(JOURNAL_RUNNING, &j->flags); set_bit(JOURNAL_running, &j->flags);
j->last_flush_write = jiffies; j->last_flush_write = jiffies;
j->reservations.idx = j->reservations.unwritten_idx = journal_cur_seq(j); j->reservations.idx = j->reservations.unwritten_idx = journal_cur_seq(j);
@ -1401,6 +1401,13 @@ int bch2_fs_journal_init(struct journal *j)
/* debug: */ /* 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) void __bch2_journal_debug_to_text(struct printbuf *out, struct journal *j)
{ {
struct bch_fs *c = container_of(j, struct bch_fs, journal); 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(); rcu_read_lock();
s = READ_ONCE(j->reservations); 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, "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:\t%llu\n", journal_cur_seq(j));
prt_printf(out, "seq_ondisk:\t%llu\n", j->seq_ondisk); 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"); prt_printf(out, "unwritten entries:\n");
bch2_journal_bufs_to_text(out, j); 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"); prt_printf(out, "space:\n");
printbuf_indent_add(out, 2); printbuf_indent_add(out, 2);
prt_printf(out, "discarded\t%u:%u\n", prt_printf(out, "discarded\t%u:%u\n",

View File

@ -372,7 +372,7 @@ static inline int bch2_journal_res_get(struct journal *j, struct journal_res *re
int ret; int ret;
EBUG_ON(res->ref); EBUG_ON(res->ref);
EBUG_ON(!test_bit(JOURNAL_RUNNING, &j->flags)); EBUG_ON(!test_bit(JOURNAL_running, &j->flags));
res->u64s = u64s; res->u64s = u64s;
@ -418,8 +418,8 @@ struct bch_dev;
static inline void bch2_journal_set_replay_done(struct journal *j) static inline void bch2_journal_set_replay_done(struct journal *j)
{ {
BUG_ON(!test_bit(JOURNAL_RUNNING, &j->flags)); BUG_ON(!test_bit(JOURNAL_running, &j->flags));
set_bit(JOURNAL_REPLAY_DONE, &j->flags); set_bit(JOURNAL_replay_done, &j->flags);
} }
void bch2_journal_unblock(struct journal *); void bch2_journal_unblock(struct journal *);

View 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 * So if we're in an error state, and we're still starting up, we don't
* write anything at all. * 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; return -EIO;
if (error || if (error ||
w->noflush || w->noflush ||
(!w->must_flush && (!w->must_flush &&
(jiffies - j->last_flush_write) < msecs_to_jiffies(c->opts.journal_flush_delay) && (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; w->noflush = true;
SET_JSET_NO_FLUSH(w->data, true); SET_JSET_NO_FLUSH(w->data, true);
w->data->last_seq = 0; 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; w->must_flush = true;
j->last_flush_write = jiffies; j->last_flush_write = jiffies;
j->nr_flush_writes++; j->nr_flush_writes++;
clear_bit(JOURNAL_NEED_FLUSH_WRITE, &j->flags); clear_bit(JOURNAL_need_flush_write, &j->flags);
} }
return 0; return 0;

View 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)) track_event_change(&c->times[BCH_TIME_blocked_write_buffer_full], low_on_wb))
trace_and_count(c, journal_full, c); 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); swap(watermark, j->watermark);
if (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) && j->space[journal_space_clean_ondisk].total) &&
(clean - clean_ondisk <= total / 8) && (clean - clean_ondisk <= total / 8) &&
(clean_ondisk * 2 > clean)) (clean_ondisk * 2 > clean))
set_bit(JOURNAL_MAY_SKIP_FLUSH, &j->flags); set_bit(JOURNAL_may_skip_flush, &j->flags);
else else
clear_bit(JOURNAL_MAY_SKIP_FLUSH, &j->flags); clear_bit(JOURNAL_may_skip_flush, &j->flags);
bch2_journal_set_watermark(j); bch2_journal_set_watermark(j);
out: 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 * If journal replay hasn't completed, the unreplayed journal entries
* hold refs on their corresponding sequence numbers * 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 || journal_last_seq(j) > seq_to_flush ||
!fifo_used(&j->pin); !fifo_used(&j->pin);
@ -833,7 +833,7 @@ bool bch2_journal_flush_pins(struct journal *j, u64 seq_to_flush)
/* time_stats this */ /* time_stats this */
bool did_work = false; bool did_work = false;
if (!test_bit(JOURNAL_RUNNING, &j->flags)) if (!test_bit(JOURNAL_running, &j->flags))
return false; return false;
closure_wait_event(&j->async_wait, closure_wait_event(&j->async_wait,

View File

@ -129,12 +129,17 @@ enum journal_space_from {
journal_space_nr, 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 { enum journal_flags {
JOURNAL_REPLAY_DONE, #define x(n) JOURNAL_##n,
JOURNAL_RUNNING, JOURNAL_FLAGS()
JOURNAL_MAY_SKIP_FLUSH, #undef x
JOURNAL_NEED_FLUSH_WRITE,
JOURNAL_SPACE_LOW,
}; };
/* Reasons we may fail to get a journal reservation: */ /* Reasons we may fail to get a journal reservation: */

View 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", bch_verbose(c, "flushing journal and stopping allocators complete, journal seq %llu",
journal_cur_seq(&c->journal)); 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)) !test_bit(BCH_FS_emergency_ro, &c->flags))
set_bit(BCH_FS_clean_shutdown, &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 * overwriting whatever was there previously, and there must always be
* at least one non-flush write in the journal or recovery will fail: * 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_need_flush_write, &c->journal.flags);
set_bit(JOURNAL_RUNNING, &c->journal.flags); set_bit(JOURNAL_running, &c->journal.flags);
for_each_rw_member(c, ca) for_each_rw_member(c, ca)
bch2_dev_allocator_add(c, ca); bch2_dev_allocator_add(c, ca);