diff options
author | Christoph Hellwig <hch@infradead.org> | 2008-10-30 01:56:53 -0400 |
---|---|---|
committer | Lachlan McIlroy <lachlan@sgi.com> | 2008-10-30 01:56:53 -0400 |
commit | 687b890a184fef263ebb773926e1f4aa69240d01 (patch) | |
tree | b8f80c134ff994927225367d148ee63f4d76506b /fs/xfs/xfs_ialloc_btree.c | |
parent | 9eaead51bed957af0070a277d945744a76df0c8b (diff) |
[XFS] implement generic xfs_btree_lshift
Make the btree left shift code generic. Based on a patch from David
Chinner with lots of changes to follow the original btree implementations
more closely. While this loses some of the generic helper routines for
inserting/moving/removing records it also solves some of the one off bugs
in the original code and makes it easier to verify.
SGI-PV: 985583
SGI-Modid: xfs-linux-melb:xfs-kern:32197a
Signed-off-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Lachlan McIlroy <lachlan@sgi.com>
Signed-off-by: Bill O'Donnell <billodo@sgi.com>
Signed-off-by: David Chinner <david@fromorbit.com>
Diffstat (limited to 'fs/xfs/xfs_ialloc_btree.c')
-rw-r--r-- | fs/xfs/xfs_ialloc_btree.c | 147 |
1 files changed, 2 insertions, 145 deletions
diff --git a/fs/xfs/xfs_ialloc_btree.c b/fs/xfs/xfs_ialloc_btree.c index 457f88a76e10..60f5db5d6dfa 100644 --- a/fs/xfs/xfs_ialloc_btree.c +++ b/fs/xfs/xfs_ialloc_btree.c | |||
@@ -43,7 +43,6 @@ STATIC void xfs_inobt_log_block(xfs_trans_t *, xfs_buf_t *, int); | |||
43 | STATIC void xfs_inobt_log_keys(xfs_btree_cur_t *, xfs_buf_t *, int, int); | 43 | STATIC void xfs_inobt_log_keys(xfs_btree_cur_t *, xfs_buf_t *, int, int); |
44 | STATIC void xfs_inobt_log_ptrs(xfs_btree_cur_t *, xfs_buf_t *, int, int); | 44 | STATIC void xfs_inobt_log_ptrs(xfs_btree_cur_t *, xfs_buf_t *, int, int); |
45 | STATIC void xfs_inobt_log_recs(xfs_btree_cur_t *, xfs_buf_t *, int, int); | 45 | STATIC void xfs_inobt_log_recs(xfs_btree_cur_t *, xfs_buf_t *, int, int); |
46 | STATIC int xfs_inobt_lshift(xfs_btree_cur_t *, int, int *); | ||
47 | STATIC int xfs_inobt_newroot(xfs_btree_cur_t *, int *); | 46 | STATIC int xfs_inobt_newroot(xfs_btree_cur_t *, int *); |
48 | STATIC int xfs_inobt_split(xfs_btree_cur_t *, int, xfs_agblock_t *, | 47 | STATIC int xfs_inobt_split(xfs_btree_cur_t *, int, xfs_agblock_t *, |
49 | xfs_inobt_key_t *, xfs_btree_cur_t **, int *); | 48 | xfs_inobt_key_t *, xfs_btree_cur_t **, int *); |
@@ -276,7 +275,7 @@ xfs_inobt_delrec( | |||
276 | */ | 275 | */ |
277 | if (be16_to_cpu(right->bb_numrecs) - 1 >= | 276 | if (be16_to_cpu(right->bb_numrecs) - 1 >= |
278 | XFS_INOBT_BLOCK_MINRECS(level, cur)) { | 277 | XFS_INOBT_BLOCK_MINRECS(level, cur)) { |
279 | if ((error = xfs_inobt_lshift(tcur, level, &i))) | 278 | if ((error = xfs_btree_lshift(tcur, level, &i))) |
280 | goto error0; | 279 | goto error0; |
281 | if (i) { | 280 | if (i) { |
282 | ASSERT(be16_to_cpu(block->bb_numrecs) >= | 281 | ASSERT(be16_to_cpu(block->bb_numrecs) >= |
@@ -616,7 +615,7 @@ xfs_inobt_insrec( | |||
616 | * Next, try shifting an entry to the left neighbor. | 615 | * Next, try shifting an entry to the left neighbor. |
617 | */ | 616 | */ |
618 | else { | 617 | else { |
619 | if ((error = xfs_inobt_lshift(cur, level, &i))) | 618 | if ((error = xfs_btree_lshift(cur, level, &i))) |
620 | return error; | 619 | return error; |
621 | if (i) { | 620 | if (i) { |
622 | optr = ptr = cur->bc_ptrs[level]; | 621 | optr = ptr = cur->bc_ptrs[level]; |
@@ -827,148 +826,6 @@ xfs_inobt_log_recs( | |||
827 | } | 826 | } |
828 | 827 | ||
829 | /* | 828 | /* |
830 | * Move 1 record left from cur/level if possible. | ||
831 | * Update cur to reflect the new path. | ||
832 | */ | ||
833 | STATIC int /* error */ | ||
834 | xfs_inobt_lshift( | ||
835 | xfs_btree_cur_t *cur, /* btree cursor */ | ||
836 | int level, /* level to shift record on */ | ||
837 | int *stat) /* success/failure */ | ||
838 | { | ||
839 | int error; /* error return value */ | ||
840 | #ifdef DEBUG | ||
841 | int i; /* loop index */ | ||
842 | #endif | ||
843 | xfs_inobt_key_t key; /* key value for leaf level upward */ | ||
844 | xfs_buf_t *lbp; /* buffer for left neighbor block */ | ||
845 | xfs_inobt_block_t *left; /* left neighbor btree block */ | ||
846 | xfs_inobt_key_t *lkp=NULL; /* key pointer for left block */ | ||
847 | xfs_inobt_ptr_t *lpp; /* address pointer for left block */ | ||
848 | xfs_inobt_rec_t *lrp=NULL; /* record pointer for left block */ | ||
849 | int nrec; /* new number of left block entries */ | ||
850 | xfs_buf_t *rbp; /* buffer for right (current) block */ | ||
851 | xfs_inobt_block_t *right; /* right (current) btree block */ | ||
852 | xfs_inobt_key_t *rkp=NULL; /* key pointer for right block */ | ||
853 | xfs_inobt_ptr_t *rpp=NULL; /* address pointer for right block */ | ||
854 | xfs_inobt_rec_t *rrp=NULL; /* record pointer for right block */ | ||
855 | |||
856 | /* | ||
857 | * Set up variables for this block as "right". | ||
858 | */ | ||
859 | rbp = cur->bc_bufs[level]; | ||
860 | right = XFS_BUF_TO_INOBT_BLOCK(rbp); | ||
861 | #ifdef DEBUG | ||
862 | if ((error = xfs_btree_check_sblock(cur, right, level, rbp))) | ||
863 | return error; | ||
864 | #endif | ||
865 | /* | ||
866 | * If we've got no left sibling then we can't shift an entry left. | ||
867 | */ | ||
868 | if (be32_to_cpu(right->bb_leftsib) == NULLAGBLOCK) { | ||
869 | *stat = 0; | ||
870 | return 0; | ||
871 | } | ||
872 | /* | ||
873 | * If the cursor entry is the one that would be moved, don't | ||
874 | * do it... it's too complicated. | ||
875 | */ | ||
876 | if (cur->bc_ptrs[level] <= 1) { | ||
877 | *stat = 0; | ||
878 | return 0; | ||
879 | } | ||
880 | /* | ||
881 | * Set up the left neighbor as "left". | ||
882 | */ | ||
883 | if ((error = xfs_btree_read_bufs(cur->bc_mp, cur->bc_tp, | ||
884 | cur->bc_private.a.agno, be32_to_cpu(right->bb_leftsib), | ||
885 | 0, &lbp, XFS_INO_BTREE_REF))) | ||
886 | return error; | ||
887 | left = XFS_BUF_TO_INOBT_BLOCK(lbp); | ||
888 | if ((error = xfs_btree_check_sblock(cur, left, level, lbp))) | ||
889 | return error; | ||
890 | /* | ||
891 | * If it's full, it can't take another entry. | ||
892 | */ | ||
893 | if (be16_to_cpu(left->bb_numrecs) == XFS_INOBT_BLOCK_MAXRECS(level, cur)) { | ||
894 | *stat = 0; | ||
895 | return 0; | ||
896 | } | ||
897 | nrec = be16_to_cpu(left->bb_numrecs) + 1; | ||
898 | /* | ||
899 | * If non-leaf, copy a key and a ptr to the left block. | ||
900 | */ | ||
901 | if (level > 0) { | ||
902 | lkp = XFS_INOBT_KEY_ADDR(left, nrec, cur); | ||
903 | rkp = XFS_INOBT_KEY_ADDR(right, 1, cur); | ||
904 | *lkp = *rkp; | ||
905 | xfs_inobt_log_keys(cur, lbp, nrec, nrec); | ||
906 | lpp = XFS_INOBT_PTR_ADDR(left, nrec, cur); | ||
907 | rpp = XFS_INOBT_PTR_ADDR(right, 1, cur); | ||
908 | #ifdef DEBUG | ||
909 | if ((error = xfs_btree_check_sptr(cur, be32_to_cpu(*rpp), level))) | ||
910 | return error; | ||
911 | #endif | ||
912 | *lpp = *rpp; | ||
913 | xfs_inobt_log_ptrs(cur, lbp, nrec, nrec); | ||
914 | } | ||
915 | /* | ||
916 | * If leaf, copy a record to the left block. | ||
917 | */ | ||
918 | else { | ||
919 | lrp = XFS_INOBT_REC_ADDR(left, nrec, cur); | ||
920 | rrp = XFS_INOBT_REC_ADDR(right, 1, cur); | ||
921 | *lrp = *rrp; | ||
922 | xfs_inobt_log_recs(cur, lbp, nrec, nrec); | ||
923 | } | ||
924 | /* | ||
925 | * Bump and log left's numrecs, decrement and log right's numrecs. | ||
926 | */ | ||
927 | be16_add_cpu(&left->bb_numrecs, 1); | ||
928 | xfs_inobt_log_block(cur->bc_tp, lbp, XFS_BB_NUMRECS); | ||
929 | #ifdef DEBUG | ||
930 | if (level > 0) | ||
931 | xfs_btree_check_key(cur->bc_btnum, lkp - 1, lkp); | ||
932 | else | ||
933 | xfs_btree_check_rec(cur->bc_btnum, lrp - 1, lrp); | ||
934 | #endif | ||
935 | be16_add_cpu(&right->bb_numrecs, -1); | ||
936 | xfs_inobt_log_block(cur->bc_tp, rbp, XFS_BB_NUMRECS); | ||
937 | /* | ||
938 | * Slide the contents of right down one entry. | ||
939 | */ | ||
940 | if (level > 0) { | ||
941 | #ifdef DEBUG | ||
942 | for (i = 0; i < be16_to_cpu(right->bb_numrecs); i++) { | ||
943 | if ((error = xfs_btree_check_sptr(cur, be32_to_cpu(rpp[i + 1]), | ||
944 | level))) | ||
945 | return error; | ||
946 | } | ||
947 | #endif | ||
948 | memmove(rkp, rkp + 1, be16_to_cpu(right->bb_numrecs) * sizeof(*rkp)); | ||
949 | memmove(rpp, rpp + 1, be16_to_cpu(right->bb_numrecs) * sizeof(*rpp)); | ||
950 | xfs_inobt_log_keys(cur, rbp, 1, be16_to_cpu(right->bb_numrecs)); | ||
951 | xfs_inobt_log_ptrs(cur, rbp, 1, be16_to_cpu(right->bb_numrecs)); | ||
952 | } else { | ||
953 | memmove(rrp, rrp + 1, be16_to_cpu(right->bb_numrecs) * sizeof(*rrp)); | ||
954 | xfs_inobt_log_recs(cur, rbp, 1, be16_to_cpu(right->bb_numrecs)); | ||
955 | key.ir_startino = rrp->ir_startino; | ||
956 | rkp = &key; | ||
957 | } | ||
958 | /* | ||
959 | * Update the parent key values of right. | ||
960 | */ | ||
961 | if ((error = xfs_btree_updkey(cur, (union xfs_btree_key *)rkp, level + 1))) | ||
962 | return error; | ||
963 | /* | ||
964 | * Slide the cursor value left one. | ||
965 | */ | ||
966 | cur->bc_ptrs[level]--; | ||
967 | *stat = 1; | ||
968 | return 0; | ||
969 | } | ||
970 | |||
971 | /* | ||
972 | * Allocate a new root block, fill it in. | 829 | * Allocate a new root block, fill it in. |
973 | */ | 830 | */ |
974 | STATIC int /* error */ | 831 | STATIC int /* error */ |