Commit 93108ebb authored by Jan Kara's avatar Jan Kara Committed by Theodore Ts'o

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: default avatarJan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20190809124233.13277-4-jack@suse.czSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent d8ede917
...@@ -918,6 +918,7 @@ void jbd2_journal_commit_transaction(journal_t *journal) ...@@ -918,6 +918,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
transaction_t *cp_transaction; transaction_t *cp_transaction;
struct buffer_head *bh; struct buffer_head *bh;
int try_to_free = 0; int try_to_free = 0;
bool drop_ref;
jh = commit_transaction->t_forget; jh = commit_transaction->t_forget;
spin_unlock(&journal->j_list_lock); spin_unlock(&journal->j_list_lock);
...@@ -1022,8 +1023,10 @@ void jbd2_journal_commit_transaction(journal_t *journal) ...@@ -1022,8 +1023,10 @@ void jbd2_journal_commit_transaction(journal_t *journal)
try_to_free = 1; try_to_free = 1;
} }
JBUFFER_TRACE(jh, "refile or unfile buffer"); JBUFFER_TRACE(jh, "refile or unfile buffer");
__jbd2_journal_refile_buffer(jh); drop_ref = __jbd2_journal_refile_buffer(jh);
jbd_unlock_bh_state(bh); jbd_unlock_bh_state(bh);
if (drop_ref)
jbd2_journal_put_journal_head(jh);
if (try_to_free) if (try_to_free)
release_buffer_page(bh); /* Drops bh reference */ release_buffer_page(bh); /* Drops bh reference */
else else
......
...@@ -1598,6 +1598,7 @@ int jbd2_journal_forget (handle_t *handle, struct buffer_head *bh) ...@@ -1598,6 +1598,7 @@ int jbd2_journal_forget (handle_t *handle, struct buffer_head *bh)
__jbd2_journal_file_buffer(jh, transaction, BJ_Forget); __jbd2_journal_file_buffer(jh, transaction, BJ_Forget);
} else { } else {
__jbd2_journal_unfile_buffer(jh); __jbd2_journal_unfile_buffer(jh);
jbd2_journal_put_journal_head(jh);
if (!buffer_jbd(bh)) { if (!buffer_jbd(bh)) {
spin_unlock(&journal->j_list_lock); spin_unlock(&journal->j_list_lock);
goto not_jbd; goto not_jbd;
...@@ -1971,17 +1972,15 @@ static void __jbd2_journal_temp_unlink_buffer(struct journal_head *jh) ...@@ -1971,17 +1972,15 @@ static void __jbd2_journal_temp_unlink_buffer(struct journal_head *jh)
} }
/* /*
* Remove buffer from all transactions. * Remove buffer from all transactions. The caller is responsible for dropping
* the jh reference that belonged to the transaction.
* *
* Called with bh_state lock and j_list_lock * Called with bh_state lock and j_list_lock
*
* jh and bh may be already freed when this function returns.
*/ */
static void __jbd2_journal_unfile_buffer(struct journal_head *jh) static void __jbd2_journal_unfile_buffer(struct journal_head *jh)
{ {
__jbd2_journal_temp_unlink_buffer(jh); __jbd2_journal_temp_unlink_buffer(jh);
jh->b_transaction = NULL; jh->b_transaction = NULL;
jbd2_journal_put_journal_head(jh);
} }
void jbd2_journal_unfile_buffer(journal_t *journal, struct journal_head *jh) 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) ...@@ -1995,6 +1994,7 @@ void jbd2_journal_unfile_buffer(journal_t *journal, struct journal_head *jh)
__jbd2_journal_unfile_buffer(jh); __jbd2_journal_unfile_buffer(jh);
spin_unlock(&journal->j_list_lock); spin_unlock(&journal->j_list_lock);
jbd_unlock_bh_state(bh); jbd_unlock_bh_state(bh);
jbd2_journal_put_journal_head(jh);
__brelse(bh); __brelse(bh);
} }
...@@ -2133,6 +2133,7 @@ static int __dispose_buffer(struct journal_head *jh, transaction_t *transaction) ...@@ -2133,6 +2133,7 @@ static int __dispose_buffer(struct journal_head *jh, transaction_t *transaction)
} else { } else {
JBUFFER_TRACE(jh, "on running transaction"); JBUFFER_TRACE(jh, "on running transaction");
__jbd2_journal_unfile_buffer(jh); __jbd2_journal_unfile_buffer(jh);
jbd2_journal_put_journal_head(jh);
} }
return may_free; return may_free;
} }
...@@ -2496,9 +2497,11 @@ void jbd2_journal_file_buffer(struct journal_head *jh, ...@@ -2496,9 +2497,11 @@ void jbd2_journal_file_buffer(struct journal_head *jh,
* Called under j_list_lock * Called under j_list_lock
* Called under jbd_lock_bh_state(jh2bh(jh)) * Called under jbd_lock_bh_state(jh2bh(jh))
* *
* jh and bh may be already free when this function returns * When this function returns true, there's no next transaction to refile to
* and the caller has to drop jh reference through
* jbd2_journal_put_journal_head().
*/ */
void __jbd2_journal_refile_buffer(struct journal_head *jh) bool __jbd2_journal_refile_buffer(struct journal_head *jh)
{ {
int was_dirty, jlist; int was_dirty, jlist;
struct buffer_head *bh = jh2bh(jh); struct buffer_head *bh = jh2bh(jh);
...@@ -2510,7 +2513,7 @@ void __jbd2_journal_refile_buffer(struct journal_head *jh) ...@@ -2510,7 +2513,7 @@ void __jbd2_journal_refile_buffer(struct journal_head *jh)
/* If the buffer is now unused, just drop it. */ /* If the buffer is now unused, just drop it. */
if (jh->b_next_transaction == NULL) { if (jh->b_next_transaction == NULL) {
__jbd2_journal_unfile_buffer(jh); __jbd2_journal_unfile_buffer(jh);
return; return true;
} }
/* /*
...@@ -2538,6 +2541,7 @@ void __jbd2_journal_refile_buffer(struct journal_head *jh) ...@@ -2538,6 +2541,7 @@ void __jbd2_journal_refile_buffer(struct journal_head *jh)
if (was_dirty) if (was_dirty)
set_buffer_jbddirty(bh); set_buffer_jbddirty(bh);
return false;
} }
/* /*
...@@ -2549,15 +2553,18 @@ void __jbd2_journal_refile_buffer(struct journal_head *jh) ...@@ -2549,15 +2553,18 @@ void __jbd2_journal_refile_buffer(struct journal_head *jh)
void jbd2_journal_refile_buffer(journal_t *journal, struct journal_head *jh) void jbd2_journal_refile_buffer(journal_t *journal, struct journal_head *jh)
{ {
struct buffer_head *bh = jh2bh(jh); struct buffer_head *bh = jh2bh(jh);
bool drop;
/* Get reference so that buffer cannot be freed before we unlock it */ /* Get reference so that buffer cannot be freed before we unlock it */
get_bh(bh); get_bh(bh);
jbd_lock_bh_state(bh); jbd_lock_bh_state(bh);
spin_lock(&journal->j_list_lock); spin_lock(&journal->j_list_lock);
__jbd2_journal_refile_buffer(jh); drop = __jbd2_journal_refile_buffer(jh);
jbd_unlock_bh_state(bh); jbd_unlock_bh_state(bh);
spin_unlock(&journal->j_list_lock); spin_unlock(&journal->j_list_lock);
__brelse(bh); __brelse(bh);
if (drop)
jbd2_journal_put_journal_head(jh);
} }
/* /*
......
...@@ -1252,7 +1252,7 @@ JBD2_FEATURE_INCOMPAT_FUNCS(csum3, CSUM_V3) ...@@ -1252,7 +1252,7 @@ JBD2_FEATURE_INCOMPAT_FUNCS(csum3, CSUM_V3)
/* Filing buffers */ /* Filing buffers */
extern void jbd2_journal_unfile_buffer(journal_t *, struct journal_head *); extern void jbd2_journal_unfile_buffer(journal_t *, struct journal_head *);
extern void __jbd2_journal_refile_buffer(struct journal_head *); extern bool __jbd2_journal_refile_buffer(struct journal_head *);
extern void jbd2_journal_refile_buffer(journal_t *, struct journal_head *); extern void jbd2_journal_refile_buffer(journal_t *, struct journal_head *);
extern void __jbd2_journal_file_buffer(struct journal_head *, transaction_t *, int); extern void __jbd2_journal_file_buffer(struct journal_head *, transaction_t *, int);
extern void __journal_free_buffer(struct journal_head *bh); extern void __journal_free_buffer(struct journal_head *bh);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment