提交 91d87232 编写于 作者: E Eric Sandeen 提交者: Tim Shimmin

[XFS] Reduce endian flipping in alloc_btree, same as was done for

ialloc_btree.

SGI-PV: 955302
SGI-Modid: xfs-linux-melb:xfs-kern:26910a
Signed-off-by: NEric Sandeen <sandeen@sandeen.net>
Signed-off-by: NNathan Scott <nathans@sgi.com>
Signed-off-by: NTim Shimmin <tes@sgi.com>
上级 edcd4bce
...@@ -92,6 +92,7 @@ xfs_alloc_delrec( ...@@ -92,6 +92,7 @@ xfs_alloc_delrec(
xfs_alloc_key_t *rkp; /* right block key pointer */ xfs_alloc_key_t *rkp; /* right block key pointer */
xfs_alloc_ptr_t *rpp; /* right block address pointer */ xfs_alloc_ptr_t *rpp; /* right block address pointer */
int rrecs=0; /* number of records in right block */ int rrecs=0; /* number of records in right block */
int numrecs;
xfs_alloc_rec_t *rrp; /* right block record pointer */ xfs_alloc_rec_t *rrp; /* right block record pointer */
xfs_btree_cur_t *tcur; /* temporary btree cursor */ xfs_btree_cur_t *tcur; /* temporary btree cursor */
...@@ -115,7 +116,8 @@ xfs_alloc_delrec( ...@@ -115,7 +116,8 @@ xfs_alloc_delrec(
/* /*
* Fail if we're off the end of the block. * Fail if we're off the end of the block.
*/ */
if (ptr > be16_to_cpu(block->bb_numrecs)) { numrecs = be16_to_cpu(block->bb_numrecs);
if (ptr > numrecs) {
*stat = 0; *stat = 0;
return 0; return 0;
} }
...@@ -129,18 +131,18 @@ xfs_alloc_delrec( ...@@ -129,18 +131,18 @@ xfs_alloc_delrec(
lkp = XFS_ALLOC_KEY_ADDR(block, 1, cur); lkp = XFS_ALLOC_KEY_ADDR(block, 1, cur);
lpp = XFS_ALLOC_PTR_ADDR(block, 1, cur); lpp = XFS_ALLOC_PTR_ADDR(block, 1, cur);
#ifdef DEBUG #ifdef DEBUG
for (i = ptr; i < be16_to_cpu(block->bb_numrecs); i++) { for (i = ptr; i < numrecs; i++) {
if ((error = xfs_btree_check_sptr(cur, be32_to_cpu(lpp[i]), level))) if ((error = xfs_btree_check_sptr(cur, be32_to_cpu(lpp[i]), level)))
return error; return error;
} }
#endif #endif
if (ptr < be16_to_cpu(block->bb_numrecs)) { if (ptr < numrecs) {
memmove(&lkp[ptr - 1], &lkp[ptr], memmove(&lkp[ptr - 1], &lkp[ptr],
(be16_to_cpu(block->bb_numrecs) - ptr) * sizeof(*lkp)); (numrecs - ptr) * sizeof(*lkp));
memmove(&lpp[ptr - 1], &lpp[ptr], memmove(&lpp[ptr - 1], &lpp[ptr],
(be16_to_cpu(block->bb_numrecs) - ptr) * sizeof(*lpp)); (numrecs - ptr) * sizeof(*lpp));
xfs_alloc_log_ptrs(cur, bp, ptr, be16_to_cpu(block->bb_numrecs) - 1); xfs_alloc_log_ptrs(cur, bp, ptr, numrecs - 1);
xfs_alloc_log_keys(cur, bp, ptr, be16_to_cpu(block->bb_numrecs) - 1); xfs_alloc_log_keys(cur, bp, ptr, numrecs - 1);
} }
} }
/* /*
...@@ -149,10 +151,10 @@ xfs_alloc_delrec( ...@@ -149,10 +151,10 @@ xfs_alloc_delrec(
*/ */
else { else {
lrp = XFS_ALLOC_REC_ADDR(block, 1, cur); lrp = XFS_ALLOC_REC_ADDR(block, 1, cur);
if (ptr < be16_to_cpu(block->bb_numrecs)) { if (ptr < numrecs) {
memmove(&lrp[ptr - 1], &lrp[ptr], memmove(&lrp[ptr - 1], &lrp[ptr],
(be16_to_cpu(block->bb_numrecs) - ptr) * sizeof(*lrp)); (numrecs - ptr) * sizeof(*lrp));
xfs_alloc_log_recs(cur, bp, ptr, be16_to_cpu(block->bb_numrecs) - 1); xfs_alloc_log_recs(cur, bp, ptr, numrecs - 1);
} }
/* /*
* If it's the first record in the block, we'll need a key * If it's the first record in the block, we'll need a key
...@@ -167,7 +169,8 @@ xfs_alloc_delrec( ...@@ -167,7 +169,8 @@ xfs_alloc_delrec(
/* /*
* Decrement and log the number of entries in the block. * Decrement and log the number of entries in the block.
*/ */
be16_add(&block->bb_numrecs, -1); numrecs--;
block->bb_numrecs = cpu_to_be16(numrecs);
xfs_alloc_log_block(cur->bc_tp, bp, XFS_BB_NUMRECS); xfs_alloc_log_block(cur->bc_tp, bp, XFS_BB_NUMRECS);
/* /*
* See if the longest free extent in the allocation group was * See if the longest free extent in the allocation group was
...@@ -181,14 +184,14 @@ xfs_alloc_delrec( ...@@ -181,14 +184,14 @@ xfs_alloc_delrec(
if (level == 0 && if (level == 0 &&
cur->bc_btnum == XFS_BTNUM_CNT && cur->bc_btnum == XFS_BTNUM_CNT &&
be32_to_cpu(block->bb_rightsib) == NULLAGBLOCK && be32_to_cpu(block->bb_rightsib) == NULLAGBLOCK &&
ptr > be16_to_cpu(block->bb_numrecs)) { ptr > numrecs) {
ASSERT(ptr == be16_to_cpu(block->bb_numrecs) + 1); ASSERT(ptr == numrecs + 1);
/* /*
* There are still records in the block. Grab the size * There are still records in the block. Grab the size
* from the last one. * from the last one.
*/ */
if (be16_to_cpu(block->bb_numrecs)) { if (numrecs) {
rrp = XFS_ALLOC_REC_ADDR(block, be16_to_cpu(block->bb_numrecs), cur); rrp = XFS_ALLOC_REC_ADDR(block, numrecs, cur);
agf->agf_longest = rrp->ar_blockcount; agf->agf_longest = rrp->ar_blockcount;
} }
/* /*
...@@ -211,7 +214,7 @@ xfs_alloc_delrec( ...@@ -211,7 +214,7 @@ xfs_alloc_delrec(
* and it's NOT the leaf level, * and it's NOT the leaf level,
* then we can get rid of this level. * then we can get rid of this level.
*/ */
if (be16_to_cpu(block->bb_numrecs) == 1 && level > 0) { if (numrecs == 1 && level > 0) {
/* /*
* lpp is still set to the first pointer in the block. * lpp is still set to the first pointer in the block.
* Make it the new root of the btree. * Make it the new root of the btree.
...@@ -267,7 +270,7 @@ xfs_alloc_delrec( ...@@ -267,7 +270,7 @@ xfs_alloc_delrec(
* If the number of records remaining in the block is at least * If the number of records remaining in the block is at least
* the minimum, we're done. * the minimum, we're done.
*/ */
if (be16_to_cpu(block->bb_numrecs) >= XFS_ALLOC_BLOCK_MINRECS(level, cur)) { if (numrecs >= XFS_ALLOC_BLOCK_MINRECS(level, cur)) {
if (level > 0 && (error = xfs_alloc_decrement(cur, level, &i))) if (level > 0 && (error = xfs_alloc_decrement(cur, level, &i)))
return error; return error;
*stat = 1; *stat = 1;
...@@ -419,19 +422,21 @@ xfs_alloc_delrec( ...@@ -419,19 +422,21 @@ xfs_alloc_delrec(
* See if we can join with the left neighbor block. * See if we can join with the left neighbor block.
*/ */
if (lbno != NULLAGBLOCK && if (lbno != NULLAGBLOCK &&
lrecs + be16_to_cpu(block->bb_numrecs) <= XFS_ALLOC_BLOCK_MAXRECS(level, cur)) { lrecs + numrecs <= XFS_ALLOC_BLOCK_MAXRECS(level, cur)) {
/* /*
* Set "right" to be the starting block, * Set "right" to be the starting block,
* "left" to be the left neighbor. * "left" to be the left neighbor.
*/ */
rbno = bno; rbno = bno;
right = block; right = block;
rrecs = be16_to_cpu(right->bb_numrecs);
rbp = bp; rbp = bp;
if ((error = xfs_btree_read_bufs(mp, cur->bc_tp, if ((error = xfs_btree_read_bufs(mp, cur->bc_tp,
cur->bc_private.a.agno, lbno, 0, &lbp, cur->bc_private.a.agno, lbno, 0, &lbp,
XFS_ALLOC_BTREE_REF))) XFS_ALLOC_BTREE_REF)))
return error; return error;
left = XFS_BUF_TO_ALLOC_BLOCK(lbp); left = XFS_BUF_TO_ALLOC_BLOCK(lbp);
lrecs = be16_to_cpu(left->bb_numrecs);
if ((error = xfs_btree_check_sblock(cur, left, level, lbp))) if ((error = xfs_btree_check_sblock(cur, left, level, lbp)))
return error; return error;
} }
...@@ -439,20 +444,21 @@ xfs_alloc_delrec( ...@@ -439,20 +444,21 @@ xfs_alloc_delrec(
* If that won't work, see if we can join with the right neighbor block. * If that won't work, see if we can join with the right neighbor block.
*/ */
else if (rbno != NULLAGBLOCK && else if (rbno != NULLAGBLOCK &&
rrecs + be16_to_cpu(block->bb_numrecs) <= rrecs + numrecs <= XFS_ALLOC_BLOCK_MAXRECS(level, cur)) {
XFS_ALLOC_BLOCK_MAXRECS(level, cur)) {
/* /*
* Set "left" to be the starting block, * Set "left" to be the starting block,
* "right" to be the right neighbor. * "right" to be the right neighbor.
*/ */
lbno = bno; lbno = bno;
left = block; left = block;
lrecs = be16_to_cpu(left->bb_numrecs);
lbp = bp; lbp = bp;
if ((error = xfs_btree_read_bufs(mp, cur->bc_tp, if ((error = xfs_btree_read_bufs(mp, cur->bc_tp,
cur->bc_private.a.agno, rbno, 0, &rbp, cur->bc_private.a.agno, rbno, 0, &rbp,
XFS_ALLOC_BTREE_REF))) XFS_ALLOC_BTREE_REF)))
return error; return error;
right = XFS_BUF_TO_ALLOC_BLOCK(rbp); right = XFS_BUF_TO_ALLOC_BLOCK(rbp);
rrecs = be16_to_cpu(right->bb_numrecs);
if ((error = xfs_btree_check_sblock(cur, right, level, rbp))) if ((error = xfs_btree_check_sblock(cur, right, level, rbp)))
return error; return error;
} }
...@@ -474,34 +480,28 @@ xfs_alloc_delrec( ...@@ -474,34 +480,28 @@ xfs_alloc_delrec(
/* /*
* It's a non-leaf. Move keys and pointers. * It's a non-leaf. Move keys and pointers.
*/ */
lkp = XFS_ALLOC_KEY_ADDR(left, be16_to_cpu(left->bb_numrecs) + 1, cur); lkp = XFS_ALLOC_KEY_ADDR(left, lrecs + 1, cur);
lpp = XFS_ALLOC_PTR_ADDR(left, be16_to_cpu(left->bb_numrecs) + 1, cur); lpp = XFS_ALLOC_PTR_ADDR(left, lrecs + 1, cur);
rkp = XFS_ALLOC_KEY_ADDR(right, 1, cur); rkp = XFS_ALLOC_KEY_ADDR(right, 1, cur);
rpp = XFS_ALLOC_PTR_ADDR(right, 1, cur); rpp = XFS_ALLOC_PTR_ADDR(right, 1, cur);
#ifdef DEBUG #ifdef DEBUG
for (i = 0; i < be16_to_cpu(right->bb_numrecs); i++) { for (i = 0; i < rrecs; i++) {
if ((error = xfs_btree_check_sptr(cur, be32_to_cpu(rpp[i]), level))) if ((error = xfs_btree_check_sptr(cur, be32_to_cpu(rpp[i]), level)))
return error; return error;
} }
#endif #endif
memcpy(lkp, rkp, be16_to_cpu(right->bb_numrecs) * sizeof(*lkp)); memcpy(lkp, rkp, rrecs * sizeof(*lkp));
memcpy(lpp, rpp, be16_to_cpu(right->bb_numrecs) * sizeof(*lpp)); memcpy(lpp, rpp, rrecs * sizeof(*lpp));
xfs_alloc_log_keys(cur, lbp, be16_to_cpu(left->bb_numrecs) + 1, xfs_alloc_log_keys(cur, lbp, lrecs + 1, lrecs + rrecs);
be16_to_cpu(left->bb_numrecs) + xfs_alloc_log_ptrs(cur, lbp, lrecs + 1, lrecs + rrecs);
be16_to_cpu(right->bb_numrecs));
xfs_alloc_log_ptrs(cur, lbp, be16_to_cpu(left->bb_numrecs) + 1,
be16_to_cpu(left->bb_numrecs) +
be16_to_cpu(right->bb_numrecs));
} else { } else {
/* /*
* It's a leaf. Move records. * It's a leaf. Move records.
*/ */
lrp = XFS_ALLOC_REC_ADDR(left, be16_to_cpu(left->bb_numrecs) + 1, cur); lrp = XFS_ALLOC_REC_ADDR(left, lrecs + 1, cur);
rrp = XFS_ALLOC_REC_ADDR(right, 1, cur); rrp = XFS_ALLOC_REC_ADDR(right, 1, cur);
memcpy(lrp, rrp, be16_to_cpu(right->bb_numrecs) * sizeof(*lrp)); memcpy(lrp, rrp, rrecs * sizeof(*lrp));
xfs_alloc_log_recs(cur, lbp, be16_to_cpu(left->bb_numrecs) + 1, xfs_alloc_log_recs(cur, lbp, lrecs + 1, lrecs + rrecs);
be16_to_cpu(left->bb_numrecs) +
be16_to_cpu(right->bb_numrecs));
} }
/* /*
* If we joined with the left neighbor, set the buffer in the * If we joined with the left neighbor, set the buffer in the
...@@ -509,7 +509,7 @@ xfs_alloc_delrec( ...@@ -509,7 +509,7 @@ xfs_alloc_delrec(
*/ */
if (bp != lbp) { if (bp != lbp) {
xfs_btree_setbuf(cur, level, lbp); xfs_btree_setbuf(cur, level, lbp);
cur->bc_ptrs[level] += be16_to_cpu(left->bb_numrecs); cur->bc_ptrs[level] += lrecs;
} }
/* /*
* If we joined with the right neighbor and there's a level above * If we joined with the right neighbor and there's a level above
...@@ -521,7 +521,8 @@ xfs_alloc_delrec( ...@@ -521,7 +521,8 @@ xfs_alloc_delrec(
/* /*
* Fix up the number of records in the surviving block. * Fix up the number of records in the surviving block.
*/ */
be16_add(&left->bb_numrecs, be16_to_cpu(right->bb_numrecs)); lrecs += rrecs;
left->bb_numrecs = cpu_to_be16(lrecs);
/* /*
* Fix up the right block pointer in the surviving block, and log it. * Fix up the right block pointer in the surviving block, and log it.
*/ */
...@@ -608,6 +609,7 @@ xfs_alloc_insrec( ...@@ -608,6 +609,7 @@ xfs_alloc_insrec(
xfs_btree_cur_t *ncur; /* new cursor to be used at next lvl */ xfs_btree_cur_t *ncur; /* new cursor to be used at next lvl */
xfs_alloc_key_t nkey; /* new key value, from split */ xfs_alloc_key_t nkey; /* new key value, from split */
xfs_alloc_rec_t nrec; /* new record value, for caller */ xfs_alloc_rec_t nrec; /* new record value, for caller */
int numrecs;
int optr; /* old ptr value */ int optr; /* old ptr value */
xfs_alloc_ptr_t *pp; /* pointer to btree addresses */ xfs_alloc_ptr_t *pp; /* pointer to btree addresses */
int ptr; /* index in btree block for this rec */ int ptr; /* index in btree block for this rec */
...@@ -653,13 +655,14 @@ xfs_alloc_insrec( ...@@ -653,13 +655,14 @@ xfs_alloc_insrec(
*/ */
bp = cur->bc_bufs[level]; bp = cur->bc_bufs[level];
block = XFS_BUF_TO_ALLOC_BLOCK(bp); block = XFS_BUF_TO_ALLOC_BLOCK(bp);
numrecs = be16_to_cpu(block->bb_numrecs);
#ifdef DEBUG #ifdef DEBUG
if ((error = xfs_btree_check_sblock(cur, block, level, bp))) if ((error = xfs_btree_check_sblock(cur, block, level, bp)))
return error; return error;
/* /*
* Check that the new entry is being inserted in the right place. * Check that the new entry is being inserted in the right place.
*/ */
if (ptr <= be16_to_cpu(block->bb_numrecs)) { if (ptr <= numrecs) {
if (level == 0) { if (level == 0) {
rp = XFS_ALLOC_REC_ADDR(block, ptr, cur); rp = XFS_ALLOC_REC_ADDR(block, ptr, cur);
xfs_btree_check_rec(cur->bc_btnum, recp, rp); xfs_btree_check_rec(cur->bc_btnum, recp, rp);
...@@ -675,7 +678,7 @@ xfs_alloc_insrec( ...@@ -675,7 +678,7 @@ xfs_alloc_insrec(
* If the block is full, we can't insert the new entry until we * If the block is full, we can't insert the new entry until we
* make the block un-full. * make the block un-full.
*/ */
if (be16_to_cpu(block->bb_numrecs) == XFS_ALLOC_BLOCK_MAXRECS(level, cur)) { if (numrecs == XFS_ALLOC_BLOCK_MAXRECS(level, cur)) {
/* /*
* First, try shifting an entry to the right neighbor. * First, try shifting an entry to the right neighbor.
*/ */
...@@ -729,6 +732,7 @@ xfs_alloc_insrec( ...@@ -729,6 +732,7 @@ xfs_alloc_insrec(
* At this point we know there's room for our new entry in the block * At this point we know there's room for our new entry in the block
* we're pointing at. * we're pointing at.
*/ */
numrecs = be16_to_cpu(block->bb_numrecs);
if (level > 0) { if (level > 0) {
/* /*
* It's a non-leaf entry. Make a hole for the new data * It's a non-leaf entry. Make a hole for the new data
...@@ -737,15 +741,15 @@ xfs_alloc_insrec( ...@@ -737,15 +741,15 @@ xfs_alloc_insrec(
kp = XFS_ALLOC_KEY_ADDR(block, 1, cur); kp = XFS_ALLOC_KEY_ADDR(block, 1, cur);
pp = XFS_ALLOC_PTR_ADDR(block, 1, cur); pp = XFS_ALLOC_PTR_ADDR(block, 1, cur);
#ifdef DEBUG #ifdef DEBUG
for (i = be16_to_cpu(block->bb_numrecs); i >= ptr; i--) { for (i = numrecs; i >= ptr; i--) {
if ((error = xfs_btree_check_sptr(cur, be32_to_cpu(pp[i - 1]), level))) if ((error = xfs_btree_check_sptr(cur, be32_to_cpu(pp[i - 1]), level)))
return error; return error;
} }
#endif #endif
memmove(&kp[ptr], &kp[ptr - 1], memmove(&kp[ptr], &kp[ptr - 1],
(be16_to_cpu(block->bb_numrecs) - ptr + 1) * sizeof(*kp)); (numrecs - ptr + 1) * sizeof(*kp));
memmove(&pp[ptr], &pp[ptr - 1], memmove(&pp[ptr], &pp[ptr - 1],
(be16_to_cpu(block->bb_numrecs) - ptr + 1) * sizeof(*pp)); (numrecs - ptr + 1) * sizeof(*pp));
#ifdef DEBUG #ifdef DEBUG
if ((error = xfs_btree_check_sptr(cur, *bnop, level))) if ((error = xfs_btree_check_sptr(cur, *bnop, level)))
return error; return error;
...@@ -755,11 +759,12 @@ xfs_alloc_insrec( ...@@ -755,11 +759,12 @@ xfs_alloc_insrec(
*/ */
kp[ptr - 1] = key; kp[ptr - 1] = key;
pp[ptr - 1] = cpu_to_be32(*bnop); pp[ptr - 1] = cpu_to_be32(*bnop);
be16_add(&block->bb_numrecs, 1); numrecs++;
xfs_alloc_log_keys(cur, bp, ptr, be16_to_cpu(block->bb_numrecs)); block->bb_numrecs = cpu_to_be16(numrecs);
xfs_alloc_log_ptrs(cur, bp, ptr, be16_to_cpu(block->bb_numrecs)); xfs_alloc_log_keys(cur, bp, ptr, numrecs);
xfs_alloc_log_ptrs(cur, bp, ptr, numrecs);
#ifdef DEBUG #ifdef DEBUG
if (ptr < be16_to_cpu(block->bb_numrecs)) if (ptr < numrecs)
xfs_btree_check_key(cur->bc_btnum, kp + ptr - 1, xfs_btree_check_key(cur->bc_btnum, kp + ptr - 1,
kp + ptr); kp + ptr);
#endif #endif
...@@ -769,16 +774,17 @@ xfs_alloc_insrec( ...@@ -769,16 +774,17 @@ xfs_alloc_insrec(
*/ */
rp = XFS_ALLOC_REC_ADDR(block, 1, cur); rp = XFS_ALLOC_REC_ADDR(block, 1, cur);
memmove(&rp[ptr], &rp[ptr - 1], memmove(&rp[ptr], &rp[ptr - 1],
(be16_to_cpu(block->bb_numrecs) - ptr + 1) * sizeof(*rp)); (numrecs - ptr + 1) * sizeof(*rp));
/* /*
* Now stuff the new record in, bump numrecs * Now stuff the new record in, bump numrecs
* and log the new data. * and log the new data.
*/ */
rp[ptr - 1] = *recp; rp[ptr - 1] = *recp;
be16_add(&block->bb_numrecs, 1); numrecs++;
xfs_alloc_log_recs(cur, bp, ptr, be16_to_cpu(block->bb_numrecs)); block->bb_numrecs = cpu_to_be16(numrecs);
xfs_alloc_log_recs(cur, bp, ptr, numrecs);
#ifdef DEBUG #ifdef DEBUG
if (ptr < be16_to_cpu(block->bb_numrecs)) if (ptr < numrecs)
xfs_btree_check_rec(cur->bc_btnum, rp + ptr - 1, xfs_btree_check_rec(cur->bc_btnum, rp + ptr - 1,
rp + ptr); rp + ptr);
#endif #endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册