diff options
Diffstat (limited to 'fs/ocfs2/alloc.c')
-rw-r--r-- | fs/ocfs2/alloc.c | 922 |
1 files changed, 662 insertions, 260 deletions
diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c index 10bfb466e068..0cc2deb9394c 100644 --- a/fs/ocfs2/alloc.c +++ b/fs/ocfs2/alloc.c | |||
@@ -49,6 +49,340 @@ | |||
49 | 49 | ||
50 | #include "buffer_head_io.h" | 50 | #include "buffer_head_io.h" |
51 | 51 | ||
52 | |||
53 | /* | ||
54 | * Operations for a specific extent tree type. | ||
55 | * | ||
56 | * To implement an on-disk btree (extent tree) type in ocfs2, add | ||
57 | * an ocfs2_extent_tree_operations structure and the matching | ||
58 | * ocfs2_init_<thingy>_extent_tree() function. That's pretty much it | ||
59 | * for the allocation portion of the extent tree. | ||
60 | */ | ||
61 | struct ocfs2_extent_tree_operations { | ||
62 | /* | ||
63 | * last_eb_blk is the block number of the right most leaf extent | ||
64 | * block. Most on-disk structures containing an extent tree store | ||
65 | * this value for fast access. The ->eo_set_last_eb_blk() and | ||
66 | * ->eo_get_last_eb_blk() operations access this value. They are | ||
67 | * both required. | ||
68 | */ | ||
69 | void (*eo_set_last_eb_blk)(struct ocfs2_extent_tree *et, | ||
70 | u64 blkno); | ||
71 | u64 (*eo_get_last_eb_blk)(struct ocfs2_extent_tree *et); | ||
72 | |||
73 | /* | ||
74 | * The on-disk structure usually keeps track of how many total | ||
75 | * clusters are stored in this extent tree. This function updates | ||
76 | * that value. new_clusters is the delta, and must be | ||
77 | * added to the total. Required. | ||
78 | */ | ||
79 | void (*eo_update_clusters)(struct inode *inode, | ||
80 | struct ocfs2_extent_tree *et, | ||
81 | u32 new_clusters); | ||
82 | |||
83 | /* | ||
84 | * If ->eo_insert_check() exists, it is called before rec is | ||
85 | * inserted into the extent tree. It is optional. | ||
86 | */ | ||
87 | int (*eo_insert_check)(struct inode *inode, | ||
88 | struct ocfs2_extent_tree *et, | ||
89 | struct ocfs2_extent_rec *rec); | ||
90 | int (*eo_sanity_check)(struct inode *inode, struct ocfs2_extent_tree *et); | ||
91 | |||
92 | /* | ||
93 | * -------------------------------------------------------------- | ||
94 | * The remaining are internal to ocfs2_extent_tree and don't have | ||
95 | * accessor functions | ||
96 | */ | ||
97 | |||
98 | /* | ||
99 | * ->eo_fill_root_el() takes et->et_object and sets et->et_root_el. | ||
100 | * It is required. | ||
101 | */ | ||
102 | void (*eo_fill_root_el)(struct ocfs2_extent_tree *et); | ||
103 | |||
104 | /* | ||
105 | * ->eo_fill_max_leaf_clusters sets et->et_max_leaf_clusters if | ||
106 | * it exists. If it does not, et->et_max_leaf_clusters is set | ||
107 | * to 0 (unlimited). Optional. | ||
108 | */ | ||
109 | void (*eo_fill_max_leaf_clusters)(struct inode *inode, | ||
110 | struct ocfs2_extent_tree *et); | ||
111 | }; | ||
112 | |||
113 | |||
114 | /* | ||
115 | * Pre-declare ocfs2_dinode_et_ops so we can use it as a sanity check | ||
116 | * in the methods. | ||
117 | */ | ||
118 | static u64 ocfs2_dinode_get_last_eb_blk(struct ocfs2_extent_tree *et); | ||
119 | static void ocfs2_dinode_set_last_eb_blk(struct ocfs2_extent_tree *et, | ||
120 | u64 blkno); | ||
121 | static void ocfs2_dinode_update_clusters(struct inode *inode, | ||
122 | struct ocfs2_extent_tree *et, | ||
123 | u32 clusters); | ||
124 | static int ocfs2_dinode_insert_check(struct inode *inode, | ||
125 | struct ocfs2_extent_tree *et, | ||
126 | struct ocfs2_extent_rec *rec); | ||
127 | static int ocfs2_dinode_sanity_check(struct inode *inode, | ||
128 | struct ocfs2_extent_tree *et); | ||
129 | static void ocfs2_dinode_fill_root_el(struct ocfs2_extent_tree *et); | ||
130 | static struct ocfs2_extent_tree_operations ocfs2_dinode_et_ops = { | ||
131 | .eo_set_last_eb_blk = ocfs2_dinode_set_last_eb_blk, | ||
132 | .eo_get_last_eb_blk = ocfs2_dinode_get_last_eb_blk, | ||
133 | .eo_update_clusters = ocfs2_dinode_update_clusters, | ||
134 | .eo_insert_check = ocfs2_dinode_insert_check, | ||
135 | .eo_sanity_check = ocfs2_dinode_sanity_check, | ||
136 | .eo_fill_root_el = ocfs2_dinode_fill_root_el, | ||
137 | }; | ||
138 | |||
139 | static void ocfs2_dinode_set_last_eb_blk(struct ocfs2_extent_tree *et, | ||
140 | u64 blkno) | ||
141 | { | ||
142 | struct ocfs2_dinode *di = et->et_object; | ||
143 | |||
144 | BUG_ON(et->et_ops != &ocfs2_dinode_et_ops); | ||
145 | di->i_last_eb_blk = cpu_to_le64(blkno); | ||
146 | } | ||
147 | |||
148 | static u64 ocfs2_dinode_get_last_eb_blk(struct ocfs2_extent_tree *et) | ||
149 | { | ||
150 | struct ocfs2_dinode *di = et->et_object; | ||
151 | |||
152 | BUG_ON(et->et_ops != &ocfs2_dinode_et_ops); | ||
153 | return le64_to_cpu(di->i_last_eb_blk); | ||
154 | } | ||
155 | |||
156 | static void ocfs2_dinode_update_clusters(struct inode *inode, | ||
157 | struct ocfs2_extent_tree *et, | ||
158 | u32 clusters) | ||
159 | { | ||
160 | struct ocfs2_dinode *di = et->et_object; | ||
161 | |||
162 | le32_add_cpu(&di->i_clusters, clusters); | ||
163 | spin_lock(&OCFS2_I(inode)->ip_lock); | ||
164 | OCFS2_I(inode)->ip_clusters = le32_to_cpu(di->i_clusters); | ||
165 | spin_unlock(&OCFS2_I(inode)->ip_lock); | ||
166 | } | ||
167 | |||
168 | static int ocfs2_dinode_insert_check(struct inode *inode, | ||
169 | struct ocfs2_extent_tree *et, | ||
170 | struct ocfs2_extent_rec *rec) | ||
171 | { | ||
172 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
173 | |||
174 | BUG_ON(OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL); | ||
175 | mlog_bug_on_msg(!ocfs2_sparse_alloc(osb) && | ||
176 | (OCFS2_I(inode)->ip_clusters != rec->e_cpos), | ||
177 | "Device %s, asking for sparse allocation: inode %llu, " | ||
178 | "cpos %u, clusters %u\n", | ||
179 | osb->dev_str, | ||
180 | (unsigned long long)OCFS2_I(inode)->ip_blkno, | ||
181 | rec->e_cpos, | ||
182 | OCFS2_I(inode)->ip_clusters); | ||
183 | |||
184 | return 0; | ||
185 | } | ||
186 | |||
187 | static int ocfs2_dinode_sanity_check(struct inode *inode, | ||
188 | struct ocfs2_extent_tree *et) | ||
189 | { | ||
190 | int ret = 0; | ||
191 | struct ocfs2_dinode *di; | ||
192 | |||
193 | BUG_ON(et->et_ops != &ocfs2_dinode_et_ops); | ||
194 | |||
195 | di = et->et_object; | ||
196 | if (!OCFS2_IS_VALID_DINODE(di)) { | ||
197 | ret = -EIO; | ||
198 | ocfs2_error(inode->i_sb, | ||
199 | "Inode %llu has invalid path root", | ||
200 | (unsigned long long)OCFS2_I(inode)->ip_blkno); | ||
201 | } | ||
202 | |||
203 | return ret; | ||
204 | } | ||
205 | |||
206 | static void ocfs2_dinode_fill_root_el(struct ocfs2_extent_tree *et) | ||
207 | { | ||
208 | struct ocfs2_dinode *di = et->et_object; | ||
209 | |||
210 | et->et_root_el = &di->id2.i_list; | ||
211 | } | ||
212 | |||
213 | |||
214 | static void ocfs2_xattr_value_fill_root_el(struct ocfs2_extent_tree *et) | ||
215 | { | ||
216 | struct ocfs2_xattr_value_root *xv = et->et_object; | ||
217 | |||
218 | et->et_root_el = &xv->xr_list; | ||
219 | } | ||
220 | |||
221 | static void ocfs2_xattr_value_set_last_eb_blk(struct ocfs2_extent_tree *et, | ||
222 | u64 blkno) | ||
223 | { | ||
224 | struct ocfs2_xattr_value_root *xv = | ||
225 | (struct ocfs2_xattr_value_root *)et->et_object; | ||
226 | |||
227 | xv->xr_last_eb_blk = cpu_to_le64(blkno); | ||
228 | } | ||
229 | |||
230 | static u64 ocfs2_xattr_value_get_last_eb_blk(struct ocfs2_extent_tree *et) | ||
231 | { | ||
232 | struct ocfs2_xattr_value_root *xv = | ||
233 | (struct ocfs2_xattr_value_root *) et->et_object; | ||
234 | |||
235 | return le64_to_cpu(xv->xr_last_eb_blk); | ||
236 | } | ||
237 | |||
238 | static void ocfs2_xattr_value_update_clusters(struct inode *inode, | ||
239 | struct ocfs2_extent_tree *et, | ||
240 | u32 clusters) | ||
241 | { | ||
242 | struct ocfs2_xattr_value_root *xv = | ||
243 | (struct ocfs2_xattr_value_root *)et->et_object; | ||
244 | |||
245 | le32_add_cpu(&xv->xr_clusters, clusters); | ||
246 | } | ||
247 | |||
248 | static struct ocfs2_extent_tree_operations ocfs2_xattr_value_et_ops = { | ||
249 | .eo_set_last_eb_blk = ocfs2_xattr_value_set_last_eb_blk, | ||
250 | .eo_get_last_eb_blk = ocfs2_xattr_value_get_last_eb_blk, | ||
251 | .eo_update_clusters = ocfs2_xattr_value_update_clusters, | ||
252 | .eo_fill_root_el = ocfs2_xattr_value_fill_root_el, | ||
253 | }; | ||
254 | |||
255 | static void ocfs2_xattr_tree_fill_root_el(struct ocfs2_extent_tree *et) | ||
256 | { | ||
257 | struct ocfs2_xattr_block *xb = et->et_object; | ||
258 | |||
259 | et->et_root_el = &xb->xb_attrs.xb_root.xt_list; | ||
260 | } | ||
261 | |||
262 | static void ocfs2_xattr_tree_fill_max_leaf_clusters(struct inode *inode, | ||
263 | struct ocfs2_extent_tree *et) | ||
264 | { | ||
265 | et->et_max_leaf_clusters = | ||
266 | ocfs2_clusters_for_bytes(inode->i_sb, | ||
267 | OCFS2_MAX_XATTR_TREE_LEAF_SIZE); | ||
268 | } | ||
269 | |||
270 | static void ocfs2_xattr_tree_set_last_eb_blk(struct ocfs2_extent_tree *et, | ||
271 | u64 blkno) | ||
272 | { | ||
273 | struct ocfs2_xattr_block *xb = et->et_object; | ||
274 | struct ocfs2_xattr_tree_root *xt = &xb->xb_attrs.xb_root; | ||
275 | |||
276 | xt->xt_last_eb_blk = cpu_to_le64(blkno); | ||
277 | } | ||
278 | |||
279 | static u64 ocfs2_xattr_tree_get_last_eb_blk(struct ocfs2_extent_tree *et) | ||
280 | { | ||
281 | struct ocfs2_xattr_block *xb = et->et_object; | ||
282 | struct ocfs2_xattr_tree_root *xt = &xb->xb_attrs.xb_root; | ||
283 | |||
284 | return le64_to_cpu(xt->xt_last_eb_blk); | ||
285 | } | ||
286 | |||
287 | static void ocfs2_xattr_tree_update_clusters(struct inode *inode, | ||
288 | struct ocfs2_extent_tree *et, | ||
289 | u32 clusters) | ||
290 | { | ||
291 | struct ocfs2_xattr_block *xb = et->et_object; | ||
292 | |||
293 | le32_add_cpu(&xb->xb_attrs.xb_root.xt_clusters, clusters); | ||
294 | } | ||
295 | |||
296 | static struct ocfs2_extent_tree_operations ocfs2_xattr_tree_et_ops = { | ||
297 | .eo_set_last_eb_blk = ocfs2_xattr_tree_set_last_eb_blk, | ||
298 | .eo_get_last_eb_blk = ocfs2_xattr_tree_get_last_eb_blk, | ||
299 | .eo_update_clusters = ocfs2_xattr_tree_update_clusters, | ||
300 | .eo_fill_root_el = ocfs2_xattr_tree_fill_root_el, | ||
301 | .eo_fill_max_leaf_clusters = ocfs2_xattr_tree_fill_max_leaf_clusters, | ||
302 | }; | ||
303 | |||
304 | static void __ocfs2_init_extent_tree(struct ocfs2_extent_tree *et, | ||
305 | struct inode *inode, | ||
306 | struct buffer_head *bh, | ||
307 | void *obj, | ||
308 | struct ocfs2_extent_tree_operations *ops) | ||
309 | { | ||
310 | et->et_ops = ops; | ||
311 | et->et_root_bh = bh; | ||
312 | if (!obj) | ||
313 | obj = (void *)bh->b_data; | ||
314 | et->et_object = obj; | ||
315 | |||
316 | et->et_ops->eo_fill_root_el(et); | ||
317 | if (!et->et_ops->eo_fill_max_leaf_clusters) | ||
318 | et->et_max_leaf_clusters = 0; | ||
319 | else | ||
320 | et->et_ops->eo_fill_max_leaf_clusters(inode, et); | ||
321 | } | ||
322 | |||
323 | void ocfs2_init_dinode_extent_tree(struct ocfs2_extent_tree *et, | ||
324 | struct inode *inode, | ||
325 | struct buffer_head *bh) | ||
326 | { | ||
327 | __ocfs2_init_extent_tree(et, inode, bh, NULL, &ocfs2_dinode_et_ops); | ||
328 | } | ||
329 | |||
330 | void ocfs2_init_xattr_tree_extent_tree(struct ocfs2_extent_tree *et, | ||
331 | struct inode *inode, | ||
332 | struct buffer_head *bh) | ||
333 | { | ||
334 | __ocfs2_init_extent_tree(et, inode, bh, NULL, | ||
335 | &ocfs2_xattr_tree_et_ops); | ||
336 | } | ||
337 | |||
338 | void ocfs2_init_xattr_value_extent_tree(struct ocfs2_extent_tree *et, | ||
339 | struct inode *inode, | ||
340 | struct buffer_head *bh, | ||
341 | struct ocfs2_xattr_value_root *xv) | ||
342 | { | ||
343 | __ocfs2_init_extent_tree(et, inode, bh, xv, | ||
344 | &ocfs2_xattr_value_et_ops); | ||
345 | } | ||
346 | |||
347 | static inline void ocfs2_et_set_last_eb_blk(struct ocfs2_extent_tree *et, | ||
348 | u64 new_last_eb_blk) | ||
349 | { | ||
350 | et->et_ops->eo_set_last_eb_blk(et, new_last_eb_blk); | ||
351 | } | ||
352 | |||
353 | static inline u64 ocfs2_et_get_last_eb_blk(struct ocfs2_extent_tree *et) | ||
354 | { | ||
355 | return et->et_ops->eo_get_last_eb_blk(et); | ||
356 | } | ||
357 | |||
358 | static inline void ocfs2_et_update_clusters(struct inode *inode, | ||
359 | struct ocfs2_extent_tree *et, | ||
360 | u32 clusters) | ||
361 | { | ||
362 | et->et_ops->eo_update_clusters(inode, et, clusters); | ||
363 | } | ||
364 | |||
365 | static inline int ocfs2_et_insert_check(struct inode *inode, | ||
366 | struct ocfs2_extent_tree *et, | ||
367 | struct ocfs2_extent_rec *rec) | ||
368 | { | ||
369 | int ret = 0; | ||
370 | |||
371 | if (et->et_ops->eo_insert_check) | ||
372 | ret = et->et_ops->eo_insert_check(inode, et, rec); | ||
373 | return ret; | ||
374 | } | ||
375 | |||
376 | static inline int ocfs2_et_sanity_check(struct inode *inode, | ||
377 | struct ocfs2_extent_tree *et) | ||
378 | { | ||
379 | int ret = 0; | ||
380 | |||
381 | if (et->et_ops->eo_sanity_check) | ||
382 | ret = et->et_ops->eo_sanity_check(inode, et); | ||
383 | return ret; | ||
384 | } | ||
385 | |||
52 | static void ocfs2_free_truncate_context(struct ocfs2_truncate_context *tc); | 386 | static void ocfs2_free_truncate_context(struct ocfs2_truncate_context *tc); |
53 | static int ocfs2_cache_extent_block_free(struct ocfs2_cached_dealloc_ctxt *ctxt, | 387 | static int ocfs2_cache_extent_block_free(struct ocfs2_cached_dealloc_ctxt *ctxt, |
54 | struct ocfs2_extent_block *eb); | 388 | struct ocfs2_extent_block *eb); |
@@ -205,17 +539,6 @@ static struct ocfs2_path *ocfs2_new_path(struct buffer_head *root_bh, | |||
205 | } | 539 | } |
206 | 540 | ||
207 | /* | 541 | /* |
208 | * Allocate and initialize a new path based on a disk inode tree. | ||
209 | */ | ||
210 | static struct ocfs2_path *ocfs2_new_inode_path(struct buffer_head *di_bh) | ||
211 | { | ||
212 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; | ||
213 | struct ocfs2_extent_list *el = &di->id2.i_list; | ||
214 | |||
215 | return ocfs2_new_path(di_bh, el); | ||
216 | } | ||
217 | |||
218 | /* | ||
219 | * Convenience function to journal all components in a path. | 542 | * Convenience function to journal all components in a path. |
220 | */ | 543 | */ |
221 | static int ocfs2_journal_access_path(struct inode *inode, handle_t *handle, | 544 | static int ocfs2_journal_access_path(struct inode *inode, handle_t *handle, |
@@ -368,39 +691,35 @@ struct ocfs2_merge_ctxt { | |||
368 | */ | 691 | */ |
369 | int ocfs2_num_free_extents(struct ocfs2_super *osb, | 692 | int ocfs2_num_free_extents(struct ocfs2_super *osb, |
370 | struct inode *inode, | 693 | struct inode *inode, |
371 | struct ocfs2_dinode *fe) | 694 | struct ocfs2_extent_tree *et) |
372 | { | 695 | { |
373 | int retval; | 696 | int retval; |
374 | struct ocfs2_extent_list *el; | 697 | struct ocfs2_extent_list *el = NULL; |
375 | struct ocfs2_extent_block *eb; | 698 | struct ocfs2_extent_block *eb; |
376 | struct buffer_head *eb_bh = NULL; | 699 | struct buffer_head *eb_bh = NULL; |
700 | u64 last_eb_blk = 0; | ||
377 | 701 | ||
378 | mlog_entry_void(); | 702 | mlog_entry_void(); |
379 | 703 | ||
380 | if (!OCFS2_IS_VALID_DINODE(fe)) { | 704 | el = et->et_root_el; |
381 | OCFS2_RO_ON_INVALID_DINODE(inode->i_sb, fe); | 705 | last_eb_blk = ocfs2_et_get_last_eb_blk(et); |
382 | retval = -EIO; | ||
383 | goto bail; | ||
384 | } | ||
385 | 706 | ||
386 | if (fe->i_last_eb_blk) { | 707 | if (last_eb_blk) { |
387 | retval = ocfs2_read_block(osb, le64_to_cpu(fe->i_last_eb_blk), | 708 | retval = ocfs2_read_block(inode, last_eb_blk, |
388 | &eb_bh, OCFS2_BH_CACHED, inode); | 709 | &eb_bh); |
389 | if (retval < 0) { | 710 | if (retval < 0) { |
390 | mlog_errno(retval); | 711 | mlog_errno(retval); |
391 | goto bail; | 712 | goto bail; |
392 | } | 713 | } |
393 | eb = (struct ocfs2_extent_block *) eb_bh->b_data; | 714 | eb = (struct ocfs2_extent_block *) eb_bh->b_data; |
394 | el = &eb->h_list; | 715 | el = &eb->h_list; |
395 | } else | 716 | } |
396 | el = &fe->id2.i_list; | ||
397 | 717 | ||
398 | BUG_ON(el->l_tree_depth != 0); | 718 | BUG_ON(el->l_tree_depth != 0); |
399 | 719 | ||
400 | retval = le16_to_cpu(el->l_count) - le16_to_cpu(el->l_next_free_rec); | 720 | retval = le16_to_cpu(el->l_count) - le16_to_cpu(el->l_next_free_rec); |
401 | bail: | 721 | bail: |
402 | if (eb_bh) | 722 | brelse(eb_bh); |
403 | brelse(eb_bh); | ||
404 | 723 | ||
405 | mlog_exit(retval); | 724 | mlog_exit(retval); |
406 | return retval; | 725 | return retval; |
@@ -486,8 +805,7 @@ static int ocfs2_create_new_meta_bhs(struct ocfs2_super *osb, | |||
486 | bail: | 805 | bail: |
487 | if (status < 0) { | 806 | if (status < 0) { |
488 | for(i = 0; i < wanted; i++) { | 807 | for(i = 0; i < wanted; i++) { |
489 | if (bhs[i]) | 808 | brelse(bhs[i]); |
490 | brelse(bhs[i]); | ||
491 | bhs[i] = NULL; | 809 | bhs[i] = NULL; |
492 | } | 810 | } |
493 | } | 811 | } |
@@ -531,7 +849,7 @@ static inline u32 ocfs2_sum_rightmost_rec(struct ocfs2_extent_list *el) | |||
531 | static int ocfs2_add_branch(struct ocfs2_super *osb, | 849 | static int ocfs2_add_branch(struct ocfs2_super *osb, |
532 | handle_t *handle, | 850 | handle_t *handle, |
533 | struct inode *inode, | 851 | struct inode *inode, |
534 | struct buffer_head *fe_bh, | 852 | struct ocfs2_extent_tree *et, |
535 | struct buffer_head *eb_bh, | 853 | struct buffer_head *eb_bh, |
536 | struct buffer_head **last_eb_bh, | 854 | struct buffer_head **last_eb_bh, |
537 | struct ocfs2_alloc_context *meta_ac) | 855 | struct ocfs2_alloc_context *meta_ac) |
@@ -540,7 +858,6 @@ static int ocfs2_add_branch(struct ocfs2_super *osb, | |||
540 | u64 next_blkno, new_last_eb_blk; | 858 | u64 next_blkno, new_last_eb_blk; |
541 | struct buffer_head *bh; | 859 | struct buffer_head *bh; |
542 | struct buffer_head **new_eb_bhs = NULL; | 860 | struct buffer_head **new_eb_bhs = NULL; |
543 | struct ocfs2_dinode *fe; | ||
544 | struct ocfs2_extent_block *eb; | 861 | struct ocfs2_extent_block *eb; |
545 | struct ocfs2_extent_list *eb_el; | 862 | struct ocfs2_extent_list *eb_el; |
546 | struct ocfs2_extent_list *el; | 863 | struct ocfs2_extent_list *el; |
@@ -550,13 +867,11 @@ static int ocfs2_add_branch(struct ocfs2_super *osb, | |||
550 | 867 | ||
551 | BUG_ON(!last_eb_bh || !*last_eb_bh); | 868 | BUG_ON(!last_eb_bh || !*last_eb_bh); |
552 | 869 | ||
553 | fe = (struct ocfs2_dinode *) fe_bh->b_data; | ||
554 | |||
555 | if (eb_bh) { | 870 | if (eb_bh) { |
556 | eb = (struct ocfs2_extent_block *) eb_bh->b_data; | 871 | eb = (struct ocfs2_extent_block *) eb_bh->b_data; |
557 | el = &eb->h_list; | 872 | el = &eb->h_list; |
558 | } else | 873 | } else |
559 | el = &fe->id2.i_list; | 874 | el = et->et_root_el; |
560 | 875 | ||
561 | /* we never add a branch to a leaf. */ | 876 | /* we never add a branch to a leaf. */ |
562 | BUG_ON(!el->l_tree_depth); | 877 | BUG_ON(!el->l_tree_depth); |
@@ -646,7 +961,7 @@ static int ocfs2_add_branch(struct ocfs2_super *osb, | |||
646 | mlog_errno(status); | 961 | mlog_errno(status); |
647 | goto bail; | 962 | goto bail; |
648 | } | 963 | } |
649 | status = ocfs2_journal_access(handle, inode, fe_bh, | 964 | status = ocfs2_journal_access(handle, inode, et->et_root_bh, |
650 | OCFS2_JOURNAL_ACCESS_WRITE); | 965 | OCFS2_JOURNAL_ACCESS_WRITE); |
651 | if (status < 0) { | 966 | if (status < 0) { |
652 | mlog_errno(status); | 967 | mlog_errno(status); |
@@ -662,7 +977,7 @@ static int ocfs2_add_branch(struct ocfs2_super *osb, | |||
662 | } | 977 | } |
663 | 978 | ||
664 | /* Link the new branch into the rest of the tree (el will | 979 | /* Link the new branch into the rest of the tree (el will |
665 | * either be on the fe, or the extent block passed in. */ | 980 | * either be on the root_bh, or the extent block passed in. */ |
666 | i = le16_to_cpu(el->l_next_free_rec); | 981 | i = le16_to_cpu(el->l_next_free_rec); |
667 | el->l_recs[i].e_blkno = cpu_to_le64(next_blkno); | 982 | el->l_recs[i].e_blkno = cpu_to_le64(next_blkno); |
668 | el->l_recs[i].e_cpos = cpu_to_le32(new_cpos); | 983 | el->l_recs[i].e_cpos = cpu_to_le32(new_cpos); |
@@ -671,7 +986,7 @@ static int ocfs2_add_branch(struct ocfs2_super *osb, | |||
671 | 986 | ||
672 | /* fe needs a new last extent block pointer, as does the | 987 | /* fe needs a new last extent block pointer, as does the |
673 | * next_leaf on the previously last-extent-block. */ | 988 | * next_leaf on the previously last-extent-block. */ |
674 | fe->i_last_eb_blk = cpu_to_le64(new_last_eb_blk); | 989 | ocfs2_et_set_last_eb_blk(et, new_last_eb_blk); |
675 | 990 | ||
676 | eb = (struct ocfs2_extent_block *) (*last_eb_bh)->b_data; | 991 | eb = (struct ocfs2_extent_block *) (*last_eb_bh)->b_data; |
677 | eb->h_next_leaf_blk = cpu_to_le64(new_last_eb_blk); | 992 | eb->h_next_leaf_blk = cpu_to_le64(new_last_eb_blk); |
@@ -679,7 +994,7 @@ static int ocfs2_add_branch(struct ocfs2_super *osb, | |||
679 | status = ocfs2_journal_dirty(handle, *last_eb_bh); | 994 | status = ocfs2_journal_dirty(handle, *last_eb_bh); |
680 | if (status < 0) | 995 | if (status < 0) |
681 | mlog_errno(status); | 996 | mlog_errno(status); |
682 | status = ocfs2_journal_dirty(handle, fe_bh); | 997 | status = ocfs2_journal_dirty(handle, et->et_root_bh); |
683 | if (status < 0) | 998 | if (status < 0) |
684 | mlog_errno(status); | 999 | mlog_errno(status); |
685 | if (eb_bh) { | 1000 | if (eb_bh) { |
@@ -700,8 +1015,7 @@ static int ocfs2_add_branch(struct ocfs2_super *osb, | |||
700 | bail: | 1015 | bail: |
701 | if (new_eb_bhs) { | 1016 | if (new_eb_bhs) { |
702 | for (i = 0; i < new_blocks; i++) | 1017 | for (i = 0; i < new_blocks; i++) |
703 | if (new_eb_bhs[i]) | 1018 | brelse(new_eb_bhs[i]); |
704 | brelse(new_eb_bhs[i]); | ||
705 | kfree(new_eb_bhs); | 1019 | kfree(new_eb_bhs); |
706 | } | 1020 | } |
707 | 1021 | ||
@@ -717,16 +1031,15 @@ bail: | |||
717 | static int ocfs2_shift_tree_depth(struct ocfs2_super *osb, | 1031 | static int ocfs2_shift_tree_depth(struct ocfs2_super *osb, |
718 | handle_t *handle, | 1032 | handle_t *handle, |
719 | struct inode *inode, | 1033 | struct inode *inode, |
720 | struct buffer_head *fe_bh, | 1034 | struct ocfs2_extent_tree *et, |
721 | struct ocfs2_alloc_context *meta_ac, | 1035 | struct ocfs2_alloc_context *meta_ac, |
722 | struct buffer_head **ret_new_eb_bh) | 1036 | struct buffer_head **ret_new_eb_bh) |
723 | { | 1037 | { |
724 | int status, i; | 1038 | int status, i; |
725 | u32 new_clusters; | 1039 | u32 new_clusters; |
726 | struct buffer_head *new_eb_bh = NULL; | 1040 | struct buffer_head *new_eb_bh = NULL; |
727 | struct ocfs2_dinode *fe; | ||
728 | struct ocfs2_extent_block *eb; | 1041 | struct ocfs2_extent_block *eb; |
729 | struct ocfs2_extent_list *fe_el; | 1042 | struct ocfs2_extent_list *root_el; |
730 | struct ocfs2_extent_list *eb_el; | 1043 | struct ocfs2_extent_list *eb_el; |
731 | 1044 | ||
732 | mlog_entry_void(); | 1045 | mlog_entry_void(); |
@@ -746,8 +1059,7 @@ static int ocfs2_shift_tree_depth(struct ocfs2_super *osb, | |||
746 | } | 1059 | } |
747 | 1060 | ||
748 | eb_el = &eb->h_list; | 1061 | eb_el = &eb->h_list; |
749 | fe = (struct ocfs2_dinode *) fe_bh->b_data; | 1062 | root_el = et->et_root_el; |
750 | fe_el = &fe->id2.i_list; | ||
751 | 1063 | ||
752 | status = ocfs2_journal_access(handle, inode, new_eb_bh, | 1064 | status = ocfs2_journal_access(handle, inode, new_eb_bh, |
753 | OCFS2_JOURNAL_ACCESS_CREATE); | 1065 | OCFS2_JOURNAL_ACCESS_CREATE); |
@@ -756,11 +1068,11 @@ static int ocfs2_shift_tree_depth(struct ocfs2_super *osb, | |||
756 | goto bail; | 1068 | goto bail; |
757 | } | 1069 | } |
758 | 1070 | ||
759 | /* copy the fe data into the new extent block */ | 1071 | /* copy the root extent list data into the new extent block */ |
760 | eb_el->l_tree_depth = fe_el->l_tree_depth; | 1072 | eb_el->l_tree_depth = root_el->l_tree_depth; |
761 | eb_el->l_next_free_rec = fe_el->l_next_free_rec; | 1073 | eb_el->l_next_free_rec = root_el->l_next_free_rec; |
762 | for(i = 0; i < le16_to_cpu(fe_el->l_next_free_rec); i++) | 1074 | for (i = 0; i < le16_to_cpu(root_el->l_next_free_rec); i++) |
763 | eb_el->l_recs[i] = fe_el->l_recs[i]; | 1075 | eb_el->l_recs[i] = root_el->l_recs[i]; |
764 | 1076 | ||
765 | status = ocfs2_journal_dirty(handle, new_eb_bh); | 1077 | status = ocfs2_journal_dirty(handle, new_eb_bh); |
766 | if (status < 0) { | 1078 | if (status < 0) { |
@@ -768,7 +1080,7 @@ static int ocfs2_shift_tree_depth(struct ocfs2_super *osb, | |||
768 | goto bail; | 1080 | goto bail; |
769 | } | 1081 | } |
770 | 1082 | ||
771 | status = ocfs2_journal_access(handle, inode, fe_bh, | 1083 | status = ocfs2_journal_access(handle, inode, et->et_root_bh, |
772 | OCFS2_JOURNAL_ACCESS_WRITE); | 1084 | OCFS2_JOURNAL_ACCESS_WRITE); |
773 | if (status < 0) { | 1085 | if (status < 0) { |
774 | mlog_errno(status); | 1086 | mlog_errno(status); |
@@ -777,21 +1089,21 @@ static int ocfs2_shift_tree_depth(struct ocfs2_super *osb, | |||
777 | 1089 | ||
778 | new_clusters = ocfs2_sum_rightmost_rec(eb_el); | 1090 | new_clusters = ocfs2_sum_rightmost_rec(eb_el); |
779 | 1091 | ||
780 | /* update fe now */ | 1092 | /* update root_bh now */ |
781 | le16_add_cpu(&fe_el->l_tree_depth, 1); | 1093 | le16_add_cpu(&root_el->l_tree_depth, 1); |
782 | fe_el->l_recs[0].e_cpos = 0; | 1094 | root_el->l_recs[0].e_cpos = 0; |
783 | fe_el->l_recs[0].e_blkno = eb->h_blkno; | 1095 | root_el->l_recs[0].e_blkno = eb->h_blkno; |
784 | fe_el->l_recs[0].e_int_clusters = cpu_to_le32(new_clusters); | 1096 | root_el->l_recs[0].e_int_clusters = cpu_to_le32(new_clusters); |
785 | for(i = 1; i < le16_to_cpu(fe_el->l_next_free_rec); i++) | 1097 | for (i = 1; i < le16_to_cpu(root_el->l_next_free_rec); i++) |
786 | memset(&fe_el->l_recs[i], 0, sizeof(struct ocfs2_extent_rec)); | 1098 | memset(&root_el->l_recs[i], 0, sizeof(struct ocfs2_extent_rec)); |
787 | fe_el->l_next_free_rec = cpu_to_le16(1); | 1099 | root_el->l_next_free_rec = cpu_to_le16(1); |
788 | 1100 | ||
789 | /* If this is our 1st tree depth shift, then last_eb_blk | 1101 | /* If this is our 1st tree depth shift, then last_eb_blk |
790 | * becomes the allocated extent block */ | 1102 | * becomes the allocated extent block */ |
791 | if (fe_el->l_tree_depth == cpu_to_le16(1)) | 1103 | if (root_el->l_tree_depth == cpu_to_le16(1)) |
792 | fe->i_last_eb_blk = eb->h_blkno; | 1104 | ocfs2_et_set_last_eb_blk(et, le64_to_cpu(eb->h_blkno)); |
793 | 1105 | ||
794 | status = ocfs2_journal_dirty(handle, fe_bh); | 1106 | status = ocfs2_journal_dirty(handle, et->et_root_bh); |
795 | if (status < 0) { | 1107 | if (status < 0) { |
796 | mlog_errno(status); | 1108 | mlog_errno(status); |
797 | goto bail; | 1109 | goto bail; |
@@ -801,8 +1113,7 @@ static int ocfs2_shift_tree_depth(struct ocfs2_super *osb, | |||
801 | new_eb_bh = NULL; | 1113 | new_eb_bh = NULL; |
802 | status = 0; | 1114 | status = 0; |
803 | bail: | 1115 | bail: |
804 | if (new_eb_bh) | 1116 | brelse(new_eb_bh); |
805 | brelse(new_eb_bh); | ||
806 | 1117 | ||
807 | mlog_exit(status); | 1118 | mlog_exit(status); |
808 | return status; | 1119 | return status; |
@@ -817,22 +1128,21 @@ bail: | |||
817 | * 1) a lowest extent block is found, then we pass it back in | 1128 | * 1) a lowest extent block is found, then we pass it back in |
818 | * *lowest_eb_bh and return '0' | 1129 | * *lowest_eb_bh and return '0' |
819 | * | 1130 | * |
820 | * 2) the search fails to find anything, but the dinode has room. We | 1131 | * 2) the search fails to find anything, but the root_el has room. We |
821 | * pass NULL back in *lowest_eb_bh, but still return '0' | 1132 | * pass NULL back in *lowest_eb_bh, but still return '0' |
822 | * | 1133 | * |
823 | * 3) the search fails to find anything AND the dinode is full, in | 1134 | * 3) the search fails to find anything AND the root_el is full, in |
824 | * which case we return > 0 | 1135 | * which case we return > 0 |
825 | * | 1136 | * |
826 | * return status < 0 indicates an error. | 1137 | * return status < 0 indicates an error. |
827 | */ | 1138 | */ |
828 | static int ocfs2_find_branch_target(struct ocfs2_super *osb, | 1139 | static int ocfs2_find_branch_target(struct ocfs2_super *osb, |
829 | struct inode *inode, | 1140 | struct inode *inode, |
830 | struct buffer_head *fe_bh, | 1141 | struct ocfs2_extent_tree *et, |
831 | struct buffer_head **target_bh) | 1142 | struct buffer_head **target_bh) |
832 | { | 1143 | { |
833 | int status = 0, i; | 1144 | int status = 0, i; |
834 | u64 blkno; | 1145 | u64 blkno; |
835 | struct ocfs2_dinode *fe; | ||
836 | struct ocfs2_extent_block *eb; | 1146 | struct ocfs2_extent_block *eb; |
837 | struct ocfs2_extent_list *el; | 1147 | struct ocfs2_extent_list *el; |
838 | struct buffer_head *bh = NULL; | 1148 | struct buffer_head *bh = NULL; |
@@ -842,8 +1152,7 @@ static int ocfs2_find_branch_target(struct ocfs2_super *osb, | |||
842 | 1152 | ||
843 | *target_bh = NULL; | 1153 | *target_bh = NULL; |
844 | 1154 | ||
845 | fe = (struct ocfs2_dinode *) fe_bh->b_data; | 1155 | el = et->et_root_el; |
846 | el = &fe->id2.i_list; | ||
847 | 1156 | ||
848 | while(le16_to_cpu(el->l_tree_depth) > 1) { | 1157 | while(le16_to_cpu(el->l_tree_depth) > 1) { |
849 | if (le16_to_cpu(el->l_next_free_rec) == 0) { | 1158 | if (le16_to_cpu(el->l_next_free_rec) == 0) { |
@@ -864,13 +1173,10 @@ static int ocfs2_find_branch_target(struct ocfs2_super *osb, | |||
864 | goto bail; | 1173 | goto bail; |
865 | } | 1174 | } |
866 | 1175 | ||
867 | if (bh) { | 1176 | brelse(bh); |
868 | brelse(bh); | 1177 | bh = NULL; |
869 | bh = NULL; | ||
870 | } | ||
871 | 1178 | ||
872 | status = ocfs2_read_block(osb, blkno, &bh, OCFS2_BH_CACHED, | 1179 | status = ocfs2_read_block(inode, blkno, &bh); |
873 | inode); | ||
874 | if (status < 0) { | 1180 | if (status < 0) { |
875 | mlog_errno(status); | 1181 | mlog_errno(status); |
876 | goto bail; | 1182 | goto bail; |
@@ -886,8 +1192,7 @@ static int ocfs2_find_branch_target(struct ocfs2_super *osb, | |||
886 | 1192 | ||
887 | if (le16_to_cpu(el->l_next_free_rec) < | 1193 | if (le16_to_cpu(el->l_next_free_rec) < |
888 | le16_to_cpu(el->l_count)) { | 1194 | le16_to_cpu(el->l_count)) { |
889 | if (lowest_bh) | 1195 | brelse(lowest_bh); |
890 | brelse(lowest_bh); | ||
891 | lowest_bh = bh; | 1196 | lowest_bh = bh; |
892 | get_bh(lowest_bh); | 1197 | get_bh(lowest_bh); |
893 | } | 1198 | } |
@@ -895,14 +1200,13 @@ static int ocfs2_find_branch_target(struct ocfs2_super *osb, | |||
895 | 1200 | ||
896 | /* If we didn't find one and the fe doesn't have any room, | 1201 | /* If we didn't find one and the fe doesn't have any room, |
897 | * then return '1' */ | 1202 | * then return '1' */ |
898 | if (!lowest_bh | 1203 | el = et->et_root_el; |
899 | && (fe->id2.i_list.l_next_free_rec == fe->id2.i_list.l_count)) | 1204 | if (!lowest_bh && (el->l_next_free_rec == el->l_count)) |
900 | status = 1; | 1205 | status = 1; |
901 | 1206 | ||
902 | *target_bh = lowest_bh; | 1207 | *target_bh = lowest_bh; |
903 | bail: | 1208 | bail: |
904 | if (bh) | 1209 | brelse(bh); |
905 | brelse(bh); | ||
906 | 1210 | ||
907 | mlog_exit(status); | 1211 | mlog_exit(status); |
908 | return status; | 1212 | return status; |
@@ -919,19 +1223,19 @@ bail: | |||
919 | * *last_eb_bh will be updated by ocfs2_add_branch(). | 1223 | * *last_eb_bh will be updated by ocfs2_add_branch(). |
920 | */ | 1224 | */ |
921 | static int ocfs2_grow_tree(struct inode *inode, handle_t *handle, | 1225 | static int ocfs2_grow_tree(struct inode *inode, handle_t *handle, |
922 | struct buffer_head *di_bh, int *final_depth, | 1226 | struct ocfs2_extent_tree *et, int *final_depth, |
923 | struct buffer_head **last_eb_bh, | 1227 | struct buffer_head **last_eb_bh, |
924 | struct ocfs2_alloc_context *meta_ac) | 1228 | struct ocfs2_alloc_context *meta_ac) |
925 | { | 1229 | { |
926 | int ret, shift; | 1230 | int ret, shift; |
927 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; | 1231 | struct ocfs2_extent_list *el = et->et_root_el; |
928 | int depth = le16_to_cpu(di->id2.i_list.l_tree_depth); | 1232 | int depth = le16_to_cpu(el->l_tree_depth); |
929 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | 1233 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); |
930 | struct buffer_head *bh = NULL; | 1234 | struct buffer_head *bh = NULL; |
931 | 1235 | ||
932 | BUG_ON(meta_ac == NULL); | 1236 | BUG_ON(meta_ac == NULL); |
933 | 1237 | ||
934 | shift = ocfs2_find_branch_target(osb, inode, di_bh, &bh); | 1238 | shift = ocfs2_find_branch_target(osb, inode, et, &bh); |
935 | if (shift < 0) { | 1239 | if (shift < 0) { |
936 | ret = shift; | 1240 | ret = shift; |
937 | mlog_errno(ret); | 1241 | mlog_errno(ret); |
@@ -948,7 +1252,7 @@ static int ocfs2_grow_tree(struct inode *inode, handle_t *handle, | |||
948 | /* ocfs2_shift_tree_depth will return us a buffer with | 1252 | /* ocfs2_shift_tree_depth will return us a buffer with |
949 | * the new extent block (so we can pass that to | 1253 | * the new extent block (so we can pass that to |
950 | * ocfs2_add_branch). */ | 1254 | * ocfs2_add_branch). */ |
951 | ret = ocfs2_shift_tree_depth(osb, handle, inode, di_bh, | 1255 | ret = ocfs2_shift_tree_depth(osb, handle, inode, et, |
952 | meta_ac, &bh); | 1256 | meta_ac, &bh); |
953 | if (ret < 0) { | 1257 | if (ret < 0) { |
954 | mlog_errno(ret); | 1258 | mlog_errno(ret); |
@@ -975,7 +1279,7 @@ static int ocfs2_grow_tree(struct inode *inode, handle_t *handle, | |||
975 | /* call ocfs2_add_branch to add the final part of the tree with | 1279 | /* call ocfs2_add_branch to add the final part of the tree with |
976 | * the new data. */ | 1280 | * the new data. */ |
977 | mlog(0, "add branch. bh = %p\n", bh); | 1281 | mlog(0, "add branch. bh = %p\n", bh); |
978 | ret = ocfs2_add_branch(osb, handle, inode, di_bh, bh, last_eb_bh, | 1282 | ret = ocfs2_add_branch(osb, handle, inode, et, bh, last_eb_bh, |
979 | meta_ac); | 1283 | meta_ac); |
980 | if (ret < 0) { | 1284 | if (ret < 0) { |
981 | mlog_errno(ret); | 1285 | mlog_errno(ret); |
@@ -990,15 +1294,6 @@ out: | |||
990 | } | 1294 | } |
991 | 1295 | ||
992 | /* | 1296 | /* |
993 | * This is only valid for leaf nodes, which are the only ones that can | ||
994 | * have empty extents anyway. | ||
995 | */ | ||
996 | static inline int ocfs2_is_empty_extent(struct ocfs2_extent_rec *rec) | ||
997 | { | ||
998 | return !rec->e_leaf_clusters; | ||
999 | } | ||
1000 | |||
1001 | /* | ||
1002 | * This function will discard the rightmost extent record. | 1297 | * This function will discard the rightmost extent record. |
1003 | */ | 1298 | */ |
1004 | static void ocfs2_shift_records_right(struct ocfs2_extent_list *el) | 1299 | static void ocfs2_shift_records_right(struct ocfs2_extent_list *el) |
@@ -1245,8 +1540,7 @@ static int __ocfs2_find_path(struct inode *inode, | |||
1245 | 1540 | ||
1246 | brelse(bh); | 1541 | brelse(bh); |
1247 | bh = NULL; | 1542 | bh = NULL; |
1248 | ret = ocfs2_read_block(OCFS2_SB(inode->i_sb), blkno, | 1543 | ret = ocfs2_read_block(inode, blkno, &bh); |
1249 | &bh, OCFS2_BH_CACHED, inode); | ||
1250 | if (ret) { | 1544 | if (ret) { |
1251 | mlog_errno(ret); | 1545 | mlog_errno(ret); |
1252 | goto out; | 1546 | goto out; |
@@ -2067,11 +2361,11 @@ static int ocfs2_rotate_subtree_left(struct inode *inode, handle_t *handle, | |||
2067 | struct ocfs2_path *right_path, | 2361 | struct ocfs2_path *right_path, |
2068 | int subtree_index, | 2362 | int subtree_index, |
2069 | struct ocfs2_cached_dealloc_ctxt *dealloc, | 2363 | struct ocfs2_cached_dealloc_ctxt *dealloc, |
2070 | int *deleted) | 2364 | int *deleted, |
2365 | struct ocfs2_extent_tree *et) | ||
2071 | { | 2366 | { |
2072 | int ret, i, del_right_subtree = 0, right_has_empty = 0; | 2367 | int ret, i, del_right_subtree = 0, right_has_empty = 0; |
2073 | struct buffer_head *root_bh, *di_bh = path_root_bh(right_path); | 2368 | struct buffer_head *root_bh, *et_root_bh = path_root_bh(right_path); |
2074 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; | ||
2075 | struct ocfs2_extent_list *right_leaf_el, *left_leaf_el; | 2369 | struct ocfs2_extent_list *right_leaf_el, *left_leaf_el; |
2076 | struct ocfs2_extent_block *eb; | 2370 | struct ocfs2_extent_block *eb; |
2077 | 2371 | ||
@@ -2123,7 +2417,7 @@ static int ocfs2_rotate_subtree_left(struct inode *inode, handle_t *handle, | |||
2123 | * We have to update i_last_eb_blk during the meta | 2417 | * We have to update i_last_eb_blk during the meta |
2124 | * data delete. | 2418 | * data delete. |
2125 | */ | 2419 | */ |
2126 | ret = ocfs2_journal_access(handle, inode, di_bh, | 2420 | ret = ocfs2_journal_access(handle, inode, et_root_bh, |
2127 | OCFS2_JOURNAL_ACCESS_WRITE); | 2421 | OCFS2_JOURNAL_ACCESS_WRITE); |
2128 | if (ret) { | 2422 | if (ret) { |
2129 | mlog_errno(ret); | 2423 | mlog_errno(ret); |
@@ -2198,7 +2492,7 @@ static int ocfs2_rotate_subtree_left(struct inode *inode, handle_t *handle, | |||
2198 | ocfs2_update_edge_lengths(inode, handle, left_path); | 2492 | ocfs2_update_edge_lengths(inode, handle, left_path); |
2199 | 2493 | ||
2200 | eb = (struct ocfs2_extent_block *)path_leaf_bh(left_path)->b_data; | 2494 | eb = (struct ocfs2_extent_block *)path_leaf_bh(left_path)->b_data; |
2201 | di->i_last_eb_blk = eb->h_blkno; | 2495 | ocfs2_et_set_last_eb_blk(et, le64_to_cpu(eb->h_blkno)); |
2202 | 2496 | ||
2203 | /* | 2497 | /* |
2204 | * Removal of the extent in the left leaf was skipped | 2498 | * Removal of the extent in the left leaf was skipped |
@@ -2208,7 +2502,7 @@ static int ocfs2_rotate_subtree_left(struct inode *inode, handle_t *handle, | |||
2208 | if (right_has_empty) | 2502 | if (right_has_empty) |
2209 | ocfs2_remove_empty_extent(left_leaf_el); | 2503 | ocfs2_remove_empty_extent(left_leaf_el); |
2210 | 2504 | ||
2211 | ret = ocfs2_journal_dirty(handle, di_bh); | 2505 | ret = ocfs2_journal_dirty(handle, et_root_bh); |
2212 | if (ret) | 2506 | if (ret) |
2213 | mlog_errno(ret); | 2507 | mlog_errno(ret); |
2214 | 2508 | ||
@@ -2331,7 +2625,8 @@ static int __ocfs2_rotate_tree_left(struct inode *inode, | |||
2331 | handle_t *handle, int orig_credits, | 2625 | handle_t *handle, int orig_credits, |
2332 | struct ocfs2_path *path, | 2626 | struct ocfs2_path *path, |
2333 | struct ocfs2_cached_dealloc_ctxt *dealloc, | 2627 | struct ocfs2_cached_dealloc_ctxt *dealloc, |
2334 | struct ocfs2_path **empty_extent_path) | 2628 | struct ocfs2_path **empty_extent_path, |
2629 | struct ocfs2_extent_tree *et) | ||
2335 | { | 2630 | { |
2336 | int ret, subtree_root, deleted; | 2631 | int ret, subtree_root, deleted; |
2337 | u32 right_cpos; | 2632 | u32 right_cpos; |
@@ -2404,7 +2699,7 @@ static int __ocfs2_rotate_tree_left(struct inode *inode, | |||
2404 | 2699 | ||
2405 | ret = ocfs2_rotate_subtree_left(inode, handle, left_path, | 2700 | ret = ocfs2_rotate_subtree_left(inode, handle, left_path, |
2406 | right_path, subtree_root, | 2701 | right_path, subtree_root, |
2407 | dealloc, &deleted); | 2702 | dealloc, &deleted, et); |
2408 | if (ret == -EAGAIN) { | 2703 | if (ret == -EAGAIN) { |
2409 | /* | 2704 | /* |
2410 | * The rotation has to temporarily stop due to | 2705 | * The rotation has to temporarily stop due to |
@@ -2447,29 +2742,20 @@ out: | |||
2447 | } | 2742 | } |
2448 | 2743 | ||
2449 | static int ocfs2_remove_rightmost_path(struct inode *inode, handle_t *handle, | 2744 | static int ocfs2_remove_rightmost_path(struct inode *inode, handle_t *handle, |
2450 | struct ocfs2_path *path, | 2745 | struct ocfs2_path *path, |
2451 | struct ocfs2_cached_dealloc_ctxt *dealloc) | 2746 | struct ocfs2_cached_dealloc_ctxt *dealloc, |
2747 | struct ocfs2_extent_tree *et) | ||
2452 | { | 2748 | { |
2453 | int ret, subtree_index; | 2749 | int ret, subtree_index; |
2454 | u32 cpos; | 2750 | u32 cpos; |
2455 | struct ocfs2_path *left_path = NULL; | 2751 | struct ocfs2_path *left_path = NULL; |
2456 | struct ocfs2_dinode *di; | ||
2457 | struct ocfs2_extent_block *eb; | 2752 | struct ocfs2_extent_block *eb; |
2458 | struct ocfs2_extent_list *el; | 2753 | struct ocfs2_extent_list *el; |
2459 | 2754 | ||
2460 | /* | ||
2461 | * XXX: This code assumes that the root is an inode, which is | ||
2462 | * true for now but may change as tree code gets generic. | ||
2463 | */ | ||
2464 | di = (struct ocfs2_dinode *)path_root_bh(path)->b_data; | ||
2465 | if (!OCFS2_IS_VALID_DINODE(di)) { | ||
2466 | ret = -EIO; | ||
2467 | ocfs2_error(inode->i_sb, | ||
2468 | "Inode %llu has invalid path root", | ||
2469 | (unsigned long long)OCFS2_I(inode)->ip_blkno); | ||
2470 | goto out; | ||
2471 | } | ||
2472 | 2755 | ||
2756 | ret = ocfs2_et_sanity_check(inode, et); | ||
2757 | if (ret) | ||
2758 | goto out; | ||
2473 | /* | 2759 | /* |
2474 | * There's two ways we handle this depending on | 2760 | * There's two ways we handle this depending on |
2475 | * whether path is the only existing one. | 2761 | * whether path is the only existing one. |
@@ -2526,7 +2812,7 @@ static int ocfs2_remove_rightmost_path(struct inode *inode, handle_t *handle, | |||
2526 | ocfs2_update_edge_lengths(inode, handle, left_path); | 2812 | ocfs2_update_edge_lengths(inode, handle, left_path); |
2527 | 2813 | ||
2528 | eb = (struct ocfs2_extent_block *)path_leaf_bh(left_path)->b_data; | 2814 | eb = (struct ocfs2_extent_block *)path_leaf_bh(left_path)->b_data; |
2529 | di->i_last_eb_blk = eb->h_blkno; | 2815 | ocfs2_et_set_last_eb_blk(et, le64_to_cpu(eb->h_blkno)); |
2530 | } else { | 2816 | } else { |
2531 | /* | 2817 | /* |
2532 | * 'path' is also the leftmost path which | 2818 | * 'path' is also the leftmost path which |
@@ -2537,12 +2823,12 @@ static int ocfs2_remove_rightmost_path(struct inode *inode, handle_t *handle, | |||
2537 | */ | 2823 | */ |
2538 | ocfs2_unlink_path(inode, handle, dealloc, path, 1); | 2824 | ocfs2_unlink_path(inode, handle, dealloc, path, 1); |
2539 | 2825 | ||
2540 | el = &di->id2.i_list; | 2826 | el = et->et_root_el; |
2541 | el->l_tree_depth = 0; | 2827 | el->l_tree_depth = 0; |
2542 | el->l_next_free_rec = 0; | 2828 | el->l_next_free_rec = 0; |
2543 | memset(&el->l_recs[0], 0, sizeof(struct ocfs2_extent_rec)); | 2829 | memset(&el->l_recs[0], 0, sizeof(struct ocfs2_extent_rec)); |
2544 | 2830 | ||
2545 | di->i_last_eb_blk = 0; | 2831 | ocfs2_et_set_last_eb_blk(et, 0); |
2546 | } | 2832 | } |
2547 | 2833 | ||
2548 | ocfs2_journal_dirty(handle, path_root_bh(path)); | 2834 | ocfs2_journal_dirty(handle, path_root_bh(path)); |
@@ -2570,7 +2856,8 @@ out: | |||
2570 | */ | 2856 | */ |
2571 | static int ocfs2_rotate_tree_left(struct inode *inode, handle_t *handle, | 2857 | static int ocfs2_rotate_tree_left(struct inode *inode, handle_t *handle, |
2572 | struct ocfs2_path *path, | 2858 | struct ocfs2_path *path, |
2573 | struct ocfs2_cached_dealloc_ctxt *dealloc) | 2859 | struct ocfs2_cached_dealloc_ctxt *dealloc, |
2860 | struct ocfs2_extent_tree *et) | ||
2574 | { | 2861 | { |
2575 | int ret, orig_credits = handle->h_buffer_credits; | 2862 | int ret, orig_credits = handle->h_buffer_credits; |
2576 | struct ocfs2_path *tmp_path = NULL, *restart_path = NULL; | 2863 | struct ocfs2_path *tmp_path = NULL, *restart_path = NULL; |
@@ -2584,7 +2871,7 @@ static int ocfs2_rotate_tree_left(struct inode *inode, handle_t *handle, | |||
2584 | if (path->p_tree_depth == 0) { | 2871 | if (path->p_tree_depth == 0) { |
2585 | rightmost_no_delete: | 2872 | rightmost_no_delete: |
2586 | /* | 2873 | /* |
2587 | * In-inode extents. This is trivially handled, so do | 2874 | * Inline extents. This is trivially handled, so do |
2588 | * it up front. | 2875 | * it up front. |
2589 | */ | 2876 | */ |
2590 | ret = ocfs2_rotate_rightmost_leaf_left(inode, handle, | 2877 | ret = ocfs2_rotate_rightmost_leaf_left(inode, handle, |
@@ -2638,7 +2925,7 @@ rightmost_no_delete: | |||
2638 | */ | 2925 | */ |
2639 | 2926 | ||
2640 | ret = ocfs2_remove_rightmost_path(inode, handle, path, | 2927 | ret = ocfs2_remove_rightmost_path(inode, handle, path, |
2641 | dealloc); | 2928 | dealloc, et); |
2642 | if (ret) | 2929 | if (ret) |
2643 | mlog_errno(ret); | 2930 | mlog_errno(ret); |
2644 | goto out; | 2931 | goto out; |
@@ -2650,7 +2937,7 @@ rightmost_no_delete: | |||
2650 | */ | 2937 | */ |
2651 | try_rotate: | 2938 | try_rotate: |
2652 | ret = __ocfs2_rotate_tree_left(inode, handle, orig_credits, path, | 2939 | ret = __ocfs2_rotate_tree_left(inode, handle, orig_credits, path, |
2653 | dealloc, &restart_path); | 2940 | dealloc, &restart_path, et); |
2654 | if (ret && ret != -EAGAIN) { | 2941 | if (ret && ret != -EAGAIN) { |
2655 | mlog_errno(ret); | 2942 | mlog_errno(ret); |
2656 | goto out; | 2943 | goto out; |
@@ -2662,7 +2949,7 @@ try_rotate: | |||
2662 | 2949 | ||
2663 | ret = __ocfs2_rotate_tree_left(inode, handle, orig_credits, | 2950 | ret = __ocfs2_rotate_tree_left(inode, handle, orig_credits, |
2664 | tmp_path, dealloc, | 2951 | tmp_path, dealloc, |
2665 | &restart_path); | 2952 | &restart_path, et); |
2666 | if (ret && ret != -EAGAIN) { | 2953 | if (ret && ret != -EAGAIN) { |
2667 | mlog_errno(ret); | 2954 | mlog_errno(ret); |
2668 | goto out; | 2955 | goto out; |
@@ -2948,6 +3235,7 @@ static int ocfs2_merge_rec_left(struct inode *inode, | |||
2948 | handle_t *handle, | 3235 | handle_t *handle, |
2949 | struct ocfs2_extent_rec *split_rec, | 3236 | struct ocfs2_extent_rec *split_rec, |
2950 | struct ocfs2_cached_dealloc_ctxt *dealloc, | 3237 | struct ocfs2_cached_dealloc_ctxt *dealloc, |
3238 | struct ocfs2_extent_tree *et, | ||
2951 | int index) | 3239 | int index) |
2952 | { | 3240 | { |
2953 | int ret, i, subtree_index = 0, has_empty_extent = 0; | 3241 | int ret, i, subtree_index = 0, has_empty_extent = 0; |
@@ -3068,7 +3356,8 @@ static int ocfs2_merge_rec_left(struct inode *inode, | |||
3068 | le16_to_cpu(el->l_next_free_rec) == 1) { | 3356 | le16_to_cpu(el->l_next_free_rec) == 1) { |
3069 | 3357 | ||
3070 | ret = ocfs2_remove_rightmost_path(inode, handle, | 3358 | ret = ocfs2_remove_rightmost_path(inode, handle, |
3071 | right_path, dealloc); | 3359 | right_path, |
3360 | dealloc, et); | ||
3072 | if (ret) { | 3361 | if (ret) { |
3073 | mlog_errno(ret); | 3362 | mlog_errno(ret); |
3074 | goto out; | 3363 | goto out; |
@@ -3095,7 +3384,8 @@ static int ocfs2_try_to_merge_extent(struct inode *inode, | |||
3095 | int split_index, | 3384 | int split_index, |
3096 | struct ocfs2_extent_rec *split_rec, | 3385 | struct ocfs2_extent_rec *split_rec, |
3097 | struct ocfs2_cached_dealloc_ctxt *dealloc, | 3386 | struct ocfs2_cached_dealloc_ctxt *dealloc, |
3098 | struct ocfs2_merge_ctxt *ctxt) | 3387 | struct ocfs2_merge_ctxt *ctxt, |
3388 | struct ocfs2_extent_tree *et) | ||
3099 | 3389 | ||
3100 | { | 3390 | { |
3101 | int ret = 0; | 3391 | int ret = 0; |
@@ -3113,7 +3403,7 @@ static int ocfs2_try_to_merge_extent(struct inode *inode, | |||
3113 | * illegal. | 3403 | * illegal. |
3114 | */ | 3404 | */ |
3115 | ret = ocfs2_rotate_tree_left(inode, handle, path, | 3405 | ret = ocfs2_rotate_tree_left(inode, handle, path, |
3116 | dealloc); | 3406 | dealloc, et); |
3117 | if (ret) { | 3407 | if (ret) { |
3118 | mlog_errno(ret); | 3408 | mlog_errno(ret); |
3119 | goto out; | 3409 | goto out; |
@@ -3156,7 +3446,8 @@ static int ocfs2_try_to_merge_extent(struct inode *inode, | |||
3156 | BUG_ON(!ocfs2_is_empty_extent(&el->l_recs[0])); | 3446 | BUG_ON(!ocfs2_is_empty_extent(&el->l_recs[0])); |
3157 | 3447 | ||
3158 | /* The merge left us with an empty extent, remove it. */ | 3448 | /* The merge left us with an empty extent, remove it. */ |
3159 | ret = ocfs2_rotate_tree_left(inode, handle, path, dealloc); | 3449 | ret = ocfs2_rotate_tree_left(inode, handle, path, |
3450 | dealloc, et); | ||
3160 | if (ret) { | 3451 | if (ret) { |
3161 | mlog_errno(ret); | 3452 | mlog_errno(ret); |
3162 | goto out; | 3453 | goto out; |
@@ -3170,7 +3461,7 @@ static int ocfs2_try_to_merge_extent(struct inode *inode, | |||
3170 | */ | 3461 | */ |
3171 | ret = ocfs2_merge_rec_left(inode, path, | 3462 | ret = ocfs2_merge_rec_left(inode, path, |
3172 | handle, rec, | 3463 | handle, rec, |
3173 | dealloc, | 3464 | dealloc, et, |
3174 | split_index); | 3465 | split_index); |
3175 | 3466 | ||
3176 | if (ret) { | 3467 | if (ret) { |
@@ -3179,7 +3470,7 @@ static int ocfs2_try_to_merge_extent(struct inode *inode, | |||
3179 | } | 3470 | } |
3180 | 3471 | ||
3181 | ret = ocfs2_rotate_tree_left(inode, handle, path, | 3472 | ret = ocfs2_rotate_tree_left(inode, handle, path, |
3182 | dealloc); | 3473 | dealloc, et); |
3183 | /* | 3474 | /* |
3184 | * Error from this last rotate is not critical, so | 3475 | * Error from this last rotate is not critical, so |
3185 | * print but don't bubble it up. | 3476 | * print but don't bubble it up. |
@@ -3199,7 +3490,7 @@ static int ocfs2_try_to_merge_extent(struct inode *inode, | |||
3199 | ret = ocfs2_merge_rec_left(inode, | 3490 | ret = ocfs2_merge_rec_left(inode, |
3200 | path, | 3491 | path, |
3201 | handle, split_rec, | 3492 | handle, split_rec, |
3202 | dealloc, | 3493 | dealloc, et, |
3203 | split_index); | 3494 | split_index); |
3204 | if (ret) { | 3495 | if (ret) { |
3205 | mlog_errno(ret); | 3496 | mlog_errno(ret); |
@@ -3222,7 +3513,7 @@ static int ocfs2_try_to_merge_extent(struct inode *inode, | |||
3222 | * our leaf. Try to rotate it away. | 3513 | * our leaf. Try to rotate it away. |
3223 | */ | 3514 | */ |
3224 | ret = ocfs2_rotate_tree_left(inode, handle, path, | 3515 | ret = ocfs2_rotate_tree_left(inode, handle, path, |
3225 | dealloc); | 3516 | dealloc, et); |
3226 | if (ret) | 3517 | if (ret) |
3227 | mlog_errno(ret); | 3518 | mlog_errno(ret); |
3228 | ret = 0; | 3519 | ret = 0; |
@@ -3356,16 +3647,6 @@ rotate: | |||
3356 | ocfs2_rotate_leaf(el, insert_rec); | 3647 | ocfs2_rotate_leaf(el, insert_rec); |
3357 | } | 3648 | } |
3358 | 3649 | ||
3359 | static inline void ocfs2_update_dinode_clusters(struct inode *inode, | ||
3360 | struct ocfs2_dinode *di, | ||
3361 | u32 clusters) | ||
3362 | { | ||
3363 | le32_add_cpu(&di->i_clusters, clusters); | ||
3364 | spin_lock(&OCFS2_I(inode)->ip_lock); | ||
3365 | OCFS2_I(inode)->ip_clusters = le32_to_cpu(di->i_clusters); | ||
3366 | spin_unlock(&OCFS2_I(inode)->ip_lock); | ||
3367 | } | ||
3368 | |||
3369 | static void ocfs2_adjust_rightmost_records(struct inode *inode, | 3650 | static void ocfs2_adjust_rightmost_records(struct inode *inode, |
3370 | handle_t *handle, | 3651 | handle_t *handle, |
3371 | struct ocfs2_path *path, | 3652 | struct ocfs2_path *path, |
@@ -3567,8 +3848,8 @@ static void ocfs2_split_record(struct inode *inode, | |||
3567 | } | 3848 | } |
3568 | 3849 | ||
3569 | /* | 3850 | /* |
3570 | * This function only does inserts on an allocation b-tree. For dinode | 3851 | * This function only does inserts on an allocation b-tree. For tree |
3571 | * lists, ocfs2_insert_at_leaf() is called directly. | 3852 | * depth = 0, ocfs2_insert_at_leaf() is called directly. |
3572 | * | 3853 | * |
3573 | * right_path is the path we want to do the actual insert | 3854 | * right_path is the path we want to do the actual insert |
3574 | * in. left_path should only be passed in if we need to update that | 3855 | * in. left_path should only be passed in if we need to update that |
@@ -3665,7 +3946,7 @@ out: | |||
3665 | 3946 | ||
3666 | static int ocfs2_do_insert_extent(struct inode *inode, | 3947 | static int ocfs2_do_insert_extent(struct inode *inode, |
3667 | handle_t *handle, | 3948 | handle_t *handle, |
3668 | struct buffer_head *di_bh, | 3949 | struct ocfs2_extent_tree *et, |
3669 | struct ocfs2_extent_rec *insert_rec, | 3950 | struct ocfs2_extent_rec *insert_rec, |
3670 | struct ocfs2_insert_type *type) | 3951 | struct ocfs2_insert_type *type) |
3671 | { | 3952 | { |
@@ -3673,13 +3954,11 @@ static int ocfs2_do_insert_extent(struct inode *inode, | |||
3673 | u32 cpos; | 3954 | u32 cpos; |
3674 | struct ocfs2_path *right_path = NULL; | 3955 | struct ocfs2_path *right_path = NULL; |
3675 | struct ocfs2_path *left_path = NULL; | 3956 | struct ocfs2_path *left_path = NULL; |
3676 | struct ocfs2_dinode *di; | ||
3677 | struct ocfs2_extent_list *el; | 3957 | struct ocfs2_extent_list *el; |
3678 | 3958 | ||
3679 | di = (struct ocfs2_dinode *) di_bh->b_data; | 3959 | el = et->et_root_el; |
3680 | el = &di->id2.i_list; | ||
3681 | 3960 | ||
3682 | ret = ocfs2_journal_access(handle, inode, di_bh, | 3961 | ret = ocfs2_journal_access(handle, inode, et->et_root_bh, |
3683 | OCFS2_JOURNAL_ACCESS_WRITE); | 3962 | OCFS2_JOURNAL_ACCESS_WRITE); |
3684 | if (ret) { | 3963 | if (ret) { |
3685 | mlog_errno(ret); | 3964 | mlog_errno(ret); |
@@ -3691,7 +3970,7 @@ static int ocfs2_do_insert_extent(struct inode *inode, | |||
3691 | goto out_update_clusters; | 3970 | goto out_update_clusters; |
3692 | } | 3971 | } |
3693 | 3972 | ||
3694 | right_path = ocfs2_new_inode_path(di_bh); | 3973 | right_path = ocfs2_new_path(et->et_root_bh, et->et_root_el); |
3695 | if (!right_path) { | 3974 | if (!right_path) { |
3696 | ret = -ENOMEM; | 3975 | ret = -ENOMEM; |
3697 | mlog_errno(ret); | 3976 | mlog_errno(ret); |
@@ -3741,7 +4020,7 @@ static int ocfs2_do_insert_extent(struct inode *inode, | |||
3741 | * ocfs2_rotate_tree_right() might have extended the | 4020 | * ocfs2_rotate_tree_right() might have extended the |
3742 | * transaction without re-journaling our tree root. | 4021 | * transaction without re-journaling our tree root. |
3743 | */ | 4022 | */ |
3744 | ret = ocfs2_journal_access(handle, inode, di_bh, | 4023 | ret = ocfs2_journal_access(handle, inode, et->et_root_bh, |
3745 | OCFS2_JOURNAL_ACCESS_WRITE); | 4024 | OCFS2_JOURNAL_ACCESS_WRITE); |
3746 | if (ret) { | 4025 | if (ret) { |
3747 | mlog_errno(ret); | 4026 | mlog_errno(ret); |
@@ -3766,10 +4045,10 @@ static int ocfs2_do_insert_extent(struct inode *inode, | |||
3766 | 4045 | ||
3767 | out_update_clusters: | 4046 | out_update_clusters: |
3768 | if (type->ins_split == SPLIT_NONE) | 4047 | if (type->ins_split == SPLIT_NONE) |
3769 | ocfs2_update_dinode_clusters(inode, di, | 4048 | ocfs2_et_update_clusters(inode, et, |
3770 | le16_to_cpu(insert_rec->e_leaf_clusters)); | 4049 | le16_to_cpu(insert_rec->e_leaf_clusters)); |
3771 | 4050 | ||
3772 | ret = ocfs2_journal_dirty(handle, di_bh); | 4051 | ret = ocfs2_journal_dirty(handle, et->et_root_bh); |
3773 | if (ret) | 4052 | if (ret) |
3774 | mlog_errno(ret); | 4053 | mlog_errno(ret); |
3775 | 4054 | ||
@@ -3899,7 +4178,8 @@ out: | |||
3899 | static void ocfs2_figure_contig_type(struct inode *inode, | 4178 | static void ocfs2_figure_contig_type(struct inode *inode, |
3900 | struct ocfs2_insert_type *insert, | 4179 | struct ocfs2_insert_type *insert, |
3901 | struct ocfs2_extent_list *el, | 4180 | struct ocfs2_extent_list *el, |
3902 | struct ocfs2_extent_rec *insert_rec) | 4181 | struct ocfs2_extent_rec *insert_rec, |
4182 | struct ocfs2_extent_tree *et) | ||
3903 | { | 4183 | { |
3904 | int i; | 4184 | int i; |
3905 | enum ocfs2_contig_type contig_type = CONTIG_NONE; | 4185 | enum ocfs2_contig_type contig_type = CONTIG_NONE; |
@@ -3915,6 +4195,21 @@ static void ocfs2_figure_contig_type(struct inode *inode, | |||
3915 | } | 4195 | } |
3916 | } | 4196 | } |
3917 | insert->ins_contig = contig_type; | 4197 | insert->ins_contig = contig_type; |
4198 | |||
4199 | if (insert->ins_contig != CONTIG_NONE) { | ||
4200 | struct ocfs2_extent_rec *rec = | ||
4201 | &el->l_recs[insert->ins_contig_index]; | ||
4202 | unsigned int len = le16_to_cpu(rec->e_leaf_clusters) + | ||
4203 | le16_to_cpu(insert_rec->e_leaf_clusters); | ||
4204 | |||
4205 | /* | ||
4206 | * Caller might want us to limit the size of extents, don't | ||
4207 | * calculate contiguousness if we might exceed that limit. | ||
4208 | */ | ||
4209 | if (et->et_max_leaf_clusters && | ||
4210 | (len > et->et_max_leaf_clusters)) | ||
4211 | insert->ins_contig = CONTIG_NONE; | ||
4212 | } | ||
3918 | } | 4213 | } |
3919 | 4214 | ||
3920 | /* | 4215 | /* |
@@ -3923,8 +4218,8 @@ static void ocfs2_figure_contig_type(struct inode *inode, | |||
3923 | * ocfs2_figure_appending_type() will figure out whether we'll have to | 4218 | * ocfs2_figure_appending_type() will figure out whether we'll have to |
3924 | * insert at the tail of the rightmost leaf. | 4219 | * insert at the tail of the rightmost leaf. |
3925 | * | 4220 | * |
3926 | * This should also work against the dinode list for tree's with 0 | 4221 | * This should also work against the root extent list for tree's with 0 |
3927 | * depth. If we consider the dinode list to be the rightmost leaf node | 4222 | * depth. If we consider the root extent list to be the rightmost leaf node |
3928 | * then the logic here makes sense. | 4223 | * then the logic here makes sense. |
3929 | */ | 4224 | */ |
3930 | static void ocfs2_figure_appending_type(struct ocfs2_insert_type *insert, | 4225 | static void ocfs2_figure_appending_type(struct ocfs2_insert_type *insert, |
@@ -3975,14 +4270,13 @@ set_tail_append: | |||
3975 | * structure. | 4270 | * structure. |
3976 | */ | 4271 | */ |
3977 | static int ocfs2_figure_insert_type(struct inode *inode, | 4272 | static int ocfs2_figure_insert_type(struct inode *inode, |
3978 | struct buffer_head *di_bh, | 4273 | struct ocfs2_extent_tree *et, |
3979 | struct buffer_head **last_eb_bh, | 4274 | struct buffer_head **last_eb_bh, |
3980 | struct ocfs2_extent_rec *insert_rec, | 4275 | struct ocfs2_extent_rec *insert_rec, |
3981 | int *free_records, | 4276 | int *free_records, |
3982 | struct ocfs2_insert_type *insert) | 4277 | struct ocfs2_insert_type *insert) |
3983 | { | 4278 | { |
3984 | int ret; | 4279 | int ret; |
3985 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; | ||
3986 | struct ocfs2_extent_block *eb; | 4280 | struct ocfs2_extent_block *eb; |
3987 | struct ocfs2_extent_list *el; | 4281 | struct ocfs2_extent_list *el; |
3988 | struct ocfs2_path *path = NULL; | 4282 | struct ocfs2_path *path = NULL; |
@@ -3990,7 +4284,7 @@ static int ocfs2_figure_insert_type(struct inode *inode, | |||
3990 | 4284 | ||
3991 | insert->ins_split = SPLIT_NONE; | 4285 | insert->ins_split = SPLIT_NONE; |
3992 | 4286 | ||
3993 | el = &di->id2.i_list; | 4287 | el = et->et_root_el; |
3994 | insert->ins_tree_depth = le16_to_cpu(el->l_tree_depth); | 4288 | insert->ins_tree_depth = le16_to_cpu(el->l_tree_depth); |
3995 | 4289 | ||
3996 | if (el->l_tree_depth) { | 4290 | if (el->l_tree_depth) { |
@@ -4000,9 +4294,7 @@ static int ocfs2_figure_insert_type(struct inode *inode, | |||
4000 | * ocfs2_figure_insert_type() and ocfs2_add_branch() | 4294 | * ocfs2_figure_insert_type() and ocfs2_add_branch() |
4001 | * may want it later. | 4295 | * may want it later. |
4002 | */ | 4296 | */ |
4003 | ret = ocfs2_read_block(OCFS2_SB(inode->i_sb), | 4297 | ret = ocfs2_read_block(inode, ocfs2_et_get_last_eb_blk(et), &bh); |
4004 | le64_to_cpu(di->i_last_eb_blk), &bh, | ||
4005 | OCFS2_BH_CACHED, inode); | ||
4006 | if (ret) { | 4298 | if (ret) { |
4007 | mlog_exit(ret); | 4299 | mlog_exit(ret); |
4008 | goto out; | 4300 | goto out; |
@@ -4023,12 +4315,12 @@ static int ocfs2_figure_insert_type(struct inode *inode, | |||
4023 | le16_to_cpu(el->l_next_free_rec); | 4315 | le16_to_cpu(el->l_next_free_rec); |
4024 | 4316 | ||
4025 | if (!insert->ins_tree_depth) { | 4317 | if (!insert->ins_tree_depth) { |
4026 | ocfs2_figure_contig_type(inode, insert, el, insert_rec); | 4318 | ocfs2_figure_contig_type(inode, insert, el, insert_rec, et); |
4027 | ocfs2_figure_appending_type(insert, el, insert_rec); | 4319 | ocfs2_figure_appending_type(insert, el, insert_rec); |
4028 | return 0; | 4320 | return 0; |
4029 | } | 4321 | } |
4030 | 4322 | ||
4031 | path = ocfs2_new_inode_path(di_bh); | 4323 | path = ocfs2_new_path(et->et_root_bh, et->et_root_el); |
4032 | if (!path) { | 4324 | if (!path) { |
4033 | ret = -ENOMEM; | 4325 | ret = -ENOMEM; |
4034 | mlog_errno(ret); | 4326 | mlog_errno(ret); |
@@ -4057,7 +4349,7 @@ static int ocfs2_figure_insert_type(struct inode *inode, | |||
4057 | * into two types of appends: simple record append, or a | 4349 | * into two types of appends: simple record append, or a |
4058 | * rotate inside the tail leaf. | 4350 | * rotate inside the tail leaf. |
4059 | */ | 4351 | */ |
4060 | ocfs2_figure_contig_type(inode, insert, el, insert_rec); | 4352 | ocfs2_figure_contig_type(inode, insert, el, insert_rec, et); |
4061 | 4353 | ||
4062 | /* | 4354 | /* |
4063 | * The insert code isn't quite ready to deal with all cases of | 4355 | * The insert code isn't quite ready to deal with all cases of |
@@ -4078,7 +4370,8 @@ static int ocfs2_figure_insert_type(struct inode *inode, | |||
4078 | * the case that we're doing a tail append, so maybe we can | 4370 | * the case that we're doing a tail append, so maybe we can |
4079 | * take advantage of that information somehow. | 4371 | * take advantage of that information somehow. |
4080 | */ | 4372 | */ |
4081 | if (le64_to_cpu(di->i_last_eb_blk) == path_leaf_bh(path)->b_blocknr) { | 4373 | if (ocfs2_et_get_last_eb_blk(et) == |
4374 | path_leaf_bh(path)->b_blocknr) { | ||
4082 | /* | 4375 | /* |
4083 | * Ok, ocfs2_find_path() returned us the rightmost | 4376 | * Ok, ocfs2_find_path() returned us the rightmost |
4084 | * tree path. This might be an appending insert. There are | 4377 | * tree path. This might be an appending insert. There are |
@@ -4108,7 +4401,7 @@ out: | |||
4108 | int ocfs2_insert_extent(struct ocfs2_super *osb, | 4401 | int ocfs2_insert_extent(struct ocfs2_super *osb, |
4109 | handle_t *handle, | 4402 | handle_t *handle, |
4110 | struct inode *inode, | 4403 | struct inode *inode, |
4111 | struct buffer_head *fe_bh, | 4404 | struct ocfs2_extent_tree *et, |
4112 | u32 cpos, | 4405 | u32 cpos, |
4113 | u64 start_blk, | 4406 | u64 start_blk, |
4114 | u32 new_clusters, | 4407 | u32 new_clusters, |
@@ -4121,26 +4414,21 @@ int ocfs2_insert_extent(struct ocfs2_super *osb, | |||
4121 | struct ocfs2_insert_type insert = {0, }; | 4414 | struct ocfs2_insert_type insert = {0, }; |
4122 | struct ocfs2_extent_rec rec; | 4415 | struct ocfs2_extent_rec rec; |
4123 | 4416 | ||
4124 | BUG_ON(OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL); | ||
4125 | |||
4126 | mlog(0, "add %u clusters at position %u to inode %llu\n", | 4417 | mlog(0, "add %u clusters at position %u to inode %llu\n", |
4127 | new_clusters, cpos, (unsigned long long)OCFS2_I(inode)->ip_blkno); | 4418 | new_clusters, cpos, (unsigned long long)OCFS2_I(inode)->ip_blkno); |
4128 | 4419 | ||
4129 | mlog_bug_on_msg(!ocfs2_sparse_alloc(osb) && | ||
4130 | (OCFS2_I(inode)->ip_clusters != cpos), | ||
4131 | "Device %s, asking for sparse allocation: inode %llu, " | ||
4132 | "cpos %u, clusters %u\n", | ||
4133 | osb->dev_str, | ||
4134 | (unsigned long long)OCFS2_I(inode)->ip_blkno, cpos, | ||
4135 | OCFS2_I(inode)->ip_clusters); | ||
4136 | |||
4137 | memset(&rec, 0, sizeof(rec)); | 4420 | memset(&rec, 0, sizeof(rec)); |
4138 | rec.e_cpos = cpu_to_le32(cpos); | 4421 | rec.e_cpos = cpu_to_le32(cpos); |
4139 | rec.e_blkno = cpu_to_le64(start_blk); | 4422 | rec.e_blkno = cpu_to_le64(start_blk); |
4140 | rec.e_leaf_clusters = cpu_to_le16(new_clusters); | 4423 | rec.e_leaf_clusters = cpu_to_le16(new_clusters); |
4141 | rec.e_flags = flags; | 4424 | rec.e_flags = flags; |
4425 | status = ocfs2_et_insert_check(inode, et, &rec); | ||
4426 | if (status) { | ||
4427 | mlog_errno(status); | ||
4428 | goto bail; | ||
4429 | } | ||
4142 | 4430 | ||
4143 | status = ocfs2_figure_insert_type(inode, fe_bh, &last_eb_bh, &rec, | 4431 | status = ocfs2_figure_insert_type(inode, et, &last_eb_bh, &rec, |
4144 | &free_records, &insert); | 4432 | &free_records, &insert); |
4145 | if (status < 0) { | 4433 | if (status < 0) { |
4146 | mlog_errno(status); | 4434 | mlog_errno(status); |
@@ -4154,7 +4442,7 @@ int ocfs2_insert_extent(struct ocfs2_super *osb, | |||
4154 | free_records, insert.ins_tree_depth); | 4442 | free_records, insert.ins_tree_depth); |
4155 | 4443 | ||
4156 | if (insert.ins_contig == CONTIG_NONE && free_records == 0) { | 4444 | if (insert.ins_contig == CONTIG_NONE && free_records == 0) { |
4157 | status = ocfs2_grow_tree(inode, handle, fe_bh, | 4445 | status = ocfs2_grow_tree(inode, handle, et, |
4158 | &insert.ins_tree_depth, &last_eb_bh, | 4446 | &insert.ins_tree_depth, &last_eb_bh, |
4159 | meta_ac); | 4447 | meta_ac); |
4160 | if (status) { | 4448 | if (status) { |
@@ -4164,17 +4452,124 @@ int ocfs2_insert_extent(struct ocfs2_super *osb, | |||
4164 | } | 4452 | } |
4165 | 4453 | ||
4166 | /* Finally, we can add clusters. This might rotate the tree for us. */ | 4454 | /* Finally, we can add clusters. This might rotate the tree for us. */ |
4167 | status = ocfs2_do_insert_extent(inode, handle, fe_bh, &rec, &insert); | 4455 | status = ocfs2_do_insert_extent(inode, handle, et, &rec, &insert); |
4168 | if (status < 0) | 4456 | if (status < 0) |
4169 | mlog_errno(status); | 4457 | mlog_errno(status); |
4170 | else | 4458 | else if (et->et_ops == &ocfs2_dinode_et_ops) |
4171 | ocfs2_extent_map_insert_rec(inode, &rec); | 4459 | ocfs2_extent_map_insert_rec(inode, &rec); |
4172 | 4460 | ||
4173 | bail: | 4461 | bail: |
4174 | if (last_eb_bh) | 4462 | brelse(last_eb_bh); |
4175 | brelse(last_eb_bh); | 4463 | |
4464 | mlog_exit(status); | ||
4465 | return status; | ||
4466 | } | ||
4467 | |||
4468 | /* | ||
4469 | * Allcate and add clusters into the extent b-tree. | ||
4470 | * The new clusters(clusters_to_add) will be inserted at logical_offset. | ||
4471 | * The extent b-tree's root is specified by et, and | ||
4472 | * it is not limited to the file storage. Any extent tree can use this | ||
4473 | * function if it implements the proper ocfs2_extent_tree. | ||
4474 | */ | ||
4475 | int ocfs2_add_clusters_in_btree(struct ocfs2_super *osb, | ||
4476 | struct inode *inode, | ||
4477 | u32 *logical_offset, | ||
4478 | u32 clusters_to_add, | ||
4479 | int mark_unwritten, | ||
4480 | struct ocfs2_extent_tree *et, | ||
4481 | handle_t *handle, | ||
4482 | struct ocfs2_alloc_context *data_ac, | ||
4483 | struct ocfs2_alloc_context *meta_ac, | ||
4484 | enum ocfs2_alloc_restarted *reason_ret) | ||
4485 | { | ||
4486 | int status = 0; | ||
4487 | int free_extents; | ||
4488 | enum ocfs2_alloc_restarted reason = RESTART_NONE; | ||
4489 | u32 bit_off, num_bits; | ||
4490 | u64 block; | ||
4491 | u8 flags = 0; | ||
4492 | |||
4493 | BUG_ON(!clusters_to_add); | ||
4494 | |||
4495 | if (mark_unwritten) | ||
4496 | flags = OCFS2_EXT_UNWRITTEN; | ||
4497 | |||
4498 | free_extents = ocfs2_num_free_extents(osb, inode, et); | ||
4499 | if (free_extents < 0) { | ||
4500 | status = free_extents; | ||
4501 | mlog_errno(status); | ||
4502 | goto leave; | ||
4503 | } | ||
4504 | |||
4505 | /* there are two cases which could cause us to EAGAIN in the | ||
4506 | * we-need-more-metadata case: | ||
4507 | * 1) we haven't reserved *any* | ||
4508 | * 2) we are so fragmented, we've needed to add metadata too | ||
4509 | * many times. */ | ||
4510 | if (!free_extents && !meta_ac) { | ||
4511 | mlog(0, "we haven't reserved any metadata!\n"); | ||
4512 | status = -EAGAIN; | ||
4513 | reason = RESTART_META; | ||
4514 | goto leave; | ||
4515 | } else if ((!free_extents) | ||
4516 | && (ocfs2_alloc_context_bits_left(meta_ac) | ||
4517 | < ocfs2_extend_meta_needed(et->et_root_el))) { | ||
4518 | mlog(0, "filesystem is really fragmented...\n"); | ||
4519 | status = -EAGAIN; | ||
4520 | reason = RESTART_META; | ||
4521 | goto leave; | ||
4522 | } | ||
4523 | |||
4524 | status = __ocfs2_claim_clusters(osb, handle, data_ac, 1, | ||
4525 | clusters_to_add, &bit_off, &num_bits); | ||
4526 | if (status < 0) { | ||
4527 | if (status != -ENOSPC) | ||
4528 | mlog_errno(status); | ||
4529 | goto leave; | ||
4530 | } | ||
4176 | 4531 | ||
4532 | BUG_ON(num_bits > clusters_to_add); | ||
4533 | |||
4534 | /* reserve our write early -- insert_extent may update the inode */ | ||
4535 | status = ocfs2_journal_access(handle, inode, et->et_root_bh, | ||
4536 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
4537 | if (status < 0) { | ||
4538 | mlog_errno(status); | ||
4539 | goto leave; | ||
4540 | } | ||
4541 | |||
4542 | block = ocfs2_clusters_to_blocks(osb->sb, bit_off); | ||
4543 | mlog(0, "Allocating %u clusters at block %u for inode %llu\n", | ||
4544 | num_bits, bit_off, (unsigned long long)OCFS2_I(inode)->ip_blkno); | ||
4545 | status = ocfs2_insert_extent(osb, handle, inode, et, | ||
4546 | *logical_offset, block, | ||
4547 | num_bits, flags, meta_ac); | ||
4548 | if (status < 0) { | ||
4549 | mlog_errno(status); | ||
4550 | goto leave; | ||
4551 | } | ||
4552 | |||
4553 | status = ocfs2_journal_dirty(handle, et->et_root_bh); | ||
4554 | if (status < 0) { | ||
4555 | mlog_errno(status); | ||
4556 | goto leave; | ||
4557 | } | ||
4558 | |||
4559 | clusters_to_add -= num_bits; | ||
4560 | *logical_offset += num_bits; | ||
4561 | |||
4562 | if (clusters_to_add) { | ||
4563 | mlog(0, "need to alloc once more, wanted = %u\n", | ||
4564 | clusters_to_add); | ||
4565 | status = -EAGAIN; | ||
4566 | reason = RESTART_TRANS; | ||
4567 | } | ||
4568 | |||
4569 | leave: | ||
4177 | mlog_exit(status); | 4570 | mlog_exit(status); |
4571 | if (reason_ret) | ||
4572 | *reason_ret = reason; | ||
4178 | return status; | 4573 | return status; |
4179 | } | 4574 | } |
4180 | 4575 | ||
@@ -4201,7 +4596,7 @@ static void ocfs2_make_right_split_rec(struct super_block *sb, | |||
4201 | static int ocfs2_split_and_insert(struct inode *inode, | 4596 | static int ocfs2_split_and_insert(struct inode *inode, |
4202 | handle_t *handle, | 4597 | handle_t *handle, |
4203 | struct ocfs2_path *path, | 4598 | struct ocfs2_path *path, |
4204 | struct buffer_head *di_bh, | 4599 | struct ocfs2_extent_tree *et, |
4205 | struct buffer_head **last_eb_bh, | 4600 | struct buffer_head **last_eb_bh, |
4206 | int split_index, | 4601 | int split_index, |
4207 | struct ocfs2_extent_rec *orig_split_rec, | 4602 | struct ocfs2_extent_rec *orig_split_rec, |
@@ -4215,7 +4610,6 @@ static int ocfs2_split_and_insert(struct inode *inode, | |||
4215 | struct ocfs2_extent_rec split_rec = *orig_split_rec; | 4610 | struct ocfs2_extent_rec split_rec = *orig_split_rec; |
4216 | struct ocfs2_insert_type insert; | 4611 | struct ocfs2_insert_type insert; |
4217 | struct ocfs2_extent_block *eb; | 4612 | struct ocfs2_extent_block *eb; |
4218 | struct ocfs2_dinode *di; | ||
4219 | 4613 | ||
4220 | leftright: | 4614 | leftright: |
4221 | /* | 4615 | /* |
@@ -4224,8 +4618,7 @@ leftright: | |||
4224 | */ | 4618 | */ |
4225 | rec = path_leaf_el(path)->l_recs[split_index]; | 4619 | rec = path_leaf_el(path)->l_recs[split_index]; |
4226 | 4620 | ||
4227 | di = (struct ocfs2_dinode *)di_bh->b_data; | 4621 | rightmost_el = et->et_root_el; |
4228 | rightmost_el = &di->id2.i_list; | ||
4229 | 4622 | ||
4230 | depth = le16_to_cpu(rightmost_el->l_tree_depth); | 4623 | depth = le16_to_cpu(rightmost_el->l_tree_depth); |
4231 | if (depth) { | 4624 | if (depth) { |
@@ -4236,8 +4629,8 @@ leftright: | |||
4236 | 4629 | ||
4237 | if (le16_to_cpu(rightmost_el->l_next_free_rec) == | 4630 | if (le16_to_cpu(rightmost_el->l_next_free_rec) == |
4238 | le16_to_cpu(rightmost_el->l_count)) { | 4631 | le16_to_cpu(rightmost_el->l_count)) { |
4239 | ret = ocfs2_grow_tree(inode, handle, di_bh, &depth, last_eb_bh, | 4632 | ret = ocfs2_grow_tree(inode, handle, et, |
4240 | meta_ac); | 4633 | &depth, last_eb_bh, meta_ac); |
4241 | if (ret) { | 4634 | if (ret) { |
4242 | mlog_errno(ret); | 4635 | mlog_errno(ret); |
4243 | goto out; | 4636 | goto out; |
@@ -4274,8 +4667,7 @@ leftright: | |||
4274 | do_leftright = 1; | 4667 | do_leftright = 1; |
4275 | } | 4668 | } |
4276 | 4669 | ||
4277 | ret = ocfs2_do_insert_extent(inode, handle, di_bh, &split_rec, | 4670 | ret = ocfs2_do_insert_extent(inode, handle, et, &split_rec, &insert); |
4278 | &insert); | ||
4279 | if (ret) { | 4671 | if (ret) { |
4280 | mlog_errno(ret); | 4672 | mlog_errno(ret); |
4281 | goto out; | 4673 | goto out; |
@@ -4317,8 +4709,9 @@ out: | |||
4317 | * of the tree is required. All other cases will degrade into a less | 4709 | * of the tree is required. All other cases will degrade into a less |
4318 | * optimal tree layout. | 4710 | * optimal tree layout. |
4319 | * | 4711 | * |
4320 | * last_eb_bh should be the rightmost leaf block for any inode with a | 4712 | * last_eb_bh should be the rightmost leaf block for any extent |
4321 | * btree. Since a split may grow the tree or a merge might shrink it, the caller cannot trust the contents of that buffer after this call. | 4713 | * btree. Since a split may grow the tree or a merge might shrink it, |
4714 | * the caller cannot trust the contents of that buffer after this call. | ||
4322 | * | 4715 | * |
4323 | * This code is optimized for readability - several passes might be | 4716 | * This code is optimized for readability - several passes might be |
4324 | * made over certain portions of the tree. All of those blocks will | 4717 | * made over certain portions of the tree. All of those blocks will |
@@ -4326,7 +4719,7 @@ out: | |||
4326 | * extra overhead is not expressed in terms of disk reads. | 4719 | * extra overhead is not expressed in terms of disk reads. |
4327 | */ | 4720 | */ |
4328 | static int __ocfs2_mark_extent_written(struct inode *inode, | 4721 | static int __ocfs2_mark_extent_written(struct inode *inode, |
4329 | struct buffer_head *di_bh, | 4722 | struct ocfs2_extent_tree *et, |
4330 | handle_t *handle, | 4723 | handle_t *handle, |
4331 | struct ocfs2_path *path, | 4724 | struct ocfs2_path *path, |
4332 | int split_index, | 4725 | int split_index, |
@@ -4366,11 +4759,9 @@ static int __ocfs2_mark_extent_written(struct inode *inode, | |||
4366 | */ | 4759 | */ |
4367 | if (path->p_tree_depth) { | 4760 | if (path->p_tree_depth) { |
4368 | struct ocfs2_extent_block *eb; | 4761 | struct ocfs2_extent_block *eb; |
4369 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; | ||
4370 | 4762 | ||
4371 | ret = ocfs2_read_block(OCFS2_SB(inode->i_sb), | 4763 | ret = ocfs2_read_block(inode, ocfs2_et_get_last_eb_blk(et), |
4372 | le64_to_cpu(di->i_last_eb_blk), | 4764 | &last_eb_bh); |
4373 | &last_eb_bh, OCFS2_BH_CACHED, inode); | ||
4374 | if (ret) { | 4765 | if (ret) { |
4375 | mlog_exit(ret); | 4766 | mlog_exit(ret); |
4376 | goto out; | 4767 | goto out; |
@@ -4403,7 +4794,7 @@ static int __ocfs2_mark_extent_written(struct inode *inode, | |||
4403 | if (ctxt.c_split_covers_rec) | 4794 | if (ctxt.c_split_covers_rec) |
4404 | el->l_recs[split_index] = *split_rec; | 4795 | el->l_recs[split_index] = *split_rec; |
4405 | else | 4796 | else |
4406 | ret = ocfs2_split_and_insert(inode, handle, path, di_bh, | 4797 | ret = ocfs2_split_and_insert(inode, handle, path, et, |
4407 | &last_eb_bh, split_index, | 4798 | &last_eb_bh, split_index, |
4408 | split_rec, meta_ac); | 4799 | split_rec, meta_ac); |
4409 | if (ret) | 4800 | if (ret) |
@@ -4411,7 +4802,7 @@ static int __ocfs2_mark_extent_written(struct inode *inode, | |||
4411 | } else { | 4802 | } else { |
4412 | ret = ocfs2_try_to_merge_extent(inode, handle, path, | 4803 | ret = ocfs2_try_to_merge_extent(inode, handle, path, |
4413 | split_index, split_rec, | 4804 | split_index, split_rec, |
4414 | dealloc, &ctxt); | 4805 | dealloc, &ctxt, et); |
4415 | if (ret) | 4806 | if (ret) |
4416 | mlog_errno(ret); | 4807 | mlog_errno(ret); |
4417 | } | 4808 | } |
@@ -4429,7 +4820,8 @@ out: | |||
4429 | * | 4820 | * |
4430 | * The caller is responsible for passing down meta_ac if we'll need it. | 4821 | * The caller is responsible for passing down meta_ac if we'll need it. |
4431 | */ | 4822 | */ |
4432 | int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *di_bh, | 4823 | int ocfs2_mark_extent_written(struct inode *inode, |
4824 | struct ocfs2_extent_tree *et, | ||
4433 | handle_t *handle, u32 cpos, u32 len, u32 phys, | 4825 | handle_t *handle, u32 cpos, u32 len, u32 phys, |
4434 | struct ocfs2_alloc_context *meta_ac, | 4826 | struct ocfs2_alloc_context *meta_ac, |
4435 | struct ocfs2_cached_dealloc_ctxt *dealloc) | 4827 | struct ocfs2_cached_dealloc_ctxt *dealloc) |
@@ -4455,10 +4847,14 @@ int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *di_bh, | |||
4455 | /* | 4847 | /* |
4456 | * XXX: This should be fixed up so that we just re-insert the | 4848 | * XXX: This should be fixed up so that we just re-insert the |
4457 | * next extent records. | 4849 | * next extent records. |
4850 | * | ||
4851 | * XXX: This is a hack on the extent tree, maybe it should be | ||
4852 | * an op? | ||
4458 | */ | 4853 | */ |
4459 | ocfs2_extent_map_trunc(inode, 0); | 4854 | if (et->et_ops == &ocfs2_dinode_et_ops) |
4855 | ocfs2_extent_map_trunc(inode, 0); | ||
4460 | 4856 | ||
4461 | left_path = ocfs2_new_inode_path(di_bh); | 4857 | left_path = ocfs2_new_path(et->et_root_bh, et->et_root_el); |
4462 | if (!left_path) { | 4858 | if (!left_path) { |
4463 | ret = -ENOMEM; | 4859 | ret = -ENOMEM; |
4464 | mlog_errno(ret); | 4860 | mlog_errno(ret); |
@@ -4489,8 +4885,9 @@ int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *di_bh, | |||
4489 | split_rec.e_flags = path_leaf_el(left_path)->l_recs[index].e_flags; | 4885 | split_rec.e_flags = path_leaf_el(left_path)->l_recs[index].e_flags; |
4490 | split_rec.e_flags &= ~OCFS2_EXT_UNWRITTEN; | 4886 | split_rec.e_flags &= ~OCFS2_EXT_UNWRITTEN; |
4491 | 4887 | ||
4492 | ret = __ocfs2_mark_extent_written(inode, di_bh, handle, left_path, | 4888 | ret = __ocfs2_mark_extent_written(inode, et, handle, left_path, |
4493 | index, &split_rec, meta_ac, dealloc); | 4889 | index, &split_rec, meta_ac, |
4890 | dealloc); | ||
4494 | if (ret) | 4891 | if (ret) |
4495 | mlog_errno(ret); | 4892 | mlog_errno(ret); |
4496 | 4893 | ||
@@ -4499,13 +4896,12 @@ out: | |||
4499 | return ret; | 4896 | return ret; |
4500 | } | 4897 | } |
4501 | 4898 | ||
4502 | static int ocfs2_split_tree(struct inode *inode, struct buffer_head *di_bh, | 4899 | static int ocfs2_split_tree(struct inode *inode, struct ocfs2_extent_tree *et, |
4503 | handle_t *handle, struct ocfs2_path *path, | 4900 | handle_t *handle, struct ocfs2_path *path, |
4504 | int index, u32 new_range, | 4901 | int index, u32 new_range, |
4505 | struct ocfs2_alloc_context *meta_ac) | 4902 | struct ocfs2_alloc_context *meta_ac) |
4506 | { | 4903 | { |
4507 | int ret, depth, credits = handle->h_buffer_credits; | 4904 | int ret, depth, credits = handle->h_buffer_credits; |
4508 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; | ||
4509 | struct buffer_head *last_eb_bh = NULL; | 4905 | struct buffer_head *last_eb_bh = NULL; |
4510 | struct ocfs2_extent_block *eb; | 4906 | struct ocfs2_extent_block *eb; |
4511 | struct ocfs2_extent_list *rightmost_el, *el; | 4907 | struct ocfs2_extent_list *rightmost_el, *el; |
@@ -4522,9 +4918,8 @@ static int ocfs2_split_tree(struct inode *inode, struct buffer_head *di_bh, | |||
4522 | 4918 | ||
4523 | depth = path->p_tree_depth; | 4919 | depth = path->p_tree_depth; |
4524 | if (depth > 0) { | 4920 | if (depth > 0) { |
4525 | ret = ocfs2_read_block(OCFS2_SB(inode->i_sb), | 4921 | ret = ocfs2_read_block(inode, ocfs2_et_get_last_eb_blk(et), |
4526 | le64_to_cpu(di->i_last_eb_blk), | 4922 | &last_eb_bh); |
4527 | &last_eb_bh, OCFS2_BH_CACHED, inode); | ||
4528 | if (ret < 0) { | 4923 | if (ret < 0) { |
4529 | mlog_errno(ret); | 4924 | mlog_errno(ret); |
4530 | goto out; | 4925 | goto out; |
@@ -4535,7 +4930,8 @@ static int ocfs2_split_tree(struct inode *inode, struct buffer_head *di_bh, | |||
4535 | } else | 4930 | } else |
4536 | rightmost_el = path_leaf_el(path); | 4931 | rightmost_el = path_leaf_el(path); |
4537 | 4932 | ||
4538 | credits += path->p_tree_depth + ocfs2_extend_meta_needed(di); | 4933 | credits += path->p_tree_depth + |
4934 | ocfs2_extend_meta_needed(et->et_root_el); | ||
4539 | ret = ocfs2_extend_trans(handle, credits); | 4935 | ret = ocfs2_extend_trans(handle, credits); |
4540 | if (ret) { | 4936 | if (ret) { |
4541 | mlog_errno(ret); | 4937 | mlog_errno(ret); |
@@ -4544,7 +4940,7 @@ static int ocfs2_split_tree(struct inode *inode, struct buffer_head *di_bh, | |||
4544 | 4940 | ||
4545 | if (le16_to_cpu(rightmost_el->l_next_free_rec) == | 4941 | if (le16_to_cpu(rightmost_el->l_next_free_rec) == |
4546 | le16_to_cpu(rightmost_el->l_count)) { | 4942 | le16_to_cpu(rightmost_el->l_count)) { |
4547 | ret = ocfs2_grow_tree(inode, handle, di_bh, &depth, &last_eb_bh, | 4943 | ret = ocfs2_grow_tree(inode, handle, et, &depth, &last_eb_bh, |
4548 | meta_ac); | 4944 | meta_ac); |
4549 | if (ret) { | 4945 | if (ret) { |
4550 | mlog_errno(ret); | 4946 | mlog_errno(ret); |
@@ -4558,7 +4954,7 @@ static int ocfs2_split_tree(struct inode *inode, struct buffer_head *di_bh, | |||
4558 | insert.ins_split = SPLIT_RIGHT; | 4954 | insert.ins_split = SPLIT_RIGHT; |
4559 | insert.ins_tree_depth = depth; | 4955 | insert.ins_tree_depth = depth; |
4560 | 4956 | ||
4561 | ret = ocfs2_do_insert_extent(inode, handle, di_bh, &split_rec, &insert); | 4957 | ret = ocfs2_do_insert_extent(inode, handle, et, &split_rec, &insert); |
4562 | if (ret) | 4958 | if (ret) |
4563 | mlog_errno(ret); | 4959 | mlog_errno(ret); |
4564 | 4960 | ||
@@ -4570,7 +4966,8 @@ out: | |||
4570 | static int ocfs2_truncate_rec(struct inode *inode, handle_t *handle, | 4966 | static int ocfs2_truncate_rec(struct inode *inode, handle_t *handle, |
4571 | struct ocfs2_path *path, int index, | 4967 | struct ocfs2_path *path, int index, |
4572 | struct ocfs2_cached_dealloc_ctxt *dealloc, | 4968 | struct ocfs2_cached_dealloc_ctxt *dealloc, |
4573 | u32 cpos, u32 len) | 4969 | u32 cpos, u32 len, |
4970 | struct ocfs2_extent_tree *et) | ||
4574 | { | 4971 | { |
4575 | int ret; | 4972 | int ret; |
4576 | u32 left_cpos, rec_range, trunc_range; | 4973 | u32 left_cpos, rec_range, trunc_range; |
@@ -4582,7 +4979,7 @@ static int ocfs2_truncate_rec(struct inode *inode, handle_t *handle, | |||
4582 | struct ocfs2_extent_block *eb; | 4979 | struct ocfs2_extent_block *eb; |
4583 | 4980 | ||
4584 | if (ocfs2_is_empty_extent(&el->l_recs[0]) && index > 0) { | 4981 | if (ocfs2_is_empty_extent(&el->l_recs[0]) && index > 0) { |
4585 | ret = ocfs2_rotate_tree_left(inode, handle, path, dealloc); | 4982 | ret = ocfs2_rotate_tree_left(inode, handle, path, dealloc, et); |
4586 | if (ret) { | 4983 | if (ret) { |
4587 | mlog_errno(ret); | 4984 | mlog_errno(ret); |
4588 | goto out; | 4985 | goto out; |
@@ -4713,7 +5110,7 @@ static int ocfs2_truncate_rec(struct inode *inode, handle_t *handle, | |||
4713 | 5110 | ||
4714 | ocfs2_journal_dirty(handle, path_leaf_bh(path)); | 5111 | ocfs2_journal_dirty(handle, path_leaf_bh(path)); |
4715 | 5112 | ||
4716 | ret = ocfs2_rotate_tree_left(inode, handle, path, dealloc); | 5113 | ret = ocfs2_rotate_tree_left(inode, handle, path, dealloc, et); |
4717 | if (ret) { | 5114 | if (ret) { |
4718 | mlog_errno(ret); | 5115 | mlog_errno(ret); |
4719 | goto out; | 5116 | goto out; |
@@ -4724,7 +5121,8 @@ out: | |||
4724 | return ret; | 5121 | return ret; |
4725 | } | 5122 | } |
4726 | 5123 | ||
4727 | int ocfs2_remove_extent(struct inode *inode, struct buffer_head *di_bh, | 5124 | int ocfs2_remove_extent(struct inode *inode, |
5125 | struct ocfs2_extent_tree *et, | ||
4728 | u32 cpos, u32 len, handle_t *handle, | 5126 | u32 cpos, u32 len, handle_t *handle, |
4729 | struct ocfs2_alloc_context *meta_ac, | 5127 | struct ocfs2_alloc_context *meta_ac, |
4730 | struct ocfs2_cached_dealloc_ctxt *dealloc) | 5128 | struct ocfs2_cached_dealloc_ctxt *dealloc) |
@@ -4733,11 +5131,11 @@ int ocfs2_remove_extent(struct inode *inode, struct buffer_head *di_bh, | |||
4733 | u32 rec_range, trunc_range; | 5131 | u32 rec_range, trunc_range; |
4734 | struct ocfs2_extent_rec *rec; | 5132 | struct ocfs2_extent_rec *rec; |
4735 | struct ocfs2_extent_list *el; | 5133 | struct ocfs2_extent_list *el; |
4736 | struct ocfs2_path *path; | 5134 | struct ocfs2_path *path = NULL; |
4737 | 5135 | ||
4738 | ocfs2_extent_map_trunc(inode, 0); | 5136 | ocfs2_extent_map_trunc(inode, 0); |
4739 | 5137 | ||
4740 | path = ocfs2_new_inode_path(di_bh); | 5138 | path = ocfs2_new_path(et->et_root_bh, et->et_root_el); |
4741 | if (!path) { | 5139 | if (!path) { |
4742 | ret = -ENOMEM; | 5140 | ret = -ENOMEM; |
4743 | mlog_errno(ret); | 5141 | mlog_errno(ret); |
@@ -4790,13 +5188,13 @@ int ocfs2_remove_extent(struct inode *inode, struct buffer_head *di_bh, | |||
4790 | 5188 | ||
4791 | if (le32_to_cpu(rec->e_cpos) == cpos || rec_range == trunc_range) { | 5189 | if (le32_to_cpu(rec->e_cpos) == cpos || rec_range == trunc_range) { |
4792 | ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc, | 5190 | ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc, |
4793 | cpos, len); | 5191 | cpos, len, et); |
4794 | if (ret) { | 5192 | if (ret) { |
4795 | mlog_errno(ret); | 5193 | mlog_errno(ret); |
4796 | goto out; | 5194 | goto out; |
4797 | } | 5195 | } |
4798 | } else { | 5196 | } else { |
4799 | ret = ocfs2_split_tree(inode, di_bh, handle, path, index, | 5197 | ret = ocfs2_split_tree(inode, et, handle, path, index, |
4800 | trunc_range, meta_ac); | 5198 | trunc_range, meta_ac); |
4801 | if (ret) { | 5199 | if (ret) { |
4802 | mlog_errno(ret); | 5200 | mlog_errno(ret); |
@@ -4845,7 +5243,7 @@ int ocfs2_remove_extent(struct inode *inode, struct buffer_head *di_bh, | |||
4845 | } | 5243 | } |
4846 | 5244 | ||
4847 | ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc, | 5245 | ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc, |
4848 | cpos, len); | 5246 | cpos, len, et); |
4849 | if (ret) { | 5247 | if (ret) { |
4850 | mlog_errno(ret); | 5248 | mlog_errno(ret); |
4851 | goto out; | 5249 | goto out; |
@@ -5188,8 +5586,7 @@ static int ocfs2_get_truncate_log_info(struct ocfs2_super *osb, | |||
5188 | goto bail; | 5586 | goto bail; |
5189 | } | 5587 | } |
5190 | 5588 | ||
5191 | status = ocfs2_read_block(osb, OCFS2_I(inode)->ip_blkno, &bh, | 5589 | status = ocfs2_read_block(inode, OCFS2_I(inode)->ip_blkno, &bh); |
5192 | OCFS2_BH_CACHED, inode); | ||
5193 | if (status < 0) { | 5590 | if (status < 0) { |
5194 | iput(inode); | 5591 | iput(inode); |
5195 | mlog_errno(status); | 5592 | mlog_errno(status); |
@@ -5264,8 +5661,7 @@ int ocfs2_begin_truncate_log_recovery(struct ocfs2_super *osb, | |||
5264 | bail: | 5661 | bail: |
5265 | if (tl_inode) | 5662 | if (tl_inode) |
5266 | iput(tl_inode); | 5663 | iput(tl_inode); |
5267 | if (tl_bh) | 5664 | brelse(tl_bh); |
5268 | brelse(tl_bh); | ||
5269 | 5665 | ||
5270 | if (status < 0 && (*tl_copy)) { | 5666 | if (status < 0 && (*tl_copy)) { |
5271 | kfree(*tl_copy); | 5667 | kfree(*tl_copy); |
@@ -6008,20 +6404,13 @@ bail: | |||
6008 | return status; | 6404 | return status; |
6009 | } | 6405 | } |
6010 | 6406 | ||
6011 | static int ocfs2_writeback_zero_func(handle_t *handle, struct buffer_head *bh) | 6407 | static int ocfs2_zero_func(handle_t *handle, struct buffer_head *bh) |
6012 | { | 6408 | { |
6013 | set_buffer_uptodate(bh); | 6409 | set_buffer_uptodate(bh); |
6014 | mark_buffer_dirty(bh); | 6410 | mark_buffer_dirty(bh); |
6015 | return 0; | 6411 | return 0; |
6016 | } | 6412 | } |
6017 | 6413 | ||
6018 | static int ocfs2_ordered_zero_func(handle_t *handle, struct buffer_head *bh) | ||
6019 | { | ||
6020 | set_buffer_uptodate(bh); | ||
6021 | mark_buffer_dirty(bh); | ||
6022 | return ocfs2_journal_dirty_data(handle, bh); | ||
6023 | } | ||
6024 | |||
6025 | static void ocfs2_map_and_dirty_page(struct inode *inode, handle_t *handle, | 6414 | static void ocfs2_map_and_dirty_page(struct inode *inode, handle_t *handle, |
6026 | unsigned int from, unsigned int to, | 6415 | unsigned int from, unsigned int to, |
6027 | struct page *page, int zero, u64 *phys) | 6416 | struct page *page, int zero, u64 *phys) |
@@ -6040,17 +6429,18 @@ static void ocfs2_map_and_dirty_page(struct inode *inode, handle_t *handle, | |||
6040 | * here if they aren't - ocfs2_map_page_blocks() | 6429 | * here if they aren't - ocfs2_map_page_blocks() |
6041 | * might've skipped some | 6430 | * might've skipped some |
6042 | */ | 6431 | */ |
6043 | if (ocfs2_should_order_data(inode)) { | 6432 | ret = walk_page_buffers(handle, page_buffers(page), |
6044 | ret = walk_page_buffers(handle, | 6433 | from, to, &partial, |
6045 | page_buffers(page), | 6434 | ocfs2_zero_func); |
6046 | from, to, &partial, | 6435 | if (ret < 0) |
6047 | ocfs2_ordered_zero_func); | 6436 | mlog_errno(ret); |
6048 | if (ret < 0) | 6437 | else if (ocfs2_should_order_data(inode)) { |
6049 | mlog_errno(ret); | 6438 | ret = ocfs2_jbd2_file_inode(handle, inode); |
6050 | } else { | 6439 | #ifdef CONFIG_OCFS2_COMPAT_JBD |
6051 | ret = walk_page_buffers(handle, page_buffers(page), | 6440 | ret = walk_page_buffers(handle, page_buffers(page), |
6052 | from, to, &partial, | 6441 | from, to, &partial, |
6053 | ocfs2_writeback_zero_func); | 6442 | ocfs2_journal_dirty_data); |
6443 | #endif | ||
6054 | if (ret < 0) | 6444 | if (ret < 0) |
6055 | mlog_errno(ret); | 6445 | mlog_errno(ret); |
6056 | } | 6446 | } |
@@ -6215,20 +6605,29 @@ out: | |||
6215 | return ret; | 6605 | return ret; |
6216 | } | 6606 | } |
6217 | 6607 | ||
6218 | static void ocfs2_zero_dinode_id2(struct inode *inode, struct ocfs2_dinode *di) | 6608 | static void ocfs2_zero_dinode_id2_with_xattr(struct inode *inode, |
6609 | struct ocfs2_dinode *di) | ||
6219 | { | 6610 | { |
6220 | unsigned int blocksize = 1 << inode->i_sb->s_blocksize_bits; | 6611 | unsigned int blocksize = 1 << inode->i_sb->s_blocksize_bits; |
6612 | unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size); | ||
6221 | 6613 | ||
6222 | memset(&di->id2, 0, blocksize - offsetof(struct ocfs2_dinode, id2)); | 6614 | if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL) |
6615 | memset(&di->id2, 0, blocksize - | ||
6616 | offsetof(struct ocfs2_dinode, id2) - | ||
6617 | xattrsize); | ||
6618 | else | ||
6619 | memset(&di->id2, 0, blocksize - | ||
6620 | offsetof(struct ocfs2_dinode, id2)); | ||
6223 | } | 6621 | } |
6224 | 6622 | ||
6225 | void ocfs2_dinode_new_extent_list(struct inode *inode, | 6623 | void ocfs2_dinode_new_extent_list(struct inode *inode, |
6226 | struct ocfs2_dinode *di) | 6624 | struct ocfs2_dinode *di) |
6227 | { | 6625 | { |
6228 | ocfs2_zero_dinode_id2(inode, di); | 6626 | ocfs2_zero_dinode_id2_with_xattr(inode, di); |
6229 | di->id2.i_list.l_tree_depth = 0; | 6627 | di->id2.i_list.l_tree_depth = 0; |
6230 | di->id2.i_list.l_next_free_rec = 0; | 6628 | di->id2.i_list.l_next_free_rec = 0; |
6231 | di->id2.i_list.l_count = cpu_to_le16(ocfs2_extent_recs_per_inode(inode->i_sb)); | 6629 | di->id2.i_list.l_count = cpu_to_le16( |
6630 | ocfs2_extent_recs_per_inode_with_xattr(inode->i_sb, di)); | ||
6232 | } | 6631 | } |
6233 | 6632 | ||
6234 | void ocfs2_set_inode_data_inline(struct inode *inode, struct ocfs2_dinode *di) | 6633 | void ocfs2_set_inode_data_inline(struct inode *inode, struct ocfs2_dinode *di) |
@@ -6245,9 +6644,10 @@ void ocfs2_set_inode_data_inline(struct inode *inode, struct ocfs2_dinode *di) | |||
6245 | * We clear the entire i_data structure here so that all | 6644 | * We clear the entire i_data structure here so that all |
6246 | * fields can be properly initialized. | 6645 | * fields can be properly initialized. |
6247 | */ | 6646 | */ |
6248 | ocfs2_zero_dinode_id2(inode, di); | 6647 | ocfs2_zero_dinode_id2_with_xattr(inode, di); |
6249 | 6648 | ||
6250 | idata->id_count = cpu_to_le16(ocfs2_max_inline_data(inode->i_sb)); | 6649 | idata->id_count = cpu_to_le16( |
6650 | ocfs2_max_inline_data_with_xattr(inode->i_sb, di)); | ||
6251 | } | 6651 | } |
6252 | 6652 | ||
6253 | int ocfs2_convert_inline_data_to_extents(struct inode *inode, | 6653 | int ocfs2_convert_inline_data_to_extents(struct inode *inode, |
@@ -6262,6 +6662,7 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode, | |||
6262 | struct ocfs2_alloc_context *data_ac = NULL; | 6662 | struct ocfs2_alloc_context *data_ac = NULL; |
6263 | struct page **pages = NULL; | 6663 | struct page **pages = NULL; |
6264 | loff_t end = osb->s_clustersize; | 6664 | loff_t end = osb->s_clustersize; |
6665 | struct ocfs2_extent_tree et; | ||
6265 | 6666 | ||
6266 | has_data = i_size_read(inode) ? 1 : 0; | 6667 | has_data = i_size_read(inode) ? 1 : 0; |
6267 | 6668 | ||
@@ -6361,7 +6762,8 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode, | |||
6361 | * this proves to be false, we could always re-build | 6762 | * this proves to be false, we could always re-build |
6362 | * the in-inode data from our pages. | 6763 | * the in-inode data from our pages. |
6363 | */ | 6764 | */ |
6364 | ret = ocfs2_insert_extent(osb, handle, inode, di_bh, | 6765 | ocfs2_init_dinode_extent_tree(&et, inode, di_bh); |
6766 | ret = ocfs2_insert_extent(osb, handle, inode, &et, | ||
6365 | 0, block, 1, 0, NULL); | 6767 | 0, block, 1, 0, NULL); |
6366 | if (ret) { | 6768 | if (ret) { |
6367 | mlog_errno(ret); | 6769 | mlog_errno(ret); |
@@ -6404,13 +6806,14 @@ int ocfs2_commit_truncate(struct ocfs2_super *osb, | |||
6404 | handle_t *handle = NULL; | 6806 | handle_t *handle = NULL; |
6405 | struct inode *tl_inode = osb->osb_tl_inode; | 6807 | struct inode *tl_inode = osb->osb_tl_inode; |
6406 | struct ocfs2_path *path = NULL; | 6808 | struct ocfs2_path *path = NULL; |
6809 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)fe_bh->b_data; | ||
6407 | 6810 | ||
6408 | mlog_entry_void(); | 6811 | mlog_entry_void(); |
6409 | 6812 | ||
6410 | new_highest_cpos = ocfs2_clusters_for_bytes(osb->sb, | 6813 | new_highest_cpos = ocfs2_clusters_for_bytes(osb->sb, |
6411 | i_size_read(inode)); | 6814 | i_size_read(inode)); |
6412 | 6815 | ||
6413 | path = ocfs2_new_inode_path(fe_bh); | 6816 | path = ocfs2_new_path(fe_bh, &di->id2.i_list); |
6414 | if (!path) { | 6817 | if (!path) { |
6415 | status = -ENOMEM; | 6818 | status = -ENOMEM; |
6416 | mlog_errno(status); | 6819 | mlog_errno(status); |
@@ -6581,8 +6984,8 @@ int ocfs2_prepare_truncate(struct ocfs2_super *osb, | |||
6581 | ocfs2_init_dealloc_ctxt(&(*tc)->tc_dealloc); | 6984 | ocfs2_init_dealloc_ctxt(&(*tc)->tc_dealloc); |
6582 | 6985 | ||
6583 | if (fe->id2.i_list.l_tree_depth) { | 6986 | if (fe->id2.i_list.l_tree_depth) { |
6584 | status = ocfs2_read_block(osb, le64_to_cpu(fe->i_last_eb_blk), | 6987 | status = ocfs2_read_block(inode, le64_to_cpu(fe->i_last_eb_blk), |
6585 | &last_eb_bh, OCFS2_BH_CACHED, inode); | 6988 | &last_eb_bh); |
6586 | if (status < 0) { | 6989 | if (status < 0) { |
6587 | mlog_errno(status); | 6990 | mlog_errno(status); |
6588 | goto bail; | 6991 | goto bail; |
@@ -6695,8 +7098,7 @@ static void ocfs2_free_truncate_context(struct ocfs2_truncate_context *tc) | |||
6695 | mlog(ML_NOTICE, | 7098 | mlog(ML_NOTICE, |
6696 | "Truncate completion has non-empty dealloc context\n"); | 7099 | "Truncate completion has non-empty dealloc context\n"); |
6697 | 7100 | ||
6698 | if (tc->tc_last_eb_bh) | 7101 | brelse(tc->tc_last_eb_bh); |
6699 | brelse(tc->tc_last_eb_bh); | ||
6700 | 7102 | ||
6701 | kfree(tc); | 7103 | kfree(tc); |
6702 | } | 7104 | } |