1 From: Jeff Mahoney <jeffm@suse.com>
2 Subject: reiserfs: cleanup path functions
4 This patch cleans up some redundancies in the reiserfs tree path code.
6 decrement_bcount() is essentially the same function as brelse(), so we use
9 decrement_counters_in_path() is exactly the same function as pathrelse(), so
10 we kill that and use pathrelse() instead.
12 There's also a bit of cleanup that makes the code a bit more readable.
14 Signed-off-by: Jeff Mahoney <jeffm@suse.com>
18 fs/reiserfs/fix_node.c | 58 ++++++++++++++++++++++++------------------------
19 fs/reiserfs/stree.c | 59 ++++++++++---------------------------------------
20 2 files changed, 43 insertions(+), 74 deletions(-)
22 --- a/fs/reiserfs/fix_node.c
23 +++ b/fs/reiserfs/fix_node.c
24 @@ -753,20 +753,21 @@ static void free_buffers_in_tb(struct tr
28 - decrement_counters_in_path(p_s_tb->tb_path);
29 + pathrelse(p_s_tb->tb_path);
31 for (n_counter = 0; n_counter < MAX_HEIGHT; n_counter++) {
32 - decrement_bcount(p_s_tb->L[n_counter]);
33 + brelse(p_s_tb->L[n_counter]);
34 + brelse(p_s_tb->R[n_counter]);
35 + brelse(p_s_tb->FL[n_counter]);
36 + brelse(p_s_tb->FR[n_counter]);
37 + brelse(p_s_tb->CFL[n_counter]);
38 + brelse(p_s_tb->CFR[n_counter]);
40 p_s_tb->L[n_counter] = NULL;
41 - decrement_bcount(p_s_tb->R[n_counter]);
42 p_s_tb->R[n_counter] = NULL;
43 - decrement_bcount(p_s_tb->FL[n_counter]);
44 p_s_tb->FL[n_counter] = NULL;
45 - decrement_bcount(p_s_tb->FR[n_counter]);
46 p_s_tb->FR[n_counter] = NULL;
47 - decrement_bcount(p_s_tb->CFL[n_counter]);
48 p_s_tb->CFL[n_counter] = NULL;
49 - decrement_bcount(p_s_tb->CFR[n_counter]);
50 p_s_tb->CFR[n_counter] = NULL;
53 @@ -1022,7 +1023,7 @@ static int get_far_parent(struct tree_ba
54 if (buffer_locked(*pp_s_com_father)) {
55 __wait_on_buffer(*pp_s_com_father);
56 if (FILESYSTEM_CHANGED_TB(p_s_tb)) {
57 - decrement_bcount(*pp_s_com_father);
58 + brelse(*pp_s_com_father);
62 @@ -1050,8 +1051,8 @@ static int get_far_parent(struct tree_ba
65 if (FILESYSTEM_CHANGED_TB(p_s_tb)) {
66 - decrement_counters_in_path(&s_path_to_neighbor_father);
67 - decrement_bcount(*pp_s_com_father);
68 + pathrelse(&s_path_to_neighbor_father);
69 + brelse(*pp_s_com_father);
73 @@ -1063,7 +1064,7 @@ static int get_far_parent(struct tree_ba
74 FIRST_PATH_ELEMENT_OFFSET, "PAP-8192: path length is too small");
76 s_path_to_neighbor_father.path_length--;
77 - decrement_counters_in_path(&s_path_to_neighbor_father);
78 + pathrelse(&s_path_to_neighbor_father);
82 @@ -1086,10 +1087,10 @@ static int get_parents(struct tree_balan
83 if (n_path_offset <= FIRST_PATH_ELEMENT_OFFSET) {
84 /* The root can not have parents.
85 Release nodes which previously were obtained as parents of the current node neighbors. */
86 - decrement_bcount(p_s_tb->FL[n_h]);
87 - decrement_bcount(p_s_tb->CFL[n_h]);
88 - decrement_bcount(p_s_tb->FR[n_h]);
89 - decrement_bcount(p_s_tb->CFR[n_h]);
90 + brelse(p_s_tb->FL[n_h]);
91 + brelse(p_s_tb->CFL[n_h]);
92 + brelse(p_s_tb->FR[n_h]);
93 + brelse(p_s_tb->CFR[n_h]);
94 p_s_tb->FL[n_h] = p_s_tb->CFL[n_h] = p_s_tb->FR[n_h] =
95 p_s_tb->CFR[n_h] = NULL;
97 @@ -1115,9 +1116,9 @@ static int get_parents(struct tree_balan
101 - decrement_bcount(p_s_tb->FL[n_h]);
102 + brelse(p_s_tb->FL[n_h]);
103 p_s_tb->FL[n_h] = p_s_curf; /* New initialization of FL[n_h]. */
104 - decrement_bcount(p_s_tb->CFL[n_h]);
105 + brelse(p_s_tb->CFL[n_h]);
106 p_s_tb->CFL[n_h] = p_s_curcf; /* New initialization of CFL[n_h]. */
108 RFALSE((p_s_curf && !B_IS_IN_TREE(p_s_curf)) ||
109 @@ -1145,10 +1146,10 @@ static int get_parents(struct tree_balan
110 p_s_tb->rkey[n_h] = n_position;
113 - decrement_bcount(p_s_tb->FR[n_h]);
114 + brelse(p_s_tb->FR[n_h]);
115 p_s_tb->FR[n_h] = p_s_curf; /* New initialization of FR[n_path_offset]. */
117 - decrement_bcount(p_s_tb->CFR[n_h]);
118 + brelse(p_s_tb->CFR[n_h]);
119 p_s_tb->CFR[n_h] = p_s_curcf; /* New initialization of CFR[n_path_offset]. */
121 RFALSE((p_s_curf && !B_IS_IN_TREE(p_s_curf)) ||
122 @@ -1964,7 +1965,7 @@ static int get_neighbors(struct tree_bal
125 if (FILESYSTEM_CHANGED_TB(p_s_tb)) {
126 - decrement_bcount(p_s_bh);
128 PROC_INFO_INC(p_s_sb, get_neighbors_restart[n_h]);
129 return REPEAT_SEARCH;
131 @@ -1980,7 +1981,7 @@ static int get_neighbors(struct tree_bal
132 dc_size(B_N_CHILD(p_s_tb->FL[0], n_child_position)),
133 "PAP-8290: invalid child size of left neighbor");
135 - decrement_bcount(p_s_tb->L[n_h]);
136 + brelse(p_s_tb->L[n_h]);
137 p_s_tb->L[n_h] = p_s_bh;
140 @@ -2001,11 +2002,11 @@ static int get_neighbors(struct tree_bal
143 if (FILESYSTEM_CHANGED_TB(p_s_tb)) {
144 - decrement_bcount(p_s_bh);
146 PROC_INFO_INC(p_s_sb, get_neighbors_restart[n_h]);
147 return REPEAT_SEARCH;
149 - decrement_bcount(p_s_tb->R[n_h]);
150 + brelse(p_s_tb->R[n_h]);
151 p_s_tb->R[n_h] = p_s_bh;
154 @@ -2511,16 +2512,17 @@ int fix_nodes(int n_op_mode, struct tree
157 brelse(p_s_tb->L[i]);
158 - p_s_tb->L[i] = NULL;
159 brelse(p_s_tb->R[i]);
160 - p_s_tb->R[i] = NULL;
161 brelse(p_s_tb->FL[i]);
162 - p_s_tb->FL[i] = NULL;
163 brelse(p_s_tb->FR[i]);
164 - p_s_tb->FR[i] = NULL;
165 brelse(p_s_tb->CFL[i]);
166 - p_s_tb->CFL[i] = NULL;
167 brelse(p_s_tb->CFR[i]);
169 + p_s_tb->L[i] = NULL;
170 + p_s_tb->R[i] = NULL;
171 + p_s_tb->FL[i] = NULL;
172 + p_s_tb->FR[i] = NULL;
173 + p_s_tb->CFL[i] = NULL;
174 p_s_tb->CFR[i] = NULL;
177 --- a/fs/reiserfs/stree.c
178 +++ b/fs/reiserfs/stree.c
183 - * decrement_counters_in_path
184 * reiserfs_check_path
185 * pathrelse_and_restore
187 @@ -359,36 +358,6 @@ static inline int key_in_buffer(struct t
191 -inline void decrement_bcount(struct buffer_head *p_s_bh)
194 - if (atomic_read(&(p_s_bh->b_count))) {
198 - reiserfs_panic(NULL, "PAP-5070",
199 - "trying to free free buffer %b", p_s_bh);
203 -/* Decrement b_count field of the all buffers in the path. */
204 -void decrement_counters_in_path(struct treepath *p_s_search_path)
206 - int n_path_offset = p_s_search_path->path_length;
208 - RFALSE(n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET ||
209 - n_path_offset > EXTENDED_MAX_HEIGHT - 1,
210 - "PAP-5080: invalid path offset of %d", n_path_offset);
212 - while (n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET) {
213 - struct buffer_head *bh;
215 - bh = PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--);
216 - decrement_bcount(bh);
218 - p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
221 int reiserfs_check_path(struct treepath *p)
223 RFALSE(p->path_length != ILLEGAL_PATH_ELEMENT_OFFSET,
224 @@ -396,12 +365,11 @@ int reiserfs_check_path(struct treepath
228 -/* Release all buffers in the path. Restore dirty bits clean
229 -** when preparing the buffer for the log
231 -** only called from fix_nodes()
233 -void pathrelse_and_restore(struct super_block *s, struct treepath *p_s_search_path)
234 +/* Drop the reference to each buffer in a path and restore
235 + * dirty bits clean when preparing the buffer for the log.
236 + * This version should only be called from fix_nodes() */
237 +void pathrelse_and_restore(struct super_block *sb,
238 + struct treepath *p_s_search_path)
240 int n_path_offset = p_s_search_path->path_length;
242 @@ -409,16 +377,15 @@ void pathrelse_and_restore(struct super_
243 "clm-4000: invalid path offset");
245 while (n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET) {
246 - reiserfs_restore_prepared_buffer(s,
247 - PATH_OFFSET_PBUFFER
250 - brelse(PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--));
251 + struct buffer_head *bh;
252 + bh = PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--);
253 + reiserfs_restore_prepared_buffer(sb, bh);
256 p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
259 -/* Release all buffers in the path. */
260 +/* Drop the reference to each buffer in a path */
261 void pathrelse(struct treepath *p_s_search_path)
263 int n_path_offset = p_s_search_path->path_length;
264 @@ -631,7 +598,7 @@ int search_by_key(struct super_block *p_
265 we must be careful to release all nodes in a path before we either
266 discard the path struct or re-use the path struct, as we do here. */
268 - decrement_counters_in_path(p_s_search_path);
269 + pathrelse(p_s_search_path);
271 right_neighbor_of_leaf_node = 0;
273 @@ -691,7 +658,7 @@ int search_by_key(struct super_block *p_
274 PROC_INFO_INC(p_s_sb, search_by_key_restarted);
275 PROC_INFO_INC(p_s_sb,
276 sbk_restarted[expected_level - 1]);
277 - decrement_counters_in_path(p_s_search_path);
278 + pathrelse(p_s_search_path);
280 /* Get the root block number so that we can repeat the search
281 starting from the root. */
282 @@ -1868,7 +1835,7 @@ int reiserfs_do_truncate(struct reiserfs
283 if (journal_transaction_should_end(th, 0) ||
284 reiserfs_transaction_free_space(th) <= JOURNAL_FOR_FREE_BLOCK_AND_UPDATE_SD) {
285 int orig_len_alloc = th->t_blocks_allocated;
286 - decrement_counters_in_path(&s_search_path);
287 + pathrelse(&s_search_path);
289 if (update_timestamps) {
290 p_s_inode->i_mtime = p_s_inode->i_ctime =