Skip to content

Commit 0b48db8

Browse files
Dave ChinnerFelix Blyakher
authored andcommitted
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>
1 parent afabc24 commit 0b48db8

File tree

1 file changed

+56
-75
lines changed

1 file changed

+56
-75
lines changed

fs/xfs/xfs_ialloc.c

Lines changed: 56 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,47 @@ xfs_inobt_get_rec(
147147
return error;
148148
}
149149

150+
/*
151+
* Verify that the number of free inodes in the AGI is correct.
152+
*/
153+
#ifdef DEBUG
154+
STATIC int
155+
xfs_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+
150191
/*
151192
* Initialise a new set of inodes.
152193
*/
@@ -548,6 +589,7 @@ xfs_ialloc_ag_select(
548589
}
549590
}
550591

592+
551593
/*
552594
* Visible inode allocation functions.
553595
*/
@@ -733,27 +775,11 @@ xfs_dialloc(
733775
*/
734776
if (!pagino)
735777
pagino = be32_to_cpu(agi->agi_newino);
736-
#ifdef DEBUG
737-
if (cur->bc_nlevels == 1) {
738-
int freecount = 0;
739778

740-
if ((error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &i)))
741-
goto error0;
742-
XFS_WANT_CORRUPTED_GOTO(i == 1, 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);
779+
error = xfs_check_agi_freecount(cur, agi);
780+
if (error)
781+
goto error0;
752782

753-
ASSERT(freecount == be32_to_cpu(agi->agi_freecount) ||
754-
XFS_FORCED_SHUTDOWN(mp));
755-
}
756-
#endif
757783
/*
758784
* If in the same a.g. as the parent, try to get near the parent.
759785
*/
@@ -951,25 +977,11 @@ xfs_dialloc(
951977
down_read(&mp->m_peraglock);
952978
mp->m_perag[tagno].pagi_freecount--;
953979
up_read(&mp->m_peraglock);
954-
#ifdef DEBUG
955-
if (cur->bc_nlevels == 1) {
956-
int freecount = 0;
957980

958-
if ((error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &i)))
959-
goto error0;
960-
do {
961-
error = xfs_inobt_get_rec(cur, &rec, &i);
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
981+
error = xfs_check_agi_freecount(cur, agi);
982+
if (error)
983+
goto error0;
984+
973985
xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
974986
xfs_trans_mod_sb(tp, XFS_TRANS_SB_IFREE, -1);
975987
*inop = ino;
@@ -1060,26 +1072,11 @@ xfs_difree(
10601072
* Initialize the cursor.
10611073
*/
10621074
cur = xfs_inobt_init_cursor(mp, tp, agbp, agno);
1063-
#ifdef DEBUG
1064-
if (cur->bc_nlevels == 1) {
1065-
int freecount = 0;
10661075

1067-
if ((error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &i)))
1068-
goto error0;
1069-
do {
1070-
error = xfs_inobt_get_rec(cur, &rec, &i);
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
1076+
error = xfs_check_agi_freecount(cur, agi);
1077+
if (error)
1078+
goto error0;
1079+
10831080
/*
10841081
* Look for the entry describing this inode.
10851082
*/
@@ -1165,26 +1162,10 @@ xfs_difree(
11651162
xfs_trans_mod_sb(tp, XFS_TRANS_SB_IFREE, 1);
11661163
}
11671164

1168-
#ifdef DEBUG
1169-
if (cur->bc_nlevels == 1) {
1170-
int freecount = 0;
1165+
error = xfs_check_agi_freecount(cur, agi);
1166+
if (error)
1167+
goto error0;
11711168

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
11881169
xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
11891170
return 0;
11901171

0 commit comments

Comments
 (0)