Commit 0b48db80ba689edfd96ed06c3124d6cf1146de3f

Authored by Dave Chinner
Committed by Felix Blyakher
1 parent afabc24a73

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>

Showing 1 changed file with 56 additions and 75 deletions Side-by-side Diff

... ... @@ -148,6 +148,47 @@
148 148 }
149 149  
150 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 +
  191 +/*
151 192 * Initialise a new set of inodes.
152 193 */
153 194 STATIC void
... ... @@ -548,6 +589,7 @@
548 589 }
549 590 }
550 591  
  592 +
551 593 /*
552 594 * Visible inode allocation functions.
553 595 */
554 596  
555 597  
... ... @@ -733,27 +775,11 @@
733 775 */
734 776 if (!pagino)
735 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)))
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;
752 782  
753   - ASSERT(freecount == be32_to_cpu(agi->agi_freecount) ||
754   - XFS_FORCED_SHUTDOWN(mp));
755   - }
756   -#endif
757 783 /*
758 784 * If in the same a.g. as the parent, try to get near the parent.
759 785 */
760 786  
... ... @@ -951,25 +977,11 @@
951 977 down_read(&mp->m_peraglock);
952 978 mp->m_perag[tagno].pagi_freecount--;
953 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)))
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 +
973 985 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
974 986 xfs_trans_mod_sb(tp, XFS_TRANS_SB_IFREE, -1);
975 987 *inop = ino;
976 988  
... ... @@ -1060,26 +1072,11 @@
1060 1072 * Initialize the cursor.
1061 1073 */
1062 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)))
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 +
1083 1080 /*
1084 1081 * Look for the entry describing this inode.
1085 1082 */
1086 1083  
... ... @@ -1165,26 +1162,10 @@
1165 1162 xfs_trans_mod_sb(tp, XFS_TRANS_SB_IFREE, 1);
1166 1163 }
1167 1164  
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;
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 1169 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
1189 1170 return 0;
1190 1171