From: Brian Foster <bfoster@redhat.com>
To: linux-bcachefs@vger.kernel.org
Subject: [PATCH 2/3] bcachefs: prepare journal buf put to handle pin put
Date: Thu, 31 Aug 2023 07:07:33 -0400 [thread overview]
Message-ID: <20230831110734.787212-3-bfoster@redhat.com> (raw)
In-Reply-To: <20230831110734.787212-1-bfoster@redhat.com>
bcachefs freeze testing has uncovered some raciness between journal
entry open/close and pin list reference count management. The
details of the problem are described in a separate patch. In
preparation for the associated fix, refactor the journal buffer put
path a bit to allow it to eventually handle dropping the pin list
reference currently held by an open journal entry. Open code the
journal write dispatch since it is essentially a single line and
instead factor out the journal state update to be reused, consistent
with other journal state update helpers. No functional changes in
this patch.
Signed-off-by: Brian Foster <bfoster@redhat.com>
---
fs/bcachefs/journal.c | 9 ---------
fs/bcachefs/journal.h | 22 +++++++++++++++++-----
2 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/fs/bcachefs/journal.c b/fs/bcachefs/journal.c
index 055920c26da6..76ebcdb3e3b4 100644
--- a/fs/bcachefs/journal.c
+++ b/fs/bcachefs/journal.c
@@ -132,15 +132,6 @@ journal_error_check_stuck(struct journal *j, int error, unsigned flags)
return stuck;
}
-/* journal entry close/open: */
-
-void __bch2_journal_buf_put(struct journal *j)
-{
- struct bch_fs *c = container_of(j, struct bch_fs, journal);
-
- closure_call(&j->io, bch2_journal_write, c->io_complete_wq, NULL);
-}
-
/*
* Returns true if journal entry is now closed:
*
diff --git a/fs/bcachefs/journal.h b/fs/bcachefs/journal.h
index 008a2e25a4fa..c7a31da077c9 100644
--- a/fs/bcachefs/journal.h
+++ b/fs/bcachefs/journal.h
@@ -252,9 +252,10 @@ static inline bool journal_entry_empty(struct jset *j)
return true;
}
-void __bch2_journal_buf_put(struct journal *);
-
-static inline void bch2_journal_buf_put(struct journal *j, unsigned idx)
+/*
+ * Drop reference on a buffer index and return true if the count has hit zero.
+ */
+static inline union journal_res_state journal_state_buf_put(struct journal *j, unsigned idx)
{
union journal_res_state s;
@@ -264,9 +265,20 @@ static inline void bch2_journal_buf_put(struct journal *j, unsigned idx)
.buf2_count = idx == 2,
.buf3_count = idx == 3,
}).v, &j->reservations.counter);
+ return s;
+}
- if (!journal_state_count(s, idx) && idx == s.unwritten_idx)
- __bch2_journal_buf_put(j);
+void bch2_journal_write(struct closure *);
+static inline void bch2_journal_buf_put(struct journal *j, unsigned idx)
+{
+ struct bch_fs *c = container_of(j, struct bch_fs, journal);
+ union journal_res_state s;
+
+ s = journal_state_buf_put(j, idx);
+ if (!journal_state_count(s, idx)) {
+ if (idx == s.unwritten_idx)
+ closure_call(&j->io, bch2_journal_write, c->io_complete_wq, NULL);
+ }
}
/*
--
2.41.0
next prev parent reply other threads:[~2023-08-31 11:08 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-31 11:07 [PATCH 0/3] bcachefs: journal bug fixes Brian Foster
2023-08-31 11:07 ` [PATCH 1/3] bcachefs: restart journal reclaim thread on ro->rw transitions Brian Foster
2023-08-31 11:07 ` Brian Foster [this message]
2023-09-03 21:09 ` [PATCH 2/3] bcachefs: prepare journal buf put to handle pin put Kent Overstreet
2023-09-05 12:41 ` Brian Foster
2023-09-10 1:55 ` Kent Overstreet
2023-08-31 11:07 ` [PATCH 3/3] bcachefs: fix race between journal entry close and pin set Brian Foster
2023-09-03 21:18 ` Kent Overstreet
2023-09-04 2:29 ` Kent Overstreet
2023-09-05 12:59 ` Brian Foster
2023-09-06 19:07 ` Brian Foster
2023-09-10 2:03 ` Kent Overstreet
2023-09-12 18:54 ` Brian Foster
2023-09-12 19:15 ` Kent Overstreet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230831110734.787212-3-bfoster@redhat.com \
--to=bfoster@redhat.com \
--cc=linux-bcachefs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox