aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Mahoney <jeffm@suse.com>2014-04-23 10:01:02 -0400
committerJan Kara <jack@suse.cz>2014-05-13 10:08:54 -0400
commit83a3a56936667e8dbf2a43ceb380bc5a08d5fa0b (patch)
tree04531ce9bb783cde23f246ab88ced2b43c8d16be
parent441378c2bf4f3a510d1afba5bf9911cb40596b68 (diff)
reiserfs: balance_leaf refactor, split up balance_leaf_when_delete
Splut up balance_leaf_when_delete into: balance_leaf_when_delete_del balance_leaf_when_cut balance_leaf_when_delete_left Also reformat to adhere to CodingStyle. Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: Jan Kara <jack@suse.cz>
-rw-r--r--fs/reiserfs/do_balan.c318
1 files changed, 163 insertions, 155 deletions
diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
index 959b7b578f9d..547575c1c3c0 100644
--- a/fs/reiserfs/do_balan.c
+++ b/fs/reiserfs/do_balan.c
@@ -74,6 +74,159 @@ inline void do_balance_mark_leaf_dirty(struct tree_balance *tb,
74 * Note that all *num* count new items being created. 74 * Note that all *num* count new items being created.
75 */ 75 */
76 76
77static void balance_leaf_when_delete_del(struct tree_balance *tb)
78{
79 struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
80 int item_pos = PATH_LAST_POSITION(tb->tb_path);
81 struct buffer_info bi;
82#ifdef CONFIG_REISERFS_CHECK
83 struct item_head *ih = item_head(tbS0, item_pos);
84#endif
85
86 RFALSE(ih_item_len(ih) + IH_SIZE != -tb->insert_size[0],
87 "vs-12013: mode Delete, insert size %d, ih to be deleted %h",
88 -tb->insert_size[0], ih);
89
90 buffer_info_init_tbS0(tb, &bi);
91 leaf_delete_items(&bi, 0, item_pos, 1, -1);
92
93 if (!item_pos && tb->CFL[0]) {
94 if (B_NR_ITEMS(tbS0)) {
95 replace_key(tb, tb->CFL[0], tb->lkey[0], tbS0, 0);
96 } else {
97 if (!PATH_H_POSITION(tb->tb_path, 1))
98 replace_key(tb, tb->CFL[0], tb->lkey[0],
99 PATH_H_PPARENT(tb->tb_path, 0), 0);
100 }
101 }
102
103 RFALSE(!item_pos && !tb->CFL[0],
104 "PAP-12020: tb->CFL[0]==%p, tb->L[0]==%p", tb->CFL[0],
105 tb->L[0]);
106}
107
108/* cut item in S[0] */
109static void balance_leaf_when_delete_cut(struct tree_balance *tb)
110{
111 struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
112 int item_pos = PATH_LAST_POSITION(tb->tb_path);
113 struct item_head *ih = item_head(tbS0, item_pos);
114 int pos_in_item = tb->tb_path->pos_in_item;
115 struct buffer_info bi;
116 buffer_info_init_tbS0(tb, &bi);
117
118 if (is_direntry_le_ih(ih)) {
119 /*
120 * UFS unlink semantics are such that you can only
121 * delete one directory entry at a time.
122 *
123 * when we cut a directory tb->insert_size[0] means
124 * number of entries to be cut (always 1)
125 */
126 tb->insert_size[0] = -1;
127 leaf_cut_from_buffer(&bi, item_pos, pos_in_item,
128 -tb->insert_size[0]);
129
130 RFALSE(!item_pos && !pos_in_item && !tb->CFL[0],
131 "PAP-12030: can not change delimiting key. CFL[0]=%p",
132 tb->CFL[0]);
133
134 if (!item_pos && !pos_in_item && tb->CFL[0])
135 replace_key(tb, tb->CFL[0], tb->lkey[0], tbS0, 0);
136 } else {
137 leaf_cut_from_buffer(&bi, item_pos, pos_in_item,
138 -tb->insert_size[0]);
139
140 RFALSE(!ih_item_len(ih),
141 "PAP-12035: cut must leave non-zero dynamic "
142 "length of item");
143 }
144}
145
146static int balance_leaf_when_delete_left(struct tree_balance *tb)
147{
148 struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
149 int n = B_NR_ITEMS(tbS0);
150
151 /* L[0] must be joined with S[0] */
152 if (tb->lnum[0] == -1) {
153 /* R[0] must be also joined with S[0] */
154 if (tb->rnum[0] == -1) {
155 if (tb->FR[0] == PATH_H_PPARENT(tb->tb_path, 0)) {
156 /*
157 * all contents of all the
158 * 3 buffers will be in L[0]
159 */
160 if (PATH_H_POSITION(tb->tb_path, 1) == 0 &&
161 1 < B_NR_ITEMS(tb->FR[0]))
162 replace_key(tb, tb->CFL[0],
163 tb->lkey[0], tb->FR[0], 1);
164
165 leaf_move_items(LEAF_FROM_S_TO_L, tb, n, -1,
166 NULL);
167 leaf_move_items(LEAF_FROM_R_TO_L, tb,
168 B_NR_ITEMS(tb->R[0]), -1,
169 NULL);
170
171 reiserfs_invalidate_buffer(tb, tbS0);
172 reiserfs_invalidate_buffer(tb, tb->R[0]);
173
174 return 0;
175 }
176
177 /* all contents of all the 3 buffers will be in R[0] */
178 leaf_move_items(LEAF_FROM_S_TO_R, tb, n, -1, NULL);
179 leaf_move_items(LEAF_FROM_L_TO_R, tb,
180 B_NR_ITEMS(tb->L[0]), -1, NULL);
181
182 /* right_delimiting_key is correct in R[0] */
183 replace_key(tb, tb->CFR[0], tb->rkey[0], tb->R[0], 0);
184
185 reiserfs_invalidate_buffer(tb, tbS0);
186 reiserfs_invalidate_buffer(tb, tb->L[0]);
187
188 return -1;
189 }
190
191 RFALSE(tb->rnum[0] != 0,
192 "PAP-12045: rnum must be 0 (%d)", tb->rnum[0]);
193 /* all contents of L[0] and S[0] will be in L[0] */
194 leaf_shift_left(tb, n, -1);
195
196 reiserfs_invalidate_buffer(tb, tbS0);
197
198 return 0;
199 }
200
201 /*
202 * a part of contents of S[0] will be in L[0] and
203 * the rest part of S[0] will be in R[0]
204 */
205
206 RFALSE((tb->lnum[0] + tb->rnum[0] < n) ||
207 (tb->lnum[0] + tb->rnum[0] > n + 1),
208 "PAP-12050: rnum(%d) and lnum(%d) and item "
209 "number(%d) in S[0] are not consistent",
210 tb->rnum[0], tb->lnum[0], n);
211 RFALSE((tb->lnum[0] + tb->rnum[0] == n) &&
212 (tb->lbytes != -1 || tb->rbytes != -1),
213 "PAP-12055: bad rbytes (%d)/lbytes (%d) "
214 "parameters when items are not split",
215 tb->rbytes, tb->lbytes);
216 RFALSE((tb->lnum[0] + tb->rnum[0] == n + 1) &&
217 (tb->lbytes < 1 || tb->rbytes != -1),
218 "PAP-12060: bad rbytes (%d)/lbytes (%d) "
219 "parameters when items are split",
220 tb->rbytes, tb->lbytes);
221
222 leaf_shift_left(tb, tb->lnum[0], tb->lbytes);
223 leaf_shift_right(tb, tb->rnum[0], tb->rbytes);
224
225 reiserfs_invalidate_buffer(tb, tbS0);
226
227 return 0;
228}
229
77/* 230/*
78 * Balance leaf node in case of delete or cut: insert_size[0] < 0 231 * Balance leaf node in case of delete or cut: insert_size[0] < 0
79 * 232 *
@@ -87,7 +240,6 @@ static int balance_leaf_when_delete(struct tree_balance *tb, int flag)
87{ 240{
88 struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); 241 struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
89 int item_pos = PATH_LAST_POSITION(tb->tb_path); 242 int item_pos = PATH_LAST_POSITION(tb->tb_path);
90 int pos_in_item = tb->tb_path->pos_in_item;
91 struct buffer_info bi; 243 struct buffer_info bi;
92 int n; 244 int n;
93 struct item_head *ih; 245 struct item_head *ih;
@@ -104,166 +256,23 @@ static int balance_leaf_when_delete(struct tree_balance *tb, int flag)
104 256
105 /* Delete or truncate the item */ 257 /* Delete or truncate the item */
106 258
107 switch (flag) { 259 BUG_ON(flag != M_DELETE && flag != M_CUT);
108 case M_DELETE: /* delete item in S[0] */ 260 if (flag == M_DELETE)
109 261 balance_leaf_when_delete_del(tb);
110 RFALSE(ih_item_len(ih) + IH_SIZE != -tb->insert_size[0], 262 else /* M_CUT */
111 "vs-12013: mode Delete, insert size %d, ih to be deleted %h", 263 balance_leaf_when_delete_cut(tb);
112 -tb->insert_size[0], ih);
113
114 leaf_delete_items(&bi, 0, item_pos, 1, -1);
115
116 if (!item_pos && tb->CFL[0]) {
117 if (B_NR_ITEMS(tbS0)) {
118 replace_key(tb, tb->CFL[0], tb->lkey[0], tbS0,
119 0);
120 } else {
121 if (!PATH_H_POSITION(tb->tb_path, 1))
122 replace_key(tb, tb->CFL[0], tb->lkey[0],
123 PATH_H_PPARENT(tb->tb_path,
124 0), 0);
125 }
126 }
127
128 RFALSE(!item_pos && !tb->CFL[0],
129 "PAP-12020: tb->CFL[0]==%p, tb->L[0]==%p", tb->CFL[0],
130 tb->L[0]);
131
132 break;
133
134 case M_CUT:{ /* cut item in S[0] */
135 if (is_direntry_le_ih(ih)) {
136
137 /*
138 * UFS unlink semantics are such that you
139 * can only delete one directory entry at
140 * a time.
141 */
142
143 /*
144 * when we cut a directory tb->insert_size[0]
145 * means number of entries to be cut (always 1)
146 */
147 tb->insert_size[0] = -1;
148 leaf_cut_from_buffer(&bi, item_pos, pos_in_item,
149 -tb->insert_size[0]);
150
151 RFALSE(!item_pos && !pos_in_item && !tb->CFL[0],
152 "PAP-12030: can not change delimiting key. CFL[0]=%p",
153 tb->CFL[0]);
154
155 if (!item_pos && !pos_in_item && tb->CFL[0]) {
156 replace_key(tb, tb->CFL[0], tb->lkey[0],
157 tbS0, 0);
158 }
159 } else {
160 leaf_cut_from_buffer(&bi, item_pos, pos_in_item,
161 -tb->insert_size[0]);
162
163 RFALSE(!ih_item_len(ih),
164 "PAP-12035: cut must leave non-zero dynamic length of item");
165 }
166 break;
167 }
168 264
169 default:
170 print_cur_tb("12040");
171 reiserfs_panic(tb->tb_sb, "PAP-12040",
172 "unexpected mode: %s(%d)",
173 (flag ==
174 M_PASTE) ? "PASTE" : ((flag ==
175 M_INSERT) ? "INSERT" :
176 "UNKNOWN"), flag);
177 }
178 265
179 /* 266 /*
180 * the rule is that no shifting occurs unless by shifting 267 * the rule is that no shifting occurs unless by shifting
181 * a node can be freed 268 * a node can be freed
182 */ 269 */
183 n = B_NR_ITEMS(tbS0); 270 n = B_NR_ITEMS(tbS0);
184 /* L[0] takes part in balancing */
185 if (tb->lnum[0]) {
186 /* L[0] must be joined with S[0] */
187 if (tb->lnum[0] == -1) {
188 /* R[0] must be also joined with S[0] */
189 if (tb->rnum[0] == -1) {
190 if (tb->FR[0] == PATH_H_PPARENT(tb->tb_path, 0)) {
191 /*
192 * all contents of all the 3 buffers
193 * will be in L[0]
194 */
195 if (PATH_H_POSITION(tb->tb_path, 1) == 0
196 && 1 < B_NR_ITEMS(tb->FR[0]))
197 replace_key(tb, tb->CFL[0],
198 tb->lkey[0],
199 tb->FR[0], 1);
200
201 leaf_move_items(LEAF_FROM_S_TO_L, tb, n,
202 -1, NULL);
203 leaf_move_items(LEAF_FROM_R_TO_L, tb,
204 B_NR_ITEMS(tb->R[0]),
205 -1, NULL);
206
207 reiserfs_invalidate_buffer(tb, tbS0);
208 reiserfs_invalidate_buffer(tb,
209 tb->R[0]);
210
211 return 0;
212 }
213 /*
214 * all contents of all the 3 buffers will
215 * be in R[0]
216 */
217 leaf_move_items(LEAF_FROM_S_TO_R, tb, n, -1,
218 NULL);
219 leaf_move_items(LEAF_FROM_L_TO_R, tb,
220 B_NR_ITEMS(tb->L[0]), -1, NULL);
221 271
222 /* right_delimiting_key is correct in R[0] */
223 replace_key(tb, tb->CFR[0], tb->rkey[0],
224 tb->R[0], 0);
225 272
226 reiserfs_invalidate_buffer(tb, tbS0); 273 /* L[0] takes part in balancing */
227 reiserfs_invalidate_buffer(tb, tb->L[0]); 274 if (tb->lnum[0])
228 275 return balance_leaf_when_delete_left(tb);
229 return -1;
230 }
231
232 RFALSE(tb->rnum[0] != 0,
233 "PAP-12045: rnum must be 0 (%d)", tb->rnum[0]);
234 /* all contents of L[0] and S[0] will be in L[0] */
235 leaf_shift_left(tb, n, -1);
236
237 reiserfs_invalidate_buffer(tb, tbS0);
238
239 return 0;
240 }
241
242 /*
243 * a part of contents of S[0] will be in L[0] and the
244 * rest part of S[0] will be in R[0]
245 */
246
247 RFALSE((tb->lnum[0] + tb->rnum[0] < n) ||
248 (tb->lnum[0] + tb->rnum[0] > n + 1),
249 "PAP-12050: rnum(%d) and lnum(%d) and item number(%d) in S[0] are not consistent",
250 tb->rnum[0], tb->lnum[0], n);
251 RFALSE((tb->lnum[0] + tb->rnum[0] == n) &&
252 (tb->lbytes != -1 || tb->rbytes != -1),
253 "PAP-12055: bad rbytes (%d)/lbytes (%d) parameters when items are not split",
254 tb->rbytes, tb->lbytes);
255 RFALSE((tb->lnum[0] + tb->rnum[0] == n + 1) &&
256 (tb->lbytes < 1 || tb->rbytes != -1),
257 "PAP-12060: bad rbytes (%d)/lbytes (%d) parameters when items are split",
258 tb->rbytes, tb->lbytes);
259
260 leaf_shift_left(tb, tb->lnum[0], tb->lbytes);
261 leaf_shift_right(tb, tb->rnum[0], tb->rbytes);
262
263 reiserfs_invalidate_buffer(tb, tbS0);
264
265 return 0;
266 }
267 276
268 if (tb->rnum[0] == -1) { 277 if (tb->rnum[0] == -1) {
269 /* all contents of R[0] and S[0] will be in R[0] */ 278 /* all contents of R[0] and S[0] will be in R[0] */
@@ -1880,9 +1889,8 @@ void do_balance(struct tree_balance *tb, struct item_head *ih,
1880 1889
1881 /* Balance internal level of the tree. */ 1890 /* Balance internal level of the tree. */
1882 for (h = 1; h < MAX_HEIGHT && tb->insert_size[h]; h++) 1891 for (h = 1; h < MAX_HEIGHT && tb->insert_size[h]; h++)
1883 child_pos = 1892 child_pos = balance_internal(tb, h, child_pos, insert_key,
1884 balance_internal(tb, h, child_pos, insert_key, insert_ptr); 1893 insert_ptr);
1885 1894
1886 do_balance_completed(tb); 1895 do_balance_completed(tb);
1887
1888} 1896}