add patch ext2-file-fs-deadlock-while-reading-corrupted-xattr-block
[ext4-patch-queue.git] / track-more-dependencies-on-transaction-commit
blob3dfc0ae39d16c50ffbac1fac98a24b6af3096d84
1 jbd2: track more dependencies on transaction commit
3 From: Jan Kara <jack@suse.cz>
5 So far we were tracking only dependency on transaction commit due to
6 starting a new handle (which may require commit to start a new
7 transaction). Now add tracking also for other cases where we wait for
8 transaction commit. This way lockdep can catch deadlocks e. g. because we
9 call jbd2_journal_stop() for a synchronous handle with some locks held
10 which rank below transaction start.
12 Signed-off-by: Jan Kara <jack@suse.cz>
13 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
14 ---
15  fs/jbd2/journal.c     | 1 +
16  fs/jbd2/transaction.c | 4 ++++
17  include/linux/jbd2.h  | 6 ++++++
18  3 files changed, 11 insertions(+)
20 diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
21 index 208e4058040b..fc1d7a39b082 100644
22 --- a/fs/jbd2/journal.c
23 +++ b/fs/jbd2/journal.c
24 @@ -691,6 +691,7 @@ int jbd2_log_wait_commit(journal_t *journal, tid_t tid)
25  {
26         int err = 0;
28 +       jbd2_might_wait_for_commit(journal);
29         read_lock(&journal->j_state_lock);
30  #ifdef CONFIG_JBD2_DEBUG
31         if (!tid_geq(journal->j_commit_request, tid)) {
32 diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
33 index c0065040c5be..b5bc3e249163 100644
34 --- a/fs/jbd2/transaction.c
35 +++ b/fs/jbd2/transaction.c
36 @@ -182,6 +182,8 @@ static int add_transaction_credits(journal_t *journal, int blocks,
37         int needed;
38         int total = blocks + rsv_blocks;
40 +       jbd2_might_wait_for_commit(journal);
42         /*
43          * If the current transaction is locked down for commit, wait
44          * for the lock to be released.
45 @@ -695,6 +697,8 @@ void jbd2_journal_lock_updates(journal_t *journal)
46  {
47         DEFINE_WAIT(wait);
49 +       jbd2_might_wait_for_commit(journal);
51         write_lock(&journal->j_state_lock);
52         ++journal->j_barrier_count;
54 diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
55 index f6232b28eadc..64f8b594dd5a 100644
56 --- a/include/linux/jbd2.h
57 +++ b/include/linux/jbd2.h
58 @@ -1045,6 +1045,12 @@ struct journal_s
59  #endif
60  };
62 +#define jbd2_might_wait_for_commit(j) \
63 +       do { \
64 +               rwsem_acquire(&j->j_trans_commit_map, 0, 0, _THIS_IP_); \
65 +               rwsem_release(&j->j_trans_commit_map, 1, _THIS_IP_); \
66 +       } while (0)
68  /* journal feature predicate functions */
69  #define JBD2_FEATURE_COMPAT_FUNCS(name, flagname) \
70  static inline bool jbd2_has_feature_##name(journal_t *j) \
71 -- 
72 2.6.6