Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Nathan Scott | 4ce3121 | 2005-11-02 14:59:41 +1100 | [diff] [blame] | 2 | * Copyright (c) 2000-2005 Silicon Graphics, Inc. |
| 3 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Nathan Scott | 4ce3121 | 2005-11-02 14:59:41 +1100 | [diff] [blame] | 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * published by the Free Software Foundation. |
| 8 | * |
Nathan Scott | 4ce3121 | 2005-11-02 14:59:41 +1100 | [diff] [blame] | 9 | * This program is distributed in the hope that it would be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
Nathan Scott | 4ce3121 | 2005-11-02 14:59:41 +1100 | [diff] [blame] | 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write the Free Software Foundation, |
| 16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
Randy Dunlap | 16f7e0f | 2006-01-11 12:17:46 -0800 | [diff] [blame] | 18 | |
| 19 | #include <linux/capability.h> |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include "xfs.h" |
| 22 | #include "xfs_fs.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 23 | #include "xfs_bit.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include "xfs_log.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 25 | #include "xfs_inum.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include "xfs_trans.h" |
| 27 | #include "xfs_sb.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 28 | #include "xfs_ag.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include "xfs_alloc.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include "xfs_quota.h" |
| 31 | #include "xfs_mount.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include "xfs_bmap_btree.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include "xfs_inode.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 34 | #include "xfs_itable.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include "xfs_bmap.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include "xfs_rtalloc.h" |
| 37 | #include "xfs_error.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include "xfs_attr.h" |
| 39 | #include "xfs_buf_item.h" |
| 40 | #include "xfs_utils.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include "xfs_qm.h" |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 42 | #include "xfs_trace.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | #ifdef DEBUG |
| 45 | # define qdprintk(s, args...) cmn_err(CE_DEBUG, s, ## args) |
| 46 | #else |
| 47 | # define qdprintk(s, args...) do { } while (0) |
| 48 | #endif |
| 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | STATIC int xfs_qm_log_quotaoff(xfs_mount_t *, xfs_qoff_logitem_t **, uint); |
| 51 | STATIC int xfs_qm_log_quotaoff_end(xfs_mount_t *, xfs_qoff_logitem_t *, |
| 52 | uint); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | STATIC uint xfs_qm_export_flags(uint); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | STATIC uint xfs_qm_export_qtype_flags(uint); |
| 55 | STATIC void xfs_qm_export_dquot(xfs_mount_t *, xfs_disk_dquot_t *, |
| 56 | fs_disk_quota_t *); |
| 57 | |
| 58 | |
| 59 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | * Turn off quota accounting and/or enforcement for all udquots and/or |
| 61 | * gdquots. Called only at unmount time. |
| 62 | * |
| 63 | * This assumes that there are no dquots of this file system cached |
| 64 | * incore, and modifies the ondisk dquot directly. Therefore, for example, |
| 65 | * it is an error to call this twice, without purging the cache. |
| 66 | */ |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 67 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | xfs_qm_scall_quotaoff( |
| 69 | xfs_mount_t *mp, |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 70 | uint flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 72 | struct xfs_quotainfo *q = mp->m_quotainfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | uint dqtype; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | int error; |
| 75 | uint inactivate_flags; |
| 76 | xfs_qoff_logitem_t *qoffstart; |
| 77 | int nculprits; |
| 78 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | /* |
| 80 | * No file system can have quotas enabled on disk but not in core. |
| 81 | * Note that quota utilities (like quotaoff) _expect_ |
| 82 | * errno == EEXIST here. |
| 83 | */ |
| 84 | if ((mp->m_qflags & flags) == 0) |
| 85 | return XFS_ERROR(EEXIST); |
| 86 | error = 0; |
| 87 | |
| 88 | flags &= (XFS_ALL_QUOTA_ACCT | XFS_ALL_QUOTA_ENFD); |
| 89 | |
| 90 | /* |
| 91 | * We don't want to deal with two quotaoffs messing up each other, |
| 92 | * so we're going to serialize it. quotaoff isn't exactly a performance |
| 93 | * critical thing. |
| 94 | * If quotaoff, then we must be dealing with the root filesystem. |
| 95 | */ |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 96 | ASSERT(q); |
| 97 | mutex_lock(&q->qi_quotaofflock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
| 99 | /* |
| 100 | * If we're just turning off quota enforcement, change mp and go. |
| 101 | */ |
| 102 | if ((flags & XFS_ALL_QUOTA_ACCT) == 0) { |
| 103 | mp->m_qflags &= ~(flags); |
| 104 | |
Eric Sandeen | 3685c2a | 2007-10-11 17:42:32 +1000 | [diff] [blame] | 105 | spin_lock(&mp->m_sb_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | mp->m_sb.sb_qflags = mp->m_qflags; |
Eric Sandeen | 3685c2a | 2007-10-11 17:42:32 +1000 | [diff] [blame] | 107 | spin_unlock(&mp->m_sb_lock); |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 108 | mutex_unlock(&q->qi_quotaofflock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
| 110 | /* XXX what to do if error ? Revert back to old vals incore ? */ |
| 111 | error = xfs_qm_write_sb_changes(mp, XFS_SB_QFLAGS); |
| 112 | return (error); |
| 113 | } |
| 114 | |
| 115 | dqtype = 0; |
| 116 | inactivate_flags = 0; |
| 117 | /* |
| 118 | * If accounting is off, we must turn enforcement off, clear the |
| 119 | * quota 'CHKD' certificate to make it known that we have to |
| 120 | * do a quotacheck the next time this quota is turned on. |
| 121 | */ |
| 122 | if (flags & XFS_UQUOTA_ACCT) { |
| 123 | dqtype |= XFS_QMOPT_UQUOTA; |
| 124 | flags |= (XFS_UQUOTA_CHKD | XFS_UQUOTA_ENFD); |
| 125 | inactivate_flags |= XFS_UQUOTA_ACTIVE; |
| 126 | } |
| 127 | if (flags & XFS_GQUOTA_ACCT) { |
| 128 | dqtype |= XFS_QMOPT_GQUOTA; |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 129 | flags |= (XFS_OQUOTA_CHKD | XFS_OQUOTA_ENFD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | inactivate_flags |= XFS_GQUOTA_ACTIVE; |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 131 | } else if (flags & XFS_PQUOTA_ACCT) { |
| 132 | dqtype |= XFS_QMOPT_PQUOTA; |
| 133 | flags |= (XFS_OQUOTA_CHKD | XFS_OQUOTA_ENFD); |
| 134 | inactivate_flags |= XFS_PQUOTA_ACTIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | /* |
| 138 | * Nothing to do? Don't complain. This happens when we're just |
| 139 | * turning off quota enforcement. |
| 140 | */ |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 141 | if ((mp->m_qflags & flags) == 0) |
| 142 | goto out_unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
| 144 | /* |
| 145 | * Write the LI_QUOTAOFF log record, and do SB changes atomically, |
David Chinner | cb6edc2 | 2008-04-10 12:20:45 +1000 | [diff] [blame] | 146 | * and synchronously. If we fail to write, we should abort the |
| 147 | * operation as it cannot be recovered safely if we crash. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | */ |
David Chinner | cb6edc2 | 2008-04-10 12:20:45 +1000 | [diff] [blame] | 149 | error = xfs_qm_log_quotaoff(mp, &qoffstart, flags); |
| 150 | if (error) |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 151 | goto out_unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
| 153 | /* |
| 154 | * Next we clear the XFS_MOUNT_*DQ_ACTIVE bit(s) in the mount struct |
| 155 | * to take care of the race between dqget and quotaoff. We don't take |
| 156 | * any special locks to reset these bits. All processes need to check |
| 157 | * these bits *after* taking inode lock(s) to see if the particular |
| 158 | * quota type is in the process of being turned off. If *ACTIVE, it is |
| 159 | * guaranteed that all dquot structures and all quotainode ptrs will all |
| 160 | * stay valid as long as that inode is kept locked. |
| 161 | * |
| 162 | * There is no turning back after this. |
| 163 | */ |
| 164 | mp->m_qflags &= ~inactivate_flags; |
| 165 | |
| 166 | /* |
| 167 | * Give back all the dquot reference(s) held by inodes. |
| 168 | * Here we go thru every single incore inode in this file system, and |
| 169 | * do a dqrele on the i_udquot/i_gdquot that it may have. |
| 170 | * Essentially, as long as somebody has an inode locked, this guarantees |
| 171 | * that quotas will not be turned off. This is handy because in a |
| 172 | * transaction once we lock the inode(s) and check for quotaon, we can |
| 173 | * depend on the quota inodes (and other things) being valid as long as |
| 174 | * we keep the lock(s). |
| 175 | */ |
| 176 | xfs_qm_dqrele_all_inodes(mp, flags); |
| 177 | |
| 178 | /* |
| 179 | * Next we make the changes in the quota flag in the mount struct. |
| 180 | * This isn't protected by a particular lock directly, because we |
| 181 | * don't want to take a mrlock everytime we depend on quotas being on. |
| 182 | */ |
| 183 | mp->m_qflags &= ~(flags); |
| 184 | |
| 185 | /* |
| 186 | * Go through all the dquots of this file system and purge them, |
| 187 | * according to what was turned off. We may not be able to get rid |
| 188 | * of all dquots, because dquots can have temporary references that |
| 189 | * are not attached to inodes. eg. xfs_setattr, xfs_create. |
| 190 | * So, if we couldn't purge all the dquots from the filesystem, |
| 191 | * we can't get rid of the incore data structures. |
| 192 | */ |
Christoph Hellwig | 8112e9d | 2010-04-20 17:02:29 +1000 | [diff] [blame] | 193 | while ((nculprits = xfs_qm_dqpurge_all(mp, dqtype))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | delay(10 * nculprits); |
| 195 | |
| 196 | /* |
| 197 | * Transactions that had started before ACTIVE state bit was cleared |
| 198 | * could have logged many dquots, so they'd have higher LSNs than |
| 199 | * the first QUOTAOFF log record does. If we happen to crash when |
| 200 | * the tail of the log has gone past the QUOTAOFF record, but |
| 201 | * before the last dquot modification, those dquots __will__ |
| 202 | * recover, and that's not good. |
| 203 | * |
| 204 | * So, we have QUOTAOFF start and end logitems; the start |
| 205 | * logitem won't get overwritten until the end logitem appears... |
| 206 | */ |
David Chinner | cb6edc2 | 2008-04-10 12:20:45 +1000 | [diff] [blame] | 207 | error = xfs_qm_log_quotaoff_end(mp, qoffstart, flags); |
| 208 | if (error) { |
| 209 | /* We're screwed now. Shutdown is the only option. */ |
| 210 | xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE); |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 211 | goto out_unlock; |
David Chinner | cb6edc2 | 2008-04-10 12:20:45 +1000 | [diff] [blame] | 212 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
| 214 | /* |
| 215 | * If quotas is completely disabled, close shop. |
| 216 | */ |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 217 | if (((flags & XFS_MOUNT_QUOTA_ALL) == XFS_MOUNT_QUOTA_SET1) || |
| 218 | ((flags & XFS_MOUNT_QUOTA_ALL) == XFS_MOUNT_QUOTA_SET2)) { |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 219 | mutex_unlock(&q->qi_quotaofflock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | xfs_qm_destroy_quotainfo(mp); |
| 221 | return (0); |
| 222 | } |
| 223 | |
| 224 | /* |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 225 | * Release our quotainode references if we don't need them anymore. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | */ |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 227 | if ((dqtype & XFS_QMOPT_UQUOTA) && q->qi_uquotaip) { |
| 228 | IRELE(q->qi_uquotaip); |
| 229 | q->qi_uquotaip = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | } |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 231 | if ((dqtype & (XFS_QMOPT_GQUOTA|XFS_QMOPT_PQUOTA)) && q->qi_gquotaip) { |
| 232 | IRELE(q->qi_gquotaip); |
| 233 | q->qi_gquotaip = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 236 | out_unlock: |
| 237 | mutex_unlock(&q->qi_quotaofflock); |
| 238 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Christoph Hellwig | 5d18898 | 2010-07-20 17:51:31 +1000 | [diff] [blame] | 241 | STATIC int |
| 242 | xfs_qm_scall_trunc_qfile( |
| 243 | struct xfs_mount *mp, |
| 244 | xfs_ino_t ino) |
| 245 | { |
| 246 | struct xfs_inode *ip; |
| 247 | struct xfs_trans *tp; |
| 248 | int error; |
| 249 | |
| 250 | if (ino == NULLFSINO) |
| 251 | return 0; |
| 252 | |
| 253 | error = xfs_iget(mp, NULL, ino, 0, 0, &ip); |
| 254 | if (error) |
| 255 | return error; |
| 256 | |
| 257 | xfs_ilock(ip, XFS_IOLOCK_EXCL); |
| 258 | |
| 259 | tp = xfs_trans_alloc(mp, XFS_TRANS_TRUNCATE_FILE); |
| 260 | error = xfs_trans_reserve(tp, 0, XFS_ITRUNCATE_LOG_RES(mp), 0, |
| 261 | XFS_TRANS_PERM_LOG_RES, |
| 262 | XFS_ITRUNCATE_LOG_COUNT); |
| 263 | if (error) { |
| 264 | xfs_trans_cancel(tp, 0); |
| 265 | xfs_iunlock(ip, XFS_IOLOCK_EXCL); |
| 266 | goto out_put; |
| 267 | } |
| 268 | |
| 269 | xfs_ilock(ip, XFS_ILOCK_EXCL); |
| 270 | xfs_trans_ijoin(tp, ip); |
| 271 | |
| 272 | error = xfs_itruncate_finish(&tp, ip, 0, XFS_DATA_FORK, 1); |
| 273 | if (error) { |
| 274 | xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES | |
| 275 | XFS_TRANS_ABORT); |
| 276 | goto out_unlock; |
| 277 | } |
| 278 | |
Dave Chinner | dcd79a1 | 2010-09-28 12:27:25 +1000 | [diff] [blame] | 279 | xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); |
Christoph Hellwig | 5d18898 | 2010-07-20 17:51:31 +1000 | [diff] [blame] | 280 | error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES); |
| 281 | |
| 282 | out_unlock: |
| 283 | xfs_iunlock(ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL); |
| 284 | out_put: |
| 285 | IRELE(ip); |
| 286 | return error; |
| 287 | } |
| 288 | |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 289 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | xfs_qm_scall_trunc_qfiles( |
| 291 | xfs_mount_t *mp, |
| 292 | uint flags) |
| 293 | { |
David Chinner | 88ab020 | 2008-04-10 12:20:51 +1000 | [diff] [blame] | 294 | int error = 0, error2 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | |
Eric Sandeen | 6211870 | 2008-03-06 13:44:28 +1100 | [diff] [blame] | 296 | if (!xfs_sb_version_hasquota(&mp->m_sb) || flags == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | qdprintk("qtrunc flags=%x m_qflags=%x\n", flags, mp->m_qflags); |
| 298 | return XFS_ERROR(EINVAL); |
| 299 | } |
| 300 | |
Christoph Hellwig | 5d18898 | 2010-07-20 17:51:31 +1000 | [diff] [blame] | 301 | if (flags & XFS_DQ_USER) |
| 302 | error = xfs_qm_scall_trunc_qfile(mp, mp->m_sb.sb_uquotino); |
| 303 | if (flags & (XFS_DQ_GROUP|XFS_DQ_PROJ)) |
| 304 | error2 = xfs_qm_scall_trunc_qfile(mp, mp->m_sb.sb_gquotino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
David Chinner | 88ab020 | 2008-04-10 12:20:51 +1000 | [diff] [blame] | 306 | return error ? error : error2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | } |
| 308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | /* |
| 310 | * Switch on (a given) quota enforcement for a filesystem. This takes |
| 311 | * effect immediately. |
| 312 | * (Switching on quota accounting must be done at mount time.) |
| 313 | */ |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 314 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | xfs_qm_scall_quotaon( |
| 316 | xfs_mount_t *mp, |
| 317 | uint flags) |
| 318 | { |
| 319 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | uint qf; |
| 321 | uint accflags; |
| 322 | __int64_t sbflags; |
| 323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | flags &= (XFS_ALL_QUOTA_ACCT | XFS_ALL_QUOTA_ENFD); |
| 325 | /* |
| 326 | * Switching on quota accounting must be done at mount time. |
| 327 | */ |
| 328 | accflags = flags & XFS_ALL_QUOTA_ACCT; |
| 329 | flags &= ~(XFS_ALL_QUOTA_ACCT); |
| 330 | |
| 331 | sbflags = 0; |
| 332 | |
| 333 | if (flags == 0) { |
| 334 | qdprintk("quotaon: zero flags, m_qflags=%x\n", mp->m_qflags); |
| 335 | return XFS_ERROR(EINVAL); |
| 336 | } |
| 337 | |
| 338 | /* No fs can turn on quotas with a delayed effect */ |
| 339 | ASSERT((flags & XFS_ALL_QUOTA_ACCT) == 0); |
| 340 | |
| 341 | /* |
| 342 | * Can't enforce without accounting. We check the superblock |
| 343 | * qflags here instead of m_qflags because rootfs can have |
| 344 | * quota acct on ondisk without m_qflags' knowing. |
| 345 | */ |
| 346 | if (((flags & XFS_UQUOTA_ACCT) == 0 && |
| 347 | (mp->m_sb.sb_qflags & XFS_UQUOTA_ACCT) == 0 && |
| 348 | (flags & XFS_UQUOTA_ENFD)) |
| 349 | || |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 350 | ((flags & XFS_PQUOTA_ACCT) == 0 && |
| 351 | (mp->m_sb.sb_qflags & XFS_PQUOTA_ACCT) == 0 && |
Donald Douwsma | 424ea91 | 2007-05-08 13:49:15 +1000 | [diff] [blame] | 352 | (flags & XFS_GQUOTA_ACCT) == 0 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | (mp->m_sb.sb_qflags & XFS_GQUOTA_ACCT) == 0 && |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 354 | (flags & XFS_OQUOTA_ENFD))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | qdprintk("Can't enforce without acct, flags=%x sbflags=%x\n", |
| 356 | flags, mp->m_sb.sb_qflags); |
| 357 | return XFS_ERROR(EINVAL); |
| 358 | } |
| 359 | /* |
| 360 | * If everything's upto-date incore, then don't waste time. |
| 361 | */ |
| 362 | if ((mp->m_qflags & flags) == flags) |
| 363 | return XFS_ERROR(EEXIST); |
| 364 | |
| 365 | /* |
| 366 | * Change sb_qflags on disk but not incore mp->qflags |
| 367 | * if this is the root filesystem. |
| 368 | */ |
Eric Sandeen | 3685c2a | 2007-10-11 17:42:32 +1000 | [diff] [blame] | 369 | spin_lock(&mp->m_sb_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | qf = mp->m_sb.sb_qflags; |
| 371 | mp->m_sb.sb_qflags = qf | flags; |
Eric Sandeen | 3685c2a | 2007-10-11 17:42:32 +1000 | [diff] [blame] | 372 | spin_unlock(&mp->m_sb_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
| 374 | /* |
| 375 | * There's nothing to change if it's the same. |
| 376 | */ |
| 377 | if ((qf & flags) == flags && sbflags == 0) |
| 378 | return XFS_ERROR(EEXIST); |
| 379 | sbflags |= XFS_SB_QFLAGS; |
| 380 | |
| 381 | if ((error = xfs_qm_write_sb_changes(mp, sbflags))) |
| 382 | return (error); |
| 383 | /* |
| 384 | * If we aren't trying to switch on quota enforcement, we are done. |
| 385 | */ |
| 386 | if (((mp->m_sb.sb_qflags & XFS_UQUOTA_ACCT) != |
| 387 | (mp->m_qflags & XFS_UQUOTA_ACCT)) || |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 388 | ((mp->m_sb.sb_qflags & XFS_PQUOTA_ACCT) != |
| 389 | (mp->m_qflags & XFS_PQUOTA_ACCT)) || |
| 390 | ((mp->m_sb.sb_qflags & XFS_GQUOTA_ACCT) != |
| 391 | (mp->m_qflags & XFS_GQUOTA_ACCT)) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | (flags & XFS_ALL_QUOTA_ENFD) == 0) |
| 393 | return (0); |
| 394 | |
| 395 | if (! XFS_IS_QUOTA_RUNNING(mp)) |
| 396 | return XFS_ERROR(ESRCH); |
| 397 | |
| 398 | /* |
| 399 | * Switch on quota enforcement in core. |
| 400 | */ |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 401 | mutex_lock(&mp->m_quotainfo->qi_quotaofflock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | mp->m_qflags |= (flags & XFS_ALL_QUOTA_ENFD); |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 403 | mutex_unlock(&mp->m_quotainfo->qi_quotaofflock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
| 405 | return (0); |
| 406 | } |
| 407 | |
| 408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | /* |
| 410 | * Return quota status information, such as uquota-off, enforcements, etc. |
| 411 | */ |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 412 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | xfs_qm_scall_getqstat( |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 414 | struct xfs_mount *mp, |
| 415 | struct fs_quota_stat *out) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | { |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 417 | struct xfs_quotainfo *q = mp->m_quotainfo; |
| 418 | struct xfs_inode *uip, *gip; |
| 419 | boolean_t tempuqip, tempgqip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | |
| 421 | uip = gip = NULL; |
| 422 | tempuqip = tempgqip = B_FALSE; |
| 423 | memset(out, 0, sizeof(fs_quota_stat_t)); |
| 424 | |
| 425 | out->qs_version = FS_QSTAT_VERSION; |
Eric Sandeen | 6211870 | 2008-03-06 13:44:28 +1100 | [diff] [blame] | 426 | if (!xfs_sb_version_hasquota(&mp->m_sb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | out->qs_uquota.qfs_ino = NULLFSINO; |
| 428 | out->qs_gquota.qfs_ino = NULLFSINO; |
| 429 | return (0); |
| 430 | } |
| 431 | out->qs_flags = (__uint16_t) xfs_qm_export_flags(mp->m_qflags & |
| 432 | (XFS_ALL_QUOTA_ACCT| |
| 433 | XFS_ALL_QUOTA_ENFD)); |
| 434 | out->qs_pad = 0; |
| 435 | out->qs_uquota.qfs_ino = mp->m_sb.sb_uquotino; |
| 436 | out->qs_gquota.qfs_ino = mp->m_sb.sb_gquotino; |
| 437 | |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 438 | if (q) { |
| 439 | uip = q->qi_uquotaip; |
| 440 | gip = q->qi_gquotaip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | } |
| 442 | if (!uip && mp->m_sb.sb_uquotino != NULLFSINO) { |
| 443 | if (xfs_iget(mp, NULL, mp->m_sb.sb_uquotino, |
Dave Chinner | 7b6259e | 2010-06-24 11:35:17 +1000 | [diff] [blame] | 444 | 0, 0, &uip) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | tempuqip = B_TRUE; |
| 446 | } |
| 447 | if (!gip && mp->m_sb.sb_gquotino != NULLFSINO) { |
| 448 | if (xfs_iget(mp, NULL, mp->m_sb.sb_gquotino, |
Dave Chinner | 7b6259e | 2010-06-24 11:35:17 +1000 | [diff] [blame] | 449 | 0, 0, &gip) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | tempgqip = B_TRUE; |
| 451 | } |
| 452 | if (uip) { |
| 453 | out->qs_uquota.qfs_nblks = uip->i_d.di_nblocks; |
| 454 | out->qs_uquota.qfs_nextents = uip->i_d.di_nextents; |
| 455 | if (tempuqip) |
Christoph Hellwig | 4335509 | 2008-03-27 18:01:08 +1100 | [diff] [blame] | 456 | IRELE(uip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | } |
| 458 | if (gip) { |
| 459 | out->qs_gquota.qfs_nblks = gip->i_d.di_nblocks; |
| 460 | out->qs_gquota.qfs_nextents = gip->i_d.di_nextents; |
| 461 | if (tempgqip) |
Christoph Hellwig | 4335509 | 2008-03-27 18:01:08 +1100 | [diff] [blame] | 462 | IRELE(gip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | } |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 464 | if (q) { |
| 465 | out->qs_incoredqs = q->qi_dquots; |
| 466 | out->qs_btimelimit = q->qi_btimelimit; |
| 467 | out->qs_itimelimit = q->qi_itimelimit; |
| 468 | out->qs_rtbtimelimit = q->qi_rtbtimelimit; |
| 469 | out->qs_bwarnlimit = q->qi_bwarnlimit; |
| 470 | out->qs_iwarnlimit = q->qi_iwarnlimit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | } |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 472 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | } |
| 474 | |
Christoph Hellwig | c472b43 | 2010-05-06 17:05:17 -0400 | [diff] [blame] | 475 | #define XFS_DQ_MASK \ |
| 476 | (FS_DQ_LIMIT_MASK | FS_DQ_TIMER_MASK | FS_DQ_WARNS_MASK) |
| 477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | /* |
| 479 | * Adjust quota limits, and start/stop timers accordingly. |
| 480 | */ |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 481 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | xfs_qm_scall_setqlim( |
| 483 | xfs_mount_t *mp, |
| 484 | xfs_dqid_t id, |
| 485 | uint type, |
| 486 | fs_disk_quota_t *newlim) |
| 487 | { |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 488 | struct xfs_quotainfo *q = mp->m_quotainfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | xfs_disk_dquot_t *ddq; |
| 490 | xfs_dquot_t *dqp; |
| 491 | xfs_trans_t *tp; |
| 492 | int error; |
| 493 | xfs_qcnt_t hard, soft; |
| 494 | |
Christoph Hellwig | c472b43 | 2010-05-06 17:05:17 -0400 | [diff] [blame] | 495 | if (newlim->d_fieldmask & ~XFS_DQ_MASK) |
| 496 | return EINVAL; |
| 497 | if ((newlim->d_fieldmask & XFS_DQ_MASK) == 0) |
| 498 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
| 500 | tp = xfs_trans_alloc(mp, XFS_TRANS_QM_SETQLIM); |
| 501 | if ((error = xfs_trans_reserve(tp, 0, sizeof(xfs_disk_dquot_t) + 128, |
| 502 | 0, 0, XFS_DEFAULT_LOG_COUNT))) { |
| 503 | xfs_trans_cancel(tp, 0); |
| 504 | return (error); |
| 505 | } |
| 506 | |
| 507 | /* |
| 508 | * We don't want to race with a quotaoff so take the quotaoff lock. |
| 509 | * (We don't hold an inode lock, so there's nothing else to stop |
| 510 | * a quotaoff from happening). (XXXThis doesn't currently happen |
| 511 | * because we take the vfslock before calling xfs_qm_sysent). |
| 512 | */ |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 513 | mutex_lock(&q->qi_quotaofflock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | |
| 515 | /* |
| 516 | * Get the dquot (locked), and join it to the transaction. |
| 517 | * Allocate the dquot if this doesn't exist. |
| 518 | */ |
| 519 | if ((error = xfs_qm_dqget(mp, NULL, id, type, XFS_QMOPT_DQALLOC, &dqp))) { |
| 520 | xfs_trans_cancel(tp, XFS_TRANS_ABORT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | ASSERT(error != ENOENT); |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 522 | goto out_unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | xfs_trans_dqjoin(tp, dqp); |
| 525 | ddq = &dqp->q_core; |
| 526 | |
| 527 | /* |
| 528 | * Make sure that hardlimits are >= soft limits before changing. |
| 529 | */ |
| 530 | hard = (newlim->d_fieldmask & FS_DQ_BHARD) ? |
| 531 | (xfs_qcnt_t) XFS_BB_TO_FSB(mp, newlim->d_blk_hardlimit) : |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 532 | be64_to_cpu(ddq->d_blk_hardlimit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | soft = (newlim->d_fieldmask & FS_DQ_BSOFT) ? |
| 534 | (xfs_qcnt_t) XFS_BB_TO_FSB(mp, newlim->d_blk_softlimit) : |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 535 | be64_to_cpu(ddq->d_blk_softlimit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | if (hard == 0 || hard >= soft) { |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 537 | ddq->d_blk_hardlimit = cpu_to_be64(hard); |
| 538 | ddq->d_blk_softlimit = cpu_to_be64(soft); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | if (id == 0) { |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 540 | q->qi_bhardlimit = hard; |
| 541 | q->qi_bsoftlimit = soft; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | } |
| 543 | } else { |
| 544 | qdprintk("blkhard %Ld < blksoft %Ld\n", hard, soft); |
| 545 | } |
| 546 | hard = (newlim->d_fieldmask & FS_DQ_RTBHARD) ? |
| 547 | (xfs_qcnt_t) XFS_BB_TO_FSB(mp, newlim->d_rtb_hardlimit) : |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 548 | be64_to_cpu(ddq->d_rtb_hardlimit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | soft = (newlim->d_fieldmask & FS_DQ_RTBSOFT) ? |
| 550 | (xfs_qcnt_t) XFS_BB_TO_FSB(mp, newlim->d_rtb_softlimit) : |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 551 | be64_to_cpu(ddq->d_rtb_softlimit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | if (hard == 0 || hard >= soft) { |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 553 | ddq->d_rtb_hardlimit = cpu_to_be64(hard); |
| 554 | ddq->d_rtb_softlimit = cpu_to_be64(soft); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | if (id == 0) { |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 556 | q->qi_rtbhardlimit = hard; |
| 557 | q->qi_rtbsoftlimit = soft; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | } |
| 559 | } else { |
| 560 | qdprintk("rtbhard %Ld < rtbsoft %Ld\n", hard, soft); |
| 561 | } |
| 562 | |
| 563 | hard = (newlim->d_fieldmask & FS_DQ_IHARD) ? |
| 564 | (xfs_qcnt_t) newlim->d_ino_hardlimit : |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 565 | be64_to_cpu(ddq->d_ino_hardlimit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | soft = (newlim->d_fieldmask & FS_DQ_ISOFT) ? |
| 567 | (xfs_qcnt_t) newlim->d_ino_softlimit : |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 568 | be64_to_cpu(ddq->d_ino_softlimit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | if (hard == 0 || hard >= soft) { |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 570 | ddq->d_ino_hardlimit = cpu_to_be64(hard); |
| 571 | ddq->d_ino_softlimit = cpu_to_be64(soft); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | if (id == 0) { |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 573 | q->qi_ihardlimit = hard; |
| 574 | q->qi_isoftlimit = soft; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | } |
| 576 | } else { |
| 577 | qdprintk("ihard %Ld < isoft %Ld\n", hard, soft); |
| 578 | } |
| 579 | |
Nathan Scott | 754002b | 2005-06-21 15:49:06 +1000 | [diff] [blame] | 580 | /* |
| 581 | * Update warnings counter(s) if requested |
| 582 | */ |
| 583 | if (newlim->d_fieldmask & FS_DQ_BWARNS) |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 584 | ddq->d_bwarns = cpu_to_be16(newlim->d_bwarns); |
Nathan Scott | 754002b | 2005-06-21 15:49:06 +1000 | [diff] [blame] | 585 | if (newlim->d_fieldmask & FS_DQ_IWARNS) |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 586 | ddq->d_iwarns = cpu_to_be16(newlim->d_iwarns); |
Nathan Scott | 754002b | 2005-06-21 15:49:06 +1000 | [diff] [blame] | 587 | if (newlim->d_fieldmask & FS_DQ_RTBWARNS) |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 588 | ddq->d_rtbwarns = cpu_to_be16(newlim->d_rtbwarns); |
Nathan Scott | 754002b | 2005-06-21 15:49:06 +1000 | [diff] [blame] | 589 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | if (id == 0) { |
| 591 | /* |
| 592 | * Timelimits for the super user set the relative time |
| 593 | * the other users can be over quota for this file system. |
| 594 | * If it is zero a default is used. Ditto for the default |
Nathan Scott | 754002b | 2005-06-21 15:49:06 +1000 | [diff] [blame] | 595 | * soft and hard limit values (already done, above), and |
| 596 | * for warnings. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | */ |
| 598 | if (newlim->d_fieldmask & FS_DQ_BTIMER) { |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 599 | q->qi_btimelimit = newlim->d_btimer; |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 600 | ddq->d_btimer = cpu_to_be32(newlim->d_btimer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | } |
| 602 | if (newlim->d_fieldmask & FS_DQ_ITIMER) { |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 603 | q->qi_itimelimit = newlim->d_itimer; |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 604 | ddq->d_itimer = cpu_to_be32(newlim->d_itimer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | } |
| 606 | if (newlim->d_fieldmask & FS_DQ_RTBTIMER) { |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 607 | q->qi_rtbtimelimit = newlim->d_rtbtimer; |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 608 | ddq->d_rtbtimer = cpu_to_be32(newlim->d_rtbtimer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | } |
Nathan Scott | 754002b | 2005-06-21 15:49:06 +1000 | [diff] [blame] | 610 | if (newlim->d_fieldmask & FS_DQ_BWARNS) |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 611 | q->qi_bwarnlimit = newlim->d_bwarns; |
Nathan Scott | 754002b | 2005-06-21 15:49:06 +1000 | [diff] [blame] | 612 | if (newlim->d_fieldmask & FS_DQ_IWARNS) |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 613 | q->qi_iwarnlimit = newlim->d_iwarns; |
Nathan Scott | 754002b | 2005-06-21 15:49:06 +1000 | [diff] [blame] | 614 | if (newlim->d_fieldmask & FS_DQ_RTBWARNS) |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 615 | q->qi_rtbwarnlimit = newlim->d_rtbwarns; |
Nathan Scott | 754002b | 2005-06-21 15:49:06 +1000 | [diff] [blame] | 616 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | /* |
| 618 | * If the user is now over quota, start the timelimit. |
| 619 | * The user will not be 'warned'. |
| 620 | * Note that we keep the timers ticking, whether enforcement |
| 621 | * is on or off. We don't really want to bother with iterating |
| 622 | * over all ondisk dquots and turning the timers on/off. |
| 623 | */ |
| 624 | xfs_qm_adjust_dqtimers(mp, ddq); |
| 625 | } |
| 626 | dqp->dq_flags |= XFS_DQ_DIRTY; |
| 627 | xfs_trans_log_dquot(tp, dqp); |
| 628 | |
David Chinner | e5720ee | 2008-04-10 12:21:18 +1000 | [diff] [blame] | 629 | error = xfs_trans_commit(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | xfs_qm_dqprint(dqp); |
| 631 | xfs_qm_dqrele(dqp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 633 | out_unlock: |
| 634 | mutex_unlock(&q->qi_quotaofflock); |
David Chinner | e5720ee | 2008-04-10 12:21:18 +1000 | [diff] [blame] | 635 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | } |
| 637 | |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 638 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | xfs_qm_scall_getquota( |
| 640 | xfs_mount_t *mp, |
| 641 | xfs_dqid_t id, |
| 642 | uint type, |
| 643 | fs_disk_quota_t *out) |
| 644 | { |
| 645 | xfs_dquot_t *dqp; |
| 646 | int error; |
| 647 | |
| 648 | /* |
| 649 | * Try to get the dquot. We don't want it allocated on disk, so |
| 650 | * we aren't passing the XFS_QMOPT_DOALLOC flag. If it doesn't |
| 651 | * exist, we'll get ENOENT back. |
| 652 | */ |
| 653 | if ((error = xfs_qm_dqget(mp, NULL, id, type, 0, &dqp))) { |
| 654 | return (error); |
| 655 | } |
| 656 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | /* |
| 658 | * If everything's NULL, this dquot doesn't quite exist as far as |
| 659 | * our utility programs are concerned. |
| 660 | */ |
| 661 | if (XFS_IS_DQUOT_UNINITIALIZED(dqp)) { |
| 662 | xfs_qm_dqput(dqp); |
| 663 | return XFS_ERROR(ENOENT); |
| 664 | } |
| 665 | /* xfs_qm_dqprint(dqp); */ |
| 666 | /* |
| 667 | * Convert the disk dquot to the exportable format |
| 668 | */ |
| 669 | xfs_qm_export_dquot(mp, &dqp->q_core, out); |
| 670 | xfs_qm_dqput(dqp); |
| 671 | return (error ? XFS_ERROR(EFAULT) : 0); |
| 672 | } |
| 673 | |
| 674 | |
| 675 | STATIC int |
| 676 | xfs_qm_log_quotaoff_end( |
| 677 | xfs_mount_t *mp, |
| 678 | xfs_qoff_logitem_t *startqoff, |
| 679 | uint flags) |
| 680 | { |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 681 | xfs_trans_t *tp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | int error; |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 683 | xfs_qoff_logitem_t *qoffi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | |
| 685 | tp = xfs_trans_alloc(mp, XFS_TRANS_QM_QUOTAOFF_END); |
| 686 | |
| 687 | if ((error = xfs_trans_reserve(tp, 0, sizeof(xfs_qoff_logitem_t) * 2, |
| 688 | 0, 0, XFS_DEFAULT_LOG_COUNT))) { |
| 689 | xfs_trans_cancel(tp, 0); |
| 690 | return (error); |
| 691 | } |
| 692 | |
| 693 | qoffi = xfs_trans_get_qoff_item(tp, startqoff, |
| 694 | flags & XFS_ALL_QUOTA_ACCT); |
| 695 | xfs_trans_log_quotaoff_item(tp, qoffi); |
| 696 | |
| 697 | /* |
| 698 | * We have to make sure that the transaction is secure on disk before we |
| 699 | * return and actually stop quota accounting. So, make it synchronous. |
| 700 | * We don't care about quotoff's performance. |
| 701 | */ |
| 702 | xfs_trans_set_sync(tp); |
Eric Sandeen | 1c72bf9 | 2007-05-08 13:48:42 +1000 | [diff] [blame] | 703 | error = xfs_trans_commit(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | return (error); |
| 705 | } |
| 706 | |
| 707 | |
| 708 | STATIC int |
| 709 | xfs_qm_log_quotaoff( |
| 710 | xfs_mount_t *mp, |
| 711 | xfs_qoff_logitem_t **qoffstartp, |
| 712 | uint flags) |
| 713 | { |
| 714 | xfs_trans_t *tp; |
| 715 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | xfs_qoff_logitem_t *qoffi=NULL; |
| 717 | uint oldsbqflag=0; |
| 718 | |
| 719 | tp = xfs_trans_alloc(mp, XFS_TRANS_QM_QUOTAOFF); |
| 720 | if ((error = xfs_trans_reserve(tp, 0, |
| 721 | sizeof(xfs_qoff_logitem_t) * 2 + |
| 722 | mp->m_sb.sb_sectsize + 128, |
| 723 | 0, |
| 724 | 0, |
| 725 | XFS_DEFAULT_LOG_COUNT))) { |
| 726 | goto error0; |
| 727 | } |
| 728 | |
| 729 | qoffi = xfs_trans_get_qoff_item(tp, NULL, flags & XFS_ALL_QUOTA_ACCT); |
| 730 | xfs_trans_log_quotaoff_item(tp, qoffi); |
| 731 | |
Eric Sandeen | 3685c2a | 2007-10-11 17:42:32 +1000 | [diff] [blame] | 732 | spin_lock(&mp->m_sb_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | oldsbqflag = mp->m_sb.sb_qflags; |
| 734 | mp->m_sb.sb_qflags = (mp->m_qflags & ~(flags)) & XFS_MOUNT_QUOTA_ALL; |
Eric Sandeen | 3685c2a | 2007-10-11 17:42:32 +1000 | [diff] [blame] | 735 | spin_unlock(&mp->m_sb_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | |
| 737 | xfs_mod_sb(tp, XFS_SB_QFLAGS); |
| 738 | |
| 739 | /* |
| 740 | * We have to make sure that the transaction is secure on disk before we |
| 741 | * return and actually stop quota accounting. So, make it synchronous. |
| 742 | * We don't care about quotoff's performance. |
| 743 | */ |
| 744 | xfs_trans_set_sync(tp); |
Eric Sandeen | 1c72bf9 | 2007-05-08 13:48:42 +1000 | [diff] [blame] | 745 | error = xfs_trans_commit(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | |
| 747 | error0: |
| 748 | if (error) { |
| 749 | xfs_trans_cancel(tp, 0); |
| 750 | /* |
| 751 | * No one else is modifying sb_qflags, so this is OK. |
| 752 | * We still hold the quotaofflock. |
| 753 | */ |
Eric Sandeen | 3685c2a | 2007-10-11 17:42:32 +1000 | [diff] [blame] | 754 | spin_lock(&mp->m_sb_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | mp->m_sb.sb_qflags = oldsbqflag; |
Eric Sandeen | 3685c2a | 2007-10-11 17:42:32 +1000 | [diff] [blame] | 756 | spin_unlock(&mp->m_sb_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | } |
| 758 | *qoffstartp = qoffi; |
| 759 | return (error); |
| 760 | } |
| 761 | |
| 762 | |
| 763 | /* |
| 764 | * Translate an internal style on-disk-dquot to the exportable format. |
| 765 | * The main differences are that the counters/limits are all in Basic |
| 766 | * Blocks (BBs) instead of the internal FSBs, and all on-disk data has |
| 767 | * to be converted to the native endianness. |
| 768 | */ |
| 769 | STATIC void |
| 770 | xfs_qm_export_dquot( |
| 771 | xfs_mount_t *mp, |
| 772 | xfs_disk_dquot_t *src, |
| 773 | struct fs_disk_quota *dst) |
| 774 | { |
| 775 | memset(dst, 0, sizeof(*dst)); |
| 776 | dst->d_version = FS_DQUOT_VERSION; /* different from src->d_version */ |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 777 | dst->d_flags = xfs_qm_export_qtype_flags(src->d_flags); |
| 778 | dst->d_id = be32_to_cpu(src->d_id); |
| 779 | dst->d_blk_hardlimit = |
| 780 | XFS_FSB_TO_BB(mp, be64_to_cpu(src->d_blk_hardlimit)); |
| 781 | dst->d_blk_softlimit = |
| 782 | XFS_FSB_TO_BB(mp, be64_to_cpu(src->d_blk_softlimit)); |
| 783 | dst->d_ino_hardlimit = be64_to_cpu(src->d_ino_hardlimit); |
| 784 | dst->d_ino_softlimit = be64_to_cpu(src->d_ino_softlimit); |
| 785 | dst->d_bcount = XFS_FSB_TO_BB(mp, be64_to_cpu(src->d_bcount)); |
| 786 | dst->d_icount = be64_to_cpu(src->d_icount); |
| 787 | dst->d_btimer = be32_to_cpu(src->d_btimer); |
| 788 | dst->d_itimer = be32_to_cpu(src->d_itimer); |
| 789 | dst->d_iwarns = be16_to_cpu(src->d_iwarns); |
| 790 | dst->d_bwarns = be16_to_cpu(src->d_bwarns); |
| 791 | dst->d_rtb_hardlimit = |
| 792 | XFS_FSB_TO_BB(mp, be64_to_cpu(src->d_rtb_hardlimit)); |
| 793 | dst->d_rtb_softlimit = |
| 794 | XFS_FSB_TO_BB(mp, be64_to_cpu(src->d_rtb_softlimit)); |
| 795 | dst->d_rtbcount = XFS_FSB_TO_BB(mp, be64_to_cpu(src->d_rtbcount)); |
| 796 | dst->d_rtbtimer = be32_to_cpu(src->d_rtbtimer); |
| 797 | dst->d_rtbwarns = be16_to_cpu(src->d_rtbwarns); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | |
| 799 | /* |
| 800 | * Internally, we don't reset all the timers when quota enforcement |
Nathan Scott | c41564b | 2006-03-29 08:55:14 +1000 | [diff] [blame] | 801 | * gets turned off. No need to confuse the user level code, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | * so return zeroes in that case. |
| 803 | */ |
Kouta Ooizumi | e6d2942 | 2007-05-08 13:49:33 +1000 | [diff] [blame] | 804 | if ((!XFS_IS_UQUOTA_ENFORCED(mp) && src->d_flags == XFS_DQ_USER) || |
| 805 | (!XFS_IS_OQUOTA_ENFORCED(mp) && |
| 806 | (src->d_flags & (XFS_DQ_PROJ | XFS_DQ_GROUP)))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | dst->d_btimer = 0; |
| 808 | dst->d_itimer = 0; |
| 809 | dst->d_rtbtimer = 0; |
| 810 | } |
| 811 | |
| 812 | #ifdef DEBUG |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 813 | if (((XFS_IS_UQUOTA_ENFORCED(mp) && dst->d_flags == FS_USER_QUOTA) || |
Kouta Ooizumi | e6d2942 | 2007-05-08 13:49:33 +1000 | [diff] [blame] | 814 | (XFS_IS_OQUOTA_ENFORCED(mp) && |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 815 | (dst->d_flags & (FS_PROJ_QUOTA | FS_GROUP_QUOTA)))) && |
Kouta Ooizumi | e6d2942 | 2007-05-08 13:49:33 +1000 | [diff] [blame] | 816 | dst->d_id != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | if (((int) dst->d_bcount >= (int) dst->d_blk_softlimit) && |
| 818 | (dst->d_blk_softlimit > 0)) { |
| 819 | ASSERT(dst->d_btimer != 0); |
| 820 | } |
| 821 | if (((int) dst->d_icount >= (int) dst->d_ino_softlimit) && |
| 822 | (dst->d_ino_softlimit > 0)) { |
| 823 | ASSERT(dst->d_itimer != 0); |
| 824 | } |
| 825 | } |
| 826 | #endif |
| 827 | } |
| 828 | |
| 829 | STATIC uint |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | xfs_qm_export_qtype_flags( |
| 831 | uint flags) |
| 832 | { |
| 833 | /* |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 834 | * Can't be more than one, or none. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | */ |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 836 | ASSERT((flags & (FS_PROJ_QUOTA | FS_USER_QUOTA)) != |
| 837 | (FS_PROJ_QUOTA | FS_USER_QUOTA)); |
| 838 | ASSERT((flags & (FS_PROJ_QUOTA | FS_GROUP_QUOTA)) != |
| 839 | (FS_PROJ_QUOTA | FS_GROUP_QUOTA)); |
| 840 | ASSERT((flags & (FS_USER_QUOTA | FS_GROUP_QUOTA)) != |
| 841 | (FS_USER_QUOTA | FS_GROUP_QUOTA)); |
| 842 | ASSERT((flags & (FS_PROJ_QUOTA|FS_USER_QUOTA|FS_GROUP_QUOTA)) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | |
| 844 | return (flags & XFS_DQ_USER) ? |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 845 | FS_USER_QUOTA : (flags & XFS_DQ_PROJ) ? |
| 846 | FS_PROJ_QUOTA : FS_GROUP_QUOTA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | STATIC uint |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | xfs_qm_export_flags( |
| 851 | uint flags) |
| 852 | { |
| 853 | uint uflags; |
| 854 | |
| 855 | uflags = 0; |
| 856 | if (flags & XFS_UQUOTA_ACCT) |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 857 | uflags |= FS_QUOTA_UDQ_ACCT; |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 858 | if (flags & XFS_PQUOTA_ACCT) |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 859 | uflags |= FS_QUOTA_PDQ_ACCT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | if (flags & XFS_GQUOTA_ACCT) |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 861 | uflags |= FS_QUOTA_GDQ_ACCT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | if (flags & XFS_UQUOTA_ENFD) |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 863 | uflags |= FS_QUOTA_UDQ_ENFD; |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 864 | if (flags & (XFS_OQUOTA_ENFD)) { |
| 865 | uflags |= (flags & XFS_GQUOTA_ACCT) ? |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 866 | FS_QUOTA_GDQ_ENFD : FS_QUOTA_PDQ_ENFD; |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 867 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | return (uflags); |
| 869 | } |
| 870 | |
| 871 | |
Christoph Hellwig | fe588ed | 2009-06-08 15:35:27 +0200 | [diff] [blame] | 872 | STATIC int |
| 873 | xfs_dqrele_inode( |
| 874 | struct xfs_inode *ip, |
| 875 | struct xfs_perag *pag, |
| 876 | int flags) |
David Chinner | 5b4d89a | 2008-10-30 17:08:03 +1100 | [diff] [blame] | 877 | { |
Christoph Hellwig | fe588ed | 2009-06-08 15:35:27 +0200 | [diff] [blame] | 878 | /* skip quota inodes */ |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 879 | if (ip == ip->i_mount->m_quotainfo->qi_uquotaip || |
| 880 | ip == ip->i_mount->m_quotainfo->qi_gquotaip) { |
Christoph Hellwig | fe588ed | 2009-06-08 15:35:27 +0200 | [diff] [blame] | 881 | ASSERT(ip->i_udquot == NULL); |
| 882 | ASSERT(ip->i_gdquot == NULL); |
Christoph Hellwig | fe588ed | 2009-06-08 15:35:27 +0200 | [diff] [blame] | 883 | return 0; |
| 884 | } |
Dave Chinner | cb4f0d1 | 2008-11-10 17:11:18 +1100 | [diff] [blame] | 885 | |
Christoph Hellwig | fe588ed | 2009-06-08 15:35:27 +0200 | [diff] [blame] | 886 | xfs_ilock(ip, XFS_ILOCK_EXCL); |
| 887 | if ((flags & XFS_UQUOTA_ACCT) && ip->i_udquot) { |
| 888 | xfs_qm_dqrele(ip->i_udquot); |
| 889 | ip->i_udquot = NULL; |
| 890 | } |
| 891 | if (flags & (XFS_PQUOTA_ACCT|XFS_GQUOTA_ACCT) && ip->i_gdquot) { |
| 892 | xfs_qm_dqrele(ip->i_gdquot); |
| 893 | ip->i_gdquot = NULL; |
| 894 | } |
Christoph Hellwig | f2d6761 | 2010-06-24 11:52:50 +1000 | [diff] [blame] | 895 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
Christoph Hellwig | fe588ed | 2009-06-08 15:35:27 +0200 | [diff] [blame] | 896 | return 0; |
David Chinner | 5b4d89a | 2008-10-30 17:08:03 +1100 | [diff] [blame] | 897 | } |
| 898 | |
Christoph Hellwig | fe588ed | 2009-06-08 15:35:27 +0200 | [diff] [blame] | 899 | |
David Chinner | 5b4d89a | 2008-10-30 17:08:03 +1100 | [diff] [blame] | 900 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | * Go thru all the inodes in the file system, releasing their dquots. |
Christoph Hellwig | fe588ed | 2009-06-08 15:35:27 +0200 | [diff] [blame] | 902 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | * Note that the mount structure gets modified to indicate that quotas are off |
Christoph Hellwig | fe588ed | 2009-06-08 15:35:27 +0200 | [diff] [blame] | 904 | * AFTER this, in the case of quotaoff. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | */ |
| 906 | void |
| 907 | xfs_qm_dqrele_all_inodes( |
| 908 | struct xfs_mount *mp, |
| 909 | uint flags) |
| 910 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | ASSERT(mp->m_quotainfo); |
Dave Chinner | 65d0f20 | 2010-09-24 18:40:15 +1000 | [diff] [blame] | 912 | xfs_inode_ag_iterator(mp, xfs_dqrele_inode, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | /*------------------------------------------------------------------------*/ |
| 916 | #ifdef DEBUG |
| 917 | /* |
| 918 | * This contains all the test functions for XFS disk quotas. |
| 919 | * Currently it does a quota accounting check. ie. it walks through |
| 920 | * all inodes in the file system, calculating the dquot accounting fields, |
| 921 | * and prints out any inconsistencies. |
| 922 | */ |
| 923 | xfs_dqhash_t *qmtest_udqtab; |
| 924 | xfs_dqhash_t *qmtest_gdqtab; |
| 925 | int qmtest_hashmask; |
| 926 | int qmtest_nfails; |
Christoph Hellwig | a0b0b8a | 2009-03-29 09:51:00 +0200 | [diff] [blame] | 927 | struct mutex qcheck_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | |
| 929 | #define DQTEST_HASHVAL(mp, id) (((__psunsigned_t)(mp) + \ |
| 930 | (__psunsigned_t)(id)) & \ |
| 931 | (qmtest_hashmask - 1)) |
| 932 | |
| 933 | #define DQTEST_HASH(mp, id, type) ((type & XFS_DQ_USER) ? \ |
| 934 | (qmtest_udqtab + \ |
| 935 | DQTEST_HASHVAL(mp, id)) : \ |
| 936 | (qmtest_gdqtab + \ |
| 937 | DQTEST_HASHVAL(mp, id))) |
| 938 | |
| 939 | #define DQTEST_LIST_PRINT(l, NXT, title) \ |
| 940 | { \ |
| 941 | xfs_dqtest_t *dqp; int i = 0;\ |
| 942 | cmn_err(CE_DEBUG, "%s (#%d)", title, (int) (l)->qh_nelems); \ |
| 943 | for (dqp = (xfs_dqtest_t *)(l)->qh_next; dqp != NULL; \ |
| 944 | dqp = (xfs_dqtest_t *)dqp->NXT) { \ |
| 945 | cmn_err(CE_DEBUG, " %d. \"%d (%s)\" bcnt = %d, icnt = %d", \ |
| 946 | ++i, dqp->d_id, DQFLAGTO_TYPESTR(dqp), \ |
| 947 | dqp->d_bcount, dqp->d_icount); } \ |
| 948 | } |
| 949 | |
| 950 | typedef struct dqtest { |
Christoph Hellwig | 74457cf | 2010-04-13 15:06:53 +1000 | [diff] [blame] | 951 | uint dq_flags; /* various flags (XFS_DQ_*) */ |
Dave Chinner | e6a81f1 | 2010-04-13 15:06:51 +1000 | [diff] [blame] | 952 | struct list_head q_hashlist; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | xfs_dqhash_t *q_hash; /* the hashchain header */ |
| 954 | xfs_mount_t *q_mount; /* filesystem this relates to */ |
| 955 | xfs_dqid_t d_id; /* user id or group id */ |
| 956 | xfs_qcnt_t d_bcount; /* # disk blocks owned by the user */ |
| 957 | xfs_qcnt_t d_icount; /* # inodes owned by the user */ |
| 958 | } xfs_dqtest_t; |
| 959 | |
| 960 | STATIC void |
| 961 | xfs_qm_hashinsert(xfs_dqhash_t *h, xfs_dqtest_t *dqp) |
| 962 | { |
Dave Chinner | e6a81f1 | 2010-04-13 15:06:51 +1000 | [diff] [blame] | 963 | list_add(&dqp->q_hashlist, &h->qh_list); |
| 964 | h->qh_version++; |
| 965 | h->qh_nelems++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | } |
| 967 | STATIC void |
| 968 | xfs_qm_dqtest_print( |
| 969 | xfs_dqtest_t *d) |
| 970 | { |
| 971 | cmn_err(CE_DEBUG, "-----------DQTEST DQUOT----------------"); |
| 972 | cmn_err(CE_DEBUG, "---- dquot ID = %d", d->d_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | cmn_err(CE_DEBUG, "---- fs = 0x%p", d->q_mount); |
| 974 | cmn_err(CE_DEBUG, "---- bcount = %Lu (0x%x)", |
| 975 | d->d_bcount, (int)d->d_bcount); |
| 976 | cmn_err(CE_DEBUG, "---- icount = %Lu (0x%x)", |
| 977 | d->d_icount, (int)d->d_icount); |
| 978 | cmn_err(CE_DEBUG, "---------------------------"); |
| 979 | } |
| 980 | |
| 981 | STATIC void |
| 982 | xfs_qm_dqtest_failed( |
| 983 | xfs_dqtest_t *d, |
| 984 | xfs_dquot_t *dqp, |
| 985 | char *reason, |
| 986 | xfs_qcnt_t a, |
| 987 | xfs_qcnt_t b, |
| 988 | int error) |
| 989 | { |
| 990 | qmtest_nfails++; |
| 991 | if (error) |
| 992 | cmn_err(CE_DEBUG, "quotacheck failed id=%d, err=%d\nreason: %s", |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 993 | d->d_id, error, reason); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | else |
| 995 | cmn_err(CE_DEBUG, "quotacheck failed id=%d (%s) [%d != %d]", |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 996 | d->d_id, reason, (int)a, (int)b); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | xfs_qm_dqtest_print(d); |
| 998 | if (dqp) |
| 999 | xfs_qm_dqprint(dqp); |
| 1000 | } |
| 1001 | |
| 1002 | STATIC int |
| 1003 | xfs_dqtest_cmp2( |
| 1004 | xfs_dqtest_t *d, |
| 1005 | xfs_dquot_t *dqp) |
| 1006 | { |
| 1007 | int err = 0; |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 1008 | if (be64_to_cpu(dqp->q_core.d_icount) != d->d_icount) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | xfs_qm_dqtest_failed(d, dqp, "icount mismatch", |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 1010 | be64_to_cpu(dqp->q_core.d_icount), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | d->d_icount, 0); |
| 1012 | err++; |
| 1013 | } |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 1014 | if (be64_to_cpu(dqp->q_core.d_bcount) != d->d_bcount) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | xfs_qm_dqtest_failed(d, dqp, "bcount mismatch", |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 1016 | be64_to_cpu(dqp->q_core.d_bcount), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | d->d_bcount, 0); |
| 1018 | err++; |
| 1019 | } |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 1020 | if (dqp->q_core.d_blk_softlimit && |
| 1021 | be64_to_cpu(dqp->q_core.d_bcount) >= |
| 1022 | be64_to_cpu(dqp->q_core.d_blk_softlimit)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | if (!dqp->q_core.d_btimer && dqp->q_core.d_id) { |
| 1024 | cmn_err(CE_DEBUG, |
| 1025 | "%d [%s] [0x%p] BLK TIMER NOT STARTED", |
| 1026 | d->d_id, DQFLAGTO_TYPESTR(d), d->q_mount); |
| 1027 | err++; |
| 1028 | } |
| 1029 | } |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 1030 | if (dqp->q_core.d_ino_softlimit && |
| 1031 | be64_to_cpu(dqp->q_core.d_icount) >= |
| 1032 | be64_to_cpu(dqp->q_core.d_ino_softlimit)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | if (!dqp->q_core.d_itimer && dqp->q_core.d_id) { |
| 1034 | cmn_err(CE_DEBUG, |
| 1035 | "%d [%s] [0x%p] INO TIMER NOT STARTED", |
| 1036 | d->d_id, DQFLAGTO_TYPESTR(d), d->q_mount); |
| 1037 | err++; |
| 1038 | } |
| 1039 | } |
| 1040 | #ifdef QUOTADEBUG |
| 1041 | if (!err) { |
| 1042 | cmn_err(CE_DEBUG, "%d [%s] [0x%p] qchecked", |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 1043 | d->d_id, DQFLAGTO_TYPESTR(d), d->q_mount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | } |
| 1045 | #endif |
| 1046 | return (err); |
| 1047 | } |
| 1048 | |
| 1049 | STATIC void |
| 1050 | xfs_dqtest_cmp( |
| 1051 | xfs_dqtest_t *d) |
| 1052 | { |
| 1053 | xfs_dquot_t *dqp; |
| 1054 | int error; |
| 1055 | |
| 1056 | /* xfs_qm_dqtest_print(d); */ |
| 1057 | if ((error = xfs_qm_dqget(d->q_mount, NULL, d->d_id, d->dq_flags, 0, |
| 1058 | &dqp))) { |
| 1059 | xfs_qm_dqtest_failed(d, NULL, "dqget failed", 0, 0, error); |
| 1060 | return; |
| 1061 | } |
| 1062 | xfs_dqtest_cmp2(d, dqp); |
| 1063 | xfs_qm_dqput(dqp); |
| 1064 | } |
| 1065 | |
| 1066 | STATIC int |
| 1067 | xfs_qm_internalqcheck_dqget( |
| 1068 | xfs_mount_t *mp, |
| 1069 | xfs_dqid_t id, |
| 1070 | uint type, |
| 1071 | xfs_dqtest_t **O_dq) |
| 1072 | { |
| 1073 | xfs_dqtest_t *d; |
| 1074 | xfs_dqhash_t *h; |
| 1075 | |
| 1076 | h = DQTEST_HASH(mp, id, type); |
Dave Chinner | e6a81f1 | 2010-04-13 15:06:51 +1000 | [diff] [blame] | 1077 | list_for_each_entry(d, &h->qh_list, q_hashlist) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | if (d->d_id == id && mp == d->q_mount) { |
| 1079 | *O_dq = d; |
| 1080 | return (0); |
| 1081 | } |
| 1082 | } |
| 1083 | d = kmem_zalloc(sizeof(xfs_dqtest_t), KM_SLEEP); |
| 1084 | d->dq_flags = type; |
| 1085 | d->d_id = id; |
| 1086 | d->q_mount = mp; |
| 1087 | d->q_hash = h; |
Dave Chinner | e6a81f1 | 2010-04-13 15:06:51 +1000 | [diff] [blame] | 1088 | INIT_LIST_HEAD(&d->q_hashlist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | xfs_qm_hashinsert(h, d); |
| 1090 | *O_dq = d; |
| 1091 | return (0); |
| 1092 | } |
| 1093 | |
| 1094 | STATIC void |
| 1095 | xfs_qm_internalqcheck_get_dquots( |
| 1096 | xfs_mount_t *mp, |
| 1097 | xfs_dqid_t uid, |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 1098 | xfs_dqid_t projid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | xfs_dqid_t gid, |
| 1100 | xfs_dqtest_t **ud, |
| 1101 | xfs_dqtest_t **gd) |
| 1102 | { |
| 1103 | if (XFS_IS_UQUOTA_ON(mp)) |
| 1104 | xfs_qm_internalqcheck_dqget(mp, uid, XFS_DQ_USER, ud); |
| 1105 | if (XFS_IS_GQUOTA_ON(mp)) |
| 1106 | xfs_qm_internalqcheck_dqget(mp, gid, XFS_DQ_GROUP, gd); |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 1107 | else if (XFS_IS_PQUOTA_ON(mp)) |
| 1108 | xfs_qm_internalqcheck_dqget(mp, projid, XFS_DQ_PROJ, gd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | |
| 1112 | STATIC void |
| 1113 | xfs_qm_internalqcheck_dqadjust( |
| 1114 | xfs_inode_t *ip, |
| 1115 | xfs_dqtest_t *d) |
| 1116 | { |
| 1117 | d->d_icount++; |
| 1118 | d->d_bcount += (xfs_qcnt_t)ip->i_d.di_nblocks; |
| 1119 | } |
| 1120 | |
| 1121 | STATIC int |
| 1122 | xfs_qm_internalqcheck_adjust( |
| 1123 | xfs_mount_t *mp, /* mount point for filesystem */ |
| 1124 | xfs_ino_t ino, /* inode number to get data for */ |
| 1125 | void __user *buffer, /* not used */ |
| 1126 | int ubsize, /* not used */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | int *ubused, /* not used */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | int *res) /* bulkstat result code */ |
| 1129 | { |
| 1130 | xfs_inode_t *ip; |
| 1131 | xfs_dqtest_t *ud, *gd; |
| 1132 | uint lock_flags; |
| 1133 | boolean_t ipreleased; |
| 1134 | int error; |
| 1135 | |
| 1136 | ASSERT(XFS_IS_QUOTA_RUNNING(mp)); |
| 1137 | |
| 1138 | if (ino == mp->m_sb.sb_uquotino || ino == mp->m_sb.sb_gquotino) { |
| 1139 | *res = BULKSTAT_RV_NOTHING; |
| 1140 | qdprintk("internalqcheck: ino=%llu, uqino=%llu, gqino=%llu\n", |
| 1141 | (unsigned long long) ino, |
| 1142 | (unsigned long long) mp->m_sb.sb_uquotino, |
| 1143 | (unsigned long long) mp->m_sb.sb_gquotino); |
| 1144 | return XFS_ERROR(EINVAL); |
| 1145 | } |
| 1146 | ipreleased = B_FALSE; |
| 1147 | again: |
| 1148 | lock_flags = XFS_ILOCK_SHARED; |
Dave Chinner | 7b6259e | 2010-06-24 11:35:17 +1000 | [diff] [blame] | 1149 | if ((error = xfs_iget(mp, NULL, ino, 0, lock_flags, &ip))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | *res = BULKSTAT_RV_NOTHING; |
| 1151 | return (error); |
| 1152 | } |
| 1153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | /* |
| 1155 | * This inode can have blocks after eof which can get released |
| 1156 | * when we send it to inactive. Since we don't check the dquot |
| 1157 | * until the after all our calculations are done, we must get rid |
| 1158 | * of those now. |
| 1159 | */ |
| 1160 | if (! ipreleased) { |
Christoph Hellwig | f2d6761 | 2010-06-24 11:52:50 +1000 | [diff] [blame] | 1161 | xfs_iunlock(ip, lock_flags); |
| 1162 | IRELE(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | ipreleased = B_TRUE; |
| 1164 | goto again; |
| 1165 | } |
| 1166 | xfs_qm_internalqcheck_get_dquots(mp, |
| 1167 | (xfs_dqid_t) ip->i_d.di_uid, |
Arkadiusz Mi?kiewicz | 6743099 | 2010-09-26 06:10:18 +0000 | [diff] [blame^] | 1168 | (xfs_dqid_t) xfs_get_projid(ip), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | (xfs_dqid_t) ip->i_d.di_gid, |
| 1170 | &ud, &gd); |
| 1171 | if (XFS_IS_UQUOTA_ON(mp)) { |
| 1172 | ASSERT(ud); |
| 1173 | xfs_qm_internalqcheck_dqadjust(ip, ud); |
| 1174 | } |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 1175 | if (XFS_IS_OQUOTA_ON(mp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | ASSERT(gd); |
| 1177 | xfs_qm_internalqcheck_dqadjust(ip, gd); |
| 1178 | } |
Christoph Hellwig | f2d6761 | 2010-06-24 11:52:50 +1000 | [diff] [blame] | 1179 | xfs_iunlock(ip, lock_flags); |
| 1180 | IRELE(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | *res = BULKSTAT_RV_DIDONE; |
| 1182 | return (0); |
| 1183 | } |
| 1184 | |
| 1185 | |
| 1186 | /* PRIVATE, debugging */ |
| 1187 | int |
| 1188 | xfs_qm_internalqcheck( |
| 1189 | xfs_mount_t *mp) |
| 1190 | { |
| 1191 | xfs_ino_t lastino; |
| 1192 | int done, count; |
| 1193 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | int error; |
| 1195 | |
| 1196 | lastino = 0; |
| 1197 | qmtest_hashmask = 32; |
| 1198 | count = 5; |
| 1199 | done = 0; |
| 1200 | qmtest_nfails = 0; |
| 1201 | |
| 1202 | if (! XFS_IS_QUOTA_ON(mp)) |
| 1203 | return XFS_ERROR(ESRCH); |
| 1204 | |
Christoph Hellwig | a14a348 | 2010-01-19 09:56:46 +0000 | [diff] [blame] | 1205 | xfs_log_force(mp, XFS_LOG_SYNC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | XFS_bflush(mp->m_ddev_targp); |
Christoph Hellwig | a14a348 | 2010-01-19 09:56:46 +0000 | [diff] [blame] | 1207 | xfs_log_force(mp, XFS_LOG_SYNC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | XFS_bflush(mp->m_ddev_targp); |
| 1209 | |
Jes Sorensen | 794ee1b | 2006-01-09 15:59:21 -0800 | [diff] [blame] | 1210 | mutex_lock(&qcheck_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | /* There should be absolutely no quota activity while this |
| 1212 | is going on. */ |
| 1213 | qmtest_udqtab = kmem_zalloc(qmtest_hashmask * |
| 1214 | sizeof(xfs_dqhash_t), KM_SLEEP); |
| 1215 | qmtest_gdqtab = kmem_zalloc(qmtest_hashmask * |
| 1216 | sizeof(xfs_dqhash_t), KM_SLEEP); |
| 1217 | do { |
| 1218 | /* |
| 1219 | * Iterate thru all the inodes in the file system, |
| 1220 | * adjusting the corresponding dquot counters |
| 1221 | */ |
Christoph Hellwig | 7dce11d | 2010-06-23 18:11:11 +1000 | [diff] [blame] | 1222 | error = xfs_bulkstat(mp, &lastino, &count, |
| 1223 | xfs_qm_internalqcheck_adjust, |
| 1224 | 0, NULL, &done); |
| 1225 | if (error) { |
| 1226 | cmn_err(CE_DEBUG, "Bulkstat returned error 0x%x", error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | break; |
| 1228 | } |
Christoph Hellwig | 7dce11d | 2010-06-23 18:11:11 +1000 | [diff] [blame] | 1229 | } while (!done); |
| 1230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | cmn_err(CE_DEBUG, "Checking results against system dquots"); |
| 1232 | for (i = 0; i < qmtest_hashmask; i++) { |
Dave Chinner | e6a81f1 | 2010-04-13 15:06:51 +1000 | [diff] [blame] | 1233 | xfs_dqtest_t *d, *n; |
| 1234 | xfs_dqhash_t *h; |
| 1235 | |
| 1236 | h = &qmtest_udqtab[i]; |
| 1237 | list_for_each_entry_safe(d, n, &h->qh_list, q_hashlist) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | xfs_dqtest_cmp(d); |
Denys Vlasenko | f0e2d93 | 2008-05-19 16:31:57 +1000 | [diff] [blame] | 1239 | kmem_free(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | } |
Dave Chinner | e6a81f1 | 2010-04-13 15:06:51 +1000 | [diff] [blame] | 1241 | h = &qmtest_gdqtab[i]; |
| 1242 | list_for_each_entry_safe(d, n, &h->qh_list, q_hashlist) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | xfs_dqtest_cmp(d); |
Denys Vlasenko | f0e2d93 | 2008-05-19 16:31:57 +1000 | [diff] [blame] | 1244 | kmem_free(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | } |
| 1246 | } |
| 1247 | |
| 1248 | if (qmtest_nfails) { |
| 1249 | cmn_err(CE_DEBUG, "******** quotacheck failed ********"); |
| 1250 | cmn_err(CE_DEBUG, "failures = %d", qmtest_nfails); |
| 1251 | } else { |
| 1252 | cmn_err(CE_DEBUG, "******** quotacheck successful! ********"); |
| 1253 | } |
Denys Vlasenko | f0e2d93 | 2008-05-19 16:31:57 +1000 | [diff] [blame] | 1254 | kmem_free(qmtest_udqtab); |
| 1255 | kmem_free(qmtest_gdqtab); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | mutex_unlock(&qcheck_lock); |
| 1257 | return (qmtest_nfails); |
| 1258 | } |
| 1259 | |
| 1260 | #endif /* DEBUG */ |