bcachefs: Fix early startup error path
Don't set JOURNAL_running until we're also calling journal_space_available() for the first time. If JOURNAL_running is set, shutdown will write an empty journal entry - but this will hit an assert in journal_entry_open() if we've never called journal_space_available(). Reported-by: syzbot+53bb24d476ef8368a7f0@syzkaller.appspotmail.com Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
+15
-2
@@ -1462,8 +1462,6 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq)
|
||||
j->last_empty_seq = cur_seq - 1; /* to match j->seq */
|
||||
|
||||
spin_lock(&j->lock);
|
||||
|
||||
set_bit(JOURNAL_running, &j->flags);
|
||||
j->last_flush_write = jiffies;
|
||||
|
||||
j->reservations.idx = journal_cur_seq(j);
|
||||
@@ -1474,6 +1472,21 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bch2_journal_set_replay_done(struct journal *j)
|
||||
{
|
||||
/*
|
||||
* journal_space_available must happen before setting JOURNAL_running
|
||||
* JOURNAL_running must happen before JOURNAL_replay_done
|
||||
*/
|
||||
spin_lock(&j->lock);
|
||||
bch2_journal_space_available(j);
|
||||
|
||||
set_bit(JOURNAL_need_flush_write, &j->flags);
|
||||
set_bit(JOURNAL_running, &j->flags);
|
||||
set_bit(JOURNAL_replay_done, &j->flags);
|
||||
spin_unlock(&j->lock);
|
||||
}
|
||||
|
||||
/* init/exit: */
|
||||
|
||||
void bch2_dev_journal_exit(struct bch_dev *ca)
|
||||
|
||||
@@ -437,12 +437,6 @@ static inline int bch2_journal_error(struct journal *j)
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void bch2_journal_unblock(struct journal *);
|
||||
void bch2_journal_block(struct journal *);
|
||||
struct journal_buf *bch2_next_write_buffer_flush_journal_buf(struct journal *, u64, bool *);
|
||||
@@ -459,6 +453,7 @@ 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);
|
||||
void bch2_journal_set_replay_done(struct journal *);
|
||||
|
||||
void bch2_dev_journal_exit(struct bch_dev *);
|
||||
int bch2_dev_journal_init(struct bch_dev *, struct bch_sb *);
|
||||
|
||||
@@ -1129,13 +1129,13 @@ int bch2_fs_initialize(struct bch_fs *c)
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
set_bit(BCH_FS_accounting_replay_done, &c->flags);
|
||||
bch2_journal_set_replay_done(&c->journal);
|
||||
|
||||
ret = bch2_fs_read_write_early(c);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
set_bit(BCH_FS_accounting_replay_done, &c->flags);
|
||||
bch2_journal_set_replay_done(&c->journal);
|
||||
|
||||
for_each_member_device(c, ca) {
|
||||
ret = bch2_dev_usage_init(ca, false);
|
||||
if (ret) {
|
||||
|
||||
+12
-13
@@ -466,29 +466,28 @@ static int __bch2_fs_read_write(struct bch_fs *c, bool early)
|
||||
|
||||
clear_bit(BCH_FS_clean_shutdown, &c->flags);
|
||||
|
||||
/*
|
||||
* First journal write must be a flush write: after a clean shutdown we
|
||||
* don't read the journal, so the first journal write may end up
|
||||
* 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);
|
||||
|
||||
__for_each_online_member(c, ca, BIT(BCH_MEMBER_STATE_rw), READ) {
|
||||
bch2_dev_allocator_add(c, ca);
|
||||
percpu_ref_reinit(&ca->io_ref[WRITE]);
|
||||
}
|
||||
bch2_recalc_capacity(c);
|
||||
|
||||
/*
|
||||
* First journal write must be a flush write: after a clean shutdown we
|
||||
* don't read the journal, so the first journal write may end up
|
||||
* overwriting whatever was there previously, and there must always be
|
||||
* at least one non-flush write in the journal or recovery will fail:
|
||||
*/
|
||||
spin_lock(&c->journal.lock);
|
||||
set_bit(JOURNAL_need_flush_write, &c->journal.flags);
|
||||
set_bit(JOURNAL_running, &c->journal.flags);
|
||||
bch2_journal_space_available(&c->journal);
|
||||
spin_unlock(&c->journal.lock);
|
||||
|
||||
ret = bch2_fs_mark_dirty(c);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
spin_lock(&c->journal.lock);
|
||||
bch2_journal_space_available(&c->journal);
|
||||
spin_unlock(&c->journal.lock);
|
||||
|
||||
ret = bch2_journal_reclaim_start(&c->journal);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
Reference in New Issue
Block a user