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 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include "xfs.h" |
| 19 | #include "xfs_fs.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 20 | #include "xfs_bit.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include "xfs_log.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 22 | #include "xfs_inum.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include "xfs_trans.h" |
| 24 | #include "xfs_sb.h" |
| 25 | #include "xfs_ag.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include "xfs_alloc.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include "xfs_quota.h" |
| 28 | #include "xfs_mount.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include "xfs_bmap_btree.h" |
| 30 | #include "xfs_ialloc_btree.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include "xfs_dinode.h" |
| 32 | #include "xfs_inode.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 33 | #include "xfs_ialloc.h" |
| 34 | #include "xfs_itable.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include "xfs_rtalloc.h" |
| 36 | #include "xfs_error.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 37 | #include "xfs_bmap.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_trans_space.h" |
| 41 | #include "xfs_utils.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include "xfs_qm.h" |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 43 | #include "xfs_trace.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
| 45 | /* |
| 46 | * The global quota manager. There is only one of these for the entire |
| 47 | * system, _not_ one per file system. XQM keeps track of the overall |
| 48 | * quota functionality, including maintaining the freelist and hash |
| 49 | * tables of dquots. |
| 50 | */ |
Christoph Hellwig | a0b0b8a | 2009-03-29 09:51:00 +0200 | [diff] [blame] | 51 | struct mutex xfs_Gqm_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | struct xfs_qm *xfs_Gqm; |
| 53 | |
| 54 | kmem_zone_t *qm_dqzone; |
| 55 | kmem_zone_t *qm_dqtrxzone; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | STATIC void xfs_qm_list_init(xfs_dqlist_t *, char *, int); |
| 58 | STATIC void xfs_qm_list_destroy(xfs_dqlist_t *); |
| 59 | |
| 60 | STATIC int xfs_qm_init_quotainos(xfs_mount_t *); |
Christoph Hellwig | ba0f32d | 2005-06-21 15:36:52 +1000 | [diff] [blame] | 61 | STATIC int xfs_qm_init_quotainfo(xfs_mount_t *); |
Ying Han | 1495f23 | 2011-05-24 17:12:27 -0700 | [diff] [blame] | 62 | STATIC int xfs_qm_shake(struct shrinker *, struct shrink_control *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | /* |
| 65 | * Initialize the XQM structure. |
| 66 | * Note that there is not one quota manager per file system. |
| 67 | */ |
| 68 | STATIC struct xfs_qm * |
| 69 | xfs_Gqm_init(void) |
| 70 | { |
Nathan Scott | 6b3f6b5 | 2005-11-02 15:08:25 +1100 | [diff] [blame] | 71 | xfs_dqhash_t *udqhash, *gdqhash; |
| 72 | xfs_qm_t *xqm; |
Nathan Scott | 215101c | 2006-09-28 11:04:43 +1000 | [diff] [blame] | 73 | size_t hsize; |
| 74 | uint i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | /* |
| 77 | * Initialize the dquot hash tables. |
| 78 | */ |
Nathan Scott | 77e4635 | 2006-09-28 11:03:27 +1000 | [diff] [blame] | 79 | udqhash = kmem_zalloc_greedy(&hsize, |
Eric Sandeen | 5995cb7 | 2007-08-16 16:49:11 +1000 | [diff] [blame] | 80 | XFS_QM_HASHSIZE_LOW * sizeof(xfs_dqhash_t), |
Christoph Hellwig | bdfb043 | 2010-01-20 21:55:30 +0000 | [diff] [blame] | 81 | XFS_QM_HASHSIZE_HIGH * sizeof(xfs_dqhash_t)); |
| 82 | if (!udqhash) |
| 83 | goto out; |
| 84 | |
| 85 | gdqhash = kmem_zalloc_large(hsize); |
Julia Lawall | d67b1b0 | 2010-02-06 08:45:15 +0000 | [diff] [blame] | 86 | if (!gdqhash) |
Christoph Hellwig | bdfb043 | 2010-01-20 21:55:30 +0000 | [diff] [blame] | 87 | goto out_free_udqhash; |
| 88 | |
Nathan Scott | 77e4635 | 2006-09-28 11:03:27 +1000 | [diff] [blame] | 89 | hsize /= sizeof(xfs_dqhash_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
Nathan Scott | 6b3f6b5 | 2005-11-02 15:08:25 +1100 | [diff] [blame] | 91 | xqm = kmem_zalloc(sizeof(xfs_qm_t), KM_SLEEP); |
| 92 | xqm->qm_dqhashmask = hsize - 1; |
| 93 | xqm->qm_usr_dqhtable = udqhash; |
| 94 | xqm->qm_grp_dqhtable = gdqhash; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | ASSERT(xqm->qm_usr_dqhtable != NULL); |
| 96 | ASSERT(xqm->qm_grp_dqhtable != NULL); |
| 97 | |
| 98 | for (i = 0; i < hsize; i++) { |
| 99 | xfs_qm_list_init(&(xqm->qm_usr_dqhtable[i]), "uxdqh", i); |
| 100 | xfs_qm_list_init(&(xqm->qm_grp_dqhtable[i]), "gxdqh", i); |
| 101 | } |
| 102 | |
| 103 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | * dquot zone. we register our own low-memory callback. |
| 105 | */ |
| 106 | if (!qm_dqzone) { |
| 107 | xqm->qm_dqzone = kmem_zone_init(sizeof(xfs_dquot_t), |
| 108 | "xfs_dquots"); |
| 109 | qm_dqzone = xqm->qm_dqzone; |
| 110 | } else |
| 111 | xqm->qm_dqzone = qm_dqzone; |
| 112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | /* |
| 114 | * The t_dqinfo portion of transactions. |
| 115 | */ |
| 116 | if (!qm_dqtrxzone) { |
| 117 | xqm->qm_dqtrxzone = kmem_zone_init(sizeof(xfs_dquot_acct_t), |
| 118 | "xfs_dqtrx"); |
| 119 | qm_dqtrxzone = xqm->qm_dqtrxzone; |
| 120 | } else |
| 121 | xqm->qm_dqtrxzone = qm_dqtrxzone; |
| 122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | xqm->qm_nrefs = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | return xqm; |
Christoph Hellwig | bdfb043 | 2010-01-20 21:55:30 +0000 | [diff] [blame] | 125 | |
| 126 | out_free_udqhash: |
| 127 | kmem_free_large(udqhash); |
| 128 | out: |
| 129 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | /* |
| 133 | * Destroy the global quota manager when its reference count goes to zero. |
| 134 | */ |
Christoph Hellwig | ba0f32d | 2005-06-21 15:36:52 +1000 | [diff] [blame] | 135 | STATIC void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | xfs_qm_destroy( |
| 137 | struct xfs_qm *xqm) |
| 138 | { |
| 139 | int hsize, i; |
| 140 | |
| 141 | ASSERT(xqm != NULL); |
| 142 | ASSERT(xqm->qm_nrefs == 0); |
Christoph Hellwig | 80a376b | 2011-12-06 21:58:16 +0000 | [diff] [blame] | 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | hsize = xqm->qm_dqhashmask + 1; |
| 145 | for (i = 0; i < hsize; i++) { |
| 146 | xfs_qm_list_destroy(&(xqm->qm_usr_dqhtable[i])); |
| 147 | xfs_qm_list_destroy(&(xqm->qm_grp_dqhtable[i])); |
| 148 | } |
Christoph Hellwig | bdfb043 | 2010-01-20 21:55:30 +0000 | [diff] [blame] | 149 | kmem_free_large(xqm->qm_usr_dqhtable); |
| 150 | kmem_free_large(xqm->qm_grp_dqhtable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | xqm->qm_usr_dqhtable = NULL; |
| 152 | xqm->qm_grp_dqhtable = NULL; |
| 153 | xqm->qm_dqhashmask = 0; |
Dave Chinner | 3a8406f | 2010-04-13 15:06:52 +1000 | [diff] [blame] | 154 | |
Denys Vlasenko | f0e2d93 | 2008-05-19 16:31:57 +1000 | [diff] [blame] | 155 | kmem_free(xqm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | /* |
| 159 | * Called at mount time to let XQM know that another file system is |
| 160 | * starting quotas. This isn't crucial information as the individual mount |
| 161 | * structures are pretty independent, but it helps the XQM keep a |
| 162 | * global view of what's going on. |
| 163 | */ |
| 164 | /* ARGSUSED */ |
| 165 | STATIC int |
| 166 | xfs_qm_hold_quotafs_ref( |
| 167 | struct xfs_mount *mp) |
| 168 | { |
| 169 | /* |
| 170 | * Need to lock the xfs_Gqm structure for things like this. For example, |
| 171 | * the structure could disappear between the entry to this routine and |
| 172 | * a HOLD operation if not locked. |
| 173 | */ |
Christoph Hellwig | e249458 | 2009-02-09 08:38:39 +0100 | [diff] [blame] | 174 | mutex_lock(&xfs_Gqm_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Christoph Hellwig | bdfb043 | 2010-01-20 21:55:30 +0000 | [diff] [blame] | 176 | if (!xfs_Gqm) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | xfs_Gqm = xfs_Gqm_init(); |
Julia Lawall | 38e712a | 2010-05-26 15:57:23 +0000 | [diff] [blame] | 178 | if (!xfs_Gqm) { |
| 179 | mutex_unlock(&xfs_Gqm_lock); |
Christoph Hellwig | bdfb043 | 2010-01-20 21:55:30 +0000 | [diff] [blame] | 180 | return ENOMEM; |
Julia Lawall | 38e712a | 2010-05-26 15:57:23 +0000 | [diff] [blame] | 181 | } |
Christoph Hellwig | bdfb043 | 2010-01-20 21:55:30 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | /* |
| 185 | * We can keep a list of all filesystems with quotas mounted for |
| 186 | * debugging and statistical purposes, but ... |
| 187 | * Just take a reference and get out. |
| 188 | */ |
Christoph Hellwig | e249458 | 2009-02-09 08:38:39 +0100 | [diff] [blame] | 189 | xfs_Gqm->qm_nrefs++; |
| 190 | mutex_unlock(&xfs_Gqm_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
| 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | |
| 196 | /* |
| 197 | * Release the reference that a filesystem took at mount time, |
| 198 | * so that we know when we need to destroy the entire quota manager. |
| 199 | */ |
| 200 | /* ARGSUSED */ |
| 201 | STATIC void |
| 202 | xfs_qm_rele_quotafs_ref( |
| 203 | struct xfs_mount *mp) |
| 204 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | ASSERT(xfs_Gqm); |
| 206 | ASSERT(xfs_Gqm->qm_nrefs > 0); |
| 207 | |
| 208 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | * Destroy the entire XQM. If somebody mounts with quotaon, this'll |
| 210 | * be restarted. |
| 211 | */ |
Christoph Hellwig | e249458 | 2009-02-09 08:38:39 +0100 | [diff] [blame] | 212 | mutex_lock(&xfs_Gqm_lock); |
| 213 | if (--xfs_Gqm->qm_nrefs == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | xfs_qm_destroy(xfs_Gqm); |
| 215 | xfs_Gqm = NULL; |
| 216 | } |
Christoph Hellwig | e249458 | 2009-02-09 08:38:39 +0100 | [diff] [blame] | 217 | mutex_unlock(&xfs_Gqm_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | * Just destroy the quotainfo structure. |
| 222 | */ |
| 223 | void |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 224 | xfs_qm_unmount( |
| 225 | struct xfs_mount *mp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | { |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 227 | if (mp->m_quotainfo) { |
Christoph Hellwig | 8112e9d | 2010-04-20 17:02:29 +1000 | [diff] [blame] | 228 | xfs_qm_dqpurge_all(mp, XFS_QMOPT_QUOTALL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | xfs_qm_destroy_quotainfo(mp); |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 230 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | |
| 234 | /* |
| 235 | * This is called from xfs_mountfs to start quotas and initialize all |
| 236 | * necessary data structures like quotainfo. This is also responsible for |
| 237 | * running a quotacheck as necessary. We are guaranteed that the superblock |
| 238 | * is consistently read in at this point. |
David Chinner | 53aa791 | 2008-04-10 12:20:31 +1000 | [diff] [blame] | 239 | * |
| 240 | * If we fail here, the mount will continue with quota turned off. We don't |
| 241 | * need to inidicate success or failure at all. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | */ |
David Chinner | 53aa791 | 2008-04-10 12:20:31 +1000 | [diff] [blame] | 243 | void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | xfs_qm_mount_quotas( |
Christoph Hellwig | 4249023 | 2008-08-13 16:49:32 +1000 | [diff] [blame] | 245 | xfs_mount_t *mp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | int error = 0; |
| 248 | uint sbf; |
| 249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | /* |
| 251 | * If quotas on realtime volumes is not supported, we disable |
| 252 | * quotas immediately. |
| 253 | */ |
| 254 | if (mp->m_sb.sb_rextents) { |
Dave Chinner | 0b932cc | 2011-03-07 10:08:35 +1100 | [diff] [blame] | 255 | xfs_notice(mp, "Cannot turn on quotas for realtime filesystem"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | mp->m_qflags = 0; |
| 257 | goto write_changes; |
| 258 | } |
| 259 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | ASSERT(XFS_IS_QUOTA_RUNNING(mp)); |
Nathan Scott | 155ffd0 | 2005-09-02 16:43:48 +1000 | [diff] [blame] | 261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | /* |
| 263 | * Allocate the quotainfo structure inside the mount struct, and |
| 264 | * create quotainode(s), and change/rev superblock if necessary. |
| 265 | */ |
David Chinner | 53aa791 | 2008-04-10 12:20:31 +1000 | [diff] [blame] | 266 | error = xfs_qm_init_quotainfo(mp); |
| 267 | if (error) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | /* |
| 269 | * We must turn off quotas. |
| 270 | */ |
| 271 | ASSERT(mp->m_quotainfo == NULL); |
| 272 | mp->m_qflags = 0; |
| 273 | goto write_changes; |
| 274 | } |
| 275 | /* |
| 276 | * If any of the quotas are not consistent, do a quotacheck. |
| 277 | */ |
Christoph Hellwig | 4249023 | 2008-08-13 16:49:32 +1000 | [diff] [blame] | 278 | if (XFS_QM_NEED_QUOTACHECK(mp)) { |
David Chinner | 53aa791 | 2008-04-10 12:20:31 +1000 | [diff] [blame] | 279 | error = xfs_qm_quotacheck(mp); |
| 280 | if (error) { |
| 281 | /* Quotacheck failed and disabled quotas. */ |
| 282 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | } |
Donald Douwsma | 646d5bd | 2007-05-08 13:49:09 +1000 | [diff] [blame] | 285 | /* |
| 286 | * If one type of quotas is off, then it will lose its |
| 287 | * quotachecked status, since we won't be doing accounting for |
| 288 | * that type anymore. |
| 289 | */ |
David Chinner | 53aa791 | 2008-04-10 12:20:31 +1000 | [diff] [blame] | 290 | if (!XFS_IS_UQUOTA_ON(mp)) |
Donald Douwsma | 646d5bd | 2007-05-08 13:49:09 +1000 | [diff] [blame] | 291 | mp->m_qflags &= ~XFS_UQUOTA_CHKD; |
David Chinner | 53aa791 | 2008-04-10 12:20:31 +1000 | [diff] [blame] | 292 | if (!(XFS_IS_GQUOTA_ON(mp) || XFS_IS_PQUOTA_ON(mp))) |
Donald Douwsma | 646d5bd | 2007-05-08 13:49:09 +1000 | [diff] [blame] | 293 | mp->m_qflags &= ~XFS_OQUOTA_CHKD; |
Nathan Scott | 155ffd0 | 2005-09-02 16:43:48 +1000 | [diff] [blame] | 294 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | write_changes: |
| 296 | /* |
Eric Sandeen | 3685c2a | 2007-10-11 17:42:32 +1000 | [diff] [blame] | 297 | * We actually don't have to acquire the m_sb_lock at all. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | * This can only be called from mount, and that's single threaded. XXX |
| 299 | */ |
Eric Sandeen | 3685c2a | 2007-10-11 17:42:32 +1000 | [diff] [blame] | 300 | spin_lock(&mp->m_sb_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | sbf = mp->m_sb.sb_qflags; |
| 302 | mp->m_sb.sb_qflags = mp->m_qflags & XFS_MOUNT_QUOTA_ALL; |
Eric Sandeen | 3685c2a | 2007-10-11 17:42:32 +1000 | [diff] [blame] | 303 | spin_unlock(&mp->m_sb_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | |
| 305 | if (sbf != (mp->m_qflags & XFS_MOUNT_QUOTA_ALL)) { |
| 306 | if (xfs_qm_write_sb_changes(mp, XFS_SB_QFLAGS)) { |
| 307 | /* |
| 308 | * We could only have been turning quotas off. |
| 309 | * We aren't in very good shape actually because |
| 310 | * the incore structures are convinced that quotas are |
| 311 | * off, but the on disk superblock doesn't know that ! |
| 312 | */ |
| 313 | ASSERT(!(XFS_IS_QUOTA_RUNNING(mp))); |
Dave Chinner | 5348778 | 2011-03-07 10:05:35 +1100 | [diff] [blame] | 314 | xfs_alert(mp, "%s: Superblock update failed!", |
| 315 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | |
| 319 | if (error) { |
Dave Chinner | 5348778 | 2011-03-07 10:05:35 +1100 | [diff] [blame] | 320 | xfs_warn(mp, "Failed to initialize disk quotas."); |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 321 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | /* |
| 326 | * Called from the vfsops layer. |
| 327 | */ |
Christoph Hellwig | e57481d | 2008-12-03 12:20:36 +0100 | [diff] [blame] | 328 | void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | xfs_qm_unmount_quotas( |
| 330 | xfs_mount_t *mp) |
| 331 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | /* |
| 333 | * Release the dquots that root inode, et al might be holding, |
| 334 | * before we flush quotas and blow away the quotainfo structure. |
| 335 | */ |
| 336 | ASSERT(mp->m_rootip); |
| 337 | xfs_qm_dqdetach(mp->m_rootip); |
| 338 | if (mp->m_rbmip) |
| 339 | xfs_qm_dqdetach(mp->m_rbmip); |
| 340 | if (mp->m_rsumip) |
| 341 | xfs_qm_dqdetach(mp->m_rsumip); |
| 342 | |
| 343 | /* |
Christoph Hellwig | e57481d | 2008-12-03 12:20:36 +0100 | [diff] [blame] | 344 | * Release the quota inodes. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | if (mp->m_quotainfo) { |
Christoph Hellwig | e57481d | 2008-12-03 12:20:36 +0100 | [diff] [blame] | 347 | if (mp->m_quotainfo->qi_uquotaip) { |
| 348 | IRELE(mp->m_quotainfo->qi_uquotaip); |
| 349 | mp->m_quotainfo->qi_uquotaip = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | } |
Christoph Hellwig | e57481d | 2008-12-03 12:20:36 +0100 | [diff] [blame] | 351 | if (mp->m_quotainfo->qi_gquotaip) { |
| 352 | IRELE(mp->m_quotainfo->qi_gquotaip); |
| 353 | mp->m_quotainfo->qi_gquotaip = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | } |
| 355 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | /* |
| 359 | * Flush all dquots of the given file system to disk. The dquots are |
| 360 | * _not_ purged from memory here, just their data written to disk. |
| 361 | */ |
Christoph Hellwig | ba0f32d | 2005-06-21 15:36:52 +1000 | [diff] [blame] | 362 | STATIC int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | xfs_qm_dqflush_all( |
Christoph Hellwig | a7ef9bd | 2011-12-06 21:58:13 +0000 | [diff] [blame] | 364 | struct xfs_mount *mp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | { |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 366 | struct xfs_quotainfo *q = mp->m_quotainfo; |
| 367 | int recl; |
| 368 | struct xfs_dquot *dqp; |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 369 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 371 | if (!q) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 372 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | again: |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 374 | mutex_lock(&q->qi_dqlist_lock); |
| 375 | list_for_each_entry(dqp, &q->qi_dqlist, q_mplist) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | xfs_dqlock(dqp); |
Christoph Hellwig | 9267855 | 2011-12-06 21:58:18 +0000 | [diff] [blame] | 377 | if ((dqp->dq_flags & XFS_DQ_FREEING) || |
| 378 | !XFS_DQ_IS_DIRTY(dqp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | xfs_dqunlock(dqp); |
| 380 | continue; |
| 381 | } |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | /* XXX a sentinel would be better */ |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 384 | recl = q->qi_dqreclaims; |
David Chinner | e1f49cf | 2008-08-13 16:41:43 +1000 | [diff] [blame] | 385 | if (!xfs_dqflock_nowait(dqp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | /* |
| 387 | * If we can't grab the flush lock then check |
| 388 | * to see if the dquot has been flushed delayed |
| 389 | * write. If so, grab its buffer and send it |
| 390 | * out immediately. We'll be able to acquire |
| 391 | * the flush lock when the I/O completes. |
| 392 | */ |
Christoph Hellwig | 800b484 | 2011-12-06 21:58:14 +0000 | [diff] [blame] | 393 | xfs_dqflock_pushbuf_wait(dqp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | } |
| 395 | /* |
| 396 | * Let go of the mplist lock. We don't want to hold it |
| 397 | * across a disk write. |
| 398 | */ |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 399 | mutex_unlock(&q->qi_dqlist_lock); |
Christoph Hellwig | a7ef9bd | 2011-12-06 21:58:13 +0000 | [diff] [blame] | 400 | error = xfs_qm_dqflush(dqp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | xfs_dqunlock(dqp); |
| 402 | if (error) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 403 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 405 | mutex_lock(&q->qi_dqlist_lock); |
| 406 | if (recl != q->qi_dqreclaims) { |
| 407 | mutex_unlock(&q->qi_dqlist_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | /* XXX restart limit */ |
| 409 | goto again; |
| 410 | } |
| 411 | } |
| 412 | |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 413 | mutex_unlock(&q->qi_dqlist_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | /* return ! busy */ |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 415 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | } |
Christoph Hellwig | 9267855 | 2011-12-06 21:58:18 +0000 | [diff] [blame] | 417 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | /* |
| 419 | * Release the group dquot pointers the user dquots may be |
| 420 | * carrying around as a hint. mplist is locked on entry and exit. |
| 421 | */ |
| 422 | STATIC void |
| 423 | xfs_qm_detach_gdquots( |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 424 | struct xfs_mount *mp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | { |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 426 | struct xfs_quotainfo *q = mp->m_quotainfo; |
| 427 | struct xfs_dquot *dqp, *gdqp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | |
| 429 | again: |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 430 | ASSERT(mutex_is_locked(&q->qi_dqlist_lock)); |
| 431 | list_for_each_entry(dqp, &q->qi_dqlist, q_mplist) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | xfs_dqlock(dqp); |
Christoph Hellwig | 9267855 | 2011-12-06 21:58:18 +0000 | [diff] [blame] | 433 | if (dqp->dq_flags & XFS_DQ_FREEING) { |
| 434 | xfs_dqunlock(dqp); |
| 435 | mutex_unlock(&q->qi_dqlist_lock); |
| 436 | delay(1); |
| 437 | mutex_lock(&q->qi_dqlist_lock); |
| 438 | goto again; |
| 439 | } |
Christoph Hellwig | 28fb588 | 2011-12-06 21:58:21 +0000 | [diff] [blame] | 440 | |
| 441 | gdqp = dqp->q_gdquot; |
| 442 | if (gdqp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | dqp->q_gdquot = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | xfs_dqunlock(dqp); |
| 445 | |
Christoph Hellwig | 28fb588 | 2011-12-06 21:58:21 +0000 | [diff] [blame] | 446 | if (gdqp) |
| 447 | xfs_qm_dqrele(gdqp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | } |
| 449 | } |
| 450 | |
| 451 | /* |
| 452 | * Go through all the incore dquots of this file system and take them |
| 453 | * off the mplist and hashlist, if the dquot type matches the dqtype |
| 454 | * parameter. This is used when turning off quota accounting for |
| 455 | * users and/or groups, as well as when the filesystem is unmounting. |
| 456 | */ |
| 457 | STATIC int |
| 458 | xfs_qm_dqpurge_int( |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 459 | struct xfs_mount *mp, |
| 460 | uint flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | { |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 462 | struct xfs_quotainfo *q = mp->m_quotainfo; |
| 463 | struct xfs_dquot *dqp, *n; |
| 464 | uint dqtype; |
Christoph Hellwig | 9267855 | 2011-12-06 21:58:18 +0000 | [diff] [blame] | 465 | int nmisses = 0; |
| 466 | LIST_HEAD (dispose_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 468 | if (!q) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 469 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | |
| 471 | dqtype = (flags & XFS_QMOPT_UQUOTA) ? XFS_DQ_USER : 0; |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 472 | dqtype |= (flags & XFS_QMOPT_PQUOTA) ? XFS_DQ_PROJ : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | dqtype |= (flags & XFS_QMOPT_GQUOTA) ? XFS_DQ_GROUP : 0; |
| 474 | |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 475 | mutex_lock(&q->qi_dqlist_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | |
| 477 | /* |
| 478 | * In the first pass through all incore dquots of this filesystem, |
| 479 | * we release the group dquot pointers the user dquots may be |
| 480 | * carrying around as a hint. We need to do this irrespective of |
| 481 | * what's being turned off. |
| 482 | */ |
| 483 | xfs_qm_detach_gdquots(mp); |
| 484 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | /* |
Christoph Hellwig | 9267855 | 2011-12-06 21:58:18 +0000 | [diff] [blame] | 486 | * Try to get rid of all of the unwanted dquots. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | */ |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 488 | list_for_each_entry_safe(dqp, n, &q->qi_dqlist, q_mplist) { |
Christoph Hellwig | be7ffc3 | 2011-12-06 21:58:17 +0000 | [diff] [blame] | 489 | xfs_dqlock(dqp); |
Christoph Hellwig | 9267855 | 2011-12-06 21:58:18 +0000 | [diff] [blame] | 490 | if ((dqp->dq_flags & dqtype) != 0 && |
| 491 | !(dqp->dq_flags & XFS_DQ_FREEING)) { |
| 492 | if (dqp->q_nrefs == 0) { |
| 493 | dqp->dq_flags |= XFS_DQ_FREEING; |
| 494 | list_move_tail(&dqp->q_mplist, &dispose_list); |
| 495 | } else |
| 496 | nmisses++; |
Christoph Hellwig | be7ffc3 | 2011-12-06 21:58:17 +0000 | [diff] [blame] | 497 | } |
| 498 | xfs_dqunlock(dqp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | } |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 500 | mutex_unlock(&q->qi_dqlist_lock); |
Christoph Hellwig | 9267855 | 2011-12-06 21:58:18 +0000 | [diff] [blame] | 501 | |
| 502 | list_for_each_entry_safe(dqp, n, &dispose_list, q_mplist) |
| 503 | xfs_qm_dqpurge(dqp); |
| 504 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | return nmisses; |
| 506 | } |
| 507 | |
| 508 | int |
| 509 | xfs_qm_dqpurge_all( |
| 510 | xfs_mount_t *mp, |
| 511 | uint flags) |
| 512 | { |
| 513 | int ndquots; |
| 514 | |
| 515 | /* |
| 516 | * Purge the dquot cache. |
| 517 | * None of the dquots should really be busy at this point. |
| 518 | */ |
| 519 | if (mp->m_quotainfo) { |
| 520 | while ((ndquots = xfs_qm_dqpurge_int(mp, flags))) { |
| 521 | delay(ndquots * 10); |
| 522 | } |
| 523 | } |
| 524 | return 0; |
| 525 | } |
| 526 | |
| 527 | STATIC int |
| 528 | xfs_qm_dqattach_one( |
| 529 | xfs_inode_t *ip, |
| 530 | xfs_dqid_t id, |
| 531 | uint type, |
| 532 | uint doalloc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | xfs_dquot_t *udqhint, /* hint */ |
| 534 | xfs_dquot_t **IO_idqpp) |
| 535 | { |
| 536 | xfs_dquot_t *dqp; |
| 537 | int error; |
| 538 | |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 539 | ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | error = 0; |
Christoph Hellwig | 8e9b6e7 | 2009-02-08 21:51:42 +0100 | [diff] [blame] | 541 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | /* |
| 543 | * See if we already have it in the inode itself. IO_idqpp is |
| 544 | * &i_udquot or &i_gdquot. This made the code look weird, but |
| 545 | * made the logic a lot simpler. |
| 546 | */ |
Christoph Hellwig | 8e9b6e7 | 2009-02-08 21:51:42 +0100 | [diff] [blame] | 547 | dqp = *IO_idqpp; |
| 548 | if (dqp) { |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 549 | trace_xfs_dqattach_found(dqp); |
Christoph Hellwig | 8e9b6e7 | 2009-02-08 21:51:42 +0100 | [diff] [blame] | 550 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | /* |
| 554 | * udqhint is the i_udquot field in inode, and is non-NULL only |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 555 | * when the type arg is group/project. Its purpose is to save a |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | * lookup by dqid (xfs_qm_dqget) by caching a group dquot inside |
| 557 | * the user dquot. |
| 558 | */ |
Christoph Hellwig | 8e9b6e7 | 2009-02-08 21:51:42 +0100 | [diff] [blame] | 559 | if (udqhint) { |
| 560 | ASSERT(type == XFS_DQ_GROUP || type == XFS_DQ_PROJ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | xfs_dqlock(udqhint); |
| 562 | |
Christoph Hellwig | 8e9b6e7 | 2009-02-08 21:51:42 +0100 | [diff] [blame] | 563 | /* |
| 564 | * No need to take dqlock to look at the id. |
| 565 | * |
| 566 | * The ID can't change until it gets reclaimed, and it won't |
| 567 | * be reclaimed as long as we have a ref from inode and we |
| 568 | * hold the ilock. |
| 569 | */ |
| 570 | dqp = udqhint->q_gdquot; |
| 571 | if (dqp && be32_to_cpu(dqp->q_core.d_id) == id) { |
Christoph Hellwig | 8e9b6e7 | 2009-02-08 21:51:42 +0100 | [diff] [blame] | 572 | ASSERT(*IO_idqpp == NULL); |
Christoph Hellwig | 8e9b6e7 | 2009-02-08 21:51:42 +0100 | [diff] [blame] | 573 | |
Christoph Hellwig | 78e5589 | 2011-12-06 21:58:22 +0000 | [diff] [blame] | 574 | *IO_idqpp = xfs_qm_dqhold(dqp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | xfs_dqunlock(udqhint); |
Christoph Hellwig | 8e9b6e7 | 2009-02-08 21:51:42 +0100 | [diff] [blame] | 576 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | } |
Christoph Hellwig | 8e9b6e7 | 2009-02-08 21:51:42 +0100 | [diff] [blame] | 578 | |
| 579 | /* |
| 580 | * We can't hold a dquot lock when we call the dqget code. |
| 581 | * We'll deadlock in no time, because of (not conforming to) |
| 582 | * lock ordering - the inodelock comes before any dquot lock, |
| 583 | * and we may drop and reacquire the ilock in xfs_qm_dqget(). |
| 584 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | xfs_dqunlock(udqhint); |
Christoph Hellwig | 8e9b6e7 | 2009-02-08 21:51:42 +0100 | [diff] [blame] | 586 | } |
| 587 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | /* |
| 589 | * Find the dquot from somewhere. This bumps the |
| 590 | * reference count of dquot and returns it locked. |
| 591 | * This can return ENOENT if dquot didn't exist on |
| 592 | * disk and we didn't ask it to allocate; |
| 593 | * ESRCH if quotas got turned off suddenly. |
| 594 | */ |
Mitsuo Hayasaka | db3e74b | 2011-11-10 01:33:10 +0000 | [diff] [blame] | 595 | error = xfs_qm_dqget(ip->i_mount, ip, id, type, |
| 596 | doalloc | XFS_QMOPT_DOWARN, &dqp); |
Christoph Hellwig | 8e9b6e7 | 2009-02-08 21:51:42 +0100 | [diff] [blame] | 597 | if (error) |
| 598 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 600 | trace_xfs_dqattach_get(dqp); |
Christoph Hellwig | 8e9b6e7 | 2009-02-08 21:51:42 +0100 | [diff] [blame] | 601 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | /* |
| 603 | * dqget may have dropped and re-acquired the ilock, but it guarantees |
| 604 | * that the dquot returned is the one that should go in the inode. |
| 605 | */ |
| 606 | *IO_idqpp = dqp; |
Christoph Hellwig | 8e9b6e7 | 2009-02-08 21:51:42 +0100 | [diff] [blame] | 607 | xfs_dqunlock(dqp); |
| 608 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | |
| 612 | /* |
| 613 | * Given a udquot and gdquot, attach a ptr to the group dquot in the |
Christoph Hellwig | ab680bb | 2011-12-06 21:58:20 +0000 | [diff] [blame] | 614 | * udquot as a hint for future lookups. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | */ |
| 616 | STATIC void |
| 617 | xfs_qm_dqattach_grouphint( |
| 618 | xfs_dquot_t *udq, |
Christoph Hellwig | 8e9b6e7 | 2009-02-08 21:51:42 +0100 | [diff] [blame] | 619 | xfs_dquot_t *gdq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | { |
| 621 | xfs_dquot_t *tmp; |
| 622 | |
Christoph Hellwig | 8e9b6e7 | 2009-02-08 21:51:42 +0100 | [diff] [blame] | 623 | xfs_dqlock(udq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | |
Christoph Hellwig | ab680bb | 2011-12-06 21:58:20 +0000 | [diff] [blame] | 625 | tmp = udq->q_gdquot; |
| 626 | if (tmp) { |
| 627 | if (tmp == gdq) |
| 628 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | |
| 630 | udq->q_gdquot = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | xfs_qm_dqrele(tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | } |
| 633 | |
Christoph Hellwig | 78e5589 | 2011-12-06 21:58:22 +0000 | [diff] [blame] | 634 | udq->q_gdquot = xfs_qm_dqhold(gdq); |
Christoph Hellwig | ab680bb | 2011-12-06 21:58:20 +0000 | [diff] [blame] | 635 | done: |
Christoph Hellwig | 8e9b6e7 | 2009-02-08 21:51:42 +0100 | [diff] [blame] | 636 | xfs_dqunlock(udq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | |
| 640 | /* |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 641 | * Given a locked inode, attach dquot(s) to it, taking U/G/P-QUOTAON |
| 642 | * into account. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | * If XFS_QMOPT_DQALLOC, the dquot(s) will be allocated if needed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | * Inode may get unlocked and relocked in here, and the caller must deal with |
| 645 | * the consequences. |
| 646 | */ |
| 647 | int |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 648 | xfs_qm_dqattach_locked( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | xfs_inode_t *ip, |
| 650 | uint flags) |
| 651 | { |
| 652 | xfs_mount_t *mp = ip->i_mount; |
| 653 | uint nquotas = 0; |
| 654 | int error = 0; |
| 655 | |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 656 | if (!XFS_IS_QUOTA_RUNNING(mp) || |
| 657 | !XFS_IS_QUOTA_ON(mp) || |
| 658 | !XFS_NOT_DQATTACHED(mp, ip) || |
| 659 | ip->i_ino == mp->m_sb.sb_uquotino || |
| 660 | ip->i_ino == mp->m_sb.sb_gquotino) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 661 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 663 | ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | |
| 665 | if (XFS_IS_UQUOTA_ON(mp)) { |
| 666 | error = xfs_qm_dqattach_one(ip, ip->i_d.di_uid, XFS_DQ_USER, |
| 667 | flags & XFS_QMOPT_DQALLOC, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | NULL, &ip->i_udquot); |
| 669 | if (error) |
| 670 | goto done; |
| 671 | nquotas++; |
| 672 | } |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 673 | |
| 674 | ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 675 | if (XFS_IS_OQUOTA_ON(mp)) { |
| 676 | error = XFS_IS_GQUOTA_ON(mp) ? |
| 677 | xfs_qm_dqattach_one(ip, ip->i_d.di_gid, XFS_DQ_GROUP, |
| 678 | flags & XFS_QMOPT_DQALLOC, |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 679 | ip->i_udquot, &ip->i_gdquot) : |
Arkadiusz Mi?kiewicz | 6743099 | 2010-09-26 06:10:18 +0000 | [diff] [blame] | 680 | xfs_qm_dqattach_one(ip, xfs_get_projid(ip), XFS_DQ_PROJ, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | flags & XFS_QMOPT_DQALLOC, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | ip->i_udquot, &ip->i_gdquot); |
| 683 | /* |
| 684 | * Don't worry about the udquot that we may have |
| 685 | * attached above. It'll get detached, if not already. |
| 686 | */ |
| 687 | if (error) |
| 688 | goto done; |
| 689 | nquotas++; |
| 690 | } |
| 691 | |
| 692 | /* |
| 693 | * Attach this group quota to the user quota as a hint. |
| 694 | * This WON'T, in general, result in a thrash. |
| 695 | */ |
| 696 | if (nquotas == 2) { |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 697 | ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | ASSERT(ip->i_udquot); |
| 699 | ASSERT(ip->i_gdquot); |
| 700 | |
| 701 | /* |
Christoph Hellwig | ab680bb | 2011-12-06 21:58:20 +0000 | [diff] [blame] | 702 | * We do not have i_udquot locked at this point, but this check |
| 703 | * is OK since we don't depend on the i_gdquot to be accurate |
| 704 | * 100% all the time. It is just a hint, and this will |
| 705 | * succeed in general. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | */ |
Christoph Hellwig | ab680bb | 2011-12-06 21:58:20 +0000 | [diff] [blame] | 707 | if (ip->i_udquot->q_gdquot != ip->i_gdquot) |
| 708 | xfs_qm_dqattach_grouphint(ip->i_udquot, ip->i_gdquot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | } |
| 710 | |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 711 | done: |
Christoph Hellwig | ea15ab3 | 2011-07-13 13:43:50 +0200 | [diff] [blame] | 712 | #ifdef DEBUG |
| 713 | if (!error) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | if (XFS_IS_UQUOTA_ON(mp)) |
| 715 | ASSERT(ip->i_udquot); |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 716 | if (XFS_IS_OQUOTA_ON(mp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | ASSERT(ip->i_gdquot); |
| 718 | } |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 719 | ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | #endif |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 721 | return error; |
| 722 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 724 | int |
| 725 | xfs_qm_dqattach( |
| 726 | struct xfs_inode *ip, |
| 727 | uint flags) |
| 728 | { |
| 729 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 731 | xfs_ilock(ip, XFS_ILOCK_EXCL); |
| 732 | error = xfs_qm_dqattach_locked(ip, flags); |
| 733 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
| 734 | |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 735 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | /* |
| 739 | * Release dquots (and their references) if any. |
| 740 | * The inode should be locked EXCL except when this's called by |
| 741 | * xfs_ireclaim. |
| 742 | */ |
| 743 | void |
| 744 | xfs_qm_dqdetach( |
| 745 | xfs_inode_t *ip) |
| 746 | { |
| 747 | if (!(ip->i_udquot || ip->i_gdquot)) |
| 748 | return; |
| 749 | |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 750 | trace_xfs_dquot_dqdetach(ip); |
| 751 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | ASSERT(ip->i_ino != ip->i_mount->m_sb.sb_uquotino); |
| 753 | ASSERT(ip->i_ino != ip->i_mount->m_sb.sb_gquotino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | if (ip->i_udquot) { |
| 755 | xfs_qm_dqrele(ip->i_udquot); |
| 756 | ip->i_udquot = NULL; |
| 757 | } |
| 758 | if (ip->i_gdquot) { |
| 759 | xfs_qm_dqrele(ip->i_gdquot); |
| 760 | ip->i_gdquot = NULL; |
| 761 | } |
| 762 | } |
| 763 | |
Christoph Hellwig | a4edd1d | 2009-01-19 02:03:11 +0100 | [diff] [blame] | 764 | /* |
| 765 | * The hash chains and the mplist use the same xfs_dqhash structure as |
| 766 | * their list head, but we can take the mplist qh_lock and one of the |
| 767 | * hash qh_locks at the same time without any problem as they aren't |
| 768 | * related. |
| 769 | */ |
| 770 | static struct lock_class_key xfs_quota_mplist_class; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | |
| 772 | /* |
| 773 | * This initializes all the quota information that's kept in the |
| 774 | * mount structure |
| 775 | */ |
Christoph Hellwig | ba0f32d | 2005-06-21 15:36:52 +1000 | [diff] [blame] | 776 | STATIC int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | xfs_qm_init_quotainfo( |
| 778 | xfs_mount_t *mp) |
| 779 | { |
| 780 | xfs_quotainfo_t *qinf; |
| 781 | int error; |
| 782 | xfs_dquot_t *dqp; |
| 783 | |
| 784 | ASSERT(XFS_IS_QUOTA_RUNNING(mp)); |
| 785 | |
| 786 | /* |
| 787 | * Tell XQM that we exist as soon as possible. |
| 788 | */ |
| 789 | if ((error = xfs_qm_hold_quotafs_ref(mp))) { |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 790 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | qinf = mp->m_quotainfo = kmem_zalloc(sizeof(xfs_quotainfo_t), KM_SLEEP); |
| 794 | |
| 795 | /* |
| 796 | * See if quotainodes are setup, and if not, allocate them, |
| 797 | * and change the superblock accordingly. |
| 798 | */ |
| 799 | if ((error = xfs_qm_init_quotainos(mp))) { |
Denys Vlasenko | f0e2d93 | 2008-05-19 16:31:57 +1000 | [diff] [blame] | 800 | kmem_free(qinf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | mp->m_quotainfo = NULL; |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 802 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | } |
| 804 | |
Dave Chinner | 3a25404 | 2010-04-13 15:06:48 +1000 | [diff] [blame] | 805 | INIT_LIST_HEAD(&qinf->qi_dqlist); |
| 806 | mutex_init(&qinf->qi_dqlist_lock); |
| 807 | lockdep_set_class(&qinf->qi_dqlist_lock, &xfs_quota_mplist_class); |
Christoph Hellwig | a4edd1d | 2009-01-19 02:03:11 +0100 | [diff] [blame] | 808 | |
Christoph Hellwig | f8739c3 | 2012-03-13 08:52:34 +0000 | [diff] [blame^] | 809 | INIT_LIST_HEAD(&qinf->qi_lru_list); |
| 810 | qinf->qi_lru_count = 0; |
| 811 | mutex_init(&qinf->qi_lru_lock); |
| 812 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | qinf->qi_dqreclaims = 0; |
| 814 | |
| 815 | /* mutex used to serialize quotaoffs */ |
Jes Sorensen | 794ee1b | 2006-01-09 15:59:21 -0800 | [diff] [blame] | 816 | mutex_init(&qinf->qi_quotaofflock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | |
| 818 | /* Precalc some constants */ |
| 819 | qinf->qi_dqchunklen = XFS_FSB_TO_BB(mp, XFS_DQUOT_CLUSTER_SIZE_FSB); |
| 820 | ASSERT(qinf->qi_dqchunklen); |
| 821 | qinf->qi_dqperchunk = BBTOB(qinf->qi_dqchunklen); |
| 822 | do_div(qinf->qi_dqperchunk, sizeof(xfs_dqblk_t)); |
| 823 | |
| 824 | mp->m_qflags |= (mp->m_sb.sb_qflags & XFS_ALL_QUOTA_CHKD); |
| 825 | |
| 826 | /* |
| 827 | * We try to get the limits from the superuser's limits fields. |
| 828 | * This is quite hacky, but it is standard quota practice. |
Christoph Hellwig | 7ae4440 | 2011-12-06 21:58:25 +0000 | [diff] [blame] | 829 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | * We look at the USR dquot with id == 0 first, but if user quotas |
| 831 | * are not enabled we goto the GRP dquot with id == 0. |
| 832 | * We don't really care to keep separate default limits for user |
| 833 | * and group quotas, at least not at this point. |
Christoph Hellwig | 7ae4440 | 2011-12-06 21:58:25 +0000 | [diff] [blame] | 834 | * |
| 835 | * Since we may not have done a quotacheck by this point, just read |
| 836 | * the dquot without attaching it to any hashtables or lists. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | */ |
Christoph Hellwig | 7ae4440 | 2011-12-06 21:58:25 +0000 | [diff] [blame] | 838 | error = xfs_qm_dqread(mp, 0, |
| 839 | XFS_IS_UQUOTA_RUNNING(mp) ? XFS_DQ_USER : |
| 840 | (XFS_IS_GQUOTA_RUNNING(mp) ? XFS_DQ_GROUP : |
| 841 | XFS_DQ_PROJ), |
| 842 | XFS_QMOPT_DOWARN, &dqp); |
| 843 | if (!error) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | xfs_disk_dquot_t *ddqp = &dqp->q_core; |
| 845 | |
| 846 | /* |
| 847 | * The warnings and timers set the grace period given to |
| 848 | * a user or group before he or she can not perform any |
| 849 | * more writing. If it is zero, a default is used. |
| 850 | */ |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 851 | qinf->qi_btimelimit = ddqp->d_btimer ? |
| 852 | be32_to_cpu(ddqp->d_btimer) : XFS_QM_BTIMELIMIT; |
| 853 | qinf->qi_itimelimit = ddqp->d_itimer ? |
| 854 | be32_to_cpu(ddqp->d_itimer) : XFS_QM_ITIMELIMIT; |
| 855 | qinf->qi_rtbtimelimit = ddqp->d_rtbtimer ? |
| 856 | be32_to_cpu(ddqp->d_rtbtimer) : XFS_QM_RTBTIMELIMIT; |
| 857 | qinf->qi_bwarnlimit = ddqp->d_bwarns ? |
| 858 | be16_to_cpu(ddqp->d_bwarns) : XFS_QM_BWARNLIMIT; |
| 859 | qinf->qi_iwarnlimit = ddqp->d_iwarns ? |
| 860 | be16_to_cpu(ddqp->d_iwarns) : XFS_QM_IWARNLIMIT; |
| 861 | qinf->qi_rtbwarnlimit = ddqp->d_rtbwarns ? |
| 862 | be16_to_cpu(ddqp->d_rtbwarns) : XFS_QM_RTBWARNLIMIT; |
| 863 | qinf->qi_bhardlimit = be64_to_cpu(ddqp->d_blk_hardlimit); |
| 864 | qinf->qi_bsoftlimit = be64_to_cpu(ddqp->d_blk_softlimit); |
| 865 | qinf->qi_ihardlimit = be64_to_cpu(ddqp->d_ino_hardlimit); |
| 866 | qinf->qi_isoftlimit = be64_to_cpu(ddqp->d_ino_softlimit); |
| 867 | qinf->qi_rtbhardlimit = be64_to_cpu(ddqp->d_rtb_hardlimit); |
| 868 | qinf->qi_rtbsoftlimit = be64_to_cpu(ddqp->d_rtb_softlimit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | xfs_qm_dqdestroy(dqp); |
| 871 | } else { |
| 872 | qinf->qi_btimelimit = XFS_QM_BTIMELIMIT; |
| 873 | qinf->qi_itimelimit = XFS_QM_ITIMELIMIT; |
| 874 | qinf->qi_rtbtimelimit = XFS_QM_RTBTIMELIMIT; |
| 875 | qinf->qi_bwarnlimit = XFS_QM_BWARNLIMIT; |
| 876 | qinf->qi_iwarnlimit = XFS_QM_IWARNLIMIT; |
Nathan Scott | 06d10dd | 2005-06-21 15:48:47 +1000 | [diff] [blame] | 877 | qinf->qi_rtbwarnlimit = XFS_QM_RTBWARNLIMIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | } |
| 879 | |
Christoph Hellwig | f8739c3 | 2012-03-13 08:52:34 +0000 | [diff] [blame^] | 880 | qinf->qi_shrinker.shrink = xfs_qm_shake; |
| 881 | qinf->qi_shrinker.seeks = DEFAULT_SEEKS; |
| 882 | register_shrinker(&qinf->qi_shrinker); |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 883 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | |
| 887 | /* |
| 888 | * Gets called when unmounting a filesystem or when all quotas get |
| 889 | * turned off. |
| 890 | * This purges the quota inodes, destroys locks and frees itself. |
| 891 | */ |
| 892 | void |
| 893 | xfs_qm_destroy_quotainfo( |
| 894 | xfs_mount_t *mp) |
| 895 | { |
| 896 | xfs_quotainfo_t *qi; |
| 897 | |
| 898 | qi = mp->m_quotainfo; |
| 899 | ASSERT(qi != NULL); |
| 900 | ASSERT(xfs_Gqm != NULL); |
| 901 | |
Christoph Hellwig | f8739c3 | 2012-03-13 08:52:34 +0000 | [diff] [blame^] | 902 | unregister_shrinker(&qi->qi_shrinker); |
| 903 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | /* |
| 905 | * Release the reference that XQM kept, so that we know |
| 906 | * when the XQM structure should be freed. We cannot assume |
| 907 | * that xfs_Gqm is non-null after this point. |
| 908 | */ |
| 909 | xfs_qm_rele_quotafs_ref(mp); |
| 910 | |
Dave Chinner | 3a25404 | 2010-04-13 15:06:48 +1000 | [diff] [blame] | 911 | ASSERT(list_empty(&qi->qi_dqlist)); |
| 912 | mutex_destroy(&qi->qi_dqlist_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | |
| 914 | if (qi->qi_uquotaip) { |
Christoph Hellwig | 26cc002 | 2008-07-18 17:12:43 +1000 | [diff] [blame] | 915 | IRELE(qi->qi_uquotaip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | qi->qi_uquotaip = NULL; /* paranoia */ |
| 917 | } |
| 918 | if (qi->qi_gquotaip) { |
Christoph Hellwig | 26cc002 | 2008-07-18 17:12:43 +1000 | [diff] [blame] | 919 | IRELE(qi->qi_gquotaip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | qi->qi_gquotaip = NULL; |
| 921 | } |
| 922 | mutex_destroy(&qi->qi_quotaofflock); |
Denys Vlasenko | f0e2d93 | 2008-05-19 16:31:57 +1000 | [diff] [blame] | 923 | kmem_free(qi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | mp->m_quotainfo = NULL; |
| 925 | } |
| 926 | |
| 927 | |
| 928 | |
| 929 | /* ------------------- PRIVATE STATIC FUNCTIONS ----------------------- */ |
| 930 | |
| 931 | /* ARGSUSED */ |
| 932 | STATIC void |
| 933 | xfs_qm_list_init( |
| 934 | xfs_dqlist_t *list, |
| 935 | char *str, |
| 936 | int n) |
| 937 | { |
Jes Sorensen | 794ee1b | 2006-01-09 15:59:21 -0800 | [diff] [blame] | 938 | mutex_init(&list->qh_lock); |
Dave Chinner | e6a81f1 | 2010-04-13 15:06:51 +1000 | [diff] [blame] | 939 | INIT_LIST_HEAD(&list->qh_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | list->qh_version = 0; |
| 941 | list->qh_nelems = 0; |
| 942 | } |
| 943 | |
| 944 | STATIC void |
| 945 | xfs_qm_list_destroy( |
| 946 | xfs_dqlist_t *list) |
| 947 | { |
| 948 | mutex_destroy(&(list->qh_lock)); |
| 949 | } |
| 950 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | /* |
| 952 | * Create an inode and return with a reference already taken, but unlocked |
| 953 | * This is how we create quota inodes |
| 954 | */ |
| 955 | STATIC int |
| 956 | xfs_qm_qino_alloc( |
| 957 | xfs_mount_t *mp, |
| 958 | xfs_inode_t **ip, |
| 959 | __int64_t sbfields, |
| 960 | uint flags) |
| 961 | { |
| 962 | xfs_trans_t *tp; |
| 963 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | int committed; |
| 965 | |
Nathan Scott | 061f720 | 2006-01-11 15:27:50 +1100 | [diff] [blame] | 966 | tp = xfs_trans_alloc(mp, XFS_TRANS_QM_QINOCREATE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | if ((error = xfs_trans_reserve(tp, |
| 968 | XFS_QM_QINOCREATE_SPACE_RES(mp), |
| 969 | XFS_CREATE_LOG_RES(mp), 0, |
| 970 | XFS_TRANS_PERM_LOG_RES, |
| 971 | XFS_CREATE_LOG_COUNT))) { |
| 972 | xfs_trans_cancel(tp, 0); |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 973 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | |
Christoph Hellwig | 6c77b0e | 2010-10-06 18:41:17 +0000 | [diff] [blame] | 976 | error = xfs_dir_ialloc(&tp, NULL, S_IFREG, 1, 0, 0, 1, ip, &committed); |
| 977 | if (error) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES | |
| 979 | XFS_TRANS_ABORT); |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 980 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | * Make the changes in the superblock, and log those too. |
| 985 | * sbfields arg may contain fields other than *QUOTINO; |
| 986 | * VERSIONNUM for example. |
| 987 | */ |
Eric Sandeen | 3685c2a | 2007-10-11 17:42:32 +1000 | [diff] [blame] | 988 | spin_lock(&mp->m_sb_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | if (flags & XFS_QMOPT_SBVERSION) { |
Eric Sandeen | 6211870 | 2008-03-06 13:44:28 +1100 | [diff] [blame] | 990 | ASSERT(!xfs_sb_version_hasquota(&mp->m_sb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | ASSERT((sbfields & (XFS_SB_VERSIONNUM | XFS_SB_UQUOTINO | |
| 992 | XFS_SB_GQUOTINO | XFS_SB_QFLAGS)) == |
| 993 | (XFS_SB_VERSIONNUM | XFS_SB_UQUOTINO | |
| 994 | XFS_SB_GQUOTINO | XFS_SB_QFLAGS)); |
| 995 | |
Eric Sandeen | 6211870 | 2008-03-06 13:44:28 +1100 | [diff] [blame] | 996 | xfs_sb_version_addquota(&mp->m_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | mp->m_sb.sb_uquotino = NULLFSINO; |
| 998 | mp->m_sb.sb_gquotino = NULLFSINO; |
| 999 | |
| 1000 | /* qflags will get updated _after_ quotacheck */ |
| 1001 | mp->m_sb.sb_qflags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | } |
| 1003 | if (flags & XFS_QMOPT_UQUOTA) |
| 1004 | mp->m_sb.sb_uquotino = (*ip)->i_ino; |
| 1005 | else |
| 1006 | mp->m_sb.sb_gquotino = (*ip)->i_ino; |
Eric Sandeen | 3685c2a | 2007-10-11 17:42:32 +1000 | [diff] [blame] | 1007 | spin_unlock(&mp->m_sb_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | xfs_mod_sb(tp, sbfields); |
| 1009 | |
Eric Sandeen | 1c72bf9 | 2007-05-08 13:48:42 +1000 | [diff] [blame] | 1010 | if ((error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES))) { |
Dave Chinner | 5348778 | 2011-03-07 10:05:35 +1100 | [diff] [blame] | 1011 | xfs_alert(mp, "%s failed (error %d)!", __func__, error); |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1012 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | } |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1014 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | |
David Chinner | 5b13973 | 2008-04-10 12:20:10 +1000 | [diff] [blame] | 1018 | STATIC void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | xfs_qm_reset_dqcounts( |
| 1020 | xfs_mount_t *mp, |
| 1021 | xfs_buf_t *bp, |
| 1022 | xfs_dqid_t id, |
| 1023 | uint type) |
| 1024 | { |
| 1025 | xfs_disk_dquot_t *ddq; |
| 1026 | int j; |
| 1027 | |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 1028 | trace_xfs_reset_dqcounts(bp, _RET_IP_); |
| 1029 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | /* |
| 1031 | * Reset all counters and timers. They'll be |
| 1032 | * started afresh by xfs_qm_quotacheck. |
| 1033 | */ |
| 1034 | #ifdef DEBUG |
| 1035 | j = XFS_FSB_TO_B(mp, XFS_DQUOT_CLUSTER_SIZE_FSB); |
| 1036 | do_div(j, sizeof(xfs_dqblk_t)); |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 1037 | ASSERT(mp->m_quotainfo->qi_dqperchunk == j); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | #endif |
Chandra Seetharaman | 6292604 | 2011-07-22 23:40:15 +0000 | [diff] [blame] | 1039 | ddq = bp->b_addr; |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 1040 | for (j = 0; j < mp->m_quotainfo->qi_dqperchunk; j++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | /* |
| 1042 | * Do a sanity check, and if needed, repair the dqblk. Don't |
| 1043 | * output any warnings because it's perfectly possible to |
Nathan Scott | c41564b | 2006-03-29 08:55:14 +1000 | [diff] [blame] | 1044 | * find uninitialised dquot blks. See comment in xfs_qm_dqcheck. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | */ |
Dave Chinner | a0fa2b6 | 2011-03-07 10:01:35 +1100 | [diff] [blame] | 1046 | (void) xfs_qm_dqcheck(mp, ddq, id+j, type, XFS_QMOPT_DQREPAIR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | "xfs_quotacheck"); |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 1048 | ddq->d_bcount = 0; |
| 1049 | ddq->d_icount = 0; |
| 1050 | ddq->d_rtbcount = 0; |
| 1051 | ddq->d_btimer = 0; |
| 1052 | ddq->d_itimer = 0; |
| 1053 | ddq->d_rtbtimer = 0; |
| 1054 | ddq->d_bwarns = 0; |
| 1055 | ddq->d_iwarns = 0; |
| 1056 | ddq->d_rtbwarns = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | ddq = (xfs_disk_dquot_t *) ((xfs_dqblk_t *)ddq + 1); |
| 1058 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | STATIC int |
| 1062 | xfs_qm_dqiter_bufs( |
| 1063 | xfs_mount_t *mp, |
| 1064 | xfs_dqid_t firstid, |
| 1065 | xfs_fsblock_t bno, |
| 1066 | xfs_filblks_t blkcnt, |
| 1067 | uint flags) |
| 1068 | { |
| 1069 | xfs_buf_t *bp; |
| 1070 | int error; |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 1071 | int type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | |
| 1073 | ASSERT(blkcnt > 0); |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 1074 | type = flags & XFS_QMOPT_UQUOTA ? XFS_DQ_USER : |
| 1075 | (flags & XFS_QMOPT_PQUOTA ? XFS_DQ_PROJ : XFS_DQ_GROUP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | error = 0; |
| 1077 | |
| 1078 | /* |
| 1079 | * Blkcnt arg can be a very big number, and might even be |
| 1080 | * larger than the log itself. So, we have to break it up into |
| 1081 | * manageable-sized transactions. |
| 1082 | * Note that we don't start a permanent transaction here; we might |
| 1083 | * not be able to get a log reservation for the whole thing up front, |
| 1084 | * and we don't really care to either, because we just discard |
| 1085 | * everything if we were to crash in the middle of this loop. |
| 1086 | */ |
| 1087 | while (blkcnt--) { |
| 1088 | error = xfs_trans_read_buf(mp, NULL, mp->m_ddev_targp, |
| 1089 | XFS_FSB_TO_DADDR(mp, bno), |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 1090 | mp->m_quotainfo->qi_dqchunklen, 0, &bp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | if (error) |
| 1092 | break; |
| 1093 | |
David Chinner | 5b13973 | 2008-04-10 12:20:10 +1000 | [diff] [blame] | 1094 | xfs_qm_reset_dqcounts(mp, bp, firstid, type); |
Christoph Hellwig | 61551f1 | 2011-08-23 08:28:06 +0000 | [diff] [blame] | 1095 | xfs_buf_delwri_queue(bp); |
| 1096 | xfs_buf_relse(bp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | /* |
| 1098 | * goto the next block. |
| 1099 | */ |
| 1100 | bno++; |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 1101 | firstid += mp->m_quotainfo->qi_dqperchunk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | } |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1103 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | /* |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 1107 | * Iterate over all allocated USR/GRP/PRJ dquots in the system, calling a |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | * caller supplied function for every chunk of dquots that we find. |
| 1109 | */ |
| 1110 | STATIC int |
| 1111 | xfs_qm_dqiterate( |
| 1112 | xfs_mount_t *mp, |
| 1113 | xfs_inode_t *qip, |
| 1114 | uint flags) |
| 1115 | { |
| 1116 | xfs_bmbt_irec_t *map; |
| 1117 | int i, nmaps; /* number of map entries */ |
| 1118 | int error; /* return value */ |
| 1119 | xfs_fileoff_t lblkno; |
| 1120 | xfs_filblks_t maxlblkcnt; |
| 1121 | xfs_dqid_t firstid; |
| 1122 | xfs_fsblock_t rablkno; |
| 1123 | xfs_filblks_t rablkcnt; |
| 1124 | |
| 1125 | error = 0; |
| 1126 | /* |
Nathan Scott | c41564b | 2006-03-29 08:55:14 +1000 | [diff] [blame] | 1127 | * This looks racy, but we can't keep an inode lock across a |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | * trans_reserve. But, this gets called during quotacheck, and that |
| 1129 | * happens only at mount time which is single threaded. |
| 1130 | */ |
| 1131 | if (qip->i_d.di_nblocks == 0) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1132 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | |
| 1134 | map = kmem_alloc(XFS_DQITER_MAP_SIZE * sizeof(*map), KM_SLEEP); |
| 1135 | |
| 1136 | lblkno = 0; |
| 1137 | maxlblkcnt = XFS_B_TO_FSB(mp, (xfs_ufsize_t)XFS_MAXIOFFSET(mp)); |
| 1138 | do { |
| 1139 | nmaps = XFS_DQITER_MAP_SIZE; |
| 1140 | /* |
| 1141 | * We aren't changing the inode itself. Just changing |
| 1142 | * some of its data. No new blocks are added here, and |
| 1143 | * the inode is never added to the transaction. |
| 1144 | */ |
| 1145 | xfs_ilock(qip, XFS_ILOCK_SHARED); |
Dave Chinner | 5c8ed20 | 2011-09-18 20:40:45 +0000 | [diff] [blame] | 1146 | error = xfs_bmapi_read(qip, lblkno, maxlblkcnt - lblkno, |
| 1147 | map, &nmaps, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | xfs_iunlock(qip, XFS_ILOCK_SHARED); |
| 1149 | if (error) |
| 1150 | break; |
| 1151 | |
| 1152 | ASSERT(nmaps <= XFS_DQITER_MAP_SIZE); |
| 1153 | for (i = 0; i < nmaps; i++) { |
| 1154 | ASSERT(map[i].br_startblock != DELAYSTARTBLOCK); |
| 1155 | ASSERT(map[i].br_blockcount); |
| 1156 | |
| 1157 | |
| 1158 | lblkno += map[i].br_blockcount; |
| 1159 | |
| 1160 | if (map[i].br_startblock == HOLESTARTBLOCK) |
| 1161 | continue; |
| 1162 | |
| 1163 | firstid = (xfs_dqid_t) map[i].br_startoff * |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 1164 | mp->m_quotainfo->qi_dqperchunk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | /* |
| 1166 | * Do a read-ahead on the next extent. |
| 1167 | */ |
| 1168 | if ((i+1 < nmaps) && |
| 1169 | (map[i+1].br_startblock != HOLESTARTBLOCK)) { |
| 1170 | rablkcnt = map[i+1].br_blockcount; |
| 1171 | rablkno = map[i+1].br_startblock; |
| 1172 | while (rablkcnt--) { |
Christoph Hellwig | 1a1a3e9 | 2010-10-06 18:41:18 +0000 | [diff] [blame] | 1173 | xfs_buf_readahead(mp->m_ddev_targp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | XFS_FSB_TO_DADDR(mp, rablkno), |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 1175 | mp->m_quotainfo->qi_dqchunklen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | rablkno++; |
| 1177 | } |
| 1178 | } |
| 1179 | /* |
| 1180 | * Iterate thru all the blks in the extent and |
| 1181 | * reset the counters of all the dquots inside them. |
| 1182 | */ |
| 1183 | if ((error = xfs_qm_dqiter_bufs(mp, |
| 1184 | firstid, |
| 1185 | map[i].br_startblock, |
| 1186 | map[i].br_blockcount, |
| 1187 | flags))) { |
| 1188 | break; |
| 1189 | } |
| 1190 | } |
| 1191 | |
| 1192 | if (error) |
| 1193 | break; |
| 1194 | } while (nmaps > 0); |
| 1195 | |
Denys Vlasenko | f0e2d93 | 2008-05-19 16:31:57 +1000 | [diff] [blame] | 1196 | kmem_free(map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1198 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | /* |
| 1202 | * Called by dqusage_adjust in doing a quotacheck. |
Christoph Hellwig | 52fda11 | 2010-09-06 01:44:22 +0000 | [diff] [blame] | 1203 | * |
| 1204 | * Given the inode, and a dquot id this updates both the incore dqout as well |
| 1205 | * as the buffer copy. This is so that once the quotacheck is done, we can |
| 1206 | * just log all the buffers, as opposed to logging numerous updates to |
| 1207 | * individual dquots. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | */ |
Christoph Hellwig | 52fda11 | 2010-09-06 01:44:22 +0000 | [diff] [blame] | 1209 | STATIC int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | xfs_qm_quotacheck_dqadjust( |
Christoph Hellwig | 52fda11 | 2010-09-06 01:44:22 +0000 | [diff] [blame] | 1211 | struct xfs_inode *ip, |
| 1212 | xfs_dqid_t id, |
| 1213 | uint type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | xfs_qcnt_t nblks, |
| 1215 | xfs_qcnt_t rtblks) |
| 1216 | { |
Christoph Hellwig | 52fda11 | 2010-09-06 01:44:22 +0000 | [diff] [blame] | 1217 | struct xfs_mount *mp = ip->i_mount; |
| 1218 | struct xfs_dquot *dqp; |
| 1219 | int error; |
| 1220 | |
| 1221 | error = xfs_qm_dqget(mp, ip, id, type, |
| 1222 | XFS_QMOPT_DQALLOC | XFS_QMOPT_DOWARN, &dqp); |
| 1223 | if (error) { |
| 1224 | /* |
| 1225 | * Shouldn't be able to turn off quotas here. |
| 1226 | */ |
| 1227 | ASSERT(error != ESRCH); |
| 1228 | ASSERT(error != ENOENT); |
| 1229 | return error; |
| 1230 | } |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 1231 | |
| 1232 | trace_xfs_dqadjust(dqp); |
| 1233 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | /* |
| 1235 | * Adjust the inode count and the block count to reflect this inode's |
| 1236 | * resource usage. |
| 1237 | */ |
Marcin Slusarz | 413d57c | 2008-02-13 15:03:29 -0800 | [diff] [blame] | 1238 | be64_add_cpu(&dqp->q_core.d_icount, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | dqp->q_res_icount++; |
| 1240 | if (nblks) { |
Marcin Slusarz | 413d57c | 2008-02-13 15:03:29 -0800 | [diff] [blame] | 1241 | be64_add_cpu(&dqp->q_core.d_bcount, nblks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | dqp->q_res_bcount += nblks; |
| 1243 | } |
| 1244 | if (rtblks) { |
Marcin Slusarz | 413d57c | 2008-02-13 15:03:29 -0800 | [diff] [blame] | 1245 | be64_add_cpu(&dqp->q_core.d_rtbcount, rtblks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | dqp->q_res_rtbcount += rtblks; |
| 1247 | } |
| 1248 | |
| 1249 | /* |
| 1250 | * Set default limits, adjust timers (since we changed usages) |
Christoph Hellwig | 191f848 | 2010-04-20 17:01:53 +1000 | [diff] [blame] | 1251 | * |
| 1252 | * There are no timers for the default values set in the root dquot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | */ |
Christoph Hellwig | 191f848 | 2010-04-20 17:01:53 +1000 | [diff] [blame] | 1254 | if (dqp->q_core.d_id) { |
Christoph Hellwig | 52fda11 | 2010-09-06 01:44:22 +0000 | [diff] [blame] | 1255 | xfs_qm_adjust_dqlimits(mp, &dqp->q_core); |
| 1256 | xfs_qm_adjust_dqtimers(mp, &dqp->q_core); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | } |
| 1258 | |
| 1259 | dqp->dq_flags |= XFS_DQ_DIRTY; |
Christoph Hellwig | 52fda11 | 2010-09-06 01:44:22 +0000 | [diff] [blame] | 1260 | xfs_qm_dqput(dqp); |
| 1261 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | STATIC int |
| 1265 | xfs_qm_get_rtblks( |
| 1266 | xfs_inode_t *ip, |
| 1267 | xfs_qcnt_t *O_rtblks) |
| 1268 | { |
| 1269 | xfs_filblks_t rtblks; /* total rt blks */ |
Mandy Kirkconnell | 4eea22f | 2006-03-14 13:29:52 +1100 | [diff] [blame] | 1270 | xfs_extnum_t idx; /* extent record index */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | xfs_ifork_t *ifp; /* inode fork pointer */ |
| 1272 | xfs_extnum_t nextents; /* number of extent entries */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | int error; |
| 1274 | |
| 1275 | ASSERT(XFS_IS_REALTIME_INODE(ip)); |
| 1276 | ifp = XFS_IFORK_PTR(ip, XFS_DATA_FORK); |
| 1277 | if (!(ifp->if_flags & XFS_IFEXTENTS)) { |
| 1278 | if ((error = xfs_iread_extents(NULL, ip, XFS_DATA_FORK))) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1279 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | } |
| 1281 | rtblks = 0; |
Mandy Kirkconnell | 4eea22f | 2006-03-14 13:29:52 +1100 | [diff] [blame] | 1282 | nextents = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t); |
Christoph Hellwig | a6f64d4 | 2007-08-16 16:23:40 +1000 | [diff] [blame] | 1283 | for (idx = 0; idx < nextents; idx++) |
| 1284 | rtblks += xfs_bmbt_get_blockcount(xfs_iext_get_ext(ifp, idx)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | *O_rtblks = (xfs_qcnt_t)rtblks; |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1286 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | /* |
| 1290 | * callback routine supplied to bulkstat(). Given an inumber, find its |
| 1291 | * dquots and update them to account for resources taken by that inode. |
| 1292 | */ |
| 1293 | /* ARGSUSED */ |
| 1294 | STATIC int |
| 1295 | xfs_qm_dqusage_adjust( |
| 1296 | xfs_mount_t *mp, /* mount point for filesystem */ |
| 1297 | xfs_ino_t ino, /* inode number to get data for */ |
| 1298 | void __user *buffer, /* not used */ |
| 1299 | int ubsize, /* not used */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | int *ubused, /* not used */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | int *res) /* result code value */ |
| 1302 | { |
| 1303 | xfs_inode_t *ip; |
Christoph Hellwig | 52fda11 | 2010-09-06 01:44:22 +0000 | [diff] [blame] | 1304 | xfs_qcnt_t nblks, rtblks = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | int error; |
| 1306 | |
| 1307 | ASSERT(XFS_IS_QUOTA_RUNNING(mp)); |
| 1308 | |
| 1309 | /* |
| 1310 | * rootino must have its resources accounted for, not so with the quota |
| 1311 | * inodes. |
| 1312 | */ |
| 1313 | if (ino == mp->m_sb.sb_uquotino || ino == mp->m_sb.sb_gquotino) { |
| 1314 | *res = BULKSTAT_RV_NOTHING; |
| 1315 | return XFS_ERROR(EINVAL); |
| 1316 | } |
| 1317 | |
| 1318 | /* |
| 1319 | * We don't _need_ to take the ilock EXCL. However, the xfs_qm_dqget |
| 1320 | * interface expects the inode to be exclusively locked because that's |
| 1321 | * the case in all other instances. It's OK that we do this because |
| 1322 | * quotacheck is done only at mount time. |
| 1323 | */ |
Christoph Hellwig | 52fda11 | 2010-09-06 01:44:22 +0000 | [diff] [blame] | 1324 | error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_EXCL, &ip); |
| 1325 | if (error) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | *res = BULKSTAT_RV_NOTHING; |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1327 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | } |
| 1329 | |
Christoph Hellwig | 52fda11 | 2010-09-06 01:44:22 +0000 | [diff] [blame] | 1330 | ASSERT(ip->i_delayed_blks == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | |
Christoph Hellwig | 52fda11 | 2010-09-06 01:44:22 +0000 | [diff] [blame] | 1332 | if (XFS_IS_REALTIME_INODE(ip)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | /* |
| 1334 | * Walk thru the extent list and count the realtime blocks. |
| 1335 | */ |
Christoph Hellwig | 52fda11 | 2010-09-06 01:44:22 +0000 | [diff] [blame] | 1336 | error = xfs_qm_get_rtblks(ip, &rtblks); |
| 1337 | if (error) |
| 1338 | goto error0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | |
Christoph Hellwig | 52fda11 | 2010-09-06 01:44:22 +0000 | [diff] [blame] | 1341 | nblks = (xfs_qcnt_t)ip->i_d.di_nblocks - rtblks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | |
| 1343 | /* |
| 1344 | * Add the (disk blocks and inode) resources occupied by this |
| 1345 | * inode to its dquots. We do this adjustment in the incore dquot, |
| 1346 | * and also copy the changes to its buffer. |
| 1347 | * We don't care about putting these changes in a transaction |
| 1348 | * envelope because if we crash in the middle of a 'quotacheck' |
| 1349 | * we have to start from the beginning anyway. |
| 1350 | * Once we're done, we'll log all the dquot bufs. |
| 1351 | * |
Nathan Scott | c41564b | 2006-03-29 08:55:14 +1000 | [diff] [blame] | 1352 | * The *QUOTA_ON checks below may look pretty racy, but quotachecks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | * and quotaoffs don't race. (Quotachecks happen at mount time only). |
| 1354 | */ |
| 1355 | if (XFS_IS_UQUOTA_ON(mp)) { |
Christoph Hellwig | 52fda11 | 2010-09-06 01:44:22 +0000 | [diff] [blame] | 1356 | error = xfs_qm_quotacheck_dqadjust(ip, ip->i_d.di_uid, |
| 1357 | XFS_DQ_USER, nblks, rtblks); |
| 1358 | if (error) |
| 1359 | goto error0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | |
Christoph Hellwig | 52fda11 | 2010-09-06 01:44:22 +0000 | [diff] [blame] | 1362 | if (XFS_IS_GQUOTA_ON(mp)) { |
| 1363 | error = xfs_qm_quotacheck_dqadjust(ip, ip->i_d.di_gid, |
| 1364 | XFS_DQ_GROUP, nblks, rtblks); |
| 1365 | if (error) |
| 1366 | goto error0; |
| 1367 | } |
| 1368 | |
| 1369 | if (XFS_IS_PQUOTA_ON(mp)) { |
Arkadiusz Mi?kiewicz | 6743099 | 2010-09-26 06:10:18 +0000 | [diff] [blame] | 1370 | error = xfs_qm_quotacheck_dqadjust(ip, xfs_get_projid(ip), |
Christoph Hellwig | 52fda11 | 2010-09-06 01:44:22 +0000 | [diff] [blame] | 1371 | XFS_DQ_PROJ, nblks, rtblks); |
| 1372 | if (error) |
| 1373 | goto error0; |
| 1374 | } |
| 1375 | |
| 1376 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
| 1377 | IRELE(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | *res = BULKSTAT_RV_DIDONE; |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1379 | return 0; |
Christoph Hellwig | 52fda11 | 2010-09-06 01:44:22 +0000 | [diff] [blame] | 1380 | |
| 1381 | error0: |
| 1382 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
| 1383 | IRELE(ip); |
| 1384 | *res = BULKSTAT_RV_GIVEUP; |
| 1385 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | /* |
| 1389 | * Walk thru all the filesystem inodes and construct a consistent view |
| 1390 | * of the disk quota world. If the quotacheck fails, disable quotas. |
| 1391 | */ |
| 1392 | int |
| 1393 | xfs_qm_quotacheck( |
| 1394 | xfs_mount_t *mp) |
| 1395 | { |
| 1396 | int done, count, error; |
| 1397 | xfs_ino_t lastino; |
| 1398 | size_t structsz; |
| 1399 | xfs_inode_t *uip, *gip; |
| 1400 | uint flags; |
| 1401 | |
| 1402 | count = INT_MAX; |
| 1403 | structsz = 1; |
| 1404 | lastino = 0; |
| 1405 | flags = 0; |
| 1406 | |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 1407 | ASSERT(mp->m_quotainfo->qi_uquotaip || mp->m_quotainfo->qi_gquotaip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | ASSERT(XFS_IS_QUOTA_RUNNING(mp)); |
| 1409 | |
| 1410 | /* |
| 1411 | * There should be no cached dquots. The (simplistic) quotacheck |
| 1412 | * algorithm doesn't like that. |
| 1413 | */ |
Dave Chinner | 3a25404 | 2010-04-13 15:06:48 +1000 | [diff] [blame] | 1414 | ASSERT(list_empty(&mp->m_quotainfo->qi_dqlist)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | |
Dave Chinner | 0b932cc | 2011-03-07 10:08:35 +1100 | [diff] [blame] | 1416 | xfs_notice(mp, "Quotacheck needed: Please wait."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | |
| 1418 | /* |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 1419 | * First we go thru all the dquots on disk, USR and GRP/PRJ, and reset |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | * their counters to zero. We need a clean slate. |
| 1421 | * We don't log our changes till later. |
| 1422 | */ |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 1423 | uip = mp->m_quotainfo->qi_uquotaip; |
| 1424 | if (uip) { |
| 1425 | error = xfs_qm_dqiterate(mp, uip, XFS_QMOPT_UQUOTA); |
| 1426 | if (error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | goto error_return; |
| 1428 | flags |= XFS_UQUOTA_CHKD; |
| 1429 | } |
| 1430 | |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 1431 | gip = mp->m_quotainfo->qi_gquotaip; |
| 1432 | if (gip) { |
| 1433 | error = xfs_qm_dqiterate(mp, gip, XFS_IS_GQUOTA_ON(mp) ? |
| 1434 | XFS_QMOPT_GQUOTA : XFS_QMOPT_PQUOTA); |
| 1435 | if (error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | goto error_return; |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 1437 | flags |= XFS_OQUOTA_CHKD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | do { |
| 1441 | /* |
| 1442 | * Iterate thru all the inodes in the file system, |
| 1443 | * adjusting the corresponding dquot counters in core. |
| 1444 | */ |
Christoph Hellwig | 7dce11d | 2010-06-23 18:11:11 +1000 | [diff] [blame] | 1445 | error = xfs_bulkstat(mp, &lastino, &count, |
| 1446 | xfs_qm_dqusage_adjust, |
| 1447 | structsz, NULL, &done); |
| 1448 | if (error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1449 | break; |
| 1450 | |
Christoph Hellwig | 7dce11d | 2010-06-23 18:11:11 +1000 | [diff] [blame] | 1451 | } while (!done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | |
| 1453 | /* |
David Chinner | 4b8879d | 2008-04-10 12:20:17 +1000 | [diff] [blame] | 1454 | * We've made all the changes that we need to make incore. |
| 1455 | * Flush them down to disk buffers if everything was updated |
| 1456 | * successfully. |
| 1457 | */ |
| 1458 | if (!error) |
Christoph Hellwig | a7ef9bd | 2011-12-06 21:58:13 +0000 | [diff] [blame] | 1459 | error = xfs_qm_dqflush_all(mp); |
David Chinner | 4b8879d | 2008-04-10 12:20:17 +1000 | [diff] [blame] | 1460 | |
| 1461 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | * We can get this error if we couldn't do a dquot allocation inside |
| 1463 | * xfs_qm_dqusage_adjust (via bulkstat). We don't care about the |
| 1464 | * dirty dquots that might be cached, we just want to get rid of them |
| 1465 | * and turn quotaoff. The dquots won't be attached to any of the inodes |
| 1466 | * at this point (because we intentionally didn't in dqget_noattach). |
| 1467 | */ |
| 1468 | if (error) { |
Christoph Hellwig | 8112e9d | 2010-04-20 17:02:29 +1000 | [diff] [blame] | 1469 | xfs_qm_dqpurge_all(mp, XFS_QMOPT_QUOTALL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | goto error_return; |
| 1471 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | |
| 1473 | /* |
| 1474 | * We didn't log anything, because if we crashed, we'll have to |
| 1475 | * start the quotacheck from scratch anyway. However, we must make |
| 1476 | * sure that our dquot changes are secure before we put the |
| 1477 | * quotacheck'd stamp on the superblock. So, here we do a synchronous |
| 1478 | * flush. |
| 1479 | */ |
Christoph Hellwig | a9add83 | 2011-10-10 16:52:52 +0000 | [diff] [blame] | 1480 | xfs_flush_buftarg(mp->m_ddev_targp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | |
| 1482 | /* |
| 1483 | * If one type of quotas is off, then it will lose its |
| 1484 | * quotachecked status, since we won't be doing accounting for |
| 1485 | * that type anymore. |
| 1486 | */ |
Chandra Seetharaman | 4177af3 | 2012-01-23 17:31:43 +0000 | [diff] [blame] | 1487 | mp->m_qflags &= ~XFS_ALL_QUOTA_CHKD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | mp->m_qflags |= flags; |
| 1489 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | error_return: |
| 1491 | if (error) { |
Dave Chinner | 0b932cc | 2011-03-07 10:08:35 +1100 | [diff] [blame] | 1492 | xfs_warn(mp, |
| 1493 | "Quotacheck: Unsuccessful (Error %d): Disabling quotas.", |
| 1494 | error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | /* |
| 1496 | * We must turn off quotas. |
| 1497 | */ |
| 1498 | ASSERT(mp->m_quotainfo != NULL); |
| 1499 | ASSERT(xfs_Gqm != NULL); |
| 1500 | xfs_qm_destroy_quotainfo(mp); |
David Chinner | 31d5577 | 2008-04-10 12:20:38 +1000 | [diff] [blame] | 1501 | if (xfs_mount_reset_sbqflags(mp)) { |
Dave Chinner | 0b932cc | 2011-03-07 10:08:35 +1100 | [diff] [blame] | 1502 | xfs_warn(mp, |
| 1503 | "Quotacheck: Failed to reset quota flags."); |
David Chinner | 31d5577 | 2008-04-10 12:20:38 +1000 | [diff] [blame] | 1504 | } |
Dave Chinner | 0b932cc | 2011-03-07 10:08:35 +1100 | [diff] [blame] | 1505 | } else |
| 1506 | xfs_notice(mp, "Quotacheck: Done."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | return (error); |
| 1508 | } |
| 1509 | |
| 1510 | /* |
| 1511 | * This is called after the superblock has been read in and we're ready to |
| 1512 | * iget the quota inodes. |
| 1513 | */ |
| 1514 | STATIC int |
| 1515 | xfs_qm_init_quotainos( |
| 1516 | xfs_mount_t *mp) |
| 1517 | { |
| 1518 | xfs_inode_t *uip, *gip; |
| 1519 | int error; |
| 1520 | __int64_t sbflags; |
| 1521 | uint flags; |
| 1522 | |
| 1523 | ASSERT(mp->m_quotainfo); |
| 1524 | uip = gip = NULL; |
| 1525 | sbflags = 0; |
| 1526 | flags = 0; |
| 1527 | |
| 1528 | /* |
| 1529 | * Get the uquota and gquota inodes |
| 1530 | */ |
Eric Sandeen | 6211870 | 2008-03-06 13:44:28 +1100 | [diff] [blame] | 1531 | if (xfs_sb_version_hasquota(&mp->m_sb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | if (XFS_IS_UQUOTA_ON(mp) && |
| 1533 | mp->m_sb.sb_uquotino != NULLFSINO) { |
| 1534 | ASSERT(mp->m_sb.sb_uquotino > 0); |
| 1535 | if ((error = xfs_iget(mp, NULL, mp->m_sb.sb_uquotino, |
Dave Chinner | 7b6259e | 2010-06-24 11:35:17 +1000 | [diff] [blame] | 1536 | 0, 0, &uip))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | return XFS_ERROR(error); |
| 1538 | } |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 1539 | if (XFS_IS_OQUOTA_ON(mp) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | mp->m_sb.sb_gquotino != NULLFSINO) { |
| 1541 | ASSERT(mp->m_sb.sb_gquotino > 0); |
| 1542 | if ((error = xfs_iget(mp, NULL, mp->m_sb.sb_gquotino, |
Dave Chinner | 7b6259e | 2010-06-24 11:35:17 +1000 | [diff] [blame] | 1543 | 0, 0, &gip))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | if (uip) |
Christoph Hellwig | 4335509 | 2008-03-27 18:01:08 +1100 | [diff] [blame] | 1545 | IRELE(uip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1546 | return XFS_ERROR(error); |
| 1547 | } |
| 1548 | } |
| 1549 | } else { |
| 1550 | flags |= XFS_QMOPT_SBVERSION; |
| 1551 | sbflags |= (XFS_SB_VERSIONNUM | XFS_SB_UQUOTINO | |
| 1552 | XFS_SB_GQUOTINO | XFS_SB_QFLAGS); |
| 1553 | } |
| 1554 | |
| 1555 | /* |
| 1556 | * Create the two inodes, if they don't exist already. The changes |
| 1557 | * made above will get added to a transaction and logged in one of |
| 1558 | * the qino_alloc calls below. If the device is readonly, |
| 1559 | * temporarily switch to read-write to do this. |
| 1560 | */ |
| 1561 | if (XFS_IS_UQUOTA_ON(mp) && uip == NULL) { |
| 1562 | if ((error = xfs_qm_qino_alloc(mp, &uip, |
| 1563 | sbflags | XFS_SB_UQUOTINO, |
| 1564 | flags | XFS_QMOPT_UQUOTA))) |
| 1565 | return XFS_ERROR(error); |
| 1566 | |
| 1567 | flags &= ~XFS_QMOPT_SBVERSION; |
| 1568 | } |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 1569 | if (XFS_IS_OQUOTA_ON(mp) && gip == NULL) { |
| 1570 | flags |= (XFS_IS_GQUOTA_ON(mp) ? |
| 1571 | XFS_QMOPT_GQUOTA : XFS_QMOPT_PQUOTA); |
| 1572 | error = xfs_qm_qino_alloc(mp, &gip, |
| 1573 | sbflags | XFS_SB_GQUOTINO, flags); |
| 1574 | if (error) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | if (uip) |
Christoph Hellwig | 4335509 | 2008-03-27 18:01:08 +1100 | [diff] [blame] | 1576 | IRELE(uip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | |
| 1578 | return XFS_ERROR(error); |
| 1579 | } |
| 1580 | } |
| 1581 | |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 1582 | mp->m_quotainfo->qi_uquotaip = uip; |
| 1583 | mp->m_quotainfo->qi_gquotaip = gip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1585 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | } |
| 1587 | |
Christoph Hellwig | 92b2e5b | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 1588 | STATIC void |
| 1589 | xfs_qm_dqfree_one( |
| 1590 | struct xfs_dquot *dqp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | { |
Christoph Hellwig | 92b2e5b | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 1592 | struct xfs_mount *mp = dqp->q_mount; |
| 1593 | struct xfs_quotainfo *qi = mp->m_quotainfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | |
Christoph Hellwig | 92b2e5b | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 1595 | mutex_lock(&dqp->q_hash->qh_lock); |
| 1596 | list_del_init(&dqp->q_hashlist); |
| 1597 | dqp->q_hash->qh_version++; |
| 1598 | mutex_unlock(&dqp->q_hash->qh_lock); |
Christoph Hellwig | bf72de3 | 2011-12-06 21:58:19 +0000 | [diff] [blame] | 1599 | |
Christoph Hellwig | 92b2e5b | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 1600 | mutex_lock(&qi->qi_dqlist_lock); |
| 1601 | list_del_init(&dqp->q_mplist); |
| 1602 | qi->qi_dquots--; |
| 1603 | qi->qi_dqreclaims++; |
| 1604 | mutex_unlock(&qi->qi_dqlist_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | |
Christoph Hellwig | 92b2e5b | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 1606 | xfs_qm_dqdestroy(dqp); |
| 1607 | } |
Christoph Hellwig | be7ffc3 | 2011-12-06 21:58:17 +0000 | [diff] [blame] | 1608 | |
Christoph Hellwig | 92b2e5b | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 1609 | STATIC void |
| 1610 | xfs_qm_dqreclaim_one( |
| 1611 | struct xfs_dquot *dqp, |
| 1612 | struct list_head *dispose_list) |
| 1613 | { |
| 1614 | struct xfs_mount *mp = dqp->q_mount; |
Christoph Hellwig | f8739c3 | 2012-03-13 08:52:34 +0000 | [diff] [blame^] | 1615 | struct xfs_quotainfo *qi = mp->m_quotainfo; |
Christoph Hellwig | 92b2e5b | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 1616 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | |
Christoph Hellwig | 92b2e5b | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 1618 | if (!xfs_dqlock_nowait(dqp)) |
| 1619 | goto out_busy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | |
Christoph Hellwig | 92b2e5b | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 1621 | /* |
| 1622 | * This dquot has acquired a reference in the meantime remove it from |
| 1623 | * the freelist and try again. |
| 1624 | */ |
| 1625 | if (dqp->q_nrefs) { |
Christoph Hellwig | 9267855 | 2011-12-06 21:58:18 +0000 | [diff] [blame] | 1626 | xfs_dqunlock(dqp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | |
Christoph Hellwig | 92b2e5b | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 1628 | trace_xfs_dqreclaim_want(dqp); |
Christoph Hellwig | 48776fd | 2012-03-13 08:52:33 +0000 | [diff] [blame] | 1629 | XFS_STATS_INC(xs_qm_dqwants); |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 1630 | |
Christoph Hellwig | f8739c3 | 2012-03-13 08:52:34 +0000 | [diff] [blame^] | 1631 | list_del_init(&dqp->q_lru); |
| 1632 | qi->qi_lru_count--; |
Christoph Hellwig | 48776fd | 2012-03-13 08:52:33 +0000 | [diff] [blame] | 1633 | XFS_STATS_DEC(xs_qm_dquot_unused); |
Christoph Hellwig | 92b2e5b | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 1634 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | } |
Christoph Hellwig | 9267855 | 2011-12-06 21:58:18 +0000 | [diff] [blame] | 1636 | |
Christoph Hellwig | 92b2e5b | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 1637 | ASSERT(dqp->q_hash); |
| 1638 | ASSERT(!list_empty(&dqp->q_mplist)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | |
Christoph Hellwig | 92b2e5b | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 1640 | /* |
| 1641 | * Try to grab the flush lock. If this dquot is in the process of |
| 1642 | * getting flushed to disk, we don't want to reclaim it. |
| 1643 | */ |
| 1644 | if (!xfs_dqflock_nowait(dqp)) |
| 1645 | goto out_busy; |
Dave Chinner | 368e136 | 2010-04-13 15:06:50 +1000 | [diff] [blame] | 1646 | |
Christoph Hellwig | 92b2e5b | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 1647 | /* |
| 1648 | * We have the flush lock so we know that this is not in the |
| 1649 | * process of being flushed. So, if this is dirty, flush it |
| 1650 | * DELWRI so that we don't get a freelist infested with |
| 1651 | * dirty dquots. |
| 1652 | */ |
| 1653 | if (XFS_DQ_IS_DIRTY(dqp)) { |
| 1654 | trace_xfs_dqreclaim_dirty(dqp); |
Dave Chinner | 368e136 | 2010-04-13 15:06:50 +1000 | [diff] [blame] | 1655 | |
Christoph Hellwig | 92b2e5b | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 1656 | /* |
| 1657 | * We flush it delayed write, so don't bother releasing the |
| 1658 | * freelist lock. |
| 1659 | */ |
| 1660 | error = xfs_qm_dqflush(dqp, 0); |
| 1661 | if (error) { |
| 1662 | xfs_warn(mp, "%s: dquot %p flush failed", |
| 1663 | __func__, dqp); |
| 1664 | } |
| 1665 | |
| 1666 | /* |
| 1667 | * Give the dquot another try on the freelist, as the |
| 1668 | * flushing will take some time. |
| 1669 | */ |
| 1670 | goto out_busy; |
Dave Chinner | 368e136 | 2010-04-13 15:06:50 +1000 | [diff] [blame] | 1671 | } |
Christoph Hellwig | 92b2e5b | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 1672 | xfs_dqfunlock(dqp); |
| 1673 | |
| 1674 | /* |
| 1675 | * Prevent lookups now that we are past the point of no return. |
| 1676 | */ |
| 1677 | dqp->dq_flags |= XFS_DQ_FREEING; |
| 1678 | xfs_dqunlock(dqp); |
| 1679 | |
| 1680 | ASSERT(dqp->q_nrefs == 0); |
Christoph Hellwig | f8739c3 | 2012-03-13 08:52:34 +0000 | [diff] [blame^] | 1681 | list_move_tail(&dqp->q_lru, dispose_list); |
| 1682 | qi->qi_lru_count--; |
Christoph Hellwig | 48776fd | 2012-03-13 08:52:33 +0000 | [diff] [blame] | 1683 | XFS_STATS_DEC(xs_qm_dquot_unused); |
Christoph Hellwig | 92b2e5b | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 1684 | |
| 1685 | trace_xfs_dqreclaim_done(dqp); |
Christoph Hellwig | 48776fd | 2012-03-13 08:52:33 +0000 | [diff] [blame] | 1686 | XFS_STATS_INC(xs_qm_dqreclaims); |
Christoph Hellwig | 92b2e5b | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 1687 | return; |
| 1688 | |
| 1689 | out_busy: |
| 1690 | xfs_dqunlock(dqp); |
| 1691 | |
| 1692 | /* |
| 1693 | * Move the dquot to the tail of the list so that we don't spin on it. |
| 1694 | */ |
Christoph Hellwig | f8739c3 | 2012-03-13 08:52:34 +0000 | [diff] [blame^] | 1695 | list_move_tail(&dqp->q_lru, &qi->qi_lru_list); |
Christoph Hellwig | 92b2e5b | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 1696 | |
| 1697 | trace_xfs_dqreclaim_busy(dqp); |
Christoph Hellwig | 48776fd | 2012-03-13 08:52:33 +0000 | [diff] [blame] | 1698 | XFS_STATS_INC(xs_qm_dqreclaim_misses); |
Dave Chinner | 368e136 | 2010-04-13 15:06:50 +1000 | [diff] [blame] | 1699 | } |
| 1700 | |
Dave Chinner | 368e136 | 2010-04-13 15:06:50 +1000 | [diff] [blame] | 1701 | STATIC int |
Dave Chinner | 7f8275d | 2010-07-19 14:56:17 +1000 | [diff] [blame] | 1702 | xfs_qm_shake( |
Christoph Hellwig | 92b2e5b | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 1703 | struct shrinker *shrink, |
| 1704 | struct shrink_control *sc) |
Dave Chinner | 368e136 | 2010-04-13 15:06:50 +1000 | [diff] [blame] | 1705 | { |
Christoph Hellwig | f8739c3 | 2012-03-13 08:52:34 +0000 | [diff] [blame^] | 1706 | struct xfs_quotainfo *qi = |
| 1707 | container_of(shrink, struct xfs_quotainfo, qi_shrinker); |
Christoph Hellwig | 92b2e5b | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 1708 | int nr_to_scan = sc->nr_to_scan; |
| 1709 | LIST_HEAD (dispose_list); |
| 1710 | struct xfs_dquot *dqp; |
Dave Chinner | 368e136 | 2010-04-13 15:06:50 +1000 | [diff] [blame] | 1711 | |
Christoph Hellwig | 92b2e5b | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 1712 | if ((sc->gfp_mask & (__GFP_FS|__GFP_WAIT)) != (__GFP_FS|__GFP_WAIT)) |
Dave Chinner | 368e136 | 2010-04-13 15:06:50 +1000 | [diff] [blame] | 1713 | return 0; |
Christoph Hellwig | 92b2e5b | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 1714 | if (!nr_to_scan) |
| 1715 | goto out; |
Dave Chinner | 368e136 | 2010-04-13 15:06:50 +1000 | [diff] [blame] | 1716 | |
Christoph Hellwig | f8739c3 | 2012-03-13 08:52:34 +0000 | [diff] [blame^] | 1717 | mutex_lock(&qi->qi_lru_lock); |
| 1718 | while (!list_empty(&qi->qi_lru_list)) { |
Christoph Hellwig | 92b2e5b | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 1719 | if (nr_to_scan-- <= 0) |
| 1720 | break; |
Christoph Hellwig | f8739c3 | 2012-03-13 08:52:34 +0000 | [diff] [blame^] | 1721 | dqp = list_first_entry(&qi->qi_lru_list, struct xfs_dquot, |
| 1722 | q_lru); |
Christoph Hellwig | 92b2e5b | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 1723 | xfs_qm_dqreclaim_one(dqp, &dispose_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | } |
Christoph Hellwig | f8739c3 | 2012-03-13 08:52:34 +0000 | [diff] [blame^] | 1725 | mutex_unlock(&qi->qi_lru_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | |
Christoph Hellwig | 92b2e5b | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 1727 | while (!list_empty(&dispose_list)) { |
Christoph Hellwig | f8739c3 | 2012-03-13 08:52:34 +0000 | [diff] [blame^] | 1728 | dqp = list_first_entry(&dispose_list, struct xfs_dquot, q_lru); |
| 1729 | list_del_init(&dqp->q_lru); |
Christoph Hellwig | 92b2e5b | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 1730 | xfs_qm_dqfree_one(dqp); |
| 1731 | } |
| 1732 | out: |
Christoph Hellwig | f8739c3 | 2012-03-13 08:52:34 +0000 | [diff] [blame^] | 1733 | return (qi->qi_lru_count / 100) * sysctl_vfs_cache_pressure; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | } |
| 1735 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | /* |
| 1737 | * Start a transaction and write the incore superblock changes to |
| 1738 | * disk. flags parameter indicates which fields have changed. |
| 1739 | */ |
| 1740 | int |
| 1741 | xfs_qm_write_sb_changes( |
| 1742 | xfs_mount_t *mp, |
| 1743 | __int64_t flags) |
| 1744 | { |
| 1745 | xfs_trans_t *tp; |
| 1746 | int error; |
| 1747 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | tp = xfs_trans_alloc(mp, XFS_TRANS_QM_SBCHANGE); |
| 1749 | if ((error = xfs_trans_reserve(tp, 0, |
| 1750 | mp->m_sb.sb_sectsize + 128, 0, |
| 1751 | 0, |
| 1752 | XFS_DEFAULT_LOG_COUNT))) { |
| 1753 | xfs_trans_cancel(tp, 0); |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1754 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | xfs_mod_sb(tp, flags); |
David Chinner | e5720ee | 2008-04-10 12:21:18 +1000 | [diff] [blame] | 1758 | error = xfs_trans_commit(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1759 | |
David Chinner | e5720ee | 2008-04-10 12:21:18 +1000 | [diff] [blame] | 1760 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | } |
| 1762 | |
| 1763 | |
| 1764 | /* --------------- utility functions for vnodeops ---------------- */ |
| 1765 | |
| 1766 | |
| 1767 | /* |
Christoph Hellwig | 6c77b0e | 2010-10-06 18:41:17 +0000 | [diff] [blame] | 1768 | * Given an inode, a uid, gid and prid make sure that we have |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1769 | * allocated relevant dquot(s) on disk, and that we won't exceed inode |
| 1770 | * quotas by creating this file. |
| 1771 | * This also attaches dquot(s) to the given inode after locking it, |
| 1772 | * and returns the dquots corresponding to the uid and/or gid. |
| 1773 | * |
| 1774 | * in : inode (unlocked) |
| 1775 | * out : udquot, gdquot with references taken and unlocked |
| 1776 | */ |
| 1777 | int |
| 1778 | xfs_qm_vop_dqalloc( |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 1779 | struct xfs_inode *ip, |
| 1780 | uid_t uid, |
| 1781 | gid_t gid, |
| 1782 | prid_t prid, |
| 1783 | uint flags, |
| 1784 | struct xfs_dquot **O_udqpp, |
| 1785 | struct xfs_dquot **O_gdqpp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | { |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 1787 | struct xfs_mount *mp = ip->i_mount; |
| 1788 | struct xfs_dquot *uq, *gq; |
| 1789 | int error; |
| 1790 | uint lockflags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 1792 | if (!XFS_IS_QUOTA_RUNNING(mp) || !XFS_IS_QUOTA_ON(mp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | return 0; |
| 1794 | |
| 1795 | lockflags = XFS_ILOCK_EXCL; |
| 1796 | xfs_ilock(ip, lockflags); |
| 1797 | |
Christoph Hellwig | bd186aa | 2007-08-30 17:21:12 +1000 | [diff] [blame] | 1798 | if ((flags & XFS_QMOPT_INHERIT) && XFS_INHERIT_GID(ip)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | gid = ip->i_d.di_gid; |
| 1800 | |
| 1801 | /* |
| 1802 | * Attach the dquot(s) to this inode, doing a dquot allocation |
| 1803 | * if necessary. The dquot(s) will not be locked. |
| 1804 | */ |
| 1805 | if (XFS_NOT_DQATTACHED(mp, ip)) { |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 1806 | error = xfs_qm_dqattach_locked(ip, XFS_QMOPT_DQALLOC); |
| 1807 | if (error) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | xfs_iunlock(ip, lockflags); |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1809 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | } |
| 1811 | } |
| 1812 | |
| 1813 | uq = gq = NULL; |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 1814 | if ((flags & XFS_QMOPT_UQUOTA) && XFS_IS_UQUOTA_ON(mp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | if (ip->i_d.di_uid != uid) { |
| 1816 | /* |
| 1817 | * What we need is the dquot that has this uid, and |
| 1818 | * if we send the inode to dqget, the uid of the inode |
| 1819 | * takes priority over what's sent in the uid argument. |
| 1820 | * We must unlock inode here before calling dqget if |
| 1821 | * we're not sending the inode, because otherwise |
| 1822 | * we'll deadlock by doing trans_reserve while |
| 1823 | * holding ilock. |
| 1824 | */ |
| 1825 | xfs_iunlock(ip, lockflags); |
| 1826 | if ((error = xfs_qm_dqget(mp, NULL, (xfs_dqid_t) uid, |
| 1827 | XFS_DQ_USER, |
| 1828 | XFS_QMOPT_DQALLOC | |
| 1829 | XFS_QMOPT_DOWARN, |
| 1830 | &uq))) { |
| 1831 | ASSERT(error != ENOENT); |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1832 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | } |
| 1834 | /* |
| 1835 | * Get the ilock in the right order. |
| 1836 | */ |
| 1837 | xfs_dqunlock(uq); |
| 1838 | lockflags = XFS_ILOCK_SHARED; |
| 1839 | xfs_ilock(ip, lockflags); |
| 1840 | } else { |
| 1841 | /* |
| 1842 | * Take an extra reference, because we'll return |
| 1843 | * this to caller |
| 1844 | */ |
| 1845 | ASSERT(ip->i_udquot); |
Christoph Hellwig | 78e5589 | 2011-12-06 21:58:22 +0000 | [diff] [blame] | 1846 | uq = xfs_qm_dqhold(ip->i_udquot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | } |
| 1848 | } |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 1849 | if ((flags & XFS_QMOPT_GQUOTA) && XFS_IS_GQUOTA_ON(mp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | if (ip->i_d.di_gid != gid) { |
| 1851 | xfs_iunlock(ip, lockflags); |
| 1852 | if ((error = xfs_qm_dqget(mp, NULL, (xfs_dqid_t)gid, |
| 1853 | XFS_DQ_GROUP, |
| 1854 | XFS_QMOPT_DQALLOC | |
| 1855 | XFS_QMOPT_DOWARN, |
| 1856 | &gq))) { |
| 1857 | if (uq) |
| 1858 | xfs_qm_dqrele(uq); |
| 1859 | ASSERT(error != ENOENT); |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1860 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | } |
| 1862 | xfs_dqunlock(gq); |
| 1863 | lockflags = XFS_ILOCK_SHARED; |
| 1864 | xfs_ilock(ip, lockflags); |
| 1865 | } else { |
| 1866 | ASSERT(ip->i_gdquot); |
Christoph Hellwig | 78e5589 | 2011-12-06 21:58:22 +0000 | [diff] [blame] | 1867 | gq = xfs_qm_dqhold(ip->i_gdquot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | } |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 1869 | } else if ((flags & XFS_QMOPT_PQUOTA) && XFS_IS_PQUOTA_ON(mp)) { |
Arkadiusz Mi?kiewicz | 6743099 | 2010-09-26 06:10:18 +0000 | [diff] [blame] | 1870 | if (xfs_get_projid(ip) != prid) { |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 1871 | xfs_iunlock(ip, lockflags); |
| 1872 | if ((error = xfs_qm_dqget(mp, NULL, (xfs_dqid_t)prid, |
| 1873 | XFS_DQ_PROJ, |
| 1874 | XFS_QMOPT_DQALLOC | |
| 1875 | XFS_QMOPT_DOWARN, |
| 1876 | &gq))) { |
| 1877 | if (uq) |
| 1878 | xfs_qm_dqrele(uq); |
| 1879 | ASSERT(error != ENOENT); |
| 1880 | return (error); |
| 1881 | } |
| 1882 | xfs_dqunlock(gq); |
| 1883 | lockflags = XFS_ILOCK_SHARED; |
| 1884 | xfs_ilock(ip, lockflags); |
| 1885 | } else { |
| 1886 | ASSERT(ip->i_gdquot); |
Christoph Hellwig | 78e5589 | 2011-12-06 21:58:22 +0000 | [diff] [blame] | 1887 | gq = xfs_qm_dqhold(ip->i_gdquot); |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 1888 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | } |
| 1890 | if (uq) |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 1891 | trace_xfs_dquot_dqalloc(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1892 | |
| 1893 | xfs_iunlock(ip, lockflags); |
| 1894 | if (O_udqpp) |
| 1895 | *O_udqpp = uq; |
| 1896 | else if (uq) |
| 1897 | xfs_qm_dqrele(uq); |
| 1898 | if (O_gdqpp) |
| 1899 | *O_gdqpp = gq; |
| 1900 | else if (gq) |
| 1901 | xfs_qm_dqrele(gq); |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1902 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | } |
| 1904 | |
| 1905 | /* |
| 1906 | * Actually transfer ownership, and do dquot modifications. |
| 1907 | * These were already reserved. |
| 1908 | */ |
| 1909 | xfs_dquot_t * |
| 1910 | xfs_qm_vop_chown( |
| 1911 | xfs_trans_t *tp, |
| 1912 | xfs_inode_t *ip, |
| 1913 | xfs_dquot_t **IO_olddq, |
| 1914 | xfs_dquot_t *newdq) |
| 1915 | { |
| 1916 | xfs_dquot_t *prevdq; |
Nathan Scott | 06d10dd | 2005-06-21 15:48:47 +1000 | [diff] [blame] | 1917 | uint bfield = XFS_IS_REALTIME_INODE(ip) ? |
| 1918 | XFS_TRANS_DQ_RTBCOUNT : XFS_TRANS_DQ_BCOUNT; |
| 1919 | |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 1920 | |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 1921 | ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | ASSERT(XFS_IS_QUOTA_RUNNING(ip->i_mount)); |
| 1923 | |
| 1924 | /* old dquot */ |
| 1925 | prevdq = *IO_olddq; |
| 1926 | ASSERT(prevdq); |
| 1927 | ASSERT(prevdq != newdq); |
| 1928 | |
Nathan Scott | 06d10dd | 2005-06-21 15:48:47 +1000 | [diff] [blame] | 1929 | xfs_trans_mod_dquot(tp, prevdq, bfield, -(ip->i_d.di_nblocks)); |
| 1930 | xfs_trans_mod_dquot(tp, prevdq, XFS_TRANS_DQ_ICOUNT, -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | |
| 1932 | /* the sparkling new dquot */ |
Nathan Scott | 06d10dd | 2005-06-21 15:48:47 +1000 | [diff] [blame] | 1933 | xfs_trans_mod_dquot(tp, newdq, bfield, ip->i_d.di_nblocks); |
| 1934 | xfs_trans_mod_dquot(tp, newdq, XFS_TRANS_DQ_ICOUNT, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1935 | |
| 1936 | /* |
Christoph Hellwig | 78e5589 | 2011-12-06 21:58:22 +0000 | [diff] [blame] | 1937 | * Take an extra reference, because the inode is going to keep |
| 1938 | * this dquot pointer even after the trans_commit. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | */ |
Christoph Hellwig | 78e5589 | 2011-12-06 21:58:22 +0000 | [diff] [blame] | 1940 | *IO_olddq = xfs_qm_dqhold(newdq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1942 | return prevdq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | /* |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 1946 | * Quota reservations for setattr(AT_UID|AT_GID|AT_PROJID). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | */ |
| 1948 | int |
| 1949 | xfs_qm_vop_chown_reserve( |
| 1950 | xfs_trans_t *tp, |
| 1951 | xfs_inode_t *ip, |
| 1952 | xfs_dquot_t *udqp, |
| 1953 | xfs_dquot_t *gdqp, |
| 1954 | uint flags) |
| 1955 | { |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 1956 | xfs_mount_t *mp = ip->i_mount; |
Nathan Scott | 9a2a7de | 2006-03-31 13:04:49 +1000 | [diff] [blame] | 1957 | uint delblks, blkflags, prjflags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1958 | xfs_dquot_t *unresudq, *unresgdq, *delblksudq, *delblksgdq; |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 1959 | int error; |
| 1960 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 1962 | ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_ILOCK_SHARED)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | ASSERT(XFS_IS_QUOTA_RUNNING(mp)); |
| 1964 | |
| 1965 | delblks = ip->i_delayed_blks; |
| 1966 | delblksudq = delblksgdq = unresudq = unresgdq = NULL; |
Nathan Scott | 06d10dd | 2005-06-21 15:48:47 +1000 | [diff] [blame] | 1967 | blkflags = XFS_IS_REALTIME_INODE(ip) ? |
| 1968 | XFS_QMOPT_RES_RTBLKS : XFS_QMOPT_RES_REGBLKS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | |
| 1970 | if (XFS_IS_UQUOTA_ON(mp) && udqp && |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 1971 | ip->i_d.di_uid != (uid_t)be32_to_cpu(udqp->q_core.d_id)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | delblksudq = udqp; |
| 1973 | /* |
| 1974 | * If there are delayed allocation blocks, then we have to |
| 1975 | * unreserve those from the old dquot, and add them to the |
| 1976 | * new dquot. |
| 1977 | */ |
| 1978 | if (delblks) { |
| 1979 | ASSERT(ip->i_udquot); |
| 1980 | unresudq = ip->i_udquot; |
| 1981 | } |
| 1982 | } |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 1983 | if (XFS_IS_OQUOTA_ON(ip->i_mount) && gdqp) { |
Nathan Scott | 9a2a7de | 2006-03-31 13:04:49 +1000 | [diff] [blame] | 1984 | if (XFS_IS_PQUOTA_ON(ip->i_mount) && |
Arkadiusz Mi?kiewicz | 6743099 | 2010-09-26 06:10:18 +0000 | [diff] [blame] | 1985 | xfs_get_projid(ip) != be32_to_cpu(gdqp->q_core.d_id)) |
Nathan Scott | 9a2a7de | 2006-03-31 13:04:49 +1000 | [diff] [blame] | 1986 | prjflags = XFS_QMOPT_ENOSPC; |
| 1987 | |
| 1988 | if (prjflags || |
| 1989 | (XFS_IS_GQUOTA_ON(ip->i_mount) && |
| 1990 | ip->i_d.di_gid != be32_to_cpu(gdqp->q_core.d_id))) { |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 1991 | delblksgdq = gdqp; |
| 1992 | if (delblks) { |
| 1993 | ASSERT(ip->i_gdquot); |
| 1994 | unresgdq = ip->i_gdquot; |
| 1995 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | } |
| 1997 | } |
| 1998 | |
| 1999 | if ((error = xfs_trans_reserve_quota_bydquots(tp, ip->i_mount, |
| 2000 | delblksudq, delblksgdq, ip->i_d.di_nblocks, 1, |
Nathan Scott | 9a2a7de | 2006-03-31 13:04:49 +1000 | [diff] [blame] | 2001 | flags | blkflags | prjflags))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | return (error); |
| 2003 | |
| 2004 | /* |
| 2005 | * Do the delayed blks reservations/unreservations now. Since, these |
| 2006 | * are done without the help of a transaction, if a reservation fails |
| 2007 | * its previous reservations won't be automatically undone by trans |
| 2008 | * code. So, we have to do it manually here. |
| 2009 | */ |
| 2010 | if (delblks) { |
| 2011 | /* |
| 2012 | * Do the reservations first. Unreservation can't fail. |
| 2013 | */ |
| 2014 | ASSERT(delblksudq || delblksgdq); |
| 2015 | ASSERT(unresudq || unresgdq); |
| 2016 | if ((error = xfs_trans_reserve_quota_bydquots(NULL, ip->i_mount, |
| 2017 | delblksudq, delblksgdq, (xfs_qcnt_t)delblks, 0, |
Nathan Scott | 9a2a7de | 2006-03-31 13:04:49 +1000 | [diff] [blame] | 2018 | flags | blkflags | prjflags))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | return (error); |
| 2020 | xfs_trans_reserve_quota_bydquots(NULL, ip->i_mount, |
| 2021 | unresudq, unresgdq, -((xfs_qcnt_t)delblks), 0, |
Nathan Scott | 06d10dd | 2005-06-21 15:48:47 +1000 | [diff] [blame] | 2022 | blkflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | } |
| 2024 | |
| 2025 | return (0); |
| 2026 | } |
| 2027 | |
| 2028 | int |
| 2029 | xfs_qm_vop_rename_dqattach( |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 2030 | struct xfs_inode **i_tab) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 | { |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 2032 | struct xfs_mount *mp = i_tab[0]->i_mount; |
| 2033 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 2035 | if (!XFS_IS_QUOTA_RUNNING(mp) || !XFS_IS_QUOTA_ON(mp)) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 2036 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 | |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 2038 | for (i = 0; (i < 4 && i_tab[i]); i++) { |
| 2039 | struct xfs_inode *ip = i_tab[i]; |
| 2040 | int error; |
| 2041 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | /* |
| 2043 | * Watch out for duplicate entries in the table. |
| 2044 | */ |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 2045 | if (i == 0 || ip != i_tab[i-1]) { |
| 2046 | if (XFS_NOT_DQATTACHED(mp, ip)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | error = xfs_qm_dqattach(ip, 0); |
| 2048 | if (error) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 2049 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | } |
| 2051 | } |
| 2052 | } |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 2053 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | } |
| 2055 | |
| 2056 | void |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 2057 | xfs_qm_vop_create_dqattach( |
| 2058 | struct xfs_trans *tp, |
| 2059 | struct xfs_inode *ip, |
| 2060 | struct xfs_dquot *udqp, |
| 2061 | struct xfs_dquot *gdqp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | { |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 2063 | struct xfs_mount *mp = tp->t_mountp; |
| 2064 | |
| 2065 | if (!XFS_IS_QUOTA_RUNNING(mp) || !XFS_IS_QUOTA_ON(mp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | return; |
| 2067 | |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 2068 | ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 2069 | ASSERT(XFS_IS_QUOTA_RUNNING(mp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | |
| 2071 | if (udqp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2072 | ASSERT(ip->i_udquot == NULL); |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 2073 | ASSERT(XFS_IS_UQUOTA_ON(mp)); |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 2074 | ASSERT(ip->i_d.di_uid == be32_to_cpu(udqp->q_core.d_id)); |
Christoph Hellwig | 78e5589 | 2011-12-06 21:58:22 +0000 | [diff] [blame] | 2075 | |
| 2076 | ip->i_udquot = xfs_qm_dqhold(udqp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2077 | xfs_trans_mod_dquot(tp, udqp, XFS_TRANS_DQ_ICOUNT, 1); |
| 2078 | } |
| 2079 | if (gdqp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | ASSERT(ip->i_gdquot == NULL); |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 2081 | ASSERT(XFS_IS_OQUOTA_ON(mp)); |
| 2082 | ASSERT((XFS_IS_GQUOTA_ON(mp) ? |
Arkadiusz Mi?kiewicz | 6743099 | 2010-09-26 06:10:18 +0000 | [diff] [blame] | 2083 | ip->i_d.di_gid : xfs_get_projid(ip)) == |
Nathan Scott | ee2a4f7 | 2006-01-11 15:33:36 +1100 | [diff] [blame] | 2084 | be32_to_cpu(gdqp->q_core.d_id)); |
Christoph Hellwig | 78e5589 | 2011-12-06 21:58:22 +0000 | [diff] [blame] | 2085 | |
| 2086 | ip->i_gdquot = xfs_qm_dqhold(gdqp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | xfs_trans_mod_dquot(tp, gdqp, XFS_TRANS_DQ_ICOUNT, 1); |
| 2088 | } |
| 2089 | } |
| 2090 | |