Skip to content

Commit 4f98186

Browse files
riteshharjanitytso
authored andcommitted
jbd2: refactor wait logic for transaction updates into a common function
No functionality change as such in this patch. This only refactors the common piece of code which waits for t_updates to finish into a common function named as jbd2_journal_wait_updates(journal_t *) Signed-off-by: Ritesh Harjani <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://lore.kernel.org/r/8c564f70f4b2591171677a2a74fccb22a7b6c3a4.1642416995.git.riteshh@linux.ibm.com Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 3ca40c0 commit 4f98186

File tree

3 files changed

+38
-38
lines changed

3 files changed

+38
-38
lines changed

fs/jbd2/commit.c

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -484,22 +484,9 @@ void jbd2_journal_commit_transaction(journal_t *journal)
484484
stats.run.rs_running = jbd2_time_diff(commit_transaction->t_start,
485485
stats.run.rs_locked);
486486

487-
spin_lock(&commit_transaction->t_handle_lock);
488-
while (atomic_read(&commit_transaction->t_updates)) {
489-
DEFINE_WAIT(wait);
487+
// waits for any t_updates to finish
488+
jbd2_journal_wait_updates(journal);
490489

491-
prepare_to_wait(&journal->j_wait_updates, &wait,
492-
TASK_UNINTERRUPTIBLE);
493-
if (atomic_read(&commit_transaction->t_updates)) {
494-
spin_unlock(&commit_transaction->t_handle_lock);
495-
write_unlock(&journal->j_state_lock);
496-
schedule();
497-
write_lock(&journal->j_state_lock);
498-
spin_lock(&commit_transaction->t_handle_lock);
499-
}
500-
finish_wait(&journal->j_wait_updates, &wait);
501-
}
502-
spin_unlock(&commit_transaction->t_handle_lock);
503490
commit_transaction->t_state = T_SWITCH;
504491
write_unlock(&journal->j_state_lock);
505492

@@ -817,7 +804,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
817804
commit_transaction->t_state = T_COMMIT_DFLUSH;
818805
write_unlock(&journal->j_state_lock);
819806

820-
/*
807+
/*
821808
* If the journal is not located on the file system device,
822809
* then we must flush the file system device before we issue
823810
* the commit record

fs/jbd2/transaction.c

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ static int start_this_handle(journal_t *journal, handle_t *handle,
449449
}
450450

451451
/* OK, account for the buffers that this operation expects to
452-
* use and add the handle to the running transaction.
452+
* use and add the handle to the running transaction.
453453
*/
454454
update_t_max_wait(transaction, ts);
455455
handle->h_transaction = transaction;
@@ -836,6 +836,35 @@ int jbd2_journal_restart(handle_t *handle, int nblocks)
836836
}
837837
EXPORT_SYMBOL(jbd2_journal_restart);
838838

839+
/*
840+
* Waits for any outstanding t_updates to finish.
841+
* This is called with write j_state_lock held.
842+
*/
843+
void jbd2_journal_wait_updates(journal_t *journal)
844+
{
845+
transaction_t *commit_transaction = journal->j_running_transaction;
846+
847+
if (!commit_transaction)
848+
return;
849+
850+
spin_lock(&commit_transaction->t_handle_lock);
851+
while (atomic_read(&commit_transaction->t_updates)) {
852+
DEFINE_WAIT(wait);
853+
854+
prepare_to_wait(&journal->j_wait_updates, &wait,
855+
TASK_UNINTERRUPTIBLE);
856+
if (atomic_read(&commit_transaction->t_updates)) {
857+
spin_unlock(&commit_transaction->t_handle_lock);
858+
write_unlock(&journal->j_state_lock);
859+
schedule();
860+
write_lock(&journal->j_state_lock);
861+
spin_lock(&commit_transaction->t_handle_lock);
862+
}
863+
finish_wait(&journal->j_wait_updates, &wait);
864+
}
865+
spin_unlock(&commit_transaction->t_handle_lock);
866+
}
867+
839868
/**
840869
* jbd2_journal_lock_updates () - establish a transaction barrier.
841870
* @journal: Journal to establish a barrier on.
@@ -863,27 +892,9 @@ void jbd2_journal_lock_updates(journal_t *journal)
863892
write_lock(&journal->j_state_lock);
864893
}
865894

866-
/* Wait until there are no running updates */
867-
while (1) {
868-
transaction_t *transaction = journal->j_running_transaction;
869-
870-
if (!transaction)
871-
break;
895+
/* Wait until there are no running t_updates */
896+
jbd2_journal_wait_updates(journal);
872897

873-
spin_lock(&transaction->t_handle_lock);
874-
prepare_to_wait(&journal->j_wait_updates, &wait,
875-
TASK_UNINTERRUPTIBLE);
876-
if (!atomic_read(&transaction->t_updates)) {
877-
spin_unlock(&transaction->t_handle_lock);
878-
finish_wait(&journal->j_wait_updates, &wait);
879-
break;
880-
}
881-
spin_unlock(&transaction->t_handle_lock);
882-
write_unlock(&journal->j_state_lock);
883-
schedule();
884-
finish_wait(&journal->j_wait_updates, &wait);
885-
write_lock(&journal->j_state_lock);
886-
}
887898
write_unlock(&journal->j_state_lock);
888899

889900
/*

include/linux/jbd2.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ struct transaction_s
594594
*/
595595
unsigned long t_log_start;
596596

597-
/*
597+
/*
598598
* Number of buffers on the t_buffers list [j_list_lock, no locks
599599
* needed for jbd2 thread]
600600
*/
@@ -1538,6 +1538,8 @@ extern int jbd2_journal_flush(journal_t *journal, unsigned int flags);
15381538
extern void jbd2_journal_lock_updates (journal_t *);
15391539
extern void jbd2_journal_unlock_updates (journal_t *);
15401540

1541+
void jbd2_journal_wait_updates(journal_t *);
1542+
15411543
extern journal_t * jbd2_journal_init_dev(struct block_device *bdev,
15421544
struct block_device *fs_dev,
15431545
unsigned long long start, int len, int bsize);

0 commit comments

Comments
 (0)