aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_btree.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/xfs/xfs_btree.c')
-rw-r--r--fs/xfs/xfs_btree.c160
1 files changed, 72 insertions, 88 deletions
diff --git a/fs/xfs/xfs_btree.c b/fs/xfs/xfs_btree.c
index 0cc63d657a14..52d5d095fc35 100644
--- a/fs/xfs/xfs_btree.c
+++ b/fs/xfs/xfs_btree.c
@@ -1,45 +1,26 @@
1/* 1/*
2 * Copyright (c) 2000-2002 Silicon Graphics, Inc. All Rights Reserved. 2 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
3 * 4 *
4 * This program is free software; you can redistribute it and/or modify it 5 * This program is free software; you can redistribute it and/or
5 * under the terms of version 2 of the GNU General Public License as 6 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
7 * 8 *
8 * This program is distributed in the hope that it would be useful, but 9 * This program is distributed in the hope that it would be useful,
9 * WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
11 * 13 *
12 * Further, this software is distributed without any warranty that it is 14 * You should have received a copy of the GNU General Public License
13 * free of the rightful claim of any third person regarding infringement 15 * along with this program; if not, write the Free Software Foundation,
14 * or the like. Any license provided herein, whether implied or 16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */ 17 */
32
33/*
34 * This file contains common code for the space manager's btree implementations.
35 */
36
37#include "xfs.h" 18#include "xfs.h"
38 19#include "xfs_fs.h"
39#include "xfs_macros.h"
40#include "xfs_types.h" 20#include "xfs_types.h"
41#include "xfs_inum.h" 21#include "xfs_bit.h"
42#include "xfs_log.h" 22#include "xfs_log.h"
23#include "xfs_inum.h"
43#include "xfs_trans.h" 24#include "xfs_trans.h"
44#include "xfs_sb.h" 25#include "xfs_sb.h"
45#include "xfs_ag.h" 26#include "xfs_ag.h"
@@ -47,17 +28,16 @@
47#include "xfs_dir2.h" 28#include "xfs_dir2.h"
48#include "xfs_dmapi.h" 29#include "xfs_dmapi.h"
49#include "xfs_mount.h" 30#include "xfs_mount.h"
50#include "xfs_alloc_btree.h"
51#include "xfs_bmap_btree.h" 31#include "xfs_bmap_btree.h"
32#include "xfs_alloc_btree.h"
52#include "xfs_ialloc_btree.h" 33#include "xfs_ialloc_btree.h"
53#include "xfs_btree.h"
54#include "xfs_ialloc.h"
55#include "xfs_attr_sf.h"
56#include "xfs_dir_sf.h" 34#include "xfs_dir_sf.h"
57#include "xfs_dir2_sf.h" 35#include "xfs_dir2_sf.h"
36#include "xfs_attr_sf.h"
58#include "xfs_dinode.h" 37#include "xfs_dinode.h"
59#include "xfs_inode.h" 38#include "xfs_inode.h"
60#include "xfs_bit.h" 39#include "xfs_btree.h"
40#include "xfs_ialloc.h"
61#include "xfs_error.h" 41#include "xfs_error.h"
62 42
63/* 43/*
@@ -110,11 +90,14 @@ xfs_btree_maxrecs(
110 switch (cur->bc_btnum) { 90 switch (cur->bc_btnum) {
111 case XFS_BTNUM_BNO: 91 case XFS_BTNUM_BNO:
112 case XFS_BTNUM_CNT: 92 case XFS_BTNUM_CNT:
113 return (int)XFS_ALLOC_BLOCK_MAXRECS(INT_GET(block->bb_h.bb_level, ARCH_CONVERT), cur); 93 return (int)XFS_ALLOC_BLOCK_MAXRECS(
94 be16_to_cpu(block->bb_h.bb_level), cur);
114 case XFS_BTNUM_BMAP: 95 case XFS_BTNUM_BMAP:
115 return (int)XFS_BMAP_BLOCK_IMAXRECS(INT_GET(block->bb_h.bb_level, ARCH_CONVERT), cur); 96 return (int)XFS_BMAP_BLOCK_IMAXRECS(
97 be16_to_cpu(block->bb_h.bb_level), cur);
116 case XFS_BTNUM_INO: 98 case XFS_BTNUM_INO:
117 return (int)XFS_INOBT_BLOCK_MAXRECS(INT_GET(block->bb_h.bb_level, ARCH_CONVERT), cur); 99 return (int)XFS_INOBT_BLOCK_MAXRECS(
100 be16_to_cpu(block->bb_h.bb_level), cur);
118 default: 101 default:
119 ASSERT(0); 102 ASSERT(0);
120 return 0; 103 return 0;
@@ -160,7 +143,7 @@ xfs_btree_check_key(
160 143
161 k1 = ak1; 144 k1 = ak1;
162 k2 = ak2; 145 k2 = ak2;
163 ASSERT(INT_GET(k1->ar_startblock, ARCH_CONVERT) < INT_GET(k2->ar_startblock, ARCH_CONVERT)); 146 ASSERT(be32_to_cpu(k1->ar_startblock) < be32_to_cpu(k2->ar_startblock));
164 break; 147 break;
165 } 148 }
166 case XFS_BTNUM_CNT: { 149 case XFS_BTNUM_CNT: {
@@ -169,9 +152,9 @@ xfs_btree_check_key(
169 152
170 k1 = ak1; 153 k1 = ak1;
171 k2 = ak2; 154 k2 = ak2;
172 ASSERT(INT_GET(k1->ar_blockcount, ARCH_CONVERT) < INT_GET(k2->ar_blockcount, ARCH_CONVERT) || 155 ASSERT(be32_to_cpu(k1->ar_blockcount) < be32_to_cpu(k2->ar_blockcount) ||
173 (INT_GET(k1->ar_blockcount, ARCH_CONVERT) == INT_GET(k2->ar_blockcount, ARCH_CONVERT) && 156 (k1->ar_blockcount == k2->ar_blockcount &&
174 INT_GET(k1->ar_startblock, ARCH_CONVERT) < INT_GET(k2->ar_startblock, ARCH_CONVERT))); 157 be32_to_cpu(k1->ar_startblock) < be32_to_cpu(k2->ar_startblock)));
175 break; 158 break;
176 } 159 }
177 case XFS_BTNUM_BMAP: { 160 case XFS_BTNUM_BMAP: {
@@ -214,16 +197,16 @@ xfs_btree_check_lblock(
214 197
215 mp = cur->bc_mp; 198 mp = cur->bc_mp;
216 lblock_ok = 199 lblock_ok =
217 INT_GET(block->bb_magic, ARCH_CONVERT) == xfs_magics[cur->bc_btnum] && 200 be32_to_cpu(block->bb_magic) == xfs_magics[cur->bc_btnum] &&
218 INT_GET(block->bb_level, ARCH_CONVERT) == level && 201 be16_to_cpu(block->bb_level) == level &&
219 INT_GET(block->bb_numrecs, ARCH_CONVERT) <= 202 be16_to_cpu(block->bb_numrecs) <=
220 xfs_btree_maxrecs(cur, (xfs_btree_block_t *)block) && 203 xfs_btree_maxrecs(cur, (xfs_btree_block_t *)block) &&
221 block->bb_leftsib && 204 block->bb_leftsib &&
222 (INT_GET(block->bb_leftsib, ARCH_CONVERT) == NULLDFSBNO || 205 (be64_to_cpu(block->bb_leftsib) == NULLDFSBNO ||
223 XFS_FSB_SANITY_CHECK(mp, INT_GET(block->bb_leftsib, ARCH_CONVERT))) && 206 XFS_FSB_SANITY_CHECK(mp, be64_to_cpu(block->bb_leftsib))) &&
224 block->bb_rightsib && 207 block->bb_rightsib &&
225 (INT_GET(block->bb_rightsib, ARCH_CONVERT) == NULLDFSBNO || 208 (be64_to_cpu(block->bb_rightsib) == NULLDFSBNO ||
226 XFS_FSB_SANITY_CHECK(mp, INT_GET(block->bb_rightsib, ARCH_CONVERT))); 209 XFS_FSB_SANITY_CHECK(mp, be64_to_cpu(block->bb_rightsib)));
227 if (unlikely(XFS_TEST_ERROR(!lblock_ok, mp, XFS_ERRTAG_BTREE_CHECK_LBLOCK, 210 if (unlikely(XFS_TEST_ERROR(!lblock_ok, mp, XFS_ERRTAG_BTREE_CHECK_LBLOCK,
228 XFS_RANDOM_BTREE_CHECK_LBLOCK))) { 211 XFS_RANDOM_BTREE_CHECK_LBLOCK))) {
229 if (bp) 212 if (bp)
@@ -271,8 +254,9 @@ xfs_btree_check_rec(
271 254
272 r1 = ar1; 255 r1 = ar1;
273 r2 = ar2; 256 r2 = ar2;
274 ASSERT(INT_GET(r1->ar_startblock, ARCH_CONVERT) + INT_GET(r1->ar_blockcount, ARCH_CONVERT) <= 257 ASSERT(be32_to_cpu(r1->ar_startblock) +
275 INT_GET(r2->ar_startblock, ARCH_CONVERT)); 258 be32_to_cpu(r1->ar_blockcount) <=
259 be32_to_cpu(r2->ar_startblock));
276 break; 260 break;
277 } 261 }
278 case XFS_BTNUM_CNT: { 262 case XFS_BTNUM_CNT: {
@@ -281,9 +265,9 @@ xfs_btree_check_rec(
281 265
282 r1 = ar1; 266 r1 = ar1;
283 r2 = ar2; 267 r2 = ar2;
284 ASSERT(INT_GET(r1->ar_blockcount, ARCH_CONVERT) < INT_GET(r2->ar_blockcount, ARCH_CONVERT) || 268 ASSERT(be32_to_cpu(r1->ar_blockcount) < be32_to_cpu(r2->ar_blockcount) ||
285 (INT_GET(r1->ar_blockcount, ARCH_CONVERT) == INT_GET(r2->ar_blockcount, ARCH_CONVERT) && 269 (r1->ar_blockcount == r2->ar_blockcount &&
286 INT_GET(r1->ar_startblock, ARCH_CONVERT) < INT_GET(r2->ar_startblock, ARCH_CONVERT))); 270 be32_to_cpu(r1->ar_startblock) < be32_to_cpu(r2->ar_startblock)));
287 break; 271 break;
288 } 272 }
289 case XFS_BTNUM_BMAP: { 273 case XFS_BTNUM_BMAP: {
@@ -331,17 +315,17 @@ xfs_btree_check_sblock(
331 315
332 agbp = cur->bc_private.a.agbp; 316 agbp = cur->bc_private.a.agbp;
333 agf = XFS_BUF_TO_AGF(agbp); 317 agf = XFS_BUF_TO_AGF(agbp);
334 agflen = INT_GET(agf->agf_length, ARCH_CONVERT); 318 agflen = be32_to_cpu(agf->agf_length);
335 sblock_ok = 319 sblock_ok =
336 INT_GET(block->bb_magic, ARCH_CONVERT) == xfs_magics[cur->bc_btnum] && 320 be32_to_cpu(block->bb_magic) == xfs_magics[cur->bc_btnum] &&
337 INT_GET(block->bb_level, ARCH_CONVERT) == level && 321 be16_to_cpu(block->bb_level) == level &&
338 INT_GET(block->bb_numrecs, ARCH_CONVERT) <= 322 be16_to_cpu(block->bb_numrecs) <=
339 xfs_btree_maxrecs(cur, (xfs_btree_block_t *)block) && 323 xfs_btree_maxrecs(cur, (xfs_btree_block_t *)block) &&
340 (INT_GET(block->bb_leftsib, ARCH_CONVERT) == NULLAGBLOCK || 324 (be32_to_cpu(block->bb_leftsib) == NULLAGBLOCK ||
341 INT_GET(block->bb_leftsib, ARCH_CONVERT) < agflen) && 325 be32_to_cpu(block->bb_leftsib) < agflen) &&
342 block->bb_leftsib && 326 block->bb_leftsib &&
343 (INT_GET(block->bb_rightsib, ARCH_CONVERT) == NULLAGBLOCK || 327 (be32_to_cpu(block->bb_rightsib) == NULLAGBLOCK ||
344 INT_GET(block->bb_rightsib, ARCH_CONVERT) < agflen) && 328 be32_to_cpu(block->bb_rightsib) < agflen) &&
345 block->bb_rightsib; 329 block->bb_rightsib;
346 if (unlikely(XFS_TEST_ERROR(!sblock_ok, cur->bc_mp, 330 if (unlikely(XFS_TEST_ERROR(!sblock_ok, cur->bc_mp,
347 XFS_ERRTAG_BTREE_CHECK_SBLOCK, 331 XFS_ERRTAG_BTREE_CHECK_SBLOCK,
@@ -372,7 +356,7 @@ xfs_btree_check_sptr(
372 XFS_WANT_CORRUPTED_RETURN( 356 XFS_WANT_CORRUPTED_RETURN(
373 level > 0 && 357 level > 0 &&
374 ptr != NULLAGBLOCK && ptr != 0 && 358 ptr != NULLAGBLOCK && ptr != 0 &&
375 ptr < INT_GET(agf->agf_length, ARCH_CONVERT)); 359 ptr < be32_to_cpu(agf->agf_length));
376 return 0; 360 return 0;
377} 361}
378 362
@@ -611,15 +595,15 @@ xfs_btree_init_cursor(
611 case XFS_BTNUM_BNO: 595 case XFS_BTNUM_BNO:
612 case XFS_BTNUM_CNT: 596 case XFS_BTNUM_CNT:
613 agf = XFS_BUF_TO_AGF(agbp); 597 agf = XFS_BUF_TO_AGF(agbp);
614 nlevels = INT_GET(agf->agf_levels[btnum], ARCH_CONVERT); 598 nlevels = be32_to_cpu(agf->agf_levels[btnum]);
615 break; 599 break;
616 case XFS_BTNUM_BMAP: 600 case XFS_BTNUM_BMAP:
617 ifp = XFS_IFORK_PTR(ip, whichfork); 601 ifp = XFS_IFORK_PTR(ip, whichfork);
618 nlevels = INT_GET(ifp->if_broot->bb_level, ARCH_CONVERT) + 1; 602 nlevels = be16_to_cpu(ifp->if_broot->bb_level) + 1;
619 break; 603 break;
620 case XFS_BTNUM_INO: 604 case XFS_BTNUM_INO:
621 agi = XFS_BUF_TO_AGI(agbp); 605 agi = XFS_BUF_TO_AGI(agbp);
622 nlevels = INT_GET(agi->agi_level, ARCH_CONVERT); 606 nlevels = be32_to_cpu(agi->agi_level);
623 break; 607 break;
624 default: 608 default:
625 ASSERT(0); 609 ASSERT(0);
@@ -683,9 +667,9 @@ xfs_btree_islastblock(
683 block = xfs_btree_get_block(cur, level, &bp); 667 block = xfs_btree_get_block(cur, level, &bp);
684 xfs_btree_check_block(cur, block, level, bp); 668 xfs_btree_check_block(cur, block, level, bp);
685 if (XFS_BTREE_LONG_PTRS(cur->bc_btnum)) 669 if (XFS_BTREE_LONG_PTRS(cur->bc_btnum))
686 return INT_GET(block->bb_u.l.bb_rightsib, ARCH_CONVERT) == NULLDFSBNO; 670 return be64_to_cpu(block->bb_u.l.bb_rightsib) == NULLDFSBNO;
687 else 671 else
688 return INT_GET(block->bb_u.s.bb_rightsib, ARCH_CONVERT) == NULLAGBLOCK; 672 return be32_to_cpu(block->bb_u.s.bb_rightsib) == NULLAGBLOCK;
689} 673}
690 674
691/* 675/*
@@ -713,7 +697,7 @@ xfs_btree_lastrec(
713 /* 697 /*
714 * Set the ptr value to numrecs, that's the last record/key. 698 * Set the ptr value to numrecs, that's the last record/key.
715 */ 699 */
716 cur->bc_ptrs[level] = INT_GET(block->bb_h.bb_numrecs, ARCH_CONVERT); 700 cur->bc_ptrs[level] = be16_to_cpu(block->bb_h.bb_numrecs);
717 return 1; 701 return 1;
718} 702}
719 703
@@ -883,38 +867,38 @@ xfs_btree_readahead_core(
883 case XFS_BTNUM_BNO: 867 case XFS_BTNUM_BNO:
884 case XFS_BTNUM_CNT: 868 case XFS_BTNUM_CNT:
885 a = XFS_BUF_TO_ALLOC_BLOCK(cur->bc_bufs[lev]); 869 a = XFS_BUF_TO_ALLOC_BLOCK(cur->bc_bufs[lev]);
886 if ((lr & XFS_BTCUR_LEFTRA) && INT_GET(a->bb_leftsib, ARCH_CONVERT) != NULLAGBLOCK) { 870 if ((lr & XFS_BTCUR_LEFTRA) && be32_to_cpu(a->bb_leftsib) != NULLAGBLOCK) {
887 xfs_btree_reada_bufs(cur->bc_mp, cur->bc_private.a.agno, 871 xfs_btree_reada_bufs(cur->bc_mp, cur->bc_private.a.agno,
888 INT_GET(a->bb_leftsib, ARCH_CONVERT), 1); 872 be32_to_cpu(a->bb_leftsib), 1);
889 rval++; 873 rval++;
890 } 874 }
891 if ((lr & XFS_BTCUR_RIGHTRA) && INT_GET(a->bb_rightsib, ARCH_CONVERT) != NULLAGBLOCK) { 875 if ((lr & XFS_BTCUR_RIGHTRA) && be32_to_cpu(a->bb_rightsib) != NULLAGBLOCK) {
892 xfs_btree_reada_bufs(cur->bc_mp, cur->bc_private.a.agno, 876 xfs_btree_reada_bufs(cur->bc_mp, cur->bc_private.a.agno,
893 INT_GET(a->bb_rightsib, ARCH_CONVERT), 1); 877 be32_to_cpu(a->bb_rightsib), 1);
894 rval++; 878 rval++;
895 } 879 }
896 break; 880 break;
897 case XFS_BTNUM_BMAP: 881 case XFS_BTNUM_BMAP:
898 b = XFS_BUF_TO_BMBT_BLOCK(cur->bc_bufs[lev]); 882 b = XFS_BUF_TO_BMBT_BLOCK(cur->bc_bufs[lev]);
899 if ((lr & XFS_BTCUR_LEFTRA) && INT_GET(b->bb_leftsib, ARCH_CONVERT) != NULLDFSBNO) { 883 if ((lr & XFS_BTCUR_LEFTRA) && be64_to_cpu(b->bb_leftsib) != NULLDFSBNO) {
900 xfs_btree_reada_bufl(cur->bc_mp, INT_GET(b->bb_leftsib, ARCH_CONVERT), 1); 884 xfs_btree_reada_bufl(cur->bc_mp, be64_to_cpu(b->bb_leftsib), 1);
901 rval++; 885 rval++;
902 } 886 }
903 if ((lr & XFS_BTCUR_RIGHTRA) && INT_GET(b->bb_rightsib, ARCH_CONVERT) != NULLDFSBNO) { 887 if ((lr & XFS_BTCUR_RIGHTRA) && be64_to_cpu(b->bb_rightsib) != NULLDFSBNO) {
904 xfs_btree_reada_bufl(cur->bc_mp, INT_GET(b->bb_rightsib, ARCH_CONVERT), 1); 888 xfs_btree_reada_bufl(cur->bc_mp, be64_to_cpu(b->bb_rightsib), 1);
905 rval++; 889 rval++;
906 } 890 }
907 break; 891 break;
908 case XFS_BTNUM_INO: 892 case XFS_BTNUM_INO:
909 i = XFS_BUF_TO_INOBT_BLOCK(cur->bc_bufs[lev]); 893 i = XFS_BUF_TO_INOBT_BLOCK(cur->bc_bufs[lev]);
910 if ((lr & XFS_BTCUR_LEFTRA) && INT_GET(i->bb_leftsib, ARCH_CONVERT) != NULLAGBLOCK) { 894 if ((lr & XFS_BTCUR_LEFTRA) && be32_to_cpu(i->bb_leftsib) != NULLAGBLOCK) {
911 xfs_btree_reada_bufs(cur->bc_mp, cur->bc_private.i.agno, 895 xfs_btree_reada_bufs(cur->bc_mp, cur->bc_private.i.agno,
912 INT_GET(i->bb_leftsib, ARCH_CONVERT), 1); 896 be32_to_cpu(i->bb_leftsib), 1);
913 rval++; 897 rval++;
914 } 898 }
915 if ((lr & XFS_BTCUR_RIGHTRA) && INT_GET(i->bb_rightsib, ARCH_CONVERT) != NULLAGBLOCK) { 899 if ((lr & XFS_BTCUR_RIGHTRA) && be32_to_cpu(i->bb_rightsib) != NULLAGBLOCK) {
916 xfs_btree_reada_bufs(cur->bc_mp, cur->bc_private.i.agno, 900 xfs_btree_reada_bufs(cur->bc_mp, cur->bc_private.i.agno,
917 INT_GET(i->bb_rightsib, ARCH_CONVERT), 1); 901 be32_to_cpu(i->bb_rightsib), 1);
918 rval++; 902 rval++;
919 } 903 }
920 break; 904 break;
@@ -946,14 +930,14 @@ xfs_btree_setbuf(
946 return; 930 return;
947 b = XFS_BUF_TO_BLOCK(bp); 931 b = XFS_BUF_TO_BLOCK(bp);
948 if (XFS_BTREE_LONG_PTRS(cur->bc_btnum)) { 932 if (XFS_BTREE_LONG_PTRS(cur->bc_btnum)) {
949 if (INT_GET(b->bb_u.l.bb_leftsib, ARCH_CONVERT) == NULLDFSBNO) 933 if (be64_to_cpu(b->bb_u.l.bb_leftsib) == NULLDFSBNO)
950 cur->bc_ra[lev] |= XFS_BTCUR_LEFTRA; 934 cur->bc_ra[lev] |= XFS_BTCUR_LEFTRA;
951 if (INT_GET(b->bb_u.l.bb_rightsib, ARCH_CONVERT) == NULLDFSBNO) 935 if (be64_to_cpu(b->bb_u.l.bb_rightsib) == NULLDFSBNO)
952 cur->bc_ra[lev] |= XFS_BTCUR_RIGHTRA; 936 cur->bc_ra[lev] |= XFS_BTCUR_RIGHTRA;
953 } else { 937 } else {
954 if (INT_GET(b->bb_u.s.bb_leftsib, ARCH_CONVERT) == NULLAGBLOCK) 938 if (be32_to_cpu(b->bb_u.s.bb_leftsib) == NULLAGBLOCK)
955 cur->bc_ra[lev] |= XFS_BTCUR_LEFTRA; 939 cur->bc_ra[lev] |= XFS_BTCUR_LEFTRA;
956 if (INT_GET(b->bb_u.s.bb_rightsib, ARCH_CONVERT) == NULLAGBLOCK) 940 if (be32_to_cpu(b->bb_u.s.bb_rightsib) == NULLAGBLOCK)
957 cur->bc_ra[lev] |= XFS_BTCUR_RIGHTRA; 941 cur->bc_ra[lev] |= XFS_BTCUR_RIGHTRA;
958 } 942 }
959} 943}