diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2022-02-28 19:29:19 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:09:26 -0400 |
commit | 24a3d53b28398d2edd4dc717bede21eaf4a3b874 (patch) | |
tree | 9ba1e8bf729fb88bd3c4027f370422c8eb5b6f97 /fs/bcachefs/journal_io.c | |
parent | 30ef633a0b46e06860f46bf7df0f5a313e6e1a19 (diff) | |
download | lwn-24a3d53b28398d2edd4dc717bede21eaf4a3b874.tar.gz lwn-24a3d53b28398d2edd4dc717bede21eaf4a3b874.zip |
bcachefs: __journal_entry_close() never fails
Previous patch just moved responsibility for incrementing the journal
sequence number and initializing the new journal entry from
__journal_entry_close() to journal_entry_open(); this patch makes the
analagous change for journal reservation state, incrementing the index
into array of journal_bufs at open time.
This means that __journal_entry_close() never fails to close an open
journal entry, which is important for the next patch that will change
our emergency shutdown behaviour.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Diffstat (limited to 'fs/bcachefs/journal_io.c')
-rw-r--r-- | fs/bcachefs/journal_io.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/fs/bcachefs/journal_io.c b/fs/bcachefs/journal_io.c index 7c8298ddad25..90743fa13ff4 100644 --- a/fs/bcachefs/journal_io.c +++ b/fs/bcachefs/journal_io.c @@ -1392,7 +1392,7 @@ static void journal_write_done(struct closure *cl) v = atomic64_read(&j->reservations.counter); do { old.v = new.v = v; - BUG_ON(new.idx == new.unwritten_idx); + BUG_ON(journal_state_count(new, new.unwritten_idx)); new.unwritten_idx++; } while ((v = atomic64_cmpxchg(&j->reservations.counter, @@ -1403,14 +1403,22 @@ static void journal_write_done(struct closure *cl) closure_wake_up(&w->wait); journal_wake(j); - if (journal_last_unwritten_seq(j) == journal_cur_seq(j)) { + if (!journal_state_count(new, new.unwritten_idx) && + journal_last_unwritten_seq(j) <= journal_cur_seq(j)) { + closure_call(&j->io, bch2_journal_write, c->io_complete_wq, NULL); + } else if (journal_last_unwritten_seq(j) == journal_cur_seq(j) && + new.cur_entry_offset < JOURNAL_ENTRY_CLOSED_VAL) { struct journal_buf *buf = journal_cur_buf(j); long delta = buf->expires - jiffies; + /* + * We don't close a journal entry to write it while there's + * previous entries still in flight - the current journal entry + * might want to be written now: + */ + mod_delayed_work(c->io_complete_wq, &j->write_work, max(0L, delta)); - } else if (journal_last_unwritten_seq(j) < journal_cur_seq(j) && - !journal_state_count(new, new.unwritten_idx)) - closure_call(&j->io, bch2_journal_write, c->io_complete_wq, NULL); + } spin_unlock(&j->lock); } |