Skip to content

Commit 93108eb

Browse files
jankaratytso
authored andcommitted
jbd2: Move dropping of jh reference out of un/re-filing functions
__jbd2_journal_unfile_buffer() and __jbd2_journal_refile_buffer() drop transaction's jh reference when they remove jh from a transaction. This will be however inconvenient once we move state lock into journal_head itself as we still need to unlock it and we'd need to grab jh reference just for that. Move dropping of jh reference out of these functions into the few callers. Signed-off-by: Jan Kara <jack@suse.cz> Link: https://lore.kernel.org/r/20190809124233.13277-4-jack@suse.cz Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent d8ede91 commit 93108eb

3 files changed

Lines changed: 20 additions & 10 deletions

File tree

‎fs/jbd2/commit.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
918918
transaction_t *cp_transaction;
919919
struct buffer_head *bh;
920920
int try_to_free = 0;
921+
bool drop_ref;
921922

922923
jh = commit_transaction->t_forget;
923924
spin_unlock(&journal->j_list_lock);
@@ -1022,8 +1023,10 @@ void jbd2_journal_commit_transaction(journal_t *journal)
10221023
try_to_free = 1;
10231024
}
10241025
JBUFFER_TRACE(jh, "refile or unfile buffer");
1025-
__jbd2_journal_refile_buffer(jh);
1026+
drop_ref = __jbd2_journal_refile_buffer(jh);
10261027
jbd_unlock_bh_state(bh);
1028+
if (drop_ref)
1029+
jbd2_journal_put_journal_head(jh);
10271030
if (try_to_free)
10281031
release_buffer_page(bh); /* Drops bh reference */
10291032
else

‎fs/jbd2/transaction.c‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,7 @@ int jbd2_journal_forget (handle_t *handle, struct buffer_head *bh)
15981598
__jbd2_journal_file_buffer(jh, transaction, BJ_Forget);
15991599
} else {
16001600
__jbd2_journal_unfile_buffer(jh);
1601+
jbd2_journal_put_journal_head(jh);
16011602
if (!buffer_jbd(bh)) {
16021603
spin_unlock(&journal->j_list_lock);
16031604
goto not_jbd;
@@ -1971,17 +1972,15 @@ static void __jbd2_journal_temp_unlink_buffer(struct journal_head *jh)
19711972
}
19721973

19731974
/*
1974-
* Remove buffer from all transactions.
1975+
* Remove buffer from all transactions. The caller is responsible for dropping
1976+
* the jh reference that belonged to the transaction.
19751977
*
19761978
* Called with bh_state lock and j_list_lock
1977-
*
1978-
* jh and bh may be already freed when this function returns.
19791979
*/
19801980
static void __jbd2_journal_unfile_buffer(struct journal_head *jh)
19811981
{
19821982
__jbd2_journal_temp_unlink_buffer(jh);
19831983
jh->b_transaction = NULL;
1984-
jbd2_journal_put_journal_head(jh);
19851984
}
19861985

19871986
void jbd2_journal_unfile_buffer(journal_t *journal, struct journal_head *jh)
@@ -1995,6 +1994,7 @@ void jbd2_journal_unfile_buffer(journal_t *journal, struct journal_head *jh)
19951994
__jbd2_journal_unfile_buffer(jh);
19961995
spin_unlock(&journal->j_list_lock);
19971996
jbd_unlock_bh_state(bh);
1997+
jbd2_journal_put_journal_head(jh);
19981998
__brelse(bh);
19991999
}
20002000

@@ -2133,6 +2133,7 @@ static int __dispose_buffer(struct journal_head *jh, transaction_t *transaction)
21332133
} else {
21342134
JBUFFER_TRACE(jh, "on running transaction");
21352135
__jbd2_journal_unfile_buffer(jh);
2136+
jbd2_journal_put_journal_head(jh);
21362137
}
21372138
return may_free;
21382139
}
@@ -2496,9 +2497,11 @@ void jbd2_journal_file_buffer(struct journal_head *jh,
24962497
* Called under j_list_lock
24972498
* Called under jbd_lock_bh_state(jh2bh(jh))
24982499
*
2499-
* jh and bh may be already free when this function returns
2500+
* When this function returns true, there's no next transaction to refile to
2501+
* and the caller has to drop jh reference through
2502+
* jbd2_journal_put_journal_head().
25002503
*/
2501-
void __jbd2_journal_refile_buffer(struct journal_head *jh)
2504+
bool __jbd2_journal_refile_buffer(struct journal_head *jh)
25022505
{
25032506
int was_dirty, jlist;
25042507
struct buffer_head *bh = jh2bh(jh);
@@ -2510,7 +2513,7 @@ void __jbd2_journal_refile_buffer(struct journal_head *jh)
25102513
/* If the buffer is now unused, just drop it. */
25112514
if (jh->b_next_transaction == NULL) {
25122515
__jbd2_journal_unfile_buffer(jh);
2513-
return;
2516+
return true;
25142517
}
25152518

25162519
/*
@@ -2538,6 +2541,7 @@ void __jbd2_journal_refile_buffer(struct journal_head *jh)
25382541

25392542
if (was_dirty)
25402543
set_buffer_jbddirty(bh);
2544+
return false;
25412545
}
25422546

25432547
/*
@@ -2549,15 +2553,18 @@ void __jbd2_journal_refile_buffer(struct journal_head *jh)
25492553
void jbd2_journal_refile_buffer(journal_t *journal, struct journal_head *jh)
25502554
{
25512555
struct buffer_head *bh = jh2bh(jh);
2556+
bool drop;
25522557

25532558
/* Get reference so that buffer cannot be freed before we unlock it */
25542559
get_bh(bh);
25552560
jbd_lock_bh_state(bh);
25562561
spin_lock(&journal->j_list_lock);
2557-
__jbd2_journal_refile_buffer(jh);
2562+
drop = __jbd2_journal_refile_buffer(jh);
25582563
jbd_unlock_bh_state(bh);
25592564
spin_unlock(&journal->j_list_lock);
25602565
__brelse(bh);
2566+
if (drop)
2567+
jbd2_journal_put_journal_head(jh);
25612568
}
25622569

25632570
/*

‎include/linux/jbd2.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ JBD2_FEATURE_INCOMPAT_FUNCS(csum3, CSUM_V3)
12521252

12531253
/* Filing buffers */
12541254
extern void jbd2_journal_unfile_buffer(journal_t *, struct journal_head *);
1255-
extern void __jbd2_journal_refile_buffer(struct journal_head *);
1255+
extern bool __jbd2_journal_refile_buffer(struct journal_head *);
12561256
extern void jbd2_journal_refile_buffer(journal_t *, struct journal_head *);
12571257
extern void __jbd2_journal_file_buffer(struct journal_head *, transaction_t *, int);
12581258
extern void __journal_free_buffer(struct journal_head *bh);

0 commit comments

Comments
 (0)