add patch create-function-to-read-journal-inode
[ext4-patch-queue.git] / fix-lockdep-annotation-in-add_transaction_credits
blob3be4f3bd62d90fcafeba63fedddc1b8a8e7402d9
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 Fixes: 1eaa566d368b214d99cbb973647c1b0b8102a9ae
15 Reported-by: Thomas Gleixner <tglx@linutronix.de>
16 Signed-off-by: Jan Kara <jack@suse.cz>
17 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
18 ---
19  fs/jbd2/transaction.c | 6 ++++--
20  1 file changed, 4 insertions(+), 2 deletions(-)
22 diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
23 index b5bc3e249163..3d8246a9faa4 100644
24 --- a/fs/jbd2/transaction.c
25 +++ b/fs/jbd2/transaction.c
26 @@ -159,6 +159,7 @@ static void wait_transaction_locked(journal_t *journal)
27         read_unlock(&journal->j_state_lock);
28         if (need_to_start)
29                 jbd2_log_start_commit(journal, tid);
30 +       jbd2_might_wait_for_commit(journal);
31         schedule();
32         finish_wait(&journal->j_wait_transaction_locked, &wait);
33  }
34 @@ -182,8 +183,6 @@ static int add_transaction_credits(journal_t *journal, int blocks,
35         int needed;
36         int total = blocks + rsv_blocks;
38 -       jbd2_might_wait_for_commit(journal);
40         /*
41          * If the current transaction is locked down for commit, wait
42          * for the lock to be released.
43 @@ -214,6 +213,7 @@ static int add_transaction_credits(journal_t *journal, int blocks,
44                 if (atomic_read(&journal->j_reserved_credits) + total >
45                     journal->j_max_transaction_buffers) {
46                         read_unlock(&journal->j_state_lock);
47 +                       jbd2_might_wait_for_commit(journal);
48                         wait_event(journal->j_wait_reserved,
49                                    atomic_read(&journal->j_reserved_credits) + total <=
50                                    journal->j_max_transaction_buffers);
51 @@ -238,6 +238,7 @@ static int add_transaction_credits(journal_t *journal, int blocks,
52         if (jbd2_log_space_left(journal) < jbd2_space_needed(journal)) {
53                 atomic_sub(total, &t->t_outstanding_credits);
54                 read_unlock(&journal->j_state_lock);
55 +               jbd2_might_wait_for_commit(journal);
56                 write_lock(&journal->j_state_lock);
57                 if (jbd2_log_space_left(journal) < jbd2_space_needed(journal))
58                         __jbd2_log_wait_for_space(journal);
59 @@ -255,6 +256,7 @@ static int add_transaction_credits(journal_t *journal, int blocks,
60                 sub_reserved_credits(journal, rsv_blocks);
61                 atomic_sub(total, &t->t_outstanding_credits);
62                 read_unlock(&journal->j_state_lock);
63 +               jbd2_might_wait_for_commit(journal);
64                 wait_event(journal->j_wait_reserved,
65                          atomic_read(&journal->j_reserved_credits) + rsv_blocks
66                          <= journal->j_max_transaction_buffers / 2);
67 -- 
68 2.6.6