add patch dont-call-ext4_should_journal_data-on-journal-inode
[ext4-patch-queue.git] / move-lockdep-tracking-to-journal_s
blob30203230755c3a1079c0bd10b32522e49da1508d
1 jbd2: move lockdep tracking to journal_s
3 From: Jan Kara <jack@suse.cz>
5 Currently lockdep map is tracked in each journal handle. To be able to
6 expand lockdep support to cover also other cases where we depend on
7 transaction commit and where handle is not available, move lockdep map
8 into struct journal_s. Since this makes the lockdep map shared for all
9 handles, we have to use rwsem_acquire_read() for acquisitions now.
11 Signed-off-by: Jan Kara <jack@suse.cz>
12 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
13 ---
14  fs/jbd2/journal.c     |  4 ++++
15  fs/jbd2/transaction.c | 11 +++--------
16  include/linux/jbd2.h  | 17 +++++++++++++----
17  3 files changed, 20 insertions(+), 12 deletions(-)
19 diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
20 index b31852f..208e405 100644
21 --- a/fs/jbd2/journal.c
22 +++ b/fs/jbd2/journal.c
23 @@ -1091,6 +1091,7 @@ static void jbd2_stats_proc_exit(journal_t *journal)
25  static journal_t * journal_init_common (void)
26  {
27 +       static struct lock_class_key jbd2_trans_commit_key;
28         journal_t *journal;
29         int err;
31 @@ -1126,6 +1127,9 @@ static journal_t * journal_init_common (void)
33         spin_lock_init(&journal->j_history_lock);
35 +       lockdep_init_map(&journal->j_trans_commit_map, "jbd2_handle",
36 +                        &jbd2_trans_commit_key, 0);
38         return journal;
39  }
41 diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
42 index 4124953..c006504 100644
43 --- a/fs/jbd2/transaction.c
44 +++ b/fs/jbd2/transaction.c
45 @@ -382,13 +382,11 @@ repeat:
46         read_unlock(&journal->j_state_lock);
47         current->journal_info = handle;
49 -       lock_map_acquire(&handle->h_lockdep_map);
50 +       rwsem_acquire_read(&journal->j_trans_commit_map, 0, 0, _THIS_IP_);
51         jbd2_journal_free_transaction(new_transaction);
52         return 0;
53  }
55 -static struct lock_class_key jbd2_handle_key;
57  /* Allocate a new handle.  This should probably be in a slab... */
58  static handle_t *new_handle(int nblocks)
59  {
60 @@ -398,9 +396,6 @@ static handle_t *new_handle(int nblocks)
61         handle->h_buffer_credits = nblocks;
62         handle->h_ref = 1;
64 -       lockdep_init_map(&handle->h_lockdep_map, "jbd2_handle",
65 -                                               &jbd2_handle_key, 0);
67         return handle;
68  }
70 @@ -672,7 +667,7 @@ int jbd2__journal_restart(handle_t *handle, int nblocks, gfp_t gfp_mask)
71         if (need_to_start)
72                 jbd2_log_start_commit(journal, tid);
74 -       lock_map_release(&handle->h_lockdep_map);
75 +       rwsem_release(&journal->j_trans_commit_map, 1, _THIS_IP_);
76         handle->h_buffer_credits = nblocks;
77         ret = start_this_handle(journal, handle, gfp_mask);
78         return ret;
79 @@ -1750,7 +1745,7 @@ int jbd2_journal_stop(handle_t *handle)
80                         wake_up(&journal->j_wait_transaction_locked);
81         }
83 -       lock_map_release(&handle->h_lockdep_map);
84 +       rwsem_release(&journal->j_trans_commit_map, 1, _THIS_IP_);
86         if (wait_for_commit)
87                 err = jbd2_log_wait_commit(journal, tid);
88 diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
89 index efb232c..3d210cb 100644
90 --- a/include/linux/jbd2.h
91 +++ b/include/linux/jbd2.h
92 @@ -491,10 +491,6 @@ struct jbd2_journal_handle
94         unsigned long           h_start_jiffies;
95         unsigned int            h_requested_credits;
97 -#ifdef CONFIG_DEBUG_LOCK_ALLOC
98 -       struct lockdep_map      h_lockdep_map;
99 -#endif
100  };
103 @@ -793,6 +789,7 @@ jbd2_time_diff(unsigned long start, unsigned long end)
104   * @j_proc_entry: procfs entry for the jbd statistics directory
105   * @j_stats: Overall statistics
106   * @j_private: An opaque pointer to fs-private information.
107 + * @j_trans_commit_map: Lockdep entity to track transaction commit dependencies
108   */
110  struct journal_s
111 @@ -1035,6 +1032,18 @@ struct journal_s
113         /* Precomputed journal UUID checksum for seeding other checksums */
114         __u32 j_csum_seed;
116 +#ifdef CONFIG_DEBUG_LOCK_ALLOC
117 +       /*
118 +        * Lockdep entity to track transaction commit dependencies. Handles
119 +        * hold this "lock" for read, when we wait for commit, we acquire the
120 +        * "lock" for writing. This matches the properties of jbd2 journalling
121 +        * where the running transaction has to wait for all handles to be
122 +        * dropped to commit that transaction and also acquiring a handle may
123 +        * require transaction commit to finish.
124 +        */
125 +       struct lockdep_map      j_trans_commit_map;
126 +#endif
127  };
129  /* journal feature predicate functions */