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-2003 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" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include "xfs_inode.h" |
| 31 | #include "xfs_bmap.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include "xfs_rtalloc.h" |
| 33 | #include "xfs_error.h" |
| 34 | #include "xfs_itable.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include "xfs_attr.h" |
| 36 | #include "xfs_buf_item.h" |
| 37 | #include "xfs_trans_space.h" |
| 38 | #include "xfs_trans_priv.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include "xfs_qm.h" |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 40 | #include "xfs_trace.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | /* |
Christoph Hellwig | bf72de3 | 2011-12-06 21:58:19 +0000 | [diff] [blame] | 43 | * Lock order: |
| 44 | * |
| 45 | * ip->i_lock |
| 46 | * qh->qh_lock |
| 47 | * qi->qi_dqlist_lock |
| 48 | * dquot->q_qlock (xfs_dqlock() and friends) |
| 49 | * dquot->q_flush (xfs_dqflock() and friends) |
| 50 | * xfs_Gqm->qm_dqfrlist_lock |
| 51 | * |
| 52 | * If two dquots need to be locked the order is user before group/project, |
| 53 | * otherwise by the lowest id first, see xfs_dqlock2. |
| 54 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #ifdef DEBUG |
| 57 | xfs_buftarg_t *xfs_dqerror_target; |
| 58 | int xfs_do_dqerror; |
| 59 | int xfs_dqreq_num; |
| 60 | int xfs_dqerror_mod = 33; |
| 61 | #endif |
| 62 | |
Christoph Hellwig | 98b8c7a | 2009-01-19 02:03:25 +0100 | [diff] [blame] | 63 | static struct lock_class_key xfs_dquot_other_class; |
| 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | * This is called to free all the memory associated with a dquot |
| 67 | */ |
| 68 | void |
| 69 | xfs_qm_dqdestroy( |
| 70 | xfs_dquot_t *dqp) |
| 71 | { |
Dave Chinner | 3a8406f | 2010-04-13 15:06:52 +1000 | [diff] [blame] | 72 | ASSERT(list_empty(&dqp->q_freelist)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
| 74 | mutex_destroy(&dqp->q_qlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | kmem_zone_free(xfs_Gqm->qm_dqzone, dqp); |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 76 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | atomic_dec(&xfs_Gqm->qm_totaldquots); |
| 78 | } |
| 79 | |
| 80 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | * If default limits are in force, push them into the dquot now. |
| 82 | * We overwrite the dquot limits only if they are zero and this |
| 83 | * is not the root dquot. |
| 84 | */ |
| 85 | void |
| 86 | xfs_qm_adjust_dqlimits( |
| 87 | xfs_mount_t *mp, |
| 88 | xfs_disk_dquot_t *d) |
| 89 | { |
| 90 | xfs_quotainfo_t *q = mp->m_quotainfo; |
| 91 | |
| 92 | ASSERT(d->d_id); |
| 93 | |
| 94 | if (q->qi_bsoftlimit && !d->d_blk_softlimit) |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 95 | d->d_blk_softlimit = cpu_to_be64(q->qi_bsoftlimit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | if (q->qi_bhardlimit && !d->d_blk_hardlimit) |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 97 | d->d_blk_hardlimit = cpu_to_be64(q->qi_bhardlimit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | if (q->qi_isoftlimit && !d->d_ino_softlimit) |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 99 | d->d_ino_softlimit = cpu_to_be64(q->qi_isoftlimit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | if (q->qi_ihardlimit && !d->d_ino_hardlimit) |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 101 | d->d_ino_hardlimit = cpu_to_be64(q->qi_ihardlimit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | if (q->qi_rtbsoftlimit && !d->d_rtb_softlimit) |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 103 | d->d_rtb_softlimit = cpu_to_be64(q->qi_rtbsoftlimit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | if (q->qi_rtbhardlimit && !d->d_rtb_hardlimit) |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 105 | d->d_rtb_hardlimit = cpu_to_be64(q->qi_rtbhardlimit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | /* |
| 109 | * Check the limits and timers of a dquot and start or reset timers |
| 110 | * if necessary. |
| 111 | * This gets called even when quota enforcement is OFF, which makes our |
| 112 | * life a little less complicated. (We just don't reject any quota |
| 113 | * reservations in that case, when enforcement is off). |
| 114 | * We also return 0 as the values of the timers in Q_GETQUOTA calls, when |
| 115 | * enforcement's off. |
| 116 | * In contrast, warnings are a little different in that they don't |
Nathan Scott | 754002b | 2005-06-21 15:49:06 +1000 | [diff] [blame] | 117 | * 'automatically' get started when limits get exceeded. They do |
| 118 | * get reset to zero, however, when we find the count to be under |
| 119 | * the soft limit (they are only ever set non-zero via userspace). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | */ |
| 121 | void |
| 122 | xfs_qm_adjust_dqtimers( |
| 123 | xfs_mount_t *mp, |
| 124 | xfs_disk_dquot_t *d) |
| 125 | { |
| 126 | ASSERT(d->d_id); |
| 127 | |
Christoph Hellwig | ea15ab3 | 2011-07-13 13:43:50 +0200 | [diff] [blame] | 128 | #ifdef DEBUG |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 129 | if (d->d_blk_hardlimit) |
| 130 | ASSERT(be64_to_cpu(d->d_blk_softlimit) <= |
| 131 | be64_to_cpu(d->d_blk_hardlimit)); |
| 132 | if (d->d_ino_hardlimit) |
| 133 | ASSERT(be64_to_cpu(d->d_ino_softlimit) <= |
| 134 | be64_to_cpu(d->d_ino_hardlimit)); |
| 135 | if (d->d_rtb_hardlimit) |
| 136 | ASSERT(be64_to_cpu(d->d_rtb_softlimit) <= |
| 137 | be64_to_cpu(d->d_rtb_hardlimit)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | #endif |
Christoph Hellwig | ea15ab3 | 2011-07-13 13:43:50 +0200 | [diff] [blame] | 139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | if (!d->d_btimer) { |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 141 | if ((d->d_blk_softlimit && |
Mitsuo Hayasaka | 20f12d8 | 2012-02-06 12:50:07 +0000 | [diff] [blame] | 142 | (be64_to_cpu(d->d_bcount) > |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 143 | be64_to_cpu(d->d_blk_softlimit))) || |
| 144 | (d->d_blk_hardlimit && |
Mitsuo Hayasaka | 20f12d8 | 2012-02-06 12:50:07 +0000 | [diff] [blame] | 145 | (be64_to_cpu(d->d_bcount) > |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 146 | be64_to_cpu(d->d_blk_hardlimit)))) { |
| 147 | d->d_btimer = cpu_to_be32(get_seconds() + |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 148 | mp->m_quotainfo->qi_btimelimit); |
Nathan Scott | 754002b | 2005-06-21 15:49:06 +1000 | [diff] [blame] | 149 | } else { |
| 150 | d->d_bwarns = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | } |
| 152 | } else { |
| 153 | if ((!d->d_blk_softlimit || |
Mitsuo Hayasaka | 20f12d8 | 2012-02-06 12:50:07 +0000 | [diff] [blame] | 154 | (be64_to_cpu(d->d_bcount) <= |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 155 | be64_to_cpu(d->d_blk_softlimit))) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | (!d->d_blk_hardlimit || |
Mitsuo Hayasaka | 20f12d8 | 2012-02-06 12:50:07 +0000 | [diff] [blame] | 157 | (be64_to_cpu(d->d_bcount) <= |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 158 | be64_to_cpu(d->d_blk_hardlimit)))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | d->d_btimer = 0; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | if (!d->d_itimer) { |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 164 | if ((d->d_ino_softlimit && |
Mitsuo Hayasaka | 20f12d8 | 2012-02-06 12:50:07 +0000 | [diff] [blame] | 165 | (be64_to_cpu(d->d_icount) > |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 166 | be64_to_cpu(d->d_ino_softlimit))) || |
| 167 | (d->d_ino_hardlimit && |
Mitsuo Hayasaka | 20f12d8 | 2012-02-06 12:50:07 +0000 | [diff] [blame] | 168 | (be64_to_cpu(d->d_icount) > |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 169 | be64_to_cpu(d->d_ino_hardlimit)))) { |
| 170 | d->d_itimer = cpu_to_be32(get_seconds() + |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 171 | mp->m_quotainfo->qi_itimelimit); |
Nathan Scott | 754002b | 2005-06-21 15:49:06 +1000 | [diff] [blame] | 172 | } else { |
| 173 | d->d_iwarns = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | } |
| 175 | } else { |
| 176 | if ((!d->d_ino_softlimit || |
Mitsuo Hayasaka | 20f12d8 | 2012-02-06 12:50:07 +0000 | [diff] [blame] | 177 | (be64_to_cpu(d->d_icount) <= |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 178 | be64_to_cpu(d->d_ino_softlimit))) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | (!d->d_ino_hardlimit || |
Mitsuo Hayasaka | 20f12d8 | 2012-02-06 12:50:07 +0000 | [diff] [blame] | 180 | (be64_to_cpu(d->d_icount) <= |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 181 | be64_to_cpu(d->d_ino_hardlimit)))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | d->d_itimer = 0; |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | if (!d->d_rtbtimer) { |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 187 | if ((d->d_rtb_softlimit && |
Mitsuo Hayasaka | 20f12d8 | 2012-02-06 12:50:07 +0000 | [diff] [blame] | 188 | (be64_to_cpu(d->d_rtbcount) > |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 189 | be64_to_cpu(d->d_rtb_softlimit))) || |
| 190 | (d->d_rtb_hardlimit && |
Mitsuo Hayasaka | 20f12d8 | 2012-02-06 12:50:07 +0000 | [diff] [blame] | 191 | (be64_to_cpu(d->d_rtbcount) > |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 192 | be64_to_cpu(d->d_rtb_hardlimit)))) { |
| 193 | d->d_rtbtimer = cpu_to_be32(get_seconds() + |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 194 | mp->m_quotainfo->qi_rtbtimelimit); |
Nathan Scott | 754002b | 2005-06-21 15:49:06 +1000 | [diff] [blame] | 195 | } else { |
| 196 | d->d_rtbwarns = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | } |
| 198 | } else { |
| 199 | if ((!d->d_rtb_softlimit || |
Mitsuo Hayasaka | 20f12d8 | 2012-02-06 12:50:07 +0000 | [diff] [blame] | 200 | (be64_to_cpu(d->d_rtbcount) <= |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 201 | be64_to_cpu(d->d_rtb_softlimit))) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | (!d->d_rtb_hardlimit || |
Mitsuo Hayasaka | 20f12d8 | 2012-02-06 12:50:07 +0000 | [diff] [blame] | 203 | (be64_to_cpu(d->d_rtbcount) <= |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 204 | be64_to_cpu(d->d_rtb_hardlimit)))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | d->d_rtbtimer = 0; |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | * initialize a buffer full of dquots and log the whole thing |
| 212 | */ |
| 213 | STATIC void |
| 214 | xfs_qm_init_dquot_blk( |
| 215 | xfs_trans_t *tp, |
| 216 | xfs_mount_t *mp, |
| 217 | xfs_dqid_t id, |
| 218 | uint type, |
| 219 | xfs_buf_t *bp) |
| 220 | { |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 221 | struct xfs_quotainfo *q = mp->m_quotainfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | xfs_dqblk_t *d; |
| 223 | int curid, i; |
| 224 | |
| 225 | ASSERT(tp); |
Christoph Hellwig | 0c842ad | 2011-07-08 14:36:19 +0200 | [diff] [blame] | 226 | ASSERT(xfs_buf_islocked(bp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
Chandra Seetharaman | 6292604 | 2011-07-22 23:40:15 +0000 | [diff] [blame] | 228 | d = bp->b_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
| 230 | /* |
| 231 | * ID of the first dquot in the block - id's are zero based. |
| 232 | */ |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 233 | curid = id - (id % q->qi_dqperchunk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | ASSERT(curid >= 0); |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 235 | memset(d, 0, BBTOB(q->qi_dqchunklen)); |
Christoph Hellwig | 49d35a5 | 2011-12-06 21:58:23 +0000 | [diff] [blame] | 236 | for (i = 0; i < q->qi_dqperchunk; i++, d++, curid++) { |
| 237 | d->dd_diskdq.d_magic = cpu_to_be16(XFS_DQUOT_MAGIC); |
| 238 | d->dd_diskdq.d_version = XFS_DQUOT_VERSION; |
| 239 | d->dd_diskdq.d_id = cpu_to_be32(curid); |
| 240 | d->dd_diskdq.d_flags = type; |
| 241 | } |
| 242 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | xfs_trans_dquot_buf(tp, bp, |
Dave Chinner | c115541 | 2010-05-07 11:05:19 +1000 | [diff] [blame] | 244 | (type & XFS_DQ_USER ? XFS_BLF_UDQUOT_BUF : |
| 245 | ((type & XFS_DQ_PROJ) ? XFS_BLF_PDQUOT_BUF : |
| 246 | XFS_BLF_GDQUOT_BUF))); |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 247 | xfs_trans_log_buf(tp, bp, 0, BBTOB(q->qi_dqchunklen) - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | |
| 251 | |
| 252 | /* |
| 253 | * Allocate a block and fill it with dquots. |
| 254 | * This is called when the bmapi finds a hole. |
| 255 | */ |
| 256 | STATIC int |
| 257 | xfs_qm_dqalloc( |
Tim Shimmin | efa092f | 2005-09-05 08:29:01 +1000 | [diff] [blame] | 258 | xfs_trans_t **tpp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | xfs_mount_t *mp, |
| 260 | xfs_dquot_t *dqp, |
| 261 | xfs_inode_t *quotip, |
| 262 | xfs_fileoff_t offset_fsb, |
| 263 | xfs_buf_t **O_bpp) |
| 264 | { |
| 265 | xfs_fsblock_t firstblock; |
| 266 | xfs_bmap_free_t flist; |
| 267 | xfs_bmbt_irec_t map; |
| 268 | int nmaps, error, committed; |
| 269 | xfs_buf_t *bp; |
Tim Shimmin | efa092f | 2005-09-05 08:29:01 +1000 | [diff] [blame] | 270 | xfs_trans_t *tp = *tpp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
| 272 | ASSERT(tp != NULL); |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 273 | |
| 274 | trace_xfs_dqalloc(dqp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | |
| 276 | /* |
| 277 | * Initialize the bmap freelist prior to calling bmapi code. |
| 278 | */ |
Eric Sandeen | 9d87c31 | 2009-01-14 23:22:07 -0600 | [diff] [blame] | 279 | xfs_bmap_init(&flist, &firstblock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | xfs_ilock(quotip, XFS_ILOCK_EXCL); |
| 281 | /* |
| 282 | * Return if this type of quotas is turned off while we didn't |
| 283 | * have an inode lock |
| 284 | */ |
| 285 | if (XFS_IS_THIS_QUOTA_OFF(dqp)) { |
| 286 | xfs_iunlock(quotip, XFS_ILOCK_EXCL); |
| 287 | return (ESRCH); |
| 288 | } |
| 289 | |
Christoph Hellwig | ddc3415 | 2011-09-19 15:00:54 +0000 | [diff] [blame] | 290 | xfs_trans_ijoin(tp, quotip, XFS_ILOCK_EXCL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | nmaps = 1; |
Dave Chinner | c0dc782 | 2011-09-18 20:40:52 +0000 | [diff] [blame] | 292 | error = xfs_bmapi_write(tp, quotip, offset_fsb, |
| 293 | XFS_DQUOT_CLUSTER_SIZE_FSB, XFS_BMAPI_METADATA, |
| 294 | &firstblock, XFS_QM_DQALLOC_SPACE_RES(mp), |
| 295 | &map, &nmaps, &flist); |
| 296 | if (error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | goto error0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | ASSERT(map.br_blockcount == XFS_DQUOT_CLUSTER_SIZE_FSB); |
| 299 | ASSERT(nmaps == 1); |
| 300 | ASSERT((map.br_startblock != DELAYSTARTBLOCK) && |
| 301 | (map.br_startblock != HOLESTARTBLOCK)); |
| 302 | |
| 303 | /* |
| 304 | * Keep track of the blkno to save a lookup later |
| 305 | */ |
| 306 | dqp->q_blkno = XFS_FSB_TO_DADDR(mp, map.br_startblock); |
| 307 | |
| 308 | /* now we can just get the buffer (there's nothing to read yet) */ |
| 309 | bp = xfs_trans_get_buf(tp, mp->m_ddev_targp, |
| 310 | dqp->q_blkno, |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 311 | mp->m_quotainfo->qi_dqchunklen, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | 0); |
Chandra Seetharaman | 2a30f36d | 2011-09-20 13:56:55 +0000 | [diff] [blame] | 313 | |
| 314 | error = xfs_buf_geterror(bp); |
| 315 | if (error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | goto error1; |
Chandra Seetharaman | 2a30f36d | 2011-09-20 13:56:55 +0000 | [diff] [blame] | 317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | /* |
| 319 | * Make a chunk of dquots out of this buffer and log |
| 320 | * the entire thing. |
| 321 | */ |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 322 | xfs_qm_init_dquot_blk(tp, mp, be32_to_cpu(dqp->q_core.d_id), |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 323 | dqp->dq_flags & XFS_DQ_ALLTYPES, bp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
Tim Shimmin | efa092f | 2005-09-05 08:29:01 +1000 | [diff] [blame] | 325 | /* |
| 326 | * xfs_bmap_finish() may commit the current transaction and |
| 327 | * start a second transaction if the freelist is not empty. |
| 328 | * |
| 329 | * Since we still want to modify this buffer, we need to |
| 330 | * ensure that the buffer is not released on commit of |
| 331 | * the first transaction and ensure the buffer is added to the |
| 332 | * second transaction. |
| 333 | * |
| 334 | * If there is only one transaction then don't stop the buffer |
| 335 | * from being released when it commits later on. |
| 336 | */ |
| 337 | |
| 338 | xfs_trans_bhold(tp, bp); |
| 339 | |
Eric Sandeen | f7c99b6 | 2007-02-10 18:37:16 +1100 | [diff] [blame] | 340 | if ((error = xfs_bmap_finish(tpp, &flist, &committed))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | goto error1; |
| 342 | } |
| 343 | |
Tim Shimmin | efa092f | 2005-09-05 08:29:01 +1000 | [diff] [blame] | 344 | if (committed) { |
| 345 | tp = *tpp; |
| 346 | xfs_trans_bjoin(tp, bp); |
| 347 | } else { |
| 348 | xfs_trans_bhold_release(tp, bp); |
| 349 | } |
| 350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | *O_bpp = bp; |
| 352 | return 0; |
| 353 | |
| 354 | error1: |
| 355 | xfs_bmap_cancel(&flist); |
| 356 | error0: |
| 357 | xfs_iunlock(quotip, XFS_ILOCK_EXCL); |
| 358 | |
| 359 | return (error); |
| 360 | } |
| 361 | |
| 362 | /* |
| 363 | * Maps a dquot to the buffer containing its on-disk version. |
| 364 | * This returns a ptr to the buffer containing the on-disk dquot |
| 365 | * in the bpp param, and a ptr to the on-disk dquot within that buffer |
| 366 | */ |
| 367 | STATIC int |
| 368 | xfs_qm_dqtobp( |
Tim Shimmin | efa092f | 2005-09-05 08:29:01 +1000 | [diff] [blame] | 369 | xfs_trans_t **tpp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | xfs_dquot_t *dqp, |
| 371 | xfs_disk_dquot_t **O_ddpp, |
| 372 | xfs_buf_t **O_bpp, |
| 373 | uint flags) |
| 374 | { |
| 375 | xfs_bmbt_irec_t map; |
Christoph Hellwig | acecf1b | 2010-09-06 01:44:45 +0000 | [diff] [blame] | 376 | int nmaps = 1, error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | xfs_buf_t *bp; |
Christoph Hellwig | acecf1b | 2010-09-06 01:44:45 +0000 | [diff] [blame] | 378 | xfs_inode_t *quotip = XFS_DQ_TO_QIP(dqp); |
| 379 | xfs_mount_t *mp = dqp->q_mount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | xfs_disk_dquot_t *ddq; |
Christoph Hellwig | acecf1b | 2010-09-06 01:44:45 +0000 | [diff] [blame] | 381 | xfs_dqid_t id = be32_to_cpu(dqp->q_core.d_id); |
Tim Shimmin | efa092f | 2005-09-05 08:29:01 +1000 | [diff] [blame] | 382 | xfs_trans_t *tp = (tpp ? *tpp : NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
Christoph Hellwig | acecf1b | 2010-09-06 01:44:45 +0000 | [diff] [blame] | 384 | dqp->q_fileoffset = (xfs_fileoff_t)id / mp->m_quotainfo->qi_dqperchunk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | |
Christoph Hellwig | acecf1b | 2010-09-06 01:44:45 +0000 | [diff] [blame] | 386 | xfs_ilock(quotip, XFS_ILOCK_SHARED); |
| 387 | if (XFS_IS_THIS_QUOTA_OFF(dqp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | /* |
Christoph Hellwig | acecf1b | 2010-09-06 01:44:45 +0000 | [diff] [blame] | 389 | * Return if this type of quotas is turned off while we |
| 390 | * didn't have the quota inode lock. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | xfs_iunlock(quotip, XFS_ILOCK_SHARED); |
Christoph Hellwig | acecf1b | 2010-09-06 01:44:45 +0000 | [diff] [blame] | 393 | return ESRCH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | |
| 396 | /* |
Christoph Hellwig | acecf1b | 2010-09-06 01:44:45 +0000 | [diff] [blame] | 397 | * Find the block map; no allocations yet |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | */ |
Dave Chinner | 5c8ed20 | 2011-09-18 20:40:45 +0000 | [diff] [blame] | 399 | error = xfs_bmapi_read(quotip, dqp->q_fileoffset, |
| 400 | XFS_DQUOT_CLUSTER_SIZE_FSB, &map, &nmaps, 0); |
Christoph Hellwig | acecf1b | 2010-09-06 01:44:45 +0000 | [diff] [blame] | 401 | |
| 402 | xfs_iunlock(quotip, XFS_ILOCK_SHARED); |
| 403 | if (error) |
| 404 | return error; |
| 405 | |
| 406 | ASSERT(nmaps == 1); |
| 407 | ASSERT(map.br_blockcount == 1); |
| 408 | |
| 409 | /* |
| 410 | * Offset of dquot in the (fixed sized) dquot chunk. |
| 411 | */ |
| 412 | dqp->q_bufoffset = (id % mp->m_quotainfo->qi_dqperchunk) * |
| 413 | sizeof(xfs_dqblk_t); |
| 414 | |
| 415 | ASSERT(map.br_startblock != DELAYSTARTBLOCK); |
| 416 | if (map.br_startblock == HOLESTARTBLOCK) { |
| 417 | /* |
| 418 | * We don't allocate unless we're asked to |
| 419 | */ |
| 420 | if (!(flags & XFS_QMOPT_DQALLOC)) |
| 421 | return ENOENT; |
| 422 | |
| 423 | ASSERT(tp); |
| 424 | error = xfs_qm_dqalloc(tpp, mp, dqp, quotip, |
| 425 | dqp->q_fileoffset, &bp); |
| 426 | if (error) |
| 427 | return error; |
| 428 | tp = *tpp; |
| 429 | } else { |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 430 | trace_xfs_dqtobp_read(dqp); |
| 431 | |
Christoph Hellwig | acecf1b | 2010-09-06 01:44:45 +0000 | [diff] [blame] | 432 | /* |
| 433 | * store the blkno etc so that we don't have to do the |
| 434 | * mapping all the time |
| 435 | */ |
| 436 | dqp->q_blkno = XFS_FSB_TO_DADDR(mp, map.br_startblock); |
| 437 | |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 438 | error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp, |
| 439 | dqp->q_blkno, |
| 440 | mp->m_quotainfo->qi_dqchunklen, |
| 441 | 0, &bp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | if (error || !bp) |
| 443 | return XFS_ERROR(error); |
| 444 | } |
Christoph Hellwig | acecf1b | 2010-09-06 01:44:45 +0000 | [diff] [blame] | 445 | |
Christoph Hellwig | 0c842ad | 2011-07-08 14:36:19 +0200 | [diff] [blame] | 446 | ASSERT(xfs_buf_islocked(bp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
| 448 | /* |
| 449 | * calculate the location of the dquot inside the buffer. |
| 450 | */ |
Chandra Seetharaman | 6292604 | 2011-07-22 23:40:15 +0000 | [diff] [blame] | 451 | ddq = bp->b_addr + dqp->q_bufoffset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | |
| 453 | /* |
| 454 | * A simple sanity check in case we got a corrupted dquot... |
| 455 | */ |
Dave Chinner | a0fa2b6 | 2011-03-07 10:01:35 +1100 | [diff] [blame] | 456 | error = xfs_qm_dqcheck(mp, ddq, id, dqp->dq_flags & XFS_DQ_ALLTYPES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | flags & (XFS_QMOPT_DQREPAIR|XFS_QMOPT_DOWARN), |
Dave Chinner | a0fa2b6 | 2011-03-07 10:01:35 +1100 | [diff] [blame] | 458 | "dqtobp"); |
| 459 | if (error) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | if (!(flags & XFS_QMOPT_DQREPAIR)) { |
| 461 | xfs_trans_brelse(tp, bp); |
| 462 | return XFS_ERROR(EIO); |
| 463 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | *O_bpp = bp; |
| 467 | *O_ddpp = ddq; |
| 468 | |
| 469 | return (0); |
| 470 | } |
| 471 | |
| 472 | |
| 473 | /* |
| 474 | * Read in the ondisk dquot using dqtobp() then copy it to an incore version, |
| 475 | * and release the buffer immediately. |
| 476 | * |
Christoph Hellwig | 97e7ade | 2011-12-06 21:58:24 +0000 | [diff] [blame] | 477 | * If XFS_QMOPT_DQALLOC is set, allocate a dquot on disk if it needed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | */ |
Christoph Hellwig | 7ae4440 | 2011-12-06 21:58:25 +0000 | [diff] [blame] | 479 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | xfs_qm_dqread( |
Christoph Hellwig | 97e7ade | 2011-12-06 21:58:24 +0000 | [diff] [blame] | 481 | struct xfs_mount *mp, |
| 482 | xfs_dqid_t id, |
| 483 | uint type, |
| 484 | uint flags, |
| 485 | struct xfs_dquot **O_dqpp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | { |
Christoph Hellwig | 97e7ade | 2011-12-06 21:58:24 +0000 | [diff] [blame] | 487 | struct xfs_dquot *dqp; |
| 488 | struct xfs_disk_dquot *ddqp; |
| 489 | struct xfs_buf *bp; |
| 490 | struct xfs_trans *tp = NULL; |
| 491 | int error; |
| 492 | int cancelflags = 0; |
Tim Shimmin | efa092f | 2005-09-05 08:29:01 +1000 | [diff] [blame] | 493 | |
Christoph Hellwig | 04da0c8 | 2012-02-01 13:57:20 +0000 | [diff] [blame] | 494 | |
| 495 | dqp = kmem_zone_zalloc(xfs_Gqm->qm_dqzone, KM_SLEEP); |
| 496 | |
| 497 | dqp->dq_flags = type; |
| 498 | dqp->q_core.d_id = cpu_to_be32(id); |
| 499 | dqp->q_mount = mp; |
| 500 | INIT_LIST_HEAD(&dqp->q_freelist); |
| 501 | mutex_init(&dqp->q_qlock); |
| 502 | init_waitqueue_head(&dqp->q_pinwait); |
| 503 | |
| 504 | /* |
| 505 | * Because we want to use a counting completion, complete |
| 506 | * the flush completion once to allow a single access to |
| 507 | * the flush completion without blocking. |
| 508 | */ |
| 509 | init_completion(&dqp->q_flush); |
| 510 | complete(&dqp->q_flush); |
| 511 | |
| 512 | /* |
| 513 | * Make sure group quotas have a different lock class than user |
| 514 | * quotas. |
| 515 | */ |
| 516 | if (!(type & XFS_DQ_USER)) |
| 517 | lockdep_set_class(&dqp->q_qlock, &xfs_dquot_other_class); |
| 518 | |
| 519 | atomic_inc(&xfs_Gqm->qm_totaldquots); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 521 | trace_xfs_dqread(dqp); |
| 522 | |
Christoph Hellwig | 97e7ade | 2011-12-06 21:58:24 +0000 | [diff] [blame] | 523 | if (flags & XFS_QMOPT_DQALLOC) { |
| 524 | tp = xfs_trans_alloc(mp, XFS_TRANS_QM_DQALLOC); |
| 525 | error = xfs_trans_reserve(tp, XFS_QM_DQALLOC_SPACE_RES(mp), |
| 526 | XFS_WRITE_LOG_RES(mp) + |
| 527 | /* |
| 528 | * Round the chunklen up to the next multiple |
| 529 | * of 128 (buf log item chunk size)). |
| 530 | */ |
| 531 | BBTOB(mp->m_quotainfo->qi_dqchunklen) - 1 + 128, |
| 532 | 0, |
| 533 | XFS_TRANS_PERM_LOG_RES, |
| 534 | XFS_WRITE_LOG_COUNT); |
| 535 | if (error) |
| 536 | goto error1; |
| 537 | cancelflags = XFS_TRANS_RELEASE_LOG_RES; |
| 538 | } |
| 539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | /* |
| 541 | * get a pointer to the on-disk dquot and the buffer containing it |
| 542 | * dqp already knows its own type (GROUP/USER). |
| 543 | */ |
Christoph Hellwig | 97e7ade | 2011-12-06 21:58:24 +0000 | [diff] [blame] | 544 | error = xfs_qm_dqtobp(&tp, dqp, &ddqp, &bp, flags); |
| 545 | if (error) { |
| 546 | /* |
| 547 | * This can happen if quotas got turned off (ESRCH), |
| 548 | * or if the dquot didn't exist on disk and we ask to |
| 549 | * allocate (ENOENT). |
| 550 | */ |
| 551 | trace_xfs_dqread_fail(dqp); |
| 552 | cancelflags |= XFS_TRANS_ABORT; |
| 553 | goto error1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | /* copy everything from disk dquot to the incore dquot */ |
| 557 | memcpy(&dqp->q_core, ddqp, sizeof(xfs_disk_dquot_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | xfs_qm_dquot_logitem_init(dqp); |
| 559 | |
| 560 | /* |
| 561 | * Reservation counters are defined as reservation plus current usage |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 562 | * to avoid having to add every time. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | */ |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 564 | dqp->q_res_bcount = be64_to_cpu(ddqp->d_bcount); |
| 565 | dqp->q_res_icount = be64_to_cpu(ddqp->d_icount); |
| 566 | dqp->q_res_rtbcount = be64_to_cpu(ddqp->d_rtbcount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
| 568 | /* Mark the buf so that this will stay incore a little longer */ |
Christoph Hellwig | 38f2323 | 2011-10-10 16:52:45 +0000 | [diff] [blame] | 569 | xfs_buf_set_ref(bp, XFS_DQUOT_REF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | |
| 571 | /* |
| 572 | * We got the buffer with a xfs_trans_read_buf() (in dqtobp()) |
| 573 | * So we need to release with xfs_trans_brelse(). |
| 574 | * The strategy here is identical to that of inodes; we lock |
| 575 | * the dquot in xfs_qm_dqget() before making it accessible to |
| 576 | * others. This is because dquots, like inodes, need a good level of |
| 577 | * concurrency, and we don't want to take locks on the entire buffers |
| 578 | * for dquot accesses. |
| 579 | * Note also that the dquot buffer may even be dirty at this point, if |
| 580 | * this particular dquot was repaired. We still aren't afraid to |
| 581 | * brelse it because we have the changes incore. |
| 582 | */ |
Christoph Hellwig | 0c842ad | 2011-07-08 14:36:19 +0200 | [diff] [blame] | 583 | ASSERT(xfs_buf_islocked(bp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | xfs_trans_brelse(tp, bp); |
| 585 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | if (tp) { |
Christoph Hellwig | 97e7ade | 2011-12-06 21:58:24 +0000 | [diff] [blame] | 587 | error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES); |
| 588 | if (error) |
| 589 | goto error0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | *O_dqpp = dqp; |
Christoph Hellwig | 97e7ade | 2011-12-06 21:58:24 +0000 | [diff] [blame] | 593 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | |
Christoph Hellwig | 97e7ade | 2011-12-06 21:58:24 +0000 | [diff] [blame] | 595 | error1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | if (tp) |
| 597 | xfs_trans_cancel(tp, cancelflags); |
Christoph Hellwig | 97e7ade | 2011-12-06 21:58:24 +0000 | [diff] [blame] | 598 | error0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | xfs_qm_dqdestroy(dqp); |
| 600 | *O_dqpp = NULL; |
Christoph Hellwig | 97e7ade | 2011-12-06 21:58:24 +0000 | [diff] [blame] | 601 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | /* |
| 605 | * Lookup a dquot in the incore dquot hashtable. We keep two separate |
| 606 | * hashtables for user and group dquots; and, these are global tables |
| 607 | * inside the XQM, not per-filesystem tables. |
| 608 | * The hash chain must be locked by caller, and it is left locked |
| 609 | * on return. Returning dquot is locked. |
| 610 | */ |
| 611 | STATIC int |
| 612 | xfs_qm_dqlookup( |
| 613 | xfs_mount_t *mp, |
| 614 | xfs_dqid_t id, |
| 615 | xfs_dqhash_t *qh, |
| 616 | xfs_dquot_t **O_dqpp) |
| 617 | { |
| 618 | xfs_dquot_t *dqp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | |
Christoph Hellwig | c9a192d | 2009-02-09 08:47:22 +0100 | [diff] [blame] | 620 | ASSERT(mutex_is_locked(&qh->qh_lock)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | /* |
| 623 | * Traverse the hashchain looking for a match |
| 624 | */ |
Dave Chinner | e6a81f1 | 2010-04-13 15:06:51 +1000 | [diff] [blame] | 625 | list_for_each_entry(dqp, &qh->qh_list, q_hashlist) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | /* |
| 627 | * We already have the hashlock. We don't need the |
| 628 | * dqlock to look at the id field of the dquot, since the |
| 629 | * id can't be modified without the hashlock anyway. |
| 630 | */ |
Christoph Hellwig | be7ffc3 | 2011-12-06 21:58:17 +0000 | [diff] [blame] | 631 | if (be32_to_cpu(dqp->q_core.d_id) != id || dqp->q_mount != mp) |
| 632 | continue; |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 633 | |
Christoph Hellwig | be7ffc3 | 2011-12-06 21:58:17 +0000 | [diff] [blame] | 634 | trace_xfs_dqlookup_found(dqp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | |
Christoph Hellwig | be7ffc3 | 2011-12-06 21:58:17 +0000 | [diff] [blame] | 636 | xfs_dqlock(dqp); |
Christoph Hellwig | 9267855 | 2011-12-06 21:58:18 +0000 | [diff] [blame] | 637 | if (dqp->dq_flags & XFS_DQ_FREEING) { |
| 638 | *O_dqpp = NULL; |
| 639 | xfs_dqunlock(dqp); |
| 640 | return -1; |
| 641 | } |
| 642 | |
Christoph Hellwig | 78e5589 | 2011-12-06 21:58:22 +0000 | [diff] [blame] | 643 | dqp->q_nrefs++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
Christoph Hellwig | be7ffc3 | 2011-12-06 21:58:17 +0000 | [diff] [blame] | 645 | /* |
| 646 | * move the dquot to the front of the hashchain |
| 647 | */ |
| 648 | list_move(&dqp->q_hashlist, &qh->qh_list); |
| 649 | trace_xfs_dqlookup_done(dqp); |
| 650 | *O_dqpp = dqp; |
| 651 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | *O_dqpp = NULL; |
Christoph Hellwig | be7ffc3 | 2011-12-06 21:58:17 +0000 | [diff] [blame] | 655 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | /* |
| 659 | * Given the file system, inode OR id, and type (UDQUOT/GDQUOT), return a |
| 660 | * a locked dquot, doing an allocation (if requested) as needed. |
| 661 | * When both an inode and an id are given, the inode's id takes precedence. |
| 662 | * That is, if the id changes while we don't hold the ilock inside this |
| 663 | * function, the new dquot is returned, not necessarily the one requested |
| 664 | * in the id argument. |
| 665 | */ |
| 666 | int |
| 667 | xfs_qm_dqget( |
| 668 | xfs_mount_t *mp, |
| 669 | xfs_inode_t *ip, /* locked inode (optional) */ |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 670 | xfs_dqid_t id, /* uid/projid/gid depending on type */ |
| 671 | uint type, /* XFS_DQ_USER/XFS_DQ_PROJ/XFS_DQ_GROUP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | uint flags, /* DQALLOC, DQSUSER, DQREPAIR, DOWARN */ |
| 673 | xfs_dquot_t **O_dqpp) /* OUT : locked incore dquot */ |
| 674 | { |
| 675 | xfs_dquot_t *dqp; |
| 676 | xfs_dqhash_t *h; |
| 677 | uint version; |
| 678 | int error; |
| 679 | |
| 680 | ASSERT(XFS_IS_QUOTA_RUNNING(mp)); |
| 681 | if ((! XFS_IS_UQUOTA_ON(mp) && type == XFS_DQ_USER) || |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 682 | (! XFS_IS_PQUOTA_ON(mp) && type == XFS_DQ_PROJ) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | (! XFS_IS_GQUOTA_ON(mp) && type == XFS_DQ_GROUP)) { |
| 684 | return (ESRCH); |
| 685 | } |
| 686 | h = XFS_DQ_HASH(mp, id, type); |
| 687 | |
| 688 | #ifdef DEBUG |
| 689 | if (xfs_do_dqerror) { |
| 690 | if ((xfs_dqerror_target == mp->m_ddev_targp) && |
| 691 | (xfs_dqreq_num++ % xfs_dqerror_mod) == 0) { |
Dave Chinner | 0b932cc | 2011-03-07 10:08:35 +1100 | [diff] [blame] | 692 | xfs_debug(mp, "Returning error in dqget"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | return (EIO); |
| 694 | } |
| 695 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame] | 697 | ASSERT(type == XFS_DQ_USER || |
| 698 | type == XFS_DQ_PROJ || |
| 699 | type == XFS_DQ_GROUP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | if (ip) { |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 701 | ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | if (type == XFS_DQ_USER) |
| 703 | ASSERT(ip->i_udquot == NULL); |
| 704 | else |
| 705 | ASSERT(ip->i_gdquot == NULL); |
| 706 | } |
| 707 | #endif |
Christoph Hellwig | 9267855 | 2011-12-06 21:58:18 +0000 | [diff] [blame] | 708 | |
| 709 | restart: |
Christoph Hellwig | c9a192d | 2009-02-09 08:47:22 +0100 | [diff] [blame] | 710 | mutex_lock(&h->qh_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | |
| 712 | /* |
| 713 | * Look in the cache (hashtable). |
| 714 | * The chain is kept locked during lookup. |
| 715 | */ |
Christoph Hellwig | 9267855 | 2011-12-06 21:58:18 +0000 | [diff] [blame] | 716 | switch (xfs_qm_dqlookup(mp, id, h, O_dqpp)) { |
| 717 | case -1: |
| 718 | XQM_STATS_INC(xqmstats.xs_qm_dquot_dups); |
| 719 | mutex_unlock(&h->qh_lock); |
| 720 | delay(1); |
| 721 | goto restart; |
| 722 | case 0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | XQM_STATS_INC(xqmstats.xs_qm_dqcachehits); |
| 724 | /* |
| 725 | * The dquot was found, moved to the front of the chain, |
| 726 | * taken off the freelist if it was on it, and locked |
| 727 | * at this point. Just unlock the hashchain and return. |
| 728 | */ |
| 729 | ASSERT(*O_dqpp); |
| 730 | ASSERT(XFS_DQ_IS_LOCKED(*O_dqpp)); |
Christoph Hellwig | c9a192d | 2009-02-09 08:47:22 +0100 | [diff] [blame] | 731 | mutex_unlock(&h->qh_lock); |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 732 | trace_xfs_dqget_hit(*O_dqpp); |
Christoph Hellwig | 9267855 | 2011-12-06 21:58:18 +0000 | [diff] [blame] | 733 | return 0; /* success */ |
| 734 | default: |
| 735 | XQM_STATS_INC(xqmstats.xs_qm_dqcachemisses); |
| 736 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | |
| 739 | /* |
| 740 | * Dquot cache miss. We don't want to keep the inode lock across |
| 741 | * a (potential) disk read. Also we don't want to deal with the lock |
| 742 | * ordering between quotainode and this inode. OTOH, dropping the inode |
| 743 | * lock here means dealing with a chown that can happen before |
| 744 | * we re-acquire the lock. |
| 745 | */ |
| 746 | if (ip) |
| 747 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
| 748 | /* |
| 749 | * Save the hashchain version stamp, and unlock the chain, so that |
| 750 | * we don't keep the lock across a disk read |
| 751 | */ |
| 752 | version = h->qh_version; |
Christoph Hellwig | c9a192d | 2009-02-09 08:47:22 +0100 | [diff] [blame] | 753 | mutex_unlock(&h->qh_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | |
Christoph Hellwig | 97e7ade | 2011-12-06 21:58:24 +0000 | [diff] [blame] | 755 | error = xfs_qm_dqread(mp, id, type, flags, &dqp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | |
Christoph Hellwig | 7ae4440 | 2011-12-06 21:58:25 +0000 | [diff] [blame] | 757 | if (ip) |
| 758 | xfs_ilock(ip, XFS_ILOCK_EXCL); |
| 759 | |
| 760 | if (error) |
| 761 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | |
| 763 | /* |
| 764 | * Dquot lock comes after hashlock in the lock ordering |
| 765 | */ |
| 766 | if (ip) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | /* |
| 768 | * A dquot could be attached to this inode by now, since |
| 769 | * we had dropped the ilock. |
| 770 | */ |
| 771 | if (type == XFS_DQ_USER) { |
Christoph Hellwig | 191f848 | 2010-04-20 17:01:53 +1000 | [diff] [blame] | 772 | if (!XFS_IS_UQUOTA_ON(mp)) { |
| 773 | /* inode stays locked on return */ |
| 774 | xfs_qm_dqdestroy(dqp); |
| 775 | return XFS_ERROR(ESRCH); |
| 776 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | if (ip->i_udquot) { |
| 778 | xfs_qm_dqdestroy(dqp); |
| 779 | dqp = ip->i_udquot; |
| 780 | xfs_dqlock(dqp); |
| 781 | goto dqret; |
| 782 | } |
| 783 | } else { |
Christoph Hellwig | 191f848 | 2010-04-20 17:01:53 +1000 | [diff] [blame] | 784 | if (!XFS_IS_OQUOTA_ON(mp)) { |
| 785 | /* inode stays locked on return */ |
| 786 | xfs_qm_dqdestroy(dqp); |
| 787 | return XFS_ERROR(ESRCH); |
| 788 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | if (ip->i_gdquot) { |
| 790 | xfs_qm_dqdestroy(dqp); |
| 791 | dqp = ip->i_gdquot; |
| 792 | xfs_dqlock(dqp); |
| 793 | goto dqret; |
| 794 | } |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | /* |
| 799 | * Hashlock comes after ilock in lock order |
| 800 | */ |
Christoph Hellwig | c9a192d | 2009-02-09 08:47:22 +0100 | [diff] [blame] | 801 | mutex_lock(&h->qh_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | if (version != h->qh_version) { |
| 803 | xfs_dquot_t *tmpdqp; |
| 804 | /* |
| 805 | * Now, see if somebody else put the dquot in the |
| 806 | * hashtable before us. This can happen because we didn't |
| 807 | * keep the hashchain lock. We don't have to worry about |
| 808 | * lock order between the two dquots here since dqp isn't |
| 809 | * on any findable lists yet. |
| 810 | */ |
Christoph Hellwig | 9267855 | 2011-12-06 21:58:18 +0000 | [diff] [blame] | 811 | switch (xfs_qm_dqlookup(mp, id, h, &tmpdqp)) { |
| 812 | case 0: |
| 813 | case -1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | /* |
Christoph Hellwig | 9267855 | 2011-12-06 21:58:18 +0000 | [diff] [blame] | 815 | * Duplicate found, either in cache or on its way out. |
| 816 | * Just throw away the new dquot and start over. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | */ |
Christoph Hellwig | 9267855 | 2011-12-06 21:58:18 +0000 | [diff] [blame] | 818 | if (tmpdqp) |
| 819 | xfs_qm_dqput(tmpdqp); |
Christoph Hellwig | c9a192d | 2009-02-09 08:47:22 +0100 | [diff] [blame] | 820 | mutex_unlock(&h->qh_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | xfs_qm_dqdestroy(dqp); |
| 822 | XQM_STATS_INC(xqmstats.xs_qm_dquot_dups); |
Christoph Hellwig | 9267855 | 2011-12-06 21:58:18 +0000 | [diff] [blame] | 823 | goto restart; |
| 824 | default: |
| 825 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | } |
| 827 | } |
| 828 | |
| 829 | /* |
| 830 | * Put the dquot at the beginning of the hash-chain and mp's list |
| 831 | * LOCK ORDER: hashlock, freelistlock, mplistlock, udqlock, gdqlock .. |
| 832 | */ |
Christoph Hellwig | c9a192d | 2009-02-09 08:47:22 +0100 | [diff] [blame] | 833 | ASSERT(mutex_is_locked(&h->qh_lock)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | dqp->q_hash = h; |
Dave Chinner | e6a81f1 | 2010-04-13 15:06:51 +1000 | [diff] [blame] | 835 | list_add(&dqp->q_hashlist, &h->qh_list); |
| 836 | h->qh_version++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | |
| 838 | /* |
| 839 | * Attach this dquot to this filesystem's list of all dquots, |
| 840 | * kept inside the mount structure in m_quotainfo field |
| 841 | */ |
Dave Chinner | 3a25404 | 2010-04-13 15:06:48 +1000 | [diff] [blame] | 842 | mutex_lock(&mp->m_quotainfo->qi_dqlist_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | |
| 844 | /* |
| 845 | * We return a locked dquot to the caller, with a reference taken |
| 846 | */ |
| 847 | xfs_dqlock(dqp); |
| 848 | dqp->q_nrefs = 1; |
| 849 | |
Dave Chinner | 3a25404 | 2010-04-13 15:06:48 +1000 | [diff] [blame] | 850 | list_add(&dqp->q_mplist, &mp->m_quotainfo->qi_dqlist); |
| 851 | mp->m_quotainfo->qi_dquots++; |
| 852 | mutex_unlock(&mp->m_quotainfo->qi_dqlist_lock); |
Christoph Hellwig | c9a192d | 2009-02-09 08:47:22 +0100 | [diff] [blame] | 853 | mutex_unlock(&h->qh_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | dqret: |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 855 | ASSERT((ip == NULL) || xfs_isilocked(ip, XFS_ILOCK_EXCL)); |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 856 | trace_xfs_dqget_miss(dqp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | *O_dqpp = dqp; |
| 858 | return (0); |
| 859 | } |
| 860 | |
| 861 | |
| 862 | /* |
| 863 | * Release a reference to the dquot (decrement ref-count) |
| 864 | * and unlock it. If there is a group quota attached to this |
| 865 | * dquot, carefully release that too without tripping over |
| 866 | * deadlocks'n'stuff. |
| 867 | */ |
| 868 | void |
| 869 | xfs_qm_dqput( |
Christoph Hellwig | bf72de3 | 2011-12-06 21:58:19 +0000 | [diff] [blame] | 870 | struct xfs_dquot *dqp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | { |
Christoph Hellwig | bf72de3 | 2011-12-06 21:58:19 +0000 | [diff] [blame] | 872 | struct xfs_dquot *gdqp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | |
| 874 | ASSERT(dqp->q_nrefs > 0); |
| 875 | ASSERT(XFS_DQ_IS_LOCKED(dqp)); |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 876 | |
| 877 | trace_xfs_dqput(dqp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | |
Christoph Hellwig | bf72de3 | 2011-12-06 21:58:19 +0000 | [diff] [blame] | 879 | recurse: |
| 880 | if (--dqp->q_nrefs > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | xfs_dqunlock(dqp); |
| 882 | return; |
| 883 | } |
| 884 | |
Christoph Hellwig | bf72de3 | 2011-12-06 21:58:19 +0000 | [diff] [blame] | 885 | trace_xfs_dqput_free(dqp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | |
Christoph Hellwig | bf72de3 | 2011-12-06 21:58:19 +0000 | [diff] [blame] | 887 | mutex_lock(&xfs_Gqm->qm_dqfrlist_lock); |
| 888 | if (list_empty(&dqp->q_freelist)) { |
| 889 | list_add_tail(&dqp->q_freelist, &xfs_Gqm->qm_dqfrlist); |
| 890 | xfs_Gqm->qm_dqfrlist_cnt++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | } |
Dave Chinner | 3a8406f | 2010-04-13 15:06:52 +1000 | [diff] [blame] | 892 | mutex_unlock(&xfs_Gqm->qm_dqfrlist_lock); |
Christoph Hellwig | bf72de3 | 2011-12-06 21:58:19 +0000 | [diff] [blame] | 893 | |
| 894 | /* |
| 895 | * If we just added a udquot to the freelist, then we want to release |
| 896 | * the gdquot reference that it (probably) has. Otherwise it'll keep |
| 897 | * the gdquot from getting reclaimed. |
| 898 | */ |
| 899 | gdqp = dqp->q_gdquot; |
| 900 | if (gdqp) { |
| 901 | xfs_dqlock(gdqp); |
| 902 | dqp->q_gdquot = NULL; |
| 903 | } |
| 904 | xfs_dqunlock(dqp); |
| 905 | |
| 906 | /* |
| 907 | * If we had a group quota hint, release it now. |
| 908 | */ |
| 909 | if (gdqp) { |
| 910 | dqp = gdqp; |
| 911 | goto recurse; |
| 912 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | /* |
| 916 | * Release a dquot. Flush it if dirty, then dqput() it. |
| 917 | * dquot must not be locked. |
| 918 | */ |
| 919 | void |
| 920 | xfs_qm_dqrele( |
| 921 | xfs_dquot_t *dqp) |
| 922 | { |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 923 | if (!dqp) |
| 924 | return; |
| 925 | |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 926 | trace_xfs_dqrele(dqp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | |
| 928 | xfs_dqlock(dqp); |
| 929 | /* |
| 930 | * We don't care to flush it if the dquot is dirty here. |
| 931 | * That will create stutters that we want to avoid. |
| 932 | * Instead we do a delayed write when we try to reclaim |
| 933 | * a dirty dquot. Also xfs_sync will take part of the burden... |
| 934 | */ |
| 935 | xfs_qm_dqput(dqp); |
| 936 | } |
| 937 | |
Christoph Hellwig | ca30b2a | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 938 | /* |
| 939 | * This is the dquot flushing I/O completion routine. It is called |
| 940 | * from interrupt level when the buffer containing the dquot is |
| 941 | * flushed to disk. It is responsible for removing the dquot logitem |
| 942 | * from the AIL if it has not been re-logged, and unlocking the dquot's |
| 943 | * flush lock. This behavior is very similar to that of inodes.. |
| 944 | */ |
| 945 | STATIC void |
| 946 | xfs_qm_dqflush_done( |
| 947 | struct xfs_buf *bp, |
| 948 | struct xfs_log_item *lip) |
| 949 | { |
| 950 | xfs_dq_logitem_t *qip = (struct xfs_dq_logitem *)lip; |
| 951 | xfs_dquot_t *dqp = qip->qli_dquot; |
| 952 | struct xfs_ail *ailp = lip->li_ailp; |
| 953 | |
| 954 | /* |
| 955 | * We only want to pull the item from the AIL if its |
| 956 | * location in the log has not changed since we started the flush. |
| 957 | * Thus, we only bother if the dquot's lsn has |
| 958 | * not changed. First we check the lsn outside the lock |
| 959 | * since it's cheaper, and then we recheck while |
| 960 | * holding the lock before removing the dquot from the AIL. |
| 961 | */ |
| 962 | if ((lip->li_flags & XFS_LI_IN_AIL) && |
| 963 | lip->li_lsn == qip->qli_flush_lsn) { |
| 964 | |
| 965 | /* xfs_trans_ail_delete() drops the AIL lock. */ |
| 966 | spin_lock(&ailp->xa_lock); |
| 967 | if (lip->li_lsn == qip->qli_flush_lsn) |
| 968 | xfs_trans_ail_delete(ailp, lip); |
| 969 | else |
| 970 | spin_unlock(&ailp->xa_lock); |
| 971 | } |
| 972 | |
| 973 | /* |
| 974 | * Release the dq's flush lock since we're done with it. |
| 975 | */ |
| 976 | xfs_dqfunlock(dqp); |
| 977 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | |
| 979 | /* |
| 980 | * Write a modified dquot to disk. |
| 981 | * The dquot must be locked and the flush lock too taken by caller. |
| 982 | * The flush lock will not be unlocked until the dquot reaches the disk, |
| 983 | * but the dquot is free to be unlocked and modified by the caller |
| 984 | * in the interim. Dquot is still locked on return. This behavior is |
| 985 | * identical to that of inodes. |
| 986 | */ |
| 987 | int |
| 988 | xfs_qm_dqflush( |
| 989 | xfs_dquot_t *dqp, |
| 990 | uint flags) |
| 991 | { |
Christoph Hellwig | acecf1b | 2010-09-06 01:44:45 +0000 | [diff] [blame] | 992 | struct xfs_mount *mp = dqp->q_mount; |
| 993 | struct xfs_buf *bp; |
| 994 | struct xfs_disk_dquot *ddqp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | |
| 997 | ASSERT(XFS_DQ_IS_LOCKED(dqp)); |
David Chinner | e1f49cf | 2008-08-13 16:41:43 +1000 | [diff] [blame] | 998 | ASSERT(!completion_done(&dqp->q_flush)); |
Christoph Hellwig | acecf1b | 2010-09-06 01:44:45 +0000 | [diff] [blame] | 999 | |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 1000 | trace_xfs_dqflush(dqp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | |
| 1002 | /* |
Christoph Hellwig | acecf1b | 2010-09-06 01:44:45 +0000 | [diff] [blame] | 1003 | * If not dirty, or it's pinned and we are not supposed to block, nada. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | */ |
David Chinner | 2f8a3ce | 2008-10-30 17:07:20 +1100 | [diff] [blame] | 1005 | if (!XFS_DQ_IS_DIRTY(dqp) || |
Christoph Hellwig | fdedf28 | 2011-12-06 21:58:10 +0000 | [diff] [blame] | 1006 | ((flags & SYNC_TRYLOCK) && atomic_read(&dqp->q_pincount) > 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | xfs_dqfunlock(dqp); |
David Chinner | 2f8a3ce | 2008-10-30 17:07:20 +1100 | [diff] [blame] | 1008 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | xfs_qm_dqunpin_wait(dqp); |
| 1011 | |
| 1012 | /* |
| 1013 | * This may have been unpinned because the filesystem is shutting |
| 1014 | * down forcibly. If that's the case we must not write this dquot |
| 1015 | * to disk, because the log record didn't make it to disk! |
| 1016 | */ |
Christoph Hellwig | acecf1b | 2010-09-06 01:44:45 +0000 | [diff] [blame] | 1017 | if (XFS_FORCED_SHUTDOWN(mp)) { |
| 1018 | dqp->dq_flags &= ~XFS_DQ_DIRTY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | xfs_dqfunlock(dqp); |
| 1020 | return XFS_ERROR(EIO); |
| 1021 | } |
| 1022 | |
| 1023 | /* |
| 1024 | * Get the buffer containing the on-disk dquot |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | */ |
Christoph Hellwig | acecf1b | 2010-09-06 01:44:45 +0000 | [diff] [blame] | 1026 | error = xfs_trans_read_buf(mp, NULL, mp->m_ddev_targp, dqp->q_blkno, |
| 1027 | mp->m_quotainfo->qi_dqchunklen, 0, &bp); |
| 1028 | if (error) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | ASSERT(error != ENOENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | xfs_dqfunlock(dqp); |
Christoph Hellwig | acecf1b | 2010-09-06 01:44:45 +0000 | [diff] [blame] | 1031 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | } |
| 1033 | |
Christoph Hellwig | acecf1b | 2010-09-06 01:44:45 +0000 | [diff] [blame] | 1034 | /* |
| 1035 | * Calculate the location of the dquot inside the buffer. |
| 1036 | */ |
Chandra Seetharaman | 6292604 | 2011-07-22 23:40:15 +0000 | [diff] [blame] | 1037 | ddqp = bp->b_addr + dqp->q_bufoffset; |
Christoph Hellwig | acecf1b | 2010-09-06 01:44:45 +0000 | [diff] [blame] | 1038 | |
| 1039 | /* |
| 1040 | * A simple sanity check in case we got a corrupted dquot.. |
| 1041 | */ |
Dave Chinner | a0fa2b6 | 2011-03-07 10:01:35 +1100 | [diff] [blame] | 1042 | error = xfs_qm_dqcheck(mp, &dqp->q_core, be32_to_cpu(ddqp->d_id), 0, |
| 1043 | XFS_QMOPT_DOWARN, "dqflush (incore copy)"); |
| 1044 | if (error) { |
Christoph Hellwig | acecf1b | 2010-09-06 01:44:45 +0000 | [diff] [blame] | 1045 | xfs_buf_relse(bp); |
| 1046 | xfs_dqfunlock(dqp); |
| 1047 | xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | return XFS_ERROR(EIO); |
| 1049 | } |
| 1050 | |
| 1051 | /* This is the only portion of data that needs to persist */ |
Christoph Hellwig | acecf1b | 2010-09-06 01:44:45 +0000 | [diff] [blame] | 1052 | memcpy(ddqp, &dqp->q_core, sizeof(xfs_disk_dquot_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | |
| 1054 | /* |
| 1055 | * Clear the dirty field and remember the flush lsn for later use. |
| 1056 | */ |
Christoph Hellwig | acecf1b | 2010-09-06 01:44:45 +0000 | [diff] [blame] | 1057 | dqp->dq_flags &= ~XFS_DQ_DIRTY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | |
David Chinner | 7b2e2a3 | 2008-10-30 17:39:12 +1100 | [diff] [blame] | 1059 | xfs_trans_ail_copy_lsn(mp->m_ail, &dqp->q_logitem.qli_flush_lsn, |
| 1060 | &dqp->q_logitem.qli_item.li_lsn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | |
| 1062 | /* |
| 1063 | * Attach an iodone routine so that we can remove this dquot from the |
| 1064 | * AIL and release the flush lock once the dquot is synced to disk. |
| 1065 | */ |
Christoph Hellwig | ca30b2a | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 1066 | xfs_buf_attach_iodone(bp, xfs_qm_dqflush_done, |
| 1067 | &dqp->q_logitem.qli_item); |
| 1068 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | /* |
| 1070 | * If the buffer is pinned then push on the log so we won't |
| 1071 | * get stuck waiting in the write for too long. |
| 1072 | */ |
Chandra Seetharaman | 811e64c | 2011-07-22 23:40:27 +0000 | [diff] [blame] | 1073 | if (xfs_buf_ispinned(bp)) { |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 1074 | trace_xfs_dqflush_force(dqp); |
Christoph Hellwig | a14a348 | 2010-01-19 09:56:46 +0000 | [diff] [blame] | 1075 | xfs_log_force(mp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | } |
| 1077 | |
Dave Chinner | 20026d9 | 2010-02-04 09:48:58 +1100 | [diff] [blame] | 1078 | if (flags & SYNC_WAIT) |
Christoph Hellwig | c2b006c | 2011-08-23 08:28:07 +0000 | [diff] [blame] | 1079 | error = xfs_bwrite(bp); |
| 1080 | else |
Christoph Hellwig | 61551f1 | 2011-08-23 08:28:06 +0000 | [diff] [blame] | 1081 | xfs_buf_delwri_queue(bp); |
Christoph Hellwig | c2b006c | 2011-08-23 08:28:07 +0000 | [diff] [blame] | 1082 | |
| 1083 | xfs_buf_relse(bp); |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 1084 | |
| 1085 | trace_xfs_dqflush_done(dqp); |
| 1086 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | /* |
| 1088 | * dqp is still locked, but caller is free to unlock it now. |
| 1089 | */ |
Dave Chinner | 20026d9 | 2010-02-04 09:48:58 +1100 | [diff] [blame] | 1090 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | |
| 1092 | } |
| 1093 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | void |
| 1095 | xfs_dqunlock( |
| 1096 | xfs_dquot_t *dqp) |
| 1097 | { |
Christoph Hellwig | 800b484 | 2011-12-06 21:58:14 +0000 | [diff] [blame] | 1098 | xfs_dqunlock_nonotify(dqp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | if (dqp->q_logitem.qli_dquot == dqp) { |
David Chinner | 783a2f6 | 2008-10-30 17:39:58 +1100 | [diff] [blame] | 1100 | xfs_trans_unlocked_item(dqp->q_logitem.qli_item.li_ailp, |
Christoph Hellwig | 800b484 | 2011-12-06 21:58:14 +0000 | [diff] [blame] | 1101 | &dqp->q_logitem.qli_item); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | } |
| 1103 | } |
| 1104 | |
Christoph Hellwig | 5bb87a3 | 2009-01-19 02:03:19 +0100 | [diff] [blame] | 1105 | /* |
| 1106 | * Lock two xfs_dquot structures. |
| 1107 | * |
| 1108 | * To avoid deadlocks we always lock the quota structure with |
| 1109 | * the lowerd id first. |
| 1110 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | void |
| 1112 | xfs_dqlock2( |
| 1113 | xfs_dquot_t *d1, |
| 1114 | xfs_dquot_t *d2) |
| 1115 | { |
| 1116 | if (d1 && d2) { |
| 1117 | ASSERT(d1 != d2); |
Christoph Hellwig | 1149d96 | 2005-11-02 15:01:12 +1100 | [diff] [blame] | 1118 | if (be32_to_cpu(d1->q_core.d_id) > |
| 1119 | be32_to_cpu(d2->q_core.d_id)) { |
Christoph Hellwig | 5bb87a3 | 2009-01-19 02:03:19 +0100 | [diff] [blame] | 1120 | mutex_lock(&d2->q_qlock); |
| 1121 | mutex_lock_nested(&d1->q_qlock, XFS_QLOCK_NESTED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | } else { |
Christoph Hellwig | 5bb87a3 | 2009-01-19 02:03:19 +0100 | [diff] [blame] | 1123 | mutex_lock(&d1->q_qlock); |
| 1124 | mutex_lock_nested(&d2->q_qlock, XFS_QLOCK_NESTED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | } |
Christoph Hellwig | 5bb87a3 | 2009-01-19 02:03:19 +0100 | [diff] [blame] | 1126 | } else if (d1) { |
| 1127 | mutex_lock(&d1->q_qlock); |
| 1128 | } else if (d2) { |
| 1129 | mutex_lock(&d2->q_qlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | } |
| 1131 | } |
| 1132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | /* |
Christoph Hellwig | 9267855 | 2011-12-06 21:58:18 +0000 | [diff] [blame] | 1134 | * Take a dquot out of the mount's dqlist as well as the hashlist. This is |
| 1135 | * called via unmount as well as quotaoff, and the purge will always succeed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | */ |
Christoph Hellwig | 9267855 | 2011-12-06 21:58:18 +0000 | [diff] [blame] | 1137 | void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | xfs_qm_dqpurge( |
Christoph Hellwig | 9267855 | 2011-12-06 21:58:18 +0000 | [diff] [blame] | 1139 | struct xfs_dquot *dqp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | { |
Christoph Hellwig | 9267855 | 2011-12-06 21:58:18 +0000 | [diff] [blame] | 1141 | struct xfs_mount *mp = dqp->q_mount; |
| 1142 | struct xfs_dqhash *qh = dqp->q_hash; |
Christoph Hellwig | 80a376b | 2011-12-06 21:58:16 +0000 | [diff] [blame] | 1143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | xfs_dqlock(dqp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | |
| 1146 | /* |
| 1147 | * If we're turning off quotas, we have to make sure that, for |
| 1148 | * example, we don't delete quota disk blocks while dquots are |
| 1149 | * in the process of getting written to those disk blocks. |
| 1150 | * This dquot might well be on AIL, and we can't leave it there |
| 1151 | * if we're turning off quotas. Basically, we need this flush |
| 1152 | * lock, and are willing to block on it. |
| 1153 | */ |
David Chinner | e1f49cf | 2008-08-13 16:41:43 +1000 | [diff] [blame] | 1154 | if (!xfs_dqflock_nowait(dqp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | /* |
| 1156 | * Block on the flush lock after nudging dquot buffer, |
| 1157 | * if it is incore. |
| 1158 | */ |
Christoph Hellwig | 800b484 | 2011-12-06 21:58:14 +0000 | [diff] [blame] | 1159 | xfs_dqflock_pushbuf_wait(dqp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | /* |
Christoph Hellwig | 9267855 | 2011-12-06 21:58:18 +0000 | [diff] [blame] | 1163 | * If we are turning this type of quotas off, we don't care |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | * about the dirty metadata sitting in this dquot. OTOH, if |
| 1165 | * we're unmounting, we do care, so we flush it and wait. |
| 1166 | */ |
| 1167 | if (XFS_DQ_IS_DIRTY(dqp)) { |
David Chinner | 3c56836 | 2008-04-10 12:20:24 +1000 | [diff] [blame] | 1168 | int error; |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 1169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | * We don't care about getting disk errors here. We need |
| 1172 | * to purge this dquot anyway, so we go ahead regardless. |
| 1173 | */ |
Dave Chinner | 20026d9 | 2010-02-04 09:48:58 +1100 | [diff] [blame] | 1174 | error = xfs_qm_dqflush(dqp, SYNC_WAIT); |
David Chinner | 3c56836 | 2008-04-10 12:20:24 +1000 | [diff] [blame] | 1175 | if (error) |
Dave Chinner | 5348778 | 2011-03-07 10:05:35 +1100 | [diff] [blame] | 1176 | xfs_warn(mp, "%s: dquot %p flush failed", |
| 1177 | __func__, dqp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | xfs_dqflock(dqp); |
| 1179 | } |
Christoph Hellwig | 9267855 | 2011-12-06 21:58:18 +0000 | [diff] [blame] | 1180 | |
Peter Leckie | bc3048e | 2008-10-30 17:05:04 +1100 | [diff] [blame] | 1181 | ASSERT(atomic_read(&dqp->q_pincount) == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | ASSERT(XFS_FORCED_SHUTDOWN(mp) || |
| 1183 | !(dqp->q_logitem.qli_item.li_flags & XFS_LI_IN_AIL)); |
| 1184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | xfs_dqfunlock(dqp); |
| 1186 | xfs_dqunlock(dqp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | |
Christoph Hellwig | 9267855 | 2011-12-06 21:58:18 +0000 | [diff] [blame] | 1188 | mutex_lock(&qh->qh_lock); |
| 1189 | list_del_init(&dqp->q_hashlist); |
| 1190 | qh->qh_version++; |
Christoph Hellwig | 80a376b | 2011-12-06 21:58:16 +0000 | [diff] [blame] | 1191 | mutex_unlock(&qh->qh_lock); |
| 1192 | |
Christoph Hellwig | 9267855 | 2011-12-06 21:58:18 +0000 | [diff] [blame] | 1193 | mutex_lock(&mp->m_quotainfo->qi_dqlist_lock); |
| 1194 | list_del_init(&dqp->q_mplist); |
| 1195 | mp->m_quotainfo->qi_dqreclaims++; |
| 1196 | mp->m_quotainfo->qi_dquots--; |
| 1197 | mutex_unlock(&mp->m_quotainfo->qi_dqlist_lock); |
| 1198 | |
| 1199 | /* |
| 1200 | * We move dquots to the freelist as soon as their reference count |
| 1201 | * hits zero, so it really should be on the freelist here. |
| 1202 | */ |
| 1203 | mutex_lock(&xfs_Gqm->qm_dqfrlist_lock); |
| 1204 | ASSERT(!list_empty(&dqp->q_freelist)); |
| 1205 | list_del_init(&dqp->q_freelist); |
| 1206 | xfs_Gqm->qm_dqfrlist_cnt--; |
| 1207 | mutex_unlock(&xfs_Gqm->qm_dqfrlist_lock); |
| 1208 | |
Christoph Hellwig | 80a376b | 2011-12-06 21:58:16 +0000 | [diff] [blame] | 1209 | xfs_qm_dqdestroy(dqp); |
Christoph Hellwig | 80a376b | 2011-12-06 21:58:16 +0000 | [diff] [blame] | 1210 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | /* |
| 1213 | * Give the buffer a little push if it is incore and |
| 1214 | * wait on the flush lock. |
| 1215 | */ |
| 1216 | void |
Christoph Hellwig | 800b484 | 2011-12-06 21:58:14 +0000 | [diff] [blame] | 1217 | xfs_dqflock_pushbuf_wait( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | xfs_dquot_t *dqp) |
| 1219 | { |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 1220 | xfs_mount_t *mp = dqp->q_mount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | xfs_buf_t *bp; |
| 1222 | |
| 1223 | /* |
| 1224 | * Check to see if the dquot has been flushed delayed |
| 1225 | * write. If so, grab its buffer and send it |
| 1226 | * out immediately. We'll be able to acquire |
| 1227 | * the flush lock when the I/O completes. |
| 1228 | */ |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 1229 | bp = xfs_incore(mp->m_ddev_targp, dqp->q_blkno, |
| 1230 | mp->m_quotainfo->qi_dqchunklen, XBF_TRYLOCK); |
Dave Chinner | 7d6a7bd | 2010-01-26 15:13:41 +1100 | [diff] [blame] | 1231 | if (!bp) |
| 1232 | goto out_lock; |
Christoph Hellwig | a14a348 | 2010-01-19 09:56:46 +0000 | [diff] [blame] | 1233 | |
Dave Chinner | 7d6a7bd | 2010-01-26 15:13:41 +1100 | [diff] [blame] | 1234 | if (XFS_BUF_ISDELAYWRITE(bp)) { |
Chandra Seetharaman | 811e64c | 2011-07-22 23:40:27 +0000 | [diff] [blame] | 1235 | if (xfs_buf_ispinned(bp)) |
Christoph Hellwig | 8a7b8a8 | 2010-04-20 17:01:30 +1000 | [diff] [blame] | 1236 | xfs_log_force(mp, 0); |
Dave Chinner | 7d6a7bd | 2010-01-26 15:13:41 +1100 | [diff] [blame] | 1237 | xfs_buf_delwri_promote(bp); |
| 1238 | wake_up_process(bp->b_target->bt_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | } |
Dave Chinner | 7d6a7bd | 2010-01-26 15:13:41 +1100 | [diff] [blame] | 1240 | xfs_buf_relse(bp); |
| 1241 | out_lock: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | xfs_dqflock(dqp); |
| 1243 | } |