aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs
diff options
context:
space:
mode:
Diffstat (limited to 'fs/xfs')
-rw-r--r--fs/xfs/xfs_alloc_btree.c44
-rw-r--r--fs/xfs/xfs_bmap.c11
-rw-r--r--fs/xfs/xfs_bmap_btree.c28
-rw-r--r--fs/xfs/xfs_btree.c150
-rw-r--r--fs/xfs/xfs_btree.h36
-rw-r--r--fs/xfs/xfs_ialloc_btree.c27
6 files changed, 135 insertions, 161 deletions
diff --git a/fs/xfs/xfs_alloc_btree.c b/fs/xfs/xfs_alloc_btree.c
index 4d44f03858b0..9e63f8c180d9 100644
--- a/fs/xfs/xfs_alloc_btree.c
+++ b/fs/xfs/xfs_alloc_btree.c
@@ -311,6 +311,45 @@ xfs_allocbt_kill_root(
311 return 0; 311 return 0;
312} 312}
313 313
314#ifdef DEBUG
315STATIC int
316xfs_allocbt_keys_inorder(
317 struct xfs_btree_cur *cur,
318 union xfs_btree_key *k1,
319 union xfs_btree_key *k2)
320{
321 if (cur->bc_btnum == XFS_BTNUM_BNO) {
322 return be32_to_cpu(k1->alloc.ar_startblock) <
323 be32_to_cpu(k2->alloc.ar_startblock);
324 } else {
325 return be32_to_cpu(k1->alloc.ar_blockcount) <
326 be32_to_cpu(k2->alloc.ar_blockcount) ||
327 (k1->alloc.ar_blockcount == k2->alloc.ar_blockcount &&
328 be32_to_cpu(k1->alloc.ar_startblock) <
329 be32_to_cpu(k2->alloc.ar_startblock));
330 }
331}
332
333STATIC int
334xfs_allocbt_recs_inorder(
335 struct xfs_btree_cur *cur,
336 union xfs_btree_rec *r1,
337 union xfs_btree_rec *r2)
338{
339 if (cur->bc_btnum == XFS_BTNUM_BNO) {
340 return be32_to_cpu(r1->alloc.ar_startblock) +
341 be32_to_cpu(r1->alloc.ar_blockcount) <=
342 be32_to_cpu(r2->alloc.ar_startblock);
343 } else {
344 return be32_to_cpu(r1->alloc.ar_blockcount) <
345 be32_to_cpu(r2->alloc.ar_blockcount) ||
346 (r1->alloc.ar_blockcount == r2->alloc.ar_blockcount &&
347 be32_to_cpu(r1->alloc.ar_startblock) <
348 be32_to_cpu(r2->alloc.ar_startblock));
349 }
350}
351#endif /* DEBUG */
352
314#ifdef XFS_BTREE_TRACE 353#ifdef XFS_BTREE_TRACE
315ktrace_t *xfs_allocbt_trace_buf; 354ktrace_t *xfs_allocbt_trace_buf;
316 355
@@ -395,6 +434,11 @@ static const struct xfs_btree_ops xfs_allocbt_ops = {
395 .init_ptr_from_cur = xfs_allocbt_init_ptr_from_cur, 434 .init_ptr_from_cur = xfs_allocbt_init_ptr_from_cur,
396 .key_diff = xfs_allocbt_key_diff, 435 .key_diff = xfs_allocbt_key_diff,
397 436
437#ifdef DEBUG
438 .keys_inorder = xfs_allocbt_keys_inorder,
439 .recs_inorder = xfs_allocbt_recs_inorder,
440#endif
441
398#ifdef XFS_BTREE_TRACE 442#ifdef XFS_BTREE_TRACE
399 .trace_enter = xfs_allocbt_trace_enter, 443 .trace_enter = xfs_allocbt_trace_enter,
400 .trace_cursor = xfs_allocbt_trace_cursor, 444 .trace_cursor = xfs_allocbt_trace_cursor,
diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
index 5cceb8d3c162..b7f99d7576d0 100644
--- a/fs/xfs/xfs_bmap.c
+++ b/fs/xfs/xfs_bmap.c
@@ -6195,7 +6195,8 @@ xfs_check_block(
6195 } 6195 }
6196 6196
6197 if (prevp) { 6197 if (prevp) {
6198 xfs_btree_check_key(XFS_BTNUM_BMAP, prevp, keyp); 6198 ASSERT(be64_to_cpu(prevp->br_startoff) <
6199 be64_to_cpu(keyp->br_startoff));
6199 } 6200 }
6200 prevp = keyp; 6201 prevp = keyp;
6201 6202
@@ -6338,11 +6339,15 @@ xfs_bmap_check_leaf_extents(
6338 6339
6339 ep = XFS_BTREE_REC_ADDR(xfs_bmbt, block, 1); 6340 ep = XFS_BTREE_REC_ADDR(xfs_bmbt, block, 1);
6340 if (i) { 6341 if (i) {
6341 xfs_btree_check_rec(XFS_BTNUM_BMAP, &last, ep); 6342 ASSERT(xfs_bmbt_disk_get_startoff(&last) +
6343 xfs_bmbt_disk_get_blockcount(&last) <=
6344 xfs_bmbt_disk_get_startoff(ep));
6342 } 6345 }
6343 for (j = 1; j < num_recs; j++) { 6346 for (j = 1; j < num_recs; j++) {
6344 nextp = XFS_BTREE_REC_ADDR(xfs_bmbt, block, j + 1); 6347 nextp = XFS_BTREE_REC_ADDR(xfs_bmbt, block, j + 1);
6345 xfs_btree_check_rec(XFS_BTNUM_BMAP, ep, nextp); 6348 ASSERT(xfs_bmbt_disk_get_startoff(ep) +
6349 xfs_bmbt_disk_get_blockcount(ep) <=
6350 xfs_bmbt_disk_get_startoff(nextp));
6346 ep = nextp; 6351 ep = nextp;
6347 } 6352 }
6348 6353
diff --git a/fs/xfs/xfs_bmap_btree.c b/fs/xfs/xfs_bmap_btree.c
index 7a02d391afec..c5eeb3241e25 100644
--- a/fs/xfs/xfs_bmap_btree.c
+++ b/fs/xfs/xfs_bmap_btree.c
@@ -699,6 +699,29 @@ xfs_bmbt_key_diff(
699 cur->bc_rec.b.br_startoff; 699 cur->bc_rec.b.br_startoff;
700} 700}
701 701
702#ifdef DEBUG
703STATIC int
704xfs_bmbt_keys_inorder(
705 struct xfs_btree_cur *cur,
706 union xfs_btree_key *k1,
707 union xfs_btree_key *k2)
708{
709 return be64_to_cpu(k1->bmbt.br_startoff) <
710 be64_to_cpu(k2->bmbt.br_startoff);
711}
712
713STATIC int
714xfs_bmbt_recs_inorder(
715 struct xfs_btree_cur *cur,
716 union xfs_btree_rec *r1,
717 union xfs_btree_rec *r2)
718{
719 return xfs_bmbt_disk_get_startoff(&r1->bmbt) +
720 xfs_bmbt_disk_get_blockcount(&r1->bmbt) <=
721 xfs_bmbt_disk_get_startoff(&r2->bmbt);
722}
723#endif /* DEBUG */
724
702#ifdef XFS_BTREE_TRACE 725#ifdef XFS_BTREE_TRACE
703ktrace_t *xfs_bmbt_trace_buf; 726ktrace_t *xfs_bmbt_trace_buf;
704 727
@@ -801,6 +824,11 @@ static const struct xfs_btree_ops xfs_bmbt_ops = {
801 .init_ptr_from_cur = xfs_bmbt_init_ptr_from_cur, 824 .init_ptr_from_cur = xfs_bmbt_init_ptr_from_cur,
802 .key_diff = xfs_bmbt_key_diff, 825 .key_diff = xfs_bmbt_key_diff,
803 826
827#ifdef DEBUG
828 .keys_inorder = xfs_bmbt_keys_inorder,
829 .recs_inorder = xfs_bmbt_recs_inorder,
830#endif
831
804#ifdef XFS_BTREE_TRACE 832#ifdef XFS_BTREE_TRACE
805 .trace_enter = xfs_bmbt_trace_enter, 833 .trace_enter = xfs_bmbt_trace_enter,
806 .trace_cursor = xfs_bmbt_trace_cursor, 834 .trace_cursor = xfs_bmbt_trace_cursor,
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 }
diff --git a/fs/xfs/xfs_btree.h b/fs/xfs/xfs_btree.h
index d6cc71e31de5..25a488d4da18 100644
--- a/fs/xfs/xfs_btree.h
+++ b/fs/xfs/xfs_btree.h
@@ -229,6 +229,18 @@ struct xfs_btree_ops {
229 __int64_t (*key_diff)(struct xfs_btree_cur *cur, 229 __int64_t (*key_diff)(struct xfs_btree_cur *cur,
230 union xfs_btree_key *key); 230 union xfs_btree_key *key);
231 231
232#ifdef DEBUG
233 /* check that k1 is lower than k2 */
234 int (*keys_inorder)(struct xfs_btree_cur *cur,
235 union xfs_btree_key *k1,
236 union xfs_btree_key *k2);
237
238 /* check that r1 is lower than r2 */
239 int (*recs_inorder)(struct xfs_btree_cur *cur,
240 union xfs_btree_rec *r1,
241 union xfs_btree_rec *r2);
242#endif
243
232 /* btree tracing */ 244 /* btree tracing */
233#ifdef XFS_BTREE_TRACE 245#ifdef XFS_BTREE_TRACE
234 void (*trace_enter)(struct xfs_btree_cur *, const char *, 246 void (*trace_enter)(struct xfs_btree_cur *, const char *,
@@ -379,30 +391,6 @@ xfs_btree_check_ptr(
379 int index, /* offset from ptr to check */ 391 int index, /* offset from ptr to check */
380 int level); /* btree block level */ 392 int level); /* btree block level */
381 393
382#ifdef DEBUG
383
384/*
385 * Debug routine: check that keys are in the right order.
386 */
387void
388xfs_btree_check_key(
389 xfs_btnum_t btnum, /* btree identifier */
390 void *ak1, /* pointer to left (lower) key */
391 void *ak2); /* pointer to right (higher) key */
392
393/*
394 * Debug routine: check that records are in the right order.
395 */
396void
397xfs_btree_check_rec(
398 xfs_btnum_t btnum, /* btree identifier */
399 void *ar1, /* pointer to left (lower) record */
400 void *ar2); /* pointer to right (higher) record */
401#else
402#define xfs_btree_check_key(a, b, c)
403#define xfs_btree_check_rec(a, b, c)
404#endif /* DEBUG */
405
406/* 394/*
407 * Delete the btree cursor. 395 * Delete the btree cursor.
408 */ 396 */
diff --git a/fs/xfs/xfs_ialloc_btree.c b/fs/xfs/xfs_ialloc_btree.c
index 9f4e33c945c2..dcd4a956e73c 100644
--- a/fs/xfs/xfs_ialloc_btree.c
+++ b/fs/xfs/xfs_ialloc_btree.c
@@ -219,6 +219,28 @@ xfs_inobt_kill_root(
219 return 0; 219 return 0;
220} 220}
221 221
222#ifdef DEBUG
223STATIC int
224xfs_inobt_keys_inorder(
225 struct xfs_btree_cur *cur,
226 union xfs_btree_key *k1,
227 union xfs_btree_key *k2)
228{
229 return be32_to_cpu(k1->inobt.ir_startino) <
230 be32_to_cpu(k2->inobt.ir_startino);
231}
232
233STATIC int
234xfs_inobt_recs_inorder(
235 struct xfs_btree_cur *cur,
236 union xfs_btree_rec *r1,
237 union xfs_btree_rec *r2)
238{
239 return be32_to_cpu(r1->inobt.ir_startino) + XFS_INODES_PER_CHUNK <=
240 be32_to_cpu(r2->inobt.ir_startino);
241}
242#endif /* DEBUG */
243
222#ifdef XFS_BTREE_TRACE 244#ifdef XFS_BTREE_TRACE
223ktrace_t *xfs_inobt_trace_buf; 245ktrace_t *xfs_inobt_trace_buf;
224 246
@@ -302,6 +324,11 @@ static const struct xfs_btree_ops xfs_inobt_ops = {
302 .init_ptr_from_cur = xfs_inobt_init_ptr_from_cur, 324 .init_ptr_from_cur = xfs_inobt_init_ptr_from_cur,
303 .key_diff = xfs_inobt_key_diff, 325 .key_diff = xfs_inobt_key_diff,
304 326
327#ifdef DEBUG
328 .keys_inorder = xfs_inobt_keys_inorder,
329 .recs_inorder = xfs_inobt_recs_inorder,
330#endif
331
305#ifdef XFS_BTREE_TRACE 332#ifdef XFS_BTREE_TRACE
306 .trace_enter = xfs_inobt_trace_enter, 333 .trace_enter = xfs_inobt_trace_enter,
307 .trace_cursor = xfs_inobt_trace_cursor, 334 .trace_cursor = xfs_inobt_trace_cursor,