Commit e678a4f0 authored by Jan Kara's avatar Jan Kara

jbd: don't wait (forever) for stale tid caused by wraparound

In the case where an inode has a very stale transaction id (tid) in
i_datasync_tid or i_sync_tid, it's possible that after a very large
(2**31) number of transactions, that the tid number space might wrap,
causing tid_geq()'s calculations to fail.

Commit d9b01934 "jbd: fix fsync() tid wraparound bug" attempted to fix
this problem, but it only avoided kjournald spinning forever by fixing
the logic in jbd_log_start_commit().
Signed-off-by: default avatarJan Kara <jack@suse.cz>
parent e6436921
...@@ -564,6 +564,16 @@ int log_wait_commit(journal_t *journal, tid_t tid) ...@@ -564,6 +564,16 @@ int log_wait_commit(journal_t *journal, tid_t tid)
spin_unlock(&journal->j_state_lock); spin_unlock(&journal->j_state_lock);
#endif #endif
spin_lock(&journal->j_state_lock); spin_lock(&journal->j_state_lock);
/*
* Not running or committing trans? Must be already committed. This
* saves us from waiting for a *long* time when tid overflows.
*/
if (!((journal->j_running_transaction &&
journal->j_running_transaction->t_tid == tid) ||
(journal->j_committing_transaction &&
journal->j_committing_transaction->t_tid == tid)))
goto out_unlock;
if (!tid_geq(journal->j_commit_waited, tid)) if (!tid_geq(journal->j_commit_waited, tid))
journal->j_commit_waited = tid; journal->j_commit_waited = tid;
while (tid_gt(tid, journal->j_commit_sequence)) { while (tid_gt(tid, journal->j_commit_sequence)) {
...@@ -575,6 +585,7 @@ int log_wait_commit(journal_t *journal, tid_t tid) ...@@ -575,6 +585,7 @@ int log_wait_commit(journal_t *journal, tid_t tid)
!tid_gt(tid, journal->j_commit_sequence)); !tid_gt(tid, journal->j_commit_sequence));
spin_lock(&journal->j_state_lock); spin_lock(&journal->j_state_lock);
} }
out_unlock:
spin_unlock(&journal->j_state_lock); spin_unlock(&journal->j_state_lock);
if (unlikely(is_journal_aborted(journal))) { if (unlikely(is_journal_aborted(journal))) {
......
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