diff options
author | Christoph Hellwig <hch@infradead.org> | 2008-10-30 01:56:43 -0400 |
---|---|---|
committer | Lachlan McIlroy <lachlan@sgi.com> | 2008-10-30 01:56:43 -0400 |
commit | 9eaead51bed957af0070a277d945744a76df0c8b (patch) | |
tree | 7b0679186c06f366c7aed30873e3395bd414953e /fs/xfs/xfs_ialloc_btree.c | |
parent | 278d0ca14e889c3932a05d1a68675252a12b3466 (diff) |
[XFS] implement generic xfs_btree_rshift
Make the btree right 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:32196a
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 | 135 |
1 files changed, 2 insertions, 133 deletions
diff --git a/fs/xfs/xfs_ialloc_btree.c b/fs/xfs/xfs_ialloc_btree.c index d080a6833a8d..457f88a76e10 100644 --- a/fs/xfs/xfs_ialloc_btree.c +++ b/fs/xfs/xfs_ialloc_btree.c | |||
@@ -45,7 +45,6 @@ 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 *); | 46 | STATIC int xfs_inobt_lshift(xfs_btree_cur_t *, int, int *); |
47 | STATIC int xfs_inobt_newroot(xfs_btree_cur_t *, int *); | 47 | STATIC int xfs_inobt_newroot(xfs_btree_cur_t *, int *); |
48 | STATIC int xfs_inobt_rshift(xfs_btree_cur_t *, int, int *); | ||
49 | STATIC int xfs_inobt_split(xfs_btree_cur_t *, int, xfs_agblock_t *, | 48 | STATIC int xfs_inobt_split(xfs_btree_cur_t *, int, xfs_agblock_t *, |
50 | xfs_inobt_key_t *, xfs_btree_cur_t **, int *); | 49 | xfs_inobt_key_t *, xfs_btree_cur_t **, int *); |
51 | 50 | ||
@@ -337,7 +336,7 @@ xfs_inobt_delrec( | |||
337 | */ | 336 | */ |
338 | if (be16_to_cpu(left->bb_numrecs) - 1 >= | 337 | if (be16_to_cpu(left->bb_numrecs) - 1 >= |
339 | XFS_INOBT_BLOCK_MINRECS(level, cur)) { | 338 | XFS_INOBT_BLOCK_MINRECS(level, cur)) { |
340 | if ((error = xfs_inobt_rshift(tcur, level, &i))) | 339 | if ((error = xfs_btree_rshift(tcur, level, &i))) |
341 | goto error0; | 340 | goto error0; |
342 | if (i) { | 341 | if (i) { |
343 | ASSERT(be16_to_cpu(block->bb_numrecs) >= | 342 | ASSERT(be16_to_cpu(block->bb_numrecs) >= |
@@ -608,7 +607,7 @@ xfs_inobt_insrec( | |||
608 | /* | 607 | /* |
609 | * First, try shifting an entry to the right neighbor. | 608 | * First, try shifting an entry to the right neighbor. |
610 | */ | 609 | */ |
611 | if ((error = xfs_inobt_rshift(cur, level, &i))) | 610 | if ((error = xfs_btree_rshift(cur, level, &i))) |
612 | return error; | 611 | return error; |
613 | if (i) { | 612 | if (i) { |
614 | /* nothing */ | 613 | /* nothing */ |
@@ -1117,136 +1116,6 @@ xfs_inobt_newroot( | |||
1117 | } | 1116 | } |
1118 | 1117 | ||
1119 | /* | 1118 | /* |
1120 | * Move 1 record right from cur/level if possible. | ||
1121 | * Update cur to reflect the new path. | ||
1122 | */ | ||
1123 | STATIC int /* error */ | ||
1124 | xfs_inobt_rshift( | ||
1125 | xfs_btree_cur_t *cur, /* btree cursor */ | ||
1126 | int level, /* level to shift record on */ | ||
1127 | int *stat) /* success/failure */ | ||
1128 | { | ||
1129 | int error; /* error return value */ | ||
1130 | int i; /* loop index */ | ||
1131 | xfs_inobt_key_t key; /* key value for leaf level upward */ | ||
1132 | xfs_buf_t *lbp; /* buffer for left (current) block */ | ||
1133 | xfs_inobt_block_t *left; /* left (current) btree block */ | ||
1134 | xfs_inobt_key_t *lkp; /* key pointer for left block */ | ||
1135 | xfs_inobt_ptr_t *lpp; /* address pointer for left block */ | ||
1136 | xfs_inobt_rec_t *lrp; /* record pointer for left block */ | ||
1137 | xfs_buf_t *rbp; /* buffer for right neighbor block */ | ||
1138 | xfs_inobt_block_t *right; /* right neighbor btree block */ | ||
1139 | xfs_inobt_key_t *rkp; /* key pointer for right block */ | ||
1140 | xfs_inobt_ptr_t *rpp; /* address pointer for right block */ | ||
1141 | xfs_inobt_rec_t *rrp=NULL; /* record pointer for right block */ | ||
1142 | xfs_btree_cur_t *tcur; /* temporary cursor */ | ||
1143 | |||
1144 | /* | ||
1145 | * Set up variables for this block as "left". | ||
1146 | */ | ||
1147 | lbp = cur->bc_bufs[level]; | ||
1148 | left = XFS_BUF_TO_INOBT_BLOCK(lbp); | ||
1149 | #ifdef DEBUG | ||
1150 | if ((error = xfs_btree_check_sblock(cur, left, level, lbp))) | ||
1151 | return error; | ||
1152 | #endif | ||
1153 | /* | ||
1154 | * If we've got no right sibling then we can't shift an entry right. | ||
1155 | */ | ||
1156 | if (be32_to_cpu(left->bb_rightsib) == NULLAGBLOCK) { | ||
1157 | *stat = 0; | ||
1158 | return 0; | ||
1159 | } | ||
1160 | /* | ||
1161 | * If the cursor entry is the one that would be moved, don't | ||
1162 | * do it... it's too complicated. | ||
1163 | */ | ||
1164 | if (cur->bc_ptrs[level] >= be16_to_cpu(left->bb_numrecs)) { | ||
1165 | *stat = 0; | ||
1166 | return 0; | ||
1167 | } | ||
1168 | /* | ||
1169 | * Set up the right neighbor as "right". | ||
1170 | */ | ||
1171 | if ((error = xfs_btree_read_bufs(cur->bc_mp, cur->bc_tp, | ||
1172 | cur->bc_private.a.agno, be32_to_cpu(left->bb_rightsib), | ||
1173 | 0, &rbp, XFS_INO_BTREE_REF))) | ||
1174 | return error; | ||
1175 | right = XFS_BUF_TO_INOBT_BLOCK(rbp); | ||
1176 | if ((error = xfs_btree_check_sblock(cur, right, level, rbp))) | ||
1177 | return error; | ||
1178 | /* | ||
1179 | * If it's full, it can't take another entry. | ||
1180 | */ | ||
1181 | if (be16_to_cpu(right->bb_numrecs) == XFS_INOBT_BLOCK_MAXRECS(level, cur)) { | ||
1182 | *stat = 0; | ||
1183 | return 0; | ||
1184 | } | ||
1185 | /* | ||
1186 | * Make a hole at the start of the right neighbor block, then | ||
1187 | * copy the last left block entry to the hole. | ||
1188 | */ | ||
1189 | if (level > 0) { | ||
1190 | lkp = XFS_INOBT_KEY_ADDR(left, be16_to_cpu(left->bb_numrecs), cur); | ||
1191 | lpp = XFS_INOBT_PTR_ADDR(left, be16_to_cpu(left->bb_numrecs), cur); | ||
1192 | rkp = XFS_INOBT_KEY_ADDR(right, 1, cur); | ||
1193 | rpp = XFS_INOBT_PTR_ADDR(right, 1, cur); | ||
1194 | #ifdef DEBUG | ||
1195 | for (i = be16_to_cpu(right->bb_numrecs) - 1; i >= 0; i--) { | ||
1196 | if ((error = xfs_btree_check_sptr(cur, be32_to_cpu(rpp[i]), level))) | ||
1197 | return error; | ||
1198 | } | ||
1199 | #endif | ||
1200 | memmove(rkp + 1, rkp, be16_to_cpu(right->bb_numrecs) * sizeof(*rkp)); | ||
1201 | memmove(rpp + 1, rpp, be16_to_cpu(right->bb_numrecs) * sizeof(*rpp)); | ||
1202 | #ifdef DEBUG | ||
1203 | if ((error = xfs_btree_check_sptr(cur, be32_to_cpu(*lpp), level))) | ||
1204 | return error; | ||
1205 | #endif | ||
1206 | *rkp = *lkp; | ||
1207 | *rpp = *lpp; | ||
1208 | xfs_inobt_log_keys(cur, rbp, 1, be16_to_cpu(right->bb_numrecs) + 1); | ||
1209 | xfs_inobt_log_ptrs(cur, rbp, 1, be16_to_cpu(right->bb_numrecs) + 1); | ||
1210 | } else { | ||
1211 | lrp = XFS_INOBT_REC_ADDR(left, be16_to_cpu(left->bb_numrecs), cur); | ||
1212 | rrp = XFS_INOBT_REC_ADDR(right, 1, cur); | ||
1213 | memmove(rrp + 1, rrp, be16_to_cpu(right->bb_numrecs) * sizeof(*rrp)); | ||
1214 | *rrp = *lrp; | ||
1215 | xfs_inobt_log_recs(cur, rbp, 1, be16_to_cpu(right->bb_numrecs) + 1); | ||
1216 | key.ir_startino = rrp->ir_startino; | ||
1217 | rkp = &key; | ||
1218 | } | ||
1219 | /* | ||
1220 | * Decrement and log left's numrecs, bump and log right's numrecs. | ||
1221 | */ | ||
1222 | be16_add_cpu(&left->bb_numrecs, -1); | ||
1223 | xfs_inobt_log_block(cur->bc_tp, lbp, XFS_BB_NUMRECS); | ||
1224 | be16_add_cpu(&right->bb_numrecs, 1); | ||
1225 | #ifdef DEBUG | ||
1226 | if (level > 0) | ||
1227 | xfs_btree_check_key(cur->bc_btnum, rkp, rkp + 1); | ||
1228 | else | ||
1229 | xfs_btree_check_rec(cur->bc_btnum, rrp, rrp + 1); | ||
1230 | #endif | ||
1231 | xfs_inobt_log_block(cur->bc_tp, rbp, XFS_BB_NUMRECS); | ||
1232 | /* | ||
1233 | * Using a temporary cursor, update the parent key values of the | ||
1234 | * block on the right. | ||
1235 | */ | ||
1236 | if ((error = xfs_btree_dup_cursor(cur, &tcur))) | ||
1237 | return error; | ||
1238 | xfs_btree_lastrec(tcur, level); | ||
1239 | if ((error = xfs_btree_increment(tcur, level, &i)) || | ||
1240 | (error = xfs_btree_updkey(tcur, (union xfs_btree_key *)rkp, level + 1))) { | ||
1241 | xfs_btree_del_cursor(tcur, XFS_BTREE_ERROR); | ||
1242 | return error; | ||
1243 | } | ||
1244 | xfs_btree_del_cursor(tcur, XFS_BTREE_NOERROR); | ||
1245 | *stat = 1; | ||
1246 | return 0; | ||
1247 | } | ||
1248 | |||
1249 | /* | ||
1250 | * Split cur/level block in half. | 1119 | * Split cur/level block in half. |
1251 | * Return new block number and its first record (to be inserted into parent). | 1120 | * Return new block number and its first record (to be inserted into parent). |
1252 | */ | 1121 | */ |