diff options
Diffstat (limited to 'fs/ocfs2/alloc.c')
-rw-r--r-- | fs/ocfs2/alloc.c | 1342 |
1 files changed, 770 insertions, 572 deletions
diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c index ab513ddaeff2..38a42f5d59ff 100644 --- a/fs/ocfs2/alloc.c +++ b/fs/ocfs2/alloc.c | |||
@@ -49,10 +49,21 @@ | |||
49 | #include "super.h" | 49 | #include "super.h" |
50 | #include "uptodate.h" | 50 | #include "uptodate.h" |
51 | #include "xattr.h" | 51 | #include "xattr.h" |
52 | #include "refcounttree.h" | ||
52 | 53 | ||
53 | #include "buffer_head_io.h" | 54 | #include "buffer_head_io.h" |
54 | 55 | ||
56 | enum ocfs2_contig_type { | ||
57 | CONTIG_NONE = 0, | ||
58 | CONTIG_LEFT, | ||
59 | CONTIG_RIGHT, | ||
60 | CONTIG_LEFTRIGHT, | ||
61 | }; | ||
55 | 62 | ||
63 | static enum ocfs2_contig_type | ||
64 | ocfs2_extent_rec_contig(struct super_block *sb, | ||
65 | struct ocfs2_extent_rec *ext, | ||
66 | struct ocfs2_extent_rec *insert_rec); | ||
56 | /* | 67 | /* |
57 | * Operations for a specific extent tree type. | 68 | * Operations for a specific extent tree type. |
58 | * | 69 | * |
@@ -79,18 +90,30 @@ struct ocfs2_extent_tree_operations { | |||
79 | * that value. new_clusters is the delta, and must be | 90 | * that value. new_clusters is the delta, and must be |
80 | * added to the total. Required. | 91 | * added to the total. Required. |
81 | */ | 92 | */ |
82 | void (*eo_update_clusters)(struct inode *inode, | 93 | void (*eo_update_clusters)(struct ocfs2_extent_tree *et, |
83 | struct ocfs2_extent_tree *et, | ||
84 | u32 new_clusters); | 94 | u32 new_clusters); |
85 | 95 | ||
86 | /* | 96 | /* |
97 | * If this extent tree is supported by an extent map, insert | ||
98 | * a record into the map. | ||
99 | */ | ||
100 | void (*eo_extent_map_insert)(struct ocfs2_extent_tree *et, | ||
101 | struct ocfs2_extent_rec *rec); | ||
102 | |||
103 | /* | ||
104 | * If this extent tree is supported by an extent map, truncate the | ||
105 | * map to clusters, | ||
106 | */ | ||
107 | void (*eo_extent_map_truncate)(struct ocfs2_extent_tree *et, | ||
108 | u32 clusters); | ||
109 | |||
110 | /* | ||
87 | * If ->eo_insert_check() exists, it is called before rec is | 111 | * If ->eo_insert_check() exists, it is called before rec is |
88 | * inserted into the extent tree. It is optional. | 112 | * inserted into the extent tree. It is optional. |
89 | */ | 113 | */ |
90 | int (*eo_insert_check)(struct inode *inode, | 114 | int (*eo_insert_check)(struct ocfs2_extent_tree *et, |
91 | struct ocfs2_extent_tree *et, | ||
92 | struct ocfs2_extent_rec *rec); | 115 | struct ocfs2_extent_rec *rec); |
93 | int (*eo_sanity_check)(struct inode *inode, struct ocfs2_extent_tree *et); | 116 | int (*eo_sanity_check)(struct ocfs2_extent_tree *et); |
94 | 117 | ||
95 | /* | 118 | /* |
96 | * -------------------------------------------------------------- | 119 | * -------------------------------------------------------------- |
@@ -109,8 +132,17 @@ struct ocfs2_extent_tree_operations { | |||
109 | * it exists. If it does not, et->et_max_leaf_clusters is set | 132 | * it exists. If it does not, et->et_max_leaf_clusters is set |
110 | * to 0 (unlimited). Optional. | 133 | * to 0 (unlimited). Optional. |
111 | */ | 134 | */ |
112 | void (*eo_fill_max_leaf_clusters)(struct inode *inode, | 135 | void (*eo_fill_max_leaf_clusters)(struct ocfs2_extent_tree *et); |
113 | struct ocfs2_extent_tree *et); | 136 | |
137 | /* | ||
138 | * ->eo_extent_contig test whether the 2 ocfs2_extent_rec | ||
139 | * are contiguous or not. Optional. Don't need to set it if use | ||
140 | * ocfs2_extent_rec as the tree leaf. | ||
141 | */ | ||
142 | enum ocfs2_contig_type | ||
143 | (*eo_extent_contig)(struct ocfs2_extent_tree *et, | ||
144 | struct ocfs2_extent_rec *ext, | ||
145 | struct ocfs2_extent_rec *insert_rec); | ||
114 | }; | 146 | }; |
115 | 147 | ||
116 | 148 | ||
@@ -121,19 +153,22 @@ struct ocfs2_extent_tree_operations { | |||
121 | static u64 ocfs2_dinode_get_last_eb_blk(struct ocfs2_extent_tree *et); | 153 | static u64 ocfs2_dinode_get_last_eb_blk(struct ocfs2_extent_tree *et); |
122 | static void ocfs2_dinode_set_last_eb_blk(struct ocfs2_extent_tree *et, | 154 | static void ocfs2_dinode_set_last_eb_blk(struct ocfs2_extent_tree *et, |
123 | u64 blkno); | 155 | u64 blkno); |
124 | static void ocfs2_dinode_update_clusters(struct inode *inode, | 156 | static void ocfs2_dinode_update_clusters(struct ocfs2_extent_tree *et, |
125 | struct ocfs2_extent_tree *et, | ||
126 | u32 clusters); | 157 | u32 clusters); |
127 | static int ocfs2_dinode_insert_check(struct inode *inode, | 158 | static void ocfs2_dinode_extent_map_insert(struct ocfs2_extent_tree *et, |
128 | struct ocfs2_extent_tree *et, | 159 | struct ocfs2_extent_rec *rec); |
160 | static void ocfs2_dinode_extent_map_truncate(struct ocfs2_extent_tree *et, | ||
161 | u32 clusters); | ||
162 | static int ocfs2_dinode_insert_check(struct ocfs2_extent_tree *et, | ||
129 | struct ocfs2_extent_rec *rec); | 163 | struct ocfs2_extent_rec *rec); |
130 | static int ocfs2_dinode_sanity_check(struct inode *inode, | 164 | static int ocfs2_dinode_sanity_check(struct ocfs2_extent_tree *et); |
131 | struct ocfs2_extent_tree *et); | ||
132 | static void ocfs2_dinode_fill_root_el(struct ocfs2_extent_tree *et); | 165 | static void ocfs2_dinode_fill_root_el(struct ocfs2_extent_tree *et); |
133 | static struct ocfs2_extent_tree_operations ocfs2_dinode_et_ops = { | 166 | static struct ocfs2_extent_tree_operations ocfs2_dinode_et_ops = { |
134 | .eo_set_last_eb_blk = ocfs2_dinode_set_last_eb_blk, | 167 | .eo_set_last_eb_blk = ocfs2_dinode_set_last_eb_blk, |
135 | .eo_get_last_eb_blk = ocfs2_dinode_get_last_eb_blk, | 168 | .eo_get_last_eb_blk = ocfs2_dinode_get_last_eb_blk, |
136 | .eo_update_clusters = ocfs2_dinode_update_clusters, | 169 | .eo_update_clusters = ocfs2_dinode_update_clusters, |
170 | .eo_extent_map_insert = ocfs2_dinode_extent_map_insert, | ||
171 | .eo_extent_map_truncate = ocfs2_dinode_extent_map_truncate, | ||
137 | .eo_insert_check = ocfs2_dinode_insert_check, | 172 | .eo_insert_check = ocfs2_dinode_insert_check, |
138 | .eo_sanity_check = ocfs2_dinode_sanity_check, | 173 | .eo_sanity_check = ocfs2_dinode_sanity_check, |
139 | .eo_fill_root_el = ocfs2_dinode_fill_root_el, | 174 | .eo_fill_root_el = ocfs2_dinode_fill_root_el, |
@@ -156,40 +191,53 @@ static u64 ocfs2_dinode_get_last_eb_blk(struct ocfs2_extent_tree *et) | |||
156 | return le64_to_cpu(di->i_last_eb_blk); | 191 | return le64_to_cpu(di->i_last_eb_blk); |
157 | } | 192 | } |
158 | 193 | ||
159 | static void ocfs2_dinode_update_clusters(struct inode *inode, | 194 | static void ocfs2_dinode_update_clusters(struct ocfs2_extent_tree *et, |
160 | struct ocfs2_extent_tree *et, | ||
161 | u32 clusters) | 195 | u32 clusters) |
162 | { | 196 | { |
197 | struct ocfs2_inode_info *oi = cache_info_to_inode(et->et_ci); | ||
163 | struct ocfs2_dinode *di = et->et_object; | 198 | struct ocfs2_dinode *di = et->et_object; |
164 | 199 | ||
165 | le32_add_cpu(&di->i_clusters, clusters); | 200 | le32_add_cpu(&di->i_clusters, clusters); |
166 | spin_lock(&OCFS2_I(inode)->ip_lock); | 201 | spin_lock(&oi->ip_lock); |
167 | OCFS2_I(inode)->ip_clusters = le32_to_cpu(di->i_clusters); | 202 | oi->ip_clusters = le32_to_cpu(di->i_clusters); |
168 | spin_unlock(&OCFS2_I(inode)->ip_lock); | 203 | spin_unlock(&oi->ip_lock); |
169 | } | 204 | } |
170 | 205 | ||
171 | static int ocfs2_dinode_insert_check(struct inode *inode, | 206 | static void ocfs2_dinode_extent_map_insert(struct ocfs2_extent_tree *et, |
172 | struct ocfs2_extent_tree *et, | 207 | struct ocfs2_extent_rec *rec) |
208 | { | ||
209 | struct inode *inode = &cache_info_to_inode(et->et_ci)->vfs_inode; | ||
210 | |||
211 | ocfs2_extent_map_insert_rec(inode, rec); | ||
212 | } | ||
213 | |||
214 | static void ocfs2_dinode_extent_map_truncate(struct ocfs2_extent_tree *et, | ||
215 | u32 clusters) | ||
216 | { | ||
217 | struct inode *inode = &cache_info_to_inode(et->et_ci)->vfs_inode; | ||
218 | |||
219 | ocfs2_extent_map_trunc(inode, clusters); | ||
220 | } | ||
221 | |||
222 | static int ocfs2_dinode_insert_check(struct ocfs2_extent_tree *et, | ||
173 | struct ocfs2_extent_rec *rec) | 223 | struct ocfs2_extent_rec *rec) |
174 | { | 224 | { |
175 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | 225 | struct ocfs2_inode_info *oi = cache_info_to_inode(et->et_ci); |
226 | struct ocfs2_super *osb = OCFS2_SB(oi->vfs_inode.i_sb); | ||
176 | 227 | ||
177 | BUG_ON(OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL); | 228 | BUG_ON(oi->ip_dyn_features & OCFS2_INLINE_DATA_FL); |
178 | mlog_bug_on_msg(!ocfs2_sparse_alloc(osb) && | 229 | mlog_bug_on_msg(!ocfs2_sparse_alloc(osb) && |
179 | (OCFS2_I(inode)->ip_clusters != | 230 | (oi->ip_clusters != le32_to_cpu(rec->e_cpos)), |
180 | le32_to_cpu(rec->e_cpos)), | ||
181 | "Device %s, asking for sparse allocation: inode %llu, " | 231 | "Device %s, asking for sparse allocation: inode %llu, " |
182 | "cpos %u, clusters %u\n", | 232 | "cpos %u, clusters %u\n", |
183 | osb->dev_str, | 233 | osb->dev_str, |
184 | (unsigned long long)OCFS2_I(inode)->ip_blkno, | 234 | (unsigned long long)oi->ip_blkno, |
185 | rec->e_cpos, | 235 | rec->e_cpos, oi->ip_clusters); |
186 | OCFS2_I(inode)->ip_clusters); | ||
187 | 236 | ||
188 | return 0; | 237 | return 0; |
189 | } | 238 | } |
190 | 239 | ||
191 | static int ocfs2_dinode_sanity_check(struct inode *inode, | 240 | static int ocfs2_dinode_sanity_check(struct ocfs2_extent_tree *et) |
192 | struct ocfs2_extent_tree *et) | ||
193 | { | 241 | { |
194 | struct ocfs2_dinode *di = et->et_object; | 242 | struct ocfs2_dinode *di = et->et_object; |
195 | 243 | ||
@@ -229,8 +277,7 @@ static u64 ocfs2_xattr_value_get_last_eb_blk(struct ocfs2_extent_tree *et) | |||
229 | return le64_to_cpu(vb->vb_xv->xr_last_eb_blk); | 277 | return le64_to_cpu(vb->vb_xv->xr_last_eb_blk); |
230 | } | 278 | } |
231 | 279 | ||
232 | static void ocfs2_xattr_value_update_clusters(struct inode *inode, | 280 | static void ocfs2_xattr_value_update_clusters(struct ocfs2_extent_tree *et, |
233 | struct ocfs2_extent_tree *et, | ||
234 | u32 clusters) | 281 | u32 clusters) |
235 | { | 282 | { |
236 | struct ocfs2_xattr_value_buf *vb = et->et_object; | 283 | struct ocfs2_xattr_value_buf *vb = et->et_object; |
@@ -252,12 +299,11 @@ static void ocfs2_xattr_tree_fill_root_el(struct ocfs2_extent_tree *et) | |||
252 | et->et_root_el = &xb->xb_attrs.xb_root.xt_list; | 299 | et->et_root_el = &xb->xb_attrs.xb_root.xt_list; |
253 | } | 300 | } |
254 | 301 | ||
255 | static void ocfs2_xattr_tree_fill_max_leaf_clusters(struct inode *inode, | 302 | static void ocfs2_xattr_tree_fill_max_leaf_clusters(struct ocfs2_extent_tree *et) |
256 | struct ocfs2_extent_tree *et) | ||
257 | { | 303 | { |
304 | struct super_block *sb = ocfs2_metadata_cache_get_super(et->et_ci); | ||
258 | et->et_max_leaf_clusters = | 305 | et->et_max_leaf_clusters = |
259 | ocfs2_clusters_for_bytes(inode->i_sb, | 306 | ocfs2_clusters_for_bytes(sb, OCFS2_MAX_XATTR_TREE_LEAF_SIZE); |
260 | OCFS2_MAX_XATTR_TREE_LEAF_SIZE); | ||
261 | } | 307 | } |
262 | 308 | ||
263 | static void ocfs2_xattr_tree_set_last_eb_blk(struct ocfs2_extent_tree *et, | 309 | static void ocfs2_xattr_tree_set_last_eb_blk(struct ocfs2_extent_tree *et, |
@@ -277,8 +323,7 @@ static u64 ocfs2_xattr_tree_get_last_eb_blk(struct ocfs2_extent_tree *et) | |||
277 | return le64_to_cpu(xt->xt_last_eb_blk); | 323 | return le64_to_cpu(xt->xt_last_eb_blk); |
278 | } | 324 | } |
279 | 325 | ||
280 | static void ocfs2_xattr_tree_update_clusters(struct inode *inode, | 326 | static void ocfs2_xattr_tree_update_clusters(struct ocfs2_extent_tree *et, |
281 | struct ocfs2_extent_tree *et, | ||
282 | u32 clusters) | 327 | u32 clusters) |
283 | { | 328 | { |
284 | struct ocfs2_xattr_block *xb = et->et_object; | 329 | struct ocfs2_xattr_block *xb = et->et_object; |
@@ -309,8 +354,7 @@ static u64 ocfs2_dx_root_get_last_eb_blk(struct ocfs2_extent_tree *et) | |||
309 | return le64_to_cpu(dx_root->dr_last_eb_blk); | 354 | return le64_to_cpu(dx_root->dr_last_eb_blk); |
310 | } | 355 | } |
311 | 356 | ||
312 | static void ocfs2_dx_root_update_clusters(struct inode *inode, | 357 | static void ocfs2_dx_root_update_clusters(struct ocfs2_extent_tree *et, |
313 | struct ocfs2_extent_tree *et, | ||
314 | u32 clusters) | 358 | u32 clusters) |
315 | { | 359 | { |
316 | struct ocfs2_dx_root_block *dx_root = et->et_object; | 360 | struct ocfs2_dx_root_block *dx_root = et->et_object; |
@@ -318,8 +362,7 @@ static void ocfs2_dx_root_update_clusters(struct inode *inode, | |||
318 | le32_add_cpu(&dx_root->dr_clusters, clusters); | 362 | le32_add_cpu(&dx_root->dr_clusters, clusters); |
319 | } | 363 | } |
320 | 364 | ||
321 | static int ocfs2_dx_root_sanity_check(struct inode *inode, | 365 | static int ocfs2_dx_root_sanity_check(struct ocfs2_extent_tree *et) |
322 | struct ocfs2_extent_tree *et) | ||
323 | { | 366 | { |
324 | struct ocfs2_dx_root_block *dx_root = et->et_object; | 367 | struct ocfs2_dx_root_block *dx_root = et->et_object; |
325 | 368 | ||
@@ -343,8 +386,54 @@ static struct ocfs2_extent_tree_operations ocfs2_dx_root_et_ops = { | |||
343 | .eo_fill_root_el = ocfs2_dx_root_fill_root_el, | 386 | .eo_fill_root_el = ocfs2_dx_root_fill_root_el, |
344 | }; | 387 | }; |
345 | 388 | ||
389 | static void ocfs2_refcount_tree_fill_root_el(struct ocfs2_extent_tree *et) | ||
390 | { | ||
391 | struct ocfs2_refcount_block *rb = et->et_object; | ||
392 | |||
393 | et->et_root_el = &rb->rf_list; | ||
394 | } | ||
395 | |||
396 | static void ocfs2_refcount_tree_set_last_eb_blk(struct ocfs2_extent_tree *et, | ||
397 | u64 blkno) | ||
398 | { | ||
399 | struct ocfs2_refcount_block *rb = et->et_object; | ||
400 | |||
401 | rb->rf_last_eb_blk = cpu_to_le64(blkno); | ||
402 | } | ||
403 | |||
404 | static u64 ocfs2_refcount_tree_get_last_eb_blk(struct ocfs2_extent_tree *et) | ||
405 | { | ||
406 | struct ocfs2_refcount_block *rb = et->et_object; | ||
407 | |||
408 | return le64_to_cpu(rb->rf_last_eb_blk); | ||
409 | } | ||
410 | |||
411 | static void ocfs2_refcount_tree_update_clusters(struct ocfs2_extent_tree *et, | ||
412 | u32 clusters) | ||
413 | { | ||
414 | struct ocfs2_refcount_block *rb = et->et_object; | ||
415 | |||
416 | le32_add_cpu(&rb->rf_clusters, clusters); | ||
417 | } | ||
418 | |||
419 | static enum ocfs2_contig_type | ||
420 | ocfs2_refcount_tree_extent_contig(struct ocfs2_extent_tree *et, | ||
421 | struct ocfs2_extent_rec *ext, | ||
422 | struct ocfs2_extent_rec *insert_rec) | ||
423 | { | ||
424 | return CONTIG_NONE; | ||
425 | } | ||
426 | |||
427 | static struct ocfs2_extent_tree_operations ocfs2_refcount_tree_et_ops = { | ||
428 | .eo_set_last_eb_blk = ocfs2_refcount_tree_set_last_eb_blk, | ||
429 | .eo_get_last_eb_blk = ocfs2_refcount_tree_get_last_eb_blk, | ||
430 | .eo_update_clusters = ocfs2_refcount_tree_update_clusters, | ||
431 | .eo_fill_root_el = ocfs2_refcount_tree_fill_root_el, | ||
432 | .eo_extent_contig = ocfs2_refcount_tree_extent_contig, | ||
433 | }; | ||
434 | |||
346 | static void __ocfs2_init_extent_tree(struct ocfs2_extent_tree *et, | 435 | static void __ocfs2_init_extent_tree(struct ocfs2_extent_tree *et, |
347 | struct inode *inode, | 436 | struct ocfs2_caching_info *ci, |
348 | struct buffer_head *bh, | 437 | struct buffer_head *bh, |
349 | ocfs2_journal_access_func access, | 438 | ocfs2_journal_access_func access, |
350 | void *obj, | 439 | void *obj, |
@@ -352,6 +441,7 @@ static void __ocfs2_init_extent_tree(struct ocfs2_extent_tree *et, | |||
352 | { | 441 | { |
353 | et->et_ops = ops; | 442 | et->et_ops = ops; |
354 | et->et_root_bh = bh; | 443 | et->et_root_bh = bh; |
444 | et->et_ci = ci; | ||
355 | et->et_root_journal_access = access; | 445 | et->et_root_journal_access = access; |
356 | if (!obj) | 446 | if (!obj) |
357 | obj = (void *)bh->b_data; | 447 | obj = (void *)bh->b_data; |
@@ -361,41 +451,49 @@ static void __ocfs2_init_extent_tree(struct ocfs2_extent_tree *et, | |||
361 | if (!et->et_ops->eo_fill_max_leaf_clusters) | 451 | if (!et->et_ops->eo_fill_max_leaf_clusters) |
362 | et->et_max_leaf_clusters = 0; | 452 | et->et_max_leaf_clusters = 0; |
363 | else | 453 | else |
364 | et->et_ops->eo_fill_max_leaf_clusters(inode, et); | 454 | et->et_ops->eo_fill_max_leaf_clusters(et); |
365 | } | 455 | } |
366 | 456 | ||
367 | void ocfs2_init_dinode_extent_tree(struct ocfs2_extent_tree *et, | 457 | void ocfs2_init_dinode_extent_tree(struct ocfs2_extent_tree *et, |
368 | struct inode *inode, | 458 | struct ocfs2_caching_info *ci, |
369 | struct buffer_head *bh) | 459 | struct buffer_head *bh) |
370 | { | 460 | { |
371 | __ocfs2_init_extent_tree(et, inode, bh, ocfs2_journal_access_di, | 461 | __ocfs2_init_extent_tree(et, ci, bh, ocfs2_journal_access_di, |
372 | NULL, &ocfs2_dinode_et_ops); | 462 | NULL, &ocfs2_dinode_et_ops); |
373 | } | 463 | } |
374 | 464 | ||
375 | void ocfs2_init_xattr_tree_extent_tree(struct ocfs2_extent_tree *et, | 465 | void ocfs2_init_xattr_tree_extent_tree(struct ocfs2_extent_tree *et, |
376 | struct inode *inode, | 466 | struct ocfs2_caching_info *ci, |
377 | struct buffer_head *bh) | 467 | struct buffer_head *bh) |
378 | { | 468 | { |
379 | __ocfs2_init_extent_tree(et, inode, bh, ocfs2_journal_access_xb, | 469 | __ocfs2_init_extent_tree(et, ci, bh, ocfs2_journal_access_xb, |
380 | NULL, &ocfs2_xattr_tree_et_ops); | 470 | NULL, &ocfs2_xattr_tree_et_ops); |
381 | } | 471 | } |
382 | 472 | ||
383 | void ocfs2_init_xattr_value_extent_tree(struct ocfs2_extent_tree *et, | 473 | void ocfs2_init_xattr_value_extent_tree(struct ocfs2_extent_tree *et, |
384 | struct inode *inode, | 474 | struct ocfs2_caching_info *ci, |
385 | struct ocfs2_xattr_value_buf *vb) | 475 | struct ocfs2_xattr_value_buf *vb) |
386 | { | 476 | { |
387 | __ocfs2_init_extent_tree(et, inode, vb->vb_bh, vb->vb_access, vb, | 477 | __ocfs2_init_extent_tree(et, ci, vb->vb_bh, vb->vb_access, vb, |
388 | &ocfs2_xattr_value_et_ops); | 478 | &ocfs2_xattr_value_et_ops); |
389 | } | 479 | } |
390 | 480 | ||
391 | void ocfs2_init_dx_root_extent_tree(struct ocfs2_extent_tree *et, | 481 | void ocfs2_init_dx_root_extent_tree(struct ocfs2_extent_tree *et, |
392 | struct inode *inode, | 482 | struct ocfs2_caching_info *ci, |
393 | struct buffer_head *bh) | 483 | struct buffer_head *bh) |
394 | { | 484 | { |
395 | __ocfs2_init_extent_tree(et, inode, bh, ocfs2_journal_access_dr, | 485 | __ocfs2_init_extent_tree(et, ci, bh, ocfs2_journal_access_dr, |
396 | NULL, &ocfs2_dx_root_et_ops); | 486 | NULL, &ocfs2_dx_root_et_ops); |
397 | } | 487 | } |
398 | 488 | ||
489 | void ocfs2_init_refcount_extent_tree(struct ocfs2_extent_tree *et, | ||
490 | struct ocfs2_caching_info *ci, | ||
491 | struct buffer_head *bh) | ||
492 | { | ||
493 | __ocfs2_init_extent_tree(et, ci, bh, ocfs2_journal_access_rb, | ||
494 | NULL, &ocfs2_refcount_tree_et_ops); | ||
495 | } | ||
496 | |||
399 | static inline void ocfs2_et_set_last_eb_blk(struct ocfs2_extent_tree *et, | 497 | static inline void ocfs2_et_set_last_eb_blk(struct ocfs2_extent_tree *et, |
400 | u64 new_last_eb_blk) | 498 | u64 new_last_eb_blk) |
401 | { | 499 | { |
@@ -407,78 +505,71 @@ static inline u64 ocfs2_et_get_last_eb_blk(struct ocfs2_extent_tree *et) | |||
407 | return et->et_ops->eo_get_last_eb_blk(et); | 505 | return et->et_ops->eo_get_last_eb_blk(et); |
408 | } | 506 | } |
409 | 507 | ||
410 | static inline void ocfs2_et_update_clusters(struct inode *inode, | 508 | static inline void ocfs2_et_update_clusters(struct ocfs2_extent_tree *et, |
411 | struct ocfs2_extent_tree *et, | ||
412 | u32 clusters) | 509 | u32 clusters) |
413 | { | 510 | { |
414 | et->et_ops->eo_update_clusters(inode, et, clusters); | 511 | et->et_ops->eo_update_clusters(et, clusters); |
512 | } | ||
513 | |||
514 | static inline void ocfs2_et_extent_map_insert(struct ocfs2_extent_tree *et, | ||
515 | struct ocfs2_extent_rec *rec) | ||
516 | { | ||
517 | if (et->et_ops->eo_extent_map_insert) | ||
518 | et->et_ops->eo_extent_map_insert(et, rec); | ||
519 | } | ||
520 | |||
521 | static inline void ocfs2_et_extent_map_truncate(struct ocfs2_extent_tree *et, | ||
522 | u32 clusters) | ||
523 | { | ||
524 | if (et->et_ops->eo_extent_map_truncate) | ||
525 | et->et_ops->eo_extent_map_truncate(et, clusters); | ||
415 | } | 526 | } |
416 | 527 | ||
417 | static inline int ocfs2_et_root_journal_access(handle_t *handle, | 528 | static inline int ocfs2_et_root_journal_access(handle_t *handle, |
418 | struct inode *inode, | ||
419 | struct ocfs2_extent_tree *et, | 529 | struct ocfs2_extent_tree *et, |
420 | int type) | 530 | int type) |
421 | { | 531 | { |
422 | return et->et_root_journal_access(handle, inode, et->et_root_bh, | 532 | return et->et_root_journal_access(handle, et->et_ci, et->et_root_bh, |
423 | type); | 533 | type); |
424 | } | 534 | } |
425 | 535 | ||
426 | static inline int ocfs2_et_insert_check(struct inode *inode, | 536 | static inline enum ocfs2_contig_type |
427 | struct ocfs2_extent_tree *et, | 537 | ocfs2_et_extent_contig(struct ocfs2_extent_tree *et, |
538 | struct ocfs2_extent_rec *rec, | ||
539 | struct ocfs2_extent_rec *insert_rec) | ||
540 | { | ||
541 | if (et->et_ops->eo_extent_contig) | ||
542 | return et->et_ops->eo_extent_contig(et, rec, insert_rec); | ||
543 | |||
544 | return ocfs2_extent_rec_contig( | ||
545 | ocfs2_metadata_cache_get_super(et->et_ci), | ||
546 | rec, insert_rec); | ||
547 | } | ||
548 | |||
549 | static inline int ocfs2_et_insert_check(struct ocfs2_extent_tree *et, | ||
428 | struct ocfs2_extent_rec *rec) | 550 | struct ocfs2_extent_rec *rec) |
429 | { | 551 | { |
430 | int ret = 0; | 552 | int ret = 0; |
431 | 553 | ||
432 | if (et->et_ops->eo_insert_check) | 554 | if (et->et_ops->eo_insert_check) |
433 | ret = et->et_ops->eo_insert_check(inode, et, rec); | 555 | ret = et->et_ops->eo_insert_check(et, rec); |
434 | return ret; | 556 | return ret; |
435 | } | 557 | } |
436 | 558 | ||
437 | static inline int ocfs2_et_sanity_check(struct inode *inode, | 559 | static inline int ocfs2_et_sanity_check(struct ocfs2_extent_tree *et) |
438 | struct ocfs2_extent_tree *et) | ||
439 | { | 560 | { |
440 | int ret = 0; | 561 | int ret = 0; |
441 | 562 | ||
442 | if (et->et_ops->eo_sanity_check) | 563 | if (et->et_ops->eo_sanity_check) |
443 | ret = et->et_ops->eo_sanity_check(inode, et); | 564 | ret = et->et_ops->eo_sanity_check(et); |
444 | return ret; | 565 | return ret; |
445 | } | 566 | } |
446 | 567 | ||
447 | static void ocfs2_free_truncate_context(struct ocfs2_truncate_context *tc); | 568 | static void ocfs2_free_truncate_context(struct ocfs2_truncate_context *tc); |
448 | static int ocfs2_cache_extent_block_free(struct ocfs2_cached_dealloc_ctxt *ctxt, | 569 | static int ocfs2_cache_extent_block_free(struct ocfs2_cached_dealloc_ctxt *ctxt, |
449 | struct ocfs2_extent_block *eb); | 570 | struct ocfs2_extent_block *eb); |
450 | 571 | static void ocfs2_adjust_rightmost_records(handle_t *handle, | |
451 | /* | 572 | struct ocfs2_extent_tree *et, |
452 | * Structures which describe a path through a btree, and functions to | ||
453 | * manipulate them. | ||
454 | * | ||
455 | * The idea here is to be as generic as possible with the tree | ||
456 | * manipulation code. | ||
457 | */ | ||
458 | struct ocfs2_path_item { | ||
459 | struct buffer_head *bh; | ||
460 | struct ocfs2_extent_list *el; | ||
461 | }; | ||
462 | |||
463 | #define OCFS2_MAX_PATH_DEPTH 5 | ||
464 | |||
465 | struct ocfs2_path { | ||
466 | int p_tree_depth; | ||
467 | ocfs2_journal_access_func p_root_access; | ||
468 | struct ocfs2_path_item p_node[OCFS2_MAX_PATH_DEPTH]; | ||
469 | }; | ||
470 | |||
471 | #define path_root_bh(_path) ((_path)->p_node[0].bh) | ||
472 | #define path_root_el(_path) ((_path)->p_node[0].el) | ||
473 | #define path_root_access(_path)((_path)->p_root_access) | ||
474 | #define path_leaf_bh(_path) ((_path)->p_node[(_path)->p_tree_depth].bh) | ||
475 | #define path_leaf_el(_path) ((_path)->p_node[(_path)->p_tree_depth].el) | ||
476 | #define path_num_items(_path) ((_path)->p_tree_depth + 1) | ||
477 | |||
478 | static int ocfs2_find_path(struct inode *inode, struct ocfs2_path *path, | ||
479 | u32 cpos); | ||
480 | static void ocfs2_adjust_rightmost_records(struct inode *inode, | ||
481 | handle_t *handle, | ||
482 | struct ocfs2_path *path, | 573 | struct ocfs2_path *path, |
483 | struct ocfs2_extent_rec *insert_rec); | 574 | struct ocfs2_extent_rec *insert_rec); |
484 | /* | 575 | /* |
@@ -486,7 +577,7 @@ static void ocfs2_adjust_rightmost_records(struct inode *inode, | |||
486 | * to build another path. Generally, this involves freeing the buffer | 577 | * to build another path. Generally, this involves freeing the buffer |
487 | * heads. | 578 | * heads. |
488 | */ | 579 | */ |
489 | static void ocfs2_reinit_path(struct ocfs2_path *path, int keep_root) | 580 | void ocfs2_reinit_path(struct ocfs2_path *path, int keep_root) |
490 | { | 581 | { |
491 | int i, start = 0, depth = 0; | 582 | int i, start = 0, depth = 0; |
492 | struct ocfs2_path_item *node; | 583 | struct ocfs2_path_item *node; |
@@ -515,7 +606,7 @@ static void ocfs2_reinit_path(struct ocfs2_path *path, int keep_root) | |||
515 | path->p_tree_depth = depth; | 606 | path->p_tree_depth = depth; |
516 | } | 607 | } |
517 | 608 | ||
518 | static void ocfs2_free_path(struct ocfs2_path *path) | 609 | void ocfs2_free_path(struct ocfs2_path *path) |
519 | { | 610 | { |
520 | if (path) { | 611 | if (path) { |
521 | ocfs2_reinit_path(path, 0); | 612 | ocfs2_reinit_path(path, 0); |
@@ -613,13 +704,13 @@ static struct ocfs2_path *ocfs2_new_path(struct buffer_head *root_bh, | |||
613 | return path; | 704 | return path; |
614 | } | 705 | } |
615 | 706 | ||
616 | static struct ocfs2_path *ocfs2_new_path_from_path(struct ocfs2_path *path) | 707 | struct ocfs2_path *ocfs2_new_path_from_path(struct ocfs2_path *path) |
617 | { | 708 | { |
618 | return ocfs2_new_path(path_root_bh(path), path_root_el(path), | 709 | return ocfs2_new_path(path_root_bh(path), path_root_el(path), |
619 | path_root_access(path)); | 710 | path_root_access(path)); |
620 | } | 711 | } |
621 | 712 | ||
622 | static struct ocfs2_path *ocfs2_new_path_from_et(struct ocfs2_extent_tree *et) | 713 | struct ocfs2_path *ocfs2_new_path_from_et(struct ocfs2_extent_tree *et) |
623 | { | 714 | { |
624 | return ocfs2_new_path(et->et_root_bh, et->et_root_el, | 715 | return ocfs2_new_path(et->et_root_bh, et->et_root_el, |
625 | et->et_root_journal_access); | 716 | et->et_root_journal_access); |
@@ -632,10 +723,10 @@ static struct ocfs2_path *ocfs2_new_path_from_et(struct ocfs2_extent_tree *et) | |||
632 | * I don't like the way this function's name looks next to | 723 | * I don't like the way this function's name looks next to |
633 | * ocfs2_journal_access_path(), but I don't have a better one. | 724 | * ocfs2_journal_access_path(), but I don't have a better one. |
634 | */ | 725 | */ |
635 | static int ocfs2_path_bh_journal_access(handle_t *handle, | 726 | int ocfs2_path_bh_journal_access(handle_t *handle, |
636 | struct inode *inode, | 727 | struct ocfs2_caching_info *ci, |
637 | struct ocfs2_path *path, | 728 | struct ocfs2_path *path, |
638 | int idx) | 729 | int idx) |
639 | { | 730 | { |
640 | ocfs2_journal_access_func access = path_root_access(path); | 731 | ocfs2_journal_access_func access = path_root_access(path); |
641 | 732 | ||
@@ -645,15 +736,16 @@ static int ocfs2_path_bh_journal_access(handle_t *handle, | |||
645 | if (idx) | 736 | if (idx) |
646 | access = ocfs2_journal_access_eb; | 737 | access = ocfs2_journal_access_eb; |
647 | 738 | ||
648 | return access(handle, inode, path->p_node[idx].bh, | 739 | return access(handle, ci, path->p_node[idx].bh, |
649 | OCFS2_JOURNAL_ACCESS_WRITE); | 740 | OCFS2_JOURNAL_ACCESS_WRITE); |
650 | } | 741 | } |
651 | 742 | ||
652 | /* | 743 | /* |
653 | * Convenience function to journal all components in a path. | 744 | * Convenience function to journal all components in a path. |
654 | */ | 745 | */ |
655 | static int ocfs2_journal_access_path(struct inode *inode, handle_t *handle, | 746 | int ocfs2_journal_access_path(struct ocfs2_caching_info *ci, |
656 | struct ocfs2_path *path) | 747 | handle_t *handle, |
748 | struct ocfs2_path *path) | ||
657 | { | 749 | { |
658 | int i, ret = 0; | 750 | int i, ret = 0; |
659 | 751 | ||
@@ -661,7 +753,7 @@ static int ocfs2_journal_access_path(struct inode *inode, handle_t *handle, | |||
661 | goto out; | 753 | goto out; |
662 | 754 | ||
663 | for(i = 0; i < path_num_items(path); i++) { | 755 | for(i = 0; i < path_num_items(path); i++) { |
664 | ret = ocfs2_path_bh_journal_access(handle, inode, path, i); | 756 | ret = ocfs2_path_bh_journal_access(handle, ci, path, i); |
665 | if (ret < 0) { | 757 | if (ret < 0) { |
666 | mlog_errno(ret); | 758 | mlog_errno(ret); |
667 | goto out; | 759 | goto out; |
@@ -702,17 +794,9 @@ int ocfs2_search_extent_list(struct ocfs2_extent_list *el, u32 v_cluster) | |||
702 | return ret; | 794 | return ret; |
703 | } | 795 | } |
704 | 796 | ||
705 | enum ocfs2_contig_type { | ||
706 | CONTIG_NONE = 0, | ||
707 | CONTIG_LEFT, | ||
708 | CONTIG_RIGHT, | ||
709 | CONTIG_LEFTRIGHT, | ||
710 | }; | ||
711 | |||
712 | |||
713 | /* | 797 | /* |
714 | * NOTE: ocfs2_block_extent_contig(), ocfs2_extents_adjacent() and | 798 | * NOTE: ocfs2_block_extent_contig(), ocfs2_extents_adjacent() and |
715 | * ocfs2_extent_contig only work properly against leaf nodes! | 799 | * ocfs2_extent_rec_contig only work properly against leaf nodes! |
716 | */ | 800 | */ |
717 | static int ocfs2_block_extent_contig(struct super_block *sb, | 801 | static int ocfs2_block_extent_contig(struct super_block *sb, |
718 | struct ocfs2_extent_rec *ext, | 802 | struct ocfs2_extent_rec *ext, |
@@ -738,9 +822,9 @@ static int ocfs2_extents_adjacent(struct ocfs2_extent_rec *left, | |||
738 | } | 822 | } |
739 | 823 | ||
740 | static enum ocfs2_contig_type | 824 | static enum ocfs2_contig_type |
741 | ocfs2_extent_contig(struct inode *inode, | 825 | ocfs2_extent_rec_contig(struct super_block *sb, |
742 | struct ocfs2_extent_rec *ext, | 826 | struct ocfs2_extent_rec *ext, |
743 | struct ocfs2_extent_rec *insert_rec) | 827 | struct ocfs2_extent_rec *insert_rec) |
744 | { | 828 | { |
745 | u64 blkno = le64_to_cpu(insert_rec->e_blkno); | 829 | u64 blkno = le64_to_cpu(insert_rec->e_blkno); |
746 | 830 | ||
@@ -753,12 +837,12 @@ static enum ocfs2_contig_type | |||
753 | return CONTIG_NONE; | 837 | return CONTIG_NONE; |
754 | 838 | ||
755 | if (ocfs2_extents_adjacent(ext, insert_rec) && | 839 | if (ocfs2_extents_adjacent(ext, insert_rec) && |
756 | ocfs2_block_extent_contig(inode->i_sb, ext, blkno)) | 840 | ocfs2_block_extent_contig(sb, ext, blkno)) |
757 | return CONTIG_RIGHT; | 841 | return CONTIG_RIGHT; |
758 | 842 | ||
759 | blkno = le64_to_cpu(ext->e_blkno); | 843 | blkno = le64_to_cpu(ext->e_blkno); |
760 | if (ocfs2_extents_adjacent(insert_rec, ext) && | 844 | if (ocfs2_extents_adjacent(insert_rec, ext) && |
761 | ocfs2_block_extent_contig(inode->i_sb, insert_rec, blkno)) | 845 | ocfs2_block_extent_contig(sb, insert_rec, blkno)) |
762 | return CONTIG_LEFT; | 846 | return CONTIG_LEFT; |
763 | 847 | ||
764 | return CONTIG_NONE; | 848 | return CONTIG_NONE; |
@@ -853,13 +937,13 @@ static int ocfs2_validate_extent_block(struct super_block *sb, | |||
853 | return 0; | 937 | return 0; |
854 | } | 938 | } |
855 | 939 | ||
856 | int ocfs2_read_extent_block(struct inode *inode, u64 eb_blkno, | 940 | int ocfs2_read_extent_block(struct ocfs2_caching_info *ci, u64 eb_blkno, |
857 | struct buffer_head **bh) | 941 | struct buffer_head **bh) |
858 | { | 942 | { |
859 | int rc; | 943 | int rc; |
860 | struct buffer_head *tmp = *bh; | 944 | struct buffer_head *tmp = *bh; |
861 | 945 | ||
862 | rc = ocfs2_read_block(inode, eb_blkno, &tmp, | 946 | rc = ocfs2_read_block(ci, eb_blkno, &tmp, |
863 | ocfs2_validate_extent_block); | 947 | ocfs2_validate_extent_block); |
864 | 948 | ||
865 | /* If ocfs2_read_block() got us a new bh, pass it up. */ | 949 | /* If ocfs2_read_block() got us a new bh, pass it up. */ |
@@ -874,7 +958,6 @@ int ocfs2_read_extent_block(struct inode *inode, u64 eb_blkno, | |||
874 | * How many free extents have we got before we need more meta data? | 958 | * How many free extents have we got before we need more meta data? |
875 | */ | 959 | */ |
876 | int ocfs2_num_free_extents(struct ocfs2_super *osb, | 960 | int ocfs2_num_free_extents(struct ocfs2_super *osb, |
877 | struct inode *inode, | ||
878 | struct ocfs2_extent_tree *et) | 961 | struct ocfs2_extent_tree *et) |
879 | { | 962 | { |
880 | int retval; | 963 | int retval; |
@@ -889,7 +972,8 @@ int ocfs2_num_free_extents(struct ocfs2_super *osb, | |||
889 | last_eb_blk = ocfs2_et_get_last_eb_blk(et); | 972 | last_eb_blk = ocfs2_et_get_last_eb_blk(et); |
890 | 973 | ||
891 | if (last_eb_blk) { | 974 | if (last_eb_blk) { |
892 | retval = ocfs2_read_extent_block(inode, last_eb_blk, &eb_bh); | 975 | retval = ocfs2_read_extent_block(et->et_ci, last_eb_blk, |
976 | &eb_bh); | ||
893 | if (retval < 0) { | 977 | if (retval < 0) { |
894 | mlog_errno(retval); | 978 | mlog_errno(retval); |
895 | goto bail; | 979 | goto bail; |
@@ -913,9 +997,8 @@ bail: | |||
913 | * sets h_signature, h_blkno, h_suballoc_bit, h_suballoc_slot, and | 997 | * sets h_signature, h_blkno, h_suballoc_bit, h_suballoc_slot, and |
914 | * l_count for you | 998 | * l_count for you |
915 | */ | 999 | */ |
916 | static int ocfs2_create_new_meta_bhs(struct ocfs2_super *osb, | 1000 | static int ocfs2_create_new_meta_bhs(handle_t *handle, |
917 | handle_t *handle, | 1001 | struct ocfs2_extent_tree *et, |
918 | struct inode *inode, | ||
919 | int wanted, | 1002 | int wanted, |
920 | struct ocfs2_alloc_context *meta_ac, | 1003 | struct ocfs2_alloc_context *meta_ac, |
921 | struct buffer_head *bhs[]) | 1004 | struct buffer_head *bhs[]) |
@@ -924,6 +1007,8 @@ static int ocfs2_create_new_meta_bhs(struct ocfs2_super *osb, | |||
924 | u16 suballoc_bit_start; | 1007 | u16 suballoc_bit_start; |
925 | u32 num_got; | 1008 | u32 num_got; |
926 | u64 first_blkno; | 1009 | u64 first_blkno; |
1010 | struct ocfs2_super *osb = | ||
1011 | OCFS2_SB(ocfs2_metadata_cache_get_super(et->et_ci)); | ||
927 | struct ocfs2_extent_block *eb; | 1012 | struct ocfs2_extent_block *eb; |
928 | 1013 | ||
929 | mlog_entry_void(); | 1014 | mlog_entry_void(); |
@@ -949,9 +1034,10 @@ static int ocfs2_create_new_meta_bhs(struct ocfs2_super *osb, | |||
949 | mlog_errno(status); | 1034 | mlog_errno(status); |
950 | goto bail; | 1035 | goto bail; |
951 | } | 1036 | } |
952 | ocfs2_set_new_buffer_uptodate(inode, bhs[i]); | 1037 | ocfs2_set_new_buffer_uptodate(et->et_ci, bhs[i]); |
953 | 1038 | ||
954 | status = ocfs2_journal_access_eb(handle, inode, bhs[i], | 1039 | status = ocfs2_journal_access_eb(handle, et->et_ci, |
1040 | bhs[i], | ||
955 | OCFS2_JOURNAL_ACCESS_CREATE); | 1041 | OCFS2_JOURNAL_ACCESS_CREATE); |
956 | if (status < 0) { | 1042 | if (status < 0) { |
957 | mlog_errno(status); | 1043 | mlog_errno(status); |
@@ -1023,7 +1109,6 @@ static inline u32 ocfs2_sum_rightmost_rec(struct ocfs2_extent_list *el) | |||
1023 | * extent block's rightmost record. | 1109 | * extent block's rightmost record. |
1024 | */ | 1110 | */ |
1025 | static int ocfs2_adjust_rightmost_branch(handle_t *handle, | 1111 | static int ocfs2_adjust_rightmost_branch(handle_t *handle, |
1026 | struct inode *inode, | ||
1027 | struct ocfs2_extent_tree *et) | 1112 | struct ocfs2_extent_tree *et) |
1028 | { | 1113 | { |
1029 | int status; | 1114 | int status; |
@@ -1037,7 +1122,7 @@ static int ocfs2_adjust_rightmost_branch(handle_t *handle, | |||
1037 | return status; | 1122 | return status; |
1038 | } | 1123 | } |
1039 | 1124 | ||
1040 | status = ocfs2_find_path(inode, path, UINT_MAX); | 1125 | status = ocfs2_find_path(et->et_ci, path, UINT_MAX); |
1041 | if (status < 0) { | 1126 | if (status < 0) { |
1042 | mlog_errno(status); | 1127 | mlog_errno(status); |
1043 | goto out; | 1128 | goto out; |
@@ -1050,7 +1135,7 @@ static int ocfs2_adjust_rightmost_branch(handle_t *handle, | |||
1050 | goto out; | 1135 | goto out; |
1051 | } | 1136 | } |
1052 | 1137 | ||
1053 | status = ocfs2_journal_access_path(inode, handle, path); | 1138 | status = ocfs2_journal_access_path(et->et_ci, handle, path); |
1054 | if (status < 0) { | 1139 | if (status < 0) { |
1055 | mlog_errno(status); | 1140 | mlog_errno(status); |
1056 | goto out; | 1141 | goto out; |
@@ -1059,7 +1144,7 @@ static int ocfs2_adjust_rightmost_branch(handle_t *handle, | |||
1059 | el = path_leaf_el(path); | 1144 | el = path_leaf_el(path); |
1060 | rec = &el->l_recs[le32_to_cpu(el->l_next_free_rec) - 1]; | 1145 | rec = &el->l_recs[le32_to_cpu(el->l_next_free_rec) - 1]; |
1061 | 1146 | ||
1062 | ocfs2_adjust_rightmost_records(inode, handle, path, rec); | 1147 | ocfs2_adjust_rightmost_records(handle, et, path, rec); |
1063 | 1148 | ||
1064 | out: | 1149 | out: |
1065 | ocfs2_free_path(path); | 1150 | ocfs2_free_path(path); |
@@ -1068,7 +1153,7 @@ out: | |||
1068 | 1153 | ||
1069 | /* | 1154 | /* |
1070 | * Add an entire tree branch to our inode. eb_bh is the extent block | 1155 | * Add an entire tree branch to our inode. eb_bh is the extent block |
1071 | * to start at, if we don't want to start the branch at the dinode | 1156 | * to start at, if we don't want to start the branch at the root |
1072 | * structure. | 1157 | * structure. |
1073 | * | 1158 | * |
1074 | * last_eb_bh is required as we have to update it's next_leaf pointer | 1159 | * last_eb_bh is required as we have to update it's next_leaf pointer |
@@ -1077,9 +1162,7 @@ out: | |||
1077 | * the new branch will be 'empty' in the sense that every block will | 1162 | * the new branch will be 'empty' in the sense that every block will |
1078 | * contain a single record with cluster count == 0. | 1163 | * contain a single record with cluster count == 0. |
1079 | */ | 1164 | */ |
1080 | static int ocfs2_add_branch(struct ocfs2_super *osb, | 1165 | static int ocfs2_add_branch(handle_t *handle, |
1081 | handle_t *handle, | ||
1082 | struct inode *inode, | ||
1083 | struct ocfs2_extent_tree *et, | 1166 | struct ocfs2_extent_tree *et, |
1084 | struct buffer_head *eb_bh, | 1167 | struct buffer_head *eb_bh, |
1085 | struct buffer_head **last_eb_bh, | 1168 | struct buffer_head **last_eb_bh, |
@@ -1123,7 +1206,7 @@ static int ocfs2_add_branch(struct ocfs2_super *osb, | |||
1123 | if (root_end > new_cpos) { | 1206 | if (root_end > new_cpos) { |
1124 | mlog(0, "adjust the cluster end from %u to %u\n", | 1207 | mlog(0, "adjust the cluster end from %u to %u\n", |
1125 | root_end, new_cpos); | 1208 | root_end, new_cpos); |
1126 | status = ocfs2_adjust_rightmost_branch(handle, inode, et); | 1209 | status = ocfs2_adjust_rightmost_branch(handle, et); |
1127 | if (status) { | 1210 | if (status) { |
1128 | mlog_errno(status); | 1211 | mlog_errno(status); |
1129 | goto bail; | 1212 | goto bail; |
@@ -1139,7 +1222,7 @@ static int ocfs2_add_branch(struct ocfs2_super *osb, | |||
1139 | goto bail; | 1222 | goto bail; |
1140 | } | 1223 | } |
1141 | 1224 | ||
1142 | status = ocfs2_create_new_meta_bhs(osb, handle, inode, new_blocks, | 1225 | status = ocfs2_create_new_meta_bhs(handle, et, new_blocks, |
1143 | meta_ac, new_eb_bhs); | 1226 | meta_ac, new_eb_bhs); |
1144 | if (status < 0) { | 1227 | if (status < 0) { |
1145 | mlog_errno(status); | 1228 | mlog_errno(status); |
@@ -1161,7 +1244,7 @@ static int ocfs2_add_branch(struct ocfs2_super *osb, | |||
1161 | BUG_ON(!OCFS2_IS_VALID_EXTENT_BLOCK(eb)); | 1244 | BUG_ON(!OCFS2_IS_VALID_EXTENT_BLOCK(eb)); |
1162 | eb_el = &eb->h_list; | 1245 | eb_el = &eb->h_list; |
1163 | 1246 | ||
1164 | status = ocfs2_journal_access_eb(handle, inode, bh, | 1247 | status = ocfs2_journal_access_eb(handle, et->et_ci, bh, |
1165 | OCFS2_JOURNAL_ACCESS_CREATE); | 1248 | OCFS2_JOURNAL_ACCESS_CREATE); |
1166 | if (status < 0) { | 1249 | if (status < 0) { |
1167 | mlog_errno(status); | 1250 | mlog_errno(status); |
@@ -1201,20 +1284,20 @@ static int ocfs2_add_branch(struct ocfs2_super *osb, | |||
1201 | * journal_dirty erroring as it won't unless we've aborted the | 1284 | * journal_dirty erroring as it won't unless we've aborted the |
1202 | * handle (in which case we would never be here) so reserving | 1285 | * handle (in which case we would never be here) so reserving |
1203 | * the write with journal_access is all we need to do. */ | 1286 | * the write with journal_access is all we need to do. */ |
1204 | status = ocfs2_journal_access_eb(handle, inode, *last_eb_bh, | 1287 | status = ocfs2_journal_access_eb(handle, et->et_ci, *last_eb_bh, |
1205 | OCFS2_JOURNAL_ACCESS_WRITE); | 1288 | OCFS2_JOURNAL_ACCESS_WRITE); |
1206 | if (status < 0) { | 1289 | if (status < 0) { |
1207 | mlog_errno(status); | 1290 | mlog_errno(status); |
1208 | goto bail; | 1291 | goto bail; |
1209 | } | 1292 | } |
1210 | status = ocfs2_et_root_journal_access(handle, inode, et, | 1293 | status = ocfs2_et_root_journal_access(handle, et, |
1211 | OCFS2_JOURNAL_ACCESS_WRITE); | 1294 | OCFS2_JOURNAL_ACCESS_WRITE); |
1212 | if (status < 0) { | 1295 | if (status < 0) { |
1213 | mlog_errno(status); | 1296 | mlog_errno(status); |
1214 | goto bail; | 1297 | goto bail; |
1215 | } | 1298 | } |
1216 | if (eb_bh) { | 1299 | if (eb_bh) { |
1217 | status = ocfs2_journal_access_eb(handle, inode, eb_bh, | 1300 | status = ocfs2_journal_access_eb(handle, et->et_ci, eb_bh, |
1218 | OCFS2_JOURNAL_ACCESS_WRITE); | 1301 | OCFS2_JOURNAL_ACCESS_WRITE); |
1219 | if (status < 0) { | 1302 | if (status < 0) { |
1220 | mlog_errno(status); | 1303 | mlog_errno(status); |
@@ -1274,9 +1357,7 @@ bail: | |||
1274 | * returns back the new extent block so you can add a branch to it | 1357 | * returns back the new extent block so you can add a branch to it |
1275 | * after this call. | 1358 | * after this call. |
1276 | */ | 1359 | */ |
1277 | static int ocfs2_shift_tree_depth(struct ocfs2_super *osb, | 1360 | static int ocfs2_shift_tree_depth(handle_t *handle, |
1278 | handle_t *handle, | ||
1279 | struct inode *inode, | ||
1280 | struct ocfs2_extent_tree *et, | 1361 | struct ocfs2_extent_tree *et, |
1281 | struct ocfs2_alloc_context *meta_ac, | 1362 | struct ocfs2_alloc_context *meta_ac, |
1282 | struct buffer_head **ret_new_eb_bh) | 1363 | struct buffer_head **ret_new_eb_bh) |
@@ -1290,7 +1371,7 @@ static int ocfs2_shift_tree_depth(struct ocfs2_super *osb, | |||
1290 | 1371 | ||
1291 | mlog_entry_void(); | 1372 | mlog_entry_void(); |
1292 | 1373 | ||
1293 | status = ocfs2_create_new_meta_bhs(osb, handle, inode, 1, meta_ac, | 1374 | status = ocfs2_create_new_meta_bhs(handle, et, 1, meta_ac, |
1294 | &new_eb_bh); | 1375 | &new_eb_bh); |
1295 | if (status < 0) { | 1376 | if (status < 0) { |
1296 | mlog_errno(status); | 1377 | mlog_errno(status); |
@@ -1304,7 +1385,7 @@ static int ocfs2_shift_tree_depth(struct ocfs2_super *osb, | |||
1304 | eb_el = &eb->h_list; | 1385 | eb_el = &eb->h_list; |
1305 | root_el = et->et_root_el; | 1386 | root_el = et->et_root_el; |
1306 | 1387 | ||
1307 | status = ocfs2_journal_access_eb(handle, inode, new_eb_bh, | 1388 | status = ocfs2_journal_access_eb(handle, et->et_ci, new_eb_bh, |
1308 | OCFS2_JOURNAL_ACCESS_CREATE); | 1389 | OCFS2_JOURNAL_ACCESS_CREATE); |
1309 | if (status < 0) { | 1390 | if (status < 0) { |
1310 | mlog_errno(status); | 1391 | mlog_errno(status); |
@@ -1323,7 +1404,7 @@ static int ocfs2_shift_tree_depth(struct ocfs2_super *osb, | |||
1323 | goto bail; | 1404 | goto bail; |
1324 | } | 1405 | } |
1325 | 1406 | ||
1326 | status = ocfs2_et_root_journal_access(handle, inode, et, | 1407 | status = ocfs2_et_root_journal_access(handle, et, |
1327 | OCFS2_JOURNAL_ACCESS_WRITE); | 1408 | OCFS2_JOURNAL_ACCESS_WRITE); |
1328 | if (status < 0) { | 1409 | if (status < 0) { |
1329 | mlog_errno(status); | 1410 | mlog_errno(status); |
@@ -1379,9 +1460,7 @@ bail: | |||
1379 | * | 1460 | * |
1380 | * return status < 0 indicates an error. | 1461 | * return status < 0 indicates an error. |
1381 | */ | 1462 | */ |
1382 | static int ocfs2_find_branch_target(struct ocfs2_super *osb, | 1463 | static int ocfs2_find_branch_target(struct ocfs2_extent_tree *et, |
1383 | struct inode *inode, | ||
1384 | struct ocfs2_extent_tree *et, | ||
1385 | struct buffer_head **target_bh) | 1464 | struct buffer_head **target_bh) |
1386 | { | 1465 | { |
1387 | int status = 0, i; | 1466 | int status = 0, i; |
@@ -1399,19 +1478,21 @@ static int ocfs2_find_branch_target(struct ocfs2_super *osb, | |||
1399 | 1478 | ||
1400 | while(le16_to_cpu(el->l_tree_depth) > 1) { | 1479 | while(le16_to_cpu(el->l_tree_depth) > 1) { |
1401 | if (le16_to_cpu(el->l_next_free_rec) == 0) { | 1480 | if (le16_to_cpu(el->l_next_free_rec) == 0) { |
1402 | ocfs2_error(inode->i_sb, "Dinode %llu has empty " | 1481 | ocfs2_error(ocfs2_metadata_cache_get_super(et->et_ci), |
1482 | "Owner %llu has empty " | ||
1403 | "extent list (next_free_rec == 0)", | 1483 | "extent list (next_free_rec == 0)", |
1404 | (unsigned long long)OCFS2_I(inode)->ip_blkno); | 1484 | (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci)); |
1405 | status = -EIO; | 1485 | status = -EIO; |
1406 | goto bail; | 1486 | goto bail; |
1407 | } | 1487 | } |
1408 | i = le16_to_cpu(el->l_next_free_rec) - 1; | 1488 | i = le16_to_cpu(el->l_next_free_rec) - 1; |
1409 | blkno = le64_to_cpu(el->l_recs[i].e_blkno); | 1489 | blkno = le64_to_cpu(el->l_recs[i].e_blkno); |
1410 | if (!blkno) { | 1490 | if (!blkno) { |
1411 | ocfs2_error(inode->i_sb, "Dinode %llu has extent " | 1491 | ocfs2_error(ocfs2_metadata_cache_get_super(et->et_ci), |
1492 | "Owner %llu has extent " | ||
1412 | "list where extent # %d has no physical " | 1493 | "list where extent # %d has no physical " |
1413 | "block start", | 1494 | "block start", |
1414 | (unsigned long long)OCFS2_I(inode)->ip_blkno, i); | 1495 | (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci), i); |
1415 | status = -EIO; | 1496 | status = -EIO; |
1416 | goto bail; | 1497 | goto bail; |
1417 | } | 1498 | } |
@@ -1419,7 +1500,7 @@ static int ocfs2_find_branch_target(struct ocfs2_super *osb, | |||
1419 | brelse(bh); | 1500 | brelse(bh); |
1420 | bh = NULL; | 1501 | bh = NULL; |
1421 | 1502 | ||
1422 | status = ocfs2_read_extent_block(inode, blkno, &bh); | 1503 | status = ocfs2_read_extent_block(et->et_ci, blkno, &bh); |
1423 | if (status < 0) { | 1504 | if (status < 0) { |
1424 | mlog_errno(status); | 1505 | mlog_errno(status); |
1425 | goto bail; | 1506 | goto bail; |
@@ -1460,20 +1541,18 @@ bail: | |||
1460 | * | 1541 | * |
1461 | * *last_eb_bh will be updated by ocfs2_add_branch(). | 1542 | * *last_eb_bh will be updated by ocfs2_add_branch(). |
1462 | */ | 1543 | */ |
1463 | static int ocfs2_grow_tree(struct inode *inode, handle_t *handle, | 1544 | static int ocfs2_grow_tree(handle_t *handle, struct ocfs2_extent_tree *et, |
1464 | struct ocfs2_extent_tree *et, int *final_depth, | 1545 | int *final_depth, struct buffer_head **last_eb_bh, |
1465 | struct buffer_head **last_eb_bh, | ||
1466 | struct ocfs2_alloc_context *meta_ac) | 1546 | struct ocfs2_alloc_context *meta_ac) |
1467 | { | 1547 | { |
1468 | int ret, shift; | 1548 | int ret, shift; |
1469 | struct ocfs2_extent_list *el = et->et_root_el; | 1549 | struct ocfs2_extent_list *el = et->et_root_el; |
1470 | int depth = le16_to_cpu(el->l_tree_depth); | 1550 | int depth = le16_to_cpu(el->l_tree_depth); |
1471 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
1472 | struct buffer_head *bh = NULL; | 1551 | struct buffer_head *bh = NULL; |
1473 | 1552 | ||
1474 | BUG_ON(meta_ac == NULL); | 1553 | BUG_ON(meta_ac == NULL); |
1475 | 1554 | ||
1476 | shift = ocfs2_find_branch_target(osb, inode, et, &bh); | 1555 | shift = ocfs2_find_branch_target(et, &bh); |
1477 | if (shift < 0) { | 1556 | if (shift < 0) { |
1478 | ret = shift; | 1557 | ret = shift; |
1479 | mlog_errno(ret); | 1558 | mlog_errno(ret); |
@@ -1490,8 +1569,7 @@ static int ocfs2_grow_tree(struct inode *inode, handle_t *handle, | |||
1490 | /* ocfs2_shift_tree_depth will return us a buffer with | 1569 | /* ocfs2_shift_tree_depth will return us a buffer with |
1491 | * the new extent block (so we can pass that to | 1570 | * the new extent block (so we can pass that to |
1492 | * ocfs2_add_branch). */ | 1571 | * ocfs2_add_branch). */ |
1493 | ret = ocfs2_shift_tree_depth(osb, handle, inode, et, | 1572 | ret = ocfs2_shift_tree_depth(handle, et, meta_ac, &bh); |
1494 | meta_ac, &bh); | ||
1495 | if (ret < 0) { | 1573 | if (ret < 0) { |
1496 | mlog_errno(ret); | 1574 | mlog_errno(ret); |
1497 | goto out; | 1575 | goto out; |
@@ -1517,7 +1595,7 @@ static int ocfs2_grow_tree(struct inode *inode, handle_t *handle, | |||
1517 | /* call ocfs2_add_branch to add the final part of the tree with | 1595 | /* call ocfs2_add_branch to add the final part of the tree with |
1518 | * the new data. */ | 1596 | * the new data. */ |
1519 | mlog(0, "add branch. bh = %p\n", bh); | 1597 | mlog(0, "add branch. bh = %p\n", bh); |
1520 | ret = ocfs2_add_branch(osb, handle, inode, et, bh, last_eb_bh, | 1598 | ret = ocfs2_add_branch(handle, et, bh, last_eb_bh, |
1521 | meta_ac); | 1599 | meta_ac); |
1522 | if (ret < 0) { | 1600 | if (ret < 0) { |
1523 | mlog_errno(ret); | 1601 | mlog_errno(ret); |
@@ -1687,7 +1765,7 @@ set_and_inc: | |||
1687 | * | 1765 | * |
1688 | * The array index of the subtree root is passed back. | 1766 | * The array index of the subtree root is passed back. |
1689 | */ | 1767 | */ |
1690 | static int ocfs2_find_subtree_root(struct inode *inode, | 1768 | static int ocfs2_find_subtree_root(struct ocfs2_extent_tree *et, |
1691 | struct ocfs2_path *left, | 1769 | struct ocfs2_path *left, |
1692 | struct ocfs2_path *right) | 1770 | struct ocfs2_path *right) |
1693 | { | 1771 | { |
@@ -1705,10 +1783,10 @@ static int ocfs2_find_subtree_root(struct inode *inode, | |||
1705 | * The caller didn't pass two adjacent paths. | 1783 | * The caller didn't pass two adjacent paths. |
1706 | */ | 1784 | */ |
1707 | mlog_bug_on_msg(i > left->p_tree_depth, | 1785 | mlog_bug_on_msg(i > left->p_tree_depth, |
1708 | "Inode %lu, left depth %u, right depth %u\n" | 1786 | "Owner %llu, left depth %u, right depth %u\n" |
1709 | "left leaf blk %llu, right leaf blk %llu\n", | 1787 | "left leaf blk %llu, right leaf blk %llu\n", |
1710 | inode->i_ino, left->p_tree_depth, | 1788 | (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci), |
1711 | right->p_tree_depth, | 1789 | left->p_tree_depth, right->p_tree_depth, |
1712 | (unsigned long long)path_leaf_bh(left)->b_blocknr, | 1790 | (unsigned long long)path_leaf_bh(left)->b_blocknr, |
1713 | (unsigned long long)path_leaf_bh(right)->b_blocknr); | 1791 | (unsigned long long)path_leaf_bh(right)->b_blocknr); |
1714 | } while (left->p_node[i].bh->b_blocknr == | 1792 | } while (left->p_node[i].bh->b_blocknr == |
@@ -1725,7 +1803,7 @@ typedef void (path_insert_t)(void *, struct buffer_head *); | |||
1725 | * This code can be called with a cpos larger than the tree, in which | 1803 | * This code can be called with a cpos larger than the tree, in which |
1726 | * case it will return the rightmost path. | 1804 | * case it will return the rightmost path. |
1727 | */ | 1805 | */ |
1728 | static int __ocfs2_find_path(struct inode *inode, | 1806 | static int __ocfs2_find_path(struct ocfs2_caching_info *ci, |
1729 | struct ocfs2_extent_list *root_el, u32 cpos, | 1807 | struct ocfs2_extent_list *root_el, u32 cpos, |
1730 | path_insert_t *func, void *data) | 1808 | path_insert_t *func, void *data) |
1731 | { | 1809 | { |
@@ -1736,15 +1814,14 @@ static int __ocfs2_find_path(struct inode *inode, | |||
1736 | struct ocfs2_extent_block *eb; | 1814 | struct ocfs2_extent_block *eb; |
1737 | struct ocfs2_extent_list *el; | 1815 | struct ocfs2_extent_list *el; |
1738 | struct ocfs2_extent_rec *rec; | 1816 | struct ocfs2_extent_rec *rec; |
1739 | struct ocfs2_inode_info *oi = OCFS2_I(inode); | ||
1740 | 1817 | ||
1741 | el = root_el; | 1818 | el = root_el; |
1742 | while (el->l_tree_depth) { | 1819 | while (el->l_tree_depth) { |
1743 | if (le16_to_cpu(el->l_next_free_rec) == 0) { | 1820 | if (le16_to_cpu(el->l_next_free_rec) == 0) { |
1744 | ocfs2_error(inode->i_sb, | 1821 | ocfs2_error(ocfs2_metadata_cache_get_super(ci), |
1745 | "Inode %llu has empty extent list at " | 1822 | "Owner %llu has empty extent list at " |
1746 | "depth %u\n", | 1823 | "depth %u\n", |
1747 | (unsigned long long)oi->ip_blkno, | 1824 | (unsigned long long)ocfs2_metadata_cache_owner(ci), |
1748 | le16_to_cpu(el->l_tree_depth)); | 1825 | le16_to_cpu(el->l_tree_depth)); |
1749 | ret = -EROFS; | 1826 | ret = -EROFS; |
1750 | goto out; | 1827 | goto out; |
@@ -1767,10 +1844,10 @@ static int __ocfs2_find_path(struct inode *inode, | |||
1767 | 1844 | ||
1768 | blkno = le64_to_cpu(el->l_recs[i].e_blkno); | 1845 | blkno = le64_to_cpu(el->l_recs[i].e_blkno); |
1769 | if (blkno == 0) { | 1846 | if (blkno == 0) { |
1770 | ocfs2_error(inode->i_sb, | 1847 | ocfs2_error(ocfs2_metadata_cache_get_super(ci), |
1771 | "Inode %llu has bad blkno in extent list " | 1848 | "Owner %llu has bad blkno in extent list " |
1772 | "at depth %u (index %d)\n", | 1849 | "at depth %u (index %d)\n", |
1773 | (unsigned long long)oi->ip_blkno, | 1850 | (unsigned long long)ocfs2_metadata_cache_owner(ci), |
1774 | le16_to_cpu(el->l_tree_depth), i); | 1851 | le16_to_cpu(el->l_tree_depth), i); |
1775 | ret = -EROFS; | 1852 | ret = -EROFS; |
1776 | goto out; | 1853 | goto out; |
@@ -1778,7 +1855,7 @@ static int __ocfs2_find_path(struct inode *inode, | |||
1778 | 1855 | ||
1779 | brelse(bh); | 1856 | brelse(bh); |
1780 | bh = NULL; | 1857 | bh = NULL; |
1781 | ret = ocfs2_read_extent_block(inode, blkno, &bh); | 1858 | ret = ocfs2_read_extent_block(ci, blkno, &bh); |
1782 | if (ret) { | 1859 | if (ret) { |
1783 | mlog_errno(ret); | 1860 | mlog_errno(ret); |
1784 | goto out; | 1861 | goto out; |
@@ -1789,10 +1866,10 @@ static int __ocfs2_find_path(struct inode *inode, | |||
1789 | 1866 | ||
1790 | if (le16_to_cpu(el->l_next_free_rec) > | 1867 | if (le16_to_cpu(el->l_next_free_rec) > |
1791 | le16_to_cpu(el->l_count)) { | 1868 | le16_to_cpu(el->l_count)) { |
1792 | ocfs2_error(inode->i_sb, | 1869 | ocfs2_error(ocfs2_metadata_cache_get_super(ci), |
1793 | "Inode %llu has bad count in extent list " | 1870 | "Owner %llu has bad count in extent list " |
1794 | "at block %llu (next free=%u, count=%u)\n", | 1871 | "at block %llu (next free=%u, count=%u)\n", |
1795 | (unsigned long long)oi->ip_blkno, | 1872 | (unsigned long long)ocfs2_metadata_cache_owner(ci), |
1796 | (unsigned long long)bh->b_blocknr, | 1873 | (unsigned long long)bh->b_blocknr, |
1797 | le16_to_cpu(el->l_next_free_rec), | 1874 | le16_to_cpu(el->l_next_free_rec), |
1798 | le16_to_cpu(el->l_count)); | 1875 | le16_to_cpu(el->l_count)); |
@@ -1836,14 +1913,14 @@ static void find_path_ins(void *data, struct buffer_head *bh) | |||
1836 | ocfs2_path_insert_eb(fp->path, fp->index, bh); | 1913 | ocfs2_path_insert_eb(fp->path, fp->index, bh); |
1837 | fp->index++; | 1914 | fp->index++; |
1838 | } | 1915 | } |
1839 | static int ocfs2_find_path(struct inode *inode, struct ocfs2_path *path, | 1916 | int ocfs2_find_path(struct ocfs2_caching_info *ci, |
1840 | u32 cpos) | 1917 | struct ocfs2_path *path, u32 cpos) |
1841 | { | 1918 | { |
1842 | struct find_path_data data; | 1919 | struct find_path_data data; |
1843 | 1920 | ||
1844 | data.index = 1; | 1921 | data.index = 1; |
1845 | data.path = path; | 1922 | data.path = path; |
1846 | return __ocfs2_find_path(inode, path_root_el(path), cpos, | 1923 | return __ocfs2_find_path(ci, path_root_el(path), cpos, |
1847 | find_path_ins, &data); | 1924 | find_path_ins, &data); |
1848 | } | 1925 | } |
1849 | 1926 | ||
@@ -1868,13 +1945,14 @@ static void find_leaf_ins(void *data, struct buffer_head *bh) | |||
1868 | * | 1945 | * |
1869 | * This function doesn't handle non btree extent lists. | 1946 | * This function doesn't handle non btree extent lists. |
1870 | */ | 1947 | */ |
1871 | int ocfs2_find_leaf(struct inode *inode, struct ocfs2_extent_list *root_el, | 1948 | int ocfs2_find_leaf(struct ocfs2_caching_info *ci, |
1872 | u32 cpos, struct buffer_head **leaf_bh) | 1949 | struct ocfs2_extent_list *root_el, u32 cpos, |
1950 | struct buffer_head **leaf_bh) | ||
1873 | { | 1951 | { |
1874 | int ret; | 1952 | int ret; |
1875 | struct buffer_head *bh = NULL; | 1953 | struct buffer_head *bh = NULL; |
1876 | 1954 | ||
1877 | ret = __ocfs2_find_path(inode, root_el, cpos, find_leaf_ins, &bh); | 1955 | ret = __ocfs2_find_path(ci, root_el, cpos, find_leaf_ins, &bh); |
1878 | if (ret) { | 1956 | if (ret) { |
1879 | mlog_errno(ret); | 1957 | mlog_errno(ret); |
1880 | goto out; | 1958 | goto out; |
@@ -1980,7 +2058,7 @@ static void ocfs2_adjust_root_records(struct ocfs2_extent_list *root_el, | |||
1980 | * - When we've adjusted the last extent record in the left path leaf and the | 2058 | * - When we've adjusted the last extent record in the left path leaf and the |
1981 | * 1st extent record in the right path leaf during cross extent block merge. | 2059 | * 1st extent record in the right path leaf during cross extent block merge. |
1982 | */ | 2060 | */ |
1983 | static void ocfs2_complete_edge_insert(struct inode *inode, handle_t *handle, | 2061 | static void ocfs2_complete_edge_insert(handle_t *handle, |
1984 | struct ocfs2_path *left_path, | 2062 | struct ocfs2_path *left_path, |
1985 | struct ocfs2_path *right_path, | 2063 | struct ocfs2_path *right_path, |
1986 | int subtree_index) | 2064 | int subtree_index) |
@@ -2058,8 +2136,8 @@ static void ocfs2_complete_edge_insert(struct inode *inode, handle_t *handle, | |||
2058 | mlog_errno(ret); | 2136 | mlog_errno(ret); |
2059 | } | 2137 | } |
2060 | 2138 | ||
2061 | static int ocfs2_rotate_subtree_right(struct inode *inode, | 2139 | static int ocfs2_rotate_subtree_right(handle_t *handle, |
2062 | handle_t *handle, | 2140 | struct ocfs2_extent_tree *et, |
2063 | struct ocfs2_path *left_path, | 2141 | struct ocfs2_path *left_path, |
2064 | struct ocfs2_path *right_path, | 2142 | struct ocfs2_path *right_path, |
2065 | int subtree_index) | 2143 | int subtree_index) |
@@ -2075,10 +2153,10 @@ static int ocfs2_rotate_subtree_right(struct inode *inode, | |||
2075 | left_el = path_leaf_el(left_path); | 2153 | left_el = path_leaf_el(left_path); |
2076 | 2154 | ||
2077 | if (left_el->l_next_free_rec != left_el->l_count) { | 2155 | if (left_el->l_next_free_rec != left_el->l_count) { |
2078 | ocfs2_error(inode->i_sb, | 2156 | ocfs2_error(ocfs2_metadata_cache_get_super(et->et_ci), |
2079 | "Inode %llu has non-full interior leaf node %llu" | 2157 | "Inode %llu has non-full interior leaf node %llu" |
2080 | "(next free = %u)", | 2158 | "(next free = %u)", |
2081 | (unsigned long long)OCFS2_I(inode)->ip_blkno, | 2159 | (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci), |
2082 | (unsigned long long)left_leaf_bh->b_blocknr, | 2160 | (unsigned long long)left_leaf_bh->b_blocknr, |
2083 | le16_to_cpu(left_el->l_next_free_rec)); | 2161 | le16_to_cpu(left_el->l_next_free_rec)); |
2084 | return -EROFS; | 2162 | return -EROFS; |
@@ -2094,7 +2172,7 @@ static int ocfs2_rotate_subtree_right(struct inode *inode, | |||
2094 | root_bh = left_path->p_node[subtree_index].bh; | 2172 | root_bh = left_path->p_node[subtree_index].bh; |
2095 | BUG_ON(root_bh != right_path->p_node[subtree_index].bh); | 2173 | BUG_ON(root_bh != right_path->p_node[subtree_index].bh); |
2096 | 2174 | ||
2097 | ret = ocfs2_path_bh_journal_access(handle, inode, right_path, | 2175 | ret = ocfs2_path_bh_journal_access(handle, et->et_ci, right_path, |
2098 | subtree_index); | 2176 | subtree_index); |
2099 | if (ret) { | 2177 | if (ret) { |
2100 | mlog_errno(ret); | 2178 | mlog_errno(ret); |
@@ -2102,14 +2180,14 @@ static int ocfs2_rotate_subtree_right(struct inode *inode, | |||
2102 | } | 2180 | } |
2103 | 2181 | ||
2104 | for(i = subtree_index + 1; i < path_num_items(right_path); i++) { | 2182 | for(i = subtree_index + 1; i < path_num_items(right_path); i++) { |
2105 | ret = ocfs2_path_bh_journal_access(handle, inode, | 2183 | ret = ocfs2_path_bh_journal_access(handle, et->et_ci, |
2106 | right_path, i); | 2184 | right_path, i); |
2107 | if (ret) { | 2185 | if (ret) { |
2108 | mlog_errno(ret); | 2186 | mlog_errno(ret); |
2109 | goto out; | 2187 | goto out; |
2110 | } | 2188 | } |
2111 | 2189 | ||
2112 | ret = ocfs2_path_bh_journal_access(handle, inode, | 2190 | ret = ocfs2_path_bh_journal_access(handle, et->et_ci, |
2113 | left_path, i); | 2191 | left_path, i); |
2114 | if (ret) { | 2192 | if (ret) { |
2115 | mlog_errno(ret); | 2193 | mlog_errno(ret); |
@@ -2123,7 +2201,7 @@ static int ocfs2_rotate_subtree_right(struct inode *inode, | |||
2123 | /* This is a code error, not a disk corruption. */ | 2201 | /* This is a code error, not a disk corruption. */ |
2124 | mlog_bug_on_msg(!right_el->l_next_free_rec, "Inode %llu: Rotate fails " | 2202 | mlog_bug_on_msg(!right_el->l_next_free_rec, "Inode %llu: Rotate fails " |
2125 | "because rightmost leaf block %llu is empty\n", | 2203 | "because rightmost leaf block %llu is empty\n", |
2126 | (unsigned long long)OCFS2_I(inode)->ip_blkno, | 2204 | (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci), |
2127 | (unsigned long long)right_leaf_bh->b_blocknr); | 2205 | (unsigned long long)right_leaf_bh->b_blocknr); |
2128 | 2206 | ||
2129 | ocfs2_create_empty_extent(right_el); | 2207 | ocfs2_create_empty_extent(right_el); |
@@ -2157,8 +2235,8 @@ static int ocfs2_rotate_subtree_right(struct inode *inode, | |||
2157 | goto out; | 2235 | goto out; |
2158 | } | 2236 | } |
2159 | 2237 | ||
2160 | ocfs2_complete_edge_insert(inode, handle, left_path, right_path, | 2238 | ocfs2_complete_edge_insert(handle, left_path, right_path, |
2161 | subtree_index); | 2239 | subtree_index); |
2162 | 2240 | ||
2163 | out: | 2241 | out: |
2164 | return ret; | 2242 | return ret; |
@@ -2248,10 +2326,18 @@ static int ocfs2_extend_rotate_transaction(handle_t *handle, int subtree_depth, | |||
2248 | int op_credits, | 2326 | int op_credits, |
2249 | struct ocfs2_path *path) | 2327 | struct ocfs2_path *path) |
2250 | { | 2328 | { |
2329 | int ret; | ||
2251 | int credits = (path->p_tree_depth - subtree_depth) * 2 + 1 + op_credits; | 2330 | int credits = (path->p_tree_depth - subtree_depth) * 2 + 1 + op_credits; |
2252 | 2331 | ||
2253 | if (handle->h_buffer_credits < credits) | 2332 | if (handle->h_buffer_credits < credits) { |
2254 | return ocfs2_extend_trans(handle, credits); | 2333 | ret = ocfs2_extend_trans(handle, |
2334 | credits - handle->h_buffer_credits); | ||
2335 | if (ret) | ||
2336 | return ret; | ||
2337 | |||
2338 | if (unlikely(handle->h_buffer_credits < credits)) | ||
2339 | return ocfs2_extend_trans(handle, credits); | ||
2340 | } | ||
2255 | 2341 | ||
2256 | return 0; | 2342 | return 0; |
2257 | } | 2343 | } |
@@ -2321,8 +2407,8 @@ static int ocfs2_leftmost_rec_contains(struct ocfs2_extent_list *el, u32 cpos) | |||
2321 | * *ret_left_path will contain a valid path which can be passed to | 2407 | * *ret_left_path will contain a valid path which can be passed to |
2322 | * ocfs2_insert_path(). | 2408 | * ocfs2_insert_path(). |
2323 | */ | 2409 | */ |
2324 | static int ocfs2_rotate_tree_right(struct inode *inode, | 2410 | static int ocfs2_rotate_tree_right(handle_t *handle, |
2325 | handle_t *handle, | 2411 | struct ocfs2_extent_tree *et, |
2326 | enum ocfs2_split_type split, | 2412 | enum ocfs2_split_type split, |
2327 | u32 insert_cpos, | 2413 | u32 insert_cpos, |
2328 | struct ocfs2_path *right_path, | 2414 | struct ocfs2_path *right_path, |
@@ -2331,6 +2417,7 @@ static int ocfs2_rotate_tree_right(struct inode *inode, | |||
2331 | int ret, start, orig_credits = handle->h_buffer_credits; | 2417 | int ret, start, orig_credits = handle->h_buffer_credits; |
2332 | u32 cpos; | 2418 | u32 cpos; |
2333 | struct ocfs2_path *left_path = NULL; | 2419 | struct ocfs2_path *left_path = NULL; |
2420 | struct super_block *sb = ocfs2_metadata_cache_get_super(et->et_ci); | ||
2334 | 2421 | ||
2335 | *ret_left_path = NULL; | 2422 | *ret_left_path = NULL; |
2336 | 2423 | ||
@@ -2341,7 +2428,7 @@ static int ocfs2_rotate_tree_right(struct inode *inode, | |||
2341 | goto out; | 2428 | goto out; |
2342 | } | 2429 | } |
2343 | 2430 | ||
2344 | ret = ocfs2_find_cpos_for_left_leaf(inode->i_sb, right_path, &cpos); | 2431 | ret = ocfs2_find_cpos_for_left_leaf(sb, right_path, &cpos); |
2345 | if (ret) { | 2432 | if (ret) { |
2346 | mlog_errno(ret); | 2433 | mlog_errno(ret); |
2347 | goto out; | 2434 | goto out; |
@@ -2379,7 +2466,7 @@ static int ocfs2_rotate_tree_right(struct inode *inode, | |||
2379 | mlog(0, "Rotating a tree: ins. cpos: %u, left path cpos: %u\n", | 2466 | mlog(0, "Rotating a tree: ins. cpos: %u, left path cpos: %u\n", |
2380 | insert_cpos, cpos); | 2467 | insert_cpos, cpos); |
2381 | 2468 | ||
2382 | ret = ocfs2_find_path(inode, left_path, cpos); | 2469 | ret = ocfs2_find_path(et->et_ci, left_path, cpos); |
2383 | if (ret) { | 2470 | if (ret) { |
2384 | mlog_errno(ret); | 2471 | mlog_errno(ret); |
2385 | goto out; | 2472 | goto out; |
@@ -2387,10 +2474,11 @@ static int ocfs2_rotate_tree_right(struct inode *inode, | |||
2387 | 2474 | ||
2388 | mlog_bug_on_msg(path_leaf_bh(left_path) == | 2475 | mlog_bug_on_msg(path_leaf_bh(left_path) == |
2389 | path_leaf_bh(right_path), | 2476 | path_leaf_bh(right_path), |
2390 | "Inode %lu: error during insert of %u " | 2477 | "Owner %llu: error during insert of %u " |
2391 | "(left path cpos %u) results in two identical " | 2478 | "(left path cpos %u) results in two identical " |
2392 | "paths ending at %llu\n", | 2479 | "paths ending at %llu\n", |
2393 | inode->i_ino, insert_cpos, cpos, | 2480 | (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci), |
2481 | insert_cpos, cpos, | ||
2394 | (unsigned long long) | 2482 | (unsigned long long) |
2395 | path_leaf_bh(left_path)->b_blocknr); | 2483 | path_leaf_bh(left_path)->b_blocknr); |
2396 | 2484 | ||
@@ -2416,7 +2504,7 @@ static int ocfs2_rotate_tree_right(struct inode *inode, | |||
2416 | goto out_ret_path; | 2504 | goto out_ret_path; |
2417 | } | 2505 | } |
2418 | 2506 | ||
2419 | start = ocfs2_find_subtree_root(inode, left_path, right_path); | 2507 | start = ocfs2_find_subtree_root(et, left_path, right_path); |
2420 | 2508 | ||
2421 | mlog(0, "Subtree root at index %d (blk %llu, depth %d)\n", | 2509 | mlog(0, "Subtree root at index %d (blk %llu, depth %d)\n", |
2422 | start, | 2510 | start, |
@@ -2430,7 +2518,7 @@ static int ocfs2_rotate_tree_right(struct inode *inode, | |||
2430 | goto out; | 2518 | goto out; |
2431 | } | 2519 | } |
2432 | 2520 | ||
2433 | ret = ocfs2_rotate_subtree_right(inode, handle, left_path, | 2521 | ret = ocfs2_rotate_subtree_right(handle, et, left_path, |
2434 | right_path, start); | 2522 | right_path, start); |
2435 | if (ret) { | 2523 | if (ret) { |
2436 | mlog_errno(ret); | 2524 | mlog_errno(ret); |
@@ -2462,8 +2550,7 @@ static int ocfs2_rotate_tree_right(struct inode *inode, | |||
2462 | */ | 2550 | */ |
2463 | ocfs2_mv_path(right_path, left_path); | 2551 | ocfs2_mv_path(right_path, left_path); |
2464 | 2552 | ||
2465 | ret = ocfs2_find_cpos_for_left_leaf(inode->i_sb, right_path, | 2553 | ret = ocfs2_find_cpos_for_left_leaf(sb, right_path, &cpos); |
2466 | &cpos); | ||
2467 | if (ret) { | 2554 | if (ret) { |
2468 | mlog_errno(ret); | 2555 | mlog_errno(ret); |
2469 | goto out; | 2556 | goto out; |
@@ -2477,7 +2564,8 @@ out_ret_path: | |||
2477 | return ret; | 2564 | return ret; |
2478 | } | 2565 | } |
2479 | 2566 | ||
2480 | static int ocfs2_update_edge_lengths(struct inode *inode, handle_t *handle, | 2567 | static int ocfs2_update_edge_lengths(handle_t *handle, |
2568 | struct ocfs2_extent_tree *et, | ||
2481 | int subtree_index, struct ocfs2_path *path) | 2569 | int subtree_index, struct ocfs2_path *path) |
2482 | { | 2570 | { |
2483 | int i, idx, ret; | 2571 | int i, idx, ret; |
@@ -2502,7 +2590,7 @@ static int ocfs2_update_edge_lengths(struct inode *inode, handle_t *handle, | |||
2502 | goto out; | 2590 | goto out; |
2503 | } | 2591 | } |
2504 | 2592 | ||
2505 | ret = ocfs2_journal_access_path(inode, handle, path); | 2593 | ret = ocfs2_journal_access_path(et->et_ci, handle, path); |
2506 | if (ret) { | 2594 | if (ret) { |
2507 | mlog_errno(ret); | 2595 | mlog_errno(ret); |
2508 | goto out; | 2596 | goto out; |
@@ -2532,7 +2620,8 @@ out: | |||
2532 | return ret; | 2620 | return ret; |
2533 | } | 2621 | } |
2534 | 2622 | ||
2535 | static void ocfs2_unlink_path(struct inode *inode, handle_t *handle, | 2623 | static void ocfs2_unlink_path(handle_t *handle, |
2624 | struct ocfs2_extent_tree *et, | ||
2536 | struct ocfs2_cached_dealloc_ctxt *dealloc, | 2625 | struct ocfs2_cached_dealloc_ctxt *dealloc, |
2537 | struct ocfs2_path *path, int unlink_start) | 2626 | struct ocfs2_path *path, int unlink_start) |
2538 | { | 2627 | { |
@@ -2554,12 +2643,12 @@ static void ocfs2_unlink_path(struct inode *inode, handle_t *handle, | |||
2554 | mlog(ML_ERROR, | 2643 | mlog(ML_ERROR, |
2555 | "Inode %llu, attempted to remove extent block " | 2644 | "Inode %llu, attempted to remove extent block " |
2556 | "%llu with %u records\n", | 2645 | "%llu with %u records\n", |
2557 | (unsigned long long)OCFS2_I(inode)->ip_blkno, | 2646 | (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci), |
2558 | (unsigned long long)le64_to_cpu(eb->h_blkno), | 2647 | (unsigned long long)le64_to_cpu(eb->h_blkno), |
2559 | le16_to_cpu(el->l_next_free_rec)); | 2648 | le16_to_cpu(el->l_next_free_rec)); |
2560 | 2649 | ||
2561 | ocfs2_journal_dirty(handle, bh); | 2650 | ocfs2_journal_dirty(handle, bh); |
2562 | ocfs2_remove_from_cache(inode, bh); | 2651 | ocfs2_remove_from_cache(et->et_ci, bh); |
2563 | continue; | 2652 | continue; |
2564 | } | 2653 | } |
2565 | 2654 | ||
@@ -2572,11 +2661,12 @@ static void ocfs2_unlink_path(struct inode *inode, handle_t *handle, | |||
2572 | if (ret) | 2661 | if (ret) |
2573 | mlog_errno(ret); | 2662 | mlog_errno(ret); |
2574 | 2663 | ||
2575 | ocfs2_remove_from_cache(inode, bh); | 2664 | ocfs2_remove_from_cache(et->et_ci, bh); |
2576 | } | 2665 | } |
2577 | } | 2666 | } |
2578 | 2667 | ||
2579 | static void ocfs2_unlink_subtree(struct inode *inode, handle_t *handle, | 2668 | static void ocfs2_unlink_subtree(handle_t *handle, |
2669 | struct ocfs2_extent_tree *et, | ||
2580 | struct ocfs2_path *left_path, | 2670 | struct ocfs2_path *left_path, |
2581 | struct ocfs2_path *right_path, | 2671 | struct ocfs2_path *right_path, |
2582 | int subtree_index, | 2672 | int subtree_index, |
@@ -2607,17 +2697,17 @@ static void ocfs2_unlink_subtree(struct inode *inode, handle_t *handle, | |||
2607 | ocfs2_journal_dirty(handle, root_bh); | 2697 | ocfs2_journal_dirty(handle, root_bh); |
2608 | ocfs2_journal_dirty(handle, path_leaf_bh(left_path)); | 2698 | ocfs2_journal_dirty(handle, path_leaf_bh(left_path)); |
2609 | 2699 | ||
2610 | ocfs2_unlink_path(inode, handle, dealloc, right_path, | 2700 | ocfs2_unlink_path(handle, et, dealloc, right_path, |
2611 | subtree_index + 1); | 2701 | subtree_index + 1); |
2612 | } | 2702 | } |
2613 | 2703 | ||
2614 | static int ocfs2_rotate_subtree_left(struct inode *inode, handle_t *handle, | 2704 | static int ocfs2_rotate_subtree_left(handle_t *handle, |
2705 | struct ocfs2_extent_tree *et, | ||
2615 | struct ocfs2_path *left_path, | 2706 | struct ocfs2_path *left_path, |
2616 | struct ocfs2_path *right_path, | 2707 | struct ocfs2_path *right_path, |
2617 | int subtree_index, | 2708 | int subtree_index, |
2618 | struct ocfs2_cached_dealloc_ctxt *dealloc, | 2709 | struct ocfs2_cached_dealloc_ctxt *dealloc, |
2619 | int *deleted, | 2710 | int *deleted) |
2620 | struct ocfs2_extent_tree *et) | ||
2621 | { | 2711 | { |
2622 | int ret, i, del_right_subtree = 0, right_has_empty = 0; | 2712 | int ret, i, del_right_subtree = 0, right_has_empty = 0; |
2623 | struct buffer_head *root_bh, *et_root_bh = path_root_bh(right_path); | 2713 | struct buffer_head *root_bh, *et_root_bh = path_root_bh(right_path); |
@@ -2653,7 +2743,7 @@ static int ocfs2_rotate_subtree_left(struct inode *inode, handle_t *handle, | |||
2653 | return -EAGAIN; | 2743 | return -EAGAIN; |
2654 | 2744 | ||
2655 | if (le16_to_cpu(right_leaf_el->l_next_free_rec) > 1) { | 2745 | if (le16_to_cpu(right_leaf_el->l_next_free_rec) > 1) { |
2656 | ret = ocfs2_journal_access_eb(handle, inode, | 2746 | ret = ocfs2_journal_access_eb(handle, et->et_ci, |
2657 | path_leaf_bh(right_path), | 2747 | path_leaf_bh(right_path), |
2658 | OCFS2_JOURNAL_ACCESS_WRITE); | 2748 | OCFS2_JOURNAL_ACCESS_WRITE); |
2659 | if (ret) { | 2749 | if (ret) { |
@@ -2672,7 +2762,7 @@ static int ocfs2_rotate_subtree_left(struct inode *inode, handle_t *handle, | |||
2672 | * We have to update i_last_eb_blk during the meta | 2762 | * We have to update i_last_eb_blk during the meta |
2673 | * data delete. | 2763 | * data delete. |
2674 | */ | 2764 | */ |
2675 | ret = ocfs2_et_root_journal_access(handle, inode, et, | 2765 | ret = ocfs2_et_root_journal_access(handle, et, |
2676 | OCFS2_JOURNAL_ACCESS_WRITE); | 2766 | OCFS2_JOURNAL_ACCESS_WRITE); |
2677 | if (ret) { | 2767 | if (ret) { |
2678 | mlog_errno(ret); | 2768 | mlog_errno(ret); |
@@ -2688,7 +2778,7 @@ static int ocfs2_rotate_subtree_left(struct inode *inode, handle_t *handle, | |||
2688 | */ | 2778 | */ |
2689 | BUG_ON(right_has_empty && !del_right_subtree); | 2779 | BUG_ON(right_has_empty && !del_right_subtree); |
2690 | 2780 | ||
2691 | ret = ocfs2_path_bh_journal_access(handle, inode, right_path, | 2781 | ret = ocfs2_path_bh_journal_access(handle, et->et_ci, right_path, |
2692 | subtree_index); | 2782 | subtree_index); |
2693 | if (ret) { | 2783 | if (ret) { |
2694 | mlog_errno(ret); | 2784 | mlog_errno(ret); |
@@ -2696,14 +2786,14 @@ static int ocfs2_rotate_subtree_left(struct inode *inode, handle_t *handle, | |||
2696 | } | 2786 | } |
2697 | 2787 | ||
2698 | for(i = subtree_index + 1; i < path_num_items(right_path); i++) { | 2788 | for(i = subtree_index + 1; i < path_num_items(right_path); i++) { |
2699 | ret = ocfs2_path_bh_journal_access(handle, inode, | 2789 | ret = ocfs2_path_bh_journal_access(handle, et->et_ci, |
2700 | right_path, i); | 2790 | right_path, i); |
2701 | if (ret) { | 2791 | if (ret) { |
2702 | mlog_errno(ret); | 2792 | mlog_errno(ret); |
2703 | goto out; | 2793 | goto out; |
2704 | } | 2794 | } |
2705 | 2795 | ||
2706 | ret = ocfs2_path_bh_journal_access(handle, inode, | 2796 | ret = ocfs2_path_bh_journal_access(handle, et->et_ci, |
2707 | left_path, i); | 2797 | left_path, i); |
2708 | if (ret) { | 2798 | if (ret) { |
2709 | mlog_errno(ret); | 2799 | mlog_errno(ret); |
@@ -2740,9 +2830,9 @@ static int ocfs2_rotate_subtree_left(struct inode *inode, handle_t *handle, | |||
2740 | mlog_errno(ret); | 2830 | mlog_errno(ret); |
2741 | 2831 | ||
2742 | if (del_right_subtree) { | 2832 | if (del_right_subtree) { |
2743 | ocfs2_unlink_subtree(inode, handle, left_path, right_path, | 2833 | ocfs2_unlink_subtree(handle, et, left_path, right_path, |
2744 | subtree_index, dealloc); | 2834 | subtree_index, dealloc); |
2745 | ret = ocfs2_update_edge_lengths(inode, handle, subtree_index, | 2835 | ret = ocfs2_update_edge_lengths(handle, et, subtree_index, |
2746 | left_path); | 2836 | left_path); |
2747 | if (ret) { | 2837 | if (ret) { |
2748 | mlog_errno(ret); | 2838 | mlog_errno(ret); |
@@ -2766,7 +2856,7 @@ static int ocfs2_rotate_subtree_left(struct inode *inode, handle_t *handle, | |||
2766 | 2856 | ||
2767 | *deleted = 1; | 2857 | *deleted = 1; |
2768 | } else | 2858 | } else |
2769 | ocfs2_complete_edge_insert(inode, handle, left_path, right_path, | 2859 | ocfs2_complete_edge_insert(handle, left_path, right_path, |
2770 | subtree_index); | 2860 | subtree_index); |
2771 | 2861 | ||
2772 | out: | 2862 | out: |
@@ -2852,8 +2942,8 @@ out: | |||
2852 | return ret; | 2942 | return ret; |
2853 | } | 2943 | } |
2854 | 2944 | ||
2855 | static int ocfs2_rotate_rightmost_leaf_left(struct inode *inode, | 2945 | static int ocfs2_rotate_rightmost_leaf_left(handle_t *handle, |
2856 | handle_t *handle, | 2946 | struct ocfs2_extent_tree *et, |
2857 | struct ocfs2_path *path) | 2947 | struct ocfs2_path *path) |
2858 | { | 2948 | { |
2859 | int ret; | 2949 | int ret; |
@@ -2863,7 +2953,7 @@ static int ocfs2_rotate_rightmost_leaf_left(struct inode *inode, | |||
2863 | if (!ocfs2_is_empty_extent(&el->l_recs[0])) | 2953 | if (!ocfs2_is_empty_extent(&el->l_recs[0])) |
2864 | return 0; | 2954 | return 0; |
2865 | 2955 | ||
2866 | ret = ocfs2_path_bh_journal_access(handle, inode, path, | 2956 | ret = ocfs2_path_bh_journal_access(handle, et->et_ci, path, |
2867 | path_num_items(path) - 1); | 2957 | path_num_items(path) - 1); |
2868 | if (ret) { | 2958 | if (ret) { |
2869 | mlog_errno(ret); | 2959 | mlog_errno(ret); |
@@ -2880,24 +2970,24 @@ out: | |||
2880 | return ret; | 2970 | return ret; |
2881 | } | 2971 | } |
2882 | 2972 | ||
2883 | static int __ocfs2_rotate_tree_left(struct inode *inode, | 2973 | static int __ocfs2_rotate_tree_left(handle_t *handle, |
2884 | handle_t *handle, int orig_credits, | 2974 | struct ocfs2_extent_tree *et, |
2975 | int orig_credits, | ||
2885 | struct ocfs2_path *path, | 2976 | struct ocfs2_path *path, |
2886 | struct ocfs2_cached_dealloc_ctxt *dealloc, | 2977 | struct ocfs2_cached_dealloc_ctxt *dealloc, |
2887 | struct ocfs2_path **empty_extent_path, | 2978 | struct ocfs2_path **empty_extent_path) |
2888 | struct ocfs2_extent_tree *et) | ||
2889 | { | 2979 | { |
2890 | int ret, subtree_root, deleted; | 2980 | int ret, subtree_root, deleted; |
2891 | u32 right_cpos; | 2981 | u32 right_cpos; |
2892 | struct ocfs2_path *left_path = NULL; | 2982 | struct ocfs2_path *left_path = NULL; |
2893 | struct ocfs2_path *right_path = NULL; | 2983 | struct ocfs2_path *right_path = NULL; |
2984 | struct super_block *sb = ocfs2_metadata_cache_get_super(et->et_ci); | ||
2894 | 2985 | ||
2895 | BUG_ON(!ocfs2_is_empty_extent(&(path_leaf_el(path)->l_recs[0]))); | 2986 | BUG_ON(!ocfs2_is_empty_extent(&(path_leaf_el(path)->l_recs[0]))); |
2896 | 2987 | ||
2897 | *empty_extent_path = NULL; | 2988 | *empty_extent_path = NULL; |
2898 | 2989 | ||
2899 | ret = ocfs2_find_cpos_for_right_leaf(inode->i_sb, path, | 2990 | ret = ocfs2_find_cpos_for_right_leaf(sb, path, &right_cpos); |
2900 | &right_cpos); | ||
2901 | if (ret) { | 2991 | if (ret) { |
2902 | mlog_errno(ret); | 2992 | mlog_errno(ret); |
2903 | goto out; | 2993 | goto out; |
@@ -2920,13 +3010,13 @@ static int __ocfs2_rotate_tree_left(struct inode *inode, | |||
2920 | } | 3010 | } |
2921 | 3011 | ||
2922 | while (right_cpos) { | 3012 | while (right_cpos) { |
2923 | ret = ocfs2_find_path(inode, right_path, right_cpos); | 3013 | ret = ocfs2_find_path(et->et_ci, right_path, right_cpos); |
2924 | if (ret) { | 3014 | if (ret) { |
2925 | mlog_errno(ret); | 3015 | mlog_errno(ret); |
2926 | goto out; | 3016 | goto out; |
2927 | } | 3017 | } |
2928 | 3018 | ||
2929 | subtree_root = ocfs2_find_subtree_root(inode, left_path, | 3019 | subtree_root = ocfs2_find_subtree_root(et, left_path, |
2930 | right_path); | 3020 | right_path); |
2931 | 3021 | ||
2932 | mlog(0, "Subtree root at index %d (blk %llu, depth %d)\n", | 3022 | mlog(0, "Subtree root at index %d (blk %llu, depth %d)\n", |
@@ -2946,16 +3036,16 @@ static int __ocfs2_rotate_tree_left(struct inode *inode, | |||
2946 | * Caller might still want to make changes to the | 3036 | * Caller might still want to make changes to the |
2947 | * tree root, so re-add it to the journal here. | 3037 | * tree root, so re-add it to the journal here. |
2948 | */ | 3038 | */ |
2949 | ret = ocfs2_path_bh_journal_access(handle, inode, | 3039 | ret = ocfs2_path_bh_journal_access(handle, et->et_ci, |
2950 | left_path, 0); | 3040 | left_path, 0); |
2951 | if (ret) { | 3041 | if (ret) { |
2952 | mlog_errno(ret); | 3042 | mlog_errno(ret); |
2953 | goto out; | 3043 | goto out; |
2954 | } | 3044 | } |
2955 | 3045 | ||
2956 | ret = ocfs2_rotate_subtree_left(inode, handle, left_path, | 3046 | ret = ocfs2_rotate_subtree_left(handle, et, left_path, |
2957 | right_path, subtree_root, | 3047 | right_path, subtree_root, |
2958 | dealloc, &deleted, et); | 3048 | dealloc, &deleted); |
2959 | if (ret == -EAGAIN) { | 3049 | if (ret == -EAGAIN) { |
2960 | /* | 3050 | /* |
2961 | * The rotation has to temporarily stop due to | 3051 | * The rotation has to temporarily stop due to |
@@ -2982,7 +3072,7 @@ static int __ocfs2_rotate_tree_left(struct inode *inode, | |||
2982 | 3072 | ||
2983 | ocfs2_mv_path(left_path, right_path); | 3073 | ocfs2_mv_path(left_path, right_path); |
2984 | 3074 | ||
2985 | ret = ocfs2_find_cpos_for_right_leaf(inode->i_sb, left_path, | 3075 | ret = ocfs2_find_cpos_for_right_leaf(sb, left_path, |
2986 | &right_cpos); | 3076 | &right_cpos); |
2987 | if (ret) { | 3077 | if (ret) { |
2988 | mlog_errno(ret); | 3078 | mlog_errno(ret); |
@@ -2997,10 +3087,10 @@ out: | |||
2997 | return ret; | 3087 | return ret; |
2998 | } | 3088 | } |
2999 | 3089 | ||
3000 | static int ocfs2_remove_rightmost_path(struct inode *inode, handle_t *handle, | 3090 | static int ocfs2_remove_rightmost_path(handle_t *handle, |
3091 | struct ocfs2_extent_tree *et, | ||
3001 | struct ocfs2_path *path, | 3092 | struct ocfs2_path *path, |
3002 | struct ocfs2_cached_dealloc_ctxt *dealloc, | 3093 | struct ocfs2_cached_dealloc_ctxt *dealloc) |
3003 | struct ocfs2_extent_tree *et) | ||
3004 | { | 3094 | { |
3005 | int ret, subtree_index; | 3095 | int ret, subtree_index; |
3006 | u32 cpos; | 3096 | u32 cpos; |
@@ -3009,7 +3099,7 @@ static int ocfs2_remove_rightmost_path(struct inode *inode, handle_t *handle, | |||
3009 | struct ocfs2_extent_list *el; | 3099 | struct ocfs2_extent_list *el; |
3010 | 3100 | ||
3011 | 3101 | ||
3012 | ret = ocfs2_et_sanity_check(inode, et); | 3102 | ret = ocfs2_et_sanity_check(et); |
3013 | if (ret) | 3103 | if (ret) |
3014 | goto out; | 3104 | goto out; |
3015 | /* | 3105 | /* |
@@ -3024,13 +3114,14 @@ static int ocfs2_remove_rightmost_path(struct inode *inode, handle_t *handle, | |||
3024 | goto out; | 3114 | goto out; |
3025 | } | 3115 | } |
3026 | 3116 | ||
3027 | ret = ocfs2_journal_access_path(inode, handle, path); | 3117 | ret = ocfs2_journal_access_path(et->et_ci, handle, path); |
3028 | if (ret) { | 3118 | if (ret) { |
3029 | mlog_errno(ret); | 3119 | mlog_errno(ret); |
3030 | goto out; | 3120 | goto out; |
3031 | } | 3121 | } |
3032 | 3122 | ||
3033 | ret = ocfs2_find_cpos_for_left_leaf(inode->i_sb, path, &cpos); | 3123 | ret = ocfs2_find_cpos_for_left_leaf(ocfs2_metadata_cache_get_super(et->et_ci), |
3124 | path, &cpos); | ||
3034 | if (ret) { | 3125 | if (ret) { |
3035 | mlog_errno(ret); | 3126 | mlog_errno(ret); |
3036 | goto out; | 3127 | goto out; |
@@ -3048,23 +3139,23 @@ static int ocfs2_remove_rightmost_path(struct inode *inode, handle_t *handle, | |||
3048 | goto out; | 3139 | goto out; |
3049 | } | 3140 | } |
3050 | 3141 | ||
3051 | ret = ocfs2_find_path(inode, left_path, cpos); | 3142 | ret = ocfs2_find_path(et->et_ci, left_path, cpos); |
3052 | if (ret) { | 3143 | if (ret) { |
3053 | mlog_errno(ret); | 3144 | mlog_errno(ret); |
3054 | goto out; | 3145 | goto out; |
3055 | } | 3146 | } |
3056 | 3147 | ||
3057 | ret = ocfs2_journal_access_path(inode, handle, left_path); | 3148 | ret = ocfs2_journal_access_path(et->et_ci, handle, left_path); |
3058 | if (ret) { | 3149 | if (ret) { |
3059 | mlog_errno(ret); | 3150 | mlog_errno(ret); |
3060 | goto out; | 3151 | goto out; |
3061 | } | 3152 | } |
3062 | 3153 | ||
3063 | subtree_index = ocfs2_find_subtree_root(inode, left_path, path); | 3154 | subtree_index = ocfs2_find_subtree_root(et, left_path, path); |
3064 | 3155 | ||
3065 | ocfs2_unlink_subtree(inode, handle, left_path, path, | 3156 | ocfs2_unlink_subtree(handle, et, left_path, path, |
3066 | subtree_index, dealloc); | 3157 | subtree_index, dealloc); |
3067 | ret = ocfs2_update_edge_lengths(inode, handle, subtree_index, | 3158 | ret = ocfs2_update_edge_lengths(handle, et, subtree_index, |
3068 | left_path); | 3159 | left_path); |
3069 | if (ret) { | 3160 | if (ret) { |
3070 | mlog_errno(ret); | 3161 | mlog_errno(ret); |
@@ -3078,10 +3169,10 @@ static int ocfs2_remove_rightmost_path(struct inode *inode, handle_t *handle, | |||
3078 | * 'path' is also the leftmost path which | 3169 | * 'path' is also the leftmost path which |
3079 | * means it must be the only one. This gets | 3170 | * means it must be the only one. This gets |
3080 | * handled differently because we want to | 3171 | * handled differently because we want to |
3081 | * revert the inode back to having extents | 3172 | * revert the root back to having extents |
3082 | * in-line. | 3173 | * in-line. |
3083 | */ | 3174 | */ |
3084 | ocfs2_unlink_path(inode, handle, dealloc, path, 1); | 3175 | ocfs2_unlink_path(handle, et, dealloc, path, 1); |
3085 | 3176 | ||
3086 | el = et->et_root_el; | 3177 | el = et->et_root_el; |
3087 | el->l_tree_depth = 0; | 3178 | el->l_tree_depth = 0; |
@@ -3114,10 +3205,10 @@ out: | |||
3114 | * the rightmost tree leaf record is removed so the caller is | 3205 | * the rightmost tree leaf record is removed so the caller is |
3115 | * responsible for detecting and correcting that. | 3206 | * responsible for detecting and correcting that. |
3116 | */ | 3207 | */ |
3117 | static int ocfs2_rotate_tree_left(struct inode *inode, handle_t *handle, | 3208 | static int ocfs2_rotate_tree_left(handle_t *handle, |
3209 | struct ocfs2_extent_tree *et, | ||
3118 | struct ocfs2_path *path, | 3210 | struct ocfs2_path *path, |
3119 | struct ocfs2_cached_dealloc_ctxt *dealloc, | 3211 | struct ocfs2_cached_dealloc_ctxt *dealloc) |
3120 | struct ocfs2_extent_tree *et) | ||
3121 | { | 3212 | { |
3122 | int ret, orig_credits = handle->h_buffer_credits; | 3213 | int ret, orig_credits = handle->h_buffer_credits; |
3123 | struct ocfs2_path *tmp_path = NULL, *restart_path = NULL; | 3214 | struct ocfs2_path *tmp_path = NULL, *restart_path = NULL; |
@@ -3134,8 +3225,7 @@ rightmost_no_delete: | |||
3134 | * Inline extents. This is trivially handled, so do | 3225 | * Inline extents. This is trivially handled, so do |
3135 | * it up front. | 3226 | * it up front. |
3136 | */ | 3227 | */ |
3137 | ret = ocfs2_rotate_rightmost_leaf_left(inode, handle, | 3228 | ret = ocfs2_rotate_rightmost_leaf_left(handle, et, path); |
3138 | path); | ||
3139 | if (ret) | 3229 | if (ret) |
3140 | mlog_errno(ret); | 3230 | mlog_errno(ret); |
3141 | goto out; | 3231 | goto out; |
@@ -3151,7 +3241,7 @@ rightmost_no_delete: | |||
3151 | * | 3241 | * |
3152 | * 1) is handled via ocfs2_rotate_rightmost_leaf_left() | 3242 | * 1) is handled via ocfs2_rotate_rightmost_leaf_left() |
3153 | * 2a) we need the left branch so that we can update it with the unlink | 3243 | * 2a) we need the left branch so that we can update it with the unlink |
3154 | * 2b) we need to bring the inode back to inline extents. | 3244 | * 2b) we need to bring the root back to inline extents. |
3155 | */ | 3245 | */ |
3156 | 3246 | ||
3157 | eb = (struct ocfs2_extent_block *)path_leaf_bh(path)->b_data; | 3247 | eb = (struct ocfs2_extent_block *)path_leaf_bh(path)->b_data; |
@@ -3167,9 +3257,9 @@ rightmost_no_delete: | |||
3167 | 3257 | ||
3168 | if (le16_to_cpu(el->l_next_free_rec) == 0) { | 3258 | if (le16_to_cpu(el->l_next_free_rec) == 0) { |
3169 | ret = -EIO; | 3259 | ret = -EIO; |
3170 | ocfs2_error(inode->i_sb, | 3260 | ocfs2_error(ocfs2_metadata_cache_get_super(et->et_ci), |
3171 | "Inode %llu has empty extent block at %llu", | 3261 | "Owner %llu has empty extent block at %llu", |
3172 | (unsigned long long)OCFS2_I(inode)->ip_blkno, | 3262 | (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci), |
3173 | (unsigned long long)le64_to_cpu(eb->h_blkno)); | 3263 | (unsigned long long)le64_to_cpu(eb->h_blkno)); |
3174 | goto out; | 3264 | goto out; |
3175 | } | 3265 | } |
@@ -3183,8 +3273,8 @@ rightmost_no_delete: | |||
3183 | * nonempty list. | 3273 | * nonempty list. |
3184 | */ | 3274 | */ |
3185 | 3275 | ||
3186 | ret = ocfs2_remove_rightmost_path(inode, handle, path, | 3276 | ret = ocfs2_remove_rightmost_path(handle, et, path, |
3187 | dealloc, et); | 3277 | dealloc); |
3188 | if (ret) | 3278 | if (ret) |
3189 | mlog_errno(ret); | 3279 | mlog_errno(ret); |
3190 | goto out; | 3280 | goto out; |
@@ -3195,8 +3285,8 @@ rightmost_no_delete: | |||
3195 | * and restarting from there. | 3285 | * and restarting from there. |
3196 | */ | 3286 | */ |
3197 | try_rotate: | 3287 | try_rotate: |
3198 | ret = __ocfs2_rotate_tree_left(inode, handle, orig_credits, path, | 3288 | ret = __ocfs2_rotate_tree_left(handle, et, orig_credits, path, |
3199 | dealloc, &restart_path, et); | 3289 | dealloc, &restart_path); |
3200 | if (ret && ret != -EAGAIN) { | 3290 | if (ret && ret != -EAGAIN) { |
3201 | mlog_errno(ret); | 3291 | mlog_errno(ret); |
3202 | goto out; | 3292 | goto out; |
@@ -3206,9 +3296,9 @@ try_rotate: | |||
3206 | tmp_path = restart_path; | 3296 | tmp_path = restart_path; |
3207 | restart_path = NULL; | 3297 | restart_path = NULL; |
3208 | 3298 | ||
3209 | ret = __ocfs2_rotate_tree_left(inode, handle, orig_credits, | 3299 | ret = __ocfs2_rotate_tree_left(handle, et, orig_credits, |
3210 | tmp_path, dealloc, | 3300 | tmp_path, dealloc, |
3211 | &restart_path, et); | 3301 | &restart_path); |
3212 | if (ret && ret != -EAGAIN) { | 3302 | if (ret && ret != -EAGAIN) { |
3213 | mlog_errno(ret); | 3303 | mlog_errno(ret); |
3214 | goto out; | 3304 | goto out; |
@@ -3259,7 +3349,7 @@ static void ocfs2_cleanup_merge(struct ocfs2_extent_list *el, | |||
3259 | } | 3349 | } |
3260 | } | 3350 | } |
3261 | 3351 | ||
3262 | static int ocfs2_get_right_path(struct inode *inode, | 3352 | static int ocfs2_get_right_path(struct ocfs2_extent_tree *et, |
3263 | struct ocfs2_path *left_path, | 3353 | struct ocfs2_path *left_path, |
3264 | struct ocfs2_path **ret_right_path) | 3354 | struct ocfs2_path **ret_right_path) |
3265 | { | 3355 | { |
@@ -3276,8 +3366,8 @@ static int ocfs2_get_right_path(struct inode *inode, | |||
3276 | left_el = path_leaf_el(left_path); | 3366 | left_el = path_leaf_el(left_path); |
3277 | BUG_ON(left_el->l_next_free_rec != left_el->l_count); | 3367 | BUG_ON(left_el->l_next_free_rec != left_el->l_count); |
3278 | 3368 | ||
3279 | ret = ocfs2_find_cpos_for_right_leaf(inode->i_sb, left_path, | 3369 | ret = ocfs2_find_cpos_for_right_leaf(ocfs2_metadata_cache_get_super(et->et_ci), |
3280 | &right_cpos); | 3370 | left_path, &right_cpos); |
3281 | if (ret) { | 3371 | if (ret) { |
3282 | mlog_errno(ret); | 3372 | mlog_errno(ret); |
3283 | goto out; | 3373 | goto out; |
@@ -3293,7 +3383,7 @@ static int ocfs2_get_right_path(struct inode *inode, | |||
3293 | goto out; | 3383 | goto out; |
3294 | } | 3384 | } |
3295 | 3385 | ||
3296 | ret = ocfs2_find_path(inode, right_path, right_cpos); | 3386 | ret = ocfs2_find_path(et->et_ci, right_path, right_cpos); |
3297 | if (ret) { | 3387 | if (ret) { |
3298 | mlog_errno(ret); | 3388 | mlog_errno(ret); |
3299 | goto out; | 3389 | goto out; |
@@ -3313,9 +3403,9 @@ out: | |||
3313 | * For index == l_count - 1, the "next" means the 1st extent rec of the | 3403 | * For index == l_count - 1, the "next" means the 1st extent rec of the |
3314 | * next extent block. | 3404 | * next extent block. |
3315 | */ | 3405 | */ |
3316 | static int ocfs2_merge_rec_right(struct inode *inode, | 3406 | static int ocfs2_merge_rec_right(struct ocfs2_path *left_path, |
3317 | struct ocfs2_path *left_path, | ||
3318 | handle_t *handle, | 3407 | handle_t *handle, |
3408 | struct ocfs2_extent_tree *et, | ||
3319 | struct ocfs2_extent_rec *split_rec, | 3409 | struct ocfs2_extent_rec *split_rec, |
3320 | int index) | 3410 | int index) |
3321 | { | 3411 | { |
@@ -3336,7 +3426,7 @@ static int ocfs2_merge_rec_right(struct inode *inode, | |||
3336 | if (index == le16_to_cpu(el->l_next_free_rec) - 1 && | 3426 | if (index == le16_to_cpu(el->l_next_free_rec) - 1 && |
3337 | le16_to_cpu(el->l_next_free_rec) == le16_to_cpu(el->l_count)) { | 3427 | le16_to_cpu(el->l_next_free_rec) == le16_to_cpu(el->l_count)) { |
3338 | /* we meet with a cross extent block merge. */ | 3428 | /* we meet with a cross extent block merge. */ |
3339 | ret = ocfs2_get_right_path(inode, left_path, &right_path); | 3429 | ret = ocfs2_get_right_path(et, left_path, &right_path); |
3340 | if (ret) { | 3430 | if (ret) { |
3341 | mlog_errno(ret); | 3431 | mlog_errno(ret); |
3342 | goto out; | 3432 | goto out; |
@@ -3355,8 +3445,8 @@ static int ocfs2_merge_rec_right(struct inode *inode, | |||
3355 | le16_to_cpu(left_rec->e_leaf_clusters) != | 3445 | le16_to_cpu(left_rec->e_leaf_clusters) != |
3356 | le32_to_cpu(right_rec->e_cpos)); | 3446 | le32_to_cpu(right_rec->e_cpos)); |
3357 | 3447 | ||
3358 | subtree_index = ocfs2_find_subtree_root(inode, | 3448 | subtree_index = ocfs2_find_subtree_root(et, left_path, |
3359 | left_path, right_path); | 3449 | right_path); |
3360 | 3450 | ||
3361 | ret = ocfs2_extend_rotate_transaction(handle, subtree_index, | 3451 | ret = ocfs2_extend_rotate_transaction(handle, subtree_index, |
3362 | handle->h_buffer_credits, | 3452 | handle->h_buffer_credits, |
@@ -3369,7 +3459,7 @@ static int ocfs2_merge_rec_right(struct inode *inode, | |||
3369 | root_bh = left_path->p_node[subtree_index].bh; | 3459 | root_bh = left_path->p_node[subtree_index].bh; |
3370 | BUG_ON(root_bh != right_path->p_node[subtree_index].bh); | 3460 | BUG_ON(root_bh != right_path->p_node[subtree_index].bh); |
3371 | 3461 | ||
3372 | ret = ocfs2_path_bh_journal_access(handle, inode, right_path, | 3462 | ret = ocfs2_path_bh_journal_access(handle, et->et_ci, right_path, |
3373 | subtree_index); | 3463 | subtree_index); |
3374 | if (ret) { | 3464 | if (ret) { |
3375 | mlog_errno(ret); | 3465 | mlog_errno(ret); |
@@ -3378,14 +3468,14 @@ static int ocfs2_merge_rec_right(struct inode *inode, | |||
3378 | 3468 | ||
3379 | for (i = subtree_index + 1; | 3469 | for (i = subtree_index + 1; |
3380 | i < path_num_items(right_path); i++) { | 3470 | i < path_num_items(right_path); i++) { |
3381 | ret = ocfs2_path_bh_journal_access(handle, inode, | 3471 | ret = ocfs2_path_bh_journal_access(handle, et->et_ci, |
3382 | right_path, i); | 3472 | right_path, i); |
3383 | if (ret) { | 3473 | if (ret) { |
3384 | mlog_errno(ret); | 3474 | mlog_errno(ret); |
3385 | goto out; | 3475 | goto out; |
3386 | } | 3476 | } |
3387 | 3477 | ||
3388 | ret = ocfs2_path_bh_journal_access(handle, inode, | 3478 | ret = ocfs2_path_bh_journal_access(handle, et->et_ci, |
3389 | left_path, i); | 3479 | left_path, i); |
3390 | if (ret) { | 3480 | if (ret) { |
3391 | mlog_errno(ret); | 3481 | mlog_errno(ret); |
@@ -3398,7 +3488,7 @@ static int ocfs2_merge_rec_right(struct inode *inode, | |||
3398 | right_rec = &el->l_recs[index + 1]; | 3488 | right_rec = &el->l_recs[index + 1]; |
3399 | } | 3489 | } |
3400 | 3490 | ||
3401 | ret = ocfs2_path_bh_journal_access(handle, inode, left_path, | 3491 | ret = ocfs2_path_bh_journal_access(handle, et->et_ci, left_path, |
3402 | path_num_items(left_path) - 1); | 3492 | path_num_items(left_path) - 1); |
3403 | if (ret) { | 3493 | if (ret) { |
3404 | mlog_errno(ret); | 3494 | mlog_errno(ret); |
@@ -3409,7 +3499,8 @@ static int ocfs2_merge_rec_right(struct inode *inode, | |||
3409 | 3499 | ||
3410 | le32_add_cpu(&right_rec->e_cpos, -split_clusters); | 3500 | le32_add_cpu(&right_rec->e_cpos, -split_clusters); |
3411 | le64_add_cpu(&right_rec->e_blkno, | 3501 | le64_add_cpu(&right_rec->e_blkno, |
3412 | -ocfs2_clusters_to_blocks(inode->i_sb, split_clusters)); | 3502 | -ocfs2_clusters_to_blocks(ocfs2_metadata_cache_get_super(et->et_ci), |
3503 | split_clusters)); | ||
3413 | le16_add_cpu(&right_rec->e_leaf_clusters, split_clusters); | 3504 | le16_add_cpu(&right_rec->e_leaf_clusters, split_clusters); |
3414 | 3505 | ||
3415 | ocfs2_cleanup_merge(el, index); | 3506 | ocfs2_cleanup_merge(el, index); |
@@ -3423,8 +3514,8 @@ static int ocfs2_merge_rec_right(struct inode *inode, | |||
3423 | if (ret) | 3514 | if (ret) |
3424 | mlog_errno(ret); | 3515 | mlog_errno(ret); |
3425 | 3516 | ||
3426 | ocfs2_complete_edge_insert(inode, handle, left_path, | 3517 | ocfs2_complete_edge_insert(handle, left_path, right_path, |
3427 | right_path, subtree_index); | 3518 | subtree_index); |
3428 | } | 3519 | } |
3429 | out: | 3520 | out: |
3430 | if (right_path) | 3521 | if (right_path) |
@@ -3432,7 +3523,7 @@ out: | |||
3432 | return ret; | 3523 | return ret; |
3433 | } | 3524 | } |
3434 | 3525 | ||
3435 | static int ocfs2_get_left_path(struct inode *inode, | 3526 | static int ocfs2_get_left_path(struct ocfs2_extent_tree *et, |
3436 | struct ocfs2_path *right_path, | 3527 | struct ocfs2_path *right_path, |
3437 | struct ocfs2_path **ret_left_path) | 3528 | struct ocfs2_path **ret_left_path) |
3438 | { | 3529 | { |
@@ -3445,7 +3536,7 @@ static int ocfs2_get_left_path(struct inode *inode, | |||
3445 | /* This function shouldn't be called for non-trees. */ | 3536 | /* This function shouldn't be called for non-trees. */ |
3446 | BUG_ON(right_path->p_tree_depth == 0); | 3537 | BUG_ON(right_path->p_tree_depth == 0); |
3447 | 3538 | ||
3448 | ret = ocfs2_find_cpos_for_left_leaf(inode->i_sb, | 3539 | ret = ocfs2_find_cpos_for_left_leaf(ocfs2_metadata_cache_get_super(et->et_ci), |
3449 | right_path, &left_cpos); | 3540 | right_path, &left_cpos); |
3450 | if (ret) { | 3541 | if (ret) { |
3451 | mlog_errno(ret); | 3542 | mlog_errno(ret); |
@@ -3462,7 +3553,7 @@ static int ocfs2_get_left_path(struct inode *inode, | |||
3462 | goto out; | 3553 | goto out; |
3463 | } | 3554 | } |
3464 | 3555 | ||
3465 | ret = ocfs2_find_path(inode, left_path, left_cpos); | 3556 | ret = ocfs2_find_path(et->et_ci, left_path, left_cpos); |
3466 | if (ret) { | 3557 | if (ret) { |
3467 | mlog_errno(ret); | 3558 | mlog_errno(ret); |
3468 | goto out; | 3559 | goto out; |
@@ -3485,12 +3576,11 @@ out: | |||
3485 | * remove the rightmost leaf extent block in the right_path and change | 3576 | * remove the rightmost leaf extent block in the right_path and change |
3486 | * the right path to indicate the new rightmost path. | 3577 | * the right path to indicate the new rightmost path. |
3487 | */ | 3578 | */ |
3488 | static int ocfs2_merge_rec_left(struct inode *inode, | 3579 | static int ocfs2_merge_rec_left(struct ocfs2_path *right_path, |
3489 | struct ocfs2_path *right_path, | ||
3490 | handle_t *handle, | 3580 | handle_t *handle, |
3581 | struct ocfs2_extent_tree *et, | ||
3491 | struct ocfs2_extent_rec *split_rec, | 3582 | struct ocfs2_extent_rec *split_rec, |
3492 | struct ocfs2_cached_dealloc_ctxt *dealloc, | 3583 | struct ocfs2_cached_dealloc_ctxt *dealloc, |
3493 | struct ocfs2_extent_tree *et, | ||
3494 | int index) | 3584 | int index) |
3495 | { | 3585 | { |
3496 | int ret, i, subtree_index = 0, has_empty_extent = 0; | 3586 | int ret, i, subtree_index = 0, has_empty_extent = 0; |
@@ -3508,7 +3598,7 @@ static int ocfs2_merge_rec_left(struct inode *inode, | |||
3508 | right_rec = &el->l_recs[index]; | 3598 | right_rec = &el->l_recs[index]; |
3509 | if (index == 0) { | 3599 | if (index == 0) { |
3510 | /* we meet with a cross extent block merge. */ | 3600 | /* we meet with a cross extent block merge. */ |
3511 | ret = ocfs2_get_left_path(inode, right_path, &left_path); | 3601 | ret = ocfs2_get_left_path(et, right_path, &left_path); |
3512 | if (ret) { | 3602 | if (ret) { |
3513 | mlog_errno(ret); | 3603 | mlog_errno(ret); |
3514 | goto out; | 3604 | goto out; |
@@ -3524,8 +3614,8 @@ static int ocfs2_merge_rec_left(struct inode *inode, | |||
3524 | le16_to_cpu(left_rec->e_leaf_clusters) != | 3614 | le16_to_cpu(left_rec->e_leaf_clusters) != |
3525 | le32_to_cpu(split_rec->e_cpos)); | 3615 | le32_to_cpu(split_rec->e_cpos)); |
3526 | 3616 | ||
3527 | subtree_index = ocfs2_find_subtree_root(inode, | 3617 | subtree_index = ocfs2_find_subtree_root(et, left_path, |
3528 | left_path, right_path); | 3618 | right_path); |
3529 | 3619 | ||
3530 | ret = ocfs2_extend_rotate_transaction(handle, subtree_index, | 3620 | ret = ocfs2_extend_rotate_transaction(handle, subtree_index, |
3531 | handle->h_buffer_credits, | 3621 | handle->h_buffer_credits, |
@@ -3538,7 +3628,7 @@ static int ocfs2_merge_rec_left(struct inode *inode, | |||
3538 | root_bh = left_path->p_node[subtree_index].bh; | 3628 | root_bh = left_path->p_node[subtree_index].bh; |
3539 | BUG_ON(root_bh != right_path->p_node[subtree_index].bh); | 3629 | BUG_ON(root_bh != right_path->p_node[subtree_index].bh); |
3540 | 3630 | ||
3541 | ret = ocfs2_path_bh_journal_access(handle, inode, right_path, | 3631 | ret = ocfs2_path_bh_journal_access(handle, et->et_ci, right_path, |
3542 | subtree_index); | 3632 | subtree_index); |
3543 | if (ret) { | 3633 | if (ret) { |
3544 | mlog_errno(ret); | 3634 | mlog_errno(ret); |
@@ -3547,14 +3637,14 @@ static int ocfs2_merge_rec_left(struct inode *inode, | |||
3547 | 3637 | ||
3548 | for (i = subtree_index + 1; | 3638 | for (i = subtree_index + 1; |
3549 | i < path_num_items(right_path); i++) { | 3639 | i < path_num_items(right_path); i++) { |
3550 | ret = ocfs2_path_bh_journal_access(handle, inode, | 3640 | ret = ocfs2_path_bh_journal_access(handle, et->et_ci, |
3551 | right_path, i); | 3641 | right_path, i); |
3552 | if (ret) { | 3642 | if (ret) { |
3553 | mlog_errno(ret); | 3643 | mlog_errno(ret); |
3554 | goto out; | 3644 | goto out; |
3555 | } | 3645 | } |
3556 | 3646 | ||
3557 | ret = ocfs2_path_bh_journal_access(handle, inode, | 3647 | ret = ocfs2_path_bh_journal_access(handle, et->et_ci, |
3558 | left_path, i); | 3648 | left_path, i); |
3559 | if (ret) { | 3649 | if (ret) { |
3560 | mlog_errno(ret); | 3650 | mlog_errno(ret); |
@@ -3567,7 +3657,7 @@ static int ocfs2_merge_rec_left(struct inode *inode, | |||
3567 | has_empty_extent = 1; | 3657 | has_empty_extent = 1; |
3568 | } | 3658 | } |
3569 | 3659 | ||
3570 | ret = ocfs2_path_bh_journal_access(handle, inode, right_path, | 3660 | ret = ocfs2_path_bh_journal_access(handle, et->et_ci, right_path, |
3571 | path_num_items(right_path) - 1); | 3661 | path_num_items(right_path) - 1); |
3572 | if (ret) { | 3662 | if (ret) { |
3573 | mlog_errno(ret); | 3663 | mlog_errno(ret); |
@@ -3586,7 +3676,8 @@ static int ocfs2_merge_rec_left(struct inode *inode, | |||
3586 | 3676 | ||
3587 | le32_add_cpu(&right_rec->e_cpos, split_clusters); | 3677 | le32_add_cpu(&right_rec->e_cpos, split_clusters); |
3588 | le64_add_cpu(&right_rec->e_blkno, | 3678 | le64_add_cpu(&right_rec->e_blkno, |
3589 | ocfs2_clusters_to_blocks(inode->i_sb, split_clusters)); | 3679 | ocfs2_clusters_to_blocks(ocfs2_metadata_cache_get_super(et->et_ci), |
3680 | split_clusters)); | ||
3590 | le16_add_cpu(&right_rec->e_leaf_clusters, -split_clusters); | 3681 | le16_add_cpu(&right_rec->e_leaf_clusters, -split_clusters); |
3591 | 3682 | ||
3592 | ocfs2_cleanup_merge(el, index); | 3683 | ocfs2_cleanup_merge(el, index); |
@@ -3608,9 +3699,9 @@ static int ocfs2_merge_rec_left(struct inode *inode, | |||
3608 | if (le16_to_cpu(right_rec->e_leaf_clusters) == 0 && | 3699 | if (le16_to_cpu(right_rec->e_leaf_clusters) == 0 && |
3609 | le16_to_cpu(el->l_next_free_rec) == 1) { | 3700 | le16_to_cpu(el->l_next_free_rec) == 1) { |
3610 | 3701 | ||
3611 | ret = ocfs2_remove_rightmost_path(inode, handle, | 3702 | ret = ocfs2_remove_rightmost_path(handle, et, |
3612 | right_path, | 3703 | right_path, |
3613 | dealloc, et); | 3704 | dealloc); |
3614 | if (ret) { | 3705 | if (ret) { |
3615 | mlog_errno(ret); | 3706 | mlog_errno(ret); |
3616 | goto out; | 3707 | goto out; |
@@ -3622,7 +3713,7 @@ static int ocfs2_merge_rec_left(struct inode *inode, | |||
3622 | ocfs2_mv_path(right_path, left_path); | 3713 | ocfs2_mv_path(right_path, left_path); |
3623 | left_path = NULL; | 3714 | left_path = NULL; |
3624 | } else | 3715 | } else |
3625 | ocfs2_complete_edge_insert(inode, handle, left_path, | 3716 | ocfs2_complete_edge_insert(handle, left_path, |
3626 | right_path, subtree_index); | 3717 | right_path, subtree_index); |
3627 | } | 3718 | } |
3628 | out: | 3719 | out: |
@@ -3631,15 +3722,13 @@ out: | |||
3631 | return ret; | 3722 | return ret; |
3632 | } | 3723 | } |
3633 | 3724 | ||
3634 | static int ocfs2_try_to_merge_extent(struct inode *inode, | 3725 | static int ocfs2_try_to_merge_extent(handle_t *handle, |
3635 | handle_t *handle, | 3726 | struct ocfs2_extent_tree *et, |
3636 | struct ocfs2_path *path, | 3727 | struct ocfs2_path *path, |
3637 | int split_index, | 3728 | int split_index, |
3638 | struct ocfs2_extent_rec *split_rec, | 3729 | struct ocfs2_extent_rec *split_rec, |
3639 | struct ocfs2_cached_dealloc_ctxt *dealloc, | 3730 | struct ocfs2_cached_dealloc_ctxt *dealloc, |
3640 | struct ocfs2_merge_ctxt *ctxt, | 3731 | struct ocfs2_merge_ctxt *ctxt) |
3641 | struct ocfs2_extent_tree *et) | ||
3642 | |||
3643 | { | 3732 | { |
3644 | int ret = 0; | 3733 | int ret = 0; |
3645 | struct ocfs2_extent_list *el = path_leaf_el(path); | 3734 | struct ocfs2_extent_list *el = path_leaf_el(path); |
@@ -3655,8 +3744,7 @@ static int ocfs2_try_to_merge_extent(struct inode *inode, | |||
3655 | * extents - having more than one in a leaf is | 3744 | * extents - having more than one in a leaf is |
3656 | * illegal. | 3745 | * illegal. |
3657 | */ | 3746 | */ |
3658 | ret = ocfs2_rotate_tree_left(inode, handle, path, | 3747 | ret = ocfs2_rotate_tree_left(handle, et, path, dealloc); |
3659 | dealloc, et); | ||
3660 | if (ret) { | 3748 | if (ret) { |
3661 | mlog_errno(ret); | 3749 | mlog_errno(ret); |
3662 | goto out; | 3750 | goto out; |
@@ -3685,8 +3773,7 @@ static int ocfs2_try_to_merge_extent(struct inode *inode, | |||
3685 | * prevoius extent block. It is more efficient and easier | 3773 | * prevoius extent block. It is more efficient and easier |
3686 | * if we do merge_right first and merge_left later. | 3774 | * if we do merge_right first and merge_left later. |
3687 | */ | 3775 | */ |
3688 | ret = ocfs2_merge_rec_right(inode, path, | 3776 | ret = ocfs2_merge_rec_right(path, handle, et, split_rec, |
3689 | handle, split_rec, | ||
3690 | split_index); | 3777 | split_index); |
3691 | if (ret) { | 3778 | if (ret) { |
3692 | mlog_errno(ret); | 3779 | mlog_errno(ret); |
@@ -3699,8 +3786,7 @@ static int ocfs2_try_to_merge_extent(struct inode *inode, | |||
3699 | BUG_ON(!ocfs2_is_empty_extent(&el->l_recs[0])); | 3786 | BUG_ON(!ocfs2_is_empty_extent(&el->l_recs[0])); |
3700 | 3787 | ||
3701 | /* The merge left us with an empty extent, remove it. */ | 3788 | /* The merge left us with an empty extent, remove it. */ |
3702 | ret = ocfs2_rotate_tree_left(inode, handle, path, | 3789 | ret = ocfs2_rotate_tree_left(handle, et, path, dealloc); |
3703 | dealloc, et); | ||
3704 | if (ret) { | 3790 | if (ret) { |
3705 | mlog_errno(ret); | 3791 | mlog_errno(ret); |
3706 | goto out; | 3792 | goto out; |
@@ -3712,18 +3798,15 @@ static int ocfs2_try_to_merge_extent(struct inode *inode, | |||
3712 | * Note that we don't pass split_rec here on purpose - | 3798 | * Note that we don't pass split_rec here on purpose - |
3713 | * we've merged it into the rec already. | 3799 | * we've merged it into the rec already. |
3714 | */ | 3800 | */ |
3715 | ret = ocfs2_merge_rec_left(inode, path, | 3801 | ret = ocfs2_merge_rec_left(path, handle, et, rec, |
3716 | handle, rec, | 3802 | dealloc, split_index); |
3717 | dealloc, et, | ||
3718 | split_index); | ||
3719 | 3803 | ||
3720 | if (ret) { | 3804 | if (ret) { |
3721 | mlog_errno(ret); | 3805 | mlog_errno(ret); |
3722 | goto out; | 3806 | goto out; |
3723 | } | 3807 | } |
3724 | 3808 | ||
3725 | ret = ocfs2_rotate_tree_left(inode, handle, path, | 3809 | ret = ocfs2_rotate_tree_left(handle, et, path, dealloc); |
3726 | dealloc, et); | ||
3727 | /* | 3810 | /* |
3728 | * Error from this last rotate is not critical, so | 3811 | * Error from this last rotate is not critical, so |
3729 | * print but don't bubble it up. | 3812 | * print but don't bubble it up. |
@@ -3740,19 +3823,16 @@ static int ocfs2_try_to_merge_extent(struct inode *inode, | |||
3740 | * the record on the left (hence the left merge). | 3823 | * the record on the left (hence the left merge). |
3741 | */ | 3824 | */ |
3742 | if (ctxt->c_contig_type == CONTIG_RIGHT) { | 3825 | if (ctxt->c_contig_type == CONTIG_RIGHT) { |
3743 | ret = ocfs2_merge_rec_left(inode, | 3826 | ret = ocfs2_merge_rec_left(path, handle, et, |
3744 | path, | 3827 | split_rec, dealloc, |
3745 | handle, split_rec, | ||
3746 | dealloc, et, | ||
3747 | split_index); | 3828 | split_index); |
3748 | if (ret) { | 3829 | if (ret) { |
3749 | mlog_errno(ret); | 3830 | mlog_errno(ret); |
3750 | goto out; | 3831 | goto out; |
3751 | } | 3832 | } |
3752 | } else { | 3833 | } else { |
3753 | ret = ocfs2_merge_rec_right(inode, | 3834 | ret = ocfs2_merge_rec_right(path, handle, |
3754 | path, | 3835 | et, split_rec, |
3755 | handle, split_rec, | ||
3756 | split_index); | 3836 | split_index); |
3757 | if (ret) { | 3837 | if (ret) { |
3758 | mlog_errno(ret); | 3838 | mlog_errno(ret); |
@@ -3765,8 +3845,8 @@ static int ocfs2_try_to_merge_extent(struct inode *inode, | |||
3765 | * The merge may have left an empty extent in | 3845 | * The merge may have left an empty extent in |
3766 | * our leaf. Try to rotate it away. | 3846 | * our leaf. Try to rotate it away. |
3767 | */ | 3847 | */ |
3768 | ret = ocfs2_rotate_tree_left(inode, handle, path, | 3848 | ret = ocfs2_rotate_tree_left(handle, et, path, |
3769 | dealloc, et); | 3849 | dealloc); |
3770 | if (ret) | 3850 | if (ret) |
3771 | mlog_errno(ret); | 3851 | mlog_errno(ret); |
3772 | ret = 0; | 3852 | ret = 0; |
@@ -3812,10 +3892,10 @@ static void ocfs2_subtract_from_rec(struct super_block *sb, | |||
3812 | * list. If this leaf is part of an allocation tree, it is assumed | 3892 | * list. If this leaf is part of an allocation tree, it is assumed |
3813 | * that the tree above has been prepared. | 3893 | * that the tree above has been prepared. |
3814 | */ | 3894 | */ |
3815 | static void ocfs2_insert_at_leaf(struct ocfs2_extent_rec *insert_rec, | 3895 | static void ocfs2_insert_at_leaf(struct ocfs2_extent_tree *et, |
3896 | struct ocfs2_extent_rec *insert_rec, | ||
3816 | struct ocfs2_extent_list *el, | 3897 | struct ocfs2_extent_list *el, |
3817 | struct ocfs2_insert_type *insert, | 3898 | struct ocfs2_insert_type *insert) |
3818 | struct inode *inode) | ||
3819 | { | 3899 | { |
3820 | int i = insert->ins_contig_index; | 3900 | int i = insert->ins_contig_index; |
3821 | unsigned int range; | 3901 | unsigned int range; |
@@ -3827,7 +3907,8 @@ static void ocfs2_insert_at_leaf(struct ocfs2_extent_rec *insert_rec, | |||
3827 | i = ocfs2_search_extent_list(el, le32_to_cpu(insert_rec->e_cpos)); | 3907 | i = ocfs2_search_extent_list(el, le32_to_cpu(insert_rec->e_cpos)); |
3828 | BUG_ON(i == -1); | 3908 | BUG_ON(i == -1); |
3829 | rec = &el->l_recs[i]; | 3909 | rec = &el->l_recs[i]; |
3830 | ocfs2_subtract_from_rec(inode->i_sb, insert->ins_split, rec, | 3910 | ocfs2_subtract_from_rec(ocfs2_metadata_cache_get_super(et->et_ci), |
3911 | insert->ins_split, rec, | ||
3831 | insert_rec); | 3912 | insert_rec); |
3832 | goto rotate; | 3913 | goto rotate; |
3833 | } | 3914 | } |
@@ -3869,10 +3950,10 @@ static void ocfs2_insert_at_leaf(struct ocfs2_extent_rec *insert_rec, | |||
3869 | 3950 | ||
3870 | mlog_bug_on_msg(le16_to_cpu(el->l_next_free_rec) >= | 3951 | mlog_bug_on_msg(le16_to_cpu(el->l_next_free_rec) >= |
3871 | le16_to_cpu(el->l_count), | 3952 | le16_to_cpu(el->l_count), |
3872 | "inode %lu, depth %u, count %u, next free %u, " | 3953 | "owner %llu, depth %u, count %u, next free %u, " |
3873 | "rec.cpos %u, rec.clusters %u, " | 3954 | "rec.cpos %u, rec.clusters %u, " |
3874 | "insert.cpos %u, insert.clusters %u\n", | 3955 | "insert.cpos %u, insert.clusters %u\n", |
3875 | inode->i_ino, | 3956 | ocfs2_metadata_cache_owner(et->et_ci), |
3876 | le16_to_cpu(el->l_tree_depth), | 3957 | le16_to_cpu(el->l_tree_depth), |
3877 | le16_to_cpu(el->l_count), | 3958 | le16_to_cpu(el->l_count), |
3878 | le16_to_cpu(el->l_next_free_rec), | 3959 | le16_to_cpu(el->l_next_free_rec), |
@@ -3900,8 +3981,8 @@ rotate: | |||
3900 | ocfs2_rotate_leaf(el, insert_rec); | 3981 | ocfs2_rotate_leaf(el, insert_rec); |
3901 | } | 3982 | } |
3902 | 3983 | ||
3903 | static void ocfs2_adjust_rightmost_records(struct inode *inode, | 3984 | static void ocfs2_adjust_rightmost_records(handle_t *handle, |
3904 | handle_t *handle, | 3985 | struct ocfs2_extent_tree *et, |
3905 | struct ocfs2_path *path, | 3986 | struct ocfs2_path *path, |
3906 | struct ocfs2_extent_rec *insert_rec) | 3987 | struct ocfs2_extent_rec *insert_rec) |
3907 | { | 3988 | { |
@@ -3919,9 +4000,9 @@ static void ocfs2_adjust_rightmost_records(struct inode *inode, | |||
3919 | 4000 | ||
3920 | next_free = le16_to_cpu(el->l_next_free_rec); | 4001 | next_free = le16_to_cpu(el->l_next_free_rec); |
3921 | if (next_free == 0) { | 4002 | if (next_free == 0) { |
3922 | ocfs2_error(inode->i_sb, | 4003 | ocfs2_error(ocfs2_metadata_cache_get_super(et->et_ci), |
3923 | "Dinode %llu has a bad extent list", | 4004 | "Owner %llu has a bad extent list", |
3924 | (unsigned long long)OCFS2_I(inode)->ip_blkno); | 4005 | (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci)); |
3925 | ret = -EIO; | 4006 | ret = -EIO; |
3926 | return; | 4007 | return; |
3927 | } | 4008 | } |
@@ -3941,7 +4022,8 @@ static void ocfs2_adjust_rightmost_records(struct inode *inode, | |||
3941 | } | 4022 | } |
3942 | } | 4023 | } |
3943 | 4024 | ||
3944 | static int ocfs2_append_rec_to_path(struct inode *inode, handle_t *handle, | 4025 | static int ocfs2_append_rec_to_path(handle_t *handle, |
4026 | struct ocfs2_extent_tree *et, | ||
3945 | struct ocfs2_extent_rec *insert_rec, | 4027 | struct ocfs2_extent_rec *insert_rec, |
3946 | struct ocfs2_path *right_path, | 4028 | struct ocfs2_path *right_path, |
3947 | struct ocfs2_path **ret_left_path) | 4029 | struct ocfs2_path **ret_left_path) |
@@ -3969,8 +4051,8 @@ static int ocfs2_append_rec_to_path(struct inode *inode, handle_t *handle, | |||
3969 | (next_free == 1 && ocfs2_is_empty_extent(&el->l_recs[0]))) { | 4051 | (next_free == 1 && ocfs2_is_empty_extent(&el->l_recs[0]))) { |
3970 | u32 left_cpos; | 4052 | u32 left_cpos; |
3971 | 4053 | ||
3972 | ret = ocfs2_find_cpos_for_left_leaf(inode->i_sb, right_path, | 4054 | ret = ocfs2_find_cpos_for_left_leaf(ocfs2_metadata_cache_get_super(et->et_ci), |
3973 | &left_cpos); | 4055 | right_path, &left_cpos); |
3974 | if (ret) { | 4056 | if (ret) { |
3975 | mlog_errno(ret); | 4057 | mlog_errno(ret); |
3976 | goto out; | 4058 | goto out; |
@@ -3992,7 +4074,8 @@ static int ocfs2_append_rec_to_path(struct inode *inode, handle_t *handle, | |||
3992 | goto out; | 4074 | goto out; |
3993 | } | 4075 | } |
3994 | 4076 | ||
3995 | ret = ocfs2_find_path(inode, left_path, left_cpos); | 4077 | ret = ocfs2_find_path(et->et_ci, left_path, |
4078 | left_cpos); | ||
3996 | if (ret) { | 4079 | if (ret) { |
3997 | mlog_errno(ret); | 4080 | mlog_errno(ret); |
3998 | goto out; | 4081 | goto out; |
@@ -4005,13 +4088,13 @@ static int ocfs2_append_rec_to_path(struct inode *inode, handle_t *handle, | |||
4005 | } | 4088 | } |
4006 | } | 4089 | } |
4007 | 4090 | ||
4008 | ret = ocfs2_journal_access_path(inode, handle, right_path); | 4091 | ret = ocfs2_journal_access_path(et->et_ci, handle, right_path); |
4009 | if (ret) { | 4092 | if (ret) { |
4010 | mlog_errno(ret); | 4093 | mlog_errno(ret); |
4011 | goto out; | 4094 | goto out; |
4012 | } | 4095 | } |
4013 | 4096 | ||
4014 | ocfs2_adjust_rightmost_records(inode, handle, right_path, insert_rec); | 4097 | ocfs2_adjust_rightmost_records(handle, et, right_path, insert_rec); |
4015 | 4098 | ||
4016 | *ret_left_path = left_path; | 4099 | *ret_left_path = left_path; |
4017 | ret = 0; | 4100 | ret = 0; |
@@ -4022,7 +4105,7 @@ out: | |||
4022 | return ret; | 4105 | return ret; |
4023 | } | 4106 | } |
4024 | 4107 | ||
4025 | static void ocfs2_split_record(struct inode *inode, | 4108 | static void ocfs2_split_record(struct ocfs2_extent_tree *et, |
4026 | struct ocfs2_path *left_path, | 4109 | struct ocfs2_path *left_path, |
4027 | struct ocfs2_path *right_path, | 4110 | struct ocfs2_path *right_path, |
4028 | struct ocfs2_extent_rec *split_rec, | 4111 | struct ocfs2_extent_rec *split_rec, |
@@ -4095,7 +4178,8 @@ static void ocfs2_split_record(struct inode *inode, | |||
4095 | } | 4178 | } |
4096 | 4179 | ||
4097 | rec = &el->l_recs[index]; | 4180 | rec = &el->l_recs[index]; |
4098 | ocfs2_subtract_from_rec(inode->i_sb, split, rec, split_rec); | 4181 | ocfs2_subtract_from_rec(ocfs2_metadata_cache_get_super(et->et_ci), |
4182 | split, rec, split_rec); | ||
4099 | ocfs2_rotate_leaf(insert_el, split_rec); | 4183 | ocfs2_rotate_leaf(insert_el, split_rec); |
4100 | } | 4184 | } |
4101 | 4185 | ||
@@ -4107,8 +4191,8 @@ static void ocfs2_split_record(struct inode *inode, | |||
4107 | * in. left_path should only be passed in if we need to update that | 4191 | * in. left_path should only be passed in if we need to update that |
4108 | * portion of the tree after an edge insert. | 4192 | * portion of the tree after an edge insert. |
4109 | */ | 4193 | */ |
4110 | static int ocfs2_insert_path(struct inode *inode, | 4194 | static int ocfs2_insert_path(handle_t *handle, |
4111 | handle_t *handle, | 4195 | struct ocfs2_extent_tree *et, |
4112 | struct ocfs2_path *left_path, | 4196 | struct ocfs2_path *left_path, |
4113 | struct ocfs2_path *right_path, | 4197 | struct ocfs2_path *right_path, |
4114 | struct ocfs2_extent_rec *insert_rec, | 4198 | struct ocfs2_extent_rec *insert_rec, |
@@ -4134,7 +4218,7 @@ static int ocfs2_insert_path(struct inode *inode, | |||
4134 | goto out; | 4218 | goto out; |
4135 | } | 4219 | } |
4136 | 4220 | ||
4137 | ret = ocfs2_journal_access_path(inode, handle, left_path); | 4221 | ret = ocfs2_journal_access_path(et->et_ci, handle, left_path); |
4138 | if (ret < 0) { | 4222 | if (ret < 0) { |
4139 | mlog_errno(ret); | 4223 | mlog_errno(ret); |
4140 | goto out; | 4224 | goto out; |
@@ -4145,7 +4229,7 @@ static int ocfs2_insert_path(struct inode *inode, | |||
4145 | * Pass both paths to the journal. The majority of inserts | 4229 | * Pass both paths to the journal. The majority of inserts |
4146 | * will be touching all components anyway. | 4230 | * will be touching all components anyway. |
4147 | */ | 4231 | */ |
4148 | ret = ocfs2_journal_access_path(inode, handle, right_path); | 4232 | ret = ocfs2_journal_access_path(et->et_ci, handle, right_path); |
4149 | if (ret < 0) { | 4233 | if (ret < 0) { |
4150 | mlog_errno(ret); | 4234 | mlog_errno(ret); |
4151 | goto out; | 4235 | goto out; |
@@ -4157,7 +4241,7 @@ static int ocfs2_insert_path(struct inode *inode, | |||
4157 | * of splits, but it's easier to just let one separate | 4241 | * of splits, but it's easier to just let one separate |
4158 | * function sort it all out. | 4242 | * function sort it all out. |
4159 | */ | 4243 | */ |
4160 | ocfs2_split_record(inode, left_path, right_path, | 4244 | ocfs2_split_record(et, left_path, right_path, |
4161 | insert_rec, insert->ins_split); | 4245 | insert_rec, insert->ins_split); |
4162 | 4246 | ||
4163 | /* | 4247 | /* |
@@ -4171,8 +4255,8 @@ static int ocfs2_insert_path(struct inode *inode, | |||
4171 | if (ret) | 4255 | if (ret) |
4172 | mlog_errno(ret); | 4256 | mlog_errno(ret); |
4173 | } else | 4257 | } else |
4174 | ocfs2_insert_at_leaf(insert_rec, path_leaf_el(right_path), | 4258 | ocfs2_insert_at_leaf(et, insert_rec, path_leaf_el(right_path), |
4175 | insert, inode); | 4259 | insert); |
4176 | 4260 | ||
4177 | ret = ocfs2_journal_dirty(handle, leaf_bh); | 4261 | ret = ocfs2_journal_dirty(handle, leaf_bh); |
4178 | if (ret) | 4262 | if (ret) |
@@ -4185,10 +4269,10 @@ static int ocfs2_insert_path(struct inode *inode, | |||
4185 | * | 4269 | * |
4186 | * XXX: Should we extend the transaction here? | 4270 | * XXX: Should we extend the transaction here? |
4187 | */ | 4271 | */ |
4188 | subtree_index = ocfs2_find_subtree_root(inode, left_path, | 4272 | subtree_index = ocfs2_find_subtree_root(et, left_path, |
4189 | right_path); | 4273 | right_path); |
4190 | ocfs2_complete_edge_insert(inode, handle, left_path, | 4274 | ocfs2_complete_edge_insert(handle, left_path, right_path, |
4191 | right_path, subtree_index); | 4275 | subtree_index); |
4192 | } | 4276 | } |
4193 | 4277 | ||
4194 | ret = 0; | 4278 | ret = 0; |
@@ -4196,8 +4280,7 @@ out: | |||
4196 | return ret; | 4280 | return ret; |
4197 | } | 4281 | } |
4198 | 4282 | ||
4199 | static int ocfs2_do_insert_extent(struct inode *inode, | 4283 | static int ocfs2_do_insert_extent(handle_t *handle, |
4200 | handle_t *handle, | ||
4201 | struct ocfs2_extent_tree *et, | 4284 | struct ocfs2_extent_tree *et, |
4202 | struct ocfs2_extent_rec *insert_rec, | 4285 | struct ocfs2_extent_rec *insert_rec, |
4203 | struct ocfs2_insert_type *type) | 4286 | struct ocfs2_insert_type *type) |
@@ -4210,7 +4293,7 @@ static int ocfs2_do_insert_extent(struct inode *inode, | |||
4210 | 4293 | ||
4211 | el = et->et_root_el; | 4294 | el = et->et_root_el; |
4212 | 4295 | ||
4213 | ret = ocfs2_et_root_journal_access(handle, inode, et, | 4296 | ret = ocfs2_et_root_journal_access(handle, et, |
4214 | OCFS2_JOURNAL_ACCESS_WRITE); | 4297 | OCFS2_JOURNAL_ACCESS_WRITE); |
4215 | if (ret) { | 4298 | if (ret) { |
4216 | mlog_errno(ret); | 4299 | mlog_errno(ret); |
@@ -4218,7 +4301,7 @@ static int ocfs2_do_insert_extent(struct inode *inode, | |||
4218 | } | 4301 | } |
4219 | 4302 | ||
4220 | if (le16_to_cpu(el->l_tree_depth) == 0) { | 4303 | if (le16_to_cpu(el->l_tree_depth) == 0) { |
4221 | ocfs2_insert_at_leaf(insert_rec, el, type, inode); | 4304 | ocfs2_insert_at_leaf(et, insert_rec, el, type); |
4222 | goto out_update_clusters; | 4305 | goto out_update_clusters; |
4223 | } | 4306 | } |
4224 | 4307 | ||
@@ -4241,7 +4324,7 @@ static int ocfs2_do_insert_extent(struct inode *inode, | |||
4241 | cpos = UINT_MAX; | 4324 | cpos = UINT_MAX; |
4242 | } | 4325 | } |
4243 | 4326 | ||
4244 | ret = ocfs2_find_path(inode, right_path, cpos); | 4327 | ret = ocfs2_find_path(et->et_ci, right_path, cpos); |
4245 | if (ret) { | 4328 | if (ret) { |
4246 | mlog_errno(ret); | 4329 | mlog_errno(ret); |
4247 | goto out; | 4330 | goto out; |
@@ -4260,7 +4343,7 @@ static int ocfs2_do_insert_extent(struct inode *inode, | |||
4260 | * can wind up skipping both of these two special cases... | 4343 | * can wind up skipping both of these two special cases... |
4261 | */ | 4344 | */ |
4262 | if (rotate) { | 4345 | if (rotate) { |
4263 | ret = ocfs2_rotate_tree_right(inode, handle, type->ins_split, | 4346 | ret = ocfs2_rotate_tree_right(handle, et, type->ins_split, |
4264 | le32_to_cpu(insert_rec->e_cpos), | 4347 | le32_to_cpu(insert_rec->e_cpos), |
4265 | right_path, &left_path); | 4348 | right_path, &left_path); |
4266 | if (ret) { | 4349 | if (ret) { |
@@ -4272,7 +4355,7 @@ static int ocfs2_do_insert_extent(struct inode *inode, | |||
4272 | * ocfs2_rotate_tree_right() might have extended the | 4355 | * ocfs2_rotate_tree_right() might have extended the |
4273 | * transaction without re-journaling our tree root. | 4356 | * transaction without re-journaling our tree root. |
4274 | */ | 4357 | */ |
4275 | ret = ocfs2_et_root_journal_access(handle, inode, et, | 4358 | ret = ocfs2_et_root_journal_access(handle, et, |
4276 | OCFS2_JOURNAL_ACCESS_WRITE); | 4359 | OCFS2_JOURNAL_ACCESS_WRITE); |
4277 | if (ret) { | 4360 | if (ret) { |
4278 | mlog_errno(ret); | 4361 | mlog_errno(ret); |
@@ -4280,7 +4363,7 @@ static int ocfs2_do_insert_extent(struct inode *inode, | |||
4280 | } | 4363 | } |
4281 | } else if (type->ins_appending == APPEND_TAIL | 4364 | } else if (type->ins_appending == APPEND_TAIL |
4282 | && type->ins_contig != CONTIG_LEFT) { | 4365 | && type->ins_contig != CONTIG_LEFT) { |
4283 | ret = ocfs2_append_rec_to_path(inode, handle, insert_rec, | 4366 | ret = ocfs2_append_rec_to_path(handle, et, insert_rec, |
4284 | right_path, &left_path); | 4367 | right_path, &left_path); |
4285 | if (ret) { | 4368 | if (ret) { |
4286 | mlog_errno(ret); | 4369 | mlog_errno(ret); |
@@ -4288,7 +4371,7 @@ static int ocfs2_do_insert_extent(struct inode *inode, | |||
4288 | } | 4371 | } |
4289 | } | 4372 | } |
4290 | 4373 | ||
4291 | ret = ocfs2_insert_path(inode, handle, left_path, right_path, | 4374 | ret = ocfs2_insert_path(handle, et, left_path, right_path, |
4292 | insert_rec, type); | 4375 | insert_rec, type); |
4293 | if (ret) { | 4376 | if (ret) { |
4294 | mlog_errno(ret); | 4377 | mlog_errno(ret); |
@@ -4297,7 +4380,7 @@ static int ocfs2_do_insert_extent(struct inode *inode, | |||
4297 | 4380 | ||
4298 | out_update_clusters: | 4381 | out_update_clusters: |
4299 | if (type->ins_split == SPLIT_NONE) | 4382 | if (type->ins_split == SPLIT_NONE) |
4300 | ocfs2_et_update_clusters(inode, et, | 4383 | ocfs2_et_update_clusters(et, |
4301 | le16_to_cpu(insert_rec->e_leaf_clusters)); | 4384 | le16_to_cpu(insert_rec->e_leaf_clusters)); |
4302 | 4385 | ||
4303 | ret = ocfs2_journal_dirty(handle, et->et_root_bh); | 4386 | ret = ocfs2_journal_dirty(handle, et->et_root_bh); |
@@ -4312,7 +4395,8 @@ out: | |||
4312 | } | 4395 | } |
4313 | 4396 | ||
4314 | static enum ocfs2_contig_type | 4397 | static enum ocfs2_contig_type |
4315 | ocfs2_figure_merge_contig_type(struct inode *inode, struct ocfs2_path *path, | 4398 | ocfs2_figure_merge_contig_type(struct ocfs2_extent_tree *et, |
4399 | struct ocfs2_path *path, | ||
4316 | struct ocfs2_extent_list *el, int index, | 4400 | struct ocfs2_extent_list *el, int index, |
4317 | struct ocfs2_extent_rec *split_rec) | 4401 | struct ocfs2_extent_rec *split_rec) |
4318 | { | 4402 | { |
@@ -4324,12 +4408,12 @@ ocfs2_figure_merge_contig_type(struct inode *inode, struct ocfs2_path *path, | |||
4324 | struct ocfs2_path *left_path = NULL, *right_path = NULL; | 4408 | struct ocfs2_path *left_path = NULL, *right_path = NULL; |
4325 | struct buffer_head *bh; | 4409 | struct buffer_head *bh; |
4326 | struct ocfs2_extent_block *eb; | 4410 | struct ocfs2_extent_block *eb; |
4411 | struct super_block *sb = ocfs2_metadata_cache_get_super(et->et_ci); | ||
4327 | 4412 | ||
4328 | if (index > 0) { | 4413 | if (index > 0) { |
4329 | rec = &el->l_recs[index - 1]; | 4414 | rec = &el->l_recs[index - 1]; |
4330 | } else if (path->p_tree_depth > 0) { | 4415 | } else if (path->p_tree_depth > 0) { |
4331 | status = ocfs2_find_cpos_for_left_leaf(inode->i_sb, | 4416 | status = ocfs2_find_cpos_for_left_leaf(sb, path, &left_cpos); |
4332 | path, &left_cpos); | ||
4333 | if (status) | 4417 | if (status) |
4334 | goto out; | 4418 | goto out; |
4335 | 4419 | ||
@@ -4338,7 +4422,8 @@ ocfs2_figure_merge_contig_type(struct inode *inode, struct ocfs2_path *path, | |||
4338 | if (!left_path) | 4422 | if (!left_path) |
4339 | goto out; | 4423 | goto out; |
4340 | 4424 | ||
4341 | status = ocfs2_find_path(inode, left_path, left_cpos); | 4425 | status = ocfs2_find_path(et->et_ci, left_path, |
4426 | left_cpos); | ||
4342 | if (status) | 4427 | if (status) |
4343 | goto out; | 4428 | goto out; |
4344 | 4429 | ||
@@ -4348,7 +4433,7 @@ ocfs2_figure_merge_contig_type(struct inode *inode, struct ocfs2_path *path, | |||
4348 | le16_to_cpu(new_el->l_count)) { | 4433 | le16_to_cpu(new_el->l_count)) { |
4349 | bh = path_leaf_bh(left_path); | 4434 | bh = path_leaf_bh(left_path); |
4350 | eb = (struct ocfs2_extent_block *)bh->b_data; | 4435 | eb = (struct ocfs2_extent_block *)bh->b_data; |
4351 | ocfs2_error(inode->i_sb, | 4436 | ocfs2_error(sb, |
4352 | "Extent block #%llu has an " | 4437 | "Extent block #%llu has an " |
4353 | "invalid l_next_free_rec of " | 4438 | "invalid l_next_free_rec of " |
4354 | "%d. It should have " | 4439 | "%d. It should have " |
@@ -4373,7 +4458,7 @@ ocfs2_figure_merge_contig_type(struct inode *inode, struct ocfs2_path *path, | |||
4373 | if (split_rec->e_cpos == el->l_recs[index].e_cpos) | 4458 | if (split_rec->e_cpos == el->l_recs[index].e_cpos) |
4374 | ret = CONTIG_RIGHT; | 4459 | ret = CONTIG_RIGHT; |
4375 | } else { | 4460 | } else { |
4376 | ret = ocfs2_extent_contig(inode, rec, split_rec); | 4461 | ret = ocfs2_et_extent_contig(et, rec, split_rec); |
4377 | } | 4462 | } |
4378 | } | 4463 | } |
4379 | 4464 | ||
@@ -4382,8 +4467,7 @@ ocfs2_figure_merge_contig_type(struct inode *inode, struct ocfs2_path *path, | |||
4382 | rec = &el->l_recs[index + 1]; | 4467 | rec = &el->l_recs[index + 1]; |
4383 | else if (le16_to_cpu(el->l_next_free_rec) == le16_to_cpu(el->l_count) && | 4468 | else if (le16_to_cpu(el->l_next_free_rec) == le16_to_cpu(el->l_count) && |
4384 | path->p_tree_depth > 0) { | 4469 | path->p_tree_depth > 0) { |
4385 | status = ocfs2_find_cpos_for_right_leaf(inode->i_sb, | 4470 | status = ocfs2_find_cpos_for_right_leaf(sb, path, &right_cpos); |
4386 | path, &right_cpos); | ||
4387 | if (status) | 4471 | if (status) |
4388 | goto out; | 4472 | goto out; |
4389 | 4473 | ||
@@ -4394,7 +4478,7 @@ ocfs2_figure_merge_contig_type(struct inode *inode, struct ocfs2_path *path, | |||
4394 | if (!right_path) | 4478 | if (!right_path) |
4395 | goto out; | 4479 | goto out; |
4396 | 4480 | ||
4397 | status = ocfs2_find_path(inode, right_path, right_cpos); | 4481 | status = ocfs2_find_path(et->et_ci, right_path, right_cpos); |
4398 | if (status) | 4482 | if (status) |
4399 | goto out; | 4483 | goto out; |
4400 | 4484 | ||
@@ -4404,7 +4488,7 @@ ocfs2_figure_merge_contig_type(struct inode *inode, struct ocfs2_path *path, | |||
4404 | if (le16_to_cpu(new_el->l_next_free_rec) <= 1) { | 4488 | if (le16_to_cpu(new_el->l_next_free_rec) <= 1) { |
4405 | bh = path_leaf_bh(right_path); | 4489 | bh = path_leaf_bh(right_path); |
4406 | eb = (struct ocfs2_extent_block *)bh->b_data; | 4490 | eb = (struct ocfs2_extent_block *)bh->b_data; |
4407 | ocfs2_error(inode->i_sb, | 4491 | ocfs2_error(sb, |
4408 | "Extent block #%llu has an " | 4492 | "Extent block #%llu has an " |
4409 | "invalid l_next_free_rec of %d", | 4493 | "invalid l_next_free_rec of %d", |
4410 | (unsigned long long)le64_to_cpu(eb->h_blkno), | 4494 | (unsigned long long)le64_to_cpu(eb->h_blkno), |
@@ -4419,7 +4503,7 @@ ocfs2_figure_merge_contig_type(struct inode *inode, struct ocfs2_path *path, | |||
4419 | if (rec) { | 4503 | if (rec) { |
4420 | enum ocfs2_contig_type contig_type; | 4504 | enum ocfs2_contig_type contig_type; |
4421 | 4505 | ||
4422 | contig_type = ocfs2_extent_contig(inode, rec, split_rec); | 4506 | contig_type = ocfs2_et_extent_contig(et, rec, split_rec); |
4423 | 4507 | ||
4424 | if (contig_type == CONTIG_LEFT && ret == CONTIG_RIGHT) | 4508 | if (contig_type == CONTIG_LEFT && ret == CONTIG_RIGHT) |
4425 | ret = CONTIG_LEFTRIGHT; | 4509 | ret = CONTIG_LEFTRIGHT; |
@@ -4436,11 +4520,10 @@ out: | |||
4436 | return ret; | 4520 | return ret; |
4437 | } | 4521 | } |
4438 | 4522 | ||
4439 | static void ocfs2_figure_contig_type(struct inode *inode, | 4523 | static void ocfs2_figure_contig_type(struct ocfs2_extent_tree *et, |
4440 | struct ocfs2_insert_type *insert, | 4524 | struct ocfs2_insert_type *insert, |
4441 | struct ocfs2_extent_list *el, | 4525 | struct ocfs2_extent_list *el, |
4442 | struct ocfs2_extent_rec *insert_rec, | 4526 | struct ocfs2_extent_rec *insert_rec) |
4443 | struct ocfs2_extent_tree *et) | ||
4444 | { | 4527 | { |
4445 | int i; | 4528 | int i; |
4446 | enum ocfs2_contig_type contig_type = CONTIG_NONE; | 4529 | enum ocfs2_contig_type contig_type = CONTIG_NONE; |
@@ -4448,8 +4531,8 @@ static void ocfs2_figure_contig_type(struct inode *inode, | |||
4448 | BUG_ON(le16_to_cpu(el->l_tree_depth) != 0); | 4531 | BUG_ON(le16_to_cpu(el->l_tree_depth) != 0); |
4449 | 4532 | ||
4450 | for(i = 0; i < le16_to_cpu(el->l_next_free_rec); i++) { | 4533 | for(i = 0; i < le16_to_cpu(el->l_next_free_rec); i++) { |
4451 | contig_type = ocfs2_extent_contig(inode, &el->l_recs[i], | 4534 | contig_type = ocfs2_et_extent_contig(et, &el->l_recs[i], |
4452 | insert_rec); | 4535 | insert_rec); |
4453 | if (contig_type != CONTIG_NONE) { | 4536 | if (contig_type != CONTIG_NONE) { |
4454 | insert->ins_contig_index = i; | 4537 | insert->ins_contig_index = i; |
4455 | break; | 4538 | break; |
@@ -4530,8 +4613,7 @@ set_tail_append: | |||
4530 | * All of the information is stored on the ocfs2_insert_type | 4613 | * All of the information is stored on the ocfs2_insert_type |
4531 | * structure. | 4614 | * structure. |
4532 | */ | 4615 | */ |
4533 | static int ocfs2_figure_insert_type(struct inode *inode, | 4616 | static int ocfs2_figure_insert_type(struct ocfs2_extent_tree *et, |
4534 | struct ocfs2_extent_tree *et, | ||
4535 | struct buffer_head **last_eb_bh, | 4617 | struct buffer_head **last_eb_bh, |
4536 | struct ocfs2_extent_rec *insert_rec, | 4618 | struct ocfs2_extent_rec *insert_rec, |
4537 | int *free_records, | 4619 | int *free_records, |
@@ -4555,7 +4637,7 @@ static int ocfs2_figure_insert_type(struct inode *inode, | |||
4555 | * ocfs2_figure_insert_type() and ocfs2_add_branch() | 4637 | * ocfs2_figure_insert_type() and ocfs2_add_branch() |
4556 | * may want it later. | 4638 | * may want it later. |
4557 | */ | 4639 | */ |
4558 | ret = ocfs2_read_extent_block(inode, | 4640 | ret = ocfs2_read_extent_block(et->et_ci, |
4559 | ocfs2_et_get_last_eb_blk(et), | 4641 | ocfs2_et_get_last_eb_blk(et), |
4560 | &bh); | 4642 | &bh); |
4561 | if (ret) { | 4643 | if (ret) { |
@@ -4578,7 +4660,7 @@ static int ocfs2_figure_insert_type(struct inode *inode, | |||
4578 | le16_to_cpu(el->l_next_free_rec); | 4660 | le16_to_cpu(el->l_next_free_rec); |
4579 | 4661 | ||
4580 | if (!insert->ins_tree_depth) { | 4662 | if (!insert->ins_tree_depth) { |
4581 | ocfs2_figure_contig_type(inode, insert, el, insert_rec, et); | 4663 | ocfs2_figure_contig_type(et, insert, el, insert_rec); |
4582 | ocfs2_figure_appending_type(insert, el, insert_rec); | 4664 | ocfs2_figure_appending_type(insert, el, insert_rec); |
4583 | return 0; | 4665 | return 0; |
4584 | } | 4666 | } |
@@ -4596,7 +4678,7 @@ static int ocfs2_figure_insert_type(struct inode *inode, | |||
4596 | * us the rightmost tree path. This is accounted for below in | 4678 | * us the rightmost tree path. This is accounted for below in |
4597 | * the appending code. | 4679 | * the appending code. |
4598 | */ | 4680 | */ |
4599 | ret = ocfs2_find_path(inode, path, le32_to_cpu(insert_rec->e_cpos)); | 4681 | ret = ocfs2_find_path(et->et_ci, path, le32_to_cpu(insert_rec->e_cpos)); |
4600 | if (ret) { | 4682 | if (ret) { |
4601 | mlog_errno(ret); | 4683 | mlog_errno(ret); |
4602 | goto out; | 4684 | goto out; |
@@ -4612,7 +4694,7 @@ static int ocfs2_figure_insert_type(struct inode *inode, | |||
4612 | * into two types of appends: simple record append, or a | 4694 | * into two types of appends: simple record append, or a |
4613 | * rotate inside the tail leaf. | 4695 | * rotate inside the tail leaf. |
4614 | */ | 4696 | */ |
4615 | ocfs2_figure_contig_type(inode, insert, el, insert_rec, et); | 4697 | ocfs2_figure_contig_type(et, insert, el, insert_rec); |
4616 | 4698 | ||
4617 | /* | 4699 | /* |
4618 | * The insert code isn't quite ready to deal with all cases of | 4700 | * The insert code isn't quite ready to deal with all cases of |
@@ -4657,13 +4739,11 @@ out: | |||
4657 | } | 4739 | } |
4658 | 4740 | ||
4659 | /* | 4741 | /* |
4660 | * Insert an extent into an inode btree. | 4742 | * Insert an extent into a btree. |
4661 | * | 4743 | * |
4662 | * The caller needs to update fe->i_clusters | 4744 | * The caller needs to update the owning btree's cluster count. |
4663 | */ | 4745 | */ |
4664 | int ocfs2_insert_extent(struct ocfs2_super *osb, | 4746 | int ocfs2_insert_extent(handle_t *handle, |
4665 | handle_t *handle, | ||
4666 | struct inode *inode, | ||
4667 | struct ocfs2_extent_tree *et, | 4747 | struct ocfs2_extent_tree *et, |
4668 | u32 cpos, | 4748 | u32 cpos, |
4669 | u64 start_blk, | 4749 | u64 start_blk, |
@@ -4677,21 +4757,22 @@ int ocfs2_insert_extent(struct ocfs2_super *osb, | |||
4677 | struct ocfs2_insert_type insert = {0, }; | 4757 | struct ocfs2_insert_type insert = {0, }; |
4678 | struct ocfs2_extent_rec rec; | 4758 | struct ocfs2_extent_rec rec; |
4679 | 4759 | ||
4680 | mlog(0, "add %u clusters at position %u to inode %llu\n", | 4760 | mlog(0, "add %u clusters at position %u to owner %llu\n", |
4681 | new_clusters, cpos, (unsigned long long)OCFS2_I(inode)->ip_blkno); | 4761 | new_clusters, cpos, |
4762 | (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci)); | ||
4682 | 4763 | ||
4683 | memset(&rec, 0, sizeof(rec)); | 4764 | memset(&rec, 0, sizeof(rec)); |
4684 | rec.e_cpos = cpu_to_le32(cpos); | 4765 | rec.e_cpos = cpu_to_le32(cpos); |
4685 | rec.e_blkno = cpu_to_le64(start_blk); | 4766 | rec.e_blkno = cpu_to_le64(start_blk); |
4686 | rec.e_leaf_clusters = cpu_to_le16(new_clusters); | 4767 | rec.e_leaf_clusters = cpu_to_le16(new_clusters); |
4687 | rec.e_flags = flags; | 4768 | rec.e_flags = flags; |
4688 | status = ocfs2_et_insert_check(inode, et, &rec); | 4769 | status = ocfs2_et_insert_check(et, &rec); |
4689 | if (status) { | 4770 | if (status) { |
4690 | mlog_errno(status); | 4771 | mlog_errno(status); |
4691 | goto bail; | 4772 | goto bail; |
4692 | } | 4773 | } |
4693 | 4774 | ||
4694 | status = ocfs2_figure_insert_type(inode, et, &last_eb_bh, &rec, | 4775 | status = ocfs2_figure_insert_type(et, &last_eb_bh, &rec, |
4695 | &free_records, &insert); | 4776 | &free_records, &insert); |
4696 | if (status < 0) { | 4777 | if (status < 0) { |
4697 | mlog_errno(status); | 4778 | mlog_errno(status); |
@@ -4705,7 +4786,7 @@ int ocfs2_insert_extent(struct ocfs2_super *osb, | |||
4705 | free_records, insert.ins_tree_depth); | 4786 | free_records, insert.ins_tree_depth); |
4706 | 4787 | ||
4707 | if (insert.ins_contig == CONTIG_NONE && free_records == 0) { | 4788 | if (insert.ins_contig == CONTIG_NONE && free_records == 0) { |
4708 | status = ocfs2_grow_tree(inode, handle, et, | 4789 | status = ocfs2_grow_tree(handle, et, |
4709 | &insert.ins_tree_depth, &last_eb_bh, | 4790 | &insert.ins_tree_depth, &last_eb_bh, |
4710 | meta_ac); | 4791 | meta_ac); |
4711 | if (status) { | 4792 | if (status) { |
@@ -4715,11 +4796,11 @@ int ocfs2_insert_extent(struct ocfs2_super *osb, | |||
4715 | } | 4796 | } |
4716 | 4797 | ||
4717 | /* Finally, we can add clusters. This might rotate the tree for us. */ | 4798 | /* Finally, we can add clusters. This might rotate the tree for us. */ |
4718 | status = ocfs2_do_insert_extent(inode, handle, et, &rec, &insert); | 4799 | status = ocfs2_do_insert_extent(handle, et, &rec, &insert); |
4719 | if (status < 0) | 4800 | if (status < 0) |
4720 | mlog_errno(status); | 4801 | mlog_errno(status); |
4721 | else if (et->et_ops == &ocfs2_dinode_et_ops) | 4802 | else |
4722 | ocfs2_extent_map_insert_rec(inode, &rec); | 4803 | ocfs2_et_extent_map_insert(et, &rec); |
4723 | 4804 | ||
4724 | bail: | 4805 | bail: |
4725 | brelse(last_eb_bh); | 4806 | brelse(last_eb_bh); |
@@ -4735,13 +4816,11 @@ bail: | |||
4735 | * it is not limited to the file storage. Any extent tree can use this | 4816 | * it is not limited to the file storage. Any extent tree can use this |
4736 | * function if it implements the proper ocfs2_extent_tree. | 4817 | * function if it implements the proper ocfs2_extent_tree. |
4737 | */ | 4818 | */ |
4738 | int ocfs2_add_clusters_in_btree(struct ocfs2_super *osb, | 4819 | int ocfs2_add_clusters_in_btree(handle_t *handle, |
4739 | struct inode *inode, | 4820 | struct ocfs2_extent_tree *et, |
4740 | u32 *logical_offset, | 4821 | u32 *logical_offset, |
4741 | u32 clusters_to_add, | 4822 | u32 clusters_to_add, |
4742 | int mark_unwritten, | 4823 | int mark_unwritten, |
4743 | struct ocfs2_extent_tree *et, | ||
4744 | handle_t *handle, | ||
4745 | struct ocfs2_alloc_context *data_ac, | 4824 | struct ocfs2_alloc_context *data_ac, |
4746 | struct ocfs2_alloc_context *meta_ac, | 4825 | struct ocfs2_alloc_context *meta_ac, |
4747 | enum ocfs2_alloc_restarted *reason_ret) | 4826 | enum ocfs2_alloc_restarted *reason_ret) |
@@ -4752,13 +4831,15 @@ int ocfs2_add_clusters_in_btree(struct ocfs2_super *osb, | |||
4752 | u32 bit_off, num_bits; | 4831 | u32 bit_off, num_bits; |
4753 | u64 block; | 4832 | u64 block; |
4754 | u8 flags = 0; | 4833 | u8 flags = 0; |
4834 | struct ocfs2_super *osb = | ||
4835 | OCFS2_SB(ocfs2_metadata_cache_get_super(et->et_ci)); | ||
4755 | 4836 | ||
4756 | BUG_ON(!clusters_to_add); | 4837 | BUG_ON(!clusters_to_add); |
4757 | 4838 | ||
4758 | if (mark_unwritten) | 4839 | if (mark_unwritten) |
4759 | flags = OCFS2_EXT_UNWRITTEN; | 4840 | flags = OCFS2_EXT_UNWRITTEN; |
4760 | 4841 | ||
4761 | free_extents = ocfs2_num_free_extents(osb, inode, et); | 4842 | free_extents = ocfs2_num_free_extents(osb, et); |
4762 | if (free_extents < 0) { | 4843 | if (free_extents < 0) { |
4763 | status = free_extents; | 4844 | status = free_extents; |
4764 | mlog_errno(status); | 4845 | mlog_errno(status); |
@@ -4795,7 +4876,7 @@ int ocfs2_add_clusters_in_btree(struct ocfs2_super *osb, | |||
4795 | BUG_ON(num_bits > clusters_to_add); | 4876 | BUG_ON(num_bits > clusters_to_add); |
4796 | 4877 | ||
4797 | /* reserve our write early -- insert_extent may update the tree root */ | 4878 | /* reserve our write early -- insert_extent may update the tree root */ |
4798 | status = ocfs2_et_root_journal_access(handle, inode, et, | 4879 | status = ocfs2_et_root_journal_access(handle, et, |
4799 | OCFS2_JOURNAL_ACCESS_WRITE); | 4880 | OCFS2_JOURNAL_ACCESS_WRITE); |
4800 | if (status < 0) { | 4881 | if (status < 0) { |
4801 | mlog_errno(status); | 4882 | mlog_errno(status); |
@@ -4803,10 +4884,10 @@ int ocfs2_add_clusters_in_btree(struct ocfs2_super *osb, | |||
4803 | } | 4884 | } |
4804 | 4885 | ||
4805 | block = ocfs2_clusters_to_blocks(osb->sb, bit_off); | 4886 | block = ocfs2_clusters_to_blocks(osb->sb, bit_off); |
4806 | mlog(0, "Allocating %u clusters at block %u for inode %llu\n", | 4887 | mlog(0, "Allocating %u clusters at block %u for owner %llu\n", |
4807 | num_bits, bit_off, (unsigned long long)OCFS2_I(inode)->ip_blkno); | 4888 | num_bits, bit_off, |
4808 | status = ocfs2_insert_extent(osb, handle, inode, et, | 4889 | (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci)); |
4809 | *logical_offset, block, | 4890 | status = ocfs2_insert_extent(handle, et, *logical_offset, block, |
4810 | num_bits, flags, meta_ac); | 4891 | num_bits, flags, meta_ac); |
4811 | if (status < 0) { | 4892 | if (status < 0) { |
4812 | mlog_errno(status); | 4893 | mlog_errno(status); |
@@ -4856,10 +4937,9 @@ static void ocfs2_make_right_split_rec(struct super_block *sb, | |||
4856 | split_rec->e_flags = rec->e_flags; | 4937 | split_rec->e_flags = rec->e_flags; |
4857 | } | 4938 | } |
4858 | 4939 | ||
4859 | static int ocfs2_split_and_insert(struct inode *inode, | 4940 | static int ocfs2_split_and_insert(handle_t *handle, |
4860 | handle_t *handle, | ||
4861 | struct ocfs2_path *path, | ||
4862 | struct ocfs2_extent_tree *et, | 4941 | struct ocfs2_extent_tree *et, |
4942 | struct ocfs2_path *path, | ||
4863 | struct buffer_head **last_eb_bh, | 4943 | struct buffer_head **last_eb_bh, |
4864 | int split_index, | 4944 | int split_index, |
4865 | struct ocfs2_extent_rec *orig_split_rec, | 4945 | struct ocfs2_extent_rec *orig_split_rec, |
@@ -4892,7 +4972,7 @@ leftright: | |||
4892 | 4972 | ||
4893 | if (le16_to_cpu(rightmost_el->l_next_free_rec) == | 4973 | if (le16_to_cpu(rightmost_el->l_next_free_rec) == |
4894 | le16_to_cpu(rightmost_el->l_count)) { | 4974 | le16_to_cpu(rightmost_el->l_count)) { |
4895 | ret = ocfs2_grow_tree(inode, handle, et, | 4975 | ret = ocfs2_grow_tree(handle, et, |
4896 | &depth, last_eb_bh, meta_ac); | 4976 | &depth, last_eb_bh, meta_ac); |
4897 | if (ret) { | 4977 | if (ret) { |
4898 | mlog_errno(ret); | 4978 | mlog_errno(ret); |
@@ -4921,8 +5001,8 @@ leftright: | |||
4921 | */ | 5001 | */ |
4922 | insert.ins_split = SPLIT_RIGHT; | 5002 | insert.ins_split = SPLIT_RIGHT; |
4923 | 5003 | ||
4924 | ocfs2_make_right_split_rec(inode->i_sb, &tmprec, insert_range, | 5004 | ocfs2_make_right_split_rec(ocfs2_metadata_cache_get_super(et->et_ci), |
4925 | &rec); | 5005 | &tmprec, insert_range, &rec); |
4926 | 5006 | ||
4927 | split_rec = tmprec; | 5007 | split_rec = tmprec; |
4928 | 5008 | ||
@@ -4930,7 +5010,7 @@ leftright: | |||
4930 | do_leftright = 1; | 5010 | do_leftright = 1; |
4931 | } | 5011 | } |
4932 | 5012 | ||
4933 | ret = ocfs2_do_insert_extent(inode, handle, et, &split_rec, &insert); | 5013 | ret = ocfs2_do_insert_extent(handle, et, &split_rec, &insert); |
4934 | if (ret) { | 5014 | if (ret) { |
4935 | mlog_errno(ret); | 5015 | mlog_errno(ret); |
4936 | goto out; | 5016 | goto out; |
@@ -4946,7 +5026,7 @@ leftright: | |||
4946 | ocfs2_reinit_path(path, 1); | 5026 | ocfs2_reinit_path(path, 1); |
4947 | 5027 | ||
4948 | cpos = le32_to_cpu(split_rec.e_cpos); | 5028 | cpos = le32_to_cpu(split_rec.e_cpos); |
4949 | ret = ocfs2_find_path(inode, path, cpos); | 5029 | ret = ocfs2_find_path(et->et_ci, path, cpos); |
4950 | if (ret) { | 5030 | if (ret) { |
4951 | mlog_errno(ret); | 5031 | mlog_errno(ret); |
4952 | goto out; | 5032 | goto out; |
@@ -4961,8 +5041,8 @@ out: | |||
4961 | return ret; | 5041 | return ret; |
4962 | } | 5042 | } |
4963 | 5043 | ||
4964 | static int ocfs2_replace_extent_rec(struct inode *inode, | 5044 | static int ocfs2_replace_extent_rec(handle_t *handle, |
4965 | handle_t *handle, | 5045 | struct ocfs2_extent_tree *et, |
4966 | struct ocfs2_path *path, | 5046 | struct ocfs2_path *path, |
4967 | struct ocfs2_extent_list *el, | 5047 | struct ocfs2_extent_list *el, |
4968 | int split_index, | 5048 | int split_index, |
@@ -4970,7 +5050,7 @@ static int ocfs2_replace_extent_rec(struct inode *inode, | |||
4970 | { | 5050 | { |
4971 | int ret; | 5051 | int ret; |
4972 | 5052 | ||
4973 | ret = ocfs2_path_bh_journal_access(handle, inode, path, | 5053 | ret = ocfs2_path_bh_journal_access(handle, et->et_ci, path, |
4974 | path_num_items(path) - 1); | 5054 | path_num_items(path) - 1); |
4975 | if (ret) { | 5055 | if (ret) { |
4976 | mlog_errno(ret); | 5056 | mlog_errno(ret); |
@@ -4985,9 +5065,8 @@ out: | |||
4985 | } | 5065 | } |
4986 | 5066 | ||
4987 | /* | 5067 | /* |
4988 | * Mark part or all of the extent record at split_index in the leaf | 5068 | * Split part or all of the extent record at split_index in the leaf |
4989 | * pointed to by path as written. This removes the unwritten | 5069 | * pointed to by path. Merge with the contiguous extent record if needed. |
4990 | * extent flag. | ||
4991 | * | 5070 | * |
4992 | * Care is taken to handle contiguousness so as to not grow the tree. | 5071 | * Care is taken to handle contiguousness so as to not grow the tree. |
4993 | * | 5072 | * |
@@ -5004,14 +5083,13 @@ out: | |||
5004 | * have been brought into cache (and pinned via the journal), so the | 5083 | * have been brought into cache (and pinned via the journal), so the |
5005 | * extra overhead is not expressed in terms of disk reads. | 5084 | * extra overhead is not expressed in terms of disk reads. |
5006 | */ | 5085 | */ |
5007 | static int __ocfs2_mark_extent_written(struct inode *inode, | 5086 | int ocfs2_split_extent(handle_t *handle, |
5008 | struct ocfs2_extent_tree *et, | 5087 | struct ocfs2_extent_tree *et, |
5009 | handle_t *handle, | 5088 | struct ocfs2_path *path, |
5010 | struct ocfs2_path *path, | 5089 | int split_index, |
5011 | int split_index, | 5090 | struct ocfs2_extent_rec *split_rec, |
5012 | struct ocfs2_extent_rec *split_rec, | 5091 | struct ocfs2_alloc_context *meta_ac, |
5013 | struct ocfs2_alloc_context *meta_ac, | 5092 | struct ocfs2_cached_dealloc_ctxt *dealloc) |
5014 | struct ocfs2_cached_dealloc_ctxt *dealloc) | ||
5015 | { | 5093 | { |
5016 | int ret = 0; | 5094 | int ret = 0; |
5017 | struct ocfs2_extent_list *el = path_leaf_el(path); | 5095 | struct ocfs2_extent_list *el = path_leaf_el(path); |
@@ -5020,12 +5098,6 @@ static int __ocfs2_mark_extent_written(struct inode *inode, | |||
5020 | struct ocfs2_merge_ctxt ctxt; | 5098 | struct ocfs2_merge_ctxt ctxt; |
5021 | struct ocfs2_extent_list *rightmost_el; | 5099 | struct ocfs2_extent_list *rightmost_el; |
5022 | 5100 | ||
5023 | if (!(rec->e_flags & OCFS2_EXT_UNWRITTEN)) { | ||
5024 | ret = -EIO; | ||
5025 | mlog_errno(ret); | ||
5026 | goto out; | ||
5027 | } | ||
5028 | |||
5029 | if (le32_to_cpu(rec->e_cpos) > le32_to_cpu(split_rec->e_cpos) || | 5101 | if (le32_to_cpu(rec->e_cpos) > le32_to_cpu(split_rec->e_cpos) || |
5030 | ((le32_to_cpu(rec->e_cpos) + le16_to_cpu(rec->e_leaf_clusters)) < | 5102 | ((le32_to_cpu(rec->e_cpos) + le16_to_cpu(rec->e_leaf_clusters)) < |
5031 | (le32_to_cpu(split_rec->e_cpos) + le16_to_cpu(split_rec->e_leaf_clusters)))) { | 5103 | (le32_to_cpu(split_rec->e_cpos) + le16_to_cpu(split_rec->e_leaf_clusters)))) { |
@@ -5034,19 +5106,19 @@ static int __ocfs2_mark_extent_written(struct inode *inode, | |||
5034 | goto out; | 5106 | goto out; |
5035 | } | 5107 | } |
5036 | 5108 | ||
5037 | ctxt.c_contig_type = ocfs2_figure_merge_contig_type(inode, path, el, | 5109 | ctxt.c_contig_type = ocfs2_figure_merge_contig_type(et, path, el, |
5038 | split_index, | 5110 | split_index, |
5039 | split_rec); | 5111 | split_rec); |
5040 | 5112 | ||
5041 | /* | 5113 | /* |
5042 | * The core merge / split code wants to know how much room is | 5114 | * The core merge / split code wants to know how much room is |
5043 | * left in this inodes allocation tree, so we pass the | 5115 | * left in this allocation tree, so we pass the |
5044 | * rightmost extent list. | 5116 | * rightmost extent list. |
5045 | */ | 5117 | */ |
5046 | if (path->p_tree_depth) { | 5118 | if (path->p_tree_depth) { |
5047 | struct ocfs2_extent_block *eb; | 5119 | struct ocfs2_extent_block *eb; |
5048 | 5120 | ||
5049 | ret = ocfs2_read_extent_block(inode, | 5121 | ret = ocfs2_read_extent_block(et->et_ci, |
5050 | ocfs2_et_get_last_eb_blk(et), | 5122 | ocfs2_et_get_last_eb_blk(et), |
5051 | &last_eb_bh); | 5123 | &last_eb_bh); |
5052 | if (ret) { | 5124 | if (ret) { |
@@ -5073,19 +5145,18 @@ static int __ocfs2_mark_extent_written(struct inode *inode, | |||
5073 | 5145 | ||
5074 | if (ctxt.c_contig_type == CONTIG_NONE) { | 5146 | if (ctxt.c_contig_type == CONTIG_NONE) { |
5075 | if (ctxt.c_split_covers_rec) | 5147 | if (ctxt.c_split_covers_rec) |
5076 | ret = ocfs2_replace_extent_rec(inode, handle, | 5148 | ret = ocfs2_replace_extent_rec(handle, et, path, el, |
5077 | path, el, | ||
5078 | split_index, split_rec); | 5149 | split_index, split_rec); |
5079 | else | 5150 | else |
5080 | ret = ocfs2_split_and_insert(inode, handle, path, et, | 5151 | ret = ocfs2_split_and_insert(handle, et, path, |
5081 | &last_eb_bh, split_index, | 5152 | &last_eb_bh, split_index, |
5082 | split_rec, meta_ac); | 5153 | split_rec, meta_ac); |
5083 | if (ret) | 5154 | if (ret) |
5084 | mlog_errno(ret); | 5155 | mlog_errno(ret); |
5085 | } else { | 5156 | } else { |
5086 | ret = ocfs2_try_to_merge_extent(inode, handle, path, | 5157 | ret = ocfs2_try_to_merge_extent(handle, et, path, |
5087 | split_index, split_rec, | 5158 | split_index, split_rec, |
5088 | dealloc, &ctxt, et); | 5159 | dealloc, &ctxt); |
5089 | if (ret) | 5160 | if (ret) |
5090 | mlog_errno(ret); | 5161 | mlog_errno(ret); |
5091 | } | 5162 | } |
@@ -5096,46 +5167,31 @@ out: | |||
5096 | } | 5167 | } |
5097 | 5168 | ||
5098 | /* | 5169 | /* |
5099 | * Mark the already-existing extent at cpos as written for len clusters. | 5170 | * Change the flags of the already-existing extent at cpos for len clusters. |
5171 | * | ||
5172 | * new_flags: the flags we want to set. | ||
5173 | * clear_flags: the flags we want to clear. | ||
5174 | * phys: the new physical offset we want this new extent starts from. | ||
5100 | * | 5175 | * |
5101 | * If the existing extent is larger than the request, initiate a | 5176 | * If the existing extent is larger than the request, initiate a |
5102 | * split. An attempt will be made at merging with adjacent extents. | 5177 | * split. An attempt will be made at merging with adjacent extents. |
5103 | * | 5178 | * |
5104 | * The caller is responsible for passing down meta_ac if we'll need it. | 5179 | * The caller is responsible for passing down meta_ac if we'll need it. |
5105 | */ | 5180 | */ |
5106 | int ocfs2_mark_extent_written(struct inode *inode, | 5181 | int ocfs2_change_extent_flag(handle_t *handle, |
5107 | struct ocfs2_extent_tree *et, | 5182 | struct ocfs2_extent_tree *et, |
5108 | handle_t *handle, u32 cpos, u32 len, u32 phys, | 5183 | u32 cpos, u32 len, u32 phys, |
5109 | struct ocfs2_alloc_context *meta_ac, | 5184 | struct ocfs2_alloc_context *meta_ac, |
5110 | struct ocfs2_cached_dealloc_ctxt *dealloc) | 5185 | struct ocfs2_cached_dealloc_ctxt *dealloc, |
5186 | int new_flags, int clear_flags) | ||
5111 | { | 5187 | { |
5112 | int ret, index; | 5188 | int ret, index; |
5113 | u64 start_blkno = ocfs2_clusters_to_blocks(inode->i_sb, phys); | 5189 | struct super_block *sb = ocfs2_metadata_cache_get_super(et->et_ci); |
5190 | u64 start_blkno = ocfs2_clusters_to_blocks(sb, phys); | ||
5114 | struct ocfs2_extent_rec split_rec; | 5191 | struct ocfs2_extent_rec split_rec; |
5115 | struct ocfs2_path *left_path = NULL; | 5192 | struct ocfs2_path *left_path = NULL; |
5116 | struct ocfs2_extent_list *el; | 5193 | struct ocfs2_extent_list *el; |
5117 | 5194 | struct ocfs2_extent_rec *rec; | |
5118 | mlog(0, "Inode %lu cpos %u, len %u, phys %u (%llu)\n", | ||
5119 | inode->i_ino, cpos, len, phys, (unsigned long long)start_blkno); | ||
5120 | |||
5121 | if (!ocfs2_writes_unwritten_extents(OCFS2_SB(inode->i_sb))) { | ||
5122 | ocfs2_error(inode->i_sb, "Inode %llu has unwritten extents " | ||
5123 | "that are being written to, but the feature bit " | ||
5124 | "is not set in the super block.", | ||
5125 | (unsigned long long)OCFS2_I(inode)->ip_blkno); | ||
5126 | ret = -EROFS; | ||
5127 | goto out; | ||
5128 | } | ||
5129 | |||
5130 | /* | ||
5131 | * XXX: This should be fixed up so that we just re-insert the | ||
5132 | * next extent records. | ||
5133 | * | ||
5134 | * XXX: This is a hack on the extent tree, maybe it should be | ||
5135 | * an op? | ||
5136 | */ | ||
5137 | if (et->et_ops == &ocfs2_dinode_et_ops) | ||
5138 | ocfs2_extent_map_trunc(inode, 0); | ||
5139 | 5195 | ||
5140 | left_path = ocfs2_new_path_from_et(et); | 5196 | left_path = ocfs2_new_path_from_et(et); |
5141 | if (!left_path) { | 5197 | if (!left_path) { |
@@ -5144,7 +5200,7 @@ int ocfs2_mark_extent_written(struct inode *inode, | |||
5144 | goto out; | 5200 | goto out; |
5145 | } | 5201 | } |
5146 | 5202 | ||
5147 | ret = ocfs2_find_path(inode, left_path, cpos); | 5203 | ret = ocfs2_find_path(et->et_ci, left_path, cpos); |
5148 | if (ret) { | 5204 | if (ret) { |
5149 | mlog_errno(ret); | 5205 | mlog_errno(ret); |
5150 | goto out; | 5206 | goto out; |
@@ -5153,34 +5209,102 @@ int ocfs2_mark_extent_written(struct inode *inode, | |||
5153 | 5209 | ||
5154 | index = ocfs2_search_extent_list(el, cpos); | 5210 | index = ocfs2_search_extent_list(el, cpos); |
5155 | if (index == -1 || index >= le16_to_cpu(el->l_next_free_rec)) { | 5211 | if (index == -1 || index >= le16_to_cpu(el->l_next_free_rec)) { |
5156 | ocfs2_error(inode->i_sb, | 5212 | ocfs2_error(sb, |
5157 | "Inode %llu has an extent at cpos %u which can no " | 5213 | "Owner %llu has an extent at cpos %u which can no " |
5158 | "longer be found.\n", | 5214 | "longer be found.\n", |
5159 | (unsigned long long)OCFS2_I(inode)->ip_blkno, cpos); | 5215 | (unsigned long long) |
5216 | ocfs2_metadata_cache_owner(et->et_ci), cpos); | ||
5160 | ret = -EROFS; | 5217 | ret = -EROFS; |
5161 | goto out; | 5218 | goto out; |
5162 | } | 5219 | } |
5163 | 5220 | ||
5221 | ret = -EIO; | ||
5222 | rec = &el->l_recs[index]; | ||
5223 | if (new_flags && (rec->e_flags & new_flags)) { | ||
5224 | mlog(ML_ERROR, "Owner %llu tried to set %d flags on an " | ||
5225 | "extent that already had them", | ||
5226 | (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci), | ||
5227 | new_flags); | ||
5228 | goto out; | ||
5229 | } | ||
5230 | |||
5231 | if (clear_flags && !(rec->e_flags & clear_flags)) { | ||
5232 | mlog(ML_ERROR, "Owner %llu tried to clear %d flags on an " | ||
5233 | "extent that didn't have them", | ||
5234 | (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci), | ||
5235 | clear_flags); | ||
5236 | goto out; | ||
5237 | } | ||
5238 | |||
5164 | memset(&split_rec, 0, sizeof(struct ocfs2_extent_rec)); | 5239 | memset(&split_rec, 0, sizeof(struct ocfs2_extent_rec)); |
5165 | split_rec.e_cpos = cpu_to_le32(cpos); | 5240 | split_rec.e_cpos = cpu_to_le32(cpos); |
5166 | split_rec.e_leaf_clusters = cpu_to_le16(len); | 5241 | split_rec.e_leaf_clusters = cpu_to_le16(len); |
5167 | split_rec.e_blkno = cpu_to_le64(start_blkno); | 5242 | split_rec.e_blkno = cpu_to_le64(start_blkno); |
5168 | split_rec.e_flags = path_leaf_el(left_path)->l_recs[index].e_flags; | 5243 | split_rec.e_flags = rec->e_flags; |
5169 | split_rec.e_flags &= ~OCFS2_EXT_UNWRITTEN; | 5244 | if (new_flags) |
5170 | 5245 | split_rec.e_flags |= new_flags; | |
5171 | ret = __ocfs2_mark_extent_written(inode, et, handle, left_path, | 5246 | if (clear_flags) |
5172 | index, &split_rec, meta_ac, | 5247 | split_rec.e_flags &= ~clear_flags; |
5173 | dealloc); | 5248 | |
5249 | ret = ocfs2_split_extent(handle, et, left_path, | ||
5250 | index, &split_rec, meta_ac, | ||
5251 | dealloc); | ||
5174 | if (ret) | 5252 | if (ret) |
5175 | mlog_errno(ret); | 5253 | mlog_errno(ret); |
5176 | 5254 | ||
5177 | out: | 5255 | out: |
5178 | ocfs2_free_path(left_path); | 5256 | ocfs2_free_path(left_path); |
5179 | return ret; | 5257 | return ret; |
5258 | |||
5180 | } | 5259 | } |
5181 | 5260 | ||
5182 | static int ocfs2_split_tree(struct inode *inode, struct ocfs2_extent_tree *et, | 5261 | /* |
5183 | handle_t *handle, struct ocfs2_path *path, | 5262 | * Mark the already-existing extent at cpos as written for len clusters. |
5263 | * This removes the unwritten extent flag. | ||
5264 | * | ||
5265 | * If the existing extent is larger than the request, initiate a | ||
5266 | * split. An attempt will be made at merging with adjacent extents. | ||
5267 | * | ||
5268 | * The caller is responsible for passing down meta_ac if we'll need it. | ||
5269 | */ | ||
5270 | int ocfs2_mark_extent_written(struct inode *inode, | ||
5271 | struct ocfs2_extent_tree *et, | ||
5272 | handle_t *handle, u32 cpos, u32 len, u32 phys, | ||
5273 | struct ocfs2_alloc_context *meta_ac, | ||
5274 | struct ocfs2_cached_dealloc_ctxt *dealloc) | ||
5275 | { | ||
5276 | int ret; | ||
5277 | |||
5278 | mlog(0, "Inode %lu cpos %u, len %u, phys clusters %u\n", | ||
5279 | inode->i_ino, cpos, len, phys); | ||
5280 | |||
5281 | if (!ocfs2_writes_unwritten_extents(OCFS2_SB(inode->i_sb))) { | ||
5282 | ocfs2_error(inode->i_sb, "Inode %llu has unwritten extents " | ||
5283 | "that are being written to, but the feature bit " | ||
5284 | "is not set in the super block.", | ||
5285 | (unsigned long long)OCFS2_I(inode)->ip_blkno); | ||
5286 | ret = -EROFS; | ||
5287 | goto out; | ||
5288 | } | ||
5289 | |||
5290 | /* | ||
5291 | * XXX: This should be fixed up so that we just re-insert the | ||
5292 | * next extent records. | ||
5293 | */ | ||
5294 | ocfs2_et_extent_map_truncate(et, 0); | ||
5295 | |||
5296 | ret = ocfs2_change_extent_flag(handle, et, cpos, | ||
5297 | len, phys, meta_ac, dealloc, | ||
5298 | 0, OCFS2_EXT_UNWRITTEN); | ||
5299 | if (ret) | ||
5300 | mlog_errno(ret); | ||
5301 | |||
5302 | out: | ||
5303 | return ret; | ||
5304 | } | ||
5305 | |||
5306 | static int ocfs2_split_tree(handle_t *handle, struct ocfs2_extent_tree *et, | ||
5307 | struct ocfs2_path *path, | ||
5184 | int index, u32 new_range, | 5308 | int index, u32 new_range, |
5185 | struct ocfs2_alloc_context *meta_ac) | 5309 | struct ocfs2_alloc_context *meta_ac) |
5186 | { | 5310 | { |
@@ -5197,11 +5321,12 @@ static int ocfs2_split_tree(struct inode *inode, struct ocfs2_extent_tree *et, | |||
5197 | */ | 5321 | */ |
5198 | el = path_leaf_el(path); | 5322 | el = path_leaf_el(path); |
5199 | rec = &el->l_recs[index]; | 5323 | rec = &el->l_recs[index]; |
5200 | ocfs2_make_right_split_rec(inode->i_sb, &split_rec, new_range, rec); | 5324 | ocfs2_make_right_split_rec(ocfs2_metadata_cache_get_super(et->et_ci), |
5325 | &split_rec, new_range, rec); | ||
5201 | 5326 | ||
5202 | depth = path->p_tree_depth; | 5327 | depth = path->p_tree_depth; |
5203 | if (depth > 0) { | 5328 | if (depth > 0) { |
5204 | ret = ocfs2_read_extent_block(inode, | 5329 | ret = ocfs2_read_extent_block(et->et_ci, |
5205 | ocfs2_et_get_last_eb_blk(et), | 5330 | ocfs2_et_get_last_eb_blk(et), |
5206 | &last_eb_bh); | 5331 | &last_eb_bh); |
5207 | if (ret < 0) { | 5332 | if (ret < 0) { |
@@ -5224,7 +5349,7 @@ static int ocfs2_split_tree(struct inode *inode, struct ocfs2_extent_tree *et, | |||
5224 | 5349 | ||
5225 | if (le16_to_cpu(rightmost_el->l_next_free_rec) == | 5350 | if (le16_to_cpu(rightmost_el->l_next_free_rec) == |
5226 | le16_to_cpu(rightmost_el->l_count)) { | 5351 | le16_to_cpu(rightmost_el->l_count)) { |
5227 | ret = ocfs2_grow_tree(inode, handle, et, &depth, &last_eb_bh, | 5352 | ret = ocfs2_grow_tree(handle, et, &depth, &last_eb_bh, |
5228 | meta_ac); | 5353 | meta_ac); |
5229 | if (ret) { | 5354 | if (ret) { |
5230 | mlog_errno(ret); | 5355 | mlog_errno(ret); |
@@ -5238,7 +5363,7 @@ static int ocfs2_split_tree(struct inode *inode, struct ocfs2_extent_tree *et, | |||
5238 | insert.ins_split = SPLIT_RIGHT; | 5363 | insert.ins_split = SPLIT_RIGHT; |
5239 | insert.ins_tree_depth = depth; | 5364 | insert.ins_tree_depth = depth; |
5240 | 5365 | ||
5241 | ret = ocfs2_do_insert_extent(inode, handle, et, &split_rec, &insert); | 5366 | ret = ocfs2_do_insert_extent(handle, et, &split_rec, &insert); |
5242 | if (ret) | 5367 | if (ret) |
5243 | mlog_errno(ret); | 5368 | mlog_errno(ret); |
5244 | 5369 | ||
@@ -5247,23 +5372,23 @@ out: | |||
5247 | return ret; | 5372 | return ret; |
5248 | } | 5373 | } |
5249 | 5374 | ||
5250 | static int ocfs2_truncate_rec(struct inode *inode, handle_t *handle, | 5375 | static int ocfs2_truncate_rec(handle_t *handle, |
5376 | struct ocfs2_extent_tree *et, | ||
5251 | struct ocfs2_path *path, int index, | 5377 | struct ocfs2_path *path, int index, |
5252 | struct ocfs2_cached_dealloc_ctxt *dealloc, | 5378 | struct ocfs2_cached_dealloc_ctxt *dealloc, |
5253 | u32 cpos, u32 len, | 5379 | u32 cpos, u32 len) |
5254 | struct ocfs2_extent_tree *et) | ||
5255 | { | 5380 | { |
5256 | int ret; | 5381 | int ret; |
5257 | u32 left_cpos, rec_range, trunc_range; | 5382 | u32 left_cpos, rec_range, trunc_range; |
5258 | int wants_rotate = 0, is_rightmost_tree_rec = 0; | 5383 | int wants_rotate = 0, is_rightmost_tree_rec = 0; |
5259 | struct super_block *sb = inode->i_sb; | 5384 | struct super_block *sb = ocfs2_metadata_cache_get_super(et->et_ci); |
5260 | struct ocfs2_path *left_path = NULL; | 5385 | struct ocfs2_path *left_path = NULL; |
5261 | struct ocfs2_extent_list *el = path_leaf_el(path); | 5386 | struct ocfs2_extent_list *el = path_leaf_el(path); |
5262 | struct ocfs2_extent_rec *rec; | 5387 | struct ocfs2_extent_rec *rec; |
5263 | struct ocfs2_extent_block *eb; | 5388 | struct ocfs2_extent_block *eb; |
5264 | 5389 | ||
5265 | if (ocfs2_is_empty_extent(&el->l_recs[0]) && index > 0) { | 5390 | if (ocfs2_is_empty_extent(&el->l_recs[0]) && index > 0) { |
5266 | ret = ocfs2_rotate_tree_left(inode, handle, path, dealloc, et); | 5391 | ret = ocfs2_rotate_tree_left(handle, et, path, dealloc); |
5267 | if (ret) { | 5392 | if (ret) { |
5268 | mlog_errno(ret); | 5393 | mlog_errno(ret); |
5269 | goto out; | 5394 | goto out; |
@@ -5295,14 +5420,13 @@ static int ocfs2_truncate_rec(struct inode *inode, handle_t *handle, | |||
5295 | * by this leaf and the one to it's left. | 5420 | * by this leaf and the one to it's left. |
5296 | * | 5421 | * |
5297 | * There are two cases we can skip: | 5422 | * There are two cases we can skip: |
5298 | * 1) Path is the leftmost one in our inode tree. | 5423 | * 1) Path is the leftmost one in our btree. |
5299 | * 2) The leaf is rightmost and will be empty after | 5424 | * 2) The leaf is rightmost and will be empty after |
5300 | * we remove the extent record - the rotate code | 5425 | * we remove the extent record - the rotate code |
5301 | * knows how to update the newly formed edge. | 5426 | * knows how to update the newly formed edge. |
5302 | */ | 5427 | */ |
5303 | 5428 | ||
5304 | ret = ocfs2_find_cpos_for_left_leaf(inode->i_sb, path, | 5429 | ret = ocfs2_find_cpos_for_left_leaf(sb, path, &left_cpos); |
5305 | &left_cpos); | ||
5306 | if (ret) { | 5430 | if (ret) { |
5307 | mlog_errno(ret); | 5431 | mlog_errno(ret); |
5308 | goto out; | 5432 | goto out; |
@@ -5316,7 +5440,8 @@ static int ocfs2_truncate_rec(struct inode *inode, handle_t *handle, | |||
5316 | goto out; | 5440 | goto out; |
5317 | } | 5441 | } |
5318 | 5442 | ||
5319 | ret = ocfs2_find_path(inode, left_path, left_cpos); | 5443 | ret = ocfs2_find_path(et->et_ci, left_path, |
5444 | left_cpos); | ||
5320 | if (ret) { | 5445 | if (ret) { |
5321 | mlog_errno(ret); | 5446 | mlog_errno(ret); |
5322 | goto out; | 5447 | goto out; |
@@ -5332,13 +5457,13 @@ static int ocfs2_truncate_rec(struct inode *inode, handle_t *handle, | |||
5332 | goto out; | 5457 | goto out; |
5333 | } | 5458 | } |
5334 | 5459 | ||
5335 | ret = ocfs2_journal_access_path(inode, handle, path); | 5460 | ret = ocfs2_journal_access_path(et->et_ci, handle, path); |
5336 | if (ret) { | 5461 | if (ret) { |
5337 | mlog_errno(ret); | 5462 | mlog_errno(ret); |
5338 | goto out; | 5463 | goto out; |
5339 | } | 5464 | } |
5340 | 5465 | ||
5341 | ret = ocfs2_journal_access_path(inode, handle, left_path); | 5466 | ret = ocfs2_journal_access_path(et->et_ci, handle, left_path); |
5342 | if (ret) { | 5467 | if (ret) { |
5343 | mlog_errno(ret); | 5468 | mlog_errno(ret); |
5344 | goto out; | 5469 | goto out; |
@@ -5361,7 +5486,7 @@ static int ocfs2_truncate_rec(struct inode *inode, handle_t *handle, | |||
5361 | * be deleted by the rotate code. | 5486 | * be deleted by the rotate code. |
5362 | */ | 5487 | */ |
5363 | rec = &el->l_recs[next_free - 1]; | 5488 | rec = &el->l_recs[next_free - 1]; |
5364 | ocfs2_adjust_rightmost_records(inode, handle, path, | 5489 | ocfs2_adjust_rightmost_records(handle, et, path, |
5365 | rec); | 5490 | rec); |
5366 | } | 5491 | } |
5367 | } else if (le32_to_cpu(rec->e_cpos) == cpos) { | 5492 | } else if (le32_to_cpu(rec->e_cpos) == cpos) { |
@@ -5373,11 +5498,12 @@ static int ocfs2_truncate_rec(struct inode *inode, handle_t *handle, | |||
5373 | /* Remove rightmost portion of the record */ | 5498 | /* Remove rightmost portion of the record */ |
5374 | le16_add_cpu(&rec->e_leaf_clusters, -len); | 5499 | le16_add_cpu(&rec->e_leaf_clusters, -len); |
5375 | if (is_rightmost_tree_rec) | 5500 | if (is_rightmost_tree_rec) |
5376 | ocfs2_adjust_rightmost_records(inode, handle, path, rec); | 5501 | ocfs2_adjust_rightmost_records(handle, et, path, rec); |
5377 | } else { | 5502 | } else { |
5378 | /* Caller should have trapped this. */ | 5503 | /* Caller should have trapped this. */ |
5379 | mlog(ML_ERROR, "Inode %llu: Invalid record truncate: (%u, %u) " | 5504 | mlog(ML_ERROR, "Owner %llu: Invalid record truncate: (%u, %u) " |
5380 | "(%u, %u)\n", (unsigned long long)OCFS2_I(inode)->ip_blkno, | 5505 | "(%u, %u)\n", |
5506 | (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci), | ||
5381 | le32_to_cpu(rec->e_cpos), | 5507 | le32_to_cpu(rec->e_cpos), |
5382 | le16_to_cpu(rec->e_leaf_clusters), cpos, len); | 5508 | le16_to_cpu(rec->e_leaf_clusters), cpos, len); |
5383 | BUG(); | 5509 | BUG(); |
@@ -5386,14 +5512,14 @@ static int ocfs2_truncate_rec(struct inode *inode, handle_t *handle, | |||
5386 | if (left_path) { | 5512 | if (left_path) { |
5387 | int subtree_index; | 5513 | int subtree_index; |
5388 | 5514 | ||
5389 | subtree_index = ocfs2_find_subtree_root(inode, left_path, path); | 5515 | subtree_index = ocfs2_find_subtree_root(et, left_path, path); |
5390 | ocfs2_complete_edge_insert(inode, handle, left_path, path, | 5516 | ocfs2_complete_edge_insert(handle, left_path, path, |
5391 | subtree_index); | 5517 | subtree_index); |
5392 | } | 5518 | } |
5393 | 5519 | ||
5394 | ocfs2_journal_dirty(handle, path_leaf_bh(path)); | 5520 | ocfs2_journal_dirty(handle, path_leaf_bh(path)); |
5395 | 5521 | ||
5396 | ret = ocfs2_rotate_tree_left(inode, handle, path, dealloc, et); | 5522 | ret = ocfs2_rotate_tree_left(handle, et, path, dealloc); |
5397 | if (ret) { | 5523 | if (ret) { |
5398 | mlog_errno(ret); | 5524 | mlog_errno(ret); |
5399 | goto out; | 5525 | goto out; |
@@ -5404,9 +5530,9 @@ out: | |||
5404 | return ret; | 5530 | return ret; |
5405 | } | 5531 | } |
5406 | 5532 | ||
5407 | int ocfs2_remove_extent(struct inode *inode, | 5533 | int ocfs2_remove_extent(handle_t *handle, |
5408 | struct ocfs2_extent_tree *et, | 5534 | struct ocfs2_extent_tree *et, |
5409 | u32 cpos, u32 len, handle_t *handle, | 5535 | u32 cpos, u32 len, |
5410 | struct ocfs2_alloc_context *meta_ac, | 5536 | struct ocfs2_alloc_context *meta_ac, |
5411 | struct ocfs2_cached_dealloc_ctxt *dealloc) | 5537 | struct ocfs2_cached_dealloc_ctxt *dealloc) |
5412 | { | 5538 | { |
@@ -5416,7 +5542,11 @@ int ocfs2_remove_extent(struct inode *inode, | |||
5416 | struct ocfs2_extent_list *el; | 5542 | struct ocfs2_extent_list *el; |
5417 | struct ocfs2_path *path = NULL; | 5543 | struct ocfs2_path *path = NULL; |
5418 | 5544 | ||
5419 | ocfs2_extent_map_trunc(inode, 0); | 5545 | /* |
5546 | * XXX: Why are we truncating to 0 instead of wherever this | ||
5547 | * affects us? | ||
5548 | */ | ||
5549 | ocfs2_et_extent_map_truncate(et, 0); | ||
5420 | 5550 | ||
5421 | path = ocfs2_new_path_from_et(et); | 5551 | path = ocfs2_new_path_from_et(et); |
5422 | if (!path) { | 5552 | if (!path) { |
@@ -5425,7 +5555,7 @@ int ocfs2_remove_extent(struct inode *inode, | |||
5425 | goto out; | 5555 | goto out; |
5426 | } | 5556 | } |
5427 | 5557 | ||
5428 | ret = ocfs2_find_path(inode, path, cpos); | 5558 | ret = ocfs2_find_path(et->et_ci, path, cpos); |
5429 | if (ret) { | 5559 | if (ret) { |
5430 | mlog_errno(ret); | 5560 | mlog_errno(ret); |
5431 | goto out; | 5561 | goto out; |
@@ -5434,10 +5564,11 @@ int ocfs2_remove_extent(struct inode *inode, | |||
5434 | el = path_leaf_el(path); | 5564 | el = path_leaf_el(path); |
5435 | index = ocfs2_search_extent_list(el, cpos); | 5565 | index = ocfs2_search_extent_list(el, cpos); |
5436 | if (index == -1 || index >= le16_to_cpu(el->l_next_free_rec)) { | 5566 | if (index == -1 || index >= le16_to_cpu(el->l_next_free_rec)) { |
5437 | ocfs2_error(inode->i_sb, | 5567 | ocfs2_error(ocfs2_metadata_cache_get_super(et->et_ci), |
5438 | "Inode %llu has an extent at cpos %u which can no " | 5568 | "Owner %llu has an extent at cpos %u which can no " |
5439 | "longer be found.\n", | 5569 | "longer be found.\n", |
5440 | (unsigned long long)OCFS2_I(inode)->ip_blkno, cpos); | 5570 | (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci), |
5571 | cpos); | ||
5441 | ret = -EROFS; | 5572 | ret = -EROFS; |
5442 | goto out; | 5573 | goto out; |
5443 | } | 5574 | } |
@@ -5464,20 +5595,21 @@ int ocfs2_remove_extent(struct inode *inode, | |||
5464 | 5595 | ||
5465 | BUG_ON(cpos < le32_to_cpu(rec->e_cpos) || trunc_range > rec_range); | 5596 | BUG_ON(cpos < le32_to_cpu(rec->e_cpos) || trunc_range > rec_range); |
5466 | 5597 | ||
5467 | mlog(0, "Inode %llu, remove (cpos %u, len %u). Existing index %d " | 5598 | mlog(0, "Owner %llu, remove (cpos %u, len %u). Existing index %d " |
5468 | "(cpos %u, len %u)\n", | 5599 | "(cpos %u, len %u)\n", |
5469 | (unsigned long long)OCFS2_I(inode)->ip_blkno, cpos, len, index, | 5600 | (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci), |
5601 | cpos, len, index, | ||
5470 | le32_to_cpu(rec->e_cpos), ocfs2_rec_clusters(el, rec)); | 5602 | le32_to_cpu(rec->e_cpos), ocfs2_rec_clusters(el, rec)); |
5471 | 5603 | ||
5472 | if (le32_to_cpu(rec->e_cpos) == cpos || rec_range == trunc_range) { | 5604 | if (le32_to_cpu(rec->e_cpos) == cpos || rec_range == trunc_range) { |
5473 | ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc, | 5605 | ret = ocfs2_truncate_rec(handle, et, path, index, dealloc, |
5474 | cpos, len, et); | 5606 | cpos, len); |
5475 | if (ret) { | 5607 | if (ret) { |
5476 | mlog_errno(ret); | 5608 | mlog_errno(ret); |
5477 | goto out; | 5609 | goto out; |
5478 | } | 5610 | } |
5479 | } else { | 5611 | } else { |
5480 | ret = ocfs2_split_tree(inode, et, handle, path, index, | 5612 | ret = ocfs2_split_tree(handle, et, path, index, |
5481 | trunc_range, meta_ac); | 5613 | trunc_range, meta_ac); |
5482 | if (ret) { | 5614 | if (ret) { |
5483 | mlog_errno(ret); | 5615 | mlog_errno(ret); |
@@ -5490,7 +5622,7 @@ int ocfs2_remove_extent(struct inode *inode, | |||
5490 | */ | 5622 | */ |
5491 | ocfs2_reinit_path(path, 1); | 5623 | ocfs2_reinit_path(path, 1); |
5492 | 5624 | ||
5493 | ret = ocfs2_find_path(inode, path, cpos); | 5625 | ret = ocfs2_find_path(et->et_ci, path, cpos); |
5494 | if (ret) { | 5626 | if (ret) { |
5495 | mlog_errno(ret); | 5627 | mlog_errno(ret); |
5496 | goto out; | 5628 | goto out; |
@@ -5499,9 +5631,9 @@ int ocfs2_remove_extent(struct inode *inode, | |||
5499 | el = path_leaf_el(path); | 5631 | el = path_leaf_el(path); |
5500 | index = ocfs2_search_extent_list(el, cpos); | 5632 | index = ocfs2_search_extent_list(el, cpos); |
5501 | if (index == -1 || index >= le16_to_cpu(el->l_next_free_rec)) { | 5633 | if (index == -1 || index >= le16_to_cpu(el->l_next_free_rec)) { |
5502 | ocfs2_error(inode->i_sb, | 5634 | ocfs2_error(ocfs2_metadata_cache_get_super(et->et_ci), |
5503 | "Inode %llu: split at cpos %u lost record.", | 5635 | "Owner %llu: split at cpos %u lost record.", |
5504 | (unsigned long long)OCFS2_I(inode)->ip_blkno, | 5636 | (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci), |
5505 | cpos); | 5637 | cpos); |
5506 | ret = -EROFS; | 5638 | ret = -EROFS; |
5507 | goto out; | 5639 | goto out; |
@@ -5515,18 +5647,18 @@ int ocfs2_remove_extent(struct inode *inode, | |||
5515 | rec_range = le32_to_cpu(rec->e_cpos) + | 5647 | rec_range = le32_to_cpu(rec->e_cpos) + |
5516 | ocfs2_rec_clusters(el, rec); | 5648 | ocfs2_rec_clusters(el, rec); |
5517 | if (rec_range != trunc_range) { | 5649 | if (rec_range != trunc_range) { |
5518 | ocfs2_error(inode->i_sb, | 5650 | ocfs2_error(ocfs2_metadata_cache_get_super(et->et_ci), |
5519 | "Inode %llu: error after split at cpos %u" | 5651 | "Owner %llu: error after split at cpos %u" |
5520 | "trunc len %u, existing record is (%u,%u)", | 5652 | "trunc len %u, existing record is (%u,%u)", |
5521 | (unsigned long long)OCFS2_I(inode)->ip_blkno, | 5653 | (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci), |
5522 | cpos, len, le32_to_cpu(rec->e_cpos), | 5654 | cpos, len, le32_to_cpu(rec->e_cpos), |
5523 | ocfs2_rec_clusters(el, rec)); | 5655 | ocfs2_rec_clusters(el, rec)); |
5524 | ret = -EROFS; | 5656 | ret = -EROFS; |
5525 | goto out; | 5657 | goto out; |
5526 | } | 5658 | } |
5527 | 5659 | ||
5528 | ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc, | 5660 | ret = ocfs2_truncate_rec(handle, et, path, index, dealloc, |
5529 | cpos, len, et); | 5661 | cpos, len); |
5530 | if (ret) { | 5662 | if (ret) { |
5531 | mlog_errno(ret); | 5663 | mlog_errno(ret); |
5532 | goto out; | 5664 | goto out; |
@@ -5573,7 +5705,7 @@ int ocfs2_remove_btree_range(struct inode *inode, | |||
5573 | goto out; | 5705 | goto out; |
5574 | } | 5706 | } |
5575 | 5707 | ||
5576 | ret = ocfs2_et_root_journal_access(handle, inode, et, | 5708 | ret = ocfs2_et_root_journal_access(handle, et, |
5577 | OCFS2_JOURNAL_ACCESS_WRITE); | 5709 | OCFS2_JOURNAL_ACCESS_WRITE); |
5578 | if (ret) { | 5710 | if (ret) { |
5579 | mlog_errno(ret); | 5711 | mlog_errno(ret); |
@@ -5583,14 +5715,13 @@ int ocfs2_remove_btree_range(struct inode *inode, | |||
5583 | vfs_dq_free_space_nodirty(inode, | 5715 | vfs_dq_free_space_nodirty(inode, |
5584 | ocfs2_clusters_to_bytes(inode->i_sb, len)); | 5716 | ocfs2_clusters_to_bytes(inode->i_sb, len)); |
5585 | 5717 | ||
5586 | ret = ocfs2_remove_extent(inode, et, cpos, len, handle, meta_ac, | 5718 | ret = ocfs2_remove_extent(handle, et, cpos, len, meta_ac, dealloc); |
5587 | dealloc); | ||
5588 | if (ret) { | 5719 | if (ret) { |
5589 | mlog_errno(ret); | 5720 | mlog_errno(ret); |
5590 | goto out_commit; | 5721 | goto out_commit; |
5591 | } | 5722 | } |
5592 | 5723 | ||
5593 | ocfs2_et_update_clusters(inode, et, -len); | 5724 | ocfs2_et_update_clusters(et, -len); |
5594 | 5725 | ||
5595 | ret = ocfs2_journal_dirty(handle, et->et_root_bh); | 5726 | ret = ocfs2_journal_dirty(handle, et->et_root_bh); |
5596 | if (ret) { | 5727 | if (ret) { |
@@ -5690,7 +5821,7 @@ int ocfs2_truncate_log_append(struct ocfs2_super *osb, | |||
5690 | goto bail; | 5821 | goto bail; |
5691 | } | 5822 | } |
5692 | 5823 | ||
5693 | status = ocfs2_journal_access_di(handle, tl_inode, tl_bh, | 5824 | status = ocfs2_journal_access_di(handle, INODE_CACHE(tl_inode), tl_bh, |
5694 | OCFS2_JOURNAL_ACCESS_WRITE); | 5825 | OCFS2_JOURNAL_ACCESS_WRITE); |
5695 | if (status < 0) { | 5826 | if (status < 0) { |
5696 | mlog_errno(status); | 5827 | mlog_errno(status); |
@@ -5752,7 +5883,7 @@ static int ocfs2_replay_truncate_records(struct ocfs2_super *osb, | |||
5752 | while (i >= 0) { | 5883 | while (i >= 0) { |
5753 | /* Caller has given us at least enough credits to | 5884 | /* Caller has given us at least enough credits to |
5754 | * update the truncate log dinode */ | 5885 | * update the truncate log dinode */ |
5755 | status = ocfs2_journal_access_di(handle, tl_inode, tl_bh, | 5886 | status = ocfs2_journal_access_di(handle, INODE_CACHE(tl_inode), tl_bh, |
5756 | OCFS2_JOURNAL_ACCESS_WRITE); | 5887 | OCFS2_JOURNAL_ACCESS_WRITE); |
5757 | if (status < 0) { | 5888 | if (status < 0) { |
5758 | mlog_errno(status); | 5889 | mlog_errno(status); |
@@ -6010,7 +6141,7 @@ int ocfs2_begin_truncate_log_recovery(struct ocfs2_super *osb, | |||
6010 | tl->tl_used = 0; | 6141 | tl->tl_used = 0; |
6011 | 6142 | ||
6012 | ocfs2_compute_meta_ecc(osb->sb, tl_bh->b_data, &di->i_check); | 6143 | ocfs2_compute_meta_ecc(osb->sb, tl_bh->b_data, &di->i_check); |
6013 | status = ocfs2_write_block(osb, tl_bh, tl_inode); | 6144 | status = ocfs2_write_block(osb, tl_bh, INODE_CACHE(tl_inode)); |
6014 | if (status < 0) { | 6145 | if (status < 0) { |
6015 | mlog_errno(status); | 6146 | mlog_errno(status); |
6016 | goto bail; | 6147 | goto bail; |
@@ -6400,9 +6531,9 @@ ocfs2_find_per_slot_free_list(int type, | |||
6400 | return fl; | 6531 | return fl; |
6401 | } | 6532 | } |
6402 | 6533 | ||
6403 | static int ocfs2_cache_block_dealloc(struct ocfs2_cached_dealloc_ctxt *ctxt, | 6534 | int ocfs2_cache_block_dealloc(struct ocfs2_cached_dealloc_ctxt *ctxt, |
6404 | int type, int slot, u64 blkno, | 6535 | int type, int slot, u64 blkno, |
6405 | unsigned int bit) | 6536 | unsigned int bit) |
6406 | { | 6537 | { |
6407 | int ret; | 6538 | int ret; |
6408 | struct ocfs2_per_slot_free_list *fl; | 6539 | struct ocfs2_per_slot_free_list *fl; |
@@ -6518,7 +6649,7 @@ static int ocfs2_find_new_last_ext_blk(struct inode *inode, | |||
6518 | goto out; | 6649 | goto out; |
6519 | } | 6650 | } |
6520 | 6651 | ||
6521 | ret = ocfs2_find_leaf(inode, path_root_el(path), cpos, &bh); | 6652 | ret = ocfs2_find_leaf(INODE_CACHE(inode), path_root_el(path), cpos, &bh); |
6522 | if (ret) { | 6653 | if (ret) { |
6523 | mlog_errno(ret); | 6654 | mlog_errno(ret); |
6524 | goto out; | 6655 | goto out; |
@@ -6551,7 +6682,7 @@ out: | |||
6551 | */ | 6682 | */ |
6552 | static int ocfs2_trim_tree(struct inode *inode, struct ocfs2_path *path, | 6683 | static int ocfs2_trim_tree(struct inode *inode, struct ocfs2_path *path, |
6553 | handle_t *handle, struct ocfs2_truncate_context *tc, | 6684 | handle_t *handle, struct ocfs2_truncate_context *tc, |
6554 | u32 clusters_to_del, u64 *delete_start) | 6685 | u32 clusters_to_del, u64 *delete_start, u8 *flags) |
6555 | { | 6686 | { |
6556 | int ret, i, index = path->p_tree_depth; | 6687 | int ret, i, index = path->p_tree_depth; |
6557 | u32 new_edge = 0; | 6688 | u32 new_edge = 0; |
@@ -6561,6 +6692,7 @@ static int ocfs2_trim_tree(struct inode *inode, struct ocfs2_path *path, | |||
6561 | struct ocfs2_extent_rec *rec; | 6692 | struct ocfs2_extent_rec *rec; |
6562 | 6693 | ||
6563 | *delete_start = 0; | 6694 | *delete_start = 0; |
6695 | *flags = 0; | ||
6564 | 6696 | ||
6565 | while (index >= 0) { | 6697 | while (index >= 0) { |
6566 | bh = path->p_node[index].bh; | 6698 | bh = path->p_node[index].bh; |
@@ -6648,6 +6780,7 @@ find_tail_record: | |||
6648 | *delete_start = le64_to_cpu(rec->e_blkno) | 6780 | *delete_start = le64_to_cpu(rec->e_blkno) |
6649 | + ocfs2_clusters_to_blocks(inode->i_sb, | 6781 | + ocfs2_clusters_to_blocks(inode->i_sb, |
6650 | le16_to_cpu(rec->e_leaf_clusters)); | 6782 | le16_to_cpu(rec->e_leaf_clusters)); |
6783 | *flags = rec->e_flags; | ||
6651 | 6784 | ||
6652 | /* | 6785 | /* |
6653 | * If it's now empty, remove this record. | 6786 | * If it's now empty, remove this record. |
@@ -6719,7 +6852,7 @@ delete: | |||
6719 | 6852 | ||
6720 | mlog(0, "deleting this extent block.\n"); | 6853 | mlog(0, "deleting this extent block.\n"); |
6721 | 6854 | ||
6722 | ocfs2_remove_from_cache(inode, bh); | 6855 | ocfs2_remove_from_cache(INODE_CACHE(inode), bh); |
6723 | 6856 | ||
6724 | BUG_ON(ocfs2_rec_clusters(el, &el->l_recs[0])); | 6857 | BUG_ON(ocfs2_rec_clusters(el, &el->l_recs[0])); |
6725 | BUG_ON(le32_to_cpu(el->l_recs[0].e_cpos)); | 6858 | BUG_ON(le32_to_cpu(el->l_recs[0].e_cpos)); |
@@ -6747,7 +6880,8 @@ static int ocfs2_do_truncate(struct ocfs2_super *osb, | |||
6747 | struct buffer_head *fe_bh, | 6880 | struct buffer_head *fe_bh, |
6748 | handle_t *handle, | 6881 | handle_t *handle, |
6749 | struct ocfs2_truncate_context *tc, | 6882 | struct ocfs2_truncate_context *tc, |
6750 | struct ocfs2_path *path) | 6883 | struct ocfs2_path *path, |
6884 | struct ocfs2_alloc_context *meta_ac) | ||
6751 | { | 6885 | { |
6752 | int status; | 6886 | int status; |
6753 | struct ocfs2_dinode *fe; | 6887 | struct ocfs2_dinode *fe; |
@@ -6755,6 +6889,7 @@ static int ocfs2_do_truncate(struct ocfs2_super *osb, | |||
6755 | struct ocfs2_extent_list *el; | 6889 | struct ocfs2_extent_list *el; |
6756 | struct buffer_head *last_eb_bh = NULL; | 6890 | struct buffer_head *last_eb_bh = NULL; |
6757 | u64 delete_blk = 0; | 6891 | u64 delete_blk = 0; |
6892 | u8 rec_flags; | ||
6758 | 6893 | ||
6759 | fe = (struct ocfs2_dinode *) fe_bh->b_data; | 6894 | fe = (struct ocfs2_dinode *) fe_bh->b_data; |
6760 | 6895 | ||
@@ -6769,14 +6904,14 @@ static int ocfs2_do_truncate(struct ocfs2_super *osb, | |||
6769 | * Each component will be touched, so we might as well journal | 6904 | * Each component will be touched, so we might as well journal |
6770 | * here to avoid having to handle errors later. | 6905 | * here to avoid having to handle errors later. |
6771 | */ | 6906 | */ |
6772 | status = ocfs2_journal_access_path(inode, handle, path); | 6907 | status = ocfs2_journal_access_path(INODE_CACHE(inode), handle, path); |
6773 | if (status < 0) { | 6908 | if (status < 0) { |
6774 | mlog_errno(status); | 6909 | mlog_errno(status); |
6775 | goto bail; | 6910 | goto bail; |
6776 | } | 6911 | } |
6777 | 6912 | ||
6778 | if (last_eb_bh) { | 6913 | if (last_eb_bh) { |
6779 | status = ocfs2_journal_access_eb(handle, inode, last_eb_bh, | 6914 | status = ocfs2_journal_access_eb(handle, INODE_CACHE(inode), last_eb_bh, |
6780 | OCFS2_JOURNAL_ACCESS_WRITE); | 6915 | OCFS2_JOURNAL_ACCESS_WRITE); |
6781 | if (status < 0) { | 6916 | if (status < 0) { |
6782 | mlog_errno(status); | 6917 | mlog_errno(status); |
@@ -6810,7 +6945,7 @@ static int ocfs2_do_truncate(struct ocfs2_super *osb, | |||
6810 | inode->i_blocks = ocfs2_inode_sector_count(inode); | 6945 | inode->i_blocks = ocfs2_inode_sector_count(inode); |
6811 | 6946 | ||
6812 | status = ocfs2_trim_tree(inode, path, handle, tc, | 6947 | status = ocfs2_trim_tree(inode, path, handle, tc, |
6813 | clusters_to_del, &delete_blk); | 6948 | clusters_to_del, &delete_blk, &rec_flags); |
6814 | if (status) { | 6949 | if (status) { |
6815 | mlog_errno(status); | 6950 | mlog_errno(status); |
6816 | goto bail; | 6951 | goto bail; |
@@ -6842,8 +6977,16 @@ static int ocfs2_do_truncate(struct ocfs2_super *osb, | |||
6842 | } | 6977 | } |
6843 | 6978 | ||
6844 | if (delete_blk) { | 6979 | if (delete_blk) { |
6845 | status = ocfs2_truncate_log_append(osb, handle, delete_blk, | 6980 | if (rec_flags & OCFS2_EXT_REFCOUNTED) |
6846 | clusters_to_del); | 6981 | status = ocfs2_decrease_refcount(inode, handle, |
6982 | ocfs2_blocks_to_clusters(osb->sb, | ||
6983 | delete_blk), | ||
6984 | clusters_to_del, meta_ac, | ||
6985 | &tc->tc_dealloc, 1); | ||
6986 | else | ||
6987 | status = ocfs2_truncate_log_append(osb, handle, | ||
6988 | delete_blk, | ||
6989 | clusters_to_del); | ||
6847 | if (status < 0) { | 6990 | if (status < 0) { |
6848 | mlog_errno(status); | 6991 | mlog_errno(status); |
6849 | goto bail; | 6992 | goto bail; |
@@ -6863,9 +7006,9 @@ static int ocfs2_zero_func(handle_t *handle, struct buffer_head *bh) | |||
6863 | return 0; | 7006 | return 0; |
6864 | } | 7007 | } |
6865 | 7008 | ||
6866 | static void ocfs2_map_and_dirty_page(struct inode *inode, handle_t *handle, | 7009 | void ocfs2_map_and_dirty_page(struct inode *inode, handle_t *handle, |
6867 | unsigned int from, unsigned int to, | 7010 | unsigned int from, unsigned int to, |
6868 | struct page *page, int zero, u64 *phys) | 7011 | struct page *page, int zero, u64 *phys) |
6869 | { | 7012 | { |
6870 | int ret, partial = 0; | 7013 | int ret, partial = 0; |
6871 | 7014 | ||
@@ -6933,20 +7076,16 @@ out: | |||
6933 | ocfs2_unlock_and_free_pages(pages, numpages); | 7076 | ocfs2_unlock_and_free_pages(pages, numpages); |
6934 | } | 7077 | } |
6935 | 7078 | ||
6936 | static int ocfs2_grab_eof_pages(struct inode *inode, loff_t start, loff_t end, | 7079 | int ocfs2_grab_pages(struct inode *inode, loff_t start, loff_t end, |
6937 | struct page **pages, int *num) | 7080 | struct page **pages, int *num) |
6938 | { | 7081 | { |
6939 | int numpages, ret = 0; | 7082 | int numpages, ret = 0; |
6940 | struct super_block *sb = inode->i_sb; | ||
6941 | struct address_space *mapping = inode->i_mapping; | 7083 | struct address_space *mapping = inode->i_mapping; |
6942 | unsigned long index; | 7084 | unsigned long index; |
6943 | loff_t last_page_bytes; | 7085 | loff_t last_page_bytes; |
6944 | 7086 | ||
6945 | BUG_ON(start > end); | 7087 | BUG_ON(start > end); |
6946 | 7088 | ||
6947 | BUG_ON(start >> OCFS2_SB(sb)->s_clustersize_bits != | ||
6948 | (end - 1) >> OCFS2_SB(sb)->s_clustersize_bits); | ||
6949 | |||
6950 | numpages = 0; | 7089 | numpages = 0; |
6951 | last_page_bytes = PAGE_ALIGN(end); | 7090 | last_page_bytes = PAGE_ALIGN(end); |
6952 | index = start >> PAGE_CACHE_SHIFT; | 7091 | index = start >> PAGE_CACHE_SHIFT; |
@@ -6974,6 +7113,17 @@ out: | |||
6974 | return ret; | 7113 | return ret; |
6975 | } | 7114 | } |
6976 | 7115 | ||
7116 | static int ocfs2_grab_eof_pages(struct inode *inode, loff_t start, loff_t end, | ||
7117 | struct page **pages, int *num) | ||
7118 | { | ||
7119 | struct super_block *sb = inode->i_sb; | ||
7120 | |||
7121 | BUG_ON(start >> OCFS2_SB(sb)->s_clustersize_bits != | ||
7122 | (end - 1) >> OCFS2_SB(sb)->s_clustersize_bits); | ||
7123 | |||
7124 | return ocfs2_grab_pages(inode, start, end, pages, num); | ||
7125 | } | ||
7126 | |||
6977 | /* | 7127 | /* |
6978 | * Zero the area past i_size but still within an allocated | 7128 | * Zero the area past i_size but still within an allocated |
6979 | * cluster. This avoids exposing nonzero data on subsequent file | 7129 | * cluster. This avoids exposing nonzero data on subsequent file |
@@ -7138,7 +7288,7 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode, | |||
7138 | goto out_unlock; | 7288 | goto out_unlock; |
7139 | } | 7289 | } |
7140 | 7290 | ||
7141 | ret = ocfs2_journal_access_di(handle, inode, di_bh, | 7291 | ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), di_bh, |
7142 | OCFS2_JOURNAL_ACCESS_WRITE); | 7292 | OCFS2_JOURNAL_ACCESS_WRITE); |
7143 | if (ret) { | 7293 | if (ret) { |
7144 | mlog_errno(ret); | 7294 | mlog_errno(ret); |
@@ -7218,9 +7368,8 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode, | |||
7218 | * this proves to be false, we could always re-build | 7368 | * this proves to be false, we could always re-build |
7219 | * the in-inode data from our pages. | 7369 | * the in-inode data from our pages. |
7220 | */ | 7370 | */ |
7221 | ocfs2_init_dinode_extent_tree(&et, inode, di_bh); | 7371 | ocfs2_init_dinode_extent_tree(&et, INODE_CACHE(inode), di_bh); |
7222 | ret = ocfs2_insert_extent(osb, handle, inode, &et, | 7372 | ret = ocfs2_insert_extent(handle, &et, 0, block, 1, 0, NULL); |
7223 | 0, block, 1, 0, NULL); | ||
7224 | if (ret) { | 7373 | if (ret) { |
7225 | mlog_errno(ret); | 7374 | mlog_errno(ret); |
7226 | goto out_commit; | 7375 | goto out_commit; |
@@ -7262,11 +7411,14 @@ int ocfs2_commit_truncate(struct ocfs2_super *osb, | |||
7262 | { | 7411 | { |
7263 | int status, i, credits, tl_sem = 0; | 7412 | int status, i, credits, tl_sem = 0; |
7264 | u32 clusters_to_del, new_highest_cpos, range; | 7413 | u32 clusters_to_del, new_highest_cpos, range; |
7414 | u64 blkno = 0; | ||
7265 | struct ocfs2_extent_list *el; | 7415 | struct ocfs2_extent_list *el; |
7266 | handle_t *handle = NULL; | 7416 | handle_t *handle = NULL; |
7267 | struct inode *tl_inode = osb->osb_tl_inode; | 7417 | struct inode *tl_inode = osb->osb_tl_inode; |
7268 | struct ocfs2_path *path = NULL; | 7418 | struct ocfs2_path *path = NULL; |
7269 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)fe_bh->b_data; | 7419 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)fe_bh->b_data; |
7420 | struct ocfs2_alloc_context *meta_ac = NULL; | ||
7421 | struct ocfs2_refcount_tree *ref_tree = NULL; | ||
7270 | 7422 | ||
7271 | mlog_entry_void(); | 7423 | mlog_entry_void(); |
7272 | 7424 | ||
@@ -7292,10 +7444,12 @@ start: | |||
7292 | goto bail; | 7444 | goto bail; |
7293 | } | 7445 | } |
7294 | 7446 | ||
7447 | credits = 0; | ||
7448 | |||
7295 | /* | 7449 | /* |
7296 | * Truncate always works against the rightmost tree branch. | 7450 | * Truncate always works against the rightmost tree branch. |
7297 | */ | 7451 | */ |
7298 | status = ocfs2_find_path(inode, path, UINT_MAX); | 7452 | status = ocfs2_find_path(INODE_CACHE(inode), path, UINT_MAX); |
7299 | if (status) { | 7453 | if (status) { |
7300 | mlog_errno(status); | 7454 | mlog_errno(status); |
7301 | goto bail; | 7455 | goto bail; |
@@ -7332,10 +7486,15 @@ start: | |||
7332 | clusters_to_del = 0; | 7486 | clusters_to_del = 0; |
7333 | } else if (le32_to_cpu(el->l_recs[i].e_cpos) >= new_highest_cpos) { | 7487 | } else if (le32_to_cpu(el->l_recs[i].e_cpos) >= new_highest_cpos) { |
7334 | clusters_to_del = ocfs2_rec_clusters(el, &el->l_recs[i]); | 7488 | clusters_to_del = ocfs2_rec_clusters(el, &el->l_recs[i]); |
7489 | blkno = le64_to_cpu(el->l_recs[i].e_blkno); | ||
7335 | } else if (range > new_highest_cpos) { | 7490 | } else if (range > new_highest_cpos) { |
7336 | clusters_to_del = (ocfs2_rec_clusters(el, &el->l_recs[i]) + | 7491 | clusters_to_del = (ocfs2_rec_clusters(el, &el->l_recs[i]) + |
7337 | le32_to_cpu(el->l_recs[i].e_cpos)) - | 7492 | le32_to_cpu(el->l_recs[i].e_cpos)) - |
7338 | new_highest_cpos; | 7493 | new_highest_cpos; |
7494 | blkno = le64_to_cpu(el->l_recs[i].e_blkno) + | ||
7495 | ocfs2_clusters_to_blocks(inode->i_sb, | ||
7496 | ocfs2_rec_clusters(el, &el->l_recs[i]) - | ||
7497 | clusters_to_del); | ||
7339 | } else { | 7498 | } else { |
7340 | status = 0; | 7499 | status = 0; |
7341 | goto bail; | 7500 | goto bail; |
@@ -7344,6 +7503,29 @@ start: | |||
7344 | mlog(0, "clusters_to_del = %u in this pass, tail blk=%llu\n", | 7503 | mlog(0, "clusters_to_del = %u in this pass, tail blk=%llu\n", |
7345 | clusters_to_del, (unsigned long long)path_leaf_bh(path)->b_blocknr); | 7504 | clusters_to_del, (unsigned long long)path_leaf_bh(path)->b_blocknr); |
7346 | 7505 | ||
7506 | if (el->l_recs[i].e_flags & OCFS2_EXT_REFCOUNTED && clusters_to_del) { | ||
7507 | BUG_ON(!(OCFS2_I(inode)->ip_dyn_features & | ||
7508 | OCFS2_HAS_REFCOUNT_FL)); | ||
7509 | |||
7510 | status = ocfs2_lock_refcount_tree(osb, | ||
7511 | le64_to_cpu(di->i_refcount_loc), | ||
7512 | 1, &ref_tree, NULL); | ||
7513 | if (status) { | ||
7514 | mlog_errno(status); | ||
7515 | goto bail; | ||
7516 | } | ||
7517 | |||
7518 | status = ocfs2_prepare_refcount_change_for_del(inode, fe_bh, | ||
7519 | blkno, | ||
7520 | clusters_to_del, | ||
7521 | &credits, | ||
7522 | &meta_ac); | ||
7523 | if (status < 0) { | ||
7524 | mlog_errno(status); | ||
7525 | goto bail; | ||
7526 | } | ||
7527 | } | ||
7528 | |||
7347 | mutex_lock(&tl_inode->i_mutex); | 7529 | mutex_lock(&tl_inode->i_mutex); |
7348 | tl_sem = 1; | 7530 | tl_sem = 1; |
7349 | /* ocfs2_truncate_log_needs_flush guarantees us at least one | 7531 | /* ocfs2_truncate_log_needs_flush guarantees us at least one |
@@ -7357,7 +7539,7 @@ start: | |||
7357 | } | 7539 | } |
7358 | } | 7540 | } |
7359 | 7541 | ||
7360 | credits = ocfs2_calc_tree_trunc_credits(osb->sb, clusters_to_del, | 7542 | credits += ocfs2_calc_tree_trunc_credits(osb->sb, clusters_to_del, |
7361 | (struct ocfs2_dinode *)fe_bh->b_data, | 7543 | (struct ocfs2_dinode *)fe_bh->b_data, |
7362 | el); | 7544 | el); |
7363 | handle = ocfs2_start_trans(osb, credits); | 7545 | handle = ocfs2_start_trans(osb, credits); |
@@ -7369,7 +7551,7 @@ start: | |||
7369 | } | 7551 | } |
7370 | 7552 | ||
7371 | status = ocfs2_do_truncate(osb, clusters_to_del, inode, fe_bh, handle, | 7553 | status = ocfs2_do_truncate(osb, clusters_to_del, inode, fe_bh, handle, |
7372 | tc, path); | 7554 | tc, path, meta_ac); |
7373 | if (status < 0) { | 7555 | if (status < 0) { |
7374 | mlog_errno(status); | 7556 | mlog_errno(status); |
7375 | goto bail; | 7557 | goto bail; |
@@ -7383,6 +7565,16 @@ start: | |||
7383 | 7565 | ||
7384 | ocfs2_reinit_path(path, 1); | 7566 | ocfs2_reinit_path(path, 1); |
7385 | 7567 | ||
7568 | if (meta_ac) { | ||
7569 | ocfs2_free_alloc_context(meta_ac); | ||
7570 | meta_ac = NULL; | ||
7571 | } | ||
7572 | |||
7573 | if (ref_tree) { | ||
7574 | ocfs2_unlock_refcount_tree(osb, ref_tree, 1); | ||
7575 | ref_tree = NULL; | ||
7576 | } | ||
7577 | |||
7386 | /* | 7578 | /* |
7387 | * The check above will catch the case where we've truncated | 7579 | * The check above will catch the case where we've truncated |
7388 | * away all allocation. | 7580 | * away all allocation. |
@@ -7399,6 +7591,12 @@ bail: | |||
7399 | if (handle) | 7591 | if (handle) |
7400 | ocfs2_commit_trans(osb, handle); | 7592 | ocfs2_commit_trans(osb, handle); |
7401 | 7593 | ||
7594 | if (meta_ac) | ||
7595 | ocfs2_free_alloc_context(meta_ac); | ||
7596 | |||
7597 | if (ref_tree) | ||
7598 | ocfs2_unlock_refcount_tree(osb, ref_tree, 1); | ||
7599 | |||
7402 | ocfs2_run_deallocs(osb, &tc->tc_dealloc); | 7600 | ocfs2_run_deallocs(osb, &tc->tc_dealloc); |
7403 | 7601 | ||
7404 | ocfs2_free_path(path); | 7602 | ocfs2_free_path(path); |
@@ -7445,7 +7643,7 @@ int ocfs2_prepare_truncate(struct ocfs2_super *osb, | |||
7445 | ocfs2_init_dealloc_ctxt(&(*tc)->tc_dealloc); | 7643 | ocfs2_init_dealloc_ctxt(&(*tc)->tc_dealloc); |
7446 | 7644 | ||
7447 | if (fe->id2.i_list.l_tree_depth) { | 7645 | if (fe->id2.i_list.l_tree_depth) { |
7448 | status = ocfs2_read_extent_block(inode, | 7646 | status = ocfs2_read_extent_block(INODE_CACHE(inode), |
7449 | le64_to_cpu(fe->i_last_eb_blk), | 7647 | le64_to_cpu(fe->i_last_eb_blk), |
7450 | &last_eb_bh); | 7648 | &last_eb_bh); |
7451 | if (status < 0) { | 7649 | if (status < 0) { |
@@ -7507,7 +7705,7 @@ int ocfs2_truncate_inline(struct inode *inode, struct buffer_head *di_bh, | |||
7507 | goto out; | 7705 | goto out; |
7508 | } | 7706 | } |
7509 | 7707 | ||
7510 | ret = ocfs2_journal_access_di(handle, inode, di_bh, | 7708 | ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), di_bh, |
7511 | OCFS2_JOURNAL_ACCESS_WRITE); | 7709 | OCFS2_JOURNAL_ACCESS_WRITE); |
7512 | if (ret) { | 7710 | if (ret) { |
7513 | mlog_errno(ret); | 7711 | mlog_errno(ret); |