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_dir2.h" |
| 30 | #include "xfs_alloc.h" |
| 31 | #include "xfs_dmapi.h" |
| 32 | #include "xfs_quota.h" |
| 33 | #include "xfs_mount.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include "xfs_bmap_btree.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 35 | #include "xfs_alloc_btree.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include "xfs_ialloc_btree.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include "xfs_dir2_sf.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 38 | #include "xfs_attr_sf.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include "xfs_dinode.h" |
| 40 | #include "xfs_inode.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 41 | #include "xfs_ialloc.h" |
| 42 | #include "xfs_itable.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include "xfs_bmap.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 44 | #include "xfs_btree.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include "xfs_rtalloc.h" |
| 46 | #include "xfs_error.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include "xfs_rw.h" |
| 48 | #include "xfs_acl.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #include "xfs_attr.h" |
| 50 | #include "xfs_buf_item.h" |
| 51 | #include "xfs_utils.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include "xfs_qm.h" |
| 53 | |
| 54 | #ifdef DEBUG |
| 55 | # define qdprintk(s, args...) cmn_err(CE_DEBUG, s, ## args) |
| 56 | #else |
| 57 | # define qdprintk(s, args...) do { } while (0) |
| 58 | #endif |
| 59 | |
| 60 | STATIC int xfs_qm_scall_trunc_qfiles(xfs_mount_t *, uint); |
| 61 | STATIC int xfs_qm_scall_getquota(xfs_mount_t *, xfs_dqid_t, uint, |
| 62 | fs_disk_quota_t *); |
| 63 | STATIC int xfs_qm_scall_getqstat(xfs_mount_t *, fs_quota_stat_t *); |
| 64 | STATIC int xfs_qm_scall_setqlim(xfs_mount_t *, xfs_dqid_t, uint, |
| 65 | fs_disk_quota_t *); |
| 66 | STATIC int xfs_qm_scall_quotaon(xfs_mount_t *, uint); |
| 67 | STATIC int xfs_qm_scall_quotaoff(xfs_mount_t *, uint, boolean_t); |
| 68 | STATIC int xfs_qm_log_quotaoff(xfs_mount_t *, xfs_qoff_logitem_t **, uint); |
| 69 | STATIC int xfs_qm_log_quotaoff_end(xfs_mount_t *, xfs_qoff_logitem_t *, |
| 70 | uint); |
| 71 | STATIC uint xfs_qm_import_flags(uint); |
| 72 | STATIC uint xfs_qm_export_flags(uint); |
| 73 | STATIC uint xfs_qm_import_qtype_flags(uint); |
| 74 | STATIC uint xfs_qm_export_qtype_flags(uint); |
| 75 | STATIC void xfs_qm_export_dquot(xfs_mount_t *, xfs_disk_dquot_t *, |
| 76 | fs_disk_quota_t *); |
| 77 | |
| 78 | |
| 79 | /* |
| 80 | * The main distribution switch of all XFS quotactl system calls. |
| 81 | */ |
| 82 | int |
| 83 | xfs_qm_quotactl( |
Christoph Hellwig | b09cc77 | 2007-08-30 17:19:57 +1000 | [diff] [blame^] | 84 | xfs_mount_t *mp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | int cmd, |
| 86 | int id, |
| 87 | xfs_caddr_t addr) |
| 88 | { |
Christoph Hellwig | b09cc77 | 2007-08-30 17:19:57 +1000 | [diff] [blame^] | 89 | bhv_vfs_t *vfsp = XFS_MTOVFS(mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
Nathan Scott | ee34807 | 2005-11-02 10:32:38 +1100 | [diff] [blame] | 93 | ASSERT(addr != NULL || cmd == Q_XQUOTASYNC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
| 95 | /* |
| 96 | * The following commands are valid even when quotaoff. |
| 97 | */ |
| 98 | switch (cmd) { |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 99 | case Q_XQUOTARM: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | /* |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 101 | * Truncate quota files. quota must be off. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | */ |
Nathan Scott | c310ab6 | 2005-11-02 10:31:41 +1100 | [diff] [blame] | 103 | if (XFS_IS_QUOTA_ON(mp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | return XFS_ERROR(EINVAL); |
| 105 | if (vfsp->vfs_flag & VFS_RDONLY) |
| 106 | return XFS_ERROR(EROFS); |
| 107 | return (xfs_qm_scall_trunc_qfiles(mp, |
| 108 | xfs_qm_import_qtype_flags(*(uint *)addr))); |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 109 | |
| 110 | case Q_XGETQSTAT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | /* |
| 112 | * Get quota status information. |
| 113 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | return (xfs_qm_scall_getqstat(mp, (fs_quota_stat_t *)addr)); |
| 115 | |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 116 | case Q_XQUOTAON: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | /* |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 118 | * QUOTAON - enabling quota enforcement. |
| 119 | * Quota accounting must be turned on at mount time. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | if (vfsp->vfs_flag & VFS_RDONLY) |
| 122 | return XFS_ERROR(EROFS); |
| 123 | return (xfs_qm_scall_quotaon(mp, |
| 124 | xfs_qm_import_flags(*(uint *)addr))); |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 125 | |
| 126 | case Q_XQUOTAOFF: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | if (vfsp->vfs_flag & VFS_RDONLY) |
| 128 | return XFS_ERROR(EROFS); |
| 129 | break; |
| 130 | |
Nathan Scott | ee34807 | 2005-11-02 10:32:38 +1100 | [diff] [blame] | 131 | case Q_XQUOTASYNC: |
Lachlan McIlroy | 1f9b3b6 | 2007-02-10 18:35:33 +1100 | [diff] [blame] | 132 | return (xfs_sync_inodes(mp, SYNC_DELWRI, NULL)); |
Nathan Scott | ee34807 | 2005-11-02 10:32:38 +1100 | [diff] [blame] | 133 | |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 134 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | break; |
| 136 | } |
| 137 | |
| 138 | if (! XFS_IS_QUOTA_ON(mp)) |
| 139 | return XFS_ERROR(ESRCH); |
| 140 | |
| 141 | switch (cmd) { |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 142 | case Q_XQUOTAOFF: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | if (vfsp->vfs_flag & VFS_RDONLY) |
| 144 | return XFS_ERROR(EROFS); |
| 145 | error = xfs_qm_scall_quotaoff(mp, |
| 146 | xfs_qm_import_flags(*(uint *)addr), |
| 147 | B_FALSE); |
| 148 | break; |
| 149 | |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 150 | case Q_XGETQUOTA: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | error = xfs_qm_scall_getquota(mp, (xfs_dqid_t)id, XFS_DQ_USER, |
| 152 | (fs_disk_quota_t *)addr); |
| 153 | break; |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 154 | case Q_XGETGQUOTA: |
| 155 | error = xfs_qm_scall_getquota(mp, (xfs_dqid_t)id, XFS_DQ_GROUP, |
| 156 | (fs_disk_quota_t *)addr); |
| 157 | break; |
| 158 | case Q_XGETPQUOTA: |
| 159 | error = xfs_qm_scall_getquota(mp, (xfs_dqid_t)id, XFS_DQ_PROJ, |
| 160 | (fs_disk_quota_t *)addr); |
| 161 | break; |
| 162 | |
| 163 | case Q_XSETQLIM: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | if (vfsp->vfs_flag & VFS_RDONLY) |
| 165 | return XFS_ERROR(EROFS); |
| 166 | error = xfs_qm_scall_setqlim(mp, (xfs_dqid_t)id, XFS_DQ_USER, |
| 167 | (fs_disk_quota_t *)addr); |
| 168 | break; |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 169 | case Q_XSETGQLIM: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | if (vfsp->vfs_flag & VFS_RDONLY) |
| 171 | return XFS_ERROR(EROFS); |
| 172 | error = xfs_qm_scall_setqlim(mp, (xfs_dqid_t)id, XFS_DQ_GROUP, |
| 173 | (fs_disk_quota_t *)addr); |
| 174 | break; |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 175 | case Q_XSETPQLIM: |
| 176 | if (vfsp->vfs_flag & VFS_RDONLY) |
| 177 | return XFS_ERROR(EROFS); |
| 178 | error = xfs_qm_scall_setqlim(mp, (xfs_dqid_t)id, XFS_DQ_PROJ, |
| 179 | (fs_disk_quota_t *)addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | break; |
| 181 | |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 182 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | error = XFS_ERROR(EINVAL); |
| 184 | break; |
| 185 | } |
| 186 | |
| 187 | return (error); |
| 188 | } |
| 189 | |
| 190 | /* |
| 191 | * Turn off quota accounting and/or enforcement for all udquots and/or |
| 192 | * gdquots. Called only at unmount time. |
| 193 | * |
| 194 | * This assumes that there are no dquots of this file system cached |
| 195 | * incore, and modifies the ondisk dquot directly. Therefore, for example, |
| 196 | * it is an error to call this twice, without purging the cache. |
| 197 | */ |
| 198 | STATIC int |
| 199 | xfs_qm_scall_quotaoff( |
| 200 | xfs_mount_t *mp, |
| 201 | uint flags, |
| 202 | boolean_t force) |
| 203 | { |
| 204 | uint dqtype; |
| 205 | unsigned long s; |
| 206 | int error; |
| 207 | uint inactivate_flags; |
| 208 | xfs_qoff_logitem_t *qoffstart; |
| 209 | int nculprits; |
| 210 | |
| 211 | if (!force && !capable(CAP_SYS_ADMIN)) |
| 212 | return XFS_ERROR(EPERM); |
| 213 | /* |
| 214 | * No file system can have quotas enabled on disk but not in core. |
| 215 | * Note that quota utilities (like quotaoff) _expect_ |
| 216 | * errno == EEXIST here. |
| 217 | */ |
| 218 | if ((mp->m_qflags & flags) == 0) |
| 219 | return XFS_ERROR(EEXIST); |
| 220 | error = 0; |
| 221 | |
| 222 | flags &= (XFS_ALL_QUOTA_ACCT | XFS_ALL_QUOTA_ENFD); |
| 223 | |
| 224 | /* |
| 225 | * We don't want to deal with two quotaoffs messing up each other, |
| 226 | * so we're going to serialize it. quotaoff isn't exactly a performance |
| 227 | * critical thing. |
| 228 | * If quotaoff, then we must be dealing with the root filesystem. |
| 229 | */ |
| 230 | ASSERT(mp->m_quotainfo); |
| 231 | if (mp->m_quotainfo) |
Jes Sorensen | 794ee1b | 2006-01-09 15:59:21 -0800 | [diff] [blame] | 232 | mutex_lock(&(XFS_QI_QOFFLOCK(mp))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
| 234 | ASSERT(mp->m_quotainfo); |
| 235 | |
| 236 | /* |
| 237 | * If we're just turning off quota enforcement, change mp and go. |
| 238 | */ |
| 239 | if ((flags & XFS_ALL_QUOTA_ACCT) == 0) { |
| 240 | mp->m_qflags &= ~(flags); |
| 241 | |
| 242 | s = XFS_SB_LOCK(mp); |
| 243 | mp->m_sb.sb_qflags = mp->m_qflags; |
| 244 | XFS_SB_UNLOCK(mp, s); |
| 245 | mutex_unlock(&(XFS_QI_QOFFLOCK(mp))); |
| 246 | |
| 247 | /* XXX what to do if error ? Revert back to old vals incore ? */ |
| 248 | error = xfs_qm_write_sb_changes(mp, XFS_SB_QFLAGS); |
| 249 | return (error); |
| 250 | } |
| 251 | |
| 252 | dqtype = 0; |
| 253 | inactivate_flags = 0; |
| 254 | /* |
| 255 | * If accounting is off, we must turn enforcement off, clear the |
| 256 | * quota 'CHKD' certificate to make it known that we have to |
| 257 | * do a quotacheck the next time this quota is turned on. |
| 258 | */ |
| 259 | if (flags & XFS_UQUOTA_ACCT) { |
| 260 | dqtype |= XFS_QMOPT_UQUOTA; |
| 261 | flags |= (XFS_UQUOTA_CHKD | XFS_UQUOTA_ENFD); |
| 262 | inactivate_flags |= XFS_UQUOTA_ACTIVE; |
| 263 | } |
| 264 | if (flags & XFS_GQUOTA_ACCT) { |
| 265 | dqtype |= XFS_QMOPT_GQUOTA; |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 266 | flags |= (XFS_OQUOTA_CHKD | XFS_OQUOTA_ENFD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | inactivate_flags |= XFS_GQUOTA_ACTIVE; |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 268 | } else if (flags & XFS_PQUOTA_ACCT) { |
| 269 | dqtype |= XFS_QMOPT_PQUOTA; |
| 270 | flags |= (XFS_OQUOTA_CHKD | XFS_OQUOTA_ENFD); |
| 271 | inactivate_flags |= XFS_PQUOTA_ACTIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | /* |
| 275 | * Nothing to do? Don't complain. This happens when we're just |
| 276 | * turning off quota enforcement. |
| 277 | */ |
| 278 | if ((mp->m_qflags & flags) == 0) { |
| 279 | mutex_unlock(&(XFS_QI_QOFFLOCK(mp))); |
| 280 | return (0); |
| 281 | } |
| 282 | |
| 283 | /* |
| 284 | * Write the LI_QUOTAOFF log record, and do SB changes atomically, |
| 285 | * and synchronously. |
| 286 | */ |
| 287 | xfs_qm_log_quotaoff(mp, &qoffstart, flags); |
| 288 | |
| 289 | /* |
| 290 | * Next we clear the XFS_MOUNT_*DQ_ACTIVE bit(s) in the mount struct |
| 291 | * to take care of the race between dqget and quotaoff. We don't take |
| 292 | * any special locks to reset these bits. All processes need to check |
| 293 | * these bits *after* taking inode lock(s) to see if the particular |
| 294 | * quota type is in the process of being turned off. If *ACTIVE, it is |
| 295 | * guaranteed that all dquot structures and all quotainode ptrs will all |
| 296 | * stay valid as long as that inode is kept locked. |
| 297 | * |
| 298 | * There is no turning back after this. |
| 299 | */ |
| 300 | mp->m_qflags &= ~inactivate_flags; |
| 301 | |
| 302 | /* |
| 303 | * Give back all the dquot reference(s) held by inodes. |
| 304 | * Here we go thru every single incore inode in this file system, and |
| 305 | * do a dqrele on the i_udquot/i_gdquot that it may have. |
| 306 | * Essentially, as long as somebody has an inode locked, this guarantees |
| 307 | * that quotas will not be turned off. This is handy because in a |
| 308 | * transaction once we lock the inode(s) and check for quotaon, we can |
| 309 | * depend on the quota inodes (and other things) being valid as long as |
| 310 | * we keep the lock(s). |
| 311 | */ |
| 312 | xfs_qm_dqrele_all_inodes(mp, flags); |
| 313 | |
| 314 | /* |
| 315 | * Next we make the changes in the quota flag in the mount struct. |
| 316 | * This isn't protected by a particular lock directly, because we |
| 317 | * don't want to take a mrlock everytime we depend on quotas being on. |
| 318 | */ |
| 319 | mp->m_qflags &= ~(flags); |
| 320 | |
| 321 | /* |
| 322 | * Go through all the dquots of this file system and purge them, |
| 323 | * according to what was turned off. We may not be able to get rid |
| 324 | * of all dquots, because dquots can have temporary references that |
| 325 | * are not attached to inodes. eg. xfs_setattr, xfs_create. |
| 326 | * So, if we couldn't purge all the dquots from the filesystem, |
| 327 | * we can't get rid of the incore data structures. |
| 328 | */ |
| 329 | while ((nculprits = xfs_qm_dqpurge_all(mp, dqtype|XFS_QMOPT_QUOTAOFF))) |
| 330 | delay(10 * nculprits); |
| 331 | |
| 332 | /* |
| 333 | * Transactions that had started before ACTIVE state bit was cleared |
| 334 | * could have logged many dquots, so they'd have higher LSNs than |
| 335 | * the first QUOTAOFF log record does. If we happen to crash when |
| 336 | * the tail of the log has gone past the QUOTAOFF record, but |
| 337 | * before the last dquot modification, those dquots __will__ |
| 338 | * recover, and that's not good. |
| 339 | * |
| 340 | * So, we have QUOTAOFF start and end logitems; the start |
| 341 | * logitem won't get overwritten until the end logitem appears... |
| 342 | */ |
| 343 | xfs_qm_log_quotaoff_end(mp, qoffstart, flags); |
| 344 | |
| 345 | /* |
| 346 | * If quotas is completely disabled, close shop. |
| 347 | */ |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 348 | if (((flags & XFS_MOUNT_QUOTA_ALL) == XFS_MOUNT_QUOTA_SET1) || |
| 349 | ((flags & XFS_MOUNT_QUOTA_ALL) == XFS_MOUNT_QUOTA_SET2)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | mutex_unlock(&(XFS_QI_QOFFLOCK(mp))); |
| 351 | xfs_qm_destroy_quotainfo(mp); |
| 352 | return (0); |
| 353 | } |
| 354 | |
| 355 | /* |
| 356 | * Release our quotainode references, and vn_purge them, |
| 357 | * if we don't need them anymore. |
| 358 | */ |
| 359 | if ((dqtype & XFS_QMOPT_UQUOTA) && XFS_QI_UQIP(mp)) { |
| 360 | XFS_PURGE_INODE(XFS_QI_UQIP(mp)); |
| 361 | XFS_QI_UQIP(mp) = NULL; |
| 362 | } |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 363 | if ((dqtype & (XFS_QMOPT_GQUOTA|XFS_QMOPT_PQUOTA)) && XFS_QI_GQIP(mp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | XFS_PURGE_INODE(XFS_QI_GQIP(mp)); |
| 365 | XFS_QI_GQIP(mp) = NULL; |
| 366 | } |
| 367 | mutex_unlock(&(XFS_QI_QOFFLOCK(mp))); |
| 368 | |
| 369 | return (error); |
| 370 | } |
| 371 | |
| 372 | STATIC int |
| 373 | xfs_qm_scall_trunc_qfiles( |
| 374 | xfs_mount_t *mp, |
| 375 | uint flags) |
| 376 | { |
| 377 | int error; |
| 378 | xfs_inode_t *qip; |
| 379 | |
| 380 | if (!capable(CAP_SYS_ADMIN)) |
| 381 | return XFS_ERROR(EPERM); |
| 382 | error = 0; |
| 383 | if (!XFS_SB_VERSION_HASQUOTA(&mp->m_sb) || flags == 0) { |
| 384 | qdprintk("qtrunc flags=%x m_qflags=%x\n", flags, mp->m_qflags); |
| 385 | return XFS_ERROR(EINVAL); |
| 386 | } |
| 387 | |
| 388 | if ((flags & XFS_DQ_USER) && mp->m_sb.sb_uquotino != NULLFSINO) { |
| 389 | error = xfs_iget(mp, NULL, mp->m_sb.sb_uquotino, 0, 0, &qip, 0); |
| 390 | if (! error) { |
| 391 | (void) xfs_truncate_file(mp, qip); |
| 392 | VN_RELE(XFS_ITOV(qip)); |
| 393 | } |
| 394 | } |
| 395 | |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 396 | if ((flags & (XFS_DQ_GROUP|XFS_DQ_PROJ)) && |
| 397 | mp->m_sb.sb_gquotino != NULLFSINO) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | error = xfs_iget(mp, NULL, mp->m_sb.sb_gquotino, 0, 0, &qip, 0); |
| 399 | if (! error) { |
| 400 | (void) xfs_truncate_file(mp, qip); |
| 401 | VN_RELE(XFS_ITOV(qip)); |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | return (error); |
| 406 | } |
| 407 | |
| 408 | |
| 409 | /* |
| 410 | * Switch on (a given) quota enforcement for a filesystem. This takes |
| 411 | * effect immediately. |
| 412 | * (Switching on quota accounting must be done at mount time.) |
| 413 | */ |
| 414 | STATIC int |
| 415 | xfs_qm_scall_quotaon( |
| 416 | xfs_mount_t *mp, |
| 417 | uint flags) |
| 418 | { |
| 419 | int error; |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 420 | unsigned long s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | uint qf; |
| 422 | uint accflags; |
| 423 | __int64_t sbflags; |
| 424 | |
| 425 | if (!capable(CAP_SYS_ADMIN)) |
| 426 | return XFS_ERROR(EPERM); |
| 427 | |
| 428 | flags &= (XFS_ALL_QUOTA_ACCT | XFS_ALL_QUOTA_ENFD); |
| 429 | /* |
| 430 | * Switching on quota accounting must be done at mount time. |
| 431 | */ |
| 432 | accflags = flags & XFS_ALL_QUOTA_ACCT; |
| 433 | flags &= ~(XFS_ALL_QUOTA_ACCT); |
| 434 | |
| 435 | sbflags = 0; |
| 436 | |
| 437 | if (flags == 0) { |
| 438 | qdprintk("quotaon: zero flags, m_qflags=%x\n", mp->m_qflags); |
| 439 | return XFS_ERROR(EINVAL); |
| 440 | } |
| 441 | |
| 442 | /* No fs can turn on quotas with a delayed effect */ |
| 443 | ASSERT((flags & XFS_ALL_QUOTA_ACCT) == 0); |
| 444 | |
| 445 | /* |
| 446 | * Can't enforce without accounting. We check the superblock |
| 447 | * qflags here instead of m_qflags because rootfs can have |
| 448 | * quota acct on ondisk without m_qflags' knowing. |
| 449 | */ |
| 450 | if (((flags & XFS_UQUOTA_ACCT) == 0 && |
| 451 | (mp->m_sb.sb_qflags & XFS_UQUOTA_ACCT) == 0 && |
| 452 | (flags & XFS_UQUOTA_ENFD)) |
| 453 | || |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 454 | ((flags & XFS_PQUOTA_ACCT) == 0 && |
| 455 | (mp->m_sb.sb_qflags & XFS_PQUOTA_ACCT) == 0 && |
Donald Douwsma | 424ea91 | 2007-05-08 13:49:15 +1000 | [diff] [blame] | 456 | (flags & XFS_GQUOTA_ACCT) == 0 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | (mp->m_sb.sb_qflags & XFS_GQUOTA_ACCT) == 0 && |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 458 | (flags & XFS_OQUOTA_ENFD))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | qdprintk("Can't enforce without acct, flags=%x sbflags=%x\n", |
| 460 | flags, mp->m_sb.sb_qflags); |
| 461 | return XFS_ERROR(EINVAL); |
| 462 | } |
| 463 | /* |
| 464 | * If everything's upto-date incore, then don't waste time. |
| 465 | */ |
| 466 | if ((mp->m_qflags & flags) == flags) |
| 467 | return XFS_ERROR(EEXIST); |
| 468 | |
| 469 | /* |
| 470 | * Change sb_qflags on disk but not incore mp->qflags |
| 471 | * if this is the root filesystem. |
| 472 | */ |
| 473 | s = XFS_SB_LOCK(mp); |
| 474 | qf = mp->m_sb.sb_qflags; |
| 475 | mp->m_sb.sb_qflags = qf | flags; |
| 476 | XFS_SB_UNLOCK(mp, s); |
| 477 | |
| 478 | /* |
| 479 | * There's nothing to change if it's the same. |
| 480 | */ |
| 481 | if ((qf & flags) == flags && sbflags == 0) |
| 482 | return XFS_ERROR(EEXIST); |
| 483 | sbflags |= XFS_SB_QFLAGS; |
| 484 | |
| 485 | if ((error = xfs_qm_write_sb_changes(mp, sbflags))) |
| 486 | return (error); |
| 487 | /* |
| 488 | * If we aren't trying to switch on quota enforcement, we are done. |
| 489 | */ |
| 490 | if (((mp->m_sb.sb_qflags & XFS_UQUOTA_ACCT) != |
| 491 | (mp->m_qflags & XFS_UQUOTA_ACCT)) || |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 492 | ((mp->m_sb.sb_qflags & XFS_PQUOTA_ACCT) != |
| 493 | (mp->m_qflags & XFS_PQUOTA_ACCT)) || |
| 494 | ((mp->m_sb.sb_qflags & XFS_GQUOTA_ACCT) != |
| 495 | (mp->m_qflags & XFS_GQUOTA_ACCT)) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | (flags & XFS_ALL_QUOTA_ENFD) == 0) |
| 497 | return (0); |
| 498 | |
| 499 | if (! XFS_IS_QUOTA_RUNNING(mp)) |
| 500 | return XFS_ERROR(ESRCH); |
| 501 | |
| 502 | /* |
| 503 | * Switch on quota enforcement in core. |
| 504 | */ |
Jes Sorensen | 794ee1b | 2006-01-09 15:59:21 -0800 | [diff] [blame] | 505 | mutex_lock(&(XFS_QI_QOFFLOCK(mp))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | mp->m_qflags |= (flags & XFS_ALL_QUOTA_ENFD); |
| 507 | mutex_unlock(&(XFS_QI_QOFFLOCK(mp))); |
| 508 | |
| 509 | return (0); |
| 510 | } |
| 511 | |
| 512 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | /* |
| 514 | * Return quota status information, such as uquota-off, enforcements, etc. |
| 515 | */ |
| 516 | STATIC int |
| 517 | xfs_qm_scall_getqstat( |
| 518 | xfs_mount_t *mp, |
| 519 | fs_quota_stat_t *out) |
| 520 | { |
| 521 | xfs_inode_t *uip, *gip; |
| 522 | boolean_t tempuqip, tempgqip; |
| 523 | |
| 524 | uip = gip = NULL; |
| 525 | tempuqip = tempgqip = B_FALSE; |
| 526 | memset(out, 0, sizeof(fs_quota_stat_t)); |
| 527 | |
| 528 | out->qs_version = FS_QSTAT_VERSION; |
| 529 | if (! XFS_SB_VERSION_HASQUOTA(&mp->m_sb)) { |
| 530 | out->qs_uquota.qfs_ino = NULLFSINO; |
| 531 | out->qs_gquota.qfs_ino = NULLFSINO; |
| 532 | return (0); |
| 533 | } |
| 534 | out->qs_flags = (__uint16_t) xfs_qm_export_flags(mp->m_qflags & |
| 535 | (XFS_ALL_QUOTA_ACCT| |
| 536 | XFS_ALL_QUOTA_ENFD)); |
| 537 | out->qs_pad = 0; |
| 538 | out->qs_uquota.qfs_ino = mp->m_sb.sb_uquotino; |
| 539 | out->qs_gquota.qfs_ino = mp->m_sb.sb_gquotino; |
| 540 | |
| 541 | if (mp->m_quotainfo) { |
| 542 | uip = mp->m_quotainfo->qi_uquotaip; |
| 543 | gip = mp->m_quotainfo->qi_gquotaip; |
| 544 | } |
| 545 | if (!uip && mp->m_sb.sb_uquotino != NULLFSINO) { |
| 546 | if (xfs_iget(mp, NULL, mp->m_sb.sb_uquotino, |
| 547 | 0, 0, &uip, 0) == 0) |
| 548 | tempuqip = B_TRUE; |
| 549 | } |
| 550 | if (!gip && mp->m_sb.sb_gquotino != NULLFSINO) { |
| 551 | if (xfs_iget(mp, NULL, mp->m_sb.sb_gquotino, |
| 552 | 0, 0, &gip, 0) == 0) |
| 553 | tempgqip = B_TRUE; |
| 554 | } |
| 555 | if (uip) { |
| 556 | out->qs_uquota.qfs_nblks = uip->i_d.di_nblocks; |
| 557 | out->qs_uquota.qfs_nextents = uip->i_d.di_nextents; |
| 558 | if (tempuqip) |
| 559 | VN_RELE(XFS_ITOV(uip)); |
| 560 | } |
| 561 | if (gip) { |
| 562 | out->qs_gquota.qfs_nblks = gip->i_d.di_nblocks; |
| 563 | out->qs_gquota.qfs_nextents = gip->i_d.di_nextents; |
| 564 | if (tempgqip) |
| 565 | VN_RELE(XFS_ITOV(gip)); |
| 566 | } |
| 567 | if (mp->m_quotainfo) { |
| 568 | out->qs_incoredqs = XFS_QI_MPLNDQUOTS(mp); |
| 569 | out->qs_btimelimit = XFS_QI_BTIMELIMIT(mp); |
| 570 | out->qs_itimelimit = XFS_QI_ITIMELIMIT(mp); |
| 571 | out->qs_rtbtimelimit = XFS_QI_RTBTIMELIMIT(mp); |
| 572 | out->qs_bwarnlimit = XFS_QI_BWARNLIMIT(mp); |
| 573 | out->qs_iwarnlimit = XFS_QI_IWARNLIMIT(mp); |
| 574 | } |
| 575 | return (0); |
| 576 | } |
| 577 | |
| 578 | /* |
| 579 | * Adjust quota limits, and start/stop timers accordingly. |
| 580 | */ |
| 581 | STATIC int |
| 582 | xfs_qm_scall_setqlim( |
| 583 | xfs_mount_t *mp, |
| 584 | xfs_dqid_t id, |
| 585 | uint type, |
| 586 | fs_disk_quota_t *newlim) |
| 587 | { |
| 588 | xfs_disk_dquot_t *ddq; |
| 589 | xfs_dquot_t *dqp; |
| 590 | xfs_trans_t *tp; |
| 591 | int error; |
| 592 | xfs_qcnt_t hard, soft; |
| 593 | |
| 594 | if (!capable(CAP_SYS_ADMIN)) |
| 595 | return XFS_ERROR(EPERM); |
| 596 | |
Nathan Scott | 754002b | 2005-06-21 15:49:06 +1000 | [diff] [blame] | 597 | if ((newlim->d_fieldmask & |
| 598 | (FS_DQ_LIMIT_MASK|FS_DQ_TIMER_MASK|FS_DQ_WARNS_MASK)) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | return (0); |
| 600 | |
| 601 | tp = xfs_trans_alloc(mp, XFS_TRANS_QM_SETQLIM); |
| 602 | if ((error = xfs_trans_reserve(tp, 0, sizeof(xfs_disk_dquot_t) + 128, |
| 603 | 0, 0, XFS_DEFAULT_LOG_COUNT))) { |
| 604 | xfs_trans_cancel(tp, 0); |
| 605 | return (error); |
| 606 | } |
| 607 | |
| 608 | /* |
| 609 | * We don't want to race with a quotaoff so take the quotaoff lock. |
| 610 | * (We don't hold an inode lock, so there's nothing else to stop |
| 611 | * a quotaoff from happening). (XXXThis doesn't currently happen |
| 612 | * because we take the vfslock before calling xfs_qm_sysent). |
| 613 | */ |
Jes Sorensen | 794ee1b | 2006-01-09 15:59:21 -0800 | [diff] [blame] | 614 | mutex_lock(&(XFS_QI_QOFFLOCK(mp))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | |
| 616 | /* |
| 617 | * Get the dquot (locked), and join it to the transaction. |
| 618 | * Allocate the dquot if this doesn't exist. |
| 619 | */ |
| 620 | if ((error = xfs_qm_dqget(mp, NULL, id, type, XFS_QMOPT_DQALLOC, &dqp))) { |
| 621 | xfs_trans_cancel(tp, XFS_TRANS_ABORT); |
| 622 | mutex_unlock(&(XFS_QI_QOFFLOCK(mp))); |
| 623 | ASSERT(error != ENOENT); |
| 624 | return (error); |
| 625 | } |
| 626 | xfs_dqtrace_entry(dqp, "Q_SETQLIM: AFT DQGET"); |
| 627 | xfs_trans_dqjoin(tp, dqp); |
| 628 | ddq = &dqp->q_core; |
| 629 | |
| 630 | /* |
| 631 | * Make sure that hardlimits are >= soft limits before changing. |
| 632 | */ |
| 633 | hard = (newlim->d_fieldmask & FS_DQ_BHARD) ? |
| 634 | (xfs_qcnt_t) XFS_BB_TO_FSB(mp, newlim->d_blk_hardlimit) : |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 635 | be64_to_cpu(ddq->d_blk_hardlimit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | soft = (newlim->d_fieldmask & FS_DQ_BSOFT) ? |
| 637 | (xfs_qcnt_t) XFS_BB_TO_FSB(mp, newlim->d_blk_softlimit) : |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 638 | be64_to_cpu(ddq->d_blk_softlimit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | if (hard == 0 || hard >= soft) { |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 640 | ddq->d_blk_hardlimit = cpu_to_be64(hard); |
| 641 | ddq->d_blk_softlimit = cpu_to_be64(soft); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | if (id == 0) { |
| 643 | mp->m_quotainfo->qi_bhardlimit = hard; |
| 644 | mp->m_quotainfo->qi_bsoftlimit = soft; |
| 645 | } |
| 646 | } else { |
| 647 | qdprintk("blkhard %Ld < blksoft %Ld\n", hard, soft); |
| 648 | } |
| 649 | hard = (newlim->d_fieldmask & FS_DQ_RTBHARD) ? |
| 650 | (xfs_qcnt_t) XFS_BB_TO_FSB(mp, newlim->d_rtb_hardlimit) : |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 651 | be64_to_cpu(ddq->d_rtb_hardlimit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | soft = (newlim->d_fieldmask & FS_DQ_RTBSOFT) ? |
| 653 | (xfs_qcnt_t) XFS_BB_TO_FSB(mp, newlim->d_rtb_softlimit) : |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 654 | be64_to_cpu(ddq->d_rtb_softlimit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | if (hard == 0 || hard >= soft) { |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 656 | ddq->d_rtb_hardlimit = cpu_to_be64(hard); |
| 657 | ddq->d_rtb_softlimit = cpu_to_be64(soft); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | if (id == 0) { |
| 659 | mp->m_quotainfo->qi_rtbhardlimit = hard; |
| 660 | mp->m_quotainfo->qi_rtbsoftlimit = soft; |
| 661 | } |
| 662 | } else { |
| 663 | qdprintk("rtbhard %Ld < rtbsoft %Ld\n", hard, soft); |
| 664 | } |
| 665 | |
| 666 | hard = (newlim->d_fieldmask & FS_DQ_IHARD) ? |
| 667 | (xfs_qcnt_t) newlim->d_ino_hardlimit : |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 668 | be64_to_cpu(ddq->d_ino_hardlimit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | soft = (newlim->d_fieldmask & FS_DQ_ISOFT) ? |
| 670 | (xfs_qcnt_t) newlim->d_ino_softlimit : |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 671 | be64_to_cpu(ddq->d_ino_softlimit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | if (hard == 0 || hard >= soft) { |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 673 | ddq->d_ino_hardlimit = cpu_to_be64(hard); |
| 674 | ddq->d_ino_softlimit = cpu_to_be64(soft); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | if (id == 0) { |
| 676 | mp->m_quotainfo->qi_ihardlimit = hard; |
| 677 | mp->m_quotainfo->qi_isoftlimit = soft; |
| 678 | } |
| 679 | } else { |
| 680 | qdprintk("ihard %Ld < isoft %Ld\n", hard, soft); |
| 681 | } |
| 682 | |
Nathan Scott | 754002b | 2005-06-21 15:49:06 +1000 | [diff] [blame] | 683 | /* |
| 684 | * Update warnings counter(s) if requested |
| 685 | */ |
| 686 | if (newlim->d_fieldmask & FS_DQ_BWARNS) |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 687 | ddq->d_bwarns = cpu_to_be16(newlim->d_bwarns); |
Nathan Scott | 754002b | 2005-06-21 15:49:06 +1000 | [diff] [blame] | 688 | if (newlim->d_fieldmask & FS_DQ_IWARNS) |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 689 | ddq->d_iwarns = cpu_to_be16(newlim->d_iwarns); |
Nathan Scott | 754002b | 2005-06-21 15:49:06 +1000 | [diff] [blame] | 690 | if (newlim->d_fieldmask & FS_DQ_RTBWARNS) |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 691 | ddq->d_rtbwarns = cpu_to_be16(newlim->d_rtbwarns); |
Nathan Scott | 754002b | 2005-06-21 15:49:06 +1000 | [diff] [blame] | 692 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | if (id == 0) { |
| 694 | /* |
| 695 | * Timelimits for the super user set the relative time |
| 696 | * the other users can be over quota for this file system. |
| 697 | * If it is zero a default is used. Ditto for the default |
Nathan Scott | 754002b | 2005-06-21 15:49:06 +1000 | [diff] [blame] | 698 | * soft and hard limit values (already done, above), and |
| 699 | * for warnings. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | */ |
| 701 | if (newlim->d_fieldmask & FS_DQ_BTIMER) { |
| 702 | mp->m_quotainfo->qi_btimelimit = newlim->d_btimer; |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 703 | ddq->d_btimer = cpu_to_be32(newlim->d_btimer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | } |
| 705 | if (newlim->d_fieldmask & FS_DQ_ITIMER) { |
| 706 | mp->m_quotainfo->qi_itimelimit = newlim->d_itimer; |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 707 | ddq->d_itimer = cpu_to_be32(newlim->d_itimer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | } |
| 709 | if (newlim->d_fieldmask & FS_DQ_RTBTIMER) { |
| 710 | mp->m_quotainfo->qi_rtbtimelimit = newlim->d_rtbtimer; |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 711 | ddq->d_rtbtimer = cpu_to_be32(newlim->d_rtbtimer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | } |
Nathan Scott | 754002b | 2005-06-21 15:49:06 +1000 | [diff] [blame] | 713 | if (newlim->d_fieldmask & FS_DQ_BWARNS) |
| 714 | mp->m_quotainfo->qi_bwarnlimit = newlim->d_bwarns; |
| 715 | if (newlim->d_fieldmask & FS_DQ_IWARNS) |
| 716 | mp->m_quotainfo->qi_iwarnlimit = newlim->d_iwarns; |
| 717 | if (newlim->d_fieldmask & FS_DQ_RTBWARNS) |
| 718 | mp->m_quotainfo->qi_rtbwarnlimit = newlim->d_rtbwarns; |
| 719 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | /* |
| 721 | * If the user is now over quota, start the timelimit. |
| 722 | * The user will not be 'warned'. |
| 723 | * Note that we keep the timers ticking, whether enforcement |
| 724 | * is on or off. We don't really want to bother with iterating |
| 725 | * over all ondisk dquots and turning the timers on/off. |
| 726 | */ |
| 727 | xfs_qm_adjust_dqtimers(mp, ddq); |
| 728 | } |
| 729 | dqp->dq_flags |= XFS_DQ_DIRTY; |
| 730 | xfs_trans_log_dquot(tp, dqp); |
| 731 | |
| 732 | xfs_dqtrace_entry(dqp, "Q_SETQLIM: COMMIT"); |
Eric Sandeen | 1c72bf9 | 2007-05-08 13:48:42 +1000 | [diff] [blame] | 733 | xfs_trans_commit(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | xfs_qm_dqprint(dqp); |
| 735 | xfs_qm_dqrele(dqp); |
| 736 | mutex_unlock(&(XFS_QI_QOFFLOCK(mp))); |
| 737 | |
| 738 | return (0); |
| 739 | } |
| 740 | |
| 741 | STATIC int |
| 742 | xfs_qm_scall_getquota( |
| 743 | xfs_mount_t *mp, |
| 744 | xfs_dqid_t id, |
| 745 | uint type, |
| 746 | fs_disk_quota_t *out) |
| 747 | { |
| 748 | xfs_dquot_t *dqp; |
| 749 | int error; |
| 750 | |
| 751 | /* |
| 752 | * Try to get the dquot. We don't want it allocated on disk, so |
| 753 | * we aren't passing the XFS_QMOPT_DOALLOC flag. If it doesn't |
| 754 | * exist, we'll get ENOENT back. |
| 755 | */ |
| 756 | if ((error = xfs_qm_dqget(mp, NULL, id, type, 0, &dqp))) { |
| 757 | return (error); |
| 758 | } |
| 759 | |
| 760 | xfs_dqtrace_entry(dqp, "Q_GETQUOTA SUCCESS"); |
| 761 | /* |
| 762 | * If everything's NULL, this dquot doesn't quite exist as far as |
| 763 | * our utility programs are concerned. |
| 764 | */ |
| 765 | if (XFS_IS_DQUOT_UNINITIALIZED(dqp)) { |
| 766 | xfs_qm_dqput(dqp); |
| 767 | return XFS_ERROR(ENOENT); |
| 768 | } |
| 769 | /* xfs_qm_dqprint(dqp); */ |
| 770 | /* |
| 771 | * Convert the disk dquot to the exportable format |
| 772 | */ |
| 773 | xfs_qm_export_dquot(mp, &dqp->q_core, out); |
| 774 | xfs_qm_dqput(dqp); |
| 775 | return (error ? XFS_ERROR(EFAULT) : 0); |
| 776 | } |
| 777 | |
| 778 | |
| 779 | STATIC int |
| 780 | xfs_qm_log_quotaoff_end( |
| 781 | xfs_mount_t *mp, |
| 782 | xfs_qoff_logitem_t *startqoff, |
| 783 | uint flags) |
| 784 | { |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 785 | xfs_trans_t *tp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | int error; |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 787 | xfs_qoff_logitem_t *qoffi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | |
| 789 | tp = xfs_trans_alloc(mp, XFS_TRANS_QM_QUOTAOFF_END); |
| 790 | |
| 791 | if ((error = xfs_trans_reserve(tp, 0, sizeof(xfs_qoff_logitem_t) * 2, |
| 792 | 0, 0, XFS_DEFAULT_LOG_COUNT))) { |
| 793 | xfs_trans_cancel(tp, 0); |
| 794 | return (error); |
| 795 | } |
| 796 | |
| 797 | qoffi = xfs_trans_get_qoff_item(tp, startqoff, |
| 798 | flags & XFS_ALL_QUOTA_ACCT); |
| 799 | xfs_trans_log_quotaoff_item(tp, qoffi); |
| 800 | |
| 801 | /* |
| 802 | * We have to make sure that the transaction is secure on disk before we |
| 803 | * return and actually stop quota accounting. So, make it synchronous. |
| 804 | * We don't care about quotoff's performance. |
| 805 | */ |
| 806 | xfs_trans_set_sync(tp); |
Eric Sandeen | 1c72bf9 | 2007-05-08 13:48:42 +1000 | [diff] [blame] | 807 | error = xfs_trans_commit(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | return (error); |
| 809 | } |
| 810 | |
| 811 | |
| 812 | STATIC int |
| 813 | xfs_qm_log_quotaoff( |
| 814 | xfs_mount_t *mp, |
| 815 | xfs_qoff_logitem_t **qoffstartp, |
| 816 | uint flags) |
| 817 | { |
| 818 | xfs_trans_t *tp; |
| 819 | int error; |
| 820 | unsigned long s; |
| 821 | xfs_qoff_logitem_t *qoffi=NULL; |
| 822 | uint oldsbqflag=0; |
| 823 | |
| 824 | tp = xfs_trans_alloc(mp, XFS_TRANS_QM_QUOTAOFF); |
| 825 | if ((error = xfs_trans_reserve(tp, 0, |
| 826 | sizeof(xfs_qoff_logitem_t) * 2 + |
| 827 | mp->m_sb.sb_sectsize + 128, |
| 828 | 0, |
| 829 | 0, |
| 830 | XFS_DEFAULT_LOG_COUNT))) { |
| 831 | goto error0; |
| 832 | } |
| 833 | |
| 834 | qoffi = xfs_trans_get_qoff_item(tp, NULL, flags & XFS_ALL_QUOTA_ACCT); |
| 835 | xfs_trans_log_quotaoff_item(tp, qoffi); |
| 836 | |
| 837 | s = XFS_SB_LOCK(mp); |
| 838 | oldsbqflag = mp->m_sb.sb_qflags; |
| 839 | mp->m_sb.sb_qflags = (mp->m_qflags & ~(flags)) & XFS_MOUNT_QUOTA_ALL; |
| 840 | XFS_SB_UNLOCK(mp, s); |
| 841 | |
| 842 | xfs_mod_sb(tp, XFS_SB_QFLAGS); |
| 843 | |
| 844 | /* |
| 845 | * We have to make sure that the transaction is secure on disk before we |
| 846 | * return and actually stop quota accounting. So, make it synchronous. |
| 847 | * We don't care about quotoff's performance. |
| 848 | */ |
| 849 | xfs_trans_set_sync(tp); |
Eric Sandeen | 1c72bf9 | 2007-05-08 13:48:42 +1000 | [diff] [blame] | 850 | error = xfs_trans_commit(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | |
| 852 | error0: |
| 853 | if (error) { |
| 854 | xfs_trans_cancel(tp, 0); |
| 855 | /* |
| 856 | * No one else is modifying sb_qflags, so this is OK. |
| 857 | * We still hold the quotaofflock. |
| 858 | */ |
| 859 | s = XFS_SB_LOCK(mp); |
| 860 | mp->m_sb.sb_qflags = oldsbqflag; |
| 861 | XFS_SB_UNLOCK(mp, s); |
| 862 | } |
| 863 | *qoffstartp = qoffi; |
| 864 | return (error); |
| 865 | } |
| 866 | |
| 867 | |
| 868 | /* |
| 869 | * Translate an internal style on-disk-dquot to the exportable format. |
| 870 | * The main differences are that the counters/limits are all in Basic |
| 871 | * Blocks (BBs) instead of the internal FSBs, and all on-disk data has |
| 872 | * to be converted to the native endianness. |
| 873 | */ |
| 874 | STATIC void |
| 875 | xfs_qm_export_dquot( |
| 876 | xfs_mount_t *mp, |
| 877 | xfs_disk_dquot_t *src, |
| 878 | struct fs_disk_quota *dst) |
| 879 | { |
| 880 | memset(dst, 0, sizeof(*dst)); |
| 881 | dst->d_version = FS_DQUOT_VERSION; /* different from src->d_version */ |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 882 | dst->d_flags = xfs_qm_export_qtype_flags(src->d_flags); |
| 883 | dst->d_id = be32_to_cpu(src->d_id); |
| 884 | dst->d_blk_hardlimit = |
| 885 | XFS_FSB_TO_BB(mp, be64_to_cpu(src->d_blk_hardlimit)); |
| 886 | dst->d_blk_softlimit = |
| 887 | XFS_FSB_TO_BB(mp, be64_to_cpu(src->d_blk_softlimit)); |
| 888 | dst->d_ino_hardlimit = be64_to_cpu(src->d_ino_hardlimit); |
| 889 | dst->d_ino_softlimit = be64_to_cpu(src->d_ino_softlimit); |
| 890 | dst->d_bcount = XFS_FSB_TO_BB(mp, be64_to_cpu(src->d_bcount)); |
| 891 | dst->d_icount = be64_to_cpu(src->d_icount); |
| 892 | dst->d_btimer = be32_to_cpu(src->d_btimer); |
| 893 | dst->d_itimer = be32_to_cpu(src->d_itimer); |
| 894 | dst->d_iwarns = be16_to_cpu(src->d_iwarns); |
| 895 | dst->d_bwarns = be16_to_cpu(src->d_bwarns); |
| 896 | dst->d_rtb_hardlimit = |
| 897 | XFS_FSB_TO_BB(mp, be64_to_cpu(src->d_rtb_hardlimit)); |
| 898 | dst->d_rtb_softlimit = |
| 899 | XFS_FSB_TO_BB(mp, be64_to_cpu(src->d_rtb_softlimit)); |
| 900 | dst->d_rtbcount = XFS_FSB_TO_BB(mp, be64_to_cpu(src->d_rtbcount)); |
| 901 | dst->d_rtbtimer = be32_to_cpu(src->d_rtbtimer); |
| 902 | dst->d_rtbwarns = be16_to_cpu(src->d_rtbwarns); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | |
| 904 | /* |
| 905 | * Internally, we don't reset all the timers when quota enforcement |
Nathan Scott | c41564b | 2006-03-29 08:55:14 +1000 | [diff] [blame] | 906 | * gets turned off. No need to confuse the user level code, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | * so return zeroes in that case. |
| 908 | */ |
Kouta Ooizumi | e6d2942 | 2007-05-08 13:49:33 +1000 | [diff] [blame] | 909 | if ((!XFS_IS_UQUOTA_ENFORCED(mp) && src->d_flags == XFS_DQ_USER) || |
| 910 | (!XFS_IS_OQUOTA_ENFORCED(mp) && |
| 911 | (src->d_flags & (XFS_DQ_PROJ | XFS_DQ_GROUP)))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | dst->d_btimer = 0; |
| 913 | dst->d_itimer = 0; |
| 914 | dst->d_rtbtimer = 0; |
| 915 | } |
| 916 | |
| 917 | #ifdef DEBUG |
Kouta Ooizumi | e6d2942 | 2007-05-08 13:49:33 +1000 | [diff] [blame] | 918 | if (((XFS_IS_UQUOTA_ENFORCED(mp) && dst->d_flags == XFS_USER_QUOTA) || |
| 919 | (XFS_IS_OQUOTA_ENFORCED(mp) && |
| 920 | (dst->d_flags & (XFS_PROJ_QUOTA | XFS_GROUP_QUOTA)))) && |
| 921 | dst->d_id != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | if (((int) dst->d_bcount >= (int) dst->d_blk_softlimit) && |
| 923 | (dst->d_blk_softlimit > 0)) { |
| 924 | ASSERT(dst->d_btimer != 0); |
| 925 | } |
| 926 | if (((int) dst->d_icount >= (int) dst->d_ino_softlimit) && |
| 927 | (dst->d_ino_softlimit > 0)) { |
| 928 | ASSERT(dst->d_itimer != 0); |
| 929 | } |
| 930 | } |
| 931 | #endif |
| 932 | } |
| 933 | |
| 934 | STATIC uint |
| 935 | xfs_qm_import_qtype_flags( |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 936 | uint uflags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | { |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 938 | uint oflags = 0; |
| 939 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | /* |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 941 | * Can't be more than one, or none. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | */ |
| 943 | if (((uflags & (XFS_GROUP_QUOTA | XFS_USER_QUOTA)) == |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 944 | (XFS_GROUP_QUOTA | XFS_USER_QUOTA)) || |
| 945 | ((uflags & (XFS_GROUP_QUOTA | XFS_PROJ_QUOTA)) == |
| 946 | (XFS_GROUP_QUOTA | XFS_PROJ_QUOTA)) || |
| 947 | ((uflags & (XFS_USER_QUOTA | XFS_PROJ_QUOTA)) == |
| 948 | (XFS_USER_QUOTA | XFS_PROJ_QUOTA)) || |
| 949 | ((uflags & (XFS_GROUP_QUOTA|XFS_USER_QUOTA|XFS_PROJ_QUOTA)) == 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | return (0); |
| 951 | |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 952 | oflags |= (uflags & XFS_USER_QUOTA) ? XFS_DQ_USER : 0; |
| 953 | oflags |= (uflags & XFS_PROJ_QUOTA) ? XFS_DQ_PROJ : 0; |
| 954 | oflags |= (uflags & XFS_GROUP_QUOTA) ? XFS_DQ_GROUP: 0; |
| 955 | return oflags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | STATIC uint |
| 959 | xfs_qm_export_qtype_flags( |
| 960 | uint flags) |
| 961 | { |
| 962 | /* |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 963 | * Can't be more than one, or none. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | */ |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 965 | ASSERT((flags & (XFS_PROJ_QUOTA | XFS_USER_QUOTA)) != |
| 966 | (XFS_PROJ_QUOTA | XFS_USER_QUOTA)); |
| 967 | ASSERT((flags & (XFS_PROJ_QUOTA | XFS_GROUP_QUOTA)) != |
| 968 | (XFS_PROJ_QUOTA | XFS_GROUP_QUOTA)); |
| 969 | ASSERT((flags & (XFS_USER_QUOTA | XFS_GROUP_QUOTA)) != |
| 970 | (XFS_USER_QUOTA | XFS_GROUP_QUOTA)); |
| 971 | ASSERT((flags & (XFS_PROJ_QUOTA|XFS_USER_QUOTA|XFS_GROUP_QUOTA)) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | |
| 973 | return (flags & XFS_DQ_USER) ? |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 974 | XFS_USER_QUOTA : (flags & XFS_DQ_PROJ) ? |
| 975 | XFS_PROJ_QUOTA : XFS_GROUP_QUOTA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | STATIC uint |
| 979 | xfs_qm_import_flags( |
| 980 | uint uflags) |
| 981 | { |
| 982 | uint flags = 0; |
| 983 | |
| 984 | if (uflags & XFS_QUOTA_UDQ_ACCT) |
| 985 | flags |= XFS_UQUOTA_ACCT; |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 986 | if (uflags & XFS_QUOTA_PDQ_ACCT) |
| 987 | flags |= XFS_PQUOTA_ACCT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | if (uflags & XFS_QUOTA_GDQ_ACCT) |
| 989 | flags |= XFS_GQUOTA_ACCT; |
| 990 | if (uflags & XFS_QUOTA_UDQ_ENFD) |
| 991 | flags |= XFS_UQUOTA_ENFD; |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 992 | if (uflags & (XFS_QUOTA_PDQ_ENFD|XFS_QUOTA_GDQ_ENFD)) |
| 993 | flags |= XFS_OQUOTA_ENFD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | return (flags); |
| 995 | } |
| 996 | |
| 997 | |
| 998 | STATIC uint |
| 999 | xfs_qm_export_flags( |
| 1000 | uint flags) |
| 1001 | { |
| 1002 | uint uflags; |
| 1003 | |
| 1004 | uflags = 0; |
| 1005 | if (flags & XFS_UQUOTA_ACCT) |
| 1006 | uflags |= XFS_QUOTA_UDQ_ACCT; |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 1007 | if (flags & XFS_PQUOTA_ACCT) |
| 1008 | uflags |= XFS_QUOTA_PDQ_ACCT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | if (flags & XFS_GQUOTA_ACCT) |
| 1010 | uflags |= XFS_QUOTA_GDQ_ACCT; |
| 1011 | if (flags & XFS_UQUOTA_ENFD) |
| 1012 | uflags |= XFS_QUOTA_UDQ_ENFD; |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 1013 | if (flags & (XFS_OQUOTA_ENFD)) { |
| 1014 | uflags |= (flags & XFS_GQUOTA_ACCT) ? |
| 1015 | XFS_QUOTA_GDQ_ENFD : XFS_QUOTA_PDQ_ENFD; |
| 1016 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | return (uflags); |
| 1018 | } |
| 1019 | |
| 1020 | |
| 1021 | /* |
| 1022 | * Go thru all the inodes in the file system, releasing their dquots. |
| 1023 | * Note that the mount structure gets modified to indicate that quotas are off |
| 1024 | * AFTER this, in the case of quotaoff. This also gets called from |
| 1025 | * xfs_rootumount. |
| 1026 | */ |
| 1027 | void |
| 1028 | xfs_qm_dqrele_all_inodes( |
| 1029 | struct xfs_mount *mp, |
| 1030 | uint flags) |
| 1031 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | xfs_inode_t *ip, *topino; |
| 1033 | uint ireclaims; |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 1034 | bhv_vnode_t *vp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | boolean_t vnode_refd; |
| 1036 | |
| 1037 | ASSERT(mp->m_quotainfo); |
| 1038 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | XFS_MOUNT_ILOCK(mp); |
Christoph Hellwig | cdb6268 | 2005-09-02 16:24:19 +1000 | [diff] [blame] | 1040 | again: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | ip = mp->m_inodes; |
| 1042 | if (ip == NULL) { |
| 1043 | XFS_MOUNT_IUNLOCK(mp); |
| 1044 | return; |
| 1045 | } |
| 1046 | do { |
| 1047 | /* Skip markers inserted by xfs_sync */ |
| 1048 | if (ip->i_mount == NULL) { |
| 1049 | ip = ip->i_mnext; |
| 1050 | continue; |
| 1051 | } |
| 1052 | /* Root inode, rbmip and rsumip have associated blocks */ |
| 1053 | if (ip == XFS_QI_UQIP(mp) || ip == XFS_QI_GQIP(mp)) { |
| 1054 | ASSERT(ip->i_udquot == NULL); |
| 1055 | ASSERT(ip->i_gdquot == NULL); |
| 1056 | ip = ip->i_mnext; |
| 1057 | continue; |
| 1058 | } |
| 1059 | vp = XFS_ITOV_NULL(ip); |
| 1060 | if (!vp) { |
| 1061 | ASSERT(ip->i_udquot == NULL); |
| 1062 | ASSERT(ip->i_gdquot == NULL); |
| 1063 | ip = ip->i_mnext; |
| 1064 | continue; |
| 1065 | } |
| 1066 | vnode_refd = B_FALSE; |
| 1067 | if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | ireclaims = mp->m_ireclaims; |
| 1069 | topino = mp->m_inodes; |
Christoph Hellwig | cdb6268 | 2005-09-02 16:24:19 +1000 | [diff] [blame] | 1070 | vp = vn_grab(vp); |
| 1071 | if (!vp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | goto again; |
Christoph Hellwig | cdb6268 | 2005-09-02 16:24:19 +1000 | [diff] [blame] | 1073 | |
| 1074 | XFS_MOUNT_IUNLOCK(mp); |
| 1075 | /* XXX restart limit ? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | xfs_ilock(ip, XFS_ILOCK_EXCL); |
| 1077 | vnode_refd = B_TRUE; |
| 1078 | } else { |
| 1079 | ireclaims = mp->m_ireclaims; |
| 1080 | topino = mp->m_inodes; |
| 1081 | XFS_MOUNT_IUNLOCK(mp); |
| 1082 | } |
| 1083 | |
| 1084 | /* |
| 1085 | * We don't keep the mountlock across the dqrele() call, |
| 1086 | * since it can take a while.. |
| 1087 | */ |
| 1088 | if ((flags & XFS_UQUOTA_ACCT) && ip->i_udquot) { |
| 1089 | xfs_qm_dqrele(ip->i_udquot); |
| 1090 | ip->i_udquot = NULL; |
| 1091 | } |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 1092 | if (flags & (XFS_PQUOTA_ACCT|XFS_GQUOTA_ACCT) && ip->i_gdquot) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | xfs_qm_dqrele(ip->i_gdquot); |
| 1094 | ip->i_gdquot = NULL; |
| 1095 | } |
| 1096 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
| 1097 | /* |
| 1098 | * Wait until we've dropped the ilock and mountlock to |
| 1099 | * do the vn_rele. Or be condemned to an eternity in the |
| 1100 | * inactive code in hell. |
| 1101 | */ |
| 1102 | if (vnode_refd) |
| 1103 | VN_RELE(vp); |
| 1104 | XFS_MOUNT_ILOCK(mp); |
| 1105 | /* |
| 1106 | * If an inode was inserted or removed, we gotta |
| 1107 | * start over again. |
| 1108 | */ |
| 1109 | if (topino != mp->m_inodes || mp->m_ireclaims != ireclaims) { |
| 1110 | /* XXX use a sentinel */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | goto again; |
| 1112 | } |
| 1113 | ip = ip->i_mnext; |
| 1114 | } while (ip != mp->m_inodes); |
| 1115 | |
| 1116 | XFS_MOUNT_IUNLOCK(mp); |
| 1117 | } |
| 1118 | |
| 1119 | /*------------------------------------------------------------------------*/ |
| 1120 | #ifdef DEBUG |
| 1121 | /* |
| 1122 | * This contains all the test functions for XFS disk quotas. |
| 1123 | * Currently it does a quota accounting check. ie. it walks through |
| 1124 | * all inodes in the file system, calculating the dquot accounting fields, |
| 1125 | * and prints out any inconsistencies. |
| 1126 | */ |
| 1127 | xfs_dqhash_t *qmtest_udqtab; |
| 1128 | xfs_dqhash_t *qmtest_gdqtab; |
| 1129 | int qmtest_hashmask; |
| 1130 | int qmtest_nfails; |
| 1131 | mutex_t qcheck_lock; |
| 1132 | |
| 1133 | #define DQTEST_HASHVAL(mp, id) (((__psunsigned_t)(mp) + \ |
| 1134 | (__psunsigned_t)(id)) & \ |
| 1135 | (qmtest_hashmask - 1)) |
| 1136 | |
| 1137 | #define DQTEST_HASH(mp, id, type) ((type & XFS_DQ_USER) ? \ |
| 1138 | (qmtest_udqtab + \ |
| 1139 | DQTEST_HASHVAL(mp, id)) : \ |
| 1140 | (qmtest_gdqtab + \ |
| 1141 | DQTEST_HASHVAL(mp, id))) |
| 1142 | |
| 1143 | #define DQTEST_LIST_PRINT(l, NXT, title) \ |
| 1144 | { \ |
| 1145 | xfs_dqtest_t *dqp; int i = 0;\ |
| 1146 | cmn_err(CE_DEBUG, "%s (#%d)", title, (int) (l)->qh_nelems); \ |
| 1147 | for (dqp = (xfs_dqtest_t *)(l)->qh_next; dqp != NULL; \ |
| 1148 | dqp = (xfs_dqtest_t *)dqp->NXT) { \ |
| 1149 | cmn_err(CE_DEBUG, " %d. \"%d (%s)\" bcnt = %d, icnt = %d", \ |
| 1150 | ++i, dqp->d_id, DQFLAGTO_TYPESTR(dqp), \ |
| 1151 | dqp->d_bcount, dqp->d_icount); } \ |
| 1152 | } |
| 1153 | |
| 1154 | typedef struct dqtest { |
| 1155 | xfs_dqmarker_t q_lists; |
| 1156 | xfs_dqhash_t *q_hash; /* the hashchain header */ |
| 1157 | xfs_mount_t *q_mount; /* filesystem this relates to */ |
| 1158 | xfs_dqid_t d_id; /* user id or group id */ |
| 1159 | xfs_qcnt_t d_bcount; /* # disk blocks owned by the user */ |
| 1160 | xfs_qcnt_t d_icount; /* # inodes owned by the user */ |
| 1161 | } xfs_dqtest_t; |
| 1162 | |
| 1163 | STATIC void |
| 1164 | xfs_qm_hashinsert(xfs_dqhash_t *h, xfs_dqtest_t *dqp) |
| 1165 | { |
| 1166 | xfs_dquot_t *d; |
| 1167 | if (((d) = (h)->qh_next)) |
| 1168 | (d)->HL_PREVP = &((dqp)->HL_NEXT); |
| 1169 | (dqp)->HL_NEXT = d; |
| 1170 | (dqp)->HL_PREVP = &((h)->qh_next); |
| 1171 | (h)->qh_next = (xfs_dquot_t *)dqp; |
| 1172 | (h)->qh_version++; |
| 1173 | (h)->qh_nelems++; |
| 1174 | } |
| 1175 | STATIC void |
| 1176 | xfs_qm_dqtest_print( |
| 1177 | xfs_dqtest_t *d) |
| 1178 | { |
| 1179 | cmn_err(CE_DEBUG, "-----------DQTEST DQUOT----------------"); |
| 1180 | cmn_err(CE_DEBUG, "---- dquot ID = %d", d->d_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | cmn_err(CE_DEBUG, "---- fs = 0x%p", d->q_mount); |
| 1182 | cmn_err(CE_DEBUG, "---- bcount = %Lu (0x%x)", |
| 1183 | d->d_bcount, (int)d->d_bcount); |
| 1184 | cmn_err(CE_DEBUG, "---- icount = %Lu (0x%x)", |
| 1185 | d->d_icount, (int)d->d_icount); |
| 1186 | cmn_err(CE_DEBUG, "---------------------------"); |
| 1187 | } |
| 1188 | |
| 1189 | STATIC void |
| 1190 | xfs_qm_dqtest_failed( |
| 1191 | xfs_dqtest_t *d, |
| 1192 | xfs_dquot_t *dqp, |
| 1193 | char *reason, |
| 1194 | xfs_qcnt_t a, |
| 1195 | xfs_qcnt_t b, |
| 1196 | int error) |
| 1197 | { |
| 1198 | qmtest_nfails++; |
| 1199 | if (error) |
| 1200 | cmn_err(CE_DEBUG, "quotacheck failed id=%d, err=%d\nreason: %s", |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 1201 | d->d_id, error, reason); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | else |
| 1203 | cmn_err(CE_DEBUG, "quotacheck failed id=%d (%s) [%d != %d]", |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 1204 | d->d_id, reason, (int)a, (int)b); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | xfs_qm_dqtest_print(d); |
| 1206 | if (dqp) |
| 1207 | xfs_qm_dqprint(dqp); |
| 1208 | } |
| 1209 | |
| 1210 | STATIC int |
| 1211 | xfs_dqtest_cmp2( |
| 1212 | xfs_dqtest_t *d, |
| 1213 | xfs_dquot_t *dqp) |
| 1214 | { |
| 1215 | int err = 0; |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 1216 | if (be64_to_cpu(dqp->q_core.d_icount) != d->d_icount) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | xfs_qm_dqtest_failed(d, dqp, "icount mismatch", |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 1218 | be64_to_cpu(dqp->q_core.d_icount), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | d->d_icount, 0); |
| 1220 | err++; |
| 1221 | } |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 1222 | if (be64_to_cpu(dqp->q_core.d_bcount) != d->d_bcount) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | xfs_qm_dqtest_failed(d, dqp, "bcount mismatch", |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 1224 | be64_to_cpu(dqp->q_core.d_bcount), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | d->d_bcount, 0); |
| 1226 | err++; |
| 1227 | } |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 1228 | if (dqp->q_core.d_blk_softlimit && |
| 1229 | be64_to_cpu(dqp->q_core.d_bcount) >= |
| 1230 | be64_to_cpu(dqp->q_core.d_blk_softlimit)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | if (!dqp->q_core.d_btimer && dqp->q_core.d_id) { |
| 1232 | cmn_err(CE_DEBUG, |
| 1233 | "%d [%s] [0x%p] BLK TIMER NOT STARTED", |
| 1234 | d->d_id, DQFLAGTO_TYPESTR(d), d->q_mount); |
| 1235 | err++; |
| 1236 | } |
| 1237 | } |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 1238 | if (dqp->q_core.d_ino_softlimit && |
| 1239 | be64_to_cpu(dqp->q_core.d_icount) >= |
| 1240 | be64_to_cpu(dqp->q_core.d_ino_softlimit)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | if (!dqp->q_core.d_itimer && dqp->q_core.d_id) { |
| 1242 | cmn_err(CE_DEBUG, |
| 1243 | "%d [%s] [0x%p] INO TIMER NOT STARTED", |
| 1244 | d->d_id, DQFLAGTO_TYPESTR(d), d->q_mount); |
| 1245 | err++; |
| 1246 | } |
| 1247 | } |
| 1248 | #ifdef QUOTADEBUG |
| 1249 | if (!err) { |
| 1250 | cmn_err(CE_DEBUG, "%d [%s] [0x%p] qchecked", |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 1251 | d->d_id, DQFLAGTO_TYPESTR(d), d->q_mount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | } |
| 1253 | #endif |
| 1254 | return (err); |
| 1255 | } |
| 1256 | |
| 1257 | STATIC void |
| 1258 | xfs_dqtest_cmp( |
| 1259 | xfs_dqtest_t *d) |
| 1260 | { |
| 1261 | xfs_dquot_t *dqp; |
| 1262 | int error; |
| 1263 | |
| 1264 | /* xfs_qm_dqtest_print(d); */ |
| 1265 | if ((error = xfs_qm_dqget(d->q_mount, NULL, d->d_id, d->dq_flags, 0, |
| 1266 | &dqp))) { |
| 1267 | xfs_qm_dqtest_failed(d, NULL, "dqget failed", 0, 0, error); |
| 1268 | return; |
| 1269 | } |
| 1270 | xfs_dqtest_cmp2(d, dqp); |
| 1271 | xfs_qm_dqput(dqp); |
| 1272 | } |
| 1273 | |
| 1274 | STATIC int |
| 1275 | xfs_qm_internalqcheck_dqget( |
| 1276 | xfs_mount_t *mp, |
| 1277 | xfs_dqid_t id, |
| 1278 | uint type, |
| 1279 | xfs_dqtest_t **O_dq) |
| 1280 | { |
| 1281 | xfs_dqtest_t *d; |
| 1282 | xfs_dqhash_t *h; |
| 1283 | |
| 1284 | h = DQTEST_HASH(mp, id, type); |
| 1285 | for (d = (xfs_dqtest_t *) h->qh_next; d != NULL; |
| 1286 | d = (xfs_dqtest_t *) d->HL_NEXT) { |
| 1287 | /* DQTEST_LIST_PRINT(h, HL_NEXT, "@@@@@ dqtestlist @@@@@"); */ |
| 1288 | if (d->d_id == id && mp == d->q_mount) { |
| 1289 | *O_dq = d; |
| 1290 | return (0); |
| 1291 | } |
| 1292 | } |
| 1293 | d = kmem_zalloc(sizeof(xfs_dqtest_t), KM_SLEEP); |
| 1294 | d->dq_flags = type; |
| 1295 | d->d_id = id; |
| 1296 | d->q_mount = mp; |
| 1297 | d->q_hash = h; |
| 1298 | xfs_qm_hashinsert(h, d); |
| 1299 | *O_dq = d; |
| 1300 | return (0); |
| 1301 | } |
| 1302 | |
| 1303 | STATIC void |
| 1304 | xfs_qm_internalqcheck_get_dquots( |
| 1305 | xfs_mount_t *mp, |
| 1306 | xfs_dqid_t uid, |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 1307 | xfs_dqid_t projid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | xfs_dqid_t gid, |
| 1309 | xfs_dqtest_t **ud, |
| 1310 | xfs_dqtest_t **gd) |
| 1311 | { |
| 1312 | if (XFS_IS_UQUOTA_ON(mp)) |
| 1313 | xfs_qm_internalqcheck_dqget(mp, uid, XFS_DQ_USER, ud); |
| 1314 | if (XFS_IS_GQUOTA_ON(mp)) |
| 1315 | xfs_qm_internalqcheck_dqget(mp, gid, XFS_DQ_GROUP, gd); |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 1316 | else if (XFS_IS_PQUOTA_ON(mp)) |
| 1317 | xfs_qm_internalqcheck_dqget(mp, projid, XFS_DQ_PROJ, gd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | } |
| 1319 | |
| 1320 | |
| 1321 | STATIC void |
| 1322 | xfs_qm_internalqcheck_dqadjust( |
| 1323 | xfs_inode_t *ip, |
| 1324 | xfs_dqtest_t *d) |
| 1325 | { |
| 1326 | d->d_icount++; |
| 1327 | d->d_bcount += (xfs_qcnt_t)ip->i_d.di_nblocks; |
| 1328 | } |
| 1329 | |
| 1330 | STATIC int |
| 1331 | xfs_qm_internalqcheck_adjust( |
| 1332 | xfs_mount_t *mp, /* mount point for filesystem */ |
| 1333 | xfs_ino_t ino, /* inode number to get data for */ |
| 1334 | void __user *buffer, /* not used */ |
| 1335 | int ubsize, /* not used */ |
| 1336 | void *private_data, /* not used */ |
| 1337 | xfs_daddr_t bno, /* starting block of inode cluster */ |
| 1338 | int *ubused, /* not used */ |
| 1339 | void *dip, /* not used */ |
| 1340 | int *res) /* bulkstat result code */ |
| 1341 | { |
| 1342 | xfs_inode_t *ip; |
| 1343 | xfs_dqtest_t *ud, *gd; |
| 1344 | uint lock_flags; |
| 1345 | boolean_t ipreleased; |
| 1346 | int error; |
| 1347 | |
| 1348 | ASSERT(XFS_IS_QUOTA_RUNNING(mp)); |
| 1349 | |
| 1350 | if (ino == mp->m_sb.sb_uquotino || ino == mp->m_sb.sb_gquotino) { |
| 1351 | *res = BULKSTAT_RV_NOTHING; |
| 1352 | qdprintk("internalqcheck: ino=%llu, uqino=%llu, gqino=%llu\n", |
| 1353 | (unsigned long long) ino, |
| 1354 | (unsigned long long) mp->m_sb.sb_uquotino, |
| 1355 | (unsigned long long) mp->m_sb.sb_gquotino); |
| 1356 | return XFS_ERROR(EINVAL); |
| 1357 | } |
| 1358 | ipreleased = B_FALSE; |
| 1359 | again: |
| 1360 | lock_flags = XFS_ILOCK_SHARED; |
| 1361 | if ((error = xfs_iget(mp, NULL, ino, 0, lock_flags, &ip, bno))) { |
| 1362 | *res = BULKSTAT_RV_NOTHING; |
| 1363 | return (error); |
| 1364 | } |
| 1365 | |
| 1366 | if (ip->i_d.di_mode == 0) { |
| 1367 | xfs_iput_new(ip, lock_flags); |
| 1368 | *res = BULKSTAT_RV_NOTHING; |
| 1369 | return XFS_ERROR(ENOENT); |
| 1370 | } |
| 1371 | |
| 1372 | /* |
| 1373 | * This inode can have blocks after eof which can get released |
| 1374 | * when we send it to inactive. Since we don't check the dquot |
| 1375 | * until the after all our calculations are done, we must get rid |
| 1376 | * of those now. |
| 1377 | */ |
| 1378 | if (! ipreleased) { |
| 1379 | xfs_iput(ip, lock_flags); |
| 1380 | ipreleased = B_TRUE; |
| 1381 | goto again; |
| 1382 | } |
| 1383 | xfs_qm_internalqcheck_get_dquots(mp, |
| 1384 | (xfs_dqid_t) ip->i_d.di_uid, |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 1385 | (xfs_dqid_t) ip->i_d.di_projid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | (xfs_dqid_t) ip->i_d.di_gid, |
| 1387 | &ud, &gd); |
| 1388 | if (XFS_IS_UQUOTA_ON(mp)) { |
| 1389 | ASSERT(ud); |
| 1390 | xfs_qm_internalqcheck_dqadjust(ip, ud); |
| 1391 | } |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 1392 | if (XFS_IS_OQUOTA_ON(mp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | ASSERT(gd); |
| 1394 | xfs_qm_internalqcheck_dqadjust(ip, gd); |
| 1395 | } |
| 1396 | xfs_iput(ip, lock_flags); |
| 1397 | *res = BULKSTAT_RV_DIDONE; |
| 1398 | return (0); |
| 1399 | } |
| 1400 | |
| 1401 | |
| 1402 | /* PRIVATE, debugging */ |
| 1403 | int |
| 1404 | xfs_qm_internalqcheck( |
| 1405 | xfs_mount_t *mp) |
| 1406 | { |
| 1407 | xfs_ino_t lastino; |
| 1408 | int done, count; |
| 1409 | int i; |
| 1410 | xfs_dqtest_t *d, *e; |
| 1411 | xfs_dqhash_t *h1; |
| 1412 | int error; |
| 1413 | |
| 1414 | lastino = 0; |
| 1415 | qmtest_hashmask = 32; |
| 1416 | count = 5; |
| 1417 | done = 0; |
| 1418 | qmtest_nfails = 0; |
| 1419 | |
| 1420 | if (! XFS_IS_QUOTA_ON(mp)) |
| 1421 | return XFS_ERROR(ESRCH); |
| 1422 | |
| 1423 | xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE | XFS_LOG_SYNC); |
| 1424 | XFS_bflush(mp->m_ddev_targp); |
| 1425 | xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE | XFS_LOG_SYNC); |
| 1426 | XFS_bflush(mp->m_ddev_targp); |
| 1427 | |
Jes Sorensen | 794ee1b | 2006-01-09 15:59:21 -0800 | [diff] [blame] | 1428 | mutex_lock(&qcheck_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | /* There should be absolutely no quota activity while this |
| 1430 | is going on. */ |
| 1431 | qmtest_udqtab = kmem_zalloc(qmtest_hashmask * |
| 1432 | sizeof(xfs_dqhash_t), KM_SLEEP); |
| 1433 | qmtest_gdqtab = kmem_zalloc(qmtest_hashmask * |
| 1434 | sizeof(xfs_dqhash_t), KM_SLEEP); |
| 1435 | do { |
| 1436 | /* |
| 1437 | * Iterate thru all the inodes in the file system, |
| 1438 | * adjusting the corresponding dquot counters |
| 1439 | */ |
| 1440 | if ((error = xfs_bulkstat(mp, &lastino, &count, |
| 1441 | xfs_qm_internalqcheck_adjust, NULL, |
| 1442 | 0, NULL, BULKSTAT_FG_IGET, &done))) { |
| 1443 | break; |
| 1444 | } |
| 1445 | } while (! done); |
| 1446 | if (error) { |
| 1447 | cmn_err(CE_DEBUG, "Bulkstat returned error 0x%x", error); |
| 1448 | } |
| 1449 | cmn_err(CE_DEBUG, "Checking results against system dquots"); |
| 1450 | for (i = 0; i < qmtest_hashmask; i++) { |
| 1451 | h1 = &qmtest_udqtab[i]; |
| 1452 | for (d = (xfs_dqtest_t *) h1->qh_next; d != NULL; ) { |
| 1453 | xfs_dqtest_cmp(d); |
| 1454 | e = (xfs_dqtest_t *) d->HL_NEXT; |
| 1455 | kmem_free(d, sizeof(xfs_dqtest_t)); |
| 1456 | d = e; |
| 1457 | } |
| 1458 | h1 = &qmtest_gdqtab[i]; |
| 1459 | for (d = (xfs_dqtest_t *) h1->qh_next; d != NULL; ) { |
| 1460 | xfs_dqtest_cmp(d); |
| 1461 | e = (xfs_dqtest_t *) d->HL_NEXT; |
| 1462 | kmem_free(d, sizeof(xfs_dqtest_t)); |
| 1463 | d = e; |
| 1464 | } |
| 1465 | } |
| 1466 | |
| 1467 | if (qmtest_nfails) { |
| 1468 | cmn_err(CE_DEBUG, "******** quotacheck failed ********"); |
| 1469 | cmn_err(CE_DEBUG, "failures = %d", qmtest_nfails); |
| 1470 | } else { |
| 1471 | cmn_err(CE_DEBUG, "******** quotacheck successful! ********"); |
| 1472 | } |
| 1473 | kmem_free(qmtest_udqtab, qmtest_hashmask * sizeof(xfs_dqhash_t)); |
| 1474 | kmem_free(qmtest_gdqtab, qmtest_hashmask * sizeof(xfs_dqhash_t)); |
| 1475 | mutex_unlock(&qcheck_lock); |
| 1476 | return (qmtest_nfails); |
| 1477 | } |
| 1478 | |
| 1479 | #endif /* DEBUG */ |