aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_btree.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@infradead.org>2008-10-30 01:58:32 -0400
committerLachlan McIlroy <lachlan@sgi.com>2008-10-30 01:58:32 -0400
commit4a26e66e7728112f0e1cd7eca3bcc430b3a221c9 (patch)
tree1944f9aa65476c963658b7b4679f7a64287adfb6 /fs/xfs/xfs_btree.c
parentfd6bcc5b63051392ba709a8fd33173b263669e0a (diff)
[XFS] add keys_inorder and recs_inorder btree methods
Add methods to check whether two keys/records are in the righ order. This replaces the xfs_btree_check_key and xfs_btree_check_rec methods. For the callers from xfs_bmap.c just opencode the bmbt-specific asserts. SGI-PV: 985583 SGI-Modid: xfs-linux-melb:xfs-kern:32208a 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_btree.c')
-rw-r--r--fs/xfs/xfs_btree.c150
1 files changed, 16 insertions, 134 deletions
diff --git a/fs/xfs/xfs_btree.c b/fs/xfs/xfs_btree.c
index 88eb00bdeb96..d667d30210a8 100644
--- a/fs/xfs/xfs_btree.c
+++ b/fs/xfs/xfs_btree.c
@@ -52,122 +52,6 @@ const __uint32_t xfs_magics[XFS_BTNUM_MAX] = {
52 XFS_ABTB_MAGIC, XFS_ABTC_MAGIC, XFS_BMAP_MAGIC, XFS_IBT_MAGIC 52 XFS_ABTB_MAGIC, XFS_ABTC_MAGIC, XFS_BMAP_MAGIC, XFS_IBT_MAGIC
53}; 53};
54 54
55/*
56 * External routines.
57 */
58
59#ifdef DEBUG
60/*
61 * Debug routine: check that keys are in the right order.
62 */
63void
64xfs_btree_check_key(
65 xfs_btnum_t btnum, /* btree identifier */
66 void *ak1, /* pointer to left (lower) key */
67 void *ak2) /* pointer to right (higher) key */
68{
69 switch (btnum) {
70 case XFS_BTNUM_BNO: {
71 xfs_alloc_key_t *k1;
72 xfs_alloc_key_t *k2;
73
74 k1 = ak1;
75 k2 = ak2;
76 ASSERT(be32_to_cpu(k1->ar_startblock) < be32_to_cpu(k2->ar_startblock));
77 break;
78 }
79 case XFS_BTNUM_CNT: {
80 xfs_alloc_key_t *k1;
81 xfs_alloc_key_t *k2;
82
83 k1 = ak1;
84 k2 = ak2;
85 ASSERT(be32_to_cpu(k1->ar_blockcount) < be32_to_cpu(k2->ar_blockcount) ||
86 (k1->ar_blockcount == k2->ar_blockcount &&
87 be32_to_cpu(k1->ar_startblock) < be32_to_cpu(k2->ar_startblock)));
88 break;
89 }
90 case XFS_BTNUM_BMAP: {
91 xfs_bmbt_key_t *k1;
92 xfs_bmbt_key_t *k2;
93
94 k1 = ak1;
95 k2 = ak2;
96 ASSERT(be64_to_cpu(k1->br_startoff) < be64_to_cpu(k2->br_startoff));
97 break;
98 }
99 case XFS_BTNUM_INO: {
100 xfs_inobt_key_t *k1;
101 xfs_inobt_key_t *k2;
102
103 k1 = ak1;
104 k2 = ak2;
105 ASSERT(be32_to_cpu(k1->ir_startino) < be32_to_cpu(k2->ir_startino));
106 break;
107 }
108 default:
109 ASSERT(0);
110 }
111}
112
113/*
114 * Debug routine: check that records are in the right order.
115 */
116void
117xfs_btree_check_rec(
118 xfs_btnum_t btnum, /* btree identifier */
119 void *ar1, /* pointer to left (lower) record */
120 void *ar2) /* pointer to right (higher) record */
121{
122 switch (btnum) {
123 case XFS_BTNUM_BNO: {
124 xfs_alloc_rec_t *r1;
125 xfs_alloc_rec_t *r2;
126
127 r1 = ar1;
128 r2 = ar2;
129 ASSERT(be32_to_cpu(r1->ar_startblock) +
130 be32_to_cpu(r1->ar_blockcount) <=
131 be32_to_cpu(r2->ar_startblock));
132 break;
133 }
134 case XFS_BTNUM_CNT: {
135 xfs_alloc_rec_t *r1;
136 xfs_alloc_rec_t *r2;
137
138 r1 = ar1;
139 r2 = ar2;
140 ASSERT(be32_to_cpu(r1->ar_blockcount) < be32_to_cpu(r2->ar_blockcount) ||
141 (r1->ar_blockcount == r2->ar_blockcount &&
142 be32_to_cpu(r1->ar_startblock) < be32_to_cpu(r2->ar_startblock)));
143 break;
144 }
145 case XFS_BTNUM_BMAP: {
146 xfs_bmbt_rec_t *r1;
147 xfs_bmbt_rec_t *r2;
148
149 r1 = ar1;
150 r2 = ar2;
151 ASSERT(xfs_bmbt_disk_get_startoff(r1) +
152 xfs_bmbt_disk_get_blockcount(r1) <=
153 xfs_bmbt_disk_get_startoff(r2));
154 break;
155 }
156 case XFS_BTNUM_INO: {
157 xfs_inobt_rec_t *r1;
158 xfs_inobt_rec_t *r2;
159
160 r1 = ar1;
161 r2 = ar2;
162 ASSERT(be32_to_cpu(r1->ir_startino) + XFS_INODES_PER_CHUNK <=
163 be32_to_cpu(r2->ir_startino));
164 break;
165 }
166 default:
167 ASSERT(0);
168 }
169}
170#endif /* DEBUG */
171 55
172int /* error (0 or EFSCORRUPTED) */ 56int /* error (0 or EFSCORRUPTED) */
173xfs_btree_check_lblock( 57xfs_btree_check_lblock(
@@ -2032,9 +1916,8 @@ xfs_btree_lshift(
2032 xfs_btree_log_keys(cur, lbp, lrecs, lrecs); 1916 xfs_btree_log_keys(cur, lbp, lrecs, lrecs);
2033 xfs_btree_log_ptrs(cur, lbp, lrecs, lrecs); 1917 xfs_btree_log_ptrs(cur, lbp, lrecs, lrecs);
2034 1918
2035 xfs_btree_check_key(cur->bc_btnum, 1919 ASSERT(cur->bc_ops->keys_inorder(cur,
2036 xfs_btree_key_addr(cur, lrecs - 1, left), 1920 xfs_btree_key_addr(cur, lrecs - 1, left), lkp));
2037 lkp);
2038 } else { 1921 } else {
2039 /* It's a leaf. Move records. */ 1922 /* It's a leaf. Move records. */
2040 union xfs_btree_rec *lrp; /* left record pointer */ 1923 union xfs_btree_rec *lrp; /* left record pointer */
@@ -2045,9 +1928,8 @@ xfs_btree_lshift(
2045 xfs_btree_copy_recs(cur, lrp, rrp, 1); 1928 xfs_btree_copy_recs(cur, lrp, rrp, 1);
2046 xfs_btree_log_recs(cur, lbp, lrecs, lrecs); 1929 xfs_btree_log_recs(cur, lbp, lrecs, lrecs);
2047 1930
2048 xfs_btree_check_rec(cur->bc_btnum, 1931 ASSERT(cur->bc_ops->recs_inorder(cur,
2049 xfs_btree_rec_addr(cur, lrecs - 1, left), 1932 xfs_btree_rec_addr(cur, lrecs - 1, left), lrp));
2050 lrp);
2051 } 1933 }
2052 1934
2053 xfs_btree_set_numrecs(left, lrecs); 1935 xfs_btree_set_numrecs(left, lrecs);
@@ -2222,8 +2104,8 @@ xfs_btree_rshift(
2222 xfs_btree_log_keys(cur, rbp, 1, rrecs + 1); 2104 xfs_btree_log_keys(cur, rbp, 1, rrecs + 1);
2223 xfs_btree_log_ptrs(cur, rbp, 1, rrecs + 1); 2105 xfs_btree_log_ptrs(cur, rbp, 1, rrecs + 1);
2224 2106
2225 xfs_btree_check_key(cur->bc_btnum, rkp, 2107 ASSERT(cur->bc_ops->keys_inorder(cur, rkp,
2226 xfs_btree_key_addr(cur, 2, right)); 2108 xfs_btree_key_addr(cur, 2, right)));
2227 } else { 2109 } else {
2228 /* It's a leaf. make a hole in the records */ 2110 /* It's a leaf. make a hole in the records */
2229 union xfs_btree_rec *lrp; 2111 union xfs_btree_rec *lrp;
@@ -2241,8 +2123,8 @@ xfs_btree_rshift(
2241 cur->bc_ops->init_key_from_rec(&key, rrp); 2123 cur->bc_ops->init_key_from_rec(&key, rrp);
2242 rkp = &key; 2124 rkp = &key;
2243 2125
2244 xfs_btree_check_rec(cur->bc_btnum, rrp, 2126 ASSERT(cur->bc_ops->recs_inorder(cur, rrp,
2245 xfs_btree_rec_addr(cur, 2, right)); 2127 xfs_btree_rec_addr(cur, 2, right)));
2246 } 2128 }
2247 2129
2248 /* 2130 /*
@@ -2849,11 +2731,11 @@ xfs_btree_insrec(
2849 /* Check that the new entry is being inserted in the right place. */ 2731 /* Check that the new entry is being inserted in the right place. */
2850 if (ptr <= numrecs) { 2732 if (ptr <= numrecs) {
2851 if (level == 0) { 2733 if (level == 0) {
2852 xfs_btree_check_rec(cur->bc_btnum, recp, 2734 ASSERT(cur->bc_ops->recs_inorder(cur, recp,
2853 xfs_btree_rec_addr(cur, ptr, block)); 2735 xfs_btree_rec_addr(cur, ptr, block)));
2854 } else { 2736 } else {
2855 xfs_btree_check_key(cur->bc_btnum, &key, 2737 ASSERT(cur->bc_ops->keys_inorder(cur, &key,
2856 xfs_btree_key_addr(cur, ptr, block)); 2738 xfs_btree_key_addr(cur, ptr, block)));
2857 } 2739 }
2858 } 2740 }
2859#endif 2741#endif
@@ -2923,8 +2805,8 @@ xfs_btree_insrec(
2923 xfs_btree_log_keys(cur, bp, ptr, numrecs); 2805 xfs_btree_log_keys(cur, bp, ptr, numrecs);
2924#ifdef DEBUG 2806#ifdef DEBUG
2925 if (ptr < numrecs) { 2807 if (ptr < numrecs) {
2926 xfs_btree_check_key(cur->bc_btnum, kp, 2808 ASSERT(cur->bc_ops->keys_inorder(cur, kp,
2927 xfs_btree_key_addr(cur, ptr + 1, block)); 2809 xfs_btree_key_addr(cur, ptr + 1, block)));
2928 } 2810 }
2929#endif 2811#endif
2930 } else { 2812 } else {
@@ -2941,8 +2823,8 @@ xfs_btree_insrec(
2941 xfs_btree_log_recs(cur, bp, ptr, numrecs); 2823 xfs_btree_log_recs(cur, bp, ptr, numrecs);
2942#ifdef DEBUG 2824#ifdef DEBUG
2943 if (ptr < numrecs) { 2825 if (ptr < numrecs) {
2944 xfs_btree_check_rec(cur->bc_btnum, rp, 2826 ASSERT(cur->bc_ops->recs_inorder(cur, rp,
2945 xfs_btree_rec_addr(cur, ptr + 1, block)); 2827 xfs_btree_rec_addr(cur, ptr + 1, block)));
2946 } 2828 }
2947#endif 2829#endif
2948 } 2830 }