aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/quota/xfs_qm_syscalls.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2011-07-13 07:43:50 -0400
committerChristoph Hellwig <hch@lst.de>2011-07-13 07:43:50 -0400
commitea15ab3cdda1bc6822f572ce9ce5d86f097f9b08 (patch)
tree1fddbe64d7f6d9150bdb86a9579c8f5feb94f734 /fs/xfs/quota/xfs_qm_syscalls.c
parent54244fec67024032cb54eb604b2a36579b5db2d3 (diff)
xfs: remove the dead QUOTADEBUG code
Remove the dead hash table test rid which has been rotting away under QUOTADEBUG, including some code that was compiled for normal debug builds, but not actually called without QUOTADEBUG, and enable a few cheap debug checks that were hidden under QUOTADEBUG for normal debug builds. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Alex Elder <aelder@sgi.com> Reviewed-by: Dave Chinner <dchinner@redhat.com>
Diffstat (limited to 'fs/xfs/quota/xfs_qm_syscalls.c')
-rw-r--r--fs/xfs/quota/xfs_qm_syscalls.c353
1 files changed, 0 insertions, 353 deletions
diff --git a/fs/xfs/quota/xfs_qm_syscalls.c b/fs/xfs/quota/xfs_qm_syscalls.c
index f2dfc74ccf34..609246f42e6c 100644
--- a/fs/xfs/quota/xfs_qm_syscalls.c
+++ b/fs/xfs/quota/xfs_qm_syscalls.c
@@ -622,7 +622,6 @@ xfs_qm_scall_setqlim(
622 xfs_trans_log_dquot(tp, dqp); 622 xfs_trans_log_dquot(tp, dqp);
623 623
624 error = xfs_trans_commit(tp, 0); 624 error = xfs_trans_commit(tp, 0);
625 xfs_qm_dqprint(dqp);
626 xfs_qm_dqrele(dqp); 625 xfs_qm_dqrele(dqp);
627 626
628 out_unlock: 627 out_unlock:
@@ -657,7 +656,6 @@ xfs_qm_scall_getquota(
657 xfs_qm_dqput(dqp); 656 xfs_qm_dqput(dqp);
658 return XFS_ERROR(ENOENT); 657 return XFS_ERROR(ENOENT);
659 } 658 }
660 /* xfs_qm_dqprint(dqp); */
661 /* 659 /*
662 * Convert the disk dquot to the exportable format 660 * Convert the disk dquot to the exportable format
663 */ 661 */
@@ -906,354 +904,3 @@ xfs_qm_dqrele_all_inodes(
906 ASSERT(mp->m_quotainfo); 904 ASSERT(mp->m_quotainfo);
907 xfs_inode_ag_iterator(mp, xfs_dqrele_inode, flags); 905 xfs_inode_ag_iterator(mp, xfs_dqrele_inode, flags);
908} 906}
909
910/*------------------------------------------------------------------------*/
911#ifdef DEBUG
912/*
913 * This contains all the test functions for XFS disk quotas.
914 * Currently it does a quota accounting check. ie. it walks through
915 * all inodes in the file system, calculating the dquot accounting fields,
916 * and prints out any inconsistencies.
917 */
918xfs_dqhash_t *qmtest_udqtab;
919xfs_dqhash_t *qmtest_gdqtab;
920int qmtest_hashmask;
921int qmtest_nfails;
922struct mutex qcheck_lock;
923
924#define DQTEST_HASHVAL(mp, id) (((__psunsigned_t)(mp) + \
925 (__psunsigned_t)(id)) & \
926 (qmtest_hashmask - 1))
927
928#define DQTEST_HASH(mp, id, type) ((type & XFS_DQ_USER) ? \
929 (qmtest_udqtab + \
930 DQTEST_HASHVAL(mp, id)) : \
931 (qmtest_gdqtab + \
932 DQTEST_HASHVAL(mp, id)))
933
934#define DQTEST_LIST_PRINT(l, NXT, title) \
935{ \
936 xfs_dqtest_t *dqp; int i = 0;\
937 xfs_debug(NULL, "%s (#%d)", title, (int) (l)->qh_nelems); \
938 for (dqp = (xfs_dqtest_t *)(l)->qh_next; dqp != NULL; \
939 dqp = (xfs_dqtest_t *)dqp->NXT) { \
940 xfs_debug(dqp->q_mount, \
941 " %d. \"%d (%s)\" bcnt = %d, icnt = %d", \
942 ++i, dqp->d_id, DQFLAGTO_TYPESTR(dqp), \
943 dqp->d_bcount, dqp->d_icount); } \
944}
945
946typedef struct dqtest {
947 uint dq_flags; /* various flags (XFS_DQ_*) */
948 struct list_head q_hashlist;
949 xfs_dqhash_t *q_hash; /* the hashchain header */
950 xfs_mount_t *q_mount; /* filesystem this relates to */
951 xfs_dqid_t d_id; /* user id or group id */
952 xfs_qcnt_t d_bcount; /* # disk blocks owned by the user */
953 xfs_qcnt_t d_icount; /* # inodes owned by the user */
954} xfs_dqtest_t;
955
956STATIC void
957xfs_qm_hashinsert(xfs_dqhash_t *h, xfs_dqtest_t *dqp)
958{
959 list_add(&dqp->q_hashlist, &h->qh_list);
960 h->qh_version++;
961 h->qh_nelems++;
962}
963STATIC void
964xfs_qm_dqtest_print(
965 struct xfs_mount *mp,
966 struct dqtest *d)
967{
968 xfs_debug(mp, "-----------DQTEST DQUOT----------------");
969 xfs_debug(mp, "---- dquot ID = %d", d->d_id);
970 xfs_debug(mp, "---- fs = 0x%p", d->q_mount);
971 xfs_debug(mp, "---- bcount = %Lu (0x%x)",
972 d->d_bcount, (int)d->d_bcount);
973 xfs_debug(mp, "---- icount = %Lu (0x%x)",
974 d->d_icount, (int)d->d_icount);
975 xfs_debug(mp, "---------------------------");
976}
977
978STATIC void
979xfs_qm_dqtest_failed(
980 xfs_dqtest_t *d,
981 xfs_dquot_t *dqp,
982 char *reason,
983 xfs_qcnt_t a,
984 xfs_qcnt_t b,
985 int error)
986{
987 qmtest_nfails++;
988 if (error)
989 xfs_debug(dqp->q_mount,
990 "quotacheck failed id=%d, err=%d\nreason: %s",
991 d->d_id, error, reason);
992 else
993 xfs_debug(dqp->q_mount,
994 "quotacheck failed id=%d (%s) [%d != %d]",
995 d->d_id, reason, (int)a, (int)b);
996 xfs_qm_dqtest_print(dqp->q_mount, d);
997 if (dqp)
998 xfs_qm_dqprint(dqp);
999}
1000
1001STATIC int
1002xfs_dqtest_cmp2(
1003 xfs_dqtest_t *d,
1004 xfs_dquot_t *dqp)
1005{
1006 int err = 0;
1007 if (be64_to_cpu(dqp->q_core.d_icount) != d->d_icount) {
1008 xfs_qm_dqtest_failed(d, dqp, "icount mismatch",
1009 be64_to_cpu(dqp->q_core.d_icount),
1010 d->d_icount, 0);
1011 err++;
1012 }
1013 if (be64_to_cpu(dqp->q_core.d_bcount) != d->d_bcount) {
1014 xfs_qm_dqtest_failed(d, dqp, "bcount mismatch",
1015 be64_to_cpu(dqp->q_core.d_bcount),
1016 d->d_bcount, 0);
1017 err++;
1018 }
1019 if (dqp->q_core.d_blk_softlimit &&
1020 be64_to_cpu(dqp->q_core.d_bcount) >=
1021 be64_to_cpu(dqp->q_core.d_blk_softlimit)) {
1022 if (!dqp->q_core.d_btimer && dqp->q_core.d_id) {
1023 xfs_debug(dqp->q_mount,
1024 "%d [%s] BLK TIMER NOT STARTED",
1025 d->d_id, DQFLAGTO_TYPESTR(d));
1026 err++;
1027 }
1028 }
1029 if (dqp->q_core.d_ino_softlimit &&
1030 be64_to_cpu(dqp->q_core.d_icount) >=
1031 be64_to_cpu(dqp->q_core.d_ino_softlimit)) {
1032 if (!dqp->q_core.d_itimer && dqp->q_core.d_id) {
1033 xfs_debug(dqp->q_mount,
1034 "%d [%s] INO TIMER NOT STARTED",
1035 d->d_id, DQFLAGTO_TYPESTR(d));
1036 err++;
1037 }
1038 }
1039#ifdef QUOTADEBUG
1040 if (!err) {
1041 xfs_debug(dqp->q_mount, "%d [%s] qchecked",
1042 d->d_id, DQFLAGTO_TYPESTR(d));
1043 }
1044#endif
1045 return (err);
1046}
1047
1048STATIC void
1049xfs_dqtest_cmp(
1050 xfs_dqtest_t *d)
1051{
1052 xfs_dquot_t *dqp;
1053 int error;
1054
1055 /* xfs_qm_dqtest_print(d); */
1056 if ((error = xfs_qm_dqget(d->q_mount, NULL, d->d_id, d->dq_flags, 0,
1057 &dqp))) {
1058 xfs_qm_dqtest_failed(d, NULL, "dqget failed", 0, 0, error);
1059 return;
1060 }
1061 xfs_dqtest_cmp2(d, dqp);
1062 xfs_qm_dqput(dqp);
1063}
1064
1065STATIC int
1066xfs_qm_internalqcheck_dqget(
1067 xfs_mount_t *mp,
1068 xfs_dqid_t id,
1069 uint type,
1070 xfs_dqtest_t **O_dq)
1071{
1072 xfs_dqtest_t *d;
1073 xfs_dqhash_t *h;
1074
1075 h = DQTEST_HASH(mp, id, type);
1076 list_for_each_entry(d, &h->qh_list, q_hashlist) {
1077 if (d->d_id == id && mp == d->q_mount) {
1078 *O_dq = d;
1079 return (0);
1080 }
1081 }
1082 d = kmem_zalloc(sizeof(xfs_dqtest_t), KM_SLEEP);
1083 d->dq_flags = type;
1084 d->d_id = id;
1085 d->q_mount = mp;
1086 d->q_hash = h;
1087 INIT_LIST_HEAD(&d->q_hashlist);
1088 xfs_qm_hashinsert(h, d);
1089 *O_dq = d;
1090 return (0);
1091}
1092
1093STATIC void
1094xfs_qm_internalqcheck_get_dquots(
1095 xfs_mount_t *mp,
1096 xfs_dqid_t uid,
1097 xfs_dqid_t projid,
1098 xfs_dqid_t gid,
1099 xfs_dqtest_t **ud,
1100 xfs_dqtest_t **gd)
1101{
1102 if (XFS_IS_UQUOTA_ON(mp))
1103 xfs_qm_internalqcheck_dqget(mp, uid, XFS_DQ_USER, ud);
1104 if (XFS_IS_GQUOTA_ON(mp))
1105 xfs_qm_internalqcheck_dqget(mp, gid, XFS_DQ_GROUP, gd);
1106 else if (XFS_IS_PQUOTA_ON(mp))
1107 xfs_qm_internalqcheck_dqget(mp, projid, XFS_DQ_PROJ, gd);
1108}
1109
1110
1111STATIC void
1112xfs_qm_internalqcheck_dqadjust(
1113 xfs_inode_t *ip,
1114 xfs_dqtest_t *d)
1115{
1116 d->d_icount++;
1117 d->d_bcount += (xfs_qcnt_t)ip->i_d.di_nblocks;
1118}
1119
1120STATIC int
1121xfs_qm_internalqcheck_adjust(
1122 xfs_mount_t *mp, /* mount point for filesystem */
1123 xfs_ino_t ino, /* inode number to get data for */
1124 void __user *buffer, /* not used */
1125 int ubsize, /* not used */
1126 int *ubused, /* not used */
1127 int *res) /* bulkstat result code */
1128{
1129 xfs_inode_t *ip;
1130 xfs_dqtest_t *ud, *gd;
1131 uint lock_flags;
1132 boolean_t ipreleased;
1133 int error;
1134
1135 ASSERT(XFS_IS_QUOTA_RUNNING(mp));
1136
1137 if (ino == mp->m_sb.sb_uquotino || ino == mp->m_sb.sb_gquotino) {
1138 *res = BULKSTAT_RV_NOTHING;
1139 xfs_debug(mp, "%s: ino=%llu, uqino=%llu, gqino=%llu\n",
1140 __func__, (unsigned long long) ino,
1141 (unsigned long long) mp->m_sb.sb_uquotino,
1142 (unsigned long long) mp->m_sb.sb_gquotino);
1143 return XFS_ERROR(EINVAL);
1144 }
1145 ipreleased = B_FALSE;
1146 again:
1147 lock_flags = XFS_ILOCK_SHARED;
1148 if ((error = xfs_iget(mp, NULL, ino, 0, lock_flags, &ip))) {
1149 *res = BULKSTAT_RV_NOTHING;
1150 return (error);
1151 }
1152
1153 /*
1154 * This inode can have blocks after eof which can get released
1155 * when we send it to inactive. Since we don't check the dquot
1156 * until the after all our calculations are done, we must get rid
1157 * of those now.
1158 */
1159 if (! ipreleased) {
1160 xfs_iunlock(ip, lock_flags);
1161 IRELE(ip);
1162 ipreleased = B_TRUE;
1163 goto again;
1164 }
1165 xfs_qm_internalqcheck_get_dquots(mp,
1166 (xfs_dqid_t) ip->i_d.di_uid,
1167 (xfs_dqid_t) xfs_get_projid(ip),
1168 (xfs_dqid_t) ip->i_d.di_gid,
1169 &ud, &gd);
1170 if (XFS_IS_UQUOTA_ON(mp)) {
1171 ASSERT(ud);
1172 xfs_qm_internalqcheck_dqadjust(ip, ud);
1173 }
1174 if (XFS_IS_OQUOTA_ON(mp)) {
1175 ASSERT(gd);
1176 xfs_qm_internalqcheck_dqadjust(ip, gd);
1177 }
1178 xfs_iunlock(ip, lock_flags);
1179 IRELE(ip);
1180 *res = BULKSTAT_RV_DIDONE;
1181 return (0);
1182}
1183
1184
1185/* PRIVATE, debugging */
1186int
1187xfs_qm_internalqcheck(
1188 xfs_mount_t *mp)
1189{
1190 xfs_ino_t lastino;
1191 int done, count;
1192 int i;
1193 int error;
1194
1195 lastino = 0;
1196 qmtest_hashmask = 32;
1197 count = 5;
1198 done = 0;
1199 qmtest_nfails = 0;
1200
1201 if (! XFS_IS_QUOTA_ON(mp))
1202 return XFS_ERROR(ESRCH);
1203
1204 xfs_log_force(mp, XFS_LOG_SYNC);
1205 XFS_bflush(mp->m_ddev_targp);
1206 xfs_log_force(mp, XFS_LOG_SYNC);
1207 XFS_bflush(mp->m_ddev_targp);
1208
1209 mutex_lock(&qcheck_lock);
1210 /* There should be absolutely no quota activity while this
1211 is going on. */
1212 qmtest_udqtab = kmem_zalloc(qmtest_hashmask *
1213 sizeof(xfs_dqhash_t), KM_SLEEP);
1214 qmtest_gdqtab = kmem_zalloc(qmtest_hashmask *
1215 sizeof(xfs_dqhash_t), KM_SLEEP);
1216 do {
1217 /*
1218 * Iterate thru all the inodes in the file system,
1219 * adjusting the corresponding dquot counters
1220 */
1221 error = xfs_bulkstat(mp, &lastino, &count,
1222 xfs_qm_internalqcheck_adjust,
1223 0, NULL, &done);
1224 if (error) {
1225 xfs_debug(mp, "Bulkstat returned error 0x%x", error);
1226 break;
1227 }
1228 } while (!done);
1229
1230 xfs_debug(mp, "Checking results against system dquots");
1231 for (i = 0; i < qmtest_hashmask; i++) {
1232 xfs_dqtest_t *d, *n;
1233 xfs_dqhash_t *h;
1234
1235 h = &qmtest_udqtab[i];
1236 list_for_each_entry_safe(d, n, &h->qh_list, q_hashlist) {
1237 xfs_dqtest_cmp(d);
1238 kmem_free(d);
1239 }
1240 h = &qmtest_gdqtab[i];
1241 list_for_each_entry_safe(d, n, &h->qh_list, q_hashlist) {
1242 xfs_dqtest_cmp(d);
1243 kmem_free(d);
1244 }
1245 }
1246
1247 if (qmtest_nfails) {
1248 xfs_debug(mp, "******** quotacheck failed ********");
1249 xfs_debug(mp, "failures = %d", qmtest_nfails);
1250 } else {
1251 xfs_debug(mp, "******** quotacheck successful! ********");
1252 }
1253 kmem_free(qmtest_udqtab);
1254 kmem_free(qmtest_gdqtab);
1255 mutex_unlock(&qcheck_lock);
1256 return (qmtest_nfails);
1257}
1258
1259#endif /* DEBUG */