diff options
Diffstat (limited to 'fs/ocfs2/alloc.c')
-rw-r--r-- | fs/ocfs2/alloc.c | 715 |
1 files changed, 490 insertions, 225 deletions
diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c index 0cc2deb9394c..60fe74035db5 100644 --- a/fs/ocfs2/alloc.c +++ b/fs/ocfs2/alloc.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <linux/slab.h> | 28 | #include <linux/slab.h> |
29 | #include <linux/highmem.h> | 29 | #include <linux/highmem.h> |
30 | #include <linux/swap.h> | 30 | #include <linux/swap.h> |
31 | #include <linux/quotaops.h> | ||
31 | 32 | ||
32 | #define MLOG_MASK_PREFIX ML_DISK_ALLOC | 33 | #define MLOG_MASK_PREFIX ML_DISK_ALLOC |
33 | #include <cluster/masklog.h> | 34 | #include <cluster/masklog.h> |
@@ -36,6 +37,7 @@ | |||
36 | 37 | ||
37 | #include "alloc.h" | 38 | #include "alloc.h" |
38 | #include "aops.h" | 39 | #include "aops.h" |
40 | #include "blockcheck.h" | ||
39 | #include "dlmglue.h" | 41 | #include "dlmglue.h" |
40 | #include "extent_map.h" | 42 | #include "extent_map.h" |
41 | #include "inode.h" | 43 | #include "inode.h" |
@@ -46,6 +48,7 @@ | |||
46 | #include "file.h" | 48 | #include "file.h" |
47 | #include "super.h" | 49 | #include "super.h" |
48 | #include "uptodate.h" | 50 | #include "uptodate.h" |
51 | #include "xattr.h" | ||
49 | 52 | ||
50 | #include "buffer_head_io.h" | 53 | #include "buffer_head_io.h" |
51 | 54 | ||
@@ -187,20 +190,12 @@ static int ocfs2_dinode_insert_check(struct inode *inode, | |||
187 | static int ocfs2_dinode_sanity_check(struct inode *inode, | 190 | static int ocfs2_dinode_sanity_check(struct inode *inode, |
188 | struct ocfs2_extent_tree *et) | 191 | struct ocfs2_extent_tree *et) |
189 | { | 192 | { |
190 | int ret = 0; | 193 | struct ocfs2_dinode *di = et->et_object; |
191 | struct ocfs2_dinode *di; | ||
192 | 194 | ||
193 | BUG_ON(et->et_ops != &ocfs2_dinode_et_ops); | 195 | BUG_ON(et->et_ops != &ocfs2_dinode_et_ops); |
196 | BUG_ON(!OCFS2_IS_VALID_DINODE(di)); | ||
194 | 197 | ||
195 | di = et->et_object; | 198 | return 0; |
196 | if (!OCFS2_IS_VALID_DINODE(di)) { | ||
197 | ret = -EIO; | ||
198 | ocfs2_error(inode->i_sb, | ||
199 | "Inode %llu has invalid path root", | ||
200 | (unsigned long long)OCFS2_I(inode)->ip_blkno); | ||
201 | } | ||
202 | |||
203 | return ret; | ||
204 | } | 199 | } |
205 | 200 | ||
206 | static void ocfs2_dinode_fill_root_el(struct ocfs2_extent_tree *et) | 201 | static void ocfs2_dinode_fill_root_el(struct ocfs2_extent_tree *et) |
@@ -213,36 +208,33 @@ static void ocfs2_dinode_fill_root_el(struct ocfs2_extent_tree *et) | |||
213 | 208 | ||
214 | static void ocfs2_xattr_value_fill_root_el(struct ocfs2_extent_tree *et) | 209 | static void ocfs2_xattr_value_fill_root_el(struct ocfs2_extent_tree *et) |
215 | { | 210 | { |
216 | struct ocfs2_xattr_value_root *xv = et->et_object; | 211 | struct ocfs2_xattr_value_buf *vb = et->et_object; |
217 | 212 | ||
218 | et->et_root_el = &xv->xr_list; | 213 | et->et_root_el = &vb->vb_xv->xr_list; |
219 | } | 214 | } |
220 | 215 | ||
221 | static void ocfs2_xattr_value_set_last_eb_blk(struct ocfs2_extent_tree *et, | 216 | static void ocfs2_xattr_value_set_last_eb_blk(struct ocfs2_extent_tree *et, |
222 | u64 blkno) | 217 | u64 blkno) |
223 | { | 218 | { |
224 | struct ocfs2_xattr_value_root *xv = | 219 | struct ocfs2_xattr_value_buf *vb = et->et_object; |
225 | (struct ocfs2_xattr_value_root *)et->et_object; | ||
226 | 220 | ||
227 | xv->xr_last_eb_blk = cpu_to_le64(blkno); | 221 | vb->vb_xv->xr_last_eb_blk = cpu_to_le64(blkno); |
228 | } | 222 | } |
229 | 223 | ||
230 | static u64 ocfs2_xattr_value_get_last_eb_blk(struct ocfs2_extent_tree *et) | 224 | static u64 ocfs2_xattr_value_get_last_eb_blk(struct ocfs2_extent_tree *et) |
231 | { | 225 | { |
232 | struct ocfs2_xattr_value_root *xv = | 226 | struct ocfs2_xattr_value_buf *vb = et->et_object; |
233 | (struct ocfs2_xattr_value_root *) et->et_object; | ||
234 | 227 | ||
235 | return le64_to_cpu(xv->xr_last_eb_blk); | 228 | return le64_to_cpu(vb->vb_xv->xr_last_eb_blk); |
236 | } | 229 | } |
237 | 230 | ||
238 | static void ocfs2_xattr_value_update_clusters(struct inode *inode, | 231 | static void ocfs2_xattr_value_update_clusters(struct inode *inode, |
239 | struct ocfs2_extent_tree *et, | 232 | struct ocfs2_extent_tree *et, |
240 | u32 clusters) | 233 | u32 clusters) |
241 | { | 234 | { |
242 | struct ocfs2_xattr_value_root *xv = | 235 | struct ocfs2_xattr_value_buf *vb = et->et_object; |
243 | (struct ocfs2_xattr_value_root *)et->et_object; | ||
244 | 236 | ||
245 | le32_add_cpu(&xv->xr_clusters, clusters); | 237 | le32_add_cpu(&vb->vb_xv->xr_clusters, clusters); |
246 | } | 238 | } |
247 | 239 | ||
248 | static struct ocfs2_extent_tree_operations ocfs2_xattr_value_et_ops = { | 240 | static struct ocfs2_extent_tree_operations ocfs2_xattr_value_et_ops = { |
@@ -304,11 +296,13 @@ static struct ocfs2_extent_tree_operations ocfs2_xattr_tree_et_ops = { | |||
304 | static void __ocfs2_init_extent_tree(struct ocfs2_extent_tree *et, | 296 | static void __ocfs2_init_extent_tree(struct ocfs2_extent_tree *et, |
305 | struct inode *inode, | 297 | struct inode *inode, |
306 | struct buffer_head *bh, | 298 | struct buffer_head *bh, |
299 | ocfs2_journal_access_func access, | ||
307 | void *obj, | 300 | void *obj, |
308 | struct ocfs2_extent_tree_operations *ops) | 301 | struct ocfs2_extent_tree_operations *ops) |
309 | { | 302 | { |
310 | et->et_ops = ops; | 303 | et->et_ops = ops; |
311 | et->et_root_bh = bh; | 304 | et->et_root_bh = bh; |
305 | et->et_root_journal_access = access; | ||
312 | if (!obj) | 306 | if (!obj) |
313 | obj = (void *)bh->b_data; | 307 | obj = (void *)bh->b_data; |
314 | et->et_object = obj; | 308 | et->et_object = obj; |
@@ -324,23 +318,23 @@ void ocfs2_init_dinode_extent_tree(struct ocfs2_extent_tree *et, | |||
324 | struct inode *inode, | 318 | struct inode *inode, |
325 | struct buffer_head *bh) | 319 | struct buffer_head *bh) |
326 | { | 320 | { |
327 | __ocfs2_init_extent_tree(et, inode, bh, NULL, &ocfs2_dinode_et_ops); | 321 | __ocfs2_init_extent_tree(et, inode, bh, ocfs2_journal_access_di, |
322 | NULL, &ocfs2_dinode_et_ops); | ||
328 | } | 323 | } |
329 | 324 | ||
330 | void ocfs2_init_xattr_tree_extent_tree(struct ocfs2_extent_tree *et, | 325 | void ocfs2_init_xattr_tree_extent_tree(struct ocfs2_extent_tree *et, |
331 | struct inode *inode, | 326 | struct inode *inode, |
332 | struct buffer_head *bh) | 327 | struct buffer_head *bh) |
333 | { | 328 | { |
334 | __ocfs2_init_extent_tree(et, inode, bh, NULL, | 329 | __ocfs2_init_extent_tree(et, inode, bh, ocfs2_journal_access_xb, |
335 | &ocfs2_xattr_tree_et_ops); | 330 | NULL, &ocfs2_xattr_tree_et_ops); |
336 | } | 331 | } |
337 | 332 | ||
338 | void ocfs2_init_xattr_value_extent_tree(struct ocfs2_extent_tree *et, | 333 | void ocfs2_init_xattr_value_extent_tree(struct ocfs2_extent_tree *et, |
339 | struct inode *inode, | 334 | struct inode *inode, |
340 | struct buffer_head *bh, | 335 | struct ocfs2_xattr_value_buf *vb) |
341 | struct ocfs2_xattr_value_root *xv) | ||
342 | { | 336 | { |
343 | __ocfs2_init_extent_tree(et, inode, bh, xv, | 337 | __ocfs2_init_extent_tree(et, inode, vb->vb_bh, vb->vb_access, vb, |
344 | &ocfs2_xattr_value_et_ops); | 338 | &ocfs2_xattr_value_et_ops); |
345 | } | 339 | } |
346 | 340 | ||
@@ -362,6 +356,15 @@ static inline void ocfs2_et_update_clusters(struct inode *inode, | |||
362 | et->et_ops->eo_update_clusters(inode, et, clusters); | 356 | et->et_ops->eo_update_clusters(inode, et, clusters); |
363 | } | 357 | } |
364 | 358 | ||
359 | static inline int ocfs2_et_root_journal_access(handle_t *handle, | ||
360 | struct inode *inode, | ||
361 | struct ocfs2_extent_tree *et, | ||
362 | int type) | ||
363 | { | ||
364 | return et->et_root_journal_access(handle, inode, et->et_root_bh, | ||
365 | type); | ||
366 | } | ||
367 | |||
365 | static inline int ocfs2_et_insert_check(struct inode *inode, | 368 | static inline int ocfs2_et_insert_check(struct inode *inode, |
366 | struct ocfs2_extent_tree *et, | 369 | struct ocfs2_extent_tree *et, |
367 | struct ocfs2_extent_rec *rec) | 370 | struct ocfs2_extent_rec *rec) |
@@ -402,12 +405,14 @@ struct ocfs2_path_item { | |||
402 | #define OCFS2_MAX_PATH_DEPTH 5 | 405 | #define OCFS2_MAX_PATH_DEPTH 5 |
403 | 406 | ||
404 | struct ocfs2_path { | 407 | struct ocfs2_path { |
405 | int p_tree_depth; | 408 | int p_tree_depth; |
406 | struct ocfs2_path_item p_node[OCFS2_MAX_PATH_DEPTH]; | 409 | ocfs2_journal_access_func p_root_access; |
410 | struct ocfs2_path_item p_node[OCFS2_MAX_PATH_DEPTH]; | ||
407 | }; | 411 | }; |
408 | 412 | ||
409 | #define path_root_bh(_path) ((_path)->p_node[0].bh) | 413 | #define path_root_bh(_path) ((_path)->p_node[0].bh) |
410 | #define path_root_el(_path) ((_path)->p_node[0].el) | 414 | #define path_root_el(_path) ((_path)->p_node[0].el) |
415 | #define path_root_access(_path)((_path)->p_root_access) | ||
411 | #define path_leaf_bh(_path) ((_path)->p_node[(_path)->p_tree_depth].bh) | 416 | #define path_leaf_bh(_path) ((_path)->p_node[(_path)->p_tree_depth].bh) |
412 | #define path_leaf_el(_path) ((_path)->p_node[(_path)->p_tree_depth].el) | 417 | #define path_leaf_el(_path) ((_path)->p_node[(_path)->p_tree_depth].el) |
413 | #define path_num_items(_path) ((_path)->p_tree_depth + 1) | 418 | #define path_num_items(_path) ((_path)->p_tree_depth + 1) |
@@ -440,6 +445,8 @@ static void ocfs2_reinit_path(struct ocfs2_path *path, int keep_root) | |||
440 | */ | 445 | */ |
441 | if (keep_root) | 446 | if (keep_root) |
442 | depth = le16_to_cpu(path_root_el(path)->l_tree_depth); | 447 | depth = le16_to_cpu(path_root_el(path)->l_tree_depth); |
448 | else | ||
449 | path_root_access(path) = NULL; | ||
443 | 450 | ||
444 | path->p_tree_depth = depth; | 451 | path->p_tree_depth = depth; |
445 | } | 452 | } |
@@ -465,6 +472,7 @@ static void ocfs2_cp_path(struct ocfs2_path *dest, struct ocfs2_path *src) | |||
465 | 472 | ||
466 | BUG_ON(path_root_bh(dest) != path_root_bh(src)); | 473 | BUG_ON(path_root_bh(dest) != path_root_bh(src)); |
467 | BUG_ON(path_root_el(dest) != path_root_el(src)); | 474 | BUG_ON(path_root_el(dest) != path_root_el(src)); |
475 | BUG_ON(path_root_access(dest) != path_root_access(src)); | ||
468 | 476 | ||
469 | ocfs2_reinit_path(dest, 1); | 477 | ocfs2_reinit_path(dest, 1); |
470 | 478 | ||
@@ -486,6 +494,7 @@ static void ocfs2_mv_path(struct ocfs2_path *dest, struct ocfs2_path *src) | |||
486 | int i; | 494 | int i; |
487 | 495 | ||
488 | BUG_ON(path_root_bh(dest) != path_root_bh(src)); | 496 | BUG_ON(path_root_bh(dest) != path_root_bh(src)); |
497 | BUG_ON(path_root_access(dest) != path_root_access(src)); | ||
489 | 498 | ||
490 | for(i = 1; i < OCFS2_MAX_PATH_DEPTH; i++) { | 499 | for(i = 1; i < OCFS2_MAX_PATH_DEPTH; i++) { |
491 | brelse(dest->p_node[i].bh); | 500 | brelse(dest->p_node[i].bh); |
@@ -521,7 +530,8 @@ static inline void ocfs2_path_insert_eb(struct ocfs2_path *path, int index, | |||
521 | } | 530 | } |
522 | 531 | ||
523 | static struct ocfs2_path *ocfs2_new_path(struct buffer_head *root_bh, | 532 | static struct ocfs2_path *ocfs2_new_path(struct buffer_head *root_bh, |
524 | struct ocfs2_extent_list *root_el) | 533 | struct ocfs2_extent_list *root_el, |
534 | ocfs2_journal_access_func access) | ||
525 | { | 535 | { |
526 | struct ocfs2_path *path; | 536 | struct ocfs2_path *path; |
527 | 537 | ||
@@ -533,11 +543,48 @@ static struct ocfs2_path *ocfs2_new_path(struct buffer_head *root_bh, | |||
533 | get_bh(root_bh); | 543 | get_bh(root_bh); |
534 | path_root_bh(path) = root_bh; | 544 | path_root_bh(path) = root_bh; |
535 | path_root_el(path) = root_el; | 545 | path_root_el(path) = root_el; |
546 | path_root_access(path) = access; | ||
536 | } | 547 | } |
537 | 548 | ||
538 | return path; | 549 | return path; |
539 | } | 550 | } |
540 | 551 | ||
552 | static struct ocfs2_path *ocfs2_new_path_from_path(struct ocfs2_path *path) | ||
553 | { | ||
554 | return ocfs2_new_path(path_root_bh(path), path_root_el(path), | ||
555 | path_root_access(path)); | ||
556 | } | ||
557 | |||
558 | static struct ocfs2_path *ocfs2_new_path_from_et(struct ocfs2_extent_tree *et) | ||
559 | { | ||
560 | return ocfs2_new_path(et->et_root_bh, et->et_root_el, | ||
561 | et->et_root_journal_access); | ||
562 | } | ||
563 | |||
564 | /* | ||
565 | * Journal the buffer at depth idx. All idx>0 are extent_blocks, | ||
566 | * otherwise it's the root_access function. | ||
567 | * | ||
568 | * I don't like the way this function's name looks next to | ||
569 | * ocfs2_journal_access_path(), but I don't have a better one. | ||
570 | */ | ||
571 | static int ocfs2_path_bh_journal_access(handle_t *handle, | ||
572 | struct inode *inode, | ||
573 | struct ocfs2_path *path, | ||
574 | int idx) | ||
575 | { | ||
576 | ocfs2_journal_access_func access = path_root_access(path); | ||
577 | |||
578 | if (!access) | ||
579 | access = ocfs2_journal_access; | ||
580 | |||
581 | if (idx) | ||
582 | access = ocfs2_journal_access_eb; | ||
583 | |||
584 | return access(handle, inode, path->p_node[idx].bh, | ||
585 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
586 | } | ||
587 | |||
541 | /* | 588 | /* |
542 | * Convenience function to journal all components in a path. | 589 | * Convenience function to journal all components in a path. |
543 | */ | 590 | */ |
@@ -550,8 +597,7 @@ static int ocfs2_journal_access_path(struct inode *inode, handle_t *handle, | |||
550 | goto out; | 597 | goto out; |
551 | 598 | ||
552 | for(i = 0; i < path_num_items(path); i++) { | 599 | for(i = 0; i < path_num_items(path); i++) { |
553 | ret = ocfs2_journal_access(handle, inode, path->p_node[i].bh, | 600 | ret = ocfs2_path_bh_journal_access(handle, inode, path, i); |
554 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
555 | if (ret < 0) { | 601 | if (ret < 0) { |
556 | mlog_errno(ret); | 602 | mlog_errno(ret); |
557 | goto out; | 603 | goto out; |
@@ -686,6 +732,80 @@ struct ocfs2_merge_ctxt { | |||
686 | int c_split_covers_rec; | 732 | int c_split_covers_rec; |
687 | }; | 733 | }; |
688 | 734 | ||
735 | static int ocfs2_validate_extent_block(struct super_block *sb, | ||
736 | struct buffer_head *bh) | ||
737 | { | ||
738 | int rc; | ||
739 | struct ocfs2_extent_block *eb = | ||
740 | (struct ocfs2_extent_block *)bh->b_data; | ||
741 | |||
742 | mlog(0, "Validating extent block %llu\n", | ||
743 | (unsigned long long)bh->b_blocknr); | ||
744 | |||
745 | BUG_ON(!buffer_uptodate(bh)); | ||
746 | |||
747 | /* | ||
748 | * If the ecc fails, we return the error but otherwise | ||
749 | * leave the filesystem running. We know any error is | ||
750 | * local to this block. | ||
751 | */ | ||
752 | rc = ocfs2_validate_meta_ecc(sb, bh->b_data, &eb->h_check); | ||
753 | if (rc) { | ||
754 | mlog(ML_ERROR, "Checksum failed for extent block %llu\n", | ||
755 | (unsigned long long)bh->b_blocknr); | ||
756 | return rc; | ||
757 | } | ||
758 | |||
759 | /* | ||
760 | * Errors after here are fatal. | ||
761 | */ | ||
762 | |||
763 | if (!OCFS2_IS_VALID_EXTENT_BLOCK(eb)) { | ||
764 | ocfs2_error(sb, | ||
765 | "Extent block #%llu has bad signature %.*s", | ||
766 | (unsigned long long)bh->b_blocknr, 7, | ||
767 | eb->h_signature); | ||
768 | return -EINVAL; | ||
769 | } | ||
770 | |||
771 | if (le64_to_cpu(eb->h_blkno) != bh->b_blocknr) { | ||
772 | ocfs2_error(sb, | ||
773 | "Extent block #%llu has an invalid h_blkno " | ||
774 | "of %llu", | ||
775 | (unsigned long long)bh->b_blocknr, | ||
776 | (unsigned long long)le64_to_cpu(eb->h_blkno)); | ||
777 | return -EINVAL; | ||
778 | } | ||
779 | |||
780 | if (le32_to_cpu(eb->h_fs_generation) != OCFS2_SB(sb)->fs_generation) { | ||
781 | ocfs2_error(sb, | ||
782 | "Extent block #%llu has an invalid " | ||
783 | "h_fs_generation of #%u", | ||
784 | (unsigned long long)bh->b_blocknr, | ||
785 | le32_to_cpu(eb->h_fs_generation)); | ||
786 | return -EINVAL; | ||
787 | } | ||
788 | |||
789 | return 0; | ||
790 | } | ||
791 | |||
792 | int ocfs2_read_extent_block(struct inode *inode, u64 eb_blkno, | ||
793 | struct buffer_head **bh) | ||
794 | { | ||
795 | int rc; | ||
796 | struct buffer_head *tmp = *bh; | ||
797 | |||
798 | rc = ocfs2_read_block(inode, eb_blkno, &tmp, | ||
799 | ocfs2_validate_extent_block); | ||
800 | |||
801 | /* If ocfs2_read_block() got us a new bh, pass it up. */ | ||
802 | if (!rc && !*bh) | ||
803 | *bh = tmp; | ||
804 | |||
805 | return rc; | ||
806 | } | ||
807 | |||
808 | |||
689 | /* | 809 | /* |
690 | * How many free extents have we got before we need more meta data? | 810 | * How many free extents have we got before we need more meta data? |
691 | */ | 811 | */ |
@@ -705,8 +825,7 @@ int ocfs2_num_free_extents(struct ocfs2_super *osb, | |||
705 | last_eb_blk = ocfs2_et_get_last_eb_blk(et); | 825 | last_eb_blk = ocfs2_et_get_last_eb_blk(et); |
706 | 826 | ||
707 | if (last_eb_blk) { | 827 | if (last_eb_blk) { |
708 | retval = ocfs2_read_block(inode, last_eb_blk, | 828 | retval = ocfs2_read_extent_block(inode, last_eb_blk, &eb_bh); |
709 | &eb_bh); | ||
710 | if (retval < 0) { | 829 | if (retval < 0) { |
711 | mlog_errno(retval); | 830 | mlog_errno(retval); |
712 | goto bail; | 831 | goto bail; |
@@ -768,8 +887,8 @@ static int ocfs2_create_new_meta_bhs(struct ocfs2_super *osb, | |||
768 | } | 887 | } |
769 | ocfs2_set_new_buffer_uptodate(inode, bhs[i]); | 888 | ocfs2_set_new_buffer_uptodate(inode, bhs[i]); |
770 | 889 | ||
771 | status = ocfs2_journal_access(handle, inode, bhs[i], | 890 | status = ocfs2_journal_access_eb(handle, inode, bhs[i], |
772 | OCFS2_JOURNAL_ACCESS_CREATE); | 891 | OCFS2_JOURNAL_ACCESS_CREATE); |
773 | if (status < 0) { | 892 | if (status < 0) { |
774 | mlog_errno(status); | 893 | mlog_errno(status); |
775 | goto bail; | 894 | goto bail; |
@@ -908,15 +1027,12 @@ static int ocfs2_add_branch(struct ocfs2_super *osb, | |||
908 | for(i = 0; i < new_blocks; i++) { | 1027 | for(i = 0; i < new_blocks; i++) { |
909 | bh = new_eb_bhs[i]; | 1028 | bh = new_eb_bhs[i]; |
910 | eb = (struct ocfs2_extent_block *) bh->b_data; | 1029 | eb = (struct ocfs2_extent_block *) bh->b_data; |
911 | if (!OCFS2_IS_VALID_EXTENT_BLOCK(eb)) { | 1030 | /* ocfs2_create_new_meta_bhs() should create it right! */ |
912 | OCFS2_RO_ON_INVALID_EXTENT_BLOCK(inode->i_sb, eb); | 1031 | BUG_ON(!OCFS2_IS_VALID_EXTENT_BLOCK(eb)); |
913 | status = -EIO; | ||
914 | goto bail; | ||
915 | } | ||
916 | eb_el = &eb->h_list; | 1032 | eb_el = &eb->h_list; |
917 | 1033 | ||
918 | status = ocfs2_journal_access(handle, inode, bh, | 1034 | status = ocfs2_journal_access_eb(handle, inode, bh, |
919 | OCFS2_JOURNAL_ACCESS_CREATE); | 1035 | OCFS2_JOURNAL_ACCESS_CREATE); |
920 | if (status < 0) { | 1036 | if (status < 0) { |
921 | mlog_errno(status); | 1037 | mlog_errno(status); |
922 | goto bail; | 1038 | goto bail; |
@@ -955,21 +1071,21 @@ static int ocfs2_add_branch(struct ocfs2_super *osb, | |||
955 | * journal_dirty erroring as it won't unless we've aborted the | 1071 | * journal_dirty erroring as it won't unless we've aborted the |
956 | * handle (in which case we would never be here) so reserving | 1072 | * handle (in which case we would never be here) so reserving |
957 | * the write with journal_access is all we need to do. */ | 1073 | * the write with journal_access is all we need to do. */ |
958 | status = ocfs2_journal_access(handle, inode, *last_eb_bh, | 1074 | status = ocfs2_journal_access_eb(handle, inode, *last_eb_bh, |
959 | OCFS2_JOURNAL_ACCESS_WRITE); | 1075 | OCFS2_JOURNAL_ACCESS_WRITE); |
960 | if (status < 0) { | 1076 | if (status < 0) { |
961 | mlog_errno(status); | 1077 | mlog_errno(status); |
962 | goto bail; | 1078 | goto bail; |
963 | } | 1079 | } |
964 | status = ocfs2_journal_access(handle, inode, et->et_root_bh, | 1080 | status = ocfs2_et_root_journal_access(handle, inode, et, |
965 | OCFS2_JOURNAL_ACCESS_WRITE); | 1081 | OCFS2_JOURNAL_ACCESS_WRITE); |
966 | if (status < 0) { | 1082 | if (status < 0) { |
967 | mlog_errno(status); | 1083 | mlog_errno(status); |
968 | goto bail; | 1084 | goto bail; |
969 | } | 1085 | } |
970 | if (eb_bh) { | 1086 | if (eb_bh) { |
971 | status = ocfs2_journal_access(handle, inode, eb_bh, | 1087 | status = ocfs2_journal_access_eb(handle, inode, eb_bh, |
972 | OCFS2_JOURNAL_ACCESS_WRITE); | 1088 | OCFS2_JOURNAL_ACCESS_WRITE); |
973 | if (status < 0) { | 1089 | if (status < 0) { |
974 | mlog_errno(status); | 1090 | mlog_errno(status); |
975 | goto bail; | 1091 | goto bail; |
@@ -1052,17 +1168,14 @@ static int ocfs2_shift_tree_depth(struct ocfs2_super *osb, | |||
1052 | } | 1168 | } |
1053 | 1169 | ||
1054 | eb = (struct ocfs2_extent_block *) new_eb_bh->b_data; | 1170 | eb = (struct ocfs2_extent_block *) new_eb_bh->b_data; |
1055 | if (!OCFS2_IS_VALID_EXTENT_BLOCK(eb)) { | 1171 | /* ocfs2_create_new_meta_bhs() should create it right! */ |
1056 | OCFS2_RO_ON_INVALID_EXTENT_BLOCK(inode->i_sb, eb); | 1172 | BUG_ON(!OCFS2_IS_VALID_EXTENT_BLOCK(eb)); |
1057 | status = -EIO; | ||
1058 | goto bail; | ||
1059 | } | ||
1060 | 1173 | ||
1061 | eb_el = &eb->h_list; | 1174 | eb_el = &eb->h_list; |
1062 | root_el = et->et_root_el; | 1175 | root_el = et->et_root_el; |
1063 | 1176 | ||
1064 | status = ocfs2_journal_access(handle, inode, new_eb_bh, | 1177 | status = ocfs2_journal_access_eb(handle, inode, new_eb_bh, |
1065 | OCFS2_JOURNAL_ACCESS_CREATE); | 1178 | OCFS2_JOURNAL_ACCESS_CREATE); |
1066 | if (status < 0) { | 1179 | if (status < 0) { |
1067 | mlog_errno(status); | 1180 | mlog_errno(status); |
1068 | goto bail; | 1181 | goto bail; |
@@ -1080,8 +1193,8 @@ static int ocfs2_shift_tree_depth(struct ocfs2_super *osb, | |||
1080 | goto bail; | 1193 | goto bail; |
1081 | } | 1194 | } |
1082 | 1195 | ||
1083 | status = ocfs2_journal_access(handle, inode, et->et_root_bh, | 1196 | status = ocfs2_et_root_journal_access(handle, inode, et, |
1084 | OCFS2_JOURNAL_ACCESS_WRITE); | 1197 | OCFS2_JOURNAL_ACCESS_WRITE); |
1085 | if (status < 0) { | 1198 | if (status < 0) { |
1086 | mlog_errno(status); | 1199 | mlog_errno(status); |
1087 | goto bail; | 1200 | goto bail; |
@@ -1176,18 +1289,13 @@ static int ocfs2_find_branch_target(struct ocfs2_super *osb, | |||
1176 | brelse(bh); | 1289 | brelse(bh); |
1177 | bh = NULL; | 1290 | bh = NULL; |
1178 | 1291 | ||
1179 | status = ocfs2_read_block(inode, blkno, &bh); | 1292 | status = ocfs2_read_extent_block(inode, blkno, &bh); |
1180 | if (status < 0) { | 1293 | if (status < 0) { |
1181 | mlog_errno(status); | 1294 | mlog_errno(status); |
1182 | goto bail; | 1295 | goto bail; |
1183 | } | 1296 | } |
1184 | 1297 | ||
1185 | eb = (struct ocfs2_extent_block *) bh->b_data; | 1298 | eb = (struct ocfs2_extent_block *) bh->b_data; |
1186 | if (!OCFS2_IS_VALID_EXTENT_BLOCK(eb)) { | ||
1187 | OCFS2_RO_ON_INVALID_EXTENT_BLOCK(inode->i_sb, eb); | ||
1188 | status = -EIO; | ||
1189 | goto bail; | ||
1190 | } | ||
1191 | el = &eb->h_list; | 1299 | el = &eb->h_list; |
1192 | 1300 | ||
1193 | if (le16_to_cpu(el->l_next_free_rec) < | 1301 | if (le16_to_cpu(el->l_next_free_rec) < |
@@ -1540,7 +1648,7 @@ static int __ocfs2_find_path(struct inode *inode, | |||
1540 | 1648 | ||
1541 | brelse(bh); | 1649 | brelse(bh); |
1542 | bh = NULL; | 1650 | bh = NULL; |
1543 | ret = ocfs2_read_block(inode, blkno, &bh); | 1651 | ret = ocfs2_read_extent_block(inode, blkno, &bh); |
1544 | if (ret) { | 1652 | if (ret) { |
1545 | mlog_errno(ret); | 1653 | mlog_errno(ret); |
1546 | goto out; | 1654 | goto out; |
@@ -1548,11 +1656,6 @@ static int __ocfs2_find_path(struct inode *inode, | |||
1548 | 1656 | ||
1549 | eb = (struct ocfs2_extent_block *) bh->b_data; | 1657 | eb = (struct ocfs2_extent_block *) bh->b_data; |
1550 | el = &eb->h_list; | 1658 | el = &eb->h_list; |
1551 | if (!OCFS2_IS_VALID_EXTENT_BLOCK(eb)) { | ||
1552 | OCFS2_RO_ON_INVALID_EXTENT_BLOCK(inode->i_sb, eb); | ||
1553 | ret = -EIO; | ||
1554 | goto out; | ||
1555 | } | ||
1556 | 1659 | ||
1557 | if (le16_to_cpu(el->l_next_free_rec) > | 1660 | if (le16_to_cpu(el->l_next_free_rec) > |
1558 | le16_to_cpu(el->l_count)) { | 1661 | le16_to_cpu(el->l_count)) { |
@@ -1860,25 +1963,23 @@ static int ocfs2_rotate_subtree_right(struct inode *inode, | |||
1860 | root_bh = left_path->p_node[subtree_index].bh; | 1963 | root_bh = left_path->p_node[subtree_index].bh; |
1861 | BUG_ON(root_bh != right_path->p_node[subtree_index].bh); | 1964 | BUG_ON(root_bh != right_path->p_node[subtree_index].bh); |
1862 | 1965 | ||
1863 | ret = ocfs2_journal_access(handle, inode, root_bh, | 1966 | ret = ocfs2_path_bh_journal_access(handle, inode, right_path, |
1864 | OCFS2_JOURNAL_ACCESS_WRITE); | 1967 | subtree_index); |
1865 | if (ret) { | 1968 | if (ret) { |
1866 | mlog_errno(ret); | 1969 | mlog_errno(ret); |
1867 | goto out; | 1970 | goto out; |
1868 | } | 1971 | } |
1869 | 1972 | ||
1870 | for(i = subtree_index + 1; i < path_num_items(right_path); i++) { | 1973 | for(i = subtree_index + 1; i < path_num_items(right_path); i++) { |
1871 | ret = ocfs2_journal_access(handle, inode, | 1974 | ret = ocfs2_path_bh_journal_access(handle, inode, |
1872 | right_path->p_node[i].bh, | 1975 | right_path, i); |
1873 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
1874 | if (ret) { | 1976 | if (ret) { |
1875 | mlog_errno(ret); | 1977 | mlog_errno(ret); |
1876 | goto out; | 1978 | goto out; |
1877 | } | 1979 | } |
1878 | 1980 | ||
1879 | ret = ocfs2_journal_access(handle, inode, | 1981 | ret = ocfs2_path_bh_journal_access(handle, inode, |
1880 | left_path->p_node[i].bh, | 1982 | left_path, i); |
1881 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
1882 | if (ret) { | 1983 | if (ret) { |
1883 | mlog_errno(ret); | 1984 | mlog_errno(ret); |
1884 | goto out; | 1985 | goto out; |
@@ -2102,8 +2203,7 @@ static int ocfs2_rotate_tree_right(struct inode *inode, | |||
2102 | 2203 | ||
2103 | *ret_left_path = NULL; | 2204 | *ret_left_path = NULL; |
2104 | 2205 | ||
2105 | left_path = ocfs2_new_path(path_root_bh(right_path), | 2206 | left_path = ocfs2_new_path_from_path(right_path); |
2106 | path_root_el(right_path)); | ||
2107 | if (!left_path) { | 2207 | if (!left_path) { |
2108 | ret = -ENOMEM; | 2208 | ret = -ENOMEM; |
2109 | mlog_errno(ret); | 2209 | mlog_errno(ret); |
@@ -2398,9 +2498,9 @@ static int ocfs2_rotate_subtree_left(struct inode *inode, handle_t *handle, | |||
2398 | return -EAGAIN; | 2498 | return -EAGAIN; |
2399 | 2499 | ||
2400 | if (le16_to_cpu(right_leaf_el->l_next_free_rec) > 1) { | 2500 | if (le16_to_cpu(right_leaf_el->l_next_free_rec) > 1) { |
2401 | ret = ocfs2_journal_access(handle, inode, | 2501 | ret = ocfs2_journal_access_eb(handle, inode, |
2402 | path_leaf_bh(right_path), | 2502 | path_leaf_bh(right_path), |
2403 | OCFS2_JOURNAL_ACCESS_WRITE); | 2503 | OCFS2_JOURNAL_ACCESS_WRITE); |
2404 | if (ret) { | 2504 | if (ret) { |
2405 | mlog_errno(ret); | 2505 | mlog_errno(ret); |
2406 | goto out; | 2506 | goto out; |
@@ -2417,8 +2517,8 @@ static int ocfs2_rotate_subtree_left(struct inode *inode, handle_t *handle, | |||
2417 | * We have to update i_last_eb_blk during the meta | 2517 | * We have to update i_last_eb_blk during the meta |
2418 | * data delete. | 2518 | * data delete. |
2419 | */ | 2519 | */ |
2420 | ret = ocfs2_journal_access(handle, inode, et_root_bh, | 2520 | ret = ocfs2_et_root_journal_access(handle, inode, et, |
2421 | OCFS2_JOURNAL_ACCESS_WRITE); | 2521 | OCFS2_JOURNAL_ACCESS_WRITE); |
2422 | if (ret) { | 2522 | if (ret) { |
2423 | mlog_errno(ret); | 2523 | mlog_errno(ret); |
2424 | goto out; | 2524 | goto out; |
@@ -2433,25 +2533,23 @@ static int ocfs2_rotate_subtree_left(struct inode *inode, handle_t *handle, | |||
2433 | */ | 2533 | */ |
2434 | BUG_ON(right_has_empty && !del_right_subtree); | 2534 | BUG_ON(right_has_empty && !del_right_subtree); |
2435 | 2535 | ||
2436 | ret = ocfs2_journal_access(handle, inode, root_bh, | 2536 | ret = ocfs2_path_bh_journal_access(handle, inode, right_path, |
2437 | OCFS2_JOURNAL_ACCESS_WRITE); | 2537 | subtree_index); |
2438 | if (ret) { | 2538 | if (ret) { |
2439 | mlog_errno(ret); | 2539 | mlog_errno(ret); |
2440 | goto out; | 2540 | goto out; |
2441 | } | 2541 | } |
2442 | 2542 | ||
2443 | for(i = subtree_index + 1; i < path_num_items(right_path); i++) { | 2543 | for(i = subtree_index + 1; i < path_num_items(right_path); i++) { |
2444 | ret = ocfs2_journal_access(handle, inode, | 2544 | ret = ocfs2_path_bh_journal_access(handle, inode, |
2445 | right_path->p_node[i].bh, | 2545 | right_path, i); |
2446 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
2447 | if (ret) { | 2546 | if (ret) { |
2448 | mlog_errno(ret); | 2547 | mlog_errno(ret); |
2449 | goto out; | 2548 | goto out; |
2450 | } | 2549 | } |
2451 | 2550 | ||
2452 | ret = ocfs2_journal_access(handle, inode, | 2551 | ret = ocfs2_path_bh_journal_access(handle, inode, |
2453 | left_path->p_node[i].bh, | 2552 | left_path, i); |
2454 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
2455 | if (ret) { | 2553 | if (ret) { |
2456 | mlog_errno(ret); | 2554 | mlog_errno(ret); |
2457 | goto out; | 2555 | goto out; |
@@ -2596,16 +2694,17 @@ out: | |||
2596 | 2694 | ||
2597 | static int ocfs2_rotate_rightmost_leaf_left(struct inode *inode, | 2695 | static int ocfs2_rotate_rightmost_leaf_left(struct inode *inode, |
2598 | handle_t *handle, | 2696 | handle_t *handle, |
2599 | struct buffer_head *bh, | 2697 | struct ocfs2_path *path) |
2600 | struct ocfs2_extent_list *el) | ||
2601 | { | 2698 | { |
2602 | int ret; | 2699 | int ret; |
2700 | struct buffer_head *bh = path_leaf_bh(path); | ||
2701 | struct ocfs2_extent_list *el = path_leaf_el(path); | ||
2603 | 2702 | ||
2604 | if (!ocfs2_is_empty_extent(&el->l_recs[0])) | 2703 | if (!ocfs2_is_empty_extent(&el->l_recs[0])) |
2605 | return 0; | 2704 | return 0; |
2606 | 2705 | ||
2607 | ret = ocfs2_journal_access(handle, inode, bh, | 2706 | ret = ocfs2_path_bh_journal_access(handle, inode, path, |
2608 | OCFS2_JOURNAL_ACCESS_WRITE); | 2707 | path_num_items(path) - 1); |
2609 | if (ret) { | 2708 | if (ret) { |
2610 | mlog_errno(ret); | 2709 | mlog_errno(ret); |
2611 | goto out; | 2710 | goto out; |
@@ -2644,8 +2743,7 @@ static int __ocfs2_rotate_tree_left(struct inode *inode, | |||
2644 | goto out; | 2743 | goto out; |
2645 | } | 2744 | } |
2646 | 2745 | ||
2647 | left_path = ocfs2_new_path(path_root_bh(path), | 2746 | left_path = ocfs2_new_path_from_path(path); |
2648 | path_root_el(path)); | ||
2649 | if (!left_path) { | 2747 | if (!left_path) { |
2650 | ret = -ENOMEM; | 2748 | ret = -ENOMEM; |
2651 | mlog_errno(ret); | 2749 | mlog_errno(ret); |
@@ -2654,8 +2752,7 @@ static int __ocfs2_rotate_tree_left(struct inode *inode, | |||
2654 | 2752 | ||
2655 | ocfs2_cp_path(left_path, path); | 2753 | ocfs2_cp_path(left_path, path); |
2656 | 2754 | ||
2657 | right_path = ocfs2_new_path(path_root_bh(path), | 2755 | right_path = ocfs2_new_path_from_path(path); |
2658 | path_root_el(path)); | ||
2659 | if (!right_path) { | 2756 | if (!right_path) { |
2660 | ret = -ENOMEM; | 2757 | ret = -ENOMEM; |
2661 | mlog_errno(ret); | 2758 | mlog_errno(ret); |
@@ -2689,9 +2786,8 @@ static int __ocfs2_rotate_tree_left(struct inode *inode, | |||
2689 | * Caller might still want to make changes to the | 2786 | * Caller might still want to make changes to the |
2690 | * tree root, so re-add it to the journal here. | 2787 | * tree root, so re-add it to the journal here. |
2691 | */ | 2788 | */ |
2692 | ret = ocfs2_journal_access(handle, inode, | 2789 | ret = ocfs2_path_bh_journal_access(handle, inode, |
2693 | path_root_bh(left_path), | 2790 | left_path, 0); |
2694 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
2695 | if (ret) { | 2791 | if (ret) { |
2696 | mlog_errno(ret); | 2792 | mlog_errno(ret); |
2697 | goto out; | 2793 | goto out; |
@@ -2785,8 +2881,7 @@ static int ocfs2_remove_rightmost_path(struct inode *inode, handle_t *handle, | |||
2785 | * We have a path to the left of this one - it needs | 2881 | * We have a path to the left of this one - it needs |
2786 | * an update too. | 2882 | * an update too. |
2787 | */ | 2883 | */ |
2788 | left_path = ocfs2_new_path(path_root_bh(path), | 2884 | left_path = ocfs2_new_path_from_path(path); |
2789 | path_root_el(path)); | ||
2790 | if (!left_path) { | 2885 | if (!left_path) { |
2791 | ret = -ENOMEM; | 2886 | ret = -ENOMEM; |
2792 | mlog_errno(ret); | 2887 | mlog_errno(ret); |
@@ -2875,8 +2970,7 @@ rightmost_no_delete: | |||
2875 | * it up front. | 2970 | * it up front. |
2876 | */ | 2971 | */ |
2877 | ret = ocfs2_rotate_rightmost_leaf_left(inode, handle, | 2972 | ret = ocfs2_rotate_rightmost_leaf_left(inode, handle, |
2878 | path_leaf_bh(path), | 2973 | path); |
2879 | path_leaf_el(path)); | ||
2880 | if (ret) | 2974 | if (ret) |
2881 | mlog_errno(ret); | 2975 | mlog_errno(ret); |
2882 | goto out; | 2976 | goto out; |
@@ -3027,8 +3121,7 @@ static int ocfs2_get_right_path(struct inode *inode, | |||
3027 | /* This function shouldn't be called for the rightmost leaf. */ | 3121 | /* This function shouldn't be called for the rightmost leaf. */ |
3028 | BUG_ON(right_cpos == 0); | 3122 | BUG_ON(right_cpos == 0); |
3029 | 3123 | ||
3030 | right_path = ocfs2_new_path(path_root_bh(left_path), | 3124 | right_path = ocfs2_new_path_from_path(left_path); |
3031 | path_root_el(left_path)); | ||
3032 | if (!right_path) { | 3125 | if (!right_path) { |
3033 | ret = -ENOMEM; | 3126 | ret = -ENOMEM; |
3034 | mlog_errno(ret); | 3127 | mlog_errno(ret); |
@@ -3111,8 +3204,8 @@ static int ocfs2_merge_rec_right(struct inode *inode, | |||
3111 | root_bh = left_path->p_node[subtree_index].bh; | 3204 | root_bh = left_path->p_node[subtree_index].bh; |
3112 | BUG_ON(root_bh != right_path->p_node[subtree_index].bh); | 3205 | BUG_ON(root_bh != right_path->p_node[subtree_index].bh); |
3113 | 3206 | ||
3114 | ret = ocfs2_journal_access(handle, inode, root_bh, | 3207 | ret = ocfs2_path_bh_journal_access(handle, inode, right_path, |
3115 | OCFS2_JOURNAL_ACCESS_WRITE); | 3208 | subtree_index); |
3116 | if (ret) { | 3209 | if (ret) { |
3117 | mlog_errno(ret); | 3210 | mlog_errno(ret); |
3118 | goto out; | 3211 | goto out; |
@@ -3120,17 +3213,15 @@ static int ocfs2_merge_rec_right(struct inode *inode, | |||
3120 | 3213 | ||
3121 | for (i = subtree_index + 1; | 3214 | for (i = subtree_index + 1; |
3122 | i < path_num_items(right_path); i++) { | 3215 | i < path_num_items(right_path); i++) { |
3123 | ret = ocfs2_journal_access(handle, inode, | 3216 | ret = ocfs2_path_bh_journal_access(handle, inode, |
3124 | right_path->p_node[i].bh, | 3217 | right_path, i); |
3125 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
3126 | if (ret) { | 3218 | if (ret) { |
3127 | mlog_errno(ret); | 3219 | mlog_errno(ret); |
3128 | goto out; | 3220 | goto out; |
3129 | } | 3221 | } |
3130 | 3222 | ||
3131 | ret = ocfs2_journal_access(handle, inode, | 3223 | ret = ocfs2_path_bh_journal_access(handle, inode, |
3132 | left_path->p_node[i].bh, | 3224 | left_path, i); |
3133 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
3134 | if (ret) { | 3225 | if (ret) { |
3135 | mlog_errno(ret); | 3226 | mlog_errno(ret); |
3136 | goto out; | 3227 | goto out; |
@@ -3142,8 +3233,8 @@ static int ocfs2_merge_rec_right(struct inode *inode, | |||
3142 | right_rec = &el->l_recs[index + 1]; | 3233 | right_rec = &el->l_recs[index + 1]; |
3143 | } | 3234 | } |
3144 | 3235 | ||
3145 | ret = ocfs2_journal_access(handle, inode, bh, | 3236 | ret = ocfs2_path_bh_journal_access(handle, inode, left_path, |
3146 | OCFS2_JOURNAL_ACCESS_WRITE); | 3237 | path_num_items(left_path) - 1); |
3147 | if (ret) { | 3238 | if (ret) { |
3148 | mlog_errno(ret); | 3239 | mlog_errno(ret); |
3149 | goto out; | 3240 | goto out; |
@@ -3199,8 +3290,7 @@ static int ocfs2_get_left_path(struct inode *inode, | |||
3199 | /* This function shouldn't be called for the leftmost leaf. */ | 3290 | /* This function shouldn't be called for the leftmost leaf. */ |
3200 | BUG_ON(left_cpos == 0); | 3291 | BUG_ON(left_cpos == 0); |
3201 | 3292 | ||
3202 | left_path = ocfs2_new_path(path_root_bh(right_path), | 3293 | left_path = ocfs2_new_path_from_path(right_path); |
3203 | path_root_el(right_path)); | ||
3204 | if (!left_path) { | 3294 | if (!left_path) { |
3205 | ret = -ENOMEM; | 3295 | ret = -ENOMEM; |
3206 | mlog_errno(ret); | 3296 | mlog_errno(ret); |
@@ -3283,8 +3373,8 @@ static int ocfs2_merge_rec_left(struct inode *inode, | |||
3283 | root_bh = left_path->p_node[subtree_index].bh; | 3373 | root_bh = left_path->p_node[subtree_index].bh; |
3284 | BUG_ON(root_bh != right_path->p_node[subtree_index].bh); | 3374 | BUG_ON(root_bh != right_path->p_node[subtree_index].bh); |
3285 | 3375 | ||
3286 | ret = ocfs2_journal_access(handle, inode, root_bh, | 3376 | ret = ocfs2_path_bh_journal_access(handle, inode, right_path, |
3287 | OCFS2_JOURNAL_ACCESS_WRITE); | 3377 | subtree_index); |
3288 | if (ret) { | 3378 | if (ret) { |
3289 | mlog_errno(ret); | 3379 | mlog_errno(ret); |
3290 | goto out; | 3380 | goto out; |
@@ -3292,17 +3382,15 @@ static int ocfs2_merge_rec_left(struct inode *inode, | |||
3292 | 3382 | ||
3293 | for (i = subtree_index + 1; | 3383 | for (i = subtree_index + 1; |
3294 | i < path_num_items(right_path); i++) { | 3384 | i < path_num_items(right_path); i++) { |
3295 | ret = ocfs2_journal_access(handle, inode, | 3385 | ret = ocfs2_path_bh_journal_access(handle, inode, |
3296 | right_path->p_node[i].bh, | 3386 | right_path, i); |
3297 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
3298 | if (ret) { | 3387 | if (ret) { |
3299 | mlog_errno(ret); | 3388 | mlog_errno(ret); |
3300 | goto out; | 3389 | goto out; |
3301 | } | 3390 | } |
3302 | 3391 | ||
3303 | ret = ocfs2_journal_access(handle, inode, | 3392 | ret = ocfs2_path_bh_journal_access(handle, inode, |
3304 | left_path->p_node[i].bh, | 3393 | left_path, i); |
3305 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
3306 | if (ret) { | 3394 | if (ret) { |
3307 | mlog_errno(ret); | 3395 | mlog_errno(ret); |
3308 | goto out; | 3396 | goto out; |
@@ -3314,8 +3402,8 @@ static int ocfs2_merge_rec_left(struct inode *inode, | |||
3314 | has_empty_extent = 1; | 3402 | has_empty_extent = 1; |
3315 | } | 3403 | } |
3316 | 3404 | ||
3317 | ret = ocfs2_journal_access(handle, inode, bh, | 3405 | ret = ocfs2_path_bh_journal_access(handle, inode, right_path, |
3318 | OCFS2_JOURNAL_ACCESS_WRITE); | 3406 | path_num_items(right_path) - 1); |
3319 | if (ret) { | 3407 | if (ret) { |
3320 | mlog_errno(ret); | 3408 | mlog_errno(ret); |
3321 | goto out; | 3409 | goto out; |
@@ -3732,8 +3820,7 @@ static int ocfs2_append_rec_to_path(struct inode *inode, handle_t *handle, | |||
3732 | * leftmost leaf. | 3820 | * leftmost leaf. |
3733 | */ | 3821 | */ |
3734 | if (left_cpos) { | 3822 | if (left_cpos) { |
3735 | left_path = ocfs2_new_path(path_root_bh(right_path), | 3823 | left_path = ocfs2_new_path_from_path(right_path); |
3736 | path_root_el(right_path)); | ||
3737 | if (!left_path) { | 3824 | if (!left_path) { |
3738 | ret = -ENOMEM; | 3825 | ret = -ENOMEM; |
3739 | mlog_errno(ret); | 3826 | mlog_errno(ret); |
@@ -3781,7 +3868,7 @@ static void ocfs2_split_record(struct inode *inode, | |||
3781 | struct ocfs2_extent_list *left_el = NULL, *right_el, *insert_el, *el; | 3868 | struct ocfs2_extent_list *left_el = NULL, *right_el, *insert_el, *el; |
3782 | struct ocfs2_extent_rec *rec, *tmprec; | 3869 | struct ocfs2_extent_rec *rec, *tmprec; |
3783 | 3870 | ||
3784 | right_el = path_leaf_el(right_path);; | 3871 | right_el = path_leaf_el(right_path); |
3785 | if (left_path) | 3872 | if (left_path) |
3786 | left_el = path_leaf_el(left_path); | 3873 | left_el = path_leaf_el(left_path); |
3787 | 3874 | ||
@@ -3958,8 +4045,8 @@ static int ocfs2_do_insert_extent(struct inode *inode, | |||
3958 | 4045 | ||
3959 | el = et->et_root_el; | 4046 | el = et->et_root_el; |
3960 | 4047 | ||
3961 | ret = ocfs2_journal_access(handle, inode, et->et_root_bh, | 4048 | ret = ocfs2_et_root_journal_access(handle, inode, et, |
3962 | OCFS2_JOURNAL_ACCESS_WRITE); | 4049 | OCFS2_JOURNAL_ACCESS_WRITE); |
3963 | if (ret) { | 4050 | if (ret) { |
3964 | mlog_errno(ret); | 4051 | mlog_errno(ret); |
3965 | goto out; | 4052 | goto out; |
@@ -3970,7 +4057,7 @@ static int ocfs2_do_insert_extent(struct inode *inode, | |||
3970 | goto out_update_clusters; | 4057 | goto out_update_clusters; |
3971 | } | 4058 | } |
3972 | 4059 | ||
3973 | right_path = ocfs2_new_path(et->et_root_bh, et->et_root_el); | 4060 | right_path = ocfs2_new_path_from_et(et); |
3974 | if (!right_path) { | 4061 | if (!right_path) { |
3975 | ret = -ENOMEM; | 4062 | ret = -ENOMEM; |
3976 | mlog_errno(ret); | 4063 | mlog_errno(ret); |
@@ -4020,8 +4107,8 @@ static int ocfs2_do_insert_extent(struct inode *inode, | |||
4020 | * ocfs2_rotate_tree_right() might have extended the | 4107 | * ocfs2_rotate_tree_right() might have extended the |
4021 | * transaction without re-journaling our tree root. | 4108 | * transaction without re-journaling our tree root. |
4022 | */ | 4109 | */ |
4023 | ret = ocfs2_journal_access(handle, inode, et->et_root_bh, | 4110 | ret = ocfs2_et_root_journal_access(handle, inode, et, |
4024 | OCFS2_JOURNAL_ACCESS_WRITE); | 4111 | OCFS2_JOURNAL_ACCESS_WRITE); |
4025 | if (ret) { | 4112 | if (ret) { |
4026 | mlog_errno(ret); | 4113 | mlog_errno(ret); |
4027 | goto out; | 4114 | goto out; |
@@ -4082,8 +4169,7 @@ ocfs2_figure_merge_contig_type(struct inode *inode, struct ocfs2_path *path, | |||
4082 | goto out; | 4169 | goto out; |
4083 | 4170 | ||
4084 | if (left_cpos != 0) { | 4171 | if (left_cpos != 0) { |
4085 | left_path = ocfs2_new_path(path_root_bh(path), | 4172 | left_path = ocfs2_new_path_from_path(path); |
4086 | path_root_el(path)); | ||
4087 | if (!left_path) | 4173 | if (!left_path) |
4088 | goto out; | 4174 | goto out; |
4089 | 4175 | ||
@@ -4097,8 +4183,15 @@ ocfs2_figure_merge_contig_type(struct inode *inode, struct ocfs2_path *path, | |||
4097 | le16_to_cpu(new_el->l_count)) { | 4183 | le16_to_cpu(new_el->l_count)) { |
4098 | bh = path_leaf_bh(left_path); | 4184 | bh = path_leaf_bh(left_path); |
4099 | eb = (struct ocfs2_extent_block *)bh->b_data; | 4185 | eb = (struct ocfs2_extent_block *)bh->b_data; |
4100 | OCFS2_RO_ON_INVALID_EXTENT_BLOCK(inode->i_sb, | 4186 | ocfs2_error(inode->i_sb, |
4101 | eb); | 4187 | "Extent block #%llu has an " |
4188 | "invalid l_next_free_rec of " | ||
4189 | "%d. It should have " | ||
4190 | "matched the l_count of %d", | ||
4191 | (unsigned long long)le64_to_cpu(eb->h_blkno), | ||
4192 | le16_to_cpu(new_el->l_next_free_rec), | ||
4193 | le16_to_cpu(new_el->l_count)); | ||
4194 | status = -EINVAL; | ||
4102 | goto out; | 4195 | goto out; |
4103 | } | 4196 | } |
4104 | rec = &new_el->l_recs[ | 4197 | rec = &new_el->l_recs[ |
@@ -4132,8 +4225,7 @@ ocfs2_figure_merge_contig_type(struct inode *inode, struct ocfs2_path *path, | |||
4132 | if (right_cpos == 0) | 4225 | if (right_cpos == 0) |
4133 | goto out; | 4226 | goto out; |
4134 | 4227 | ||
4135 | right_path = ocfs2_new_path(path_root_bh(path), | 4228 | right_path = ocfs2_new_path_from_path(path); |
4136 | path_root_el(path)); | ||
4137 | if (!right_path) | 4229 | if (!right_path) |
4138 | goto out; | 4230 | goto out; |
4139 | 4231 | ||
@@ -4147,8 +4239,12 @@ ocfs2_figure_merge_contig_type(struct inode *inode, struct ocfs2_path *path, | |||
4147 | if (le16_to_cpu(new_el->l_next_free_rec) <= 1) { | 4239 | if (le16_to_cpu(new_el->l_next_free_rec) <= 1) { |
4148 | bh = path_leaf_bh(right_path); | 4240 | bh = path_leaf_bh(right_path); |
4149 | eb = (struct ocfs2_extent_block *)bh->b_data; | 4241 | eb = (struct ocfs2_extent_block *)bh->b_data; |
4150 | OCFS2_RO_ON_INVALID_EXTENT_BLOCK(inode->i_sb, | 4242 | ocfs2_error(inode->i_sb, |
4151 | eb); | 4243 | "Extent block #%llu has an " |
4244 | "invalid l_next_free_rec of %d", | ||
4245 | (unsigned long long)le64_to_cpu(eb->h_blkno), | ||
4246 | le16_to_cpu(new_el->l_next_free_rec)); | ||
4247 | status = -EINVAL; | ||
4152 | goto out; | 4248 | goto out; |
4153 | } | 4249 | } |
4154 | rec = &new_el->l_recs[1]; | 4250 | rec = &new_el->l_recs[1]; |
@@ -4294,7 +4390,9 @@ static int ocfs2_figure_insert_type(struct inode *inode, | |||
4294 | * ocfs2_figure_insert_type() and ocfs2_add_branch() | 4390 | * ocfs2_figure_insert_type() and ocfs2_add_branch() |
4295 | * may want it later. | 4391 | * may want it later. |
4296 | */ | 4392 | */ |
4297 | ret = ocfs2_read_block(inode, ocfs2_et_get_last_eb_blk(et), &bh); | 4393 | ret = ocfs2_read_extent_block(inode, |
4394 | ocfs2_et_get_last_eb_blk(et), | ||
4395 | &bh); | ||
4298 | if (ret) { | 4396 | if (ret) { |
4299 | mlog_exit(ret); | 4397 | mlog_exit(ret); |
4300 | goto out; | 4398 | goto out; |
@@ -4320,7 +4418,7 @@ static int ocfs2_figure_insert_type(struct inode *inode, | |||
4320 | return 0; | 4418 | return 0; |
4321 | } | 4419 | } |
4322 | 4420 | ||
4323 | path = ocfs2_new_path(et->et_root_bh, et->et_root_el); | 4421 | path = ocfs2_new_path_from_et(et); |
4324 | if (!path) { | 4422 | if (!path) { |
4325 | ret = -ENOMEM; | 4423 | ret = -ENOMEM; |
4326 | mlog_errno(ret); | 4424 | mlog_errno(ret); |
@@ -4531,9 +4629,9 @@ int ocfs2_add_clusters_in_btree(struct ocfs2_super *osb, | |||
4531 | 4629 | ||
4532 | BUG_ON(num_bits > clusters_to_add); | 4630 | BUG_ON(num_bits > clusters_to_add); |
4533 | 4631 | ||
4534 | /* reserve our write early -- insert_extent may update the inode */ | 4632 | /* reserve our write early -- insert_extent may update the tree root */ |
4535 | status = ocfs2_journal_access(handle, inode, et->et_root_bh, | 4633 | status = ocfs2_et_root_journal_access(handle, inode, et, |
4536 | OCFS2_JOURNAL_ACCESS_WRITE); | 4634 | OCFS2_JOURNAL_ACCESS_WRITE); |
4537 | if (status < 0) { | 4635 | if (status < 0) { |
4538 | mlog_errno(status); | 4636 | mlog_errno(status); |
4539 | goto leave; | 4637 | goto leave; |
@@ -4760,20 +4858,15 @@ static int __ocfs2_mark_extent_written(struct inode *inode, | |||
4760 | if (path->p_tree_depth) { | 4858 | if (path->p_tree_depth) { |
4761 | struct ocfs2_extent_block *eb; | 4859 | struct ocfs2_extent_block *eb; |
4762 | 4860 | ||
4763 | ret = ocfs2_read_block(inode, ocfs2_et_get_last_eb_blk(et), | 4861 | ret = ocfs2_read_extent_block(inode, |
4764 | &last_eb_bh); | 4862 | ocfs2_et_get_last_eb_blk(et), |
4863 | &last_eb_bh); | ||
4765 | if (ret) { | 4864 | if (ret) { |
4766 | mlog_exit(ret); | 4865 | mlog_exit(ret); |
4767 | goto out; | 4866 | goto out; |
4768 | } | 4867 | } |
4769 | 4868 | ||
4770 | eb = (struct ocfs2_extent_block *) last_eb_bh->b_data; | 4869 | eb = (struct ocfs2_extent_block *) last_eb_bh->b_data; |
4771 | if (!OCFS2_IS_VALID_EXTENT_BLOCK(eb)) { | ||
4772 | OCFS2_RO_ON_INVALID_EXTENT_BLOCK(inode->i_sb, eb); | ||
4773 | ret = -EROFS; | ||
4774 | goto out; | ||
4775 | } | ||
4776 | |||
4777 | rightmost_el = &eb->h_list; | 4870 | rightmost_el = &eb->h_list; |
4778 | } else | 4871 | } else |
4779 | rightmost_el = path_root_el(path); | 4872 | rightmost_el = path_root_el(path); |
@@ -4854,7 +4947,7 @@ int ocfs2_mark_extent_written(struct inode *inode, | |||
4854 | if (et->et_ops == &ocfs2_dinode_et_ops) | 4947 | if (et->et_ops == &ocfs2_dinode_et_ops) |
4855 | ocfs2_extent_map_trunc(inode, 0); | 4948 | ocfs2_extent_map_trunc(inode, 0); |
4856 | 4949 | ||
4857 | left_path = ocfs2_new_path(et->et_root_bh, et->et_root_el); | 4950 | left_path = ocfs2_new_path_from_et(et); |
4858 | if (!left_path) { | 4951 | if (!left_path) { |
4859 | ret = -ENOMEM; | 4952 | ret = -ENOMEM; |
4860 | mlog_errno(ret); | 4953 | mlog_errno(ret); |
@@ -4918,8 +5011,9 @@ static int ocfs2_split_tree(struct inode *inode, struct ocfs2_extent_tree *et, | |||
4918 | 5011 | ||
4919 | depth = path->p_tree_depth; | 5012 | depth = path->p_tree_depth; |
4920 | if (depth > 0) { | 5013 | if (depth > 0) { |
4921 | ret = ocfs2_read_block(inode, ocfs2_et_get_last_eb_blk(et), | 5014 | ret = ocfs2_read_extent_block(inode, |
4922 | &last_eb_bh); | 5015 | ocfs2_et_get_last_eb_blk(et), |
5016 | &last_eb_bh); | ||
4923 | if (ret < 0) { | 5017 | if (ret < 0) { |
4924 | mlog_errno(ret); | 5018 | mlog_errno(ret); |
4925 | goto out; | 5019 | goto out; |
@@ -5025,8 +5119,7 @@ static int ocfs2_truncate_rec(struct inode *inode, handle_t *handle, | |||
5025 | } | 5119 | } |
5026 | 5120 | ||
5027 | if (left_cpos && le16_to_cpu(el->l_next_free_rec) > 1) { | 5121 | if (left_cpos && le16_to_cpu(el->l_next_free_rec) > 1) { |
5028 | left_path = ocfs2_new_path(path_root_bh(path), | 5122 | left_path = ocfs2_new_path_from_path(path); |
5029 | path_root_el(path)); | ||
5030 | if (!left_path) { | 5123 | if (!left_path) { |
5031 | ret = -ENOMEM; | 5124 | ret = -ENOMEM; |
5032 | mlog_errno(ret); | 5125 | mlog_errno(ret); |
@@ -5135,7 +5228,7 @@ int ocfs2_remove_extent(struct inode *inode, | |||
5135 | 5228 | ||
5136 | ocfs2_extent_map_trunc(inode, 0); | 5229 | ocfs2_extent_map_trunc(inode, 0); |
5137 | 5230 | ||
5138 | path = ocfs2_new_path(et->et_root_bh, et->et_root_el); | 5231 | path = ocfs2_new_path_from_et(et); |
5139 | if (!path) { | 5232 | if (!path) { |
5140 | ret = -ENOMEM; | 5233 | ret = -ENOMEM; |
5141 | mlog_errno(ret); | 5234 | mlog_errno(ret); |
@@ -5255,6 +5348,81 @@ out: | |||
5255 | return ret; | 5348 | return ret; |
5256 | } | 5349 | } |
5257 | 5350 | ||
5351 | int ocfs2_remove_btree_range(struct inode *inode, | ||
5352 | struct ocfs2_extent_tree *et, | ||
5353 | u32 cpos, u32 phys_cpos, u32 len, | ||
5354 | struct ocfs2_cached_dealloc_ctxt *dealloc) | ||
5355 | { | ||
5356 | int ret; | ||
5357 | u64 phys_blkno = ocfs2_clusters_to_blocks(inode->i_sb, phys_cpos); | ||
5358 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
5359 | struct inode *tl_inode = osb->osb_tl_inode; | ||
5360 | handle_t *handle; | ||
5361 | struct ocfs2_alloc_context *meta_ac = NULL; | ||
5362 | |||
5363 | ret = ocfs2_lock_allocators(inode, et, 0, 1, NULL, &meta_ac); | ||
5364 | if (ret) { | ||
5365 | mlog_errno(ret); | ||
5366 | return ret; | ||
5367 | } | ||
5368 | |||
5369 | mutex_lock(&tl_inode->i_mutex); | ||
5370 | |||
5371 | if (ocfs2_truncate_log_needs_flush(osb)) { | ||
5372 | ret = __ocfs2_flush_truncate_log(osb); | ||
5373 | if (ret < 0) { | ||
5374 | mlog_errno(ret); | ||
5375 | goto out; | ||
5376 | } | ||
5377 | } | ||
5378 | |||
5379 | handle = ocfs2_start_trans(osb, ocfs2_remove_extent_credits(osb->sb)); | ||
5380 | if (IS_ERR(handle)) { | ||
5381 | ret = PTR_ERR(handle); | ||
5382 | mlog_errno(ret); | ||
5383 | goto out; | ||
5384 | } | ||
5385 | |||
5386 | ret = ocfs2_et_root_journal_access(handle, inode, et, | ||
5387 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
5388 | if (ret) { | ||
5389 | mlog_errno(ret); | ||
5390 | goto out; | ||
5391 | } | ||
5392 | |||
5393 | vfs_dq_free_space_nodirty(inode, | ||
5394 | ocfs2_clusters_to_bytes(inode->i_sb, len)); | ||
5395 | |||
5396 | ret = ocfs2_remove_extent(inode, et, cpos, len, handle, meta_ac, | ||
5397 | dealloc); | ||
5398 | if (ret) { | ||
5399 | mlog_errno(ret); | ||
5400 | goto out_commit; | ||
5401 | } | ||
5402 | |||
5403 | ocfs2_et_update_clusters(inode, et, -len); | ||
5404 | |||
5405 | ret = ocfs2_journal_dirty(handle, et->et_root_bh); | ||
5406 | if (ret) { | ||
5407 | mlog_errno(ret); | ||
5408 | goto out_commit; | ||
5409 | } | ||
5410 | |||
5411 | ret = ocfs2_truncate_log_append(osb, handle, phys_blkno, len); | ||
5412 | if (ret) | ||
5413 | mlog_errno(ret); | ||
5414 | |||
5415 | out_commit: | ||
5416 | ocfs2_commit_trans(osb, handle); | ||
5417 | out: | ||
5418 | mutex_unlock(&tl_inode->i_mutex); | ||
5419 | |||
5420 | if (meta_ac) | ||
5421 | ocfs2_free_alloc_context(meta_ac); | ||
5422 | |||
5423 | return ret; | ||
5424 | } | ||
5425 | |||
5258 | int ocfs2_truncate_log_needs_flush(struct ocfs2_super *osb) | 5426 | int ocfs2_truncate_log_needs_flush(struct ocfs2_super *osb) |
5259 | { | 5427 | { |
5260 | struct buffer_head *tl_bh = osb->osb_tl_bh; | 5428 | struct buffer_head *tl_bh = osb->osb_tl_bh; |
@@ -5308,13 +5476,13 @@ int ocfs2_truncate_log_append(struct ocfs2_super *osb, | |||
5308 | start_cluster = ocfs2_blocks_to_clusters(osb->sb, start_blk); | 5476 | start_cluster = ocfs2_blocks_to_clusters(osb->sb, start_blk); |
5309 | 5477 | ||
5310 | di = (struct ocfs2_dinode *) tl_bh->b_data; | 5478 | di = (struct ocfs2_dinode *) tl_bh->b_data; |
5311 | tl = &di->id2.i_dealloc; | ||
5312 | if (!OCFS2_IS_VALID_DINODE(di)) { | ||
5313 | OCFS2_RO_ON_INVALID_DINODE(osb->sb, di); | ||
5314 | status = -EIO; | ||
5315 | goto bail; | ||
5316 | } | ||
5317 | 5479 | ||
5480 | /* tl_bh is loaded from ocfs2_truncate_log_init(). It's validated | ||
5481 | * by the underlying call to ocfs2_read_inode_block(), so any | ||
5482 | * corruption is a code bug */ | ||
5483 | BUG_ON(!OCFS2_IS_VALID_DINODE(di)); | ||
5484 | |||
5485 | tl = &di->id2.i_dealloc; | ||
5318 | tl_count = le16_to_cpu(tl->tl_count); | 5486 | tl_count = le16_to_cpu(tl->tl_count); |
5319 | mlog_bug_on_msg(tl_count > ocfs2_truncate_recs_per_inode(osb->sb) || | 5487 | mlog_bug_on_msg(tl_count > ocfs2_truncate_recs_per_inode(osb->sb) || |
5320 | tl_count == 0, | 5488 | tl_count == 0, |
@@ -5332,8 +5500,8 @@ int ocfs2_truncate_log_append(struct ocfs2_super *osb, | |||
5332 | goto bail; | 5500 | goto bail; |
5333 | } | 5501 | } |
5334 | 5502 | ||
5335 | status = ocfs2_journal_access(handle, tl_inode, tl_bh, | 5503 | status = ocfs2_journal_access_di(handle, tl_inode, tl_bh, |
5336 | OCFS2_JOURNAL_ACCESS_WRITE); | 5504 | OCFS2_JOURNAL_ACCESS_WRITE); |
5337 | if (status < 0) { | 5505 | if (status < 0) { |
5338 | mlog_errno(status); | 5506 | mlog_errno(status); |
5339 | goto bail; | 5507 | goto bail; |
@@ -5394,8 +5562,8 @@ static int ocfs2_replay_truncate_records(struct ocfs2_super *osb, | |||
5394 | while (i >= 0) { | 5562 | while (i >= 0) { |
5395 | /* Caller has given us at least enough credits to | 5563 | /* Caller has given us at least enough credits to |
5396 | * update the truncate log dinode */ | 5564 | * update the truncate log dinode */ |
5397 | status = ocfs2_journal_access(handle, tl_inode, tl_bh, | 5565 | status = ocfs2_journal_access_di(handle, tl_inode, tl_bh, |
5398 | OCFS2_JOURNAL_ACCESS_WRITE); | 5566 | OCFS2_JOURNAL_ACCESS_WRITE); |
5399 | if (status < 0) { | 5567 | if (status < 0) { |
5400 | mlog_errno(status); | 5568 | mlog_errno(status); |
5401 | goto bail; | 5569 | goto bail; |
@@ -5464,13 +5632,13 @@ int __ocfs2_flush_truncate_log(struct ocfs2_super *osb) | |||
5464 | BUG_ON(mutex_trylock(&tl_inode->i_mutex)); | 5632 | BUG_ON(mutex_trylock(&tl_inode->i_mutex)); |
5465 | 5633 | ||
5466 | di = (struct ocfs2_dinode *) tl_bh->b_data; | 5634 | di = (struct ocfs2_dinode *) tl_bh->b_data; |
5467 | tl = &di->id2.i_dealloc; | ||
5468 | if (!OCFS2_IS_VALID_DINODE(di)) { | ||
5469 | OCFS2_RO_ON_INVALID_DINODE(osb->sb, di); | ||
5470 | status = -EIO; | ||
5471 | goto out; | ||
5472 | } | ||
5473 | 5635 | ||
5636 | /* tl_bh is loaded from ocfs2_truncate_log_init(). It's validated | ||
5637 | * by the underlying call to ocfs2_read_inode_block(), so any | ||
5638 | * corruption is a code bug */ | ||
5639 | BUG_ON(!OCFS2_IS_VALID_DINODE(di)); | ||
5640 | |||
5641 | tl = &di->id2.i_dealloc; | ||
5474 | num_to_flush = le16_to_cpu(tl->tl_used); | 5642 | num_to_flush = le16_to_cpu(tl->tl_used); |
5475 | mlog(0, "Flush %u records from truncate log #%llu\n", | 5643 | mlog(0, "Flush %u records from truncate log #%llu\n", |
5476 | num_to_flush, (unsigned long long)OCFS2_I(tl_inode)->ip_blkno); | 5644 | num_to_flush, (unsigned long long)OCFS2_I(tl_inode)->ip_blkno); |
@@ -5586,7 +5754,7 @@ static int ocfs2_get_truncate_log_info(struct ocfs2_super *osb, | |||
5586 | goto bail; | 5754 | goto bail; |
5587 | } | 5755 | } |
5588 | 5756 | ||
5589 | status = ocfs2_read_block(inode, OCFS2_I(inode)->ip_blkno, &bh); | 5757 | status = ocfs2_read_inode_block(inode, &bh); |
5590 | if (status < 0) { | 5758 | if (status < 0) { |
5591 | iput(inode); | 5759 | iput(inode); |
5592 | mlog_errno(status); | 5760 | mlog_errno(status); |
@@ -5625,13 +5793,13 @@ int ocfs2_begin_truncate_log_recovery(struct ocfs2_super *osb, | |||
5625 | } | 5793 | } |
5626 | 5794 | ||
5627 | di = (struct ocfs2_dinode *) tl_bh->b_data; | 5795 | di = (struct ocfs2_dinode *) tl_bh->b_data; |
5628 | tl = &di->id2.i_dealloc; | ||
5629 | if (!OCFS2_IS_VALID_DINODE(di)) { | ||
5630 | OCFS2_RO_ON_INVALID_DINODE(tl_inode->i_sb, di); | ||
5631 | status = -EIO; | ||
5632 | goto bail; | ||
5633 | } | ||
5634 | 5796 | ||
5797 | /* tl_bh is loaded from ocfs2_get_truncate_log_info(). It's | ||
5798 | * validated by the underlying call to ocfs2_read_inode_block(), | ||
5799 | * so any corruption is a code bug */ | ||
5800 | BUG_ON(!OCFS2_IS_VALID_DINODE(di)); | ||
5801 | |||
5802 | tl = &di->id2.i_dealloc; | ||
5635 | if (le16_to_cpu(tl->tl_used)) { | 5803 | if (le16_to_cpu(tl->tl_used)) { |
5636 | mlog(0, "We'll have %u logs to recover\n", | 5804 | mlog(0, "We'll have %u logs to recover\n", |
5637 | le16_to_cpu(tl->tl_used)); | 5805 | le16_to_cpu(tl->tl_used)); |
@@ -5651,6 +5819,7 @@ int ocfs2_begin_truncate_log_recovery(struct ocfs2_super *osb, | |||
5651 | * tl_used. */ | 5819 | * tl_used. */ |
5652 | tl->tl_used = 0; | 5820 | tl->tl_used = 0; |
5653 | 5821 | ||
5822 | ocfs2_compute_meta_ecc(osb->sb, tl_bh->b_data, &di->i_check); | ||
5654 | status = ocfs2_write_block(osb, tl_bh, tl_inode); | 5823 | status = ocfs2_write_block(osb, tl_bh, tl_inode); |
5655 | if (status < 0) { | 5824 | if (status < 0) { |
5656 | mlog_errno(status); | 5825 | mlog_errno(status); |
@@ -5800,7 +5969,10 @@ int ocfs2_truncate_log_init(struct ocfs2_super *osb) | |||
5800 | */ | 5969 | */ |
5801 | 5970 | ||
5802 | /* | 5971 | /* |
5803 | * Describes a single block free from a suballocator | 5972 | * Describe a single bit freed from a suballocator. For the block |
5973 | * suballocators, it represents one block. For the global cluster | ||
5974 | * allocator, it represents some clusters and free_bit indicates | ||
5975 | * clusters number. | ||
5804 | */ | 5976 | */ |
5805 | struct ocfs2_cached_block_free { | 5977 | struct ocfs2_cached_block_free { |
5806 | struct ocfs2_cached_block_free *free_next; | 5978 | struct ocfs2_cached_block_free *free_next; |
@@ -5815,10 +5987,10 @@ struct ocfs2_per_slot_free_list { | |||
5815 | struct ocfs2_cached_block_free *f_first; | 5987 | struct ocfs2_cached_block_free *f_first; |
5816 | }; | 5988 | }; |
5817 | 5989 | ||
5818 | static int ocfs2_free_cached_items(struct ocfs2_super *osb, | 5990 | static int ocfs2_free_cached_blocks(struct ocfs2_super *osb, |
5819 | int sysfile_type, | 5991 | int sysfile_type, |
5820 | int slot, | 5992 | int slot, |
5821 | struct ocfs2_cached_block_free *head) | 5993 | struct ocfs2_cached_block_free *head) |
5822 | { | 5994 | { |
5823 | int ret; | 5995 | int ret; |
5824 | u64 bg_blkno; | 5996 | u64 bg_blkno; |
@@ -5893,6 +6065,82 @@ out: | |||
5893 | return ret; | 6065 | return ret; |
5894 | } | 6066 | } |
5895 | 6067 | ||
6068 | int ocfs2_cache_cluster_dealloc(struct ocfs2_cached_dealloc_ctxt *ctxt, | ||
6069 | u64 blkno, unsigned int bit) | ||
6070 | { | ||
6071 | int ret = 0; | ||
6072 | struct ocfs2_cached_block_free *item; | ||
6073 | |||
6074 | item = kmalloc(sizeof(*item), GFP_NOFS); | ||
6075 | if (item == NULL) { | ||
6076 | ret = -ENOMEM; | ||
6077 | mlog_errno(ret); | ||
6078 | return ret; | ||
6079 | } | ||
6080 | |||
6081 | mlog(0, "Insert clusters: (bit %u, blk %llu)\n", | ||
6082 | bit, (unsigned long long)blkno); | ||
6083 | |||
6084 | item->free_blk = blkno; | ||
6085 | item->free_bit = bit; | ||
6086 | item->free_next = ctxt->c_global_allocator; | ||
6087 | |||
6088 | ctxt->c_global_allocator = item; | ||
6089 | return ret; | ||
6090 | } | ||
6091 | |||
6092 | static int ocfs2_free_cached_clusters(struct ocfs2_super *osb, | ||
6093 | struct ocfs2_cached_block_free *head) | ||
6094 | { | ||
6095 | struct ocfs2_cached_block_free *tmp; | ||
6096 | struct inode *tl_inode = osb->osb_tl_inode; | ||
6097 | handle_t *handle; | ||
6098 | int ret = 0; | ||
6099 | |||
6100 | mutex_lock(&tl_inode->i_mutex); | ||
6101 | |||
6102 | while (head) { | ||
6103 | if (ocfs2_truncate_log_needs_flush(osb)) { | ||
6104 | ret = __ocfs2_flush_truncate_log(osb); | ||
6105 | if (ret < 0) { | ||
6106 | mlog_errno(ret); | ||
6107 | break; | ||
6108 | } | ||
6109 | } | ||
6110 | |||
6111 | handle = ocfs2_start_trans(osb, OCFS2_TRUNCATE_LOG_UPDATE); | ||
6112 | if (IS_ERR(handle)) { | ||
6113 | ret = PTR_ERR(handle); | ||
6114 | mlog_errno(ret); | ||
6115 | break; | ||
6116 | } | ||
6117 | |||
6118 | ret = ocfs2_truncate_log_append(osb, handle, head->free_blk, | ||
6119 | head->free_bit); | ||
6120 | |||
6121 | ocfs2_commit_trans(osb, handle); | ||
6122 | tmp = head; | ||
6123 | head = head->free_next; | ||
6124 | kfree(tmp); | ||
6125 | |||
6126 | if (ret < 0) { | ||
6127 | mlog_errno(ret); | ||
6128 | break; | ||
6129 | } | ||
6130 | } | ||
6131 | |||
6132 | mutex_unlock(&tl_inode->i_mutex); | ||
6133 | |||
6134 | while (head) { | ||
6135 | /* Premature exit may have left some dangling items. */ | ||
6136 | tmp = head; | ||
6137 | head = head->free_next; | ||
6138 | kfree(tmp); | ||
6139 | } | ||
6140 | |||
6141 | return ret; | ||
6142 | } | ||
6143 | |||
5896 | int ocfs2_run_deallocs(struct ocfs2_super *osb, | 6144 | int ocfs2_run_deallocs(struct ocfs2_super *osb, |
5897 | struct ocfs2_cached_dealloc_ctxt *ctxt) | 6145 | struct ocfs2_cached_dealloc_ctxt *ctxt) |
5898 | { | 6146 | { |
@@ -5908,8 +6156,10 @@ int ocfs2_run_deallocs(struct ocfs2_super *osb, | |||
5908 | if (fl->f_first) { | 6156 | if (fl->f_first) { |
5909 | mlog(0, "Free items: (type %u, slot %d)\n", | 6157 | mlog(0, "Free items: (type %u, slot %d)\n", |
5910 | fl->f_inode_type, fl->f_slot); | 6158 | fl->f_inode_type, fl->f_slot); |
5911 | ret2 = ocfs2_free_cached_items(osb, fl->f_inode_type, | 6159 | ret2 = ocfs2_free_cached_blocks(osb, |
5912 | fl->f_slot, fl->f_first); | 6160 | fl->f_inode_type, |
6161 | fl->f_slot, | ||
6162 | fl->f_first); | ||
5913 | if (ret2) | 6163 | if (ret2) |
5914 | mlog_errno(ret2); | 6164 | mlog_errno(ret2); |
5915 | if (!ret) | 6165 | if (!ret) |
@@ -5920,6 +6170,17 @@ int ocfs2_run_deallocs(struct ocfs2_super *osb, | |||
5920 | kfree(fl); | 6170 | kfree(fl); |
5921 | } | 6171 | } |
5922 | 6172 | ||
6173 | if (ctxt->c_global_allocator) { | ||
6174 | ret2 = ocfs2_free_cached_clusters(osb, | ||
6175 | ctxt->c_global_allocator); | ||
6176 | if (ret2) | ||
6177 | mlog_errno(ret2); | ||
6178 | if (!ret) | ||
6179 | ret = ret2; | ||
6180 | |||
6181 | ctxt->c_global_allocator = NULL; | ||
6182 | } | ||
6183 | |||
5923 | return ret; | 6184 | return ret; |
5924 | } | 6185 | } |
5925 | 6186 | ||
@@ -6075,11 +6336,10 @@ static int ocfs2_find_new_last_ext_blk(struct inode *inode, | |||
6075 | 6336 | ||
6076 | eb = (struct ocfs2_extent_block *) bh->b_data; | 6337 | eb = (struct ocfs2_extent_block *) bh->b_data; |
6077 | el = &eb->h_list; | 6338 | el = &eb->h_list; |
6078 | if (!OCFS2_IS_VALID_EXTENT_BLOCK(eb)) { | 6339 | |
6079 | OCFS2_RO_ON_INVALID_EXTENT_BLOCK(inode->i_sb, eb); | 6340 | /* ocfs2_find_leaf() gets the eb from ocfs2_read_extent_block(). |
6080 | ret = -EROFS; | 6341 | * Any corruption is a code bug. */ |
6081 | goto out; | 6342 | BUG_ON(!OCFS2_IS_VALID_EXTENT_BLOCK(eb)); |
6082 | } | ||
6083 | 6343 | ||
6084 | *new_last_eb = bh; | 6344 | *new_last_eb = bh; |
6085 | get_bh(*new_last_eb); | 6345 | get_bh(*new_last_eb); |
@@ -6326,8 +6586,8 @@ static int ocfs2_do_truncate(struct ocfs2_super *osb, | |||
6326 | } | 6586 | } |
6327 | 6587 | ||
6328 | if (last_eb_bh) { | 6588 | if (last_eb_bh) { |
6329 | status = ocfs2_journal_access(handle, inode, last_eb_bh, | 6589 | status = ocfs2_journal_access_eb(handle, inode, last_eb_bh, |
6330 | OCFS2_JOURNAL_ACCESS_WRITE); | 6590 | OCFS2_JOURNAL_ACCESS_WRITE); |
6331 | if (status < 0) { | 6591 | if (status < 0) { |
6332 | mlog_errno(status); | 6592 | mlog_errno(status); |
6333 | goto bail; | 6593 | goto bail; |
@@ -6350,6 +6610,8 @@ static int ocfs2_do_truncate(struct ocfs2_super *osb, | |||
6350 | goto bail; | 6610 | goto bail; |
6351 | } | 6611 | } |
6352 | 6612 | ||
6613 | vfs_dq_free_space_nodirty(inode, | ||
6614 | ocfs2_clusters_to_bytes(osb->sb, clusters_to_del)); | ||
6353 | spin_lock(&OCFS2_I(inode)->ip_lock); | 6615 | spin_lock(&OCFS2_I(inode)->ip_lock); |
6354 | OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters) - | 6616 | OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters) - |
6355 | clusters_to_del; | 6617 | clusters_to_del; |
@@ -6436,11 +6698,6 @@ static void ocfs2_map_and_dirty_page(struct inode *inode, handle_t *handle, | |||
6436 | mlog_errno(ret); | 6698 | mlog_errno(ret); |
6437 | else if (ocfs2_should_order_data(inode)) { | 6699 | else if (ocfs2_should_order_data(inode)) { |
6438 | ret = ocfs2_jbd2_file_inode(handle, inode); | 6700 | ret = ocfs2_jbd2_file_inode(handle, inode); |
6439 | #ifdef CONFIG_OCFS2_COMPAT_JBD | ||
6440 | ret = walk_page_buffers(handle, page_buffers(page), | ||
6441 | from, to, &partial, | ||
6442 | ocfs2_journal_dirty_data); | ||
6443 | #endif | ||
6444 | if (ret < 0) | 6701 | if (ret < 0) |
6445 | mlog_errno(ret); | 6702 | mlog_errno(ret); |
6446 | } | 6703 | } |
@@ -6663,6 +6920,7 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode, | |||
6663 | struct page **pages = NULL; | 6920 | struct page **pages = NULL; |
6664 | loff_t end = osb->s_clustersize; | 6921 | loff_t end = osb->s_clustersize; |
6665 | struct ocfs2_extent_tree et; | 6922 | struct ocfs2_extent_tree et; |
6923 | int did_quota = 0; | ||
6666 | 6924 | ||
6667 | has_data = i_size_read(inode) ? 1 : 0; | 6925 | has_data = i_size_read(inode) ? 1 : 0; |
6668 | 6926 | ||
@@ -6682,15 +6940,16 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode, | |||
6682 | } | 6940 | } |
6683 | } | 6941 | } |
6684 | 6942 | ||
6685 | handle = ocfs2_start_trans(osb, OCFS2_INLINE_TO_EXTENTS_CREDITS); | 6943 | handle = ocfs2_start_trans(osb, |
6944 | ocfs2_inline_to_extents_credits(osb->sb)); | ||
6686 | if (IS_ERR(handle)) { | 6945 | if (IS_ERR(handle)) { |
6687 | ret = PTR_ERR(handle); | 6946 | ret = PTR_ERR(handle); |
6688 | mlog_errno(ret); | 6947 | mlog_errno(ret); |
6689 | goto out_unlock; | 6948 | goto out_unlock; |
6690 | } | 6949 | } |
6691 | 6950 | ||
6692 | ret = ocfs2_journal_access(handle, inode, di_bh, | 6951 | ret = ocfs2_journal_access_di(handle, inode, di_bh, |
6693 | OCFS2_JOURNAL_ACCESS_WRITE); | 6952 | OCFS2_JOURNAL_ACCESS_WRITE); |
6694 | if (ret) { | 6953 | if (ret) { |
6695 | mlog_errno(ret); | 6954 | mlog_errno(ret); |
6696 | goto out_commit; | 6955 | goto out_commit; |
@@ -6701,6 +6960,13 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode, | |||
6701 | unsigned int page_end; | 6960 | unsigned int page_end; |
6702 | u64 phys; | 6961 | u64 phys; |
6703 | 6962 | ||
6963 | if (vfs_dq_alloc_space_nodirty(inode, | ||
6964 | ocfs2_clusters_to_bytes(osb->sb, 1))) { | ||
6965 | ret = -EDQUOT; | ||
6966 | goto out_commit; | ||
6967 | } | ||
6968 | did_quota = 1; | ||
6969 | |||
6704 | ret = ocfs2_claim_clusters(osb, handle, data_ac, 1, &bit_off, | 6970 | ret = ocfs2_claim_clusters(osb, handle, data_ac, 1, &bit_off, |
6705 | &num); | 6971 | &num); |
6706 | if (ret) { | 6972 | if (ret) { |
@@ -6774,6 +7040,10 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode, | |||
6774 | } | 7040 | } |
6775 | 7041 | ||
6776 | out_commit: | 7042 | out_commit: |
7043 | if (ret < 0 && did_quota) | ||
7044 | vfs_dq_free_space_nodirty(inode, | ||
7045 | ocfs2_clusters_to_bytes(osb->sb, 1)); | ||
7046 | |||
6777 | ocfs2_commit_trans(osb, handle); | 7047 | ocfs2_commit_trans(osb, handle); |
6778 | 7048 | ||
6779 | out_unlock: | 7049 | out_unlock: |
@@ -6813,7 +7083,8 @@ int ocfs2_commit_truncate(struct ocfs2_super *osb, | |||
6813 | new_highest_cpos = ocfs2_clusters_for_bytes(osb->sb, | 7083 | new_highest_cpos = ocfs2_clusters_for_bytes(osb->sb, |
6814 | i_size_read(inode)); | 7084 | i_size_read(inode)); |
6815 | 7085 | ||
6816 | path = ocfs2_new_path(fe_bh, &di->id2.i_list); | 7086 | path = ocfs2_new_path(fe_bh, &di->id2.i_list, |
7087 | ocfs2_journal_access_di); | ||
6817 | if (!path) { | 7088 | if (!path) { |
6818 | status = -ENOMEM; | 7089 | status = -ENOMEM; |
6819 | mlog_errno(status); | 7090 | mlog_errno(status); |
@@ -6984,20 +7255,14 @@ int ocfs2_prepare_truncate(struct ocfs2_super *osb, | |||
6984 | ocfs2_init_dealloc_ctxt(&(*tc)->tc_dealloc); | 7255 | ocfs2_init_dealloc_ctxt(&(*tc)->tc_dealloc); |
6985 | 7256 | ||
6986 | if (fe->id2.i_list.l_tree_depth) { | 7257 | if (fe->id2.i_list.l_tree_depth) { |
6987 | status = ocfs2_read_block(inode, le64_to_cpu(fe->i_last_eb_blk), | 7258 | status = ocfs2_read_extent_block(inode, |
6988 | &last_eb_bh); | 7259 | le64_to_cpu(fe->i_last_eb_blk), |
7260 | &last_eb_bh); | ||
6989 | if (status < 0) { | 7261 | if (status < 0) { |
6990 | mlog_errno(status); | 7262 | mlog_errno(status); |
6991 | goto bail; | 7263 | goto bail; |
6992 | } | 7264 | } |
6993 | eb = (struct ocfs2_extent_block *) last_eb_bh->b_data; | 7265 | eb = (struct ocfs2_extent_block *) last_eb_bh->b_data; |
6994 | if (!OCFS2_IS_VALID_EXTENT_BLOCK(eb)) { | ||
6995 | OCFS2_RO_ON_INVALID_EXTENT_BLOCK(inode->i_sb, eb); | ||
6996 | |||
6997 | brelse(last_eb_bh); | ||
6998 | status = -EIO; | ||
6999 | goto bail; | ||
7000 | } | ||
7001 | } | 7266 | } |
7002 | 7267 | ||
7003 | (*tc)->tc_last_eb_bh = last_eb_bh; | 7268 | (*tc)->tc_last_eb_bh = last_eb_bh; |
@@ -7052,8 +7317,8 @@ int ocfs2_truncate_inline(struct inode *inode, struct buffer_head *di_bh, | |||
7052 | goto out; | 7317 | goto out; |
7053 | } | 7318 | } |
7054 | 7319 | ||
7055 | ret = ocfs2_journal_access(handle, inode, di_bh, | 7320 | ret = ocfs2_journal_access_di(handle, inode, di_bh, |
7056 | OCFS2_JOURNAL_ACCESS_WRITE); | 7321 | OCFS2_JOURNAL_ACCESS_WRITE); |
7057 | if (ret) { | 7322 | if (ret) { |
7058 | mlog_errno(ret); | 7323 | mlog_errno(ret); |
7059 | goto out_commit; | 7324 | goto out_commit; |