Skip to content

Commit 24dc986

Browse files
Lukas Czernertytso
authored andcommitted
jbd2: make sure jh have b_transaction set in refile/unfile_buffer
Callers of __jbd2_journal_unfile_buffer() and __jbd2_journal_refile_buffer() assume that the b_transaction is set. In fact if it's not, we can end up with journal_head refcounting errors leading to crash much later that might be very hard to track down. Add asserts to make sure that is the case. We also make sure that b_next_transaction is NULL in __jbd2_journal_unfile_buffer() since the callers expect that as well and we should not get into that stage in this state anyway, leading to problems later on if we do. Tested with fstests. Signed-off-by: Lukas Czerner <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent e030a28 commit 24dc986

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

fs/jbd2/transaction.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,6 +2026,9 @@ static void __jbd2_journal_temp_unlink_buffer(struct journal_head *jh)
20262026
*/
20272027
static void __jbd2_journal_unfile_buffer(struct journal_head *jh)
20282028
{
2029+
J_ASSERT_JH(jh, jh->b_transaction != NULL);
2030+
J_ASSERT_JH(jh, jh->b_next_transaction == NULL);
2031+
20292032
__jbd2_journal_temp_unlink_buffer(jh);
20302033
jh->b_transaction = NULL;
20312034
}
@@ -2572,6 +2575,13 @@ bool __jbd2_journal_refile_buffer(struct journal_head *jh)
25722575

25732576
was_dirty = test_clear_buffer_jbddirty(bh);
25742577
__jbd2_journal_temp_unlink_buffer(jh);
2578+
2579+
/*
2580+
* b_transaction must be set, otherwise the new b_transaction won't
2581+
* be holding jh reference
2582+
*/
2583+
J_ASSERT_JH(jh, jh->b_transaction != NULL);
2584+
25752585
/*
25762586
* We set b_transaction here because b_next_transaction will inherit
25772587
* our jh reference and thus __jbd2_journal_file_buffer() must not

0 commit comments

Comments
 (0)