aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorDave Chinner <dgc@sgi.com>2009-08-31 19:57:09 -0400
committerFelix Blyakher <felixb@sgi.com>2009-09-01 13:45:18 -0400
commit0b48db80ba689edfd96ed06c3124d6cf1146de3f (patch)
treed145e86f4bb459fc5462e7b97aeec4b01c55a7d6 /fs
parentafabc24a73bfee2656724b0a70395f1693eaa62b (diff)
xfs: factor out debug checks from xfs_dialloc and xfs_difree
Factor out a common helper from repeated debug checks in xfs_dialloc and xfs_difree. [hch: split out from Dave's dynamic allocation policy patches] Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Alex Elder <aelder@sgi.com> Signed-off-by: Felix Blyakher <felixb@sgi.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/xfs/xfs_ialloc.c131
1 files changed, 56 insertions, 75 deletions
diff --git a/fs/xfs/xfs_ialloc.c b/fs/xfs/xfs_ialloc.c
index 8819cdacf702..18bf6eece54d 100644
--- a/fs/xfs/xfs_ialloc.c
+++ b/fs/xfs/xfs_ialloc.c
@@ -148,6 +148,47 @@ xfs_inobt_get_rec(
148} 148}
149 149
150/* 150/*
151 * Verify that the number of free inodes in the AGI is correct.
152 */
153#ifdef DEBUG
154STATIC int
155xfs_check_agi_freecount(
156 struct xfs_btree_cur *cur,
157 struct xfs_agi *agi)
158{
159 if (cur->bc_nlevels == 1) {
160 xfs_inobt_rec_incore_t rec;
161 int freecount = 0;
162 int error;
163 int i;
164
165 error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &i);
166 if (error)
167 return error;
168
169 do {
170 error = xfs_inobt_get_rec(cur, &rec, &i);
171 if (error)
172 return error;
173
174 if (i) {
175 freecount += rec.ir_freecount;
176 error = xfs_btree_increment(cur, 0, &i);
177 if (error)
178 return error;
179 }
180 } while (i == 1);
181
182 if (!XFS_FORCED_SHUTDOWN(cur->bc_mp))
183 ASSERT(freecount == be32_to_cpu(agi->agi_freecount));
184 }
185 return 0;
186}
187#else
188#define xfs_check_agi_freecount(cur, agi) 0
189#endif
190
191/*
151 * Initialise a new set of inodes. 192 * Initialise a new set of inodes.
152 */ 193 */
153STATIC void 194STATIC void
@@ -548,6 +589,7 @@ nextag:
548 } 589 }
549} 590}
550 591
592
551/* 593/*
552 * Visible inode allocation functions. 594 * Visible inode allocation functions.
553 */ 595 */
@@ -733,27 +775,11 @@ nextag:
733 */ 775 */
734 if (!pagino) 776 if (!pagino)
735 pagino = be32_to_cpu(agi->agi_newino); 777 pagino = be32_to_cpu(agi->agi_newino);
736#ifdef DEBUG
737 if (cur->bc_nlevels == 1) {
738 int freecount = 0;
739 778
740 if ((error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &i))) 779 error = xfs_check_agi_freecount(cur, agi);
741 goto error0; 780 if (error)
742 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 781 goto error0;
743 do {
744 error = xfs_inobt_get_rec(cur, &rec, &i);
745 if (error)
746 goto error0;
747 XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
748 freecount += rec.ir_freecount;
749 if ((error = xfs_btree_increment(cur, 0, &i)))
750 goto error0;
751 } while (i == 1);
752 782
753 ASSERT(freecount == be32_to_cpu(agi->agi_freecount) ||
754 XFS_FORCED_SHUTDOWN(mp));
755 }
756#endif
757 /* 783 /*
758 * If in the same a.g. as the parent, try to get near the parent. 784 * If in the same a.g. as the parent, try to get near the parent.
759 */ 785 */
@@ -951,25 +977,11 @@ nextag:
951 down_read(&mp->m_peraglock); 977 down_read(&mp->m_peraglock);
952 mp->m_perag[tagno].pagi_freecount--; 978 mp->m_perag[tagno].pagi_freecount--;
953 up_read(&mp->m_peraglock); 979 up_read(&mp->m_peraglock);
954#ifdef DEBUG
955 if (cur->bc_nlevels == 1) {
956 int freecount = 0;
957 980
958 if ((error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &i))) 981 error = xfs_check_agi_freecount(cur, agi);
959 goto error0; 982 if (error)
960 do { 983 goto error0;
961 error = xfs_inobt_get_rec(cur, &rec, &i); 984
962 if (error)
963 goto error0;
964 XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
965 freecount += rec.ir_freecount;
966 if ((error = xfs_btree_increment(cur, 0, &i)))
967 goto error0;
968 } while (i == 1);
969 ASSERT(freecount == be32_to_cpu(agi->agi_freecount) ||
970 XFS_FORCED_SHUTDOWN(mp));
971 }
972#endif
973 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR); 985 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
974 xfs_trans_mod_sb(tp, XFS_TRANS_SB_IFREE, -1); 986 xfs_trans_mod_sb(tp, XFS_TRANS_SB_IFREE, -1);
975 *inop = ino; 987 *inop = ino;
@@ -1060,26 +1072,11 @@ xfs_difree(
1060 * Initialize the cursor. 1072 * Initialize the cursor.
1061 */ 1073 */
1062 cur = xfs_inobt_init_cursor(mp, tp, agbp, agno); 1074 cur = xfs_inobt_init_cursor(mp, tp, agbp, agno);
1063#ifdef DEBUG
1064 if (cur->bc_nlevels == 1) {
1065 int freecount = 0;
1066 1075
1067 if ((error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &i))) 1076 error = xfs_check_agi_freecount(cur, agi);
1068 goto error0; 1077 if (error)
1069 do { 1078 goto error0;
1070 error = xfs_inobt_get_rec(cur, &rec, &i); 1079
1071 if (error)
1072 goto error0;
1073 if (i) {
1074 freecount += rec.ir_freecount;
1075 if ((error = xfs_btree_increment(cur, 0, &i)))
1076 goto error0;
1077 }
1078 } while (i == 1);
1079 ASSERT(freecount == be32_to_cpu(agi->agi_freecount) ||
1080 XFS_FORCED_SHUTDOWN(mp));
1081 }
1082#endif
1083 /* 1080 /*
1084 * Look for the entry describing this inode. 1081 * Look for the entry describing this inode.
1085 */ 1082 */
@@ -1165,26 +1162,10 @@ xfs_difree(
1165 xfs_trans_mod_sb(tp, XFS_TRANS_SB_IFREE, 1); 1162 xfs_trans_mod_sb(tp, XFS_TRANS_SB_IFREE, 1);
1166 } 1163 }
1167 1164
1168#ifdef DEBUG 1165 error = xfs_check_agi_freecount(cur, agi);
1169 if (cur->bc_nlevels == 1) { 1166 if (error)
1170 int freecount = 0; 1167 goto error0;
1171 1168
1172 if ((error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &i)))
1173 goto error0;
1174 do {
1175 error = xfs_inobt_get_rec(cur, &rec, &i);
1176 if (error)
1177 goto error0;
1178 if (i) {
1179 freecount += rec.ir_freecount;
1180 if ((error = xfs_btree_increment(cur, 0, &i)))
1181 goto error0;
1182 }
1183 } while (i == 1);
1184 ASSERT(freecount == be32_to_cpu(agi->agi_freecount) ||
1185 XFS_FORCED_SHUTDOWN(mp));
1186 }
1187#endif
1188 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR); 1169 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
1189 return 0; 1170 return 0;
1190 1171