diff options
author | Dave Chinner <dchinner@redhat.com> | 2013-04-24 04:58:02 -0400 |
---|---|---|
committer | Ben Myers <bpm@sgi.com> | 2013-04-27 13:33:38 -0400 |
commit | f5ea110044fa858925a880b4fa9f551bfa2dfc38 (patch) | |
tree | eb0a3d50a8a1a475c13b99bbe88472e421866f47 | |
parent | 6b2647a12a00bdad431ac1e9049c5e8579aa7869 (diff) |
xfs: add CRCs to dir2/da node blocks
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Ben Myers <bpm@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
-rw-r--r-- | fs/xfs/xfs_attr.c | 31 | ||||
-rw-r--r-- | fs/xfs/xfs_attr_leaf.c | 29 | ||||
-rw-r--r-- | fs/xfs/xfs_bmap.c | 1 | ||||
-rw-r--r-- | fs/xfs/xfs_da_btree.c | 1396 | ||||
-rw-r--r-- | fs/xfs/xfs_da_btree.h | 106 | ||||
-rw-r--r-- | fs/xfs/xfs_dir2_node.c | 26 | ||||
-rw-r--r-- | fs/xfs/xfs_trace.c | 2 |
7 files changed, 972 insertions, 619 deletions
diff --git a/fs/xfs/xfs_attr.c b/fs/xfs/xfs_attr.c index 888683844d98..7afef2810e41 100644 --- a/fs/xfs/xfs_attr.c +++ b/fs/xfs/xfs_attr.c | |||
@@ -15,7 +15,6 @@ | |||
15 | * along with this program; if not, write the Free Software Foundation, | 15 | * along with this program; if not, write the Free Software Foundation, |
16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
17 | */ | 17 | */ |
18 | |||
19 | #include "xfs.h" | 18 | #include "xfs.h" |
20 | #include "xfs_fs.h" | 19 | #include "xfs_fs.h" |
21 | #include "xfs_types.h" | 20 | #include "xfs_types.h" |
@@ -1236,7 +1235,7 @@ restart: | |||
1236 | * Search to see if name already exists, and get back a pointer | 1235 | * Search to see if name already exists, and get back a pointer |
1237 | * to where it should go. | 1236 | * to where it should go. |
1238 | */ | 1237 | */ |
1239 | error = xfs_da_node_lookup_int(state, &retval); | 1238 | error = xfs_da3_node_lookup_int(state, &retval); |
1240 | if (error) | 1239 | if (error) |
1241 | goto out; | 1240 | goto out; |
1242 | blk = &state->path.blk[ state->path.active-1 ]; | 1241 | blk = &state->path.blk[ state->path.active-1 ]; |
@@ -1307,7 +1306,7 @@ restart: | |||
1307 | * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields. | 1306 | * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields. |
1308 | */ | 1307 | */ |
1309 | xfs_bmap_init(args->flist, args->firstblock); | 1308 | xfs_bmap_init(args->flist, args->firstblock); |
1310 | error = xfs_da_split(state); | 1309 | error = xfs_da3_split(state); |
1311 | if (!error) { | 1310 | if (!error) { |
1312 | error = xfs_bmap_finish(&args->trans, args->flist, | 1311 | error = xfs_bmap_finish(&args->trans, args->flist, |
1313 | &committed); | 1312 | &committed); |
@@ -1329,7 +1328,7 @@ restart: | |||
1329 | /* | 1328 | /* |
1330 | * Addition succeeded, update Btree hashvals. | 1329 | * Addition succeeded, update Btree hashvals. |
1331 | */ | 1330 | */ |
1332 | xfs_da_fixhashpath(state, &state->path); | 1331 | xfs_da3_fixhashpath(state, &state->path); |
1333 | } | 1332 | } |
1334 | 1333 | ||
1335 | /* | 1334 | /* |
@@ -1400,7 +1399,7 @@ restart: | |||
1400 | state->blocksize = state->mp->m_sb.sb_blocksize; | 1399 | state->blocksize = state->mp->m_sb.sb_blocksize; |
1401 | state->node_ents = state->mp->m_attr_node_ents; | 1400 | state->node_ents = state->mp->m_attr_node_ents; |
1402 | state->inleaf = 0; | 1401 | state->inleaf = 0; |
1403 | error = xfs_da_node_lookup_int(state, &retval); | 1402 | error = xfs_da3_node_lookup_int(state, &retval); |
1404 | if (error) | 1403 | if (error) |
1405 | goto out; | 1404 | goto out; |
1406 | 1405 | ||
@@ -1410,14 +1409,14 @@ restart: | |||
1410 | blk = &state->path.blk[ state->path.active-1 ]; | 1409 | blk = &state->path.blk[ state->path.active-1 ]; |
1411 | ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC); | 1410 | ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC); |
1412 | error = xfs_attr_leaf_remove(blk->bp, args); | 1411 | error = xfs_attr_leaf_remove(blk->bp, args); |
1413 | xfs_da_fixhashpath(state, &state->path); | 1412 | xfs_da3_fixhashpath(state, &state->path); |
1414 | 1413 | ||
1415 | /* | 1414 | /* |
1416 | * Check to see if the tree needs to be collapsed. | 1415 | * Check to see if the tree needs to be collapsed. |
1417 | */ | 1416 | */ |
1418 | if (retval && (state->path.active > 1)) { | 1417 | if (retval && (state->path.active > 1)) { |
1419 | xfs_bmap_init(args->flist, args->firstblock); | 1418 | xfs_bmap_init(args->flist, args->firstblock); |
1420 | error = xfs_da_join(state); | 1419 | error = xfs_da3_join(state); |
1421 | if (!error) { | 1420 | if (!error) { |
1422 | error = xfs_bmap_finish(&args->trans, | 1421 | error = xfs_bmap_finish(&args->trans, |
1423 | args->flist, | 1422 | args->flist, |
@@ -1495,7 +1494,7 @@ xfs_attr_node_removename(xfs_da_args_t *args) | |||
1495 | /* | 1494 | /* |
1496 | * Search to see if name exists, and get back a pointer to it. | 1495 | * Search to see if name exists, and get back a pointer to it. |
1497 | */ | 1496 | */ |
1498 | error = xfs_da_node_lookup_int(state, &retval); | 1497 | error = xfs_da3_node_lookup_int(state, &retval); |
1499 | if (error || (retval != EEXIST)) { | 1498 | if (error || (retval != EEXIST)) { |
1500 | if (error == 0) | 1499 | if (error == 0) |
1501 | error = retval; | 1500 | error = retval; |
@@ -1546,14 +1545,14 @@ xfs_attr_node_removename(xfs_da_args_t *args) | |||
1546 | blk = &state->path.blk[ state->path.active-1 ]; | 1545 | blk = &state->path.blk[ state->path.active-1 ]; |
1547 | ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC); | 1546 | ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC); |
1548 | retval = xfs_attr_leaf_remove(blk->bp, args); | 1547 | retval = xfs_attr_leaf_remove(blk->bp, args); |
1549 | xfs_da_fixhashpath(state, &state->path); | 1548 | xfs_da3_fixhashpath(state, &state->path); |
1550 | 1549 | ||
1551 | /* | 1550 | /* |
1552 | * Check to see if the tree needs to be collapsed. | 1551 | * Check to see if the tree needs to be collapsed. |
1553 | */ | 1552 | */ |
1554 | if (retval && (state->path.active > 1)) { | 1553 | if (retval && (state->path.active > 1)) { |
1555 | xfs_bmap_init(args->flist, args->firstblock); | 1554 | xfs_bmap_init(args->flist, args->firstblock); |
1556 | error = xfs_da_join(state); | 1555 | error = xfs_da3_join(state); |
1557 | if (!error) { | 1556 | if (!error) { |
1558 | error = xfs_bmap_finish(&args->trans, args->flist, | 1557 | error = xfs_bmap_finish(&args->trans, args->flist, |
1559 | &committed); | 1558 | &committed); |
@@ -1699,7 +1698,7 @@ xfs_attr_refillstate(xfs_da_state_t *state) | |||
1699 | ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH)); | 1698 | ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH)); |
1700 | for (blk = path->blk, level = 0; level < path->active; blk++, level++) { | 1699 | for (blk = path->blk, level = 0; level < path->active; blk++, level++) { |
1701 | if (blk->disk_blkno) { | 1700 | if (blk->disk_blkno) { |
1702 | error = xfs_da_node_read(state->args->trans, | 1701 | error = xfs_da3_node_read(state->args->trans, |
1703 | state->args->dp, | 1702 | state->args->dp, |
1704 | blk->blkno, blk->disk_blkno, | 1703 | blk->blkno, blk->disk_blkno, |
1705 | &blk->bp, XFS_ATTR_FORK); | 1704 | &blk->bp, XFS_ATTR_FORK); |
@@ -1718,7 +1717,7 @@ xfs_attr_refillstate(xfs_da_state_t *state) | |||
1718 | ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH)); | 1717 | ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH)); |
1719 | for (blk = path->blk, level = 0; level < path->active; blk++, level++) { | 1718 | for (blk = path->blk, level = 0; level < path->active; blk++, level++) { |
1720 | if (blk->disk_blkno) { | 1719 | if (blk->disk_blkno) { |
1721 | error = xfs_da_node_read(state->args->trans, | 1720 | error = xfs_da3_node_read(state->args->trans, |
1722 | state->args->dp, | 1721 | state->args->dp, |
1723 | blk->blkno, blk->disk_blkno, | 1722 | blk->blkno, blk->disk_blkno, |
1724 | &blk->bp, XFS_ATTR_FORK); | 1723 | &blk->bp, XFS_ATTR_FORK); |
@@ -1758,7 +1757,7 @@ xfs_attr_node_get(xfs_da_args_t *args) | |||
1758 | /* | 1757 | /* |
1759 | * Search to see if name exists, and get back a pointer to it. | 1758 | * Search to see if name exists, and get back a pointer to it. |
1760 | */ | 1759 | */ |
1761 | error = xfs_da_node_lookup_int(state, &retval); | 1760 | error = xfs_da3_node_lookup_int(state, &retval); |
1762 | if (error) { | 1761 | if (error) { |
1763 | retval = error; | 1762 | retval = error; |
1764 | } else if (retval == EEXIST) { | 1763 | } else if (retval == EEXIST) { |
@@ -1810,7 +1809,7 @@ xfs_attr_node_list(xfs_attr_list_context_t *context) | |||
1810 | */ | 1809 | */ |
1811 | bp = NULL; | 1810 | bp = NULL; |
1812 | if (cursor->blkno > 0) { | 1811 | if (cursor->blkno > 0) { |
1813 | error = xfs_da_node_read(NULL, context->dp, cursor->blkno, -1, | 1812 | error = xfs_da3_node_read(NULL, context->dp, cursor->blkno, -1, |
1814 | &bp, XFS_ATTR_FORK); | 1813 | &bp, XFS_ATTR_FORK); |
1815 | if ((error != 0) && (error != EFSCORRUPTED)) | 1814 | if ((error != 0) && (error != EFSCORRUPTED)) |
1816 | return(error); | 1815 | return(error); |
@@ -1852,7 +1851,7 @@ xfs_attr_node_list(xfs_attr_list_context_t *context) | |||
1852 | if (bp == NULL) { | 1851 | if (bp == NULL) { |
1853 | cursor->blkno = 0; | 1852 | cursor->blkno = 0; |
1854 | for (;;) { | 1853 | for (;;) { |
1855 | error = xfs_da_node_read(NULL, context->dp, | 1854 | error = xfs_da3_node_read(NULL, context->dp, |
1856 | cursor->blkno, -1, &bp, | 1855 | cursor->blkno, -1, &bp, |
1857 | XFS_ATTR_FORK); | 1856 | XFS_ATTR_FORK); |
1858 | if (error) | 1857 | if (error) |
@@ -1870,7 +1869,7 @@ xfs_attr_node_list(xfs_attr_list_context_t *context) | |||
1870 | xfs_trans_brelse(NULL, bp); | 1869 | xfs_trans_brelse(NULL, bp); |
1871 | return(XFS_ERROR(EFSCORRUPTED)); | 1870 | return(XFS_ERROR(EFSCORRUPTED)); |
1872 | } | 1871 | } |
1873 | btree = node->btree; | 1872 | btree = xfs_da3_node_tree_p(node); |
1874 | for (i = 0; i < be16_to_cpu(node->hdr.count); | 1873 | for (i = 0; i < be16_to_cpu(node->hdr.count); |
1875 | btree++, i++) { | 1874 | btree++, i++) { |
1876 | if (cursor->hashval | 1875 | if (cursor->hashval |
diff --git a/fs/xfs/xfs_attr_leaf.c b/fs/xfs/xfs_attr_leaf.c index aa4765f15cbe..54b0dc8cc82c 100644 --- a/fs/xfs/xfs_attr_leaf.c +++ b/fs/xfs/xfs_attr_leaf.c | |||
@@ -910,6 +910,7 @@ xfs_attr_leaf_to_node(xfs_da_args_t *args) | |||
910 | struct xfs_buf *bp1, *bp2; | 910 | struct xfs_buf *bp1, *bp2; |
911 | xfs_dablk_t blkno; | 911 | xfs_dablk_t blkno; |
912 | int error; | 912 | int error; |
913 | struct xfs_da_node_entry *btree; | ||
913 | 914 | ||
914 | trace_xfs_attr_leaf_to_node(args); | 915 | trace_xfs_attr_leaf_to_node(args); |
915 | 916 | ||
@@ -935,16 +936,16 @@ xfs_attr_leaf_to_node(xfs_da_args_t *args) | |||
935 | /* | 936 | /* |
936 | * Set up the new root node. | 937 | * Set up the new root node. |
937 | */ | 938 | */ |
938 | error = xfs_da_node_create(args, 0, 1, &bp1, XFS_ATTR_FORK); | 939 | error = xfs_da3_node_create(args, 0, 1, &bp1, XFS_ATTR_FORK); |
939 | if (error) | 940 | if (error) |
940 | goto out; | 941 | goto out; |
941 | node = bp1->b_addr; | 942 | node = bp1->b_addr; |
942 | leaf = bp2->b_addr; | 943 | leaf = bp2->b_addr; |
943 | ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); | 944 | ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); |
944 | /* both on-disk, don't endian-flip twice */ | 945 | /* both on-disk, don't endian-flip twice */ |
945 | node->btree[0].hashval = | 946 | btree = xfs_da3_node_tree_p(node); |
946 | leaf->entries[be16_to_cpu(leaf->hdr.count)-1 ].hashval; | 947 | btree[0].hashval = leaf->entries[be16_to_cpu(leaf->hdr.count)-1 ].hashval; |
947 | node->btree[0].before = cpu_to_be32(blkno); | 948 | btree[0].before = cpu_to_be32(blkno); |
948 | node->hdr.count = cpu_to_be16(1); | 949 | node->hdr.count = cpu_to_be16(1); |
949 | xfs_trans_log_buf(args->trans, bp1, 0, XFS_LBSIZE(dp->i_mount) - 1); | 950 | xfs_trans_log_buf(args->trans, bp1, 0, XFS_LBSIZE(dp->i_mount) - 1); |
950 | error = 0; | 951 | error = 0; |
@@ -1032,7 +1033,7 @@ xfs_attr_leaf_split(xfs_da_state_t *state, xfs_da_state_blk_t *oldblk, | |||
1032 | * NOTE: rebalance() currently depends on the 2nd block being empty. | 1033 | * NOTE: rebalance() currently depends on the 2nd block being empty. |
1033 | */ | 1034 | */ |
1034 | xfs_attr_leaf_rebalance(state, oldblk, newblk); | 1035 | xfs_attr_leaf_rebalance(state, oldblk, newblk); |
1035 | error = xfs_da_blk_link(state, oldblk, newblk); | 1036 | error = xfs_da3_blk_link(state, oldblk, newblk); |
1036 | if (error) | 1037 | if (error) |
1037 | return(error); | 1038 | return(error); |
1038 | 1039 | ||
@@ -1660,7 +1661,7 @@ xfs_attr_leaf_toosmall(xfs_da_state_t *state, int *action) | |||
1660 | */ | 1661 | */ |
1661 | forward = (info->forw != 0); | 1662 | forward = (info->forw != 0); |
1662 | memcpy(&state->altpath, &state->path, sizeof(state->path)); | 1663 | memcpy(&state->altpath, &state->path, sizeof(state->path)); |
1663 | error = xfs_da_path_shift(state, &state->altpath, forward, | 1664 | error = xfs_da3_path_shift(state, &state->altpath, forward, |
1664 | 0, &retval); | 1665 | 0, &retval); |
1665 | if (error) | 1666 | if (error) |
1666 | return(error); | 1667 | return(error); |
@@ -1717,10 +1718,10 @@ xfs_attr_leaf_toosmall(xfs_da_state_t *state, int *action) | |||
1717 | */ | 1718 | */ |
1718 | memcpy(&state->altpath, &state->path, sizeof(state->path)); | 1719 | memcpy(&state->altpath, &state->path, sizeof(state->path)); |
1719 | if (blkno < blk->blkno) { | 1720 | if (blkno < blk->blkno) { |
1720 | error = xfs_da_path_shift(state, &state->altpath, forward, | 1721 | error = xfs_da3_path_shift(state, &state->altpath, forward, |
1721 | 0, &retval); | 1722 | 0, &retval); |
1722 | } else { | 1723 | } else { |
1723 | error = xfs_da_path_shift(state, &state->path, forward, | 1724 | error = xfs_da3_path_shift(state, &state->path, forward, |
1724 | 0, &retval); | 1725 | 0, &retval); |
1725 | } | 1726 | } |
1726 | if (error) | 1727 | if (error) |
@@ -2783,7 +2784,7 @@ xfs_attr_root_inactive(xfs_trans_t **trans, xfs_inode_t *dp) | |||
2783 | * the extents in reverse order the extent containing | 2784 | * the extents in reverse order the extent containing |
2784 | * block 0 must still be there. | 2785 | * block 0 must still be there. |
2785 | */ | 2786 | */ |
2786 | error = xfs_da_node_read(*trans, dp, 0, -1, &bp, XFS_ATTR_FORK); | 2787 | error = xfs_da3_node_read(*trans, dp, 0, -1, &bp, XFS_ATTR_FORK); |
2787 | if (error) | 2788 | if (error) |
2788 | return(error); | 2789 | return(error); |
2789 | blkno = XFS_BUF_ADDR(bp); | 2790 | blkno = XFS_BUF_ADDR(bp); |
@@ -2836,6 +2837,7 @@ xfs_attr_node_inactive( | |||
2836 | xfs_daddr_t parent_blkno, child_blkno; | 2837 | xfs_daddr_t parent_blkno, child_blkno; |
2837 | int error, count, i; | 2838 | int error, count, i; |
2838 | struct xfs_buf *child_bp; | 2839 | struct xfs_buf *child_bp; |
2840 | struct xfs_da_node_entry *btree; | ||
2839 | 2841 | ||
2840 | /* | 2842 | /* |
2841 | * Since this code is recursive (gasp!) we must protect ourselves. | 2843 | * Since this code is recursive (gasp!) we must protect ourselves. |
@@ -2853,7 +2855,8 @@ xfs_attr_node_inactive( | |||
2853 | xfs_trans_brelse(*trans, bp); | 2855 | xfs_trans_brelse(*trans, bp); |
2854 | return(0); | 2856 | return(0); |
2855 | } | 2857 | } |
2856 | child_fsb = be32_to_cpu(node->btree[0].before); | 2858 | btree = xfs_da3_node_tree_p(node); |
2859 | child_fsb = be32_to_cpu(btree[0].before); | ||
2857 | xfs_trans_brelse(*trans, bp); /* no locks for later trans */ | 2860 | xfs_trans_brelse(*trans, bp); /* no locks for later trans */ |
2858 | 2861 | ||
2859 | /* | 2862 | /* |
@@ -2868,7 +2871,7 @@ xfs_attr_node_inactive( | |||
2868 | * traversal of the tree so we may deal with many blocks | 2871 | * traversal of the tree so we may deal with many blocks |
2869 | * before we come back to this one. | 2872 | * before we come back to this one. |
2870 | */ | 2873 | */ |
2871 | error = xfs_da_node_read(*trans, dp, child_fsb, -2, &child_bp, | 2874 | error = xfs_da3_node_read(*trans, dp, child_fsb, -2, &child_bp, |
2872 | XFS_ATTR_FORK); | 2875 | XFS_ATTR_FORK); |
2873 | if (error) | 2876 | if (error) |
2874 | return(error); | 2877 | return(error); |
@@ -2909,11 +2912,11 @@ xfs_attr_node_inactive( | |||
2909 | * child block number. | 2912 | * child block number. |
2910 | */ | 2913 | */ |
2911 | if ((i+1) < count) { | 2914 | if ((i+1) < count) { |
2912 | error = xfs_da_node_read(*trans, dp, 0, parent_blkno, | 2915 | error = xfs_da3_node_read(*trans, dp, 0, parent_blkno, |
2913 | &bp, XFS_ATTR_FORK); | 2916 | &bp, XFS_ATTR_FORK); |
2914 | if (error) | 2917 | if (error) |
2915 | return(error); | 2918 | return(error); |
2916 | child_fsb = be32_to_cpu(node->btree[i+1].before); | 2919 | child_fsb = be32_to_cpu(btree[i+1].before); |
2917 | xfs_trans_brelse(*trans, bp); | 2920 | xfs_trans_brelse(*trans, bp); |
2918 | } | 2921 | } |
2919 | /* | 2922 | /* |
diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c index 0fcb7f48e91f..2844724f507e 100644 --- a/fs/xfs/xfs_bmap.c +++ b/fs/xfs/xfs_bmap.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include "xfs_sb.h" | 25 | #include "xfs_sb.h" |
26 | #include "xfs_ag.h" | 26 | #include "xfs_ag.h" |
27 | #include "xfs_dir2.h" | 27 | #include "xfs_dir2.h" |
28 | #include "xfs_mount.h" | ||
28 | #include "xfs_da_btree.h" | 29 | #include "xfs_da_btree.h" |
29 | #include "xfs_bmap_btree.h" | 30 | #include "xfs_bmap_btree.h" |
30 | #include "xfs_alloc_btree.h" | 31 | #include "xfs_alloc_btree.h" |
diff --git a/fs/xfs/xfs_da_btree.c b/fs/xfs/xfs_da_btree.c index 2f23b14e3adf..6a1eb752af03 100644 --- a/fs/xfs/xfs_da_btree.c +++ b/fs/xfs/xfs_da_btree.c | |||
@@ -1,5 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2000-2005 Silicon Graphics, Inc. | 2 | * Copyright (c) 2000-2005 Silicon Graphics, Inc. |
3 | * Copyright (c) 2013 Red Hat, Inc. | ||
3 | * All Rights Reserved. | 4 | * All Rights Reserved. |
4 | * | 5 | * |
5 | * This program is free software; you can redistribute it and/or | 6 | * This program is free software; you can redistribute it and/or |
@@ -38,6 +39,8 @@ | |||
38 | #include "xfs_attr_leaf.h" | 39 | #include "xfs_attr_leaf.h" |
39 | #include "xfs_error.h" | 40 | #include "xfs_error.h" |
40 | #include "xfs_trace.h" | 41 | #include "xfs_trace.h" |
42 | #include "xfs_cksum.h" | ||
43 | #include "xfs_buf_item.h" | ||
41 | 44 | ||
42 | /* | 45 | /* |
43 | * xfs_da_btree.c | 46 | * xfs_da_btree.c |
@@ -52,69 +55,195 @@ | |||
52 | /* | 55 | /* |
53 | * Routines used for growing the Btree. | 56 | * Routines used for growing the Btree. |
54 | */ | 57 | */ |
55 | STATIC int xfs_da_root_split(xfs_da_state_t *state, | 58 | STATIC int xfs_da3_root_split(xfs_da_state_t *state, |
56 | xfs_da_state_blk_t *existing_root, | 59 | xfs_da_state_blk_t *existing_root, |
57 | xfs_da_state_blk_t *new_child); | 60 | xfs_da_state_blk_t *new_child); |
58 | STATIC int xfs_da_node_split(xfs_da_state_t *state, | 61 | STATIC int xfs_da3_node_split(xfs_da_state_t *state, |
59 | xfs_da_state_blk_t *existing_blk, | 62 | xfs_da_state_blk_t *existing_blk, |
60 | xfs_da_state_blk_t *split_blk, | 63 | xfs_da_state_blk_t *split_blk, |
61 | xfs_da_state_blk_t *blk_to_add, | 64 | xfs_da_state_blk_t *blk_to_add, |
62 | int treelevel, | 65 | int treelevel, |
63 | int *result); | 66 | int *result); |
64 | STATIC void xfs_da_node_rebalance(xfs_da_state_t *state, | 67 | STATIC void xfs_da3_node_rebalance(xfs_da_state_t *state, |
65 | xfs_da_state_blk_t *node_blk_1, | 68 | xfs_da_state_blk_t *node_blk_1, |
66 | xfs_da_state_blk_t *node_blk_2); | 69 | xfs_da_state_blk_t *node_blk_2); |
67 | STATIC void xfs_da_node_add(xfs_da_state_t *state, | 70 | STATIC void xfs_da3_node_add(xfs_da_state_t *state, |
68 | xfs_da_state_blk_t *old_node_blk, | 71 | xfs_da_state_blk_t *old_node_blk, |
69 | xfs_da_state_blk_t *new_node_blk); | 72 | xfs_da_state_blk_t *new_node_blk); |
70 | 73 | ||
71 | /* | 74 | /* |
72 | * Routines used for shrinking the Btree. | 75 | * Routines used for shrinking the Btree. |
73 | */ | 76 | */ |
74 | STATIC int xfs_da_root_join(xfs_da_state_t *state, | 77 | STATIC int xfs_da3_root_join(xfs_da_state_t *state, |
75 | xfs_da_state_blk_t *root_blk); | 78 | xfs_da_state_blk_t *root_blk); |
76 | STATIC int xfs_da_node_toosmall(xfs_da_state_t *state, int *retval); | 79 | STATIC int xfs_da3_node_toosmall(xfs_da_state_t *state, int *retval); |
77 | STATIC void xfs_da_node_remove(xfs_da_state_t *state, | 80 | STATIC void xfs_da3_node_remove(xfs_da_state_t *state, |
78 | xfs_da_state_blk_t *drop_blk); | 81 | xfs_da_state_blk_t *drop_blk); |
79 | STATIC void xfs_da_node_unbalance(xfs_da_state_t *state, | 82 | STATIC void xfs_da3_node_unbalance(xfs_da_state_t *state, |
80 | xfs_da_state_blk_t *src_node_blk, | 83 | xfs_da_state_blk_t *src_node_blk, |
81 | xfs_da_state_blk_t *dst_node_blk); | 84 | xfs_da_state_blk_t *dst_node_blk); |
82 | 85 | ||
83 | /* | 86 | /* |
84 | * Utility routines. | 87 | * Utility routines. |
85 | */ | 88 | */ |
86 | STATIC uint xfs_da_node_lasthash(struct xfs_buf *bp, int *count); | 89 | STATIC int xfs_da3_blk_unlink(xfs_da_state_t *state, |
87 | STATIC int xfs_da_node_order(struct xfs_buf *node1_bp, | ||
88 | struct xfs_buf *node2_bp); | ||
89 | STATIC int xfs_da_blk_unlink(xfs_da_state_t *state, | ||
90 | xfs_da_state_blk_t *drop_blk, | 90 | xfs_da_state_blk_t *drop_blk, |
91 | xfs_da_state_blk_t *save_blk); | 91 | xfs_da_state_blk_t *save_blk); |
92 | STATIC void xfs_da_state_kill_altpath(xfs_da_state_t *state); | ||
93 | 92 | ||
94 | static void | 93 | |
95 | xfs_da_node_verify( | 94 | kmem_zone_t *xfs_da_state_zone; /* anchor for state struct zone */ |
95 | |||
96 | /* | ||
97 | * Allocate a dir-state structure. | ||
98 | * We don't put them on the stack since they're large. | ||
99 | */ | ||
100 | xfs_da_state_t * | ||
101 | xfs_da_state_alloc(void) | ||
102 | { | ||
103 | return kmem_zone_zalloc(xfs_da_state_zone, KM_NOFS); | ||
104 | } | ||
105 | |||
106 | /* | ||
107 | * Kill the altpath contents of a da-state structure. | ||
108 | */ | ||
109 | STATIC void | ||
110 | xfs_da_state_kill_altpath(xfs_da_state_t *state) | ||
111 | { | ||
112 | int i; | ||
113 | |||
114 | for (i = 0; i < state->altpath.active; i++) | ||
115 | state->altpath.blk[i].bp = NULL; | ||
116 | state->altpath.active = 0; | ||
117 | } | ||
118 | |||
119 | /* | ||
120 | * Free a da-state structure. | ||
121 | */ | ||
122 | void | ||
123 | xfs_da_state_free(xfs_da_state_t *state) | ||
124 | { | ||
125 | xfs_da_state_kill_altpath(state); | ||
126 | #ifdef DEBUG | ||
127 | memset((char *)state, 0, sizeof(*state)); | ||
128 | #endif /* DEBUG */ | ||
129 | kmem_zone_free(xfs_da_state_zone, state); | ||
130 | } | ||
131 | |||
132 | void | ||
133 | xfs_da3_node_hdr_from_disk( | ||
134 | struct xfs_da3_icnode_hdr *to, | ||
135 | struct xfs_da_intnode *from) | ||
136 | { | ||
137 | ASSERT(from->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC) || | ||
138 | from->hdr.info.magic == cpu_to_be16(XFS_DA3_NODE_MAGIC)); | ||
139 | |||
140 | if (from->hdr.info.magic == cpu_to_be16(XFS_DA3_NODE_MAGIC)) { | ||
141 | struct xfs_da3_node_hdr *hdr3 = (struct xfs_da3_node_hdr *)from; | ||
142 | |||
143 | to->forw = be32_to_cpu(hdr3->info.hdr.forw); | ||
144 | to->back = be32_to_cpu(hdr3->info.hdr.back); | ||
145 | to->magic = be16_to_cpu(hdr3->info.hdr.magic); | ||
146 | to->count = be16_to_cpu(hdr3->count); | ||
147 | to->level = be16_to_cpu(hdr3->__level); | ||
148 | return; | ||
149 | } | ||
150 | to->forw = be32_to_cpu(from->hdr.info.forw); | ||
151 | to->back = be32_to_cpu(from->hdr.info.back); | ||
152 | to->magic = be16_to_cpu(from->hdr.info.magic); | ||
153 | to->count = be16_to_cpu(from->hdr.count); | ||
154 | to->level = be16_to_cpu(from->hdr.__level); | ||
155 | } | ||
156 | |||
157 | void | ||
158 | xfs_da3_node_hdr_to_disk( | ||
159 | struct xfs_da_intnode *to, | ||
160 | struct xfs_da3_icnode_hdr *from) | ||
161 | { | ||
162 | ASSERT(from->magic == XFS_DA_NODE_MAGIC || | ||
163 | from->magic == XFS_DA3_NODE_MAGIC); | ||
164 | |||
165 | if (from->magic == XFS_DA3_NODE_MAGIC) { | ||
166 | struct xfs_da3_node_hdr *hdr3 = (struct xfs_da3_node_hdr *)to; | ||
167 | |||
168 | hdr3->info.hdr.forw = cpu_to_be32(from->forw); | ||
169 | hdr3->info.hdr.back = cpu_to_be32(from->back); | ||
170 | hdr3->info.hdr.magic = cpu_to_be16(from->magic); | ||
171 | hdr3->count = cpu_to_be16(from->count); | ||
172 | hdr3->__level = cpu_to_be16(from->level); | ||
173 | return; | ||
174 | } | ||
175 | to->hdr.info.forw = cpu_to_be32(from->forw); | ||
176 | to->hdr.info.back = cpu_to_be32(from->back); | ||
177 | to->hdr.info.magic = cpu_to_be16(from->magic); | ||
178 | to->hdr.count = cpu_to_be16(from->count); | ||
179 | to->hdr.__level = cpu_to_be16(from->level); | ||
180 | } | ||
181 | |||
182 | static bool | ||
183 | xfs_da3_node_verify( | ||
96 | struct xfs_buf *bp) | 184 | struct xfs_buf *bp) |
97 | { | 185 | { |
98 | struct xfs_mount *mp = bp->b_target->bt_mount; | 186 | struct xfs_mount *mp = bp->b_target->bt_mount; |
99 | struct xfs_da_node_hdr *hdr = bp->b_addr; | 187 | struct xfs_da_intnode *hdr = bp->b_addr; |
100 | int block_ok = 0; | 188 | struct xfs_da3_icnode_hdr ichdr; |
101 | 189 | ||
102 | block_ok = hdr->info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC); | 190 | xfs_da3_node_hdr_from_disk(&ichdr, hdr); |
103 | block_ok = block_ok && | 191 | |
104 | be16_to_cpu(hdr->level) > 0 && | 192 | if (xfs_sb_version_hascrc(&mp->m_sb)) { |
105 | be16_to_cpu(hdr->count) > 0 ; | 193 | struct xfs_da3_node_hdr *hdr3 = bp->b_addr; |
106 | if (!block_ok) { | 194 | |
107 | XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, hdr); | 195 | if (ichdr.magic != XFS_DA3_NODE_MAGIC) |
108 | xfs_buf_ioerror(bp, EFSCORRUPTED); | 196 | return false; |
197 | |||
198 | if (!uuid_equal(&hdr3->info.uuid, &mp->m_sb.sb_uuid)) | ||
199 | return false; | ||
200 | if (be64_to_cpu(hdr3->info.blkno) != bp->b_bn) | ||
201 | return false; | ||
202 | } else { | ||
203 | if (ichdr.magic != XFS_DA_NODE_MAGIC) | ||
204 | return false; | ||
109 | } | 205 | } |
206 | if (ichdr.level == 0) | ||
207 | return false; | ||
208 | if (ichdr.level > XFS_DA_NODE_MAXDEPTH) | ||
209 | return false; | ||
210 | if (ichdr.count == 0) | ||
211 | return false; | ||
212 | |||
213 | /* | ||
214 | * we don't know if the node is for and attribute or directory tree, | ||
215 | * so only fail if the count is outside both bounds | ||
216 | */ | ||
217 | if (ichdr.count > mp->m_dir_node_ents && | ||
218 | ichdr.count > mp->m_attr_node_ents) | ||
219 | return false; | ||
220 | |||
221 | /* XXX: hash order check? */ | ||
110 | 222 | ||
223 | return true; | ||
111 | } | 224 | } |
112 | 225 | ||
113 | static void | 226 | static void |
114 | xfs_da_node_write_verify( | 227 | xfs_da3_node_write_verify( |
115 | struct xfs_buf *bp) | 228 | struct xfs_buf *bp) |
116 | { | 229 | { |
117 | xfs_da_node_verify(bp); | 230 | struct xfs_mount *mp = bp->b_target->bt_mount; |
231 | struct xfs_buf_log_item *bip = bp->b_fspriv; | ||
232 | struct xfs_da3_node_hdr *hdr3 = bp->b_addr; | ||
233 | |||
234 | if (!xfs_da3_node_verify(bp)) { | ||
235 | XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, bp->b_addr); | ||
236 | xfs_buf_ioerror(bp, EFSCORRUPTED); | ||
237 | return; | ||
238 | } | ||
239 | |||
240 | if (!xfs_sb_version_hascrc(&mp->m_sb)) | ||
241 | return; | ||
242 | |||
243 | if (bip) | ||
244 | hdr3->info.lsn = cpu_to_be64(bip->bli_item.li_lsn); | ||
245 | |||
246 | xfs_update_cksum(bp->b_addr, BBTOB(bp->b_length), XFS_DA3_NODE_CRC_OFF); | ||
118 | } | 247 | } |
119 | 248 | ||
120 | /* | 249 | /* |
@@ -124,16 +253,22 @@ xfs_da_node_write_verify( | |||
124 | * format of the block being read. | 253 | * format of the block being read. |
125 | */ | 254 | */ |
126 | static void | 255 | static void |
127 | xfs_da_node_read_verify( | 256 | xfs_da3_node_read_verify( |
128 | struct xfs_buf *bp) | 257 | struct xfs_buf *bp) |
129 | { | 258 | { |
130 | struct xfs_mount *mp = bp->b_target->bt_mount; | 259 | struct xfs_mount *mp = bp->b_target->bt_mount; |
131 | struct xfs_da_blkinfo *info = bp->b_addr; | 260 | struct xfs_da_blkinfo *info = bp->b_addr; |
132 | 261 | ||
133 | switch (be16_to_cpu(info->magic)) { | 262 | switch (be16_to_cpu(info->magic)) { |
263 | case XFS_DA3_NODE_MAGIC: | ||
264 | if (!xfs_verify_cksum(bp->b_addr, BBTOB(bp->b_length), | ||
265 | XFS_DA3_NODE_CRC_OFF)) | ||
266 | break; | ||
267 | /* fall through */ | ||
134 | case XFS_DA_NODE_MAGIC: | 268 | case XFS_DA_NODE_MAGIC: |
135 | xfs_da_node_verify(bp); | 269 | if (!xfs_da3_node_verify(bp)) |
136 | break; | 270 | break; |
271 | return; | ||
137 | case XFS_ATTR_LEAF_MAGIC: | 272 | case XFS_ATTR_LEAF_MAGIC: |
138 | bp->b_ops = &xfs_attr_leaf_buf_ops; | 273 | bp->b_ops = &xfs_attr_leaf_buf_ops; |
139 | bp->b_ops->verify_read(bp); | 274 | bp->b_ops->verify_read(bp); |
@@ -144,21 +279,22 @@ xfs_da_node_read_verify( | |||
144 | bp->b_ops->verify_read(bp); | 279 | bp->b_ops->verify_read(bp); |
145 | return; | 280 | return; |
146 | default: | 281 | default: |
147 | XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, | ||
148 | mp, info); | ||
149 | xfs_buf_ioerror(bp, EFSCORRUPTED); | ||
150 | break; | 282 | break; |
151 | } | 283 | } |
284 | |||
285 | /* corrupt block */ | ||
286 | XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, bp->b_addr); | ||
287 | xfs_buf_ioerror(bp, EFSCORRUPTED); | ||
152 | } | 288 | } |
153 | 289 | ||
154 | const struct xfs_buf_ops xfs_da_node_buf_ops = { | 290 | const struct xfs_buf_ops xfs_da3_node_buf_ops = { |
155 | .verify_read = xfs_da_node_read_verify, | 291 | .verify_read = xfs_da3_node_read_verify, |
156 | .verify_write = xfs_da_node_write_verify, | 292 | .verify_write = xfs_da3_node_write_verify, |
157 | }; | 293 | }; |
158 | 294 | ||
159 | 295 | ||
160 | int | 296 | int |
161 | xfs_da_node_read( | 297 | xfs_da3_node_read( |
162 | struct xfs_trans *tp, | 298 | struct xfs_trans *tp, |
163 | struct xfs_inode *dp, | 299 | struct xfs_inode *dp, |
164 | xfs_dablk_t bno, | 300 | xfs_dablk_t bno, |
@@ -167,7 +303,7 @@ xfs_da_node_read( | |||
167 | int which_fork) | 303 | int which_fork) |
168 | { | 304 | { |
169 | return xfs_da_read_buf(tp, dp, bno, mappedbno, bpp, | 305 | return xfs_da_read_buf(tp, dp, bno, mappedbno, bpp, |
170 | which_fork, &xfs_da_node_buf_ops); | 306 | which_fork, &xfs_da3_node_buf_ops); |
171 | } | 307 | } |
172 | 308 | ||
173 | /*======================================================================== | 309 | /*======================================================================== |
@@ -178,33 +314,45 @@ xfs_da_node_read( | |||
178 | * Create the initial contents of an intermediate node. | 314 | * Create the initial contents of an intermediate node. |
179 | */ | 315 | */ |
180 | int | 316 | int |
181 | xfs_da_node_create(xfs_da_args_t *args, xfs_dablk_t blkno, int level, | 317 | xfs_da3_node_create( |
182 | struct xfs_buf **bpp, int whichfork) | 318 | struct xfs_da_args *args, |
319 | xfs_dablk_t blkno, | ||
320 | int level, | ||
321 | struct xfs_buf **bpp, | ||
322 | int whichfork) | ||
183 | { | 323 | { |
184 | xfs_da_intnode_t *node; | 324 | struct xfs_da_intnode *node; |
185 | struct xfs_buf *bp; | 325 | struct xfs_trans *tp = args->trans; |
186 | int error; | 326 | struct xfs_mount *mp = tp->t_mountp; |
187 | xfs_trans_t *tp; | 327 | struct xfs_da3_icnode_hdr ichdr = {0}; |
328 | struct xfs_buf *bp; | ||
329 | int error; | ||
188 | 330 | ||
189 | trace_xfs_da_node_create(args); | 331 | trace_xfs_da_node_create(args); |
332 | ASSERT(level <= XFS_DA_NODE_MAXDEPTH); | ||
190 | 333 | ||
191 | tp = args->trans; | ||
192 | error = xfs_da_get_buf(tp, args->dp, blkno, -1, &bp, whichfork); | 334 | error = xfs_da_get_buf(tp, args->dp, blkno, -1, &bp, whichfork); |
193 | if (error) | 335 | if (error) |
194 | return(error); | 336 | return(error); |
195 | ASSERT(bp != NULL); | ||
196 | node = bp->b_addr; | 337 | node = bp->b_addr; |
197 | node->hdr.info.forw = 0; | ||
198 | node->hdr.info.back = 0; | ||
199 | node->hdr.info.magic = cpu_to_be16(XFS_DA_NODE_MAGIC); | ||
200 | node->hdr.info.pad = 0; | ||
201 | node->hdr.count = 0; | ||
202 | node->hdr.level = cpu_to_be16(level); | ||
203 | 338 | ||
339 | if (xfs_sb_version_hascrc(&mp->m_sb)) { | ||
340 | struct xfs_da3_node_hdr *hdr3 = bp->b_addr; | ||
341 | |||
342 | ichdr.magic = XFS_DA3_NODE_MAGIC; | ||
343 | hdr3->info.blkno = cpu_to_be64(bp->b_bn); | ||
344 | hdr3->info.owner = cpu_to_be64(args->dp->i_ino); | ||
345 | uuid_copy(&hdr3->info.uuid, &mp->m_sb.sb_uuid); | ||
346 | } else { | ||
347 | ichdr.magic = XFS_DA_NODE_MAGIC; | ||
348 | } | ||
349 | ichdr.level = level; | ||
350 | |||
351 | xfs_da3_node_hdr_to_disk(node, &ichdr); | ||
204 | xfs_trans_log_buf(tp, bp, | 352 | xfs_trans_log_buf(tp, bp, |
205 | XFS_DA_LOGRANGE(node, &node->hdr, sizeof(node->hdr))); | 353 | XFS_DA_LOGRANGE(node, &node->hdr, xfs_da3_node_hdr_size(node))); |
206 | 354 | ||
207 | bp->b_ops = &xfs_da_node_buf_ops; | 355 | bp->b_ops = &xfs_da3_node_buf_ops; |
208 | *bpp = bp; | 356 | *bpp = bp; |
209 | return(0); | 357 | return(0); |
210 | } | 358 | } |
@@ -214,12 +362,18 @@ xfs_da_node_create(xfs_da_args_t *args, xfs_dablk_t blkno, int level, | |||
214 | * intermediate nodes, rebalance, etc. | 362 | * intermediate nodes, rebalance, etc. |
215 | */ | 363 | */ |
216 | int /* error */ | 364 | int /* error */ |
217 | xfs_da_split(xfs_da_state_t *state) | 365 | xfs_da3_split( |
366 | struct xfs_da_state *state) | ||
218 | { | 367 | { |
219 | xfs_da_state_blk_t *oldblk, *newblk, *addblk; | 368 | struct xfs_da_state_blk *oldblk; |
220 | xfs_da_intnode_t *node; | 369 | struct xfs_da_state_blk *newblk; |
221 | struct xfs_buf *bp; | 370 | struct xfs_da_state_blk *addblk; |
222 | int max, action, error, i; | 371 | struct xfs_da_intnode *node; |
372 | struct xfs_buf *bp; | ||
373 | int max; | ||
374 | int action; | ||
375 | int error; | ||
376 | int i; | ||
223 | 377 | ||
224 | trace_xfs_da_split(state->args); | 378 | trace_xfs_da_split(state->args); |
225 | 379 | ||
@@ -281,7 +435,7 @@ xfs_da_split(xfs_da_state_t *state) | |||
281 | addblk = newblk; | 435 | addblk = newblk; |
282 | break; | 436 | break; |
283 | case XFS_DA_NODE_MAGIC: | 437 | case XFS_DA_NODE_MAGIC: |
284 | error = xfs_da_node_split(state, oldblk, newblk, addblk, | 438 | error = xfs_da3_node_split(state, oldblk, newblk, addblk, |
285 | max - i, &action); | 439 | max - i, &action); |
286 | addblk->bp = NULL; | 440 | addblk->bp = NULL; |
287 | if (error) | 441 | if (error) |
@@ -299,7 +453,7 @@ xfs_da_split(xfs_da_state_t *state) | |||
299 | /* | 453 | /* |
300 | * Update the btree to show the new hashval for this child. | 454 | * Update the btree to show the new hashval for this child. |
301 | */ | 455 | */ |
302 | xfs_da_fixhashpath(state, &state->path); | 456 | xfs_da3_fixhashpath(state, &state->path); |
303 | } | 457 | } |
304 | if (!addblk) | 458 | if (!addblk) |
305 | return(0); | 459 | return(0); |
@@ -309,7 +463,7 @@ xfs_da_split(xfs_da_state_t *state) | |||
309 | */ | 463 | */ |
310 | ASSERT(state->path.active == 0); | 464 | ASSERT(state->path.active == 0); |
311 | oldblk = &state->path.blk[0]; | 465 | oldblk = &state->path.blk[0]; |
312 | error = xfs_da_root_split(state, oldblk, addblk); | 466 | error = xfs_da3_root_split(state, oldblk, addblk); |
313 | if (error) { | 467 | if (error) { |
314 | addblk->bp = NULL; | 468 | addblk->bp = NULL; |
315 | return(error); /* GROT: dir is inconsistent */ | 469 | return(error); /* GROT: dir is inconsistent */ |
@@ -320,8 +474,12 @@ xfs_da_split(xfs_da_state_t *state) | |||
320 | * just got bumped because of the addition of a new root node. | 474 | * just got bumped because of the addition of a new root node. |
321 | * There might be three blocks involved if a double split occurred, | 475 | * There might be three blocks involved if a double split occurred, |
322 | * and the original block 0 could be at any position in the list. | 476 | * and the original block 0 could be at any position in the list. |
477 | * | ||
478 | * Note: the magic numbers and sibling pointers are in the same | ||
479 | * physical place for both v2 and v3 headers (by design). Hence it | ||
480 | * doesn't matter which version of the xfs_da_intnode structure we use | ||
481 | * here as the result will be the same using either structure. | ||
323 | */ | 482 | */ |
324 | |||
325 | node = oldblk->bp->b_addr; | 483 | node = oldblk->bp->b_addr; |
326 | if (node->hdr.info.forw) { | 484 | if (node->hdr.info.forw) { |
327 | if (be32_to_cpu(node->hdr.info.forw) == addblk->blkno) { | 485 | if (be32_to_cpu(node->hdr.info.forw) == addblk->blkno) { |
@@ -360,18 +518,25 @@ xfs_da_split(xfs_da_state_t *state) | |||
360 | * the EOF, extending the inode in process. | 518 | * the EOF, extending the inode in process. |
361 | */ | 519 | */ |
362 | STATIC int /* error */ | 520 | STATIC int /* error */ |
363 | xfs_da_root_split(xfs_da_state_t *state, xfs_da_state_blk_t *blk1, | 521 | xfs_da3_root_split( |
364 | xfs_da_state_blk_t *blk2) | 522 | struct xfs_da_state *state, |
523 | struct xfs_da_state_blk *blk1, | ||
524 | struct xfs_da_state_blk *blk2) | ||
365 | { | 525 | { |
366 | xfs_da_intnode_t *node, *oldroot; | 526 | struct xfs_da_intnode *node; |
367 | xfs_da_args_t *args; | 527 | struct xfs_da_intnode *oldroot; |
368 | xfs_dablk_t blkno; | 528 | struct xfs_da_node_entry *btree; |
369 | struct xfs_buf *bp; | 529 | struct xfs_da3_icnode_hdr nodehdr; |
370 | int error, size; | 530 | struct xfs_da_args *args; |
371 | xfs_inode_t *dp; | 531 | struct xfs_buf *bp; |
372 | xfs_trans_t *tp; | 532 | struct xfs_inode *dp; |
373 | xfs_mount_t *mp; | 533 | struct xfs_trans *tp; |
374 | xfs_dir2_leaf_t *leaf; | 534 | struct xfs_mount *mp; |
535 | struct xfs_dir2_leaf *leaf; | ||
536 | xfs_dablk_t blkno; | ||
537 | int level; | ||
538 | int error; | ||
539 | int size; | ||
375 | 540 | ||
376 | trace_xfs_da_root_split(state->args); | 541 | trace_xfs_da_root_split(state->args); |
377 | 542 | ||
@@ -380,22 +545,26 @@ xfs_da_root_split(xfs_da_state_t *state, xfs_da_state_blk_t *blk1, | |||
380 | * to a free space somewhere. | 545 | * to a free space somewhere. |
381 | */ | 546 | */ |
382 | args = state->args; | 547 | args = state->args; |
383 | ASSERT(args != NULL); | ||
384 | error = xfs_da_grow_inode(args, &blkno); | 548 | error = xfs_da_grow_inode(args, &blkno); |
385 | if (error) | 549 | if (error) |
386 | return(error); | 550 | return error; |
551 | |||
387 | dp = args->dp; | 552 | dp = args->dp; |
388 | tp = args->trans; | 553 | tp = args->trans; |
389 | mp = state->mp; | 554 | mp = state->mp; |
390 | error = xfs_da_get_buf(tp, dp, blkno, -1, &bp, args->whichfork); | 555 | error = xfs_da_get_buf(tp, dp, blkno, -1, &bp, args->whichfork); |
391 | if (error) | 556 | if (error) |
392 | return(error); | 557 | return error; |
393 | ASSERT(bp != NULL); | ||
394 | node = bp->b_addr; | 558 | node = bp->b_addr; |
395 | oldroot = blk1->bp->b_addr; | 559 | oldroot = blk1->bp->b_addr; |
396 | if (oldroot->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)) { | 560 | if (oldroot->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC) || |
397 | size = (int)((char *)&oldroot->btree[be16_to_cpu(oldroot->hdr.count)] - | 561 | oldroot->hdr.info.magic == cpu_to_be16(XFS_DA3_NODE_MAGIC)) { |
398 | (char *)oldroot); | 562 | struct xfs_da3_icnode_hdr nodehdr; |
563 | |||
564 | xfs_da3_node_hdr_from_disk(&nodehdr, oldroot); | ||
565 | btree = xfs_da3_node_tree_p(oldroot); | ||
566 | size = (int)((char *)&btree[nodehdr.count] - (char *)oldroot); | ||
567 | level = nodehdr.level; | ||
399 | } else { | 568 | } else { |
400 | struct xfs_dir3_icleaf_hdr leafhdr; | 569 | struct xfs_dir3_icleaf_hdr leafhdr; |
401 | struct xfs_dir2_leaf_entry *ents; | 570 | struct xfs_dir2_leaf_entry *ents; |
@@ -407,9 +576,22 @@ xfs_da_root_split(xfs_da_state_t *state, xfs_da_state_blk_t *blk1, | |||
407 | ASSERT(leafhdr.magic == XFS_DIR2_LEAFN_MAGIC || | 576 | ASSERT(leafhdr.magic == XFS_DIR2_LEAFN_MAGIC || |
408 | leafhdr.magic == XFS_DIR3_LEAFN_MAGIC); | 577 | leafhdr.magic == XFS_DIR3_LEAFN_MAGIC); |
409 | size = (int)((char *)&ents[leafhdr.count] - (char *)leaf); | 578 | size = (int)((char *)&ents[leafhdr.count] - (char *)leaf); |
579 | level = 0; | ||
410 | } | 580 | } |
411 | /* XXX: can't just copy CRC headers from one block to another */ | 581 | |
582 | /* | ||
583 | * we can copy most of the information in the node from one block to | ||
584 | * another, but for CRC enabled headers we have to make sure that the | ||
585 | * block specific identifiers are kept intact. We update the buffer | ||
586 | * directly for this. | ||
587 | */ | ||
412 | memcpy(node, oldroot, size); | 588 | memcpy(node, oldroot, size); |
589 | if (oldroot->hdr.info.magic == cpu_to_be16(XFS_DA3_NODE_MAGIC) || | ||
590 | oldroot->hdr.info.magic == cpu_to_be16(XFS_DIR3_LEAFN_MAGIC)) { | ||
591 | struct xfs_da3_intnode *node3 = (struct xfs_da3_intnode *)node; | ||
592 | |||
593 | node3->hdr.info.blkno = cpu_to_be64(bp->b_bn); | ||
594 | } | ||
413 | xfs_trans_log_buf(tp, bp, 0, size - 1); | 595 | xfs_trans_log_buf(tp, bp, 0, size - 1); |
414 | 596 | ||
415 | bp->b_ops = blk1->bp->b_ops; | 597 | bp->b_ops = blk1->bp->b_ops; |
@@ -419,17 +601,21 @@ xfs_da_root_split(xfs_da_state_t *state, xfs_da_state_blk_t *blk1, | |||
419 | /* | 601 | /* |
420 | * Set up the new root node. | 602 | * Set up the new root node. |
421 | */ | 603 | */ |
422 | error = xfs_da_node_create(args, | 604 | error = xfs_da3_node_create(args, |
423 | (args->whichfork == XFS_DATA_FORK) ? mp->m_dirleafblk : 0, | 605 | (args->whichfork == XFS_DATA_FORK) ? mp->m_dirleafblk : 0, |
424 | be16_to_cpu(node->hdr.level) + 1, &bp, args->whichfork); | 606 | level + 1, &bp, args->whichfork); |
425 | if (error) | 607 | if (error) |
426 | return(error); | 608 | return error; |
609 | |||
427 | node = bp->b_addr; | 610 | node = bp->b_addr; |
428 | node->btree[0].hashval = cpu_to_be32(blk1->hashval); | 611 | xfs_da3_node_hdr_from_disk(&nodehdr, node); |
429 | node->btree[0].before = cpu_to_be32(blk1->blkno); | 612 | btree = xfs_da3_node_tree_p(node); |
430 | node->btree[1].hashval = cpu_to_be32(blk2->hashval); | 613 | btree[0].hashval = cpu_to_be32(blk1->hashval); |
431 | node->btree[1].before = cpu_to_be32(blk2->blkno); | 614 | btree[0].before = cpu_to_be32(blk1->blkno); |
432 | node->hdr.count = cpu_to_be16(2); | 615 | btree[1].hashval = cpu_to_be32(blk2->hashval); |
616 | btree[1].before = cpu_to_be32(blk2->blkno); | ||
617 | nodehdr.count = 2; | ||
618 | xfs_da3_node_hdr_to_disk(node, &nodehdr); | ||
433 | 619 | ||
434 | #ifdef DEBUG | 620 | #ifdef DEBUG |
435 | if (oldroot->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAFN_MAGIC) || | 621 | if (oldroot->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAFN_MAGIC) || |
@@ -443,30 +629,34 @@ xfs_da_root_split(xfs_da_state_t *state, xfs_da_state_blk_t *blk1, | |||
443 | 629 | ||
444 | /* Header is already logged by xfs_da_node_create */ | 630 | /* Header is already logged by xfs_da_node_create */ |
445 | xfs_trans_log_buf(tp, bp, | 631 | xfs_trans_log_buf(tp, bp, |
446 | XFS_DA_LOGRANGE(node, node->btree, | 632 | XFS_DA_LOGRANGE(node, btree, sizeof(xfs_da_node_entry_t) * 2)); |
447 | sizeof(xfs_da_node_entry_t) * 2)); | ||
448 | 633 | ||
449 | return(0); | 634 | return 0; |
450 | } | 635 | } |
451 | 636 | ||
452 | /* | 637 | /* |
453 | * Split the node, rebalance, then add the new entry. | 638 | * Split the node, rebalance, then add the new entry. |
454 | */ | 639 | */ |
455 | STATIC int /* error */ | 640 | STATIC int /* error */ |
456 | xfs_da_node_split(xfs_da_state_t *state, xfs_da_state_blk_t *oldblk, | 641 | xfs_da3_node_split( |
457 | xfs_da_state_blk_t *newblk, | 642 | struct xfs_da_state *state, |
458 | xfs_da_state_blk_t *addblk, | 643 | struct xfs_da_state_blk *oldblk, |
459 | int treelevel, int *result) | 644 | struct xfs_da_state_blk *newblk, |
645 | struct xfs_da_state_blk *addblk, | ||
646 | int treelevel, | ||
647 | int *result) | ||
460 | { | 648 | { |
461 | xfs_da_intnode_t *node; | 649 | struct xfs_da_intnode *node; |
462 | xfs_dablk_t blkno; | 650 | struct xfs_da3_icnode_hdr nodehdr; |
463 | int newcount, error; | 651 | xfs_dablk_t blkno; |
464 | int useextra; | 652 | int newcount; |
653 | int error; | ||
654 | int useextra; | ||
465 | 655 | ||
466 | trace_xfs_da_node_split(state->args); | 656 | trace_xfs_da_node_split(state->args); |
467 | 657 | ||
468 | node = oldblk->bp->b_addr; | 658 | node = oldblk->bp->b_addr; |
469 | ASSERT(node->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); | 659 | xfs_da3_node_hdr_from_disk(&nodehdr, node); |
470 | 660 | ||
471 | /* | 661 | /* |
472 | * With V2 dirs the extra block is data or freespace. | 662 | * With V2 dirs the extra block is data or freespace. |
@@ -476,7 +666,7 @@ xfs_da_node_split(xfs_da_state_t *state, xfs_da_state_blk_t *oldblk, | |||
476 | /* | 666 | /* |
477 | * Do we have to split the node? | 667 | * Do we have to split the node? |
478 | */ | 668 | */ |
479 | if ((be16_to_cpu(node->hdr.count) + newcount) > state->node_ents) { | 669 | if (nodehdr.count + newcount > state->node_ents) { |
480 | /* | 670 | /* |
481 | * Allocate a new node, add to the doubly linked chain of | 671 | * Allocate a new node, add to the doubly linked chain of |
482 | * nodes, then move some of our excess entries into it. | 672 | * nodes, then move some of our excess entries into it. |
@@ -485,14 +675,14 @@ xfs_da_node_split(xfs_da_state_t *state, xfs_da_state_blk_t *oldblk, | |||
485 | if (error) | 675 | if (error) |
486 | return(error); /* GROT: dir is inconsistent */ | 676 | return(error); /* GROT: dir is inconsistent */ |
487 | 677 | ||
488 | error = xfs_da_node_create(state->args, blkno, treelevel, | 678 | error = xfs_da3_node_create(state->args, blkno, treelevel, |
489 | &newblk->bp, state->args->whichfork); | 679 | &newblk->bp, state->args->whichfork); |
490 | if (error) | 680 | if (error) |
491 | return(error); /* GROT: dir is inconsistent */ | 681 | return(error); /* GROT: dir is inconsistent */ |
492 | newblk->blkno = blkno; | 682 | newblk->blkno = blkno; |
493 | newblk->magic = XFS_DA_NODE_MAGIC; | 683 | newblk->magic = XFS_DA_NODE_MAGIC; |
494 | xfs_da_node_rebalance(state, oldblk, newblk); | 684 | xfs_da3_node_rebalance(state, oldblk, newblk); |
495 | error = xfs_da_blk_link(state, oldblk, newblk); | 685 | error = xfs_da3_blk_link(state, oldblk, newblk); |
496 | if (error) | 686 | if (error) |
497 | return(error); | 687 | return(error); |
498 | *result = 1; | 688 | *result = 1; |
@@ -504,7 +694,7 @@ xfs_da_node_split(xfs_da_state_t *state, xfs_da_state_blk_t *oldblk, | |||
504 | * Insert the new entry(s) into the correct block | 694 | * Insert the new entry(s) into the correct block |
505 | * (updating last hashval in the process). | 695 | * (updating last hashval in the process). |
506 | * | 696 | * |
507 | * xfs_da_node_add() inserts BEFORE the given index, | 697 | * xfs_da3_node_add() inserts BEFORE the given index, |
508 | * and as a result of using node_lookup_int() we always | 698 | * and as a result of using node_lookup_int() we always |
509 | * point to a valid entry (not after one), but a split | 699 | * point to a valid entry (not after one), but a split |
510 | * operation always results in a new block whose hashvals | 700 | * operation always results in a new block whose hashvals |
@@ -513,22 +703,23 @@ xfs_da_node_split(xfs_da_state_t *state, xfs_da_state_blk_t *oldblk, | |||
513 | * If we had double-split op below us, then add the extra block too. | 703 | * If we had double-split op below us, then add the extra block too. |
514 | */ | 704 | */ |
515 | node = oldblk->bp->b_addr; | 705 | node = oldblk->bp->b_addr; |
516 | if (oldblk->index <= be16_to_cpu(node->hdr.count)) { | 706 | xfs_da3_node_hdr_from_disk(&nodehdr, node); |
707 | if (oldblk->index <= nodehdr.count) { | ||
517 | oldblk->index++; | 708 | oldblk->index++; |
518 | xfs_da_node_add(state, oldblk, addblk); | 709 | xfs_da3_node_add(state, oldblk, addblk); |
519 | if (useextra) { | 710 | if (useextra) { |
520 | if (state->extraafter) | 711 | if (state->extraafter) |
521 | oldblk->index++; | 712 | oldblk->index++; |
522 | xfs_da_node_add(state, oldblk, &state->extrablk); | 713 | xfs_da3_node_add(state, oldblk, &state->extrablk); |
523 | state->extravalid = 0; | 714 | state->extravalid = 0; |
524 | } | 715 | } |
525 | } else { | 716 | } else { |
526 | newblk->index++; | 717 | newblk->index++; |
527 | xfs_da_node_add(state, newblk, addblk); | 718 | xfs_da3_node_add(state, newblk, addblk); |
528 | if (useextra) { | 719 | if (useextra) { |
529 | if (state->extraafter) | 720 | if (state->extraafter) |
530 | newblk->index++; | 721 | newblk->index++; |
531 | xfs_da_node_add(state, newblk, &state->extrablk); | 722 | xfs_da3_node_add(state, newblk, &state->extrablk); |
532 | state->extravalid = 0; | 723 | state->extravalid = 0; |
533 | } | 724 | } |
534 | } | 725 | } |
@@ -543,33 +734,53 @@ xfs_da_node_split(xfs_da_state_t *state, xfs_da_state_blk_t *oldblk, | |||
543 | * NOTE: if blk2 is empty, then it will get the upper half of blk1. | 734 | * NOTE: if blk2 is empty, then it will get the upper half of blk1. |
544 | */ | 735 | */ |
545 | STATIC void | 736 | STATIC void |
546 | xfs_da_node_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1, | 737 | xfs_da3_node_rebalance( |
547 | xfs_da_state_blk_t *blk2) | 738 | struct xfs_da_state *state, |
739 | struct xfs_da_state_blk *blk1, | ||
740 | struct xfs_da_state_blk *blk2) | ||
548 | { | 741 | { |
549 | xfs_da_intnode_t *node1, *node2, *tmpnode; | 742 | struct xfs_da_intnode *node1; |
550 | xfs_da_node_entry_t *btree_s, *btree_d; | 743 | struct xfs_da_intnode *node2; |
551 | int count, tmp; | 744 | struct xfs_da_intnode *tmpnode; |
552 | xfs_trans_t *tp; | 745 | struct xfs_da_node_entry *btree1; |
746 | struct xfs_da_node_entry *btree2; | ||
747 | struct xfs_da_node_entry *btree_s; | ||
748 | struct xfs_da_node_entry *btree_d; | ||
749 | struct xfs_da3_icnode_hdr nodehdr1; | ||
750 | struct xfs_da3_icnode_hdr nodehdr2; | ||
751 | struct xfs_trans *tp; | ||
752 | int count; | ||
753 | int tmp; | ||
754 | int swap = 0; | ||
553 | 755 | ||
554 | trace_xfs_da_node_rebalance(state->args); | 756 | trace_xfs_da_node_rebalance(state->args); |
555 | 757 | ||
556 | node1 = blk1->bp->b_addr; | 758 | node1 = blk1->bp->b_addr; |
557 | node2 = blk2->bp->b_addr; | 759 | node2 = blk2->bp->b_addr; |
760 | xfs_da3_node_hdr_from_disk(&nodehdr1, node1); | ||
761 | xfs_da3_node_hdr_from_disk(&nodehdr2, node2); | ||
762 | btree1 = xfs_da3_node_tree_p(node1); | ||
763 | btree2 = xfs_da3_node_tree_p(node2); | ||
764 | |||
558 | /* | 765 | /* |
559 | * Figure out how many entries need to move, and in which direction. | 766 | * Figure out how many entries need to move, and in which direction. |
560 | * Swap the nodes around if that makes it simpler. | 767 | * Swap the nodes around if that makes it simpler. |
561 | */ | 768 | */ |
562 | if ((be16_to_cpu(node1->hdr.count) > 0) && (be16_to_cpu(node2->hdr.count) > 0) && | 769 | if (nodehdr1.count > 0 && nodehdr2.count > 0 && |
563 | ((be32_to_cpu(node2->btree[0].hashval) < be32_to_cpu(node1->btree[0].hashval)) || | 770 | ((be32_to_cpu(btree2[0].hashval) < be32_to_cpu(btree1[0].hashval)) || |
564 | (be32_to_cpu(node2->btree[be16_to_cpu(node2->hdr.count)-1].hashval) < | 771 | (be32_to_cpu(btree2[nodehdr2.count - 1].hashval) < |
565 | be32_to_cpu(node1->btree[be16_to_cpu(node1->hdr.count)-1].hashval)))) { | 772 | be32_to_cpu(btree1[nodehdr1.count - 1].hashval)))) { |
566 | tmpnode = node1; | 773 | tmpnode = node1; |
567 | node1 = node2; | 774 | node1 = node2; |
568 | node2 = tmpnode; | 775 | node2 = tmpnode; |
776 | xfs_da3_node_hdr_from_disk(&nodehdr1, node1); | ||
777 | xfs_da3_node_hdr_from_disk(&nodehdr2, node2); | ||
778 | btree1 = xfs_da3_node_tree_p(node1); | ||
779 | btree2 = xfs_da3_node_tree_p(node2); | ||
780 | swap = 1; | ||
569 | } | 781 | } |
570 | ASSERT(node1->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); | 782 | |
571 | ASSERT(node2->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); | 783 | count = (nodehdr1.count - nodehdr2.count) / 2; |
572 | count = (be16_to_cpu(node1->hdr.count) - be16_to_cpu(node2->hdr.count)) / 2; | ||
573 | if (count == 0) | 784 | if (count == 0) |
574 | return; | 785 | return; |
575 | tp = state->args->trans; | 786 | tp = state->args->trans; |
@@ -580,10 +791,11 @@ xfs_da_node_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1, | |||
580 | /* | 791 | /* |
581 | * Move elements in node2 up to make a hole. | 792 | * Move elements in node2 up to make a hole. |
582 | */ | 793 | */ |
583 | if ((tmp = be16_to_cpu(node2->hdr.count)) > 0) { | 794 | tmp = nodehdr2.count; |
795 | if (tmp > 0) { | ||
584 | tmp *= (uint)sizeof(xfs_da_node_entry_t); | 796 | tmp *= (uint)sizeof(xfs_da_node_entry_t); |
585 | btree_s = &node2->btree[0]; | 797 | btree_s = &btree2[0]; |
586 | btree_d = &node2->btree[count]; | 798 | btree_d = &btree2[count]; |
587 | memmove(btree_d, btree_s, tmp); | 799 | memmove(btree_d, btree_s, tmp); |
588 | } | 800 | } |
589 | 801 | ||
@@ -591,12 +803,12 @@ xfs_da_node_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1, | |||
591 | * Move the req'd B-tree elements from high in node1 to | 803 | * Move the req'd B-tree elements from high in node1 to |
592 | * low in node2. | 804 | * low in node2. |
593 | */ | 805 | */ |
594 | be16_add_cpu(&node2->hdr.count, count); | 806 | nodehdr2.count += count; |
595 | tmp = count * (uint)sizeof(xfs_da_node_entry_t); | 807 | tmp = count * (uint)sizeof(xfs_da_node_entry_t); |
596 | btree_s = &node1->btree[be16_to_cpu(node1->hdr.count) - count]; | 808 | btree_s = &btree1[nodehdr1.count - count]; |
597 | btree_d = &node2->btree[0]; | 809 | btree_d = &btree2[0]; |
598 | memcpy(btree_d, btree_s, tmp); | 810 | memcpy(btree_d, btree_s, tmp); |
599 | be16_add_cpu(&node1->hdr.count, -count); | 811 | nodehdr1.count -= count; |
600 | } else { | 812 | } else { |
601 | /* | 813 | /* |
602 | * Move the req'd B-tree elements from low in node2 to | 814 | * Move the req'd B-tree elements from low in node2 to |
@@ -604,49 +816,60 @@ xfs_da_node_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1, | |||
604 | */ | 816 | */ |
605 | count = -count; | 817 | count = -count; |
606 | tmp = count * (uint)sizeof(xfs_da_node_entry_t); | 818 | tmp = count * (uint)sizeof(xfs_da_node_entry_t); |
607 | btree_s = &node2->btree[0]; | 819 | btree_s = &btree2[0]; |
608 | btree_d = &node1->btree[be16_to_cpu(node1->hdr.count)]; | 820 | btree_d = &btree1[nodehdr1.count]; |
609 | memcpy(btree_d, btree_s, tmp); | 821 | memcpy(btree_d, btree_s, tmp); |
610 | be16_add_cpu(&node1->hdr.count, count); | 822 | nodehdr1.count += count; |
823 | |||
611 | xfs_trans_log_buf(tp, blk1->bp, | 824 | xfs_trans_log_buf(tp, blk1->bp, |
612 | XFS_DA_LOGRANGE(node1, btree_d, tmp)); | 825 | XFS_DA_LOGRANGE(node1, btree_d, tmp)); |
613 | 826 | ||
614 | /* | 827 | /* |
615 | * Move elements in node2 down to fill the hole. | 828 | * Move elements in node2 down to fill the hole. |
616 | */ | 829 | */ |
617 | tmp = be16_to_cpu(node2->hdr.count) - count; | 830 | tmp = nodehdr2.count - count; |
618 | tmp *= (uint)sizeof(xfs_da_node_entry_t); | 831 | tmp *= (uint)sizeof(xfs_da_node_entry_t); |
619 | btree_s = &node2->btree[count]; | 832 | btree_s = &btree2[count]; |
620 | btree_d = &node2->btree[0]; | 833 | btree_d = &btree2[0]; |
621 | memmove(btree_d, btree_s, tmp); | 834 | memmove(btree_d, btree_s, tmp); |
622 | be16_add_cpu(&node2->hdr.count, -count); | 835 | nodehdr2.count -= count; |
623 | } | 836 | } |
624 | 837 | ||
625 | /* | 838 | /* |
626 | * Log header of node 1 and all current bits of node 2. | 839 | * Log header of node 1 and all current bits of node 2. |
627 | */ | 840 | */ |
841 | xfs_da3_node_hdr_to_disk(node1, &nodehdr1); | ||
628 | xfs_trans_log_buf(tp, blk1->bp, | 842 | xfs_trans_log_buf(tp, blk1->bp, |
629 | XFS_DA_LOGRANGE(node1, &node1->hdr, sizeof(node1->hdr))); | 843 | XFS_DA_LOGRANGE(node1, &node1->hdr, |
844 | xfs_da3_node_hdr_size(node1))); | ||
845 | |||
846 | xfs_da3_node_hdr_to_disk(node2, &nodehdr2); | ||
630 | xfs_trans_log_buf(tp, blk2->bp, | 847 | xfs_trans_log_buf(tp, blk2->bp, |
631 | XFS_DA_LOGRANGE(node2, &node2->hdr, | 848 | XFS_DA_LOGRANGE(node2, &node2->hdr, |
632 | sizeof(node2->hdr) + | 849 | xfs_da3_node_hdr_size(node2) + |
633 | sizeof(node2->btree[0]) * be16_to_cpu(node2->hdr.count))); | 850 | (sizeof(btree2[0]) * nodehdr2.count))); |
634 | 851 | ||
635 | /* | 852 | /* |
636 | * Record the last hashval from each block for upward propagation. | 853 | * Record the last hashval from each block for upward propagation. |
637 | * (note: don't use the swapped node pointers) | 854 | * (note: don't use the swapped node pointers) |
638 | */ | 855 | */ |
639 | node1 = blk1->bp->b_addr; | 856 | if (swap) { |
640 | node2 = blk2->bp->b_addr; | 857 | node1 = blk1->bp->b_addr; |
641 | blk1->hashval = be32_to_cpu(node1->btree[be16_to_cpu(node1->hdr.count)-1].hashval); | 858 | node2 = blk2->bp->b_addr; |
642 | blk2->hashval = be32_to_cpu(node2->btree[be16_to_cpu(node2->hdr.count)-1].hashval); | 859 | xfs_da3_node_hdr_from_disk(&nodehdr1, node1); |
860 | xfs_da3_node_hdr_from_disk(&nodehdr2, node2); | ||
861 | btree1 = xfs_da3_node_tree_p(node1); | ||
862 | btree2 = xfs_da3_node_tree_p(node2); | ||
863 | } | ||
864 | blk1->hashval = be32_to_cpu(btree1[nodehdr1.count - 1].hashval); | ||
865 | blk2->hashval = be32_to_cpu(btree2[nodehdr2.count - 1].hashval); | ||
643 | 866 | ||
644 | /* | 867 | /* |
645 | * Adjust the expected index for insertion. | 868 | * Adjust the expected index for insertion. |
646 | */ | 869 | */ |
647 | if (blk1->index >= be16_to_cpu(node1->hdr.count)) { | 870 | if (blk1->index >= nodehdr1.count) { |
648 | blk2->index = blk1->index - be16_to_cpu(node1->hdr.count); | 871 | blk2->index = blk1->index - nodehdr1.count; |
649 | blk1->index = be16_to_cpu(node1->hdr.count) + 1; /* make it invalid */ | 872 | blk1->index = nodehdr1.count + 1; /* make it invalid */ |
650 | } | 873 | } |
651 | } | 874 | } |
652 | 875 | ||
@@ -654,18 +877,23 @@ xfs_da_node_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1, | |||
654 | * Add a new entry to an intermediate node. | 877 | * Add a new entry to an intermediate node. |
655 | */ | 878 | */ |
656 | STATIC void | 879 | STATIC void |
657 | xfs_da_node_add(xfs_da_state_t *state, xfs_da_state_blk_t *oldblk, | 880 | xfs_da3_node_add( |
658 | xfs_da_state_blk_t *newblk) | 881 | struct xfs_da_state *state, |
882 | struct xfs_da_state_blk *oldblk, | ||
883 | struct xfs_da_state_blk *newblk) | ||
659 | { | 884 | { |
660 | xfs_da_intnode_t *node; | 885 | struct xfs_da_intnode *node; |
661 | xfs_da_node_entry_t *btree; | 886 | struct xfs_da3_icnode_hdr nodehdr; |
662 | int tmp; | 887 | struct xfs_da_node_entry *btree; |
888 | int tmp; | ||
663 | 889 | ||
664 | trace_xfs_da_node_add(state->args); | 890 | trace_xfs_da_node_add(state->args); |
665 | 891 | ||
666 | node = oldblk->bp->b_addr; | 892 | node = oldblk->bp->b_addr; |
667 | ASSERT(node->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); | 893 | xfs_da3_node_hdr_from_disk(&nodehdr, node); |
668 | ASSERT((oldblk->index >= 0) && (oldblk->index <= be16_to_cpu(node->hdr.count))); | 894 | btree = xfs_da3_node_tree_p(node); |
895 | |||
896 | ASSERT(oldblk->index >= 0 && oldblk->index <= nodehdr.count); | ||
669 | ASSERT(newblk->blkno != 0); | 897 | ASSERT(newblk->blkno != 0); |
670 | if (state->args->whichfork == XFS_DATA_FORK) | 898 | if (state->args->whichfork == XFS_DATA_FORK) |
671 | ASSERT(newblk->blkno >= state->mp->m_dirleafblk && | 899 | ASSERT(newblk->blkno >= state->mp->m_dirleafblk && |
@@ -675,23 +903,25 @@ xfs_da_node_add(xfs_da_state_t *state, xfs_da_state_blk_t *oldblk, | |||
675 | * We may need to make some room before we insert the new node. | 903 | * We may need to make some room before we insert the new node. |
676 | */ | 904 | */ |
677 | tmp = 0; | 905 | tmp = 0; |
678 | btree = &node->btree[ oldblk->index ]; | 906 | if (oldblk->index < nodehdr.count) { |
679 | if (oldblk->index < be16_to_cpu(node->hdr.count)) { | 907 | tmp = (nodehdr.count - oldblk->index) * (uint)sizeof(*btree); |
680 | tmp = (be16_to_cpu(node->hdr.count) - oldblk->index) * (uint)sizeof(*btree); | 908 | memmove(&btree[oldblk->index + 1], &btree[oldblk->index], tmp); |
681 | memmove(btree + 1, btree, tmp); | ||
682 | } | 909 | } |
683 | btree->hashval = cpu_to_be32(newblk->hashval); | 910 | btree[oldblk->index].hashval = cpu_to_be32(newblk->hashval); |
684 | btree->before = cpu_to_be32(newblk->blkno); | 911 | btree[oldblk->index].before = cpu_to_be32(newblk->blkno); |
685 | xfs_trans_log_buf(state->args->trans, oldblk->bp, | 912 | xfs_trans_log_buf(state->args->trans, oldblk->bp, |
686 | XFS_DA_LOGRANGE(node, btree, tmp + sizeof(*btree))); | 913 | XFS_DA_LOGRANGE(node, &btree[oldblk->index], |
687 | be16_add_cpu(&node->hdr.count, 1); | 914 | tmp + sizeof(*btree))); |
915 | |||
916 | nodehdr.count += 1; | ||
917 | xfs_da3_node_hdr_to_disk(node, &nodehdr); | ||
688 | xfs_trans_log_buf(state->args->trans, oldblk->bp, | 918 | xfs_trans_log_buf(state->args->trans, oldblk->bp, |
689 | XFS_DA_LOGRANGE(node, &node->hdr, sizeof(node->hdr))); | 919 | XFS_DA_LOGRANGE(node, &node->hdr, xfs_da3_node_hdr_size(node))); |
690 | 920 | ||
691 | /* | 921 | /* |
692 | * Copy the last hash value from the oldblk to propagate upwards. | 922 | * Copy the last hash value from the oldblk to propagate upwards. |
693 | */ | 923 | */ |
694 | oldblk->hashval = be32_to_cpu(node->btree[be16_to_cpu(node->hdr.count)-1 ].hashval); | 924 | oldblk->hashval = be32_to_cpu(btree[nodehdr.count - 1].hashval); |
695 | } | 925 | } |
696 | 926 | ||
697 | /*======================================================================== | 927 | /*======================================================================== |
@@ -703,14 +933,16 @@ xfs_da_node_add(xfs_da_state_t *state, xfs_da_state_blk_t *oldblk, | |||
703 | * possibly deallocating that block, etc... | 933 | * possibly deallocating that block, etc... |
704 | */ | 934 | */ |
705 | int | 935 | int |
706 | xfs_da_join(xfs_da_state_t *state) | 936 | xfs_da3_join( |
937 | struct xfs_da_state *state) | ||
707 | { | 938 | { |
708 | xfs_da_state_blk_t *drop_blk, *save_blk; | 939 | struct xfs_da_state_blk *drop_blk; |
709 | int action, error; | 940 | struct xfs_da_state_blk *save_blk; |
941 | int action = 0; | ||
942 | int error; | ||
710 | 943 | ||
711 | trace_xfs_da_join(state->args); | 944 | trace_xfs_da_join(state->args); |
712 | 945 | ||
713 | action = 0; | ||
714 | drop_blk = &state->path.blk[ state->path.active-1 ]; | 946 | drop_blk = &state->path.blk[ state->path.active-1 ]; |
715 | save_blk = &state->altpath.blk[ state->path.active-1 ]; | 947 | save_blk = &state->altpath.blk[ state->path.active-1 ]; |
716 | ASSERT(state->path.blk[0].magic == XFS_DA_NODE_MAGIC); | 948 | ASSERT(state->path.blk[0].magic == XFS_DA_NODE_MAGIC); |
@@ -751,18 +983,18 @@ xfs_da_join(xfs_da_state_t *state) | |||
751 | * Remove the offending node, fixup hashvals, | 983 | * Remove the offending node, fixup hashvals, |
752 | * check for a toosmall neighbor. | 984 | * check for a toosmall neighbor. |
753 | */ | 985 | */ |
754 | xfs_da_node_remove(state, drop_blk); | 986 | xfs_da3_node_remove(state, drop_blk); |
755 | xfs_da_fixhashpath(state, &state->path); | 987 | xfs_da3_fixhashpath(state, &state->path); |
756 | error = xfs_da_node_toosmall(state, &action); | 988 | error = xfs_da3_node_toosmall(state, &action); |
757 | if (error) | 989 | if (error) |
758 | return(error); | 990 | return(error); |
759 | if (action == 0) | 991 | if (action == 0) |
760 | return 0; | 992 | return 0; |
761 | xfs_da_node_unbalance(state, drop_blk, save_blk); | 993 | xfs_da3_node_unbalance(state, drop_blk, save_blk); |
762 | break; | 994 | break; |
763 | } | 995 | } |
764 | xfs_da_fixhashpath(state, &state->altpath); | 996 | xfs_da3_fixhashpath(state, &state->altpath); |
765 | error = xfs_da_blk_unlink(state, drop_blk, save_blk); | 997 | error = xfs_da3_blk_unlink(state, drop_blk, save_blk); |
766 | xfs_da_state_kill_altpath(state); | 998 | xfs_da_state_kill_altpath(state); |
767 | if (error) | 999 | if (error) |
768 | return(error); | 1000 | return(error); |
@@ -777,9 +1009,9 @@ xfs_da_join(xfs_da_state_t *state) | |||
777 | * we only have one entry in the root, make the child block | 1009 | * we only have one entry in the root, make the child block |
778 | * the new root. | 1010 | * the new root. |
779 | */ | 1011 | */ |
780 | xfs_da_node_remove(state, drop_blk); | 1012 | xfs_da3_node_remove(state, drop_blk); |
781 | xfs_da_fixhashpath(state, &state->path); | 1013 | xfs_da3_fixhashpath(state, &state->path); |
782 | error = xfs_da_root_join(state, &state->path.blk[0]); | 1014 | error = xfs_da3_root_join(state, &state->path.blk[0]); |
783 | return(error); | 1015 | return(error); |
784 | } | 1016 | } |
785 | 1017 | ||
@@ -793,8 +1025,10 @@ xfs_da_blkinfo_onlychild_validate(struct xfs_da_blkinfo *blkinfo, __u16 level) | |||
793 | ASSERT(magic == cpu_to_be16(XFS_DIR2_LEAFN_MAGIC) || | 1025 | ASSERT(magic == cpu_to_be16(XFS_DIR2_LEAFN_MAGIC) || |
794 | magic == cpu_to_be16(XFS_DIR3_LEAFN_MAGIC) || | 1026 | magic == cpu_to_be16(XFS_DIR3_LEAFN_MAGIC) || |
795 | magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); | 1027 | magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); |
796 | } else | 1028 | } else { |
797 | ASSERT(magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); | 1029 | ASSERT(magic == cpu_to_be16(XFS_DA_NODE_MAGIC) || |
1030 | magic == cpu_to_be16(XFS_DA3_NODE_MAGIC)); | ||
1031 | } | ||
798 | ASSERT(!blkinfo->forw); | 1032 | ASSERT(!blkinfo->forw); |
799 | ASSERT(!blkinfo->back); | 1033 | ASSERT(!blkinfo->back); |
800 | } | 1034 | } |
@@ -807,52 +1041,60 @@ xfs_da_blkinfo_onlychild_validate(struct xfs_da_blkinfo *blkinfo, __u16 level) | |||
807 | * the old root to block 0 as the new root node. | 1041 | * the old root to block 0 as the new root node. |
808 | */ | 1042 | */ |
809 | STATIC int | 1043 | STATIC int |
810 | xfs_da_root_join(xfs_da_state_t *state, xfs_da_state_blk_t *root_blk) | 1044 | xfs_da3_root_join( |
1045 | struct xfs_da_state *state, | ||
1046 | struct xfs_da_state_blk *root_blk) | ||
811 | { | 1047 | { |
812 | xfs_da_intnode_t *oldroot; | 1048 | struct xfs_da_intnode *oldroot; |
813 | xfs_da_args_t *args; | 1049 | struct xfs_da_args *args; |
814 | xfs_dablk_t child; | 1050 | xfs_dablk_t child; |
815 | struct xfs_buf *bp; | 1051 | struct xfs_buf *bp; |
816 | int error; | 1052 | struct xfs_da3_icnode_hdr oldroothdr; |
1053 | struct xfs_da_node_entry *btree; | ||
1054 | int error; | ||
817 | 1055 | ||
818 | trace_xfs_da_root_join(state->args); | 1056 | trace_xfs_da_root_join(state->args); |
819 | 1057 | ||
820 | args = state->args; | ||
821 | ASSERT(args != NULL); | ||
822 | ASSERT(root_blk->magic == XFS_DA_NODE_MAGIC); | 1058 | ASSERT(root_blk->magic == XFS_DA_NODE_MAGIC); |
1059 | |||
1060 | args = state->args; | ||
823 | oldroot = root_blk->bp->b_addr; | 1061 | oldroot = root_blk->bp->b_addr; |
824 | ASSERT(oldroot->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); | 1062 | xfs_da3_node_hdr_from_disk(&oldroothdr, oldroot); |
825 | ASSERT(!oldroot->hdr.info.forw); | 1063 | ASSERT(oldroothdr.forw == 0); |
826 | ASSERT(!oldroot->hdr.info.back); | 1064 | ASSERT(oldroothdr.back == 0); |
827 | 1065 | ||
828 | /* | 1066 | /* |
829 | * If the root has more than one child, then don't do anything. | 1067 | * If the root has more than one child, then don't do anything. |
830 | */ | 1068 | */ |
831 | if (be16_to_cpu(oldroot->hdr.count) > 1) | 1069 | if (oldroothdr.count > 1) |
832 | return(0); | 1070 | return 0; |
833 | 1071 | ||
834 | /* | 1072 | /* |
835 | * Read in the (only) child block, then copy those bytes into | 1073 | * Read in the (only) child block, then copy those bytes into |
836 | * the root block's buffer and free the original child block. | 1074 | * the root block's buffer and free the original child block. |
837 | */ | 1075 | */ |
838 | child = be32_to_cpu(oldroot->btree[0].before); | 1076 | btree = xfs_da3_node_tree_p(oldroot); |
1077 | child = be32_to_cpu(btree[0].before); | ||
839 | ASSERT(child != 0); | 1078 | ASSERT(child != 0); |
840 | error = xfs_da_node_read(args->trans, args->dp, child, -1, &bp, | 1079 | error = xfs_da3_node_read(args->trans, args->dp, child, -1, &bp, |
841 | args->whichfork); | 1080 | args->whichfork); |
842 | if (error) | 1081 | if (error) |
843 | return(error); | 1082 | return error; |
844 | ASSERT(bp != NULL); | 1083 | xfs_da_blkinfo_onlychild_validate(bp->b_addr, oldroothdr.level); |
845 | xfs_da_blkinfo_onlychild_validate(bp->b_addr, | ||
846 | be16_to_cpu(oldroot->hdr.level)); | ||
847 | 1084 | ||
848 | /* | 1085 | /* |
849 | * This could be copying a leaf back into the root block in the case of | 1086 | * This could be copying a leaf back into the root block in the case of |
850 | * there only being a single leaf block left in the tree. Hence we have | 1087 | * there only being a single leaf block left in the tree. Hence we have |
851 | * to update the b_ops pointer as well to match the buffer type change | 1088 | * to update the b_ops pointer as well to match the buffer type change |
852 | * that could occur. | 1089 | * that could occur. For dir3 blocks we also need to update the block |
1090 | * number in the buffer header. | ||
853 | */ | 1091 | */ |
854 | memcpy(root_blk->bp->b_addr, bp->b_addr, state->blocksize); | 1092 | memcpy(root_blk->bp->b_addr, bp->b_addr, state->blocksize); |
855 | root_blk->bp->b_ops = bp->b_ops; | 1093 | root_blk->bp->b_ops = bp->b_ops; |
1094 | if (oldroothdr.magic == XFS_DA3_NODE_MAGIC) { | ||
1095 | struct xfs_da3_blkinfo *da3 = root_blk->bp->b_addr; | ||
1096 | da3->blkno = cpu_to_be64(root_blk->bp->b_bn); | ||
1097 | } | ||
856 | xfs_trans_log_buf(args->trans, root_blk->bp, 0, state->blocksize - 1); | 1098 | xfs_trans_log_buf(args->trans, root_blk->bp, 0, state->blocksize - 1); |
857 | error = xfs_da_shrink_inode(args, child, bp); | 1099 | error = xfs_da_shrink_inode(args, child, bp); |
858 | return(error); | 1100 | return(error); |
@@ -868,14 +1110,21 @@ xfs_da_root_join(xfs_da_state_t *state, xfs_da_state_blk_t *root_blk) | |||
868 | * If nothing can be done, return 0. | 1110 | * If nothing can be done, return 0. |
869 | */ | 1111 | */ |
870 | STATIC int | 1112 | STATIC int |
871 | xfs_da_node_toosmall(xfs_da_state_t *state, int *action) | 1113 | xfs_da3_node_toosmall( |
1114 | struct xfs_da_state *state, | ||
1115 | int *action) | ||
872 | { | 1116 | { |
873 | xfs_da_intnode_t *node; | 1117 | struct xfs_da_intnode *node; |
874 | xfs_da_state_blk_t *blk; | 1118 | struct xfs_da_state_blk *blk; |
875 | xfs_da_blkinfo_t *info; | 1119 | struct xfs_da_blkinfo *info; |
876 | int count, forward, error, retval, i; | 1120 | xfs_dablk_t blkno; |
877 | xfs_dablk_t blkno; | 1121 | struct xfs_buf *bp; |
878 | struct xfs_buf *bp; | 1122 | struct xfs_da3_icnode_hdr nodehdr; |
1123 | int count; | ||
1124 | int forward; | ||
1125 | int error; | ||
1126 | int retval; | ||
1127 | int i; | ||
879 | 1128 | ||
880 | trace_xfs_da_node_toosmall(state->args); | 1129 | trace_xfs_da_node_toosmall(state->args); |
881 | 1130 | ||
@@ -886,10 +1135,9 @@ xfs_da_node_toosmall(xfs_da_state_t *state, int *action) | |||
886 | */ | 1135 | */ |
887 | blk = &state->path.blk[ state->path.active-1 ]; | 1136 | blk = &state->path.blk[ state->path.active-1 ]; |
888 | info = blk->bp->b_addr; | 1137 | info = blk->bp->b_addr; |
889 | ASSERT(info->magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); | ||
890 | node = (xfs_da_intnode_t *)info; | 1138 | node = (xfs_da_intnode_t *)info; |
891 | count = be16_to_cpu(node->hdr.count); | 1139 | xfs_da3_node_hdr_from_disk(&nodehdr, node); |
892 | if (count > (state->node_ents >> 1)) { | 1140 | if (nodehdr.count > (state->node_ents >> 1)) { |
893 | *action = 0; /* blk over 50%, don't try to join */ | 1141 | *action = 0; /* blk over 50%, don't try to join */ |
894 | return(0); /* blk over 50%, don't try to join */ | 1142 | return(0); /* blk over 50%, don't try to join */ |
895 | } | 1143 | } |
@@ -900,14 +1148,14 @@ xfs_da_node_toosmall(xfs_da_state_t *state, int *action) | |||
900 | * coalesce it with a sibling block. We choose (arbitrarily) | 1148 | * coalesce it with a sibling block. We choose (arbitrarily) |
901 | * to merge with the forward block unless it is NULL. | 1149 | * to merge with the forward block unless it is NULL. |
902 | */ | 1150 | */ |
903 | if (count == 0) { | 1151 | if (nodehdr.count == 0) { |
904 | /* | 1152 | /* |
905 | * Make altpath point to the block we want to keep and | 1153 | * Make altpath point to the block we want to keep and |
906 | * path point to the block we want to drop (this one). | 1154 | * path point to the block we want to drop (this one). |
907 | */ | 1155 | */ |
908 | forward = (info->forw != 0); | 1156 | forward = (info->forw != 0); |
909 | memcpy(&state->altpath, &state->path, sizeof(state->path)); | 1157 | memcpy(&state->altpath, &state->path, sizeof(state->path)); |
910 | error = xfs_da_path_shift(state, &state->altpath, forward, | 1158 | error = xfs_da3_path_shift(state, &state->altpath, forward, |
911 | 0, &retval); | 1159 | 0, &retval); |
912 | if (error) | 1160 | if (error) |
913 | return(error); | 1161 | return(error); |
@@ -926,35 +1174,34 @@ xfs_da_node_toosmall(xfs_da_state_t *state, int *action) | |||
926 | * We prefer coalescing with the lower numbered sibling so as | 1174 | * We prefer coalescing with the lower numbered sibling so as |
927 | * to shrink a directory over time. | 1175 | * to shrink a directory over time. |
928 | */ | 1176 | */ |
1177 | count = state->node_ents; | ||
1178 | count -= state->node_ents >> 2; | ||
1179 | count -= nodehdr.count; | ||
1180 | |||
929 | /* start with smaller blk num */ | 1181 | /* start with smaller blk num */ |
930 | forward = (be32_to_cpu(info->forw) < be32_to_cpu(info->back)); | 1182 | forward = nodehdr.forw < nodehdr.back; |
931 | for (i = 0; i < 2; forward = !forward, i++) { | 1183 | for (i = 0; i < 2; forward = !forward, i++) { |
932 | if (forward) | 1184 | if (forward) |
933 | blkno = be32_to_cpu(info->forw); | 1185 | blkno = nodehdr.forw; |
934 | else | 1186 | else |
935 | blkno = be32_to_cpu(info->back); | 1187 | blkno = nodehdr.back; |
936 | if (blkno == 0) | 1188 | if (blkno == 0) |
937 | continue; | 1189 | continue; |
938 | error = xfs_da_node_read(state->args->trans, state->args->dp, | 1190 | error = xfs_da3_node_read(state->args->trans, state->args->dp, |
939 | blkno, -1, &bp, state->args->whichfork); | 1191 | blkno, -1, &bp, state->args->whichfork); |
940 | if (error) | 1192 | if (error) |
941 | return(error); | 1193 | return(error); |
942 | ASSERT(bp != NULL); | ||
943 | 1194 | ||
944 | node = (xfs_da_intnode_t *)info; | ||
945 | count = state->node_ents; | ||
946 | count -= state->node_ents >> 2; | ||
947 | count -= be16_to_cpu(node->hdr.count); | ||
948 | node = bp->b_addr; | 1195 | node = bp->b_addr; |
949 | ASSERT(node->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); | 1196 | xfs_da3_node_hdr_from_disk(&nodehdr, node); |
950 | count -= be16_to_cpu(node->hdr.count); | ||
951 | xfs_trans_brelse(state->args->trans, bp); | 1197 | xfs_trans_brelse(state->args->trans, bp); |
952 | if (count >= 0) | 1198 | |
1199 | if (count - nodehdr.count >= 0) | ||
953 | break; /* fits with at least 25% to spare */ | 1200 | break; /* fits with at least 25% to spare */ |
954 | } | 1201 | } |
955 | if (i >= 2) { | 1202 | if (i >= 2) { |
956 | *action = 0; | 1203 | *action = 0; |
957 | return(0); | 1204 | return 0; |
958 | } | 1205 | } |
959 | 1206 | ||
960 | /* | 1207 | /* |
@@ -963,28 +1210,42 @@ xfs_da_node_toosmall(xfs_da_state_t *state, int *action) | |||
963 | */ | 1210 | */ |
964 | memcpy(&state->altpath, &state->path, sizeof(state->path)); | 1211 | memcpy(&state->altpath, &state->path, sizeof(state->path)); |
965 | if (blkno < blk->blkno) { | 1212 | if (blkno < blk->blkno) { |
966 | error = xfs_da_path_shift(state, &state->altpath, forward, | 1213 | error = xfs_da3_path_shift(state, &state->altpath, forward, |
967 | 0, &retval); | 1214 | 0, &retval); |
968 | if (error) { | ||
969 | return(error); | ||
970 | } | ||
971 | if (retval) { | ||
972 | *action = 0; | ||
973 | return(0); | ||
974 | } | ||
975 | } else { | 1215 | } else { |
976 | error = xfs_da_path_shift(state, &state->path, forward, | 1216 | error = xfs_da3_path_shift(state, &state->path, forward, |
977 | 0, &retval); | 1217 | 0, &retval); |
978 | if (error) { | 1218 | } |
979 | return(error); | 1219 | if (error) |
980 | } | 1220 | return error; |
981 | if (retval) { | 1221 | if (retval) { |
982 | *action = 0; | 1222 | *action = 0; |
983 | return(0); | 1223 | return 0; |
984 | } | ||
985 | } | 1224 | } |
986 | *action = 1; | 1225 | *action = 1; |
987 | return(0); | 1226 | return 0; |
1227 | } | ||
1228 | |||
1229 | /* | ||
1230 | * Pick up the last hashvalue from an intermediate node. | ||
1231 | */ | ||
1232 | STATIC uint | ||
1233 | xfs_da3_node_lasthash( | ||
1234 | struct xfs_buf *bp, | ||
1235 | int *count) | ||
1236 | { | ||
1237 | struct xfs_da_intnode *node; | ||
1238 | struct xfs_da_node_entry *btree; | ||
1239 | struct xfs_da3_icnode_hdr nodehdr; | ||
1240 | |||
1241 | node = bp->b_addr; | ||
1242 | xfs_da3_node_hdr_from_disk(&nodehdr, node); | ||
1243 | if (count) | ||
1244 | *count = nodehdr.count; | ||
1245 | if (!nodehdr.count) | ||
1246 | return 0; | ||
1247 | btree = xfs_da3_node_tree_p(node); | ||
1248 | return be32_to_cpu(btree[nodehdr.count - 1].hashval); | ||
988 | } | 1249 | } |
989 | 1250 | ||
990 | /* | 1251 | /* |
@@ -992,13 +1253,16 @@ xfs_da_node_toosmall(xfs_da_state_t *state, int *action) | |||
992 | * when we stop making changes, return. | 1253 | * when we stop making changes, return. |
993 | */ | 1254 | */ |
994 | void | 1255 | void |
995 | xfs_da_fixhashpath(xfs_da_state_t *state, xfs_da_state_path_t *path) | 1256 | xfs_da3_fixhashpath( |
1257 | struct xfs_da_state *state, | ||
1258 | struct xfs_da_state_path *path) | ||
996 | { | 1259 | { |
997 | xfs_da_state_blk_t *blk; | 1260 | struct xfs_da_state_blk *blk; |
998 | xfs_da_intnode_t *node; | 1261 | struct xfs_da_intnode *node; |
999 | xfs_da_node_entry_t *btree; | 1262 | struct xfs_da_node_entry *btree; |
1000 | xfs_dahash_t lasthash=0; | 1263 | xfs_dahash_t lasthash=0; |
1001 | int level, count; | 1264 | int level; |
1265 | int count; | ||
1002 | 1266 | ||
1003 | trace_xfs_da_fixhashpath(state->args); | 1267 | trace_xfs_da_fixhashpath(state->args); |
1004 | 1268 | ||
@@ -1016,23 +1280,26 @@ xfs_da_fixhashpath(xfs_da_state_t *state, xfs_da_state_path_t *path) | |||
1016 | return; | 1280 | return; |
1017 | break; | 1281 | break; |
1018 | case XFS_DA_NODE_MAGIC: | 1282 | case XFS_DA_NODE_MAGIC: |
1019 | lasthash = xfs_da_node_lasthash(blk->bp, &count); | 1283 | lasthash = xfs_da3_node_lasthash(blk->bp, &count); |
1020 | if (count == 0) | 1284 | if (count == 0) |
1021 | return; | 1285 | return; |
1022 | break; | 1286 | break; |
1023 | } | 1287 | } |
1024 | for (blk--, level--; level >= 0; blk--, level--) { | 1288 | for (blk--, level--; level >= 0; blk--, level--) { |
1289 | struct xfs_da3_icnode_hdr nodehdr; | ||
1290 | |||
1025 | node = blk->bp->b_addr; | 1291 | node = blk->bp->b_addr; |
1026 | ASSERT(node->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); | 1292 | xfs_da3_node_hdr_from_disk(&nodehdr, node); |
1027 | btree = &node->btree[ blk->index ]; | 1293 | btree = xfs_da3_node_tree_p(node); |
1028 | if (be32_to_cpu(btree->hashval) == lasthash) | 1294 | if (be32_to_cpu(btree->hashval) == lasthash) |
1029 | break; | 1295 | break; |
1030 | blk->hashval = lasthash; | 1296 | blk->hashval = lasthash; |
1031 | btree->hashval = cpu_to_be32(lasthash); | 1297 | btree[blk->index].hashval = cpu_to_be32(lasthash); |
1032 | xfs_trans_log_buf(state->args->trans, blk->bp, | 1298 | xfs_trans_log_buf(state->args->trans, blk->bp, |
1033 | XFS_DA_LOGRANGE(node, btree, sizeof(*btree))); | 1299 | XFS_DA_LOGRANGE(node, &btree[blk->index], |
1300 | sizeof(*btree))); | ||
1034 | 1301 | ||
1035 | lasthash = be32_to_cpu(node->btree[be16_to_cpu(node->hdr.count)-1].hashval); | 1302 | lasthash = be32_to_cpu(btree[nodehdr.count - 1].hashval); |
1036 | } | 1303 | } |
1037 | } | 1304 | } |
1038 | 1305 | ||
@@ -1040,104 +1307,120 @@ xfs_da_fixhashpath(xfs_da_state_t *state, xfs_da_state_path_t *path) | |||
1040 | * Remove an entry from an intermediate node. | 1307 | * Remove an entry from an intermediate node. |
1041 | */ | 1308 | */ |
1042 | STATIC void | 1309 | STATIC void |
1043 | xfs_da_node_remove(xfs_da_state_t *state, xfs_da_state_blk_t *drop_blk) | 1310 | xfs_da3_node_remove( |
1311 | struct xfs_da_state *state, | ||
1312 | struct xfs_da_state_blk *drop_blk) | ||
1044 | { | 1313 | { |
1045 | xfs_da_intnode_t *node; | 1314 | struct xfs_da_intnode *node; |
1046 | xfs_da_node_entry_t *btree; | 1315 | struct xfs_da3_icnode_hdr nodehdr; |
1047 | int tmp; | 1316 | struct xfs_da_node_entry *btree; |
1317 | int index; | ||
1318 | int tmp; | ||
1048 | 1319 | ||
1049 | trace_xfs_da_node_remove(state->args); | 1320 | trace_xfs_da_node_remove(state->args); |
1050 | 1321 | ||
1051 | node = drop_blk->bp->b_addr; | 1322 | node = drop_blk->bp->b_addr; |
1052 | ASSERT(drop_blk->index < be16_to_cpu(node->hdr.count)); | 1323 | xfs_da3_node_hdr_from_disk(&nodehdr, node); |
1324 | ASSERT(drop_blk->index < nodehdr.count); | ||
1053 | ASSERT(drop_blk->index >= 0); | 1325 | ASSERT(drop_blk->index >= 0); |
1054 | 1326 | ||
1055 | /* | 1327 | /* |
1056 | * Copy over the offending entry, or just zero it out. | 1328 | * Copy over the offending entry, or just zero it out. |
1057 | */ | 1329 | */ |
1058 | btree = &node->btree[drop_blk->index]; | 1330 | index = drop_blk->index; |
1059 | if (drop_blk->index < (be16_to_cpu(node->hdr.count)-1)) { | 1331 | btree = xfs_da3_node_tree_p(node); |
1060 | tmp = be16_to_cpu(node->hdr.count) - drop_blk->index - 1; | 1332 | if (index < nodehdr.count - 1) { |
1333 | tmp = nodehdr.count - index - 1; | ||
1061 | tmp *= (uint)sizeof(xfs_da_node_entry_t); | 1334 | tmp *= (uint)sizeof(xfs_da_node_entry_t); |
1062 | memmove(btree, btree + 1, tmp); | 1335 | memmove(&btree[index], &btree[index + 1], tmp); |
1063 | xfs_trans_log_buf(state->args->trans, drop_blk->bp, | 1336 | xfs_trans_log_buf(state->args->trans, drop_blk->bp, |
1064 | XFS_DA_LOGRANGE(node, btree, tmp)); | 1337 | XFS_DA_LOGRANGE(node, &btree[index], tmp)); |
1065 | btree = &node->btree[be16_to_cpu(node->hdr.count)-1]; | 1338 | index = nodehdr.count - 1; |
1066 | } | 1339 | } |
1067 | memset((char *)btree, 0, sizeof(xfs_da_node_entry_t)); | 1340 | memset(&btree[index], 0, sizeof(xfs_da_node_entry_t)); |
1068 | xfs_trans_log_buf(state->args->trans, drop_blk->bp, | 1341 | xfs_trans_log_buf(state->args->trans, drop_blk->bp, |
1069 | XFS_DA_LOGRANGE(node, btree, sizeof(*btree))); | 1342 | XFS_DA_LOGRANGE(node, &btree[index], sizeof(btree[index]))); |
1070 | be16_add_cpu(&node->hdr.count, -1); | 1343 | nodehdr.count -= 1; |
1344 | xfs_da3_node_hdr_to_disk(node, &nodehdr); | ||
1071 | xfs_trans_log_buf(state->args->trans, drop_blk->bp, | 1345 | xfs_trans_log_buf(state->args->trans, drop_blk->bp, |
1072 | XFS_DA_LOGRANGE(node, &node->hdr, sizeof(node->hdr))); | 1346 | XFS_DA_LOGRANGE(node, &node->hdr, xfs_da3_node_hdr_size(node))); |
1073 | 1347 | ||
1074 | /* | 1348 | /* |
1075 | * Copy the last hash value from the block to propagate upwards. | 1349 | * Copy the last hash value from the block to propagate upwards. |
1076 | */ | 1350 | */ |
1077 | btree--; | 1351 | drop_blk->hashval = be32_to_cpu(btree[index - 1].hashval); |
1078 | drop_blk->hashval = be32_to_cpu(btree->hashval); | ||
1079 | } | 1352 | } |
1080 | 1353 | ||
1081 | /* | 1354 | /* |
1082 | * Unbalance the btree elements between two intermediate nodes, | 1355 | * Unbalance the elements between two intermediate nodes, |
1083 | * move all Btree elements from one node into another. | 1356 | * move all Btree elements from one node into another. |
1084 | */ | 1357 | */ |
1085 | STATIC void | 1358 | STATIC void |
1086 | xfs_da_node_unbalance(xfs_da_state_t *state, xfs_da_state_blk_t *drop_blk, | 1359 | xfs_da3_node_unbalance( |
1087 | xfs_da_state_blk_t *save_blk) | 1360 | struct xfs_da_state *state, |
1361 | struct xfs_da_state_blk *drop_blk, | ||
1362 | struct xfs_da_state_blk *save_blk) | ||
1088 | { | 1363 | { |
1089 | xfs_da_intnode_t *drop_node, *save_node; | 1364 | struct xfs_da_intnode *drop_node; |
1090 | xfs_da_node_entry_t *btree; | 1365 | struct xfs_da_intnode *save_node; |
1091 | int tmp; | 1366 | struct xfs_da_node_entry *drop_btree; |
1092 | xfs_trans_t *tp; | 1367 | struct xfs_da_node_entry *save_btree; |
1368 | struct xfs_da3_icnode_hdr drop_hdr; | ||
1369 | struct xfs_da3_icnode_hdr save_hdr; | ||
1370 | struct xfs_trans *tp; | ||
1371 | int sindex; | ||
1372 | int tmp; | ||
1093 | 1373 | ||
1094 | trace_xfs_da_node_unbalance(state->args); | 1374 | trace_xfs_da_node_unbalance(state->args); |
1095 | 1375 | ||
1096 | drop_node = drop_blk->bp->b_addr; | 1376 | drop_node = drop_blk->bp->b_addr; |
1097 | save_node = save_blk->bp->b_addr; | 1377 | save_node = save_blk->bp->b_addr; |
1098 | ASSERT(drop_node->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); | 1378 | xfs_da3_node_hdr_from_disk(&drop_hdr, drop_node); |
1099 | ASSERT(save_node->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); | 1379 | xfs_da3_node_hdr_from_disk(&save_hdr, save_node); |
1380 | drop_btree = xfs_da3_node_tree_p(drop_node); | ||
1381 | save_btree = xfs_da3_node_tree_p(save_node); | ||
1100 | tp = state->args->trans; | 1382 | tp = state->args->trans; |
1101 | 1383 | ||
1102 | /* | 1384 | /* |
1103 | * If the dying block has lower hashvals, then move all the | 1385 | * If the dying block has lower hashvals, then move all the |
1104 | * elements in the remaining block up to make a hole. | 1386 | * elements in the remaining block up to make a hole. |
1105 | */ | 1387 | */ |
1106 | if ((be32_to_cpu(drop_node->btree[0].hashval) < be32_to_cpu(save_node->btree[ 0 ].hashval)) || | 1388 | if ((be32_to_cpu(drop_btree[0].hashval) < |
1107 | (be32_to_cpu(drop_node->btree[be16_to_cpu(drop_node->hdr.count)-1].hashval) < | 1389 | be32_to_cpu(save_btree[0].hashval)) || |
1108 | be32_to_cpu(save_node->btree[be16_to_cpu(save_node->hdr.count)-1].hashval))) | 1390 | (be32_to_cpu(drop_btree[drop_hdr.count - 1].hashval) < |
1109 | { | 1391 | be32_to_cpu(save_btree[save_hdr.count - 1].hashval))) { |
1110 | btree = &save_node->btree[be16_to_cpu(drop_node->hdr.count)]; | 1392 | /* XXX: check this - is memmove dst correct? */ |
1111 | tmp = be16_to_cpu(save_node->hdr.count) * (uint)sizeof(xfs_da_node_entry_t); | 1393 | tmp = save_hdr.count * sizeof(xfs_da_node_entry_t); |
1112 | memmove(btree, &save_node->btree[0], tmp); | 1394 | memmove(&save_btree[drop_hdr.count], &save_btree[0], tmp); |
1113 | btree = &save_node->btree[0]; | 1395 | |
1396 | sindex = 0; | ||
1114 | xfs_trans_log_buf(tp, save_blk->bp, | 1397 | xfs_trans_log_buf(tp, save_blk->bp, |
1115 | XFS_DA_LOGRANGE(save_node, btree, | 1398 | XFS_DA_LOGRANGE(save_node, &save_btree[0], |
1116 | (be16_to_cpu(save_node->hdr.count) + be16_to_cpu(drop_node->hdr.count)) * | 1399 | (save_hdr.count + drop_hdr.count) * |
1117 | sizeof(xfs_da_node_entry_t))); | 1400 | sizeof(xfs_da_node_entry_t))); |
1118 | } else { | 1401 | } else { |
1119 | btree = &save_node->btree[be16_to_cpu(save_node->hdr.count)]; | 1402 | sindex = save_hdr.count; |
1120 | xfs_trans_log_buf(tp, save_blk->bp, | 1403 | xfs_trans_log_buf(tp, save_blk->bp, |
1121 | XFS_DA_LOGRANGE(save_node, btree, | 1404 | XFS_DA_LOGRANGE(save_node, &save_btree[sindex], |
1122 | be16_to_cpu(drop_node->hdr.count) * | 1405 | drop_hdr.count * sizeof(xfs_da_node_entry_t))); |
1123 | sizeof(xfs_da_node_entry_t))); | ||
1124 | } | 1406 | } |
1125 | 1407 | ||
1126 | /* | 1408 | /* |
1127 | * Move all the B-tree elements from drop_blk to save_blk. | 1409 | * Move all the B-tree elements from drop_blk to save_blk. |
1128 | */ | 1410 | */ |
1129 | tmp = be16_to_cpu(drop_node->hdr.count) * (uint)sizeof(xfs_da_node_entry_t); | 1411 | tmp = drop_hdr.count * (uint)sizeof(xfs_da_node_entry_t); |
1130 | memcpy(btree, &drop_node->btree[0], tmp); | 1412 | memcpy(&save_btree[sindex], &drop_btree[0], tmp); |
1131 | be16_add_cpu(&save_node->hdr.count, be16_to_cpu(drop_node->hdr.count)); | 1413 | save_hdr.count += drop_hdr.count; |
1132 | 1414 | ||
1415 | xfs_da3_node_hdr_to_disk(save_node, &save_hdr); | ||
1133 | xfs_trans_log_buf(tp, save_blk->bp, | 1416 | xfs_trans_log_buf(tp, save_blk->bp, |
1134 | XFS_DA_LOGRANGE(save_node, &save_node->hdr, | 1417 | XFS_DA_LOGRANGE(save_node, &save_node->hdr, |
1135 | sizeof(save_node->hdr))); | 1418 | xfs_da3_node_hdr_size(save_node))); |
1136 | 1419 | ||
1137 | /* | 1420 | /* |
1138 | * Save the last hashval in the remaining block for upward propagation. | 1421 | * Save the last hashval in the remaining block for upward propagation. |
1139 | */ | 1422 | */ |
1140 | save_blk->hashval = be32_to_cpu(save_node->btree[be16_to_cpu(save_node->hdr.count)-1].hashval); | 1423 | save_blk->hashval = be32_to_cpu(save_btree[save_hdr.count - 1].hashval); |
1141 | } | 1424 | } |
1142 | 1425 | ||
1143 | /*======================================================================== | 1426 | /*======================================================================== |
@@ -1156,16 +1439,24 @@ xfs_da_node_unbalance(xfs_da_state_t *state, xfs_da_state_blk_t *drop_blk, | |||
1156 | * pruned depth-first tree search. | 1439 | * pruned depth-first tree search. |
1157 | */ | 1440 | */ |
1158 | int /* error */ | 1441 | int /* error */ |
1159 | xfs_da_node_lookup_int(xfs_da_state_t *state, int *result) | 1442 | xfs_da3_node_lookup_int( |
1443 | struct xfs_da_state *state, | ||
1444 | int *result) | ||
1160 | { | 1445 | { |
1161 | xfs_da_state_blk_t *blk; | 1446 | struct xfs_da_state_blk *blk; |
1162 | xfs_da_blkinfo_t *curr; | 1447 | struct xfs_da_blkinfo *curr; |
1163 | xfs_da_intnode_t *node; | 1448 | struct xfs_da_intnode *node; |
1164 | xfs_da_node_entry_t *btree; | 1449 | struct xfs_da_node_entry *btree; |
1165 | xfs_dablk_t blkno; | 1450 | struct xfs_da3_icnode_hdr nodehdr; |
1166 | int probe, span, max, error, retval; | 1451 | struct xfs_da_args *args; |
1167 | xfs_dahash_t hashval, btreehashval; | 1452 | xfs_dablk_t blkno; |
1168 | xfs_da_args_t *args; | 1453 | xfs_dahash_t hashval; |
1454 | xfs_dahash_t btreehashval; | ||
1455 | int probe; | ||
1456 | int span; | ||
1457 | int max; | ||
1458 | int error; | ||
1459 | int retval; | ||
1169 | 1460 | ||
1170 | args = state->args; | 1461 | args = state->args; |
1171 | 1462 | ||
@@ -1181,7 +1472,7 @@ xfs_da_node_lookup_int(xfs_da_state_t *state, int *result) | |||
1181 | * Read the next node down in the tree. | 1472 | * Read the next node down in the tree. |
1182 | */ | 1473 | */ |
1183 | blk->blkno = blkno; | 1474 | blk->blkno = blkno; |
1184 | error = xfs_da_node_read(args->trans, args->dp, blkno, | 1475 | error = xfs_da3_node_read(args->trans, args->dp, blkno, |
1185 | -1, &blk->bp, args->whichfork); | 1476 | -1, &blk->bp, args->whichfork); |
1186 | if (error) { | 1477 | if (error) { |
1187 | blk->blkno = 0; | 1478 | blk->blkno = 0; |
@@ -1190,66 +1481,73 @@ xfs_da_node_lookup_int(xfs_da_state_t *state, int *result) | |||
1190 | } | 1481 | } |
1191 | curr = blk->bp->b_addr; | 1482 | curr = blk->bp->b_addr; |
1192 | blk->magic = be16_to_cpu(curr->magic); | 1483 | blk->magic = be16_to_cpu(curr->magic); |
1193 | ASSERT(blk->magic == XFS_DA_NODE_MAGIC || | 1484 | |
1194 | blk->magic == XFS_DIR2_LEAFN_MAGIC || | 1485 | if (blk->magic == XFS_ATTR_LEAF_MAGIC) { |
1195 | blk->magic == XFS_ATTR_LEAF_MAGIC); | 1486 | blk->hashval = xfs_attr_leaf_lasthash(blk->bp, NULL); |
1487 | break; | ||
1488 | } | ||
1489 | |||
1490 | if (blk->magic == XFS_DIR2_LEAFN_MAGIC || | ||
1491 | blk->magic == XFS_DIR3_LEAFN_MAGIC) { | ||
1492 | blk->magic = XFS_DIR2_LEAFN_MAGIC; | ||
1493 | blk->hashval = xfs_dir2_leafn_lasthash(blk->bp, NULL); | ||
1494 | break; | ||
1495 | } | ||
1496 | |||
1497 | blk->magic = XFS_DA_NODE_MAGIC; | ||
1498 | |||
1196 | 1499 | ||
1197 | /* | 1500 | /* |
1198 | * Search an intermediate node for a match. | 1501 | * Search an intermediate node for a match. |
1199 | */ | 1502 | */ |
1200 | if (blk->magic == XFS_DA_NODE_MAGIC) { | 1503 | node = blk->bp->b_addr; |
1201 | node = blk->bp->b_addr; | 1504 | xfs_da3_node_hdr_from_disk(&nodehdr, node); |
1202 | max = be16_to_cpu(node->hdr.count); | 1505 | btree = xfs_da3_node_tree_p(node); |
1203 | blk->hashval = be32_to_cpu(node->btree[max-1].hashval); | ||
1204 | 1506 | ||
1205 | /* | 1507 | max = nodehdr.count; |
1206 | * Binary search. (note: small blocks will skip loop) | 1508 | blk->hashval = be32_to_cpu(btree[max - 1].hashval); |
1207 | */ | ||
1208 | probe = span = max / 2; | ||
1209 | hashval = args->hashval; | ||
1210 | for (btree = &node->btree[probe]; span > 4; | ||
1211 | btree = &node->btree[probe]) { | ||
1212 | span /= 2; | ||
1213 | btreehashval = be32_to_cpu(btree->hashval); | ||
1214 | if (btreehashval < hashval) | ||
1215 | probe += span; | ||
1216 | else if (btreehashval > hashval) | ||
1217 | probe -= span; | ||
1218 | else | ||
1219 | break; | ||
1220 | } | ||
1221 | ASSERT((probe >= 0) && (probe < max)); | ||
1222 | ASSERT((span <= 4) || (be32_to_cpu(btree->hashval) == hashval)); | ||
1223 | 1509 | ||
1224 | /* | 1510 | /* |
1225 | * Since we may have duplicate hashval's, find the first | 1511 | * Binary search. (note: small blocks will skip loop) |
1226 | * matching hashval in the node. | 1512 | */ |
1227 | */ | 1513 | probe = span = max / 2; |
1228 | while ((probe > 0) && (be32_to_cpu(btree->hashval) >= hashval)) { | 1514 | hashval = args->hashval; |
1229 | btree--; | 1515 | while (span > 4) { |
1230 | probe--; | 1516 | span /= 2; |
1231 | } | 1517 | btreehashval = be32_to_cpu(btree[probe].hashval); |
1232 | while ((probe < max) && (be32_to_cpu(btree->hashval) < hashval)) { | 1518 | if (btreehashval < hashval) |
1233 | btree++; | 1519 | probe += span; |
1234 | probe++; | 1520 | else if (btreehashval > hashval) |
1235 | } | 1521 | probe -= span; |
1522 | else | ||
1523 | break; | ||
1524 | } | ||
1525 | ASSERT((probe >= 0) && (probe < max)); | ||
1526 | ASSERT((span <= 4) || | ||
1527 | (be32_to_cpu(btree[probe].hashval) == hashval)); | ||
1236 | 1528 | ||
1237 | /* | 1529 | /* |
1238 | * Pick the right block to descend on. | 1530 | * Since we may have duplicate hashval's, find the first |
1239 | */ | 1531 | * matching hashval in the node. |
1240 | if (probe == max) { | 1532 | */ |
1241 | blk->index = max-1; | 1533 | while (probe > 0 && |
1242 | blkno = be32_to_cpu(node->btree[max-1].before); | 1534 | be32_to_cpu(btree[probe].hashval) >= hashval) { |
1243 | } else { | 1535 | probe--; |
1244 | blk->index = probe; | 1536 | } |
1245 | blkno = be32_to_cpu(btree->before); | 1537 | while (probe < max && |
1246 | } | 1538 | be32_to_cpu(btree[probe].hashval) < hashval) { |
1247 | } else if (blk->magic == XFS_ATTR_LEAF_MAGIC) { | 1539 | probe++; |
1248 | blk->hashval = xfs_attr_leaf_lasthash(blk->bp, NULL); | 1540 | } |
1249 | break; | 1541 | |
1250 | } else if (blk->magic == XFS_DIR2_LEAFN_MAGIC) { | 1542 | /* |
1251 | blk->hashval = xfs_dir2_leafn_lasthash(blk->bp, NULL); | 1543 | * Pick the right block to descend on. |
1252 | break; | 1544 | */ |
1545 | if (probe == max) { | ||
1546 | blk->index = max - 1; | ||
1547 | blkno = be32_to_cpu(btree[max - 1].before); | ||
1548 | } else { | ||
1549 | blk->index = probe; | ||
1550 | blkno = be32_to_cpu(btree[probe].before); | ||
1253 | } | 1551 | } |
1254 | } | 1552 | } |
1255 | 1553 | ||
@@ -1273,7 +1571,7 @@ xfs_da_node_lookup_int(xfs_da_state_t *state, int *result) | |||
1273 | } | 1571 | } |
1274 | if (((retval == ENOENT) || (retval == ENOATTR)) && | 1572 | if (((retval == ENOENT) || (retval == ENOATTR)) && |
1275 | (blk->hashval == args->hashval)) { | 1573 | (blk->hashval == args->hashval)) { |
1276 | error = xfs_da_path_shift(state, &state->path, 1, 1, | 1574 | error = xfs_da3_path_shift(state, &state->path, 1, 1, |
1277 | &retval); | 1575 | &retval); |
1278 | if (error) | 1576 | if (error) |
1279 | return(error); | 1577 | return(error); |
@@ -1295,16 +1593,52 @@ xfs_da_node_lookup_int(xfs_da_state_t *state, int *result) | |||
1295 | *========================================================================*/ | 1593 | *========================================================================*/ |
1296 | 1594 | ||
1297 | /* | 1595 | /* |
1596 | * Compare two intermediate nodes for "order". | ||
1597 | */ | ||
1598 | STATIC int | ||
1599 | xfs_da3_node_order( | ||
1600 | struct xfs_buf *node1_bp, | ||
1601 | struct xfs_buf *node2_bp) | ||
1602 | { | ||
1603 | struct xfs_da_intnode *node1; | ||
1604 | struct xfs_da_intnode *node2; | ||
1605 | struct xfs_da_node_entry *btree1; | ||
1606 | struct xfs_da_node_entry *btree2; | ||
1607 | struct xfs_da3_icnode_hdr node1hdr; | ||
1608 | struct xfs_da3_icnode_hdr node2hdr; | ||
1609 | |||
1610 | node1 = node1_bp->b_addr; | ||
1611 | node2 = node2_bp->b_addr; | ||
1612 | xfs_da3_node_hdr_from_disk(&node1hdr, node1); | ||
1613 | xfs_da3_node_hdr_from_disk(&node2hdr, node2); | ||
1614 | btree1 = xfs_da3_node_tree_p(node1); | ||
1615 | btree2 = xfs_da3_node_tree_p(node2); | ||
1616 | |||
1617 | if (node1hdr.count > 0 && node2hdr.count > 0 && | ||
1618 | ((be32_to_cpu(btree2[0].hashval) < be32_to_cpu(btree1[0].hashval)) || | ||
1619 | (be32_to_cpu(btree2[node2hdr.count - 1].hashval) < | ||
1620 | be32_to_cpu(btree1[node1hdr.count - 1].hashval)))) { | ||
1621 | return 1; | ||
1622 | } | ||
1623 | return 0; | ||
1624 | } | ||
1625 | |||
1626 | /* | ||
1298 | * Link a new block into a doubly linked list of blocks (of whatever type). | 1627 | * Link a new block into a doubly linked list of blocks (of whatever type). |
1299 | */ | 1628 | */ |
1300 | int /* error */ | 1629 | int /* error */ |
1301 | xfs_da_blk_link(xfs_da_state_t *state, xfs_da_state_blk_t *old_blk, | 1630 | xfs_da3_blk_link( |
1302 | xfs_da_state_blk_t *new_blk) | 1631 | struct xfs_da_state *state, |
1632 | struct xfs_da_state_blk *old_blk, | ||
1633 | struct xfs_da_state_blk *new_blk) | ||
1303 | { | 1634 | { |
1304 | xfs_da_blkinfo_t *old_info, *new_info, *tmp_info; | 1635 | struct xfs_da_blkinfo *old_info; |
1305 | xfs_da_args_t *args; | 1636 | struct xfs_da_blkinfo *new_info; |
1306 | int before=0, error; | 1637 | struct xfs_da_blkinfo *tmp_info; |
1307 | struct xfs_buf *bp; | 1638 | struct xfs_da_args *args; |
1639 | struct xfs_buf *bp; | ||
1640 | int before = 0; | ||
1641 | int error; | ||
1308 | 1642 | ||
1309 | /* | 1643 | /* |
1310 | * Set up environment. | 1644 | * Set up environment. |
@@ -1316,9 +1650,6 @@ xfs_da_blk_link(xfs_da_state_t *state, xfs_da_state_blk_t *old_blk, | |||
1316 | ASSERT(old_blk->magic == XFS_DA_NODE_MAGIC || | 1650 | ASSERT(old_blk->magic == XFS_DA_NODE_MAGIC || |
1317 | old_blk->magic == XFS_DIR2_LEAFN_MAGIC || | 1651 | old_blk->magic == XFS_DIR2_LEAFN_MAGIC || |
1318 | old_blk->magic == XFS_ATTR_LEAF_MAGIC); | 1652 | old_blk->magic == XFS_ATTR_LEAF_MAGIC); |
1319 | ASSERT(old_blk->magic == be16_to_cpu(old_info->magic)); | ||
1320 | ASSERT(new_blk->magic == be16_to_cpu(new_info->magic)); | ||
1321 | ASSERT(old_blk->magic == new_blk->magic); | ||
1322 | 1653 | ||
1323 | switch (old_blk->magic) { | 1654 | switch (old_blk->magic) { |
1324 | case XFS_ATTR_LEAF_MAGIC: | 1655 | case XFS_ATTR_LEAF_MAGIC: |
@@ -1328,7 +1659,7 @@ xfs_da_blk_link(xfs_da_state_t *state, xfs_da_state_blk_t *old_blk, | |||
1328 | before = xfs_dir2_leafn_order(old_blk->bp, new_blk->bp); | 1659 | before = xfs_dir2_leafn_order(old_blk->bp, new_blk->bp); |
1329 | break; | 1660 | break; |
1330 | case XFS_DA_NODE_MAGIC: | 1661 | case XFS_DA_NODE_MAGIC: |
1331 | before = xfs_da_node_order(old_blk->bp, new_blk->bp); | 1662 | before = xfs_da3_node_order(old_blk->bp, new_blk->bp); |
1332 | break; | 1663 | break; |
1333 | } | 1664 | } |
1334 | 1665 | ||
@@ -1343,14 +1674,14 @@ xfs_da_blk_link(xfs_da_state_t *state, xfs_da_state_blk_t *old_blk, | |||
1343 | new_info->forw = cpu_to_be32(old_blk->blkno); | 1674 | new_info->forw = cpu_to_be32(old_blk->blkno); |
1344 | new_info->back = old_info->back; | 1675 | new_info->back = old_info->back; |
1345 | if (old_info->back) { | 1676 | if (old_info->back) { |
1346 | error = xfs_da_node_read(args->trans, args->dp, | 1677 | error = xfs_da3_node_read(args->trans, args->dp, |
1347 | be32_to_cpu(old_info->back), | 1678 | be32_to_cpu(old_info->back), |
1348 | -1, &bp, args->whichfork); | 1679 | -1, &bp, args->whichfork); |
1349 | if (error) | 1680 | if (error) |
1350 | return(error); | 1681 | return(error); |
1351 | ASSERT(bp != NULL); | 1682 | ASSERT(bp != NULL); |
1352 | tmp_info = bp->b_addr; | 1683 | tmp_info = bp->b_addr; |
1353 | ASSERT(be16_to_cpu(tmp_info->magic) == be16_to_cpu(old_info->magic)); | 1684 | ASSERT(tmp_info->magic == old_info->magic); |
1354 | ASSERT(be32_to_cpu(tmp_info->forw) == old_blk->blkno); | 1685 | ASSERT(be32_to_cpu(tmp_info->forw) == old_blk->blkno); |
1355 | tmp_info->forw = cpu_to_be32(new_blk->blkno); | 1686 | tmp_info->forw = cpu_to_be32(new_blk->blkno); |
1356 | xfs_trans_log_buf(args->trans, bp, 0, sizeof(*tmp_info)-1); | 1687 | xfs_trans_log_buf(args->trans, bp, 0, sizeof(*tmp_info)-1); |
@@ -1364,7 +1695,7 @@ xfs_da_blk_link(xfs_da_state_t *state, xfs_da_state_blk_t *old_blk, | |||
1364 | new_info->forw = old_info->forw; | 1695 | new_info->forw = old_info->forw; |
1365 | new_info->back = cpu_to_be32(old_blk->blkno); | 1696 | new_info->back = cpu_to_be32(old_blk->blkno); |
1366 | if (old_info->forw) { | 1697 | if (old_info->forw) { |
1367 | error = xfs_da_node_read(args->trans, args->dp, | 1698 | error = xfs_da3_node_read(args->trans, args->dp, |
1368 | be32_to_cpu(old_info->forw), | 1699 | be32_to_cpu(old_info->forw), |
1369 | -1, &bp, args->whichfork); | 1700 | -1, &bp, args->whichfork); |
1370 | if (error) | 1701 | if (error) |
@@ -1385,59 +1716,20 @@ xfs_da_blk_link(xfs_da_state_t *state, xfs_da_state_blk_t *old_blk, | |||
1385 | } | 1716 | } |
1386 | 1717 | ||
1387 | /* | 1718 | /* |
1388 | * Compare two intermediate nodes for "order". | ||
1389 | */ | ||
1390 | STATIC int | ||
1391 | xfs_da_node_order( | ||
1392 | struct xfs_buf *node1_bp, | ||
1393 | struct xfs_buf *node2_bp) | ||
1394 | { | ||
1395 | xfs_da_intnode_t *node1, *node2; | ||
1396 | |||
1397 | node1 = node1_bp->b_addr; | ||
1398 | node2 = node2_bp->b_addr; | ||
1399 | ASSERT(node1->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC) && | ||
1400 | node2->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); | ||
1401 | if ((be16_to_cpu(node1->hdr.count) > 0) && (be16_to_cpu(node2->hdr.count) > 0) && | ||
1402 | ((be32_to_cpu(node2->btree[0].hashval) < | ||
1403 | be32_to_cpu(node1->btree[0].hashval)) || | ||
1404 | (be32_to_cpu(node2->btree[be16_to_cpu(node2->hdr.count)-1].hashval) < | ||
1405 | be32_to_cpu(node1->btree[be16_to_cpu(node1->hdr.count)-1].hashval)))) { | ||
1406 | return(1); | ||
1407 | } | ||
1408 | return(0); | ||
1409 | } | ||
1410 | |||
1411 | /* | ||
1412 | * Pick up the last hashvalue from an intermediate node. | ||
1413 | */ | ||
1414 | STATIC uint | ||
1415 | xfs_da_node_lasthash( | ||
1416 | struct xfs_buf *bp, | ||
1417 | int *count) | ||
1418 | { | ||
1419 | xfs_da_intnode_t *node; | ||
1420 | |||
1421 | node = bp->b_addr; | ||
1422 | ASSERT(node->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); | ||
1423 | if (count) | ||
1424 | *count = be16_to_cpu(node->hdr.count); | ||
1425 | if (!node->hdr.count) | ||
1426 | return(0); | ||
1427 | return be32_to_cpu(node->btree[be16_to_cpu(node->hdr.count)-1].hashval); | ||
1428 | } | ||
1429 | |||
1430 | /* | ||
1431 | * Unlink a block from a doubly linked list of blocks. | 1719 | * Unlink a block from a doubly linked list of blocks. |
1432 | */ | 1720 | */ |
1433 | STATIC int /* error */ | 1721 | STATIC int /* error */ |
1434 | xfs_da_blk_unlink(xfs_da_state_t *state, xfs_da_state_blk_t *drop_blk, | 1722 | xfs_da3_blk_unlink( |
1435 | xfs_da_state_blk_t *save_blk) | 1723 | struct xfs_da_state *state, |
1724 | struct xfs_da_state_blk *drop_blk, | ||
1725 | struct xfs_da_state_blk *save_blk) | ||
1436 | { | 1726 | { |
1437 | xfs_da_blkinfo_t *drop_info, *save_info, *tmp_info; | 1727 | struct xfs_da_blkinfo *drop_info; |
1438 | xfs_da_args_t *args; | 1728 | struct xfs_da_blkinfo *save_info; |
1439 | struct xfs_buf *bp; | 1729 | struct xfs_da_blkinfo *tmp_info; |
1440 | int error; | 1730 | struct xfs_da_args *args; |
1731 | struct xfs_buf *bp; | ||
1732 | int error; | ||
1441 | 1733 | ||
1442 | /* | 1734 | /* |
1443 | * Set up environment. | 1735 | * Set up environment. |
@@ -1449,8 +1741,6 @@ xfs_da_blk_unlink(xfs_da_state_t *state, xfs_da_state_blk_t *drop_blk, | |||
1449 | ASSERT(save_blk->magic == XFS_DA_NODE_MAGIC || | 1741 | ASSERT(save_blk->magic == XFS_DA_NODE_MAGIC || |
1450 | save_blk->magic == XFS_DIR2_LEAFN_MAGIC || | 1742 | save_blk->magic == XFS_DIR2_LEAFN_MAGIC || |
1451 | save_blk->magic == XFS_ATTR_LEAF_MAGIC); | 1743 | save_blk->magic == XFS_ATTR_LEAF_MAGIC); |
1452 | ASSERT(save_blk->magic == be16_to_cpu(save_info->magic)); | ||
1453 | ASSERT(drop_blk->magic == be16_to_cpu(drop_info->magic)); | ||
1454 | ASSERT(save_blk->magic == drop_blk->magic); | 1744 | ASSERT(save_blk->magic == drop_blk->magic); |
1455 | ASSERT((be32_to_cpu(save_info->forw) == drop_blk->blkno) || | 1745 | ASSERT((be32_to_cpu(save_info->forw) == drop_blk->blkno) || |
1456 | (be32_to_cpu(save_info->back) == drop_blk->blkno)); | 1746 | (be32_to_cpu(save_info->back) == drop_blk->blkno)); |
@@ -1464,7 +1754,7 @@ xfs_da_blk_unlink(xfs_da_state_t *state, xfs_da_state_blk_t *drop_blk, | |||
1464 | trace_xfs_da_unlink_back(args); | 1754 | trace_xfs_da_unlink_back(args); |
1465 | save_info->back = drop_info->back; | 1755 | save_info->back = drop_info->back; |
1466 | if (drop_info->back) { | 1756 | if (drop_info->back) { |
1467 | error = xfs_da_node_read(args->trans, args->dp, | 1757 | error = xfs_da3_node_read(args->trans, args->dp, |
1468 | be32_to_cpu(drop_info->back), | 1758 | be32_to_cpu(drop_info->back), |
1469 | -1, &bp, args->whichfork); | 1759 | -1, &bp, args->whichfork); |
1470 | if (error) | 1760 | if (error) |
@@ -1481,7 +1771,7 @@ xfs_da_blk_unlink(xfs_da_state_t *state, xfs_da_state_blk_t *drop_blk, | |||
1481 | trace_xfs_da_unlink_forward(args); | 1771 | trace_xfs_da_unlink_forward(args); |
1482 | save_info->forw = drop_info->forw; | 1772 | save_info->forw = drop_info->forw; |
1483 | if (drop_info->forw) { | 1773 | if (drop_info->forw) { |
1484 | error = xfs_da_node_read(args->trans, args->dp, | 1774 | error = xfs_da3_node_read(args->trans, args->dp, |
1485 | be32_to_cpu(drop_info->forw), | 1775 | be32_to_cpu(drop_info->forw), |
1486 | -1, &bp, args->whichfork); | 1776 | -1, &bp, args->whichfork); |
1487 | if (error) | 1777 | if (error) |
@@ -1509,15 +1799,22 @@ xfs_da_blk_unlink(xfs_da_state_t *state, xfs_da_state_blk_t *drop_blk, | |||
1509 | * the new bottom and the root. | 1799 | * the new bottom and the root. |
1510 | */ | 1800 | */ |
1511 | int /* error */ | 1801 | int /* error */ |
1512 | xfs_da_path_shift(xfs_da_state_t *state, xfs_da_state_path_t *path, | 1802 | xfs_da3_path_shift( |
1513 | int forward, int release, int *result) | 1803 | struct xfs_da_state *state, |
1804 | struct xfs_da_state_path *path, | ||
1805 | int forward, | ||
1806 | int release, | ||
1807 | int *result) | ||
1514 | { | 1808 | { |
1515 | xfs_da_state_blk_t *blk; | 1809 | struct xfs_da_state_blk *blk; |
1516 | xfs_da_blkinfo_t *info; | 1810 | struct xfs_da_blkinfo *info; |
1517 | xfs_da_intnode_t *node; | 1811 | struct xfs_da_intnode *node; |
1518 | xfs_da_args_t *args; | 1812 | struct xfs_da_args *args; |
1519 | xfs_dablk_t blkno=0; | 1813 | struct xfs_da_node_entry *btree; |
1520 | int level, error; | 1814 | struct xfs_da3_icnode_hdr nodehdr; |
1815 | xfs_dablk_t blkno = 0; | ||
1816 | int level; | ||
1817 | int error; | ||
1521 | 1818 | ||
1522 | trace_xfs_da_path_shift(state->args); | 1819 | trace_xfs_da_path_shift(state->args); |
1523 | 1820 | ||
@@ -1532,16 +1829,17 @@ xfs_da_path_shift(xfs_da_state_t *state, xfs_da_state_path_t *path, | |||
1532 | ASSERT((path->active > 0) && (path->active < XFS_DA_NODE_MAXDEPTH)); | 1829 | ASSERT((path->active > 0) && (path->active < XFS_DA_NODE_MAXDEPTH)); |
1533 | level = (path->active-1) - 1; /* skip bottom layer in path */ | 1830 | level = (path->active-1) - 1; /* skip bottom layer in path */ |
1534 | for (blk = &path->blk[level]; level >= 0; blk--, level--) { | 1831 | for (blk = &path->blk[level]; level >= 0; blk--, level--) { |
1535 | ASSERT(blk->bp != NULL); | ||
1536 | node = blk->bp->b_addr; | 1832 | node = blk->bp->b_addr; |
1537 | ASSERT(node->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); | 1833 | xfs_da3_node_hdr_from_disk(&nodehdr, node); |
1538 | if (forward && (blk->index < be16_to_cpu(node->hdr.count)-1)) { | 1834 | btree = xfs_da3_node_tree_p(node); |
1835 | |||
1836 | if (forward && (blk->index < nodehdr.count - 1)) { | ||
1539 | blk->index++; | 1837 | blk->index++; |
1540 | blkno = be32_to_cpu(node->btree[blk->index].before); | 1838 | blkno = be32_to_cpu(btree[blk->index].before); |
1541 | break; | 1839 | break; |
1542 | } else if (!forward && (blk->index > 0)) { | 1840 | } else if (!forward && (blk->index > 0)) { |
1543 | blk->index--; | 1841 | blk->index--; |
1544 | blkno = be32_to_cpu(node->btree[blk->index].before); | 1842 | blkno = be32_to_cpu(btree[blk->index].before); |
1545 | break; | 1843 | break; |
1546 | } | 1844 | } |
1547 | } | 1845 | } |
@@ -1567,47 +1865,58 @@ xfs_da_path_shift(xfs_da_state_t *state, xfs_da_state_path_t *path, | |||
1567 | * Read the next child block. | 1865 | * Read the next child block. |
1568 | */ | 1866 | */ |
1569 | blk->blkno = blkno; | 1867 | blk->blkno = blkno; |
1570 | error = xfs_da_node_read(args->trans, args->dp, blkno, -1, | 1868 | error = xfs_da3_node_read(args->trans, args->dp, blkno, -1, |
1571 | &blk->bp, args->whichfork); | 1869 | &blk->bp, args->whichfork); |
1572 | if (error) | 1870 | if (error) |
1573 | return(error); | 1871 | return(error); |
1574 | ASSERT(blk->bp != NULL); | ||
1575 | info = blk->bp->b_addr; | 1872 | info = blk->bp->b_addr; |
1576 | ASSERT(info->magic == cpu_to_be16(XFS_DA_NODE_MAGIC) || | 1873 | ASSERT(info->magic == cpu_to_be16(XFS_DA_NODE_MAGIC) || |
1874 | info->magic == cpu_to_be16(XFS_DA3_NODE_MAGIC) || | ||
1577 | info->magic == cpu_to_be16(XFS_DIR2_LEAFN_MAGIC) || | 1875 | info->magic == cpu_to_be16(XFS_DIR2_LEAFN_MAGIC) || |
1578 | info->magic == cpu_to_be16(XFS_DIR3_LEAFN_MAGIC) || | 1876 | info->magic == cpu_to_be16(XFS_DIR3_LEAFN_MAGIC) || |
1579 | info->magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); | 1877 | info->magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); |
1580 | blk->magic = be16_to_cpu(info->magic); | 1878 | |
1581 | if (blk->magic == XFS_DA_NODE_MAGIC) { | 1879 | |
1880 | /* | ||
1881 | * Note: we flatten the magic number to a single type so we | ||
1882 | * don't have to compare against crc/non-crc types elsewhere. | ||
1883 | */ | ||
1884 | switch (be16_to_cpu(info->magic)) { | ||
1885 | case XFS_DA_NODE_MAGIC: | ||
1886 | case XFS_DA3_NODE_MAGIC: | ||
1887 | blk->magic = XFS_DA_NODE_MAGIC; | ||
1582 | node = (xfs_da_intnode_t *)info; | 1888 | node = (xfs_da_intnode_t *)info; |
1583 | blk->hashval = be32_to_cpu(node->btree[be16_to_cpu(node->hdr.count)-1].hashval); | 1889 | xfs_da3_node_hdr_from_disk(&nodehdr, node); |
1890 | btree = xfs_da3_node_tree_p(node); | ||
1891 | blk->hashval = be32_to_cpu(btree[nodehdr.count - 1].hashval); | ||
1584 | if (forward) | 1892 | if (forward) |
1585 | blk->index = 0; | 1893 | blk->index = 0; |
1586 | else | 1894 | else |
1587 | blk->index = be16_to_cpu(node->hdr.count)-1; | 1895 | blk->index = nodehdr.count - 1; |
1588 | blkno = be32_to_cpu(node->btree[blk->index].before); | 1896 | blkno = be32_to_cpu(btree[blk->index].before); |
1589 | } else { | 1897 | break; |
1898 | case XFS_ATTR_LEAF_MAGIC: | ||
1899 | blk->magic = XFS_ATTR_LEAF_MAGIC; | ||
1590 | ASSERT(level == path->active-1); | 1900 | ASSERT(level == path->active-1); |
1591 | blk->index = 0; | 1901 | blk->index = 0; |
1592 | switch(blk->magic) { | 1902 | blk->hashval = xfs_attr_leaf_lasthash(blk->bp, |
1593 | case XFS_ATTR_LEAF_MAGIC: | 1903 | NULL); |
1594 | blk->hashval = xfs_attr_leaf_lasthash(blk->bp, | 1904 | break; |
1595 | NULL); | 1905 | case XFS_DIR2_LEAFN_MAGIC: |
1596 | break; | 1906 | case XFS_DIR3_LEAFN_MAGIC: |
1597 | case XFS_DIR2_LEAFN_MAGIC: | 1907 | blk->magic = XFS_DIR2_LEAFN_MAGIC; |
1598 | case XFS_DIR3_LEAFN_MAGIC: | 1908 | ASSERT(level == path->active-1); |
1599 | blk->magic = XFS_DIR2_LEAFN_MAGIC; | 1909 | blk->index = 0; |
1600 | blk->hashval = xfs_dir2_leafn_lasthash(blk->bp, | 1910 | blk->hashval = xfs_dir2_leafn_lasthash(blk->bp, |
1601 | NULL); | 1911 | NULL); |
1602 | break; | 1912 | break; |
1603 | default: | 1913 | default: |
1604 | ASSERT(0); | 1914 | ASSERT(0); |
1605 | break; | 1915 | break; |
1606 | } | ||
1607 | } | 1916 | } |
1608 | } | 1917 | } |
1609 | *result = 0; | 1918 | *result = 0; |
1610 | return(0); | 1919 | return 0; |
1611 | } | 1920 | } |
1612 | 1921 | ||
1613 | 1922 | ||
@@ -1794,22 +2103,36 @@ xfs_da_grow_inode( | |||
1794 | * a bmap btree split to do that. | 2103 | * a bmap btree split to do that. |
1795 | */ | 2104 | */ |
1796 | STATIC int | 2105 | STATIC int |
1797 | xfs_da_swap_lastblock( | 2106 | xfs_da3_swap_lastblock( |
1798 | xfs_da_args_t *args, | 2107 | struct xfs_da_args *args, |
1799 | xfs_dablk_t *dead_blknop, | 2108 | xfs_dablk_t *dead_blknop, |
1800 | struct xfs_buf **dead_bufp) | 2109 | struct xfs_buf **dead_bufp) |
1801 | { | 2110 | { |
1802 | xfs_dablk_t dead_blkno, last_blkno, sib_blkno, par_blkno; | 2111 | struct xfs_da_blkinfo *dead_info; |
1803 | struct xfs_buf *dead_buf, *last_buf, *sib_buf, *par_buf; | 2112 | struct xfs_da_blkinfo *sib_info; |
1804 | xfs_fileoff_t lastoff; | 2113 | struct xfs_da_intnode *par_node; |
1805 | xfs_inode_t *ip; | 2114 | struct xfs_da_intnode *dead_node; |
1806 | xfs_trans_t *tp; | 2115 | struct xfs_dir2_leaf *dead_leaf2; |
1807 | xfs_mount_t *mp; | 2116 | struct xfs_da_node_entry *btree; |
1808 | int error, w, entno, level, dead_level; | 2117 | struct xfs_da3_icnode_hdr par_hdr; |
1809 | xfs_da_blkinfo_t *dead_info, *sib_info; | 2118 | struct xfs_inode *ip; |
1810 | xfs_da_intnode_t *par_node, *dead_node; | 2119 | struct xfs_trans *tp; |
1811 | xfs_dir2_leaf_t *dead_leaf2; | 2120 | struct xfs_mount *mp; |
1812 | xfs_dahash_t dead_hash; | 2121 | struct xfs_buf *dead_buf; |
2122 | struct xfs_buf *last_buf; | ||
2123 | struct xfs_buf *sib_buf; | ||
2124 | struct xfs_buf *par_buf; | ||
2125 | xfs_dahash_t dead_hash; | ||
2126 | xfs_fileoff_t lastoff; | ||
2127 | xfs_dablk_t dead_blkno; | ||
2128 | xfs_dablk_t last_blkno; | ||
2129 | xfs_dablk_t sib_blkno; | ||
2130 | xfs_dablk_t par_blkno; | ||
2131 | int error; | ||
2132 | int w; | ||
2133 | int entno; | ||
2134 | int level; | ||
2135 | int dead_level; | ||
1813 | 2136 | ||
1814 | trace_xfs_da_swap_lastblock(args); | 2137 | trace_xfs_da_swap_lastblock(args); |
1815 | 2138 | ||
@@ -1833,7 +2156,7 @@ xfs_da_swap_lastblock( | |||
1833 | * Read the last block in the btree space. | 2156 | * Read the last block in the btree space. |
1834 | */ | 2157 | */ |
1835 | last_blkno = (xfs_dablk_t)lastoff - mp->m_dirblkfsbs; | 2158 | last_blkno = (xfs_dablk_t)lastoff - mp->m_dirblkfsbs; |
1836 | error = xfs_da_node_read(tp, ip, last_blkno, -1, &last_buf, w); | 2159 | error = xfs_da3_node_read(tp, ip, last_blkno, -1, &last_buf, w); |
1837 | if (error) | 2160 | if (error) |
1838 | return error; | 2161 | return error; |
1839 | /* | 2162 | /* |
@@ -1856,17 +2179,20 @@ xfs_da_swap_lastblock( | |||
1856 | dead_level = 0; | 2179 | dead_level = 0; |
1857 | dead_hash = be32_to_cpu(ents[leafhdr.count - 1].hashval); | 2180 | dead_hash = be32_to_cpu(ents[leafhdr.count - 1].hashval); |
1858 | } else { | 2181 | } else { |
1859 | ASSERT(dead_info->magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); | 2182 | struct xfs_da3_icnode_hdr deadhdr; |
2183 | |||
1860 | dead_node = (xfs_da_intnode_t *)dead_info; | 2184 | dead_node = (xfs_da_intnode_t *)dead_info; |
1861 | dead_level = be16_to_cpu(dead_node->hdr.level); | 2185 | xfs_da3_node_hdr_from_disk(&deadhdr, dead_node); |
1862 | dead_hash = be32_to_cpu(dead_node->btree[be16_to_cpu(dead_node->hdr.count) - 1].hashval); | 2186 | btree = xfs_da3_node_tree_p(dead_node); |
2187 | dead_level = deadhdr.level; | ||
2188 | dead_hash = be32_to_cpu(btree[deadhdr.count - 1].hashval); | ||
1863 | } | 2189 | } |
1864 | sib_buf = par_buf = NULL; | 2190 | sib_buf = par_buf = NULL; |
1865 | /* | 2191 | /* |
1866 | * If the moved block has a left sibling, fix up the pointers. | 2192 | * If the moved block has a left sibling, fix up the pointers. |
1867 | */ | 2193 | */ |
1868 | if ((sib_blkno = be32_to_cpu(dead_info->back))) { | 2194 | if ((sib_blkno = be32_to_cpu(dead_info->back))) { |
1869 | error = xfs_da_node_read(tp, ip, sib_blkno, -1, &sib_buf, w); | 2195 | error = xfs_da3_node_read(tp, ip, sib_blkno, -1, &sib_buf, w); |
1870 | if (error) | 2196 | if (error) |
1871 | goto done; | 2197 | goto done; |
1872 | sib_info = sib_buf->b_addr; | 2198 | sib_info = sib_buf->b_addr; |
@@ -1888,7 +2214,7 @@ xfs_da_swap_lastblock( | |||
1888 | * If the moved block has a right sibling, fix up the pointers. | 2214 | * If the moved block has a right sibling, fix up the pointers. |
1889 | */ | 2215 | */ |
1890 | if ((sib_blkno = be32_to_cpu(dead_info->forw))) { | 2216 | if ((sib_blkno = be32_to_cpu(dead_info->forw))) { |
1891 | error = xfs_da_node_read(tp, ip, sib_blkno, -1, &sib_buf, w); | 2217 | error = xfs_da3_node_read(tp, ip, sib_blkno, -1, &sib_buf, w); |
1892 | if (error) | 2218 | if (error) |
1893 | goto done; | 2219 | goto done; |
1894 | sib_info = sib_buf->b_addr; | 2220 | sib_info = sib_buf->b_addr; |
@@ -1912,31 +2238,31 @@ xfs_da_swap_lastblock( | |||
1912 | * Walk down the tree looking for the parent of the moved block. | 2238 | * Walk down the tree looking for the parent of the moved block. |
1913 | */ | 2239 | */ |
1914 | for (;;) { | 2240 | for (;;) { |
1915 | error = xfs_da_node_read(tp, ip, par_blkno, -1, &par_buf, w); | 2241 | error = xfs_da3_node_read(tp, ip, par_blkno, -1, &par_buf, w); |
1916 | if (error) | 2242 | if (error) |
1917 | goto done; | 2243 | goto done; |
1918 | par_node = par_buf->b_addr; | 2244 | par_node = par_buf->b_addr; |
1919 | if (unlikely(par_node->hdr.info.magic != | 2245 | xfs_da3_node_hdr_from_disk(&par_hdr, par_node); |
1920 | cpu_to_be16(XFS_DA_NODE_MAGIC) || | 2246 | if (level >= 0 && level != par_hdr.level + 1) { |
1921 | (level >= 0 && level != be16_to_cpu(par_node->hdr.level) + 1))) { | ||
1922 | XFS_ERROR_REPORT("xfs_da_swap_lastblock(4)", | 2247 | XFS_ERROR_REPORT("xfs_da_swap_lastblock(4)", |
1923 | XFS_ERRLEVEL_LOW, mp); | 2248 | XFS_ERRLEVEL_LOW, mp); |
1924 | error = XFS_ERROR(EFSCORRUPTED); | 2249 | error = XFS_ERROR(EFSCORRUPTED); |
1925 | goto done; | 2250 | goto done; |
1926 | } | 2251 | } |
1927 | level = be16_to_cpu(par_node->hdr.level); | 2252 | level = par_hdr.level; |
2253 | btree = xfs_da3_node_tree_p(par_node); | ||
1928 | for (entno = 0; | 2254 | for (entno = 0; |
1929 | entno < be16_to_cpu(par_node->hdr.count) && | 2255 | entno < par_hdr.count && |
1930 | be32_to_cpu(par_node->btree[entno].hashval) < dead_hash; | 2256 | be32_to_cpu(btree[entno].hashval) < dead_hash; |
1931 | entno++) | 2257 | entno++) |
1932 | continue; | 2258 | continue; |
1933 | if (unlikely(entno == be16_to_cpu(par_node->hdr.count))) { | 2259 | if (entno == par_hdr.count) { |
1934 | XFS_ERROR_REPORT("xfs_da_swap_lastblock(5)", | 2260 | XFS_ERROR_REPORT("xfs_da_swap_lastblock(5)", |
1935 | XFS_ERRLEVEL_LOW, mp); | 2261 | XFS_ERRLEVEL_LOW, mp); |
1936 | error = XFS_ERROR(EFSCORRUPTED); | 2262 | error = XFS_ERROR(EFSCORRUPTED); |
1937 | goto done; | 2263 | goto done; |
1938 | } | 2264 | } |
1939 | par_blkno = be32_to_cpu(par_node->btree[entno].before); | 2265 | par_blkno = be32_to_cpu(btree[entno].before); |
1940 | if (level == dead_level + 1) | 2266 | if (level == dead_level + 1) |
1941 | break; | 2267 | break; |
1942 | xfs_trans_brelse(tp, par_buf); | 2268 | xfs_trans_brelse(tp, par_buf); |
@@ -1948,13 +2274,13 @@ xfs_da_swap_lastblock( | |||
1948 | */ | 2274 | */ |
1949 | for (;;) { | 2275 | for (;;) { |
1950 | for (; | 2276 | for (; |
1951 | entno < be16_to_cpu(par_node->hdr.count) && | 2277 | entno < par_hdr.count && |
1952 | be32_to_cpu(par_node->btree[entno].before) != last_blkno; | 2278 | be32_to_cpu(btree[entno].before) != last_blkno; |
1953 | entno++) | 2279 | entno++) |
1954 | continue; | 2280 | continue; |
1955 | if (entno < be16_to_cpu(par_node->hdr.count)) | 2281 | if (entno < par_hdr.count) |
1956 | break; | 2282 | break; |
1957 | par_blkno = be32_to_cpu(par_node->hdr.info.forw); | 2283 | par_blkno = par_hdr.forw; |
1958 | xfs_trans_brelse(tp, par_buf); | 2284 | xfs_trans_brelse(tp, par_buf); |
1959 | par_buf = NULL; | 2285 | par_buf = NULL; |
1960 | if (unlikely(par_blkno == 0)) { | 2286 | if (unlikely(par_blkno == 0)) { |
@@ -1963,27 +2289,27 @@ xfs_da_swap_lastblock( | |||
1963 | error = XFS_ERROR(EFSCORRUPTED); | 2289 | error = XFS_ERROR(EFSCORRUPTED); |
1964 | goto done; | 2290 | goto done; |
1965 | } | 2291 | } |
1966 | error = xfs_da_node_read(tp, ip, par_blkno, -1, &par_buf, w); | 2292 | error = xfs_da3_node_read(tp, ip, par_blkno, -1, &par_buf, w); |
1967 | if (error) | 2293 | if (error) |
1968 | goto done; | 2294 | goto done; |
1969 | par_node = par_buf->b_addr; | 2295 | par_node = par_buf->b_addr; |
1970 | if (unlikely( | 2296 | xfs_da3_node_hdr_from_disk(&par_hdr, par_node); |
1971 | be16_to_cpu(par_node->hdr.level) != level || | 2297 | if (par_hdr.level != level) { |
1972 | par_node->hdr.info.magic != cpu_to_be16(XFS_DA_NODE_MAGIC))) { | ||
1973 | XFS_ERROR_REPORT("xfs_da_swap_lastblock(7)", | 2298 | XFS_ERROR_REPORT("xfs_da_swap_lastblock(7)", |
1974 | XFS_ERRLEVEL_LOW, mp); | 2299 | XFS_ERRLEVEL_LOW, mp); |
1975 | error = XFS_ERROR(EFSCORRUPTED); | 2300 | error = XFS_ERROR(EFSCORRUPTED); |
1976 | goto done; | 2301 | goto done; |
1977 | } | 2302 | } |
2303 | btree = xfs_da3_node_tree_p(par_node); | ||
1978 | entno = 0; | 2304 | entno = 0; |
1979 | } | 2305 | } |
1980 | /* | 2306 | /* |
1981 | * Update the parent entry pointing to the moved block. | 2307 | * Update the parent entry pointing to the moved block. |
1982 | */ | 2308 | */ |
1983 | par_node->btree[entno].before = cpu_to_be32(dead_blkno); | 2309 | btree[entno].before = cpu_to_be32(dead_blkno); |
1984 | xfs_trans_log_buf(tp, par_buf, | 2310 | xfs_trans_log_buf(tp, par_buf, |
1985 | XFS_DA_LOGRANGE(par_node, &par_node->btree[entno].before, | 2311 | XFS_DA_LOGRANGE(par_node, &btree[entno].before, |
1986 | sizeof(par_node->btree[entno].before))); | 2312 | sizeof(btree[entno].before))); |
1987 | *dead_blknop = last_blkno; | 2313 | *dead_blknop = last_blkno; |
1988 | *dead_bufp = last_buf; | 2314 | *dead_bufp = last_buf; |
1989 | return 0; | 2315 | return 0; |
@@ -2025,14 +2351,15 @@ xfs_da_shrink_inode( | |||
2025 | * Remove extents. If we get ENOSPC for a dir we have to move | 2351 | * Remove extents. If we get ENOSPC for a dir we have to move |
2026 | * the last block to the place we want to kill. | 2352 | * the last block to the place we want to kill. |
2027 | */ | 2353 | */ |
2028 | if ((error = xfs_bunmapi(tp, dp, dead_blkno, count, | 2354 | error = xfs_bunmapi(tp, dp, dead_blkno, count, |
2029 | xfs_bmapi_aflag(w)|XFS_BMAPI_METADATA, | 2355 | xfs_bmapi_aflag(w)|XFS_BMAPI_METADATA, |
2030 | 0, args->firstblock, args->flist, | 2356 | 0, args->firstblock, args->flist, &done); |
2031 | &done)) == ENOSPC) { | 2357 | if (error == ENOSPC) { |
2032 | if (w != XFS_DATA_FORK) | 2358 | if (w != XFS_DATA_FORK) |
2033 | break; | 2359 | break; |
2034 | if ((error = xfs_da_swap_lastblock(args, &dead_blkno, | 2360 | error = xfs_da3_swap_lastblock(args, &dead_blkno, |
2035 | &dead_buf))) | 2361 | &dead_buf); |
2362 | if (error) | ||
2036 | break; | 2363 | break; |
2037 | } else { | 2364 | } else { |
2038 | break; | 2365 | break; |
@@ -2297,6 +2624,7 @@ xfs_da_read_buf( | |||
2297 | magic1 = be32_to_cpu(hdr->magic); | 2624 | magic1 = be32_to_cpu(hdr->magic); |
2298 | if (unlikely( | 2625 | if (unlikely( |
2299 | XFS_TEST_ERROR((magic != XFS_DA_NODE_MAGIC) && | 2626 | XFS_TEST_ERROR((magic != XFS_DA_NODE_MAGIC) && |
2627 | (magic != XFS_DA3_NODE_MAGIC) && | ||
2300 | (magic != XFS_ATTR_LEAF_MAGIC) && | 2628 | (magic != XFS_ATTR_LEAF_MAGIC) && |
2301 | (magic != XFS_DIR2_LEAF1_MAGIC) && | 2629 | (magic != XFS_DIR2_LEAF1_MAGIC) && |
2302 | (magic != XFS_DIR3_LEAF1_MAGIC) && | 2630 | (magic != XFS_DIR3_LEAF1_MAGIC) && |
@@ -2367,41 +2695,3 @@ out_free: | |||
2367 | return -1; | 2695 | return -1; |
2368 | return mappedbno; | 2696 | return mappedbno; |
2369 | } | 2697 | } |
2370 | |||
2371 | kmem_zone_t *xfs_da_state_zone; /* anchor for state struct zone */ | ||
2372 | |||
2373 | /* | ||
2374 | * Allocate a dir-state structure. | ||
2375 | * We don't put them on the stack since they're large. | ||
2376 | */ | ||
2377 | xfs_da_state_t * | ||
2378 | xfs_da_state_alloc(void) | ||
2379 | { | ||
2380 | return kmem_zone_zalloc(xfs_da_state_zone, KM_NOFS); | ||
2381 | } | ||
2382 | |||
2383 | /* | ||
2384 | * Kill the altpath contents of a da-state structure. | ||
2385 | */ | ||
2386 | STATIC void | ||
2387 | xfs_da_state_kill_altpath(xfs_da_state_t *state) | ||
2388 | { | ||
2389 | int i; | ||
2390 | |||
2391 | for (i = 0; i < state->altpath.active; i++) | ||
2392 | state->altpath.blk[i].bp = NULL; | ||
2393 | state->altpath.active = 0; | ||
2394 | } | ||
2395 | |||
2396 | /* | ||
2397 | * Free a da-state structure. | ||
2398 | */ | ||
2399 | void | ||
2400 | xfs_da_state_free(xfs_da_state_t *state) | ||
2401 | { | ||
2402 | xfs_da_state_kill_altpath(state); | ||
2403 | #ifdef DEBUG | ||
2404 | memset((char *)state, 0, sizeof(*state)); | ||
2405 | #endif /* DEBUG */ | ||
2406 | kmem_zone_free(xfs_da_state_zone, state); | ||
2407 | } | ||
diff --git a/fs/xfs/xfs_da_btree.h b/fs/xfs/xfs_da_btree.h index 0854b95b1dc1..6bedb3c1f5d3 100644 --- a/fs/xfs/xfs_da_btree.h +++ b/fs/xfs/xfs_da_btree.h | |||
@@ -1,5 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc. | 2 | * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc. |
3 | * Copyright (c) 2013 Red Hat, Inc. | ||
3 | * All Rights Reserved. | 4 | * All Rights Reserved. |
4 | * | 5 | * |
5 | * This program is free software; you can redistribute it and/or | 6 | * This program is free software; you can redistribute it and/or |
@@ -20,7 +21,6 @@ | |||
20 | 21 | ||
21 | struct xfs_bmap_free; | 22 | struct xfs_bmap_free; |
22 | struct xfs_inode; | 23 | struct xfs_inode; |
23 | struct xfs_mount; | ||
24 | struct xfs_trans; | 24 | struct xfs_trans; |
25 | struct zone; | 25 | struct zone; |
26 | 26 | ||
@@ -50,8 +50,11 @@ typedef struct xfs_da_blkinfo { | |||
50 | * CRC enabled directory structure types | 50 | * CRC enabled directory structure types |
51 | * | 51 | * |
52 | * The headers change size for the additional verification information, but | 52 | * The headers change size for the additional verification information, but |
53 | * otherwise the tree layouts and contents are unchanged. | 53 | * otherwise the tree layouts and contents are unchanged. Hence the da btree |
54 | * code can use the struct xfs_da_blkinfo for manipulating the tree links and | ||
55 | * magic numbers without modification for both v2 and v3 nodes. | ||
54 | */ | 56 | */ |
57 | #define XFS_DA3_NODE_MAGIC 0x3ebe /* magic number: non-leaf blocks */ | ||
55 | #define XFS_DIR3_LEAF1_MAGIC 0x3df1 /* magic number: v2 dirlf single blks */ | 58 | #define XFS_DIR3_LEAF1_MAGIC 0x3df1 /* magic number: v2 dirlf single blks */ |
56 | #define XFS_DIR3_LEAFN_MAGIC 0x3dff /* magic number: v2 dirlf multi blks */ | 59 | #define XFS_DIR3_LEAFN_MAGIC 0x3dff /* magic number: v2 dirlf multi blks */ |
57 | 60 | ||
@@ -80,19 +83,76 @@ struct xfs_da3_blkinfo { | |||
80 | */ | 83 | */ |
81 | #define XFS_DA_NODE_MAXDEPTH 5 /* max depth of Btree */ | 84 | #define XFS_DA_NODE_MAXDEPTH 5 /* max depth of Btree */ |
82 | 85 | ||
86 | typedef struct xfs_da_node_hdr { | ||
87 | struct xfs_da_blkinfo info; /* block type, links, etc. */ | ||
88 | __be16 count; /* count of active entries */ | ||
89 | __be16 __level; /* level above leaves (leaf == 0) */ | ||
90 | } xfs_da_node_hdr_t; | ||
91 | |||
92 | struct xfs_da3_node_hdr { | ||
93 | struct xfs_da3_blkinfo info; /* block type, links, etc. */ | ||
94 | __be16 count; /* count of active entries */ | ||
95 | __be16 __level; /* level above leaves (leaf == 0) */ | ||
96 | __be32 __pad32; | ||
97 | }; | ||
98 | |||
99 | #define XFS_DA3_NODE_CRC_OFF (offsetof(struct xfs_da3_node_hdr, info.crc)) | ||
100 | |||
101 | typedef struct xfs_da_node_entry { | ||
102 | __be32 hashval; /* hash value for this descendant */ | ||
103 | __be32 before; /* Btree block before this key */ | ||
104 | } xfs_da_node_entry_t; | ||
105 | |||
83 | typedef struct xfs_da_intnode { | 106 | typedef struct xfs_da_intnode { |
84 | struct xfs_da_node_hdr { /* constant-structure header block */ | 107 | struct xfs_da_node_hdr hdr; |
85 | xfs_da_blkinfo_t info; /* block type, links, etc. */ | 108 | struct xfs_da_node_entry __btree[]; |
86 | __be16 count; /* count of active entries */ | ||
87 | __be16 level; /* level above leaves (leaf == 0) */ | ||
88 | } hdr; | ||
89 | struct xfs_da_node_entry { | ||
90 | __be32 hashval; /* hash value for this descendant */ | ||
91 | __be32 before; /* Btree block before this key */ | ||
92 | } btree[1]; /* variable sized array of keys */ | ||
93 | } xfs_da_intnode_t; | 109 | } xfs_da_intnode_t; |
94 | typedef struct xfs_da_node_hdr xfs_da_node_hdr_t; | 110 | |
95 | typedef struct xfs_da_node_entry xfs_da_node_entry_t; | 111 | struct xfs_da3_intnode { |
112 | struct xfs_da3_node_hdr hdr; | ||
113 | struct xfs_da_node_entry __btree[]; | ||
114 | }; | ||
115 | |||
116 | /* | ||
117 | * In-core version of the node header to abstract the differences in the v2 and | ||
118 | * v3 disk format of the headers. Callers need to convert to/from disk format as | ||
119 | * appropriate. | ||
120 | */ | ||
121 | struct xfs_da3_icnode_hdr { | ||
122 | __uint32_t forw; | ||
123 | __uint32_t back; | ||
124 | __uint16_t magic; | ||
125 | __uint16_t count; | ||
126 | __uint16_t level; | ||
127 | }; | ||
128 | |||
129 | extern void xfs_da3_node_hdr_from_disk(struct xfs_da3_icnode_hdr *to, | ||
130 | struct xfs_da_intnode *from); | ||
131 | extern void xfs_da3_node_hdr_to_disk(struct xfs_da_intnode *to, | ||
132 | struct xfs_da3_icnode_hdr *from); | ||
133 | |||
134 | static inline int | ||
135 | xfs_da3_node_hdr_size(struct xfs_da_intnode *dap) | ||
136 | { | ||
137 | if (dap->hdr.info.magic == cpu_to_be16(XFS_DA3_NODE_MAGIC)) | ||
138 | return sizeof(struct xfs_da3_node_hdr); | ||
139 | return sizeof(struct xfs_da_node_hdr); | ||
140 | } | ||
141 | |||
142 | static inline struct xfs_da_node_entry * | ||
143 | xfs_da3_node_tree_p(struct xfs_da_intnode *dap) | ||
144 | { | ||
145 | if (dap->hdr.info.magic == cpu_to_be16(XFS_DA3_NODE_MAGIC)) { | ||
146 | struct xfs_da3_intnode *dap3 = (struct xfs_da3_intnode *)dap; | ||
147 | return dap3->__btree; | ||
148 | } | ||
149 | return dap->__btree; | ||
150 | } | ||
151 | |||
152 | extern void xfs_da3_intnode_from_disk(struct xfs_da3_icnode_hdr *to, | ||
153 | struct xfs_da_intnode *from); | ||
154 | extern void xfs_da3_intnode_to_disk(struct xfs_da_intnode *to, | ||
155 | struct xfs_da3_icnode_hdr *from); | ||
96 | 156 | ||
97 | #define XFS_LBSIZE(mp) (mp)->m_sb.sb_blocksize | 157 | #define XFS_LBSIZE(mp) (mp)->m_sb.sb_blocksize |
98 | 158 | ||
@@ -214,29 +274,29 @@ struct xfs_nameops { | |||
214 | /* | 274 | /* |
215 | * Routines used for growing the Btree. | 275 | * Routines used for growing the Btree. |
216 | */ | 276 | */ |
217 | int xfs_da_node_create(xfs_da_args_t *args, xfs_dablk_t blkno, int level, | 277 | int xfs_da3_node_create(struct xfs_da_args *args, xfs_dablk_t blkno, |
218 | struct xfs_buf **bpp, int whichfork); | 278 | int level, struct xfs_buf **bpp, int whichfork); |
219 | int xfs_da_split(xfs_da_state_t *state); | 279 | int xfs_da3_split(xfs_da_state_t *state); |
220 | 280 | ||
221 | /* | 281 | /* |
222 | * Routines used for shrinking the Btree. | 282 | * Routines used for shrinking the Btree. |
223 | */ | 283 | */ |
224 | int xfs_da_join(xfs_da_state_t *state); | 284 | int xfs_da3_join(xfs_da_state_t *state); |
225 | void xfs_da_fixhashpath(xfs_da_state_t *state, | 285 | void xfs_da3_fixhashpath(struct xfs_da_state *state, |
226 | xfs_da_state_path_t *path_to_to_fix); | 286 | struct xfs_da_state_path *path_to_to_fix); |
227 | 287 | ||
228 | /* | 288 | /* |
229 | * Routines used for finding things in the Btree. | 289 | * Routines used for finding things in the Btree. |
230 | */ | 290 | */ |
231 | int xfs_da_node_lookup_int(xfs_da_state_t *state, int *result); | 291 | int xfs_da3_node_lookup_int(xfs_da_state_t *state, int *result); |
232 | int xfs_da_path_shift(xfs_da_state_t *state, xfs_da_state_path_t *path, | 292 | int xfs_da3_path_shift(xfs_da_state_t *state, xfs_da_state_path_t *path, |
233 | int forward, int release, int *result); | 293 | int forward, int release, int *result); |
234 | /* | 294 | /* |
235 | * Utility routines. | 295 | * Utility routines. |
236 | */ | 296 | */ |
237 | int xfs_da_blk_link(xfs_da_state_t *state, xfs_da_state_blk_t *old_blk, | 297 | int xfs_da3_blk_link(xfs_da_state_t *state, xfs_da_state_blk_t *old_blk, |
238 | xfs_da_state_blk_t *new_blk); | 298 | xfs_da_state_blk_t *new_blk); |
239 | int xfs_da_node_read(struct xfs_trans *tp, struct xfs_inode *dp, | 299 | int xfs_da3_node_read(struct xfs_trans *tp, struct xfs_inode *dp, |
240 | xfs_dablk_t bno, xfs_daddr_t mappedbno, | 300 | xfs_dablk_t bno, xfs_daddr_t mappedbno, |
241 | struct xfs_buf **bpp, int which_fork); | 301 | struct xfs_buf **bpp, int which_fork); |
242 | 302 | ||
diff --git a/fs/xfs/xfs_dir2_node.c b/fs/xfs/xfs_dir2_node.c index baaf9d96e354..122449b33f5e 100644 --- a/fs/xfs/xfs_dir2_node.c +++ b/fs/xfs/xfs_dir2_node.c | |||
@@ -1371,7 +1371,7 @@ xfs_dir2_leafn_split( | |||
1371 | * block into the leaves. | 1371 | * block into the leaves. |
1372 | */ | 1372 | */ |
1373 | xfs_dir2_leafn_rebalance(state, oldblk, newblk); | 1373 | xfs_dir2_leafn_rebalance(state, oldblk, newblk); |
1374 | error = xfs_da_blk_link(state, oldblk, newblk); | 1374 | error = xfs_da3_blk_link(state, oldblk, newblk); |
1375 | if (error) { | 1375 | if (error) { |
1376 | return error; | 1376 | return error; |
1377 | } | 1377 | } |
@@ -1452,7 +1452,7 @@ xfs_dir2_leafn_toosmall( | |||
1452 | */ | 1452 | */ |
1453 | forward = (leafhdr.forw != 0); | 1453 | forward = (leafhdr.forw != 0); |
1454 | memcpy(&state->altpath, &state->path, sizeof(state->path)); | 1454 | memcpy(&state->altpath, &state->path, sizeof(state->path)); |
1455 | error = xfs_da_path_shift(state, &state->altpath, forward, 0, | 1455 | error = xfs_da3_path_shift(state, &state->altpath, forward, 0, |
1456 | &rval); | 1456 | &rval); |
1457 | if (error) | 1457 | if (error) |
1458 | return error; | 1458 | return error; |
@@ -1514,10 +1514,10 @@ xfs_dir2_leafn_toosmall( | |||
1514 | */ | 1514 | */ |
1515 | memcpy(&state->altpath, &state->path, sizeof(state->path)); | 1515 | memcpy(&state->altpath, &state->path, sizeof(state->path)); |
1516 | if (blkno < blk->blkno) | 1516 | if (blkno < blk->blkno) |
1517 | error = xfs_da_path_shift(state, &state->altpath, forward, 0, | 1517 | error = xfs_da3_path_shift(state, &state->altpath, forward, 0, |
1518 | &rval); | 1518 | &rval); |
1519 | else | 1519 | else |
1520 | error = xfs_da_path_shift(state, &state->path, forward, 0, | 1520 | error = xfs_da3_path_shift(state, &state->path, forward, 0, |
1521 | &rval); | 1521 | &rval); |
1522 | if (error) { | 1522 | if (error) { |
1523 | return error; | 1523 | return error; |
@@ -1614,7 +1614,7 @@ xfs_dir2_node_addname( | |||
1614 | * Look up the name. We're not supposed to find it, but | 1614 | * Look up the name. We're not supposed to find it, but |
1615 | * this gives us the insertion point. | 1615 | * this gives us the insertion point. |
1616 | */ | 1616 | */ |
1617 | error = xfs_da_node_lookup_int(state, &rval); | 1617 | error = xfs_da3_node_lookup_int(state, &rval); |
1618 | if (error) | 1618 | if (error) |
1619 | rval = error; | 1619 | rval = error; |
1620 | if (rval != ENOENT) { | 1620 | if (rval != ENOENT) { |
@@ -1640,7 +1640,7 @@ xfs_dir2_node_addname( | |||
1640 | * It worked, fix the hash values up the btree. | 1640 | * It worked, fix the hash values up the btree. |
1641 | */ | 1641 | */ |
1642 | if (!(args->op_flags & XFS_DA_OP_JUSTCHECK)) | 1642 | if (!(args->op_flags & XFS_DA_OP_JUSTCHECK)) |
1643 | xfs_da_fixhashpath(state, &state->path); | 1643 | xfs_da3_fixhashpath(state, &state->path); |
1644 | } else { | 1644 | } else { |
1645 | /* | 1645 | /* |
1646 | * It didn't work, we need to split the leaf block. | 1646 | * It didn't work, we need to split the leaf block. |
@@ -1652,7 +1652,7 @@ xfs_dir2_node_addname( | |||
1652 | /* | 1652 | /* |
1653 | * Split the leaf block and insert the new entry. | 1653 | * Split the leaf block and insert the new entry. |
1654 | */ | 1654 | */ |
1655 | rval = xfs_da_split(state); | 1655 | rval = xfs_da3_split(state); |
1656 | } | 1656 | } |
1657 | done: | 1657 | done: |
1658 | xfs_da_state_free(state); | 1658 | xfs_da_state_free(state); |
@@ -2030,7 +2030,7 @@ xfs_dir2_node_addname_int( | |||
2030 | 2030 | ||
2031 | /* | 2031 | /* |
2032 | * Lookup an entry in a node-format directory. | 2032 | * Lookup an entry in a node-format directory. |
2033 | * All the real work happens in xfs_da_node_lookup_int. | 2033 | * All the real work happens in xfs_da3_node_lookup_int. |
2034 | * The only real output is the inode number of the entry. | 2034 | * The only real output is the inode number of the entry. |
2035 | */ | 2035 | */ |
2036 | int /* error */ | 2036 | int /* error */ |
@@ -2055,7 +2055,7 @@ xfs_dir2_node_lookup( | |||
2055 | /* | 2055 | /* |
2056 | * Fill in the path to the entry in the cursor. | 2056 | * Fill in the path to the entry in the cursor. |
2057 | */ | 2057 | */ |
2058 | error = xfs_da_node_lookup_int(state, &rval); | 2058 | error = xfs_da3_node_lookup_int(state, &rval); |
2059 | if (error) | 2059 | if (error) |
2060 | rval = error; | 2060 | rval = error; |
2061 | else if (rval == ENOENT && args->cmpresult == XFS_CMP_CASE) { | 2061 | else if (rval == ENOENT && args->cmpresult == XFS_CMP_CASE) { |
@@ -2110,7 +2110,7 @@ xfs_dir2_node_removename( | |||
2110 | /* | 2110 | /* |
2111 | * Look up the entry we're deleting, set up the cursor. | 2111 | * Look up the entry we're deleting, set up the cursor. |
2112 | */ | 2112 | */ |
2113 | error = xfs_da_node_lookup_int(state, &rval); | 2113 | error = xfs_da3_node_lookup_int(state, &rval); |
2114 | if (error) | 2114 | if (error) |
2115 | rval = error; | 2115 | rval = error; |
2116 | /* | 2116 | /* |
@@ -2134,12 +2134,12 @@ xfs_dir2_node_removename( | |||
2134 | /* | 2134 | /* |
2135 | * Fix the hash values up the btree. | 2135 | * Fix the hash values up the btree. |
2136 | */ | 2136 | */ |
2137 | xfs_da_fixhashpath(state, &state->path); | 2137 | xfs_da3_fixhashpath(state, &state->path); |
2138 | /* | 2138 | /* |
2139 | * If we need to join leaf blocks, do it. | 2139 | * If we need to join leaf blocks, do it. |
2140 | */ | 2140 | */ |
2141 | if (rval && state->path.active > 1) | 2141 | if (rval && state->path.active > 1) |
2142 | error = xfs_da_join(state); | 2142 | error = xfs_da3_join(state); |
2143 | /* | 2143 | /* |
2144 | * If no errors so far, try conversion to leaf format. | 2144 | * If no errors so far, try conversion to leaf format. |
2145 | */ | 2145 | */ |
@@ -2181,7 +2181,7 @@ xfs_dir2_node_replace( | |||
2181 | /* | 2181 | /* |
2182 | * Lookup the entry to change in the btree. | 2182 | * Lookup the entry to change in the btree. |
2183 | */ | 2183 | */ |
2184 | error = xfs_da_node_lookup_int(state, &rval); | 2184 | error = xfs_da3_node_lookup_int(state, &rval); |
2185 | if (error) { | 2185 | if (error) { |
2186 | rval = error; | 2186 | rval = error; |
2187 | } | 2187 | } |
diff --git a/fs/xfs/xfs_trace.c b/fs/xfs/xfs_trace.c index 624bedd81357..b6e3897c1d9f 100644 --- a/fs/xfs/xfs_trace.c +++ b/fs/xfs/xfs_trace.c | |||
@@ -22,7 +22,6 @@ | |||
22 | #include "xfs_trans.h" | 22 | #include "xfs_trans.h" |
23 | #include "xfs_sb.h" | 23 | #include "xfs_sb.h" |
24 | #include "xfs_ag.h" | 24 | #include "xfs_ag.h" |
25 | #include "xfs_da_btree.h" | ||
26 | #include "xfs_bmap_btree.h" | 25 | #include "xfs_bmap_btree.h" |
27 | #include "xfs_alloc_btree.h" | 26 | #include "xfs_alloc_btree.h" |
28 | #include "xfs_ialloc_btree.h" | 27 | #include "xfs_ialloc_btree.h" |
@@ -30,6 +29,7 @@ | |||
30 | #include "xfs_inode.h" | 29 | #include "xfs_inode.h" |
31 | #include "xfs_btree.h" | 30 | #include "xfs_btree.h" |
32 | #include "xfs_mount.h" | 31 | #include "xfs_mount.h" |
32 | #include "xfs_da_btree.h" | ||
33 | #include "xfs_ialloc.h" | 33 | #include "xfs_ialloc.h" |
34 | #include "xfs_itable.h" | 34 | #include "xfs_itable.h" |
35 | #include "xfs_alloc.h" | 35 | #include "xfs_alloc.h" |