Commit a66ff26b authored by Kent Overstreet's avatar Kent Overstreet
Browse files

bcachefs: Close journal entry if necessary when flushing all pins



Since outstanding journal buffers hold a journal pin, when flushing all
pins we need to close the current journal entry if necessary so its pin
can be released.

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 4a147af2
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -249,7 +249,7 @@ static bool journal_entry_want_write(struct journal *j)
	return ret;
}

static bool journal_entry_close(struct journal *j)
bool bch2_journal_entry_close(struct journal *j)
{
	bool ret;

@@ -383,7 +383,7 @@ static bool journal_quiesced(struct journal *j)
	bool ret = atomic64_read(&j->seq) == j->seq_ondisk;

	if (!ret)
		journal_entry_close(j);
		bch2_journal_entry_close(j);
	return ret;
}

@@ -436,7 +436,7 @@ static int __journal_res_get(struct journal *j, struct journal_res *res,

	/*
	 * Recheck after taking the lock, so we don't race with another thread
	 * that just did journal_entry_open() and call journal_entry_close()
	 * that just did journal_entry_open() and call bch2_journal_entry_close()
	 * unnecessarily
	 */
	if (journal_res_get_fast(j, res, flags)) {
@@ -1041,7 +1041,7 @@ void bch2_fs_journal_stop(struct journal *j)
	bch2_journal_reclaim_stop(j);
	bch2_journal_flush_all_pins(j);

	wait_event(j->wait, journal_entry_close(j));
	wait_event(j->wait, bch2_journal_entry_close(j));

	/*
	 * Always write a new journal entry, to make sure the clock hands are up
+1 −0
Original line number Diff line number Diff line
@@ -266,6 +266,7 @@ static inline union journal_res_state journal_state_buf_put(struct journal *j, u
	return s;
}

bool bch2_journal_entry_close(struct journal *);
void bch2_journal_buf_put_final(struct journal *, u64, bool);

static inline void __bch2_journal_buf_put(struct journal *j, unsigned idx, u64 seq)
+1 −0
Original line number Diff line number Diff line
@@ -1599,6 +1599,7 @@ static CLOSURE_CALLBACK(journal_write_done)
	} while ((v = atomic64_cmpxchg(&j->reservations.counter,
				       old.v, new.v)) != old.v);

	bch2_journal_reclaim_fast(j);
	bch2_journal_space_available(j);

	closure_wake_up(&w->wait);
+3 −0
Original line number Diff line number Diff line
@@ -776,6 +776,9 @@ static int journal_flush_done(struct journal *j, u64 seq_to_flush,
			       (1U << JOURNAL_PIN_btree), 0, 0, 0))
		*did_work = true;

	if (seq_to_flush > journal_cur_seq(j))
		bch2_journal_entry_close(j);

	spin_lock(&j->lock);
	/*
	 * If journal replay hasn't completed, the unreplayed journal entries