alloc.c (d9a0a1f83bf083b55b3c1f16efddecc31abace61) alloc.c (3d03a305ded8057155bd3c801e64ffef9f534827)
1/* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
3 *
4 * alloc.c
5 *
6 * Extent allocs and frees
7 *
8 * Copyright (C) 2002, 2004 Oracle. All rights reserved.

--- 840 unchanged lines hidden (view full) ---

849 (unsigned long long)bh->b_blocknr,
850 le32_to_cpu(eb->h_fs_generation));
851 return -EINVAL;
852 }
853
854 return 0;
855}
856
1/* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
3 *
4 * alloc.c
5 *
6 * Extent allocs and frees
7 *
8 * Copyright (C) 2002, 2004 Oracle. All rights reserved.

--- 840 unchanged lines hidden (view full) ---

849 (unsigned long long)bh->b_blocknr,
850 le32_to_cpu(eb->h_fs_generation));
851 return -EINVAL;
852 }
853
854 return 0;
855}
856
857int ocfs2_read_extent_block(struct inode *inode, u64 eb_blkno,
857int ocfs2_read_extent_block(struct ocfs2_caching_info *ci, u64 eb_blkno,
858 struct buffer_head **bh)
859{
860 int rc;
861 struct buffer_head *tmp = *bh;
862
858 struct buffer_head **bh)
859{
860 int rc;
861 struct buffer_head *tmp = *bh;
862
863 rc = ocfs2_read_block(INODE_CACHE(inode), eb_blkno, &tmp,
863 rc = ocfs2_read_block(ci, eb_blkno, &tmp,
864 ocfs2_validate_extent_block);
865
866 /* If ocfs2_read_block() got us a new bh, pass it up. */
867 if (!rc && !*bh)
868 *bh = tmp;
869
870 return rc;
871}
872
873
874/*
875 * How many free extents have we got before we need more meta data?
876 */
877int ocfs2_num_free_extents(struct ocfs2_super *osb,
864 ocfs2_validate_extent_block);
865
866 /* If ocfs2_read_block() got us a new bh, pass it up. */
867 if (!rc && !*bh)
868 *bh = tmp;
869
870 return rc;
871}
872
873
874/*
875 * How many free extents have we got before we need more meta data?
876 */
877int ocfs2_num_free_extents(struct ocfs2_super *osb,
878 struct inode *inode,
879 struct ocfs2_extent_tree *et)
880{
881 int retval;
882 struct ocfs2_extent_list *el = NULL;
883 struct ocfs2_extent_block *eb;
884 struct buffer_head *eb_bh = NULL;
885 u64 last_eb_blk = 0;
886
887 mlog_entry_void();
888
889 el = et->et_root_el;
890 last_eb_blk = ocfs2_et_get_last_eb_blk(et);
891
892 if (last_eb_blk) {
878 struct ocfs2_extent_tree *et)
879{
880 int retval;
881 struct ocfs2_extent_list *el = NULL;
882 struct ocfs2_extent_block *eb;
883 struct buffer_head *eb_bh = NULL;
884 u64 last_eb_blk = 0;
885
886 mlog_entry_void();
887
888 el = et->et_root_el;
889 last_eb_blk = ocfs2_et_get_last_eb_blk(et);
890
891 if (last_eb_blk) {
893 retval = ocfs2_read_extent_block(inode, last_eb_blk, &eb_bh);
892 retval = ocfs2_read_extent_block(et->et_ci, last_eb_blk,
893 &eb_bh);
894 if (retval < 0) {
895 mlog_errno(retval);
896 goto bail;
897 }
898 eb = (struct ocfs2_extent_block *) eb_bh->b_data;
899 el = &eb->h_list;
900 }
901

--- 475 unchanged lines hidden (view full) ---

1377 * pass NULL back in *lowest_eb_bh, but still return '0'
1378 *
1379 * 3) the search fails to find anything AND the root_el is full, in
1380 * which case we return > 0
1381 *
1382 * return status < 0 indicates an error.
1383 */
1384static int ocfs2_find_branch_target(struct ocfs2_super *osb,
894 if (retval < 0) {
895 mlog_errno(retval);
896 goto bail;
897 }
898 eb = (struct ocfs2_extent_block *) eb_bh->b_data;
899 el = &eb->h_list;
900 }
901

--- 475 unchanged lines hidden (view full) ---

1377 * pass NULL back in *lowest_eb_bh, but still return '0'
1378 *
1379 * 3) the search fails to find anything AND the root_el is full, in
1380 * which case we return > 0
1381 *
1382 * return status < 0 indicates an error.
1383 */
1384static int ocfs2_find_branch_target(struct ocfs2_super *osb,
1385 struct inode *inode,
1386 struct ocfs2_extent_tree *et,
1387 struct buffer_head **target_bh)
1388{
1389 int status = 0, i;
1390 u64 blkno;
1391 struct ocfs2_extent_block *eb;
1392 struct ocfs2_extent_list *el;
1393 struct buffer_head *bh = NULL;
1394 struct buffer_head *lowest_bh = NULL;
1395
1396 mlog_entry_void();
1397
1398 *target_bh = NULL;
1399
1400 el = et->et_root_el;
1401
1402 while(le16_to_cpu(el->l_tree_depth) > 1) {
1403 if (le16_to_cpu(el->l_next_free_rec) == 0) {
1385 struct ocfs2_extent_tree *et,
1386 struct buffer_head **target_bh)
1387{
1388 int status = 0, i;
1389 u64 blkno;
1390 struct ocfs2_extent_block *eb;
1391 struct ocfs2_extent_list *el;
1392 struct buffer_head *bh = NULL;
1393 struct buffer_head *lowest_bh = NULL;
1394
1395 mlog_entry_void();
1396
1397 *target_bh = NULL;
1398
1399 el = et->et_root_el;
1400
1401 while(le16_to_cpu(el->l_tree_depth) > 1) {
1402 if (le16_to_cpu(el->l_next_free_rec) == 0) {
1404 ocfs2_error(inode->i_sb, "Dinode %llu has empty "
1403 ocfs2_error(ocfs2_metadata_cache_get_super(et->et_ci),
1404 "Owner %llu has empty "
1405 "extent list (next_free_rec == 0)",
1405 "extent list (next_free_rec == 0)",
1406 (unsigned long long)OCFS2_I(inode)->ip_blkno);
1406 (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci));
1407 status = -EIO;
1408 goto bail;
1409 }
1410 i = le16_to_cpu(el->l_next_free_rec) - 1;
1411 blkno = le64_to_cpu(el->l_recs[i].e_blkno);
1412 if (!blkno) {
1407 status = -EIO;
1408 goto bail;
1409 }
1410 i = le16_to_cpu(el->l_next_free_rec) - 1;
1411 blkno = le64_to_cpu(el->l_recs[i].e_blkno);
1412 if (!blkno) {
1413 ocfs2_error(inode->i_sb, "Dinode %llu has extent "
1413 ocfs2_error(ocfs2_metadata_cache_get_super(et->et_ci),
1414 "Owner %llu has extent "
1414 "list where extent # %d has no physical "
1415 "block start",
1415 "list where extent # %d has no physical "
1416 "block start",
1416 (unsigned long long)OCFS2_I(inode)->ip_blkno, i);
1417 (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci), i);
1417 status = -EIO;
1418 goto bail;
1419 }
1420
1421 brelse(bh);
1422 bh = NULL;
1423
1418 status = -EIO;
1419 goto bail;
1420 }
1421
1422 brelse(bh);
1423 bh = NULL;
1424
1424 status = ocfs2_read_extent_block(inode, blkno, &bh);
1425 status = ocfs2_read_extent_block(et->et_ci, blkno, &bh);
1425 if (status < 0) {
1426 mlog_errno(status);
1427 goto bail;
1428 }
1429
1430 eb = (struct ocfs2_extent_block *) bh->b_data;
1431 el = &eb->h_list;
1432

--- 37 unchanged lines hidden (view full) ---

1470 int ret, shift;
1471 struct ocfs2_extent_list *el = et->et_root_el;
1472 int depth = le16_to_cpu(el->l_tree_depth);
1473 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1474 struct buffer_head *bh = NULL;
1475
1476 BUG_ON(meta_ac == NULL);
1477
1426 if (status < 0) {
1427 mlog_errno(status);
1428 goto bail;
1429 }
1430
1431 eb = (struct ocfs2_extent_block *) bh->b_data;
1432 el = &eb->h_list;
1433

--- 37 unchanged lines hidden (view full) ---

1471 int ret, shift;
1472 struct ocfs2_extent_list *el = et->et_root_el;
1473 int depth = le16_to_cpu(el->l_tree_depth);
1474 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1475 struct buffer_head *bh = NULL;
1476
1477 BUG_ON(meta_ac == NULL);
1478
1478 shift = ocfs2_find_branch_target(osb, inode, et, &bh);
1479 shift = ocfs2_find_branch_target(osb, et, &bh);
1479 if (shift < 0) {
1480 ret = shift;
1481 mlog_errno(ret);
1482 goto out;
1483 }
1484
1485 /* We traveled all the way to the bottom of the allocation tree
1486 * and didn't find room for any more extents - we need to add

--- 288 unchanged lines hidden (view full) ---

1775 (unsigned long long)oi->ip_blkno,
1776 le16_to_cpu(el->l_tree_depth), i);
1777 ret = -EROFS;
1778 goto out;
1779 }
1780
1781 brelse(bh);
1782 bh = NULL;
1480 if (shift < 0) {
1481 ret = shift;
1482 mlog_errno(ret);
1483 goto out;
1484 }
1485
1486 /* We traveled all the way to the bottom of the allocation tree
1487 * and didn't find room for any more extents - we need to add

--- 288 unchanged lines hidden (view full) ---

1776 (unsigned long long)oi->ip_blkno,
1777 le16_to_cpu(el->l_tree_depth), i);
1778 ret = -EROFS;
1779 goto out;
1780 }
1781
1782 brelse(bh);
1783 bh = NULL;
1783 ret = ocfs2_read_extent_block(inode, blkno, &bh);
1784 ret = ocfs2_read_extent_block(INODE_CACHE(inode), blkno, &bh);
1784 if (ret) {
1785 mlog_errno(ret);
1786 goto out;
1787 }
1788
1789 eb = (struct ocfs2_extent_block *) bh->b_data;
1790 el = &eb->h_list;
1791

--- 1235 unchanged lines hidden (view full) ---

3027 }
3028
3029 ret = ocfs2_journal_access_path(et->et_ci, handle, path);
3030 if (ret) {
3031 mlog_errno(ret);
3032 goto out;
3033 }
3034
1785 if (ret) {
1786 mlog_errno(ret);
1787 goto out;
1788 }
1789
1790 eb = (struct ocfs2_extent_block *) bh->b_data;
1791 el = &eb->h_list;
1792

--- 1235 unchanged lines hidden (view full) ---

3028 }
3029
3030 ret = ocfs2_journal_access_path(et->et_ci, handle, path);
3031 if (ret) {
3032 mlog_errno(ret);
3033 goto out;
3034 }
3035
3035 ret = ocfs2_find_cpos_for_left_leaf(inode->i_sb, path, &cpos);
3036 ret = ocfs2_find_cpos_for_left_leaf(ocfs2_metadata_cache_get_super(et->et_ci),
3037 path, &cpos);
3036 if (ret) {
3037 mlog_errno(ret);
3038 goto out;
3039 }
3040
3041 if (cpos) {
3042 /*
3043 * We have a path to the left of this one - it needs

--- 1508 unchanged lines hidden (view full) ---

4552
4553 if (el->l_tree_depth) {
4554 /*
4555 * If we have tree depth, we read in the
4556 * rightmost extent block ahead of time as
4557 * ocfs2_figure_insert_type() and ocfs2_add_branch()
4558 * may want it later.
4559 */
3038 if (ret) {
3039 mlog_errno(ret);
3040 goto out;
3041 }
3042
3043 if (cpos) {
3044 /*
3045 * We have a path to the left of this one - it needs

--- 1508 unchanged lines hidden (view full) ---

4554
4555 if (el->l_tree_depth) {
4556 /*
4557 * If we have tree depth, we read in the
4558 * rightmost extent block ahead of time as
4559 * ocfs2_figure_insert_type() and ocfs2_add_branch()
4560 * may want it later.
4561 */
4560 ret = ocfs2_read_extent_block(inode,
4562 ret = ocfs2_read_extent_block(et->et_ci,
4561 ocfs2_et_get_last_eb_blk(et),
4562 &bh);
4563 if (ret) {
4564 mlog_exit(ret);
4565 goto out;
4566 }
4567 eb = (struct ocfs2_extent_block *) bh->b_data;
4568 el = &eb->h_list;

--- 186 unchanged lines hidden (view full) ---

4755 u64 block;
4756 u8 flags = 0;
4757
4758 BUG_ON(!clusters_to_add);
4759
4760 if (mark_unwritten)
4761 flags = OCFS2_EXT_UNWRITTEN;
4762
4563 ocfs2_et_get_last_eb_blk(et),
4564 &bh);
4565 if (ret) {
4566 mlog_exit(ret);
4567 goto out;
4568 }
4569 eb = (struct ocfs2_extent_block *) bh->b_data;
4570 el = &eb->h_list;

--- 186 unchanged lines hidden (view full) ---

4757 u64 block;
4758 u8 flags = 0;
4759
4760 BUG_ON(!clusters_to_add);
4761
4762 if (mark_unwritten)
4763 flags = OCFS2_EXT_UNWRITTEN;
4764
4763 free_extents = ocfs2_num_free_extents(osb, inode, et);
4765 free_extents = ocfs2_num_free_extents(osb, et);
4764 if (free_extents < 0) {
4765 status = free_extents;
4766 mlog_errno(status);
4767 goto leave;
4768 }
4769
4770 /* there are two cases which could cause us to EAGAIN in the
4771 * we-need-more-metadata case:

--- 271 unchanged lines hidden (view full) ---

5043 /*
5044 * The core merge / split code wants to know how much room is
5045 * left in this inodes allocation tree, so we pass the
5046 * rightmost extent list.
5047 */
5048 if (path->p_tree_depth) {
5049 struct ocfs2_extent_block *eb;
5050
4766 if (free_extents < 0) {
4767 status = free_extents;
4768 mlog_errno(status);
4769 goto leave;
4770 }
4771
4772 /* there are two cases which could cause us to EAGAIN in the
4773 * we-need-more-metadata case:

--- 271 unchanged lines hidden (view full) ---

5045 /*
5046 * The core merge / split code wants to know how much room is
5047 * left in this inodes allocation tree, so we pass the
5048 * rightmost extent list.
5049 */
5050 if (path->p_tree_depth) {
5051 struct ocfs2_extent_block *eb;
5052
5051 ret = ocfs2_read_extent_block(inode,
5053 ret = ocfs2_read_extent_block(et->et_ci,
5052 ocfs2_et_get_last_eb_blk(et),
5053 &last_eb_bh);
5054 if (ret) {
5055 mlog_exit(ret);
5056 goto out;
5057 }
5058
5059 eb = (struct ocfs2_extent_block *) last_eb_bh->b_data;

--- 138 unchanged lines hidden (view full) ---

5198 * Setup the record to split before we grow the tree.
5199 */
5200 el = path_leaf_el(path);
5201 rec = &el->l_recs[index];
5202 ocfs2_make_right_split_rec(inode->i_sb, &split_rec, new_range, rec);
5203
5204 depth = path->p_tree_depth;
5205 if (depth > 0) {
5054 ocfs2_et_get_last_eb_blk(et),
5055 &last_eb_bh);
5056 if (ret) {
5057 mlog_exit(ret);
5058 goto out;
5059 }
5060
5061 eb = (struct ocfs2_extent_block *) last_eb_bh->b_data;

--- 138 unchanged lines hidden (view full) ---

5200 * Setup the record to split before we grow the tree.
5201 */
5202 el = path_leaf_el(path);
5203 rec = &el->l_recs[index];
5204 ocfs2_make_right_split_rec(inode->i_sb, &split_rec, new_range, rec);
5205
5206 depth = path->p_tree_depth;
5207 if (depth > 0) {
5206 ret = ocfs2_read_extent_block(inode,
5208 ret = ocfs2_read_extent_block(et->et_ci,
5207 ocfs2_et_get_last_eb_blk(et),
5208 &last_eb_bh);
5209 if (ret < 0) {
5210 mlog_errno(ret);
5211 goto out;
5212 }
5213
5214 eb = (struct ocfs2_extent_block *) last_eb_bh->b_data;

--- 2227 unchanged lines hidden (view full) ---

7442 if (!(*tc)) {
7443 status = -ENOMEM;
7444 mlog_errno(status);
7445 goto bail;
7446 }
7447 ocfs2_init_dealloc_ctxt(&(*tc)->tc_dealloc);
7448
7449 if (fe->id2.i_list.l_tree_depth) {
5209 ocfs2_et_get_last_eb_blk(et),
5210 &last_eb_bh);
5211 if (ret < 0) {
5212 mlog_errno(ret);
5213 goto out;
5214 }
5215
5216 eb = (struct ocfs2_extent_block *) last_eb_bh->b_data;

--- 2227 unchanged lines hidden (view full) ---

7444 if (!(*tc)) {
7445 status = -ENOMEM;
7446 mlog_errno(status);
7447 goto bail;
7448 }
7449 ocfs2_init_dealloc_ctxt(&(*tc)->tc_dealloc);
7450
7451 if (fe->id2.i_list.l_tree_depth) {
7450 status = ocfs2_read_extent_block(inode,
7452 status = ocfs2_read_extent_block(INODE_CACHE(inode),
7451 le64_to_cpu(fe->i_last_eb_blk),
7452 &last_eb_bh);
7453 if (status < 0) {
7454 mlog_errno(status);
7455 goto bail;
7456 }
7457 eb = (struct ocfs2_extent_block *) last_eb_bh->b_data;
7458 }

--- 103 unchanged lines hidden ---
7453 le64_to_cpu(fe->i_last_eb_blk),
7454 &last_eb_bh);
7455 if (status < 0) {
7456 mlog_errno(status);
7457 goto bail;
7458 }
7459 eb = (struct ocfs2_extent_block *) last_eb_bh->b_data;
7460 }

--- 103 unchanged lines hidden ---