Add stable@vger.kernel.org annotations
[ext4-patch-queue.git] / fix-lockdep-annotation-in-add_transaction_credits
blob9275eb044309bdcf3b0fd17bece385dfdfac7b7e
1 jbd2: fix lockdep annotation in add_transaction_credits()
3 From: Jan Kara <jack@suse.cz>
5 Thomas has reported a lockdep splat hitting in
6 add_transaction_credits(). The problem is that that function calls
7 jbd2_might_wait_for_commit() while holding j_state_lock which is wrong
8 (we do not really wait for transaction commit while holding that lock).
10 Fix the problem by moving jbd2_might_wait_for_commit() into places where
11 we are ready to wait for transaction commit and thus j_state_lock is
12 unlocked.
14 Cc: stable@vger.kernel.org
15 Fixes: 1eaa566d368b214d99cbb973647c1b0b8102a9ae
16 Reported-by: Thomas Gleixner <tglx@linutronix.de>
17 Signed-off-by: Jan Kara <jack@suse.cz>
18 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
19 ---
20  fs/jbd2/transaction.c | 6 ++++--
21  1 file changed, 4 insertions(+), 2 deletions(-)
23 diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
24 index b5bc3e249163..3d8246a9faa4 100644
25 --- a/fs/jbd2/transaction.c
26 +++ b/fs/jbd2/transaction.c
27 @@ -159,6 +159,7 @@ static void wait_transaction_locked(journal_t *journal)
28         read_unlock(&journal->j_state_lock);
29         if (need_to_start)
30                 jbd2_log_start_commit(journal, tid);
31 +       jbd2_might_wait_for_commit(journal);
32         schedule();
33         finish_wait(&journal->j_wait_transaction_locked, &wait);
34  }
35 @@ -182,8 +183,6 @@ static int add_transaction_credits(journal_t *journal, int blocks,
36         int needed;
37         int total = blocks + rsv_blocks;
39 -       jbd2_might_wait_for_commit(journal);
41         /*
42          * If the current transaction is locked down for commit, wait
43          * for the lock to be released.
44 @@ -214,6 +213,7 @@ static int add_transaction_credits(journal_t *journal, int blocks,
45                 if (atomic_read(&journal->j_reserved_credits) + total >
46                     journal->j_max_transaction_buffers) {
47                         read_unlock(&journal->j_state_lock);
48 +                       jbd2_might_wait_for_commit(journal);
49                         wait_event(journal->j_wait_reserved,
50                                    atomic_read(&journal->j_reserved_credits) + total <=
51                                    journal->j_max_transaction_buffers);
52 @@ -238,6 +238,7 @@ static int add_transaction_credits(journal_t *journal, int blocks,
53         if (jbd2_log_space_left(journal) < jbd2_space_needed(journal)) {
54                 atomic_sub(total, &t->t_outstanding_credits);
55                 read_unlock(&journal->j_state_lock);
56 +               jbd2_might_wait_for_commit(journal);
57                 write_lock(&journal->j_state_lock);
58                 if (jbd2_log_space_left(journal) < jbd2_space_needed(journal))
59                         __jbd2_log_wait_for_space(journal);
60 @@ -255,6 +256,7 @@ static int add_transaction_credits(journal_t *journal, int blocks,
61                 sub_reserved_credits(journal, rsv_blocks);
62                 atomic_sub(total, &t->t_outstanding_credits);
63                 read_unlock(&journal->j_state_lock);
64 +               jbd2_might_wait_for_commit(journal);
65                 wait_event(journal->j_wait_reserved,
66                          atomic_read(&journal->j_reserved_credits) + rsv_blocks
67                          <= journal->j_max_transaction_buffers / 2);
68 -- 
69 2.6.6