summaryrefslogtreecommitdiff
path: root/fs/bcachefs/journal_reclaim.h
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2020-12-16 15:41:29 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:08:50 -0400
commitd483dd17e2bfd6858498d39eb92abd232d7b8e97 (patch)
tree14accac982779273e6f2b769834aded96fc39de3 /fs/bcachefs/journal_reclaim.h
parentf30dd8601262c74caf148fe834418ad7c931af66 (diff)
bcachefs: Fix race between journal_seq_copy() and journal_seq_drop()
In bch2_btree_interior_update_will_free_node, we copy the journal pins from outstanding writes on the btree node we're about to free. But, this can race with the writes completing, and dropping their journal pins. To guard against this, just use READ_ONCE() in bch2_journal_pin_copy(). Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/journal_reclaim.h')
-rw-r--r--fs/bcachefs/journal_reclaim.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/fs/bcachefs/journal_reclaim.h b/fs/bcachefs/journal_reclaim.h
index f02caa3d49ea..adf1f5c981cd 100644
--- a/fs/bcachefs/journal_reclaim.h
+++ b/fs/bcachefs/journal_reclaim.h
@@ -53,8 +53,11 @@ static inline void bch2_journal_pin_copy(struct journal *j,
struct journal_entry_pin *src,
journal_pin_flush_fn flush_fn)
{
- if (journal_pin_active(src))
- bch2_journal_pin_add(j, src->seq, dst, flush_fn);
+ /* Guard against racing with journal_pin_drop(src): */
+ u64 seq = READ_ONCE(src->seq);
+
+ if (seq)
+ bch2_journal_pin_add(j, seq, dst, flush_fn);
}
static inline void bch2_journal_pin_update(struct journal *j, u64 seq,