diff options
author | Jan Kara <jack@suse.cz> | 2012-01-04 22:03:11 -0500 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2012-01-04 22:03:11 -0500 |
commit | 9837d8e982b7e87a7207f90618e45d460e196e6a (patch) | |
tree | 639e335810e90680ce0078b36803835d148144b4 /fs/jbd2 | |
parent | 9b90e5e02896406a6da28a376568003d14c06770 (diff) |
jbd2: fix hung processes in jbd2_journal_lock_updates()
Toshiyuki Okajima found out that when running
for ((i=0; i < 100000; i++)); do
if ((i%2 == 0)); then
chattr +j /mnt/file
else
chattr -j /mnt/file
fi
echo "0" >> /mnt/file
done
process sometimes hangs indefinitely in jbd2_journal_lock_updates().
Toshiyuki identified that the following race happens:
jbd2_journal_lock_updates() |jbd2_journal_stop()
---------------------------------------+---------------------------------------
write_lock(&journal->j_state_lock) | .
++journal->j_barrier_count | .
spin_lock(&tran->t_handle_lock) | .
atomic_read(&tran->t_updates) //not 0 |
| atomic_dec_and_test(&tran->t_updates)
| // t_updates = 0
| wake_up(&journal->j_wait_updates)
prepare_to_wait() | // no process is woken up.
spin_unlock(&tran->t_handle_lock) |
write_unlock(&journal->j_state_lock) |
schedule() // never return |
We fix the problem by first calling prepare_to_wait() and only after that
checking t_updates in jbd2_journal_lock_updates().
Reported-and-analyzed-by: Toshiyuki Okajima <toshi.okajima@jp.fujitsu.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'fs/jbd2')
-rw-r--r-- | fs/jbd2/transaction.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c index a0e41a4c080e..35ae096bed5d 100644 --- a/fs/jbd2/transaction.c +++ b/fs/jbd2/transaction.c | |||
@@ -517,12 +517,13 @@ void jbd2_journal_lock_updates(journal_t *journal) | |||
517 | break; | 517 | break; |
518 | 518 | ||
519 | spin_lock(&transaction->t_handle_lock); | 519 | spin_lock(&transaction->t_handle_lock); |
520 | prepare_to_wait(&journal->j_wait_updates, &wait, | ||
521 | TASK_UNINTERRUPTIBLE); | ||
520 | if (!atomic_read(&transaction->t_updates)) { | 522 | if (!atomic_read(&transaction->t_updates)) { |
521 | spin_unlock(&transaction->t_handle_lock); | 523 | spin_unlock(&transaction->t_handle_lock); |
524 | finish_wait(&journal->j_wait_updates, &wait); | ||
522 | break; | 525 | break; |
523 | } | 526 | } |
524 | prepare_to_wait(&journal->j_wait_updates, &wait, | ||
525 | TASK_UNINTERRUPTIBLE); | ||
526 | spin_unlock(&transaction->t_handle_lock); | 527 | spin_unlock(&transaction->t_handle_lock); |
527 | write_unlock(&journal->j_state_lock); | 528 | write_unlock(&journal->j_state_lock); |
528 | schedule(); | 529 | schedule(); |