blob: 2025f6eea4aa3bc1644935d3344fb7e86d610b1b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott4ce31212005-11-02 14:59:41 +11002 * Copyright (c) 2000-2002 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott4ce31212005-11-02 14:59:41 +11005 * 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 Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott4ce31212005-11-02 14:59:41 +11009 * 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 Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott4ce31212005-11-02 14:59:41 +110014 * 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 Torvalds1da177e2005-04-16 15:20:36 -070017 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "xfs.h"
19#include "xfs_fs.h"
Dave Chinner70a9883c2013-10-23 10:36:05 +110020#include "xfs_shared.h"
Dave Chinner239880e2013-10-23 10:50:10 +110021#include "xfs_format.h"
22#include "xfs_log_format.h"
23#include "xfs_trans_resv.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include "xfs_sb.h"
25#include "xfs_ag.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include "xfs_alloc.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include "xfs_quota.h"
28#include "xfs_mount.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include "xfs_bmap_btree.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include "xfs_inode.h"
Nathan Scotta844f452005-11-02 14:38:42 +110031#include "xfs_itable.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include "xfs_bmap.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "xfs_rtalloc.h"
34#include "xfs_error.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include "xfs_attr.h"
Dave Chinner239880e2013-10-23 10:50:10 +110036#include "xfs_trans.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include "xfs_buf_item.h"
38#include "xfs_trans_priv.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include "xfs_qm.h"
40
41STATIC void xfs_trans_alloc_dqinfo(xfs_trans_t *);
42
43/*
44 * Add the locked dquot to the transaction.
45 * The dquot must be locked, and it cannot be associated with any
46 * transaction.
47 */
48void
49xfs_trans_dqjoin(
50 xfs_trans_t *tp,
51 xfs_dquot_t *dqp)
52{
Christoph Hellwig191f8482010-04-20 17:01:53 +100053 ASSERT(dqp->q_transp != tp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 ASSERT(XFS_DQ_IS_LOCKED(dqp));
Christoph Hellwige98c4142010-06-23 18:11:15 +100055 ASSERT(dqp->q_logitem.qli_dquot == dqp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57 /*
58 * Get a log_item_desc to point at the new item.
59 */
Christoph Hellwige98c4142010-06-23 18:11:15 +100060 xfs_trans_add_item(tp, &dqp->q_logitem.qli_item);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62 /*
Christoph Hellwigf3ca87382011-07-08 14:34:47 +020063 * Initialize d_transp so we can later determine if this dquot is
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 * associated with this transaction.
65 */
66 dqp->q_transp = tp;
67}
68
69
70/*
71 * This is called to mark the dquot as needing
72 * to be logged when the transaction is committed. The dquot must
73 * already be associated with the given transaction.
74 * Note that it marks the entire transaction as dirty. In the ordinary
75 * case, this gets called via xfs_trans_commit, after the transaction
76 * is already dirty. However, there's nothing stop this from getting
77 * called directly, as done by xfs_qm_scall_setqlim. Hence, the TRANS_DIRTY
78 * flag.
79 */
80void
81xfs_trans_log_dquot(
82 xfs_trans_t *tp,
83 xfs_dquot_t *dqp)
84{
Christoph Hellwig191f8482010-04-20 17:01:53 +100085 ASSERT(dqp->q_transp == tp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 ASSERT(XFS_DQ_IS_LOCKED(dqp));
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 tp->t_flags |= XFS_TRANS_DIRTY;
Christoph Hellwige98c4142010-06-23 18:11:15 +100089 dqp->q_logitem.qli_item.li_desc->lid_flags |= XFS_LID_DIRTY;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
92/*
93 * Carry forward whatever is left of the quota blk reservation to
94 * the spanky new transaction
95 */
Christoph Hellwig7d095252009-06-08 15:33:32 +020096void
Linus Torvalds1da177e2005-04-16 15:20:36 -070097xfs_trans_dup_dqinfo(
98 xfs_trans_t *otp,
99 xfs_trans_t *ntp)
100{
101 xfs_dqtrx_t *oq, *nq;
102 int i,j;
103 xfs_dqtrx_t *oqa, *nqa;
104
105 if (!otp->t_dqinfo)
106 return;
107
108 xfs_trans_alloc_dqinfo(ntp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110 /*
111 * Because the quota blk reservation is carried forward,
112 * it is also necessary to carry forward the DQ_DIRTY flag.
113 */
114 if(otp->t_flags & XFS_TRANS_DQ_DIRTY)
115 ntp->t_flags |= XFS_TRANS_DQ_DIRTY;
116
Chandra Seetharaman0e6436d2013-06-27 17:25:09 -0500117 for (j = 0; j < XFS_QM_TRANS_DQTYPES; j++) {
118 oqa = otp->t_dqinfo->dqs[j];
119 nqa = ntp->t_dqinfo->dqs[j];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 for (i = 0; i < XFS_QM_TRANS_MAXDQS; i++) {
121 if (oqa[i].qt_dquot == NULL)
122 break;
123 oq = &oqa[i];
124 nq = &nqa[i];
125
126 nq->qt_dquot = oq->qt_dquot;
127 nq->qt_bcount_delta = nq->qt_icount_delta = 0;
128 nq->qt_rtbcount_delta = 0;
129
130 /*
131 * Transfer whatever is left of the reservations.
132 */
133 nq->qt_blk_res = oq->qt_blk_res - oq->qt_blk_res_used;
134 oq->qt_blk_res = oq->qt_blk_res_used;
135
136 nq->qt_rtblk_res = oq->qt_rtblk_res -
137 oq->qt_rtblk_res_used;
138 oq->qt_rtblk_res = oq->qt_rtblk_res_used;
139
140 nq->qt_ino_res = oq->qt_ino_res - oq->qt_ino_res_used;
141 oq->qt_ino_res = oq->qt_ino_res_used;
142
143 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 }
145}
146
147/*
148 * Wrap around mod_dquot to account for both user and group quotas.
149 */
Christoph Hellwig7d095252009-06-08 15:33:32 +0200150void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151xfs_trans_mod_dquot_byino(
152 xfs_trans_t *tp,
153 xfs_inode_t *ip,
154 uint field,
155 long delta)
156{
Christoph Hellwig7d095252009-06-08 15:33:32 +0200157 xfs_mount_t *mp = tp->t_mountp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Christoph Hellwig7d095252009-06-08 15:33:32 +0200159 if (!XFS_IS_QUOTA_RUNNING(mp) ||
160 !XFS_IS_QUOTA_ON(mp) ||
Chandra Seetharaman9cad19d2013-06-27 17:25:04 -0500161 xfs_is_quota_inode(&mp->m_sb, ip->i_ino))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 return;
163
164 if (tp->t_dqinfo == NULL)
165 xfs_trans_alloc_dqinfo(tp);
166
Nathan Scottc8ad20f2005-06-21 15:38:48 +1000167 if (XFS_IS_UQUOTA_ON(mp) && ip->i_udquot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 (void) xfs_trans_mod_dquot(tp, ip->i_udquot, field, delta);
Chandra Seetharaman92f8ff72013-07-11 00:00:40 -0500169 if (XFS_IS_GQUOTA_ON(mp) && ip->i_gdquot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 (void) xfs_trans_mod_dquot(tp, ip->i_gdquot, field, delta);
Chandra Seetharaman92f8ff72013-07-11 00:00:40 -0500171 if (XFS_IS_PQUOTA_ON(mp) && ip->i_pdquot)
172 (void) xfs_trans_mod_dquot(tp, ip->i_pdquot, field, delta);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173}
174
Chandra Seetharaman113a5682013-06-27 17:25:07 -0500175STATIC struct xfs_dqtrx *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176xfs_trans_get_dqtrx(
Chandra Seetharaman113a5682013-06-27 17:25:07 -0500177 struct xfs_trans *tp,
178 struct xfs_dquot *dqp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179{
Chandra Seetharaman113a5682013-06-27 17:25:07 -0500180 int i;
181 struct xfs_dqtrx *qa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Chandra Seetharaman0e6436d2013-06-27 17:25:09 -0500183 if (XFS_QM_ISUDQ(dqp))
184 qa = tp->t_dqinfo->dqs[XFS_QM_TRANS_USR];
Chandra Seetharaman92f8ff72013-07-11 00:00:40 -0500185 else if (XFS_QM_ISGDQ(dqp))
Chandra Seetharaman0e6436d2013-06-27 17:25:09 -0500186 qa = tp->t_dqinfo->dqs[XFS_QM_TRANS_GRP];
Chandra Seetharaman92f8ff72013-07-11 00:00:40 -0500187 else if (XFS_QM_ISPDQ(dqp))
188 qa = tp->t_dqinfo->dqs[XFS_QM_TRANS_PRJ];
189 else
190 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Christoph Hellwig191f8482010-04-20 17:01:53 +1000192 for (i = 0; i < XFS_QM_TRANS_MAXDQS; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 if (qa[i].qt_dquot == NULL ||
Christoph Hellwig191f8482010-04-20 17:01:53 +1000194 qa[i].qt_dquot == dqp)
195 return &qa[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 }
197
Christoph Hellwig191f8482010-04-20 17:01:53 +1000198 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199}
200
201/*
202 * Make the changes in the transaction structure.
203 * The moral equivalent to xfs_trans_mod_sb().
204 * We don't touch any fields in the dquot, so we don't care
205 * if it's locked or not (most of the time it won't be).
206 */
207void
208xfs_trans_mod_dquot(
209 xfs_trans_t *tp,
210 xfs_dquot_t *dqp,
211 uint field,
212 long delta)
213{
214 xfs_dqtrx_t *qtrx;
215
216 ASSERT(tp);
Christoph Hellwig7d095252009-06-08 15:33:32 +0200217 ASSERT(XFS_IS_QUOTA_RUNNING(tp->t_mountp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 qtrx = NULL;
219
220 if (tp->t_dqinfo == NULL)
221 xfs_trans_alloc_dqinfo(tp);
222 /*
223 * Find either the first free slot or the slot that belongs
224 * to this dquot.
225 */
226 qtrx = xfs_trans_get_dqtrx(tp, dqp);
227 ASSERT(qtrx);
228 if (qtrx->qt_dquot == NULL)
229 qtrx->qt_dquot = dqp;
230
231 switch (field) {
232
233 /*
234 * regular disk blk reservation
235 */
236 case XFS_TRANS_DQ_RES_BLKS:
237 qtrx->qt_blk_res += (ulong)delta;
238 break;
239
240 /*
241 * inode reservation
242 */
243 case XFS_TRANS_DQ_RES_INOS:
244 qtrx->qt_ino_res += (ulong)delta;
245 break;
246
247 /*
248 * disk blocks used.
249 */
250 case XFS_TRANS_DQ_BCOUNT:
251 if (qtrx->qt_blk_res && delta > 0) {
252 qtrx->qt_blk_res_used += (ulong)delta;
253 ASSERT(qtrx->qt_blk_res >= qtrx->qt_blk_res_used);
254 }
255 qtrx->qt_bcount_delta += delta;
256 break;
257
258 case XFS_TRANS_DQ_DELBCOUNT:
259 qtrx->qt_delbcnt_delta += delta;
260 break;
261
262 /*
263 * Inode Count
264 */
265 case XFS_TRANS_DQ_ICOUNT:
266 if (qtrx->qt_ino_res && delta > 0) {
267 qtrx->qt_ino_res_used += (ulong)delta;
268 ASSERT(qtrx->qt_ino_res >= qtrx->qt_ino_res_used);
269 }
270 qtrx->qt_icount_delta += delta;
271 break;
272
273 /*
274 * rtblk reservation
275 */
276 case XFS_TRANS_DQ_RES_RTBLKS:
277 qtrx->qt_rtblk_res += (ulong)delta;
278 break;
279
280 /*
281 * rtblk count
282 */
283 case XFS_TRANS_DQ_RTBCOUNT:
284 if (qtrx->qt_rtblk_res && delta > 0) {
285 qtrx->qt_rtblk_res_used += (ulong)delta;
286 ASSERT(qtrx->qt_rtblk_res >= qtrx->qt_rtblk_res_used);
287 }
288 qtrx->qt_rtbcount_delta += delta;
289 break;
290
291 case XFS_TRANS_DQ_DELRTBCOUNT:
292 qtrx->qt_delrtb_delta += delta;
293 break;
294
295 default:
296 ASSERT(0);
297 }
298 tp->t_flags |= XFS_TRANS_DQ_DIRTY;
299}
300
301
302/*
Dave Chinnerb0a9dab2013-07-10 07:04:01 +1000303 * Given an array of dqtrx structures, lock all the dquots associated and join
304 * them to the transaction, provided they have been modified. We know that the
305 * highest number of dquots of one type - usr, grp OR prj - involved in a
306 * transaction is 2 so we don't need to make this very generic.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 */
308STATIC void
309xfs_trans_dqlockedjoin(
310 xfs_trans_t *tp,
311 xfs_dqtrx_t *q)
312{
313 ASSERT(q[0].qt_dquot != NULL);
314 if (q[1].qt_dquot == NULL) {
315 xfs_dqlock(q[0].qt_dquot);
316 xfs_trans_dqjoin(tp, q[0].qt_dquot);
317 } else {
318 ASSERT(XFS_QM_TRANS_MAXDQS == 2);
319 xfs_dqlock2(q[0].qt_dquot, q[1].qt_dquot);
320 xfs_trans_dqjoin(tp, q[0].qt_dquot);
321 xfs_trans_dqjoin(tp, q[1].qt_dquot);
322 }
323}
324
325
326/*
327 * Called by xfs_trans_commit() and similar in spirit to
328 * xfs_trans_apply_sb_deltas().
329 * Go thru all the dquots belonging to this transaction and modify the
330 * INCORE dquot to reflect the actual usages.
331 * Unreserve just the reservations done by this transaction.
332 * dquot is still left locked at exit.
333 */
Christoph Hellwig7d095252009-06-08 15:33:32 +0200334void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335xfs_trans_apply_dquot_deltas(
Brian Foster4b6eae2e2013-03-18 10:51:45 -0400336 struct xfs_trans *tp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337{
338 int i, j;
Brian Foster4b6eae2e2013-03-18 10:51:45 -0400339 struct xfs_dquot *dqp;
340 struct xfs_dqtrx *qtrx, *qa;
341 struct xfs_disk_dquot *d;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 long totalbdelta;
343 long totalrtbdelta;
344
Christoph Hellwig7d095252009-06-08 15:33:32 +0200345 if (!(tp->t_flags & XFS_TRANS_DQ_DIRTY))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 return;
347
348 ASSERT(tp->t_dqinfo);
Chandra Seetharaman0e6436d2013-06-27 17:25:09 -0500349 for (j = 0; j < XFS_QM_TRANS_DQTYPES; j++) {
350 qa = tp->t_dqinfo->dqs[j];
351 if (qa[0].qt_dquot == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
354 /*
355 * Lock all of the dquots and join them to the transaction.
356 */
357 xfs_trans_dqlockedjoin(tp, qa);
358
359 for (i = 0; i < XFS_QM_TRANS_MAXDQS; i++) {
360 qtrx = &qa[i];
361 /*
362 * The array of dquots is filled
363 * sequentially, not sparsely.
364 */
365 if ((dqp = qtrx->qt_dquot) == NULL)
366 break;
367
368 ASSERT(XFS_DQ_IS_LOCKED(dqp));
Christoph Hellwig191f8482010-04-20 17:01:53 +1000369 ASSERT(dqp->q_transp == tp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
371 /*
372 * adjust the actual number of blocks used
373 */
374 d = &dqp->q_core;
375
376 /*
377 * The issue here is - sometimes we don't make a blkquota
378 * reservation intentionally to be fair to users
379 * (when the amount is small). On the other hand,
380 * delayed allocs do make reservations, but that's
381 * outside of a transaction, so we have no
382 * idea how much was really reserved.
383 * So, here we've accumulated delayed allocation blks and
384 * non-delay blks. The assumption is that the
385 * delayed ones are always reserved (outside of a
386 * transaction), and the others may or may not have
387 * quota reservations.
388 */
389 totalbdelta = qtrx->qt_bcount_delta +
390 qtrx->qt_delbcnt_delta;
391 totalrtbdelta = qtrx->qt_rtbcount_delta +
392 qtrx->qt_delrtb_delta;
Christoph Hellwigea15ab32011-07-13 13:43:50 +0200393#ifdef DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 if (totalbdelta < 0)
Christoph Hellwig1149d962005-11-02 15:01:12 +1100395 ASSERT(be64_to_cpu(d->d_bcount) >=
Christoph Hellwigea15ab32011-07-13 13:43:50 +0200396 -totalbdelta);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
398 if (totalrtbdelta < 0)
Christoph Hellwig1149d962005-11-02 15:01:12 +1100399 ASSERT(be64_to_cpu(d->d_rtbcount) >=
Christoph Hellwigea15ab32011-07-13 13:43:50 +0200400 -totalrtbdelta);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
402 if (qtrx->qt_icount_delta < 0)
Christoph Hellwig1149d962005-11-02 15:01:12 +1100403 ASSERT(be64_to_cpu(d->d_icount) >=
Christoph Hellwigea15ab32011-07-13 13:43:50 +0200404 -qtrx->qt_icount_delta);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405#endif
406 if (totalbdelta)
Marcin Slusarz413d57c2008-02-13 15:03:29 -0800407 be64_add_cpu(&d->d_bcount, (xfs_qcnt_t)totalbdelta);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409 if (qtrx->qt_icount_delta)
Marcin Slusarz413d57c2008-02-13 15:03:29 -0800410 be64_add_cpu(&d->d_icount, (xfs_qcnt_t)qtrx->qt_icount_delta);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
412 if (totalrtbdelta)
Marcin Slusarz413d57c2008-02-13 15:03:29 -0800413 be64_add_cpu(&d->d_rtbcount, (xfs_qcnt_t)totalrtbdelta);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
415 /*
416 * Get any default limits in use.
417 * Start/reset the timer(s) if needed.
418 */
419 if (d->d_id) {
Brian Foster4b6eae2e2013-03-18 10:51:45 -0400420 xfs_qm_adjust_dqlimits(tp->t_mountp, dqp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 xfs_qm_adjust_dqtimers(tp->t_mountp, d);
422 }
423
424 dqp->dq_flags |= XFS_DQ_DIRTY;
425 /*
426 * add this to the list of items to get logged
427 */
428 xfs_trans_log_dquot(tp, dqp);
429 /*
430 * Take off what's left of the original reservation.
431 * In case of delayed allocations, there's no
432 * reservation that a transaction structure knows of.
433 */
434 if (qtrx->qt_blk_res != 0) {
435 if (qtrx->qt_blk_res != qtrx->qt_blk_res_used) {
436 if (qtrx->qt_blk_res >
437 qtrx->qt_blk_res_used)
438 dqp->q_res_bcount -= (xfs_qcnt_t)
439 (qtrx->qt_blk_res -
440 qtrx->qt_blk_res_used);
441 else
442 dqp->q_res_bcount -= (xfs_qcnt_t)
443 (qtrx->qt_blk_res_used -
444 qtrx->qt_blk_res);
445 }
446 } else {
447 /*
448 * These blks were never reserved, either inside
449 * a transaction or outside one (in a delayed
450 * allocation). Also, this isn't always a
451 * negative number since we sometimes
452 * deliberately skip quota reservations.
453 */
454 if (qtrx->qt_bcount_delta) {
455 dqp->q_res_bcount +=
456 (xfs_qcnt_t)qtrx->qt_bcount_delta;
457 }
458 }
459 /*
460 * Adjust the RT reservation.
461 */
462 if (qtrx->qt_rtblk_res != 0) {
Nathan Scott06d10dd2005-06-21 15:48:47 +1000463 if (qtrx->qt_rtblk_res != qtrx->qt_rtblk_res_used) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 if (qtrx->qt_rtblk_res >
465 qtrx->qt_rtblk_res_used)
466 dqp->q_res_rtbcount -= (xfs_qcnt_t)
467 (qtrx->qt_rtblk_res -
468 qtrx->qt_rtblk_res_used);
469 else
470 dqp->q_res_rtbcount -= (xfs_qcnt_t)
471 (qtrx->qt_rtblk_res_used -
472 qtrx->qt_rtblk_res);
473 }
474 } else {
475 if (qtrx->qt_rtbcount_delta)
476 dqp->q_res_rtbcount +=
477 (xfs_qcnt_t)qtrx->qt_rtbcount_delta;
478 }
479
480 /*
481 * Adjust the inode reservation.
482 */
483 if (qtrx->qt_ino_res != 0) {
484 ASSERT(qtrx->qt_ino_res >=
485 qtrx->qt_ino_res_used);
486 if (qtrx->qt_ino_res > qtrx->qt_ino_res_used)
487 dqp->q_res_icount -= (xfs_qcnt_t)
488 (qtrx->qt_ino_res -
489 qtrx->qt_ino_res_used);
490 } else {
491 if (qtrx->qt_icount_delta)
492 dqp->q_res_icount +=
493 (xfs_qcnt_t)qtrx->qt_icount_delta;
494 }
495
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 ASSERT(dqp->q_res_bcount >=
Christoph Hellwig1149d962005-11-02 15:01:12 +1100497 be64_to_cpu(dqp->q_core.d_bcount));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 ASSERT(dqp->q_res_icount >=
Christoph Hellwig1149d962005-11-02 15:01:12 +1100499 be64_to_cpu(dqp->q_core.d_icount));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 ASSERT(dqp->q_res_rtbcount >=
Christoph Hellwig1149d962005-11-02 15:01:12 +1100501 be64_to_cpu(dqp->q_core.d_rtbcount));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 }
504}
505
506/*
507 * Release the reservations, and adjust the dquots accordingly.
508 * This is called only when the transaction is being aborted. If by
509 * any chance we have done dquot modifications incore (ie. deltas) already,
510 * we simply throw those away, since that's the expected behavior
511 * when a transaction is curtailed without a commit.
512 */
Christoph Hellwig7d095252009-06-08 15:33:32 +0200513void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514xfs_trans_unreserve_and_mod_dquots(
515 xfs_trans_t *tp)
516{
517 int i, j;
518 xfs_dquot_t *dqp;
519 xfs_dqtrx_t *qtrx, *qa;
Thiago Farina667a9292012-11-12 21:32:59 -0200520 bool locked;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
522 if (!tp->t_dqinfo || !(tp->t_flags & XFS_TRANS_DQ_DIRTY))
523 return;
524
Chandra Seetharaman0e6436d2013-06-27 17:25:09 -0500525 for (j = 0; j < XFS_QM_TRANS_DQTYPES; j++) {
526 qa = tp->t_dqinfo->dqs[j];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 for (i = 0; i < XFS_QM_TRANS_MAXDQS; i++) {
529 qtrx = &qa[i];
530 /*
531 * We assume that the array of dquots is filled
532 * sequentially, not sparsely.
533 */
534 if ((dqp = qtrx->qt_dquot) == NULL)
535 break;
536 /*
537 * Unreserve the original reservation. We don't care
538 * about the number of blocks used field, or deltas.
539 * Also we don't bother to zero the fields.
540 */
Thiago Farina667a9292012-11-12 21:32:59 -0200541 locked = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 if (qtrx->qt_blk_res) {
543 xfs_dqlock(dqp);
Thiago Farina667a9292012-11-12 21:32:59 -0200544 locked = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 dqp->q_res_bcount -=
546 (xfs_qcnt_t)qtrx->qt_blk_res;
547 }
548 if (qtrx->qt_ino_res) {
549 if (!locked) {
550 xfs_dqlock(dqp);
Thiago Farina667a9292012-11-12 21:32:59 -0200551 locked = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 }
553 dqp->q_res_icount -=
554 (xfs_qcnt_t)qtrx->qt_ino_res;
555 }
556
557 if (qtrx->qt_rtblk_res) {
558 if (!locked) {
559 xfs_dqlock(dqp);
Thiago Farina667a9292012-11-12 21:32:59 -0200560 locked = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 }
562 dqp->q_res_rtbcount -=
563 (xfs_qcnt_t)qtrx->qt_rtblk_res;
564 }
565 if (locked)
566 xfs_dqunlock(dqp);
567
568 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 }
570}
571
Christoph Hellwiga210c1a2010-01-17 22:36:19 +0000572STATIC void
573xfs_quota_warn(
574 struct xfs_mount *mp,
575 struct xfs_dquot *dqp,
576 int type)
577{
578 /* no warnings for project quotas - we just return ENOSPC later */
579 if (dqp->dq_flags & XFS_DQ_PROJ)
580 return;
Eric W. Biederman431f1972012-09-16 02:32:43 -0700581 quota_send_warning(make_kqid(&init_user_ns,
582 (dqp->dq_flags & XFS_DQ_USER) ?
583 USRQUOTA : GRPQUOTA,
584 be32_to_cpu(dqp->q_core.d_id)),
585 mp->m_super->s_dev, type);
Christoph Hellwiga210c1a2010-01-17 22:36:19 +0000586}
587
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588/*
589 * This reserves disk blocks and inodes against a dquot.
590 * Flags indicate if the dquot is to be locked here and also
591 * if the blk reservation is for RT or regular blocks.
592 * Sending in XFS_QMOPT_FORCE_RES flag skips the quota check.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 */
594STATIC int
595xfs_trans_dqresv(
596 xfs_trans_t *tp,
597 xfs_mount_t *mp,
598 xfs_dquot_t *dqp,
599 long nblks,
600 long ninos,
601 uint flags)
602{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 xfs_qcnt_t hardlimit;
604 xfs_qcnt_t softlimit;
Nathan Scott06d10dd2005-06-21 15:48:47 +1000605 time_t timer;
606 xfs_qwarncnt_t warns;
607 xfs_qwarncnt_t warnlimit;
Mitsuo Hayasaka70b54372012-02-06 12:51:05 +0000608 xfs_qcnt_t total_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 xfs_qcnt_t *resbcountp;
610 xfs_quotainfo_t *q = mp->m_quotainfo;
611
Christoph Hellwig8e9b6e72009-02-08 21:51:42 +0100612
613 xfs_dqlock(dqp);
614
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 if (flags & XFS_TRANS_DQ_RES_BLKS) {
Christoph Hellwig1149d962005-11-02 15:01:12 +1100616 hardlimit = be64_to_cpu(dqp->q_core.d_blk_hardlimit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 if (!hardlimit)
618 hardlimit = q->qi_bhardlimit;
Christoph Hellwig1149d962005-11-02 15:01:12 +1100619 softlimit = be64_to_cpu(dqp->q_core.d_blk_softlimit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 if (!softlimit)
621 softlimit = q->qi_bsoftlimit;
Christoph Hellwig1149d962005-11-02 15:01:12 +1100622 timer = be32_to_cpu(dqp->q_core.d_btimer);
623 warns = be16_to_cpu(dqp->q_core.d_bwarns);
Christoph Hellwig8a7b8a82010-04-20 17:01:30 +1000624 warnlimit = dqp->q_mount->m_quotainfo->qi_bwarnlimit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 resbcountp = &dqp->q_res_bcount;
626 } else {
627 ASSERT(flags & XFS_TRANS_DQ_RES_RTBLKS);
Christoph Hellwig1149d962005-11-02 15:01:12 +1100628 hardlimit = be64_to_cpu(dqp->q_core.d_rtb_hardlimit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 if (!hardlimit)
630 hardlimit = q->qi_rtbhardlimit;
Christoph Hellwig1149d962005-11-02 15:01:12 +1100631 softlimit = be64_to_cpu(dqp->q_core.d_rtb_softlimit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 if (!softlimit)
633 softlimit = q->qi_rtbsoftlimit;
Christoph Hellwig1149d962005-11-02 15:01:12 +1100634 timer = be32_to_cpu(dqp->q_core.d_rtbtimer);
635 warns = be16_to_cpu(dqp->q_core.d_rtbwarns);
Christoph Hellwig8a7b8a82010-04-20 17:01:30 +1000636 warnlimit = dqp->q_mount->m_quotainfo->qi_rtbwarnlimit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 resbcountp = &dqp->q_res_rtbcount;
638 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
640 if ((flags & XFS_QMOPT_FORCE_RES) == 0 &&
641 dqp->q_core.d_id &&
Kouta Ooizumie6d29422007-05-08 13:49:33 +1000642 ((XFS_IS_UQUOTA_ENFORCED(dqp->q_mount) && XFS_QM_ISUDQ(dqp)) ||
Chandra Seetharaman83e782e2013-06-27 17:25:10 -0500643 (XFS_IS_GQUOTA_ENFORCED(dqp->q_mount) && XFS_QM_ISGDQ(dqp)) ||
644 (XFS_IS_PQUOTA_ENFORCED(dqp->q_mount) && XFS_QM_ISPDQ(dqp)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 if (nblks > 0) {
646 /*
647 * dquot is locked already. See if we'd go over the
648 * hardlimit or exceed the timelimit if we allocate
649 * nblks.
650 */
Mitsuo Hayasaka70b54372012-02-06 12:51:05 +0000651 total_count = *resbcountp + nblks;
652 if (hardlimit && total_count > hardlimit) {
Christoph Hellwiga210c1a2010-01-17 22:36:19 +0000653 xfs_quota_warn(mp, dqp, QUOTA_NL_BHARDWARN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 goto error_return;
Christoph Hellwiga210c1a2010-01-17 22:36:19 +0000655 }
Mitsuo Hayasaka70b54372012-02-06 12:51:05 +0000656 if (softlimit && total_count > softlimit) {
Christoph Hellwiga210c1a2010-01-17 22:36:19 +0000657 if ((timer != 0 && get_seconds() > timer) ||
658 (warns != 0 && warns >= warnlimit)) {
659 xfs_quota_warn(mp, dqp,
660 QUOTA_NL_BSOFTLONGWARN);
661 goto error_return;
662 }
663
664 xfs_quota_warn(mp, dqp, QUOTA_NL_BSOFTWARN);
665 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 }
667 if (ninos > 0) {
Mitsuo Hayasaka70b54372012-02-06 12:51:05 +0000668 total_count = be64_to_cpu(dqp->q_core.d_icount) + ninos;
Christoph Hellwig1149d962005-11-02 15:01:12 +1100669 timer = be32_to_cpu(dqp->q_core.d_itimer);
670 warns = be16_to_cpu(dqp->q_core.d_iwarns);
Christoph Hellwig8a7b8a82010-04-20 17:01:30 +1000671 warnlimit = dqp->q_mount->m_quotainfo->qi_iwarnlimit;
Christoph Hellwig1149d962005-11-02 15:01:12 +1100672 hardlimit = be64_to_cpu(dqp->q_core.d_ino_hardlimit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 if (!hardlimit)
674 hardlimit = q->qi_ihardlimit;
Christoph Hellwig1149d962005-11-02 15:01:12 +1100675 softlimit = be64_to_cpu(dqp->q_core.d_ino_softlimit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 if (!softlimit)
677 softlimit = q->qi_isoftlimit;
Christoph Hellwig4d1f88d2010-01-13 22:05:49 +0000678
Mitsuo Hayasaka70b54372012-02-06 12:51:05 +0000679 if (hardlimit && total_count > hardlimit) {
Christoph Hellwiga210c1a2010-01-17 22:36:19 +0000680 xfs_quota_warn(mp, dqp, QUOTA_NL_IHARDWARN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 goto error_return;
Christoph Hellwiga210c1a2010-01-17 22:36:19 +0000682 }
Mitsuo Hayasaka70b54372012-02-06 12:51:05 +0000683 if (softlimit && total_count > softlimit) {
Christoph Hellwiga210c1a2010-01-17 22:36:19 +0000684 if ((timer != 0 && get_seconds() > timer) ||
685 (warns != 0 && warns >= warnlimit)) {
686 xfs_quota_warn(mp, dqp,
687 QUOTA_NL_ISOFTLONGWARN);
688 goto error_return;
689 }
690 xfs_quota_warn(mp, dqp, QUOTA_NL_ISOFTWARN);
691 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 }
693 }
694
695 /*
696 * Change the reservation, but not the actual usage.
697 * Note that q_res_bcount = q_core.d_bcount + resv
698 */
699 (*resbcountp) += (xfs_qcnt_t)nblks;
700 if (ninos != 0)
701 dqp->q_res_icount += (xfs_qcnt_t)ninos;
702
703 /*
704 * note the reservation amt in the trans struct too,
705 * so that the transaction knows how much was reserved by
706 * it against this particular dquot.
707 * We don't do this when we are reserving for a delayed allocation,
708 * because we don't have the luxury of a transaction envelope then.
709 */
710 if (tp) {
711 ASSERT(tp->t_dqinfo);
712 ASSERT(flags & XFS_QMOPT_RESBLK_MASK);
713 if (nblks != 0)
714 xfs_trans_mod_dquot(tp, dqp,
715 flags & XFS_QMOPT_RESBLK_MASK,
716 nblks);
717 if (ninos != 0)
718 xfs_trans_mod_dquot(tp, dqp,
719 XFS_TRANS_DQ_RES_INOS,
720 ninos);
721 }
Christoph Hellwig1149d962005-11-02 15:01:12 +1100722 ASSERT(dqp->q_res_bcount >= be64_to_cpu(dqp->q_core.d_bcount));
723 ASSERT(dqp->q_res_rtbcount >= be64_to_cpu(dqp->q_core.d_rtbcount));
724 ASSERT(dqp->q_res_icount >= be64_to_cpu(dqp->q_core.d_icount));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
Christoph Hellwig4d1f88d2010-01-13 22:05:49 +0000726 xfs_dqunlock(dqp);
727 return 0;
728
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729error_return:
Christoph Hellwig8e9b6e72009-02-08 21:51:42 +0100730 xfs_dqunlock(dqp);
Christoph Hellwig4d1f88d2010-01-13 22:05:49 +0000731 if (flags & XFS_QMOPT_ENOSPC)
732 return ENOSPC;
733 return EDQUOT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734}
735
736
737/*
Nathan Scott9a2a7de2006-03-31 13:04:49 +1000738 * Given dquot(s), make disk block and/or inode reservations against them.
Chandra Seetharaman92f8ff72013-07-11 00:00:40 -0500739 * The fact that this does the reservation against user, group and
740 * project quotas is important, because this follows a all-or-nothing
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 * approach.
742 *
Christoph Hellwig8e9b6e72009-02-08 21:51:42 +0100743 * flags = XFS_QMOPT_FORCE_RES evades limit enforcement. Used by chown.
Nathan Scott9a2a7de2006-03-31 13:04:49 +1000744 * XFS_QMOPT_ENOSPC returns ENOSPC not EDQUOT. Used by pquota.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 * XFS_TRANS_DQ_RES_BLKS reserves regular disk blocks
746 * XFS_TRANS_DQ_RES_RTBLKS reserves realtime disk blocks
747 * dquots are unlocked on return, if they were not locked by caller.
748 */
749int
750xfs_trans_reserve_quota_bydquots(
Chandra Seetharaman113a5682013-06-27 17:25:07 -0500751 struct xfs_trans *tp,
752 struct xfs_mount *mp,
753 struct xfs_dquot *udqp,
754 struct xfs_dquot *gdqp,
Chandra Seetharaman92f8ff72013-07-11 00:00:40 -0500755 struct xfs_dquot *pdqp,
Chandra Seetharaman113a5682013-06-27 17:25:07 -0500756 long nblks,
757 long ninos,
758 uint flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759{
Chandra Seetharaman113a5682013-06-27 17:25:07 -0500760 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
Christoph Hellwig7d095252009-06-08 15:33:32 +0200762 if (!XFS_IS_QUOTA_RUNNING(mp) || !XFS_IS_QUOTA_ON(mp))
Nathan Scott9a2a7de2006-03-31 13:04:49 +1000763 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
765 if (tp && tp->t_dqinfo == NULL)
766 xfs_trans_alloc_dqinfo(tp);
767
768 ASSERT(flags & XFS_QMOPT_RESBLK_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
770 if (udqp) {
Nathan Scott9a2a7de2006-03-31 13:04:49 +1000771 error = xfs_trans_dqresv(tp, mp, udqp, nblks, ninos,
772 (flags & ~XFS_QMOPT_ENOSPC));
773 if (error)
774 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 }
776
777 if (gdqp) {
Nathan Scott9a2a7de2006-03-31 13:04:49 +1000778 error = xfs_trans_dqresv(tp, mp, gdqp, nblks, ninos, flags);
Chandra Seetharaman113a5682013-06-27 17:25:07 -0500779 if (error)
780 goto unwind_usr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 }
782
Chandra Seetharaman92f8ff72013-07-11 00:00:40 -0500783 if (pdqp) {
784 error = xfs_trans_dqresv(tp, mp, pdqp, nblks, ninos, flags);
785 if (error)
786 goto unwind_grp;
787 }
788
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 /*
Nathan Scottc41564b2006-03-29 08:55:14 +1000790 * Didn't change anything critical, so, no need to log
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 */
Nathan Scott9a2a7de2006-03-31 13:04:49 +1000792 return 0;
Chandra Seetharaman113a5682013-06-27 17:25:07 -0500793
Chandra Seetharaman92f8ff72013-07-11 00:00:40 -0500794unwind_grp:
795 flags |= XFS_QMOPT_FORCE_RES;
796 if (gdqp)
797 xfs_trans_dqresv(tp, mp, gdqp, -nblks, -ninos, flags);
Chandra Seetharaman113a5682013-06-27 17:25:07 -0500798unwind_usr:
799 flags |= XFS_QMOPT_FORCE_RES;
800 if (udqp)
801 xfs_trans_dqresv(tp, mp, udqp, -nblks, -ninos, flags);
802 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803}
804
805
806/*
807 * Lock the dquot and change the reservation if we can.
808 * This doesn't change the actual usage, just the reservation.
809 * The inode sent in is locked.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 */
Christoph Hellwig7d095252009-06-08 15:33:32 +0200811int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812xfs_trans_reserve_quota_nblks(
Christoph Hellwig7d095252009-06-08 15:33:32 +0200813 struct xfs_trans *tp,
814 struct xfs_inode *ip,
815 long nblks,
816 long ninos,
817 uint flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818{
Christoph Hellwig7d095252009-06-08 15:33:32 +0200819 struct xfs_mount *mp = ip->i_mount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
Christoph Hellwig7d095252009-06-08 15:33:32 +0200821 if (!XFS_IS_QUOTA_RUNNING(mp) || !XFS_IS_QUOTA_ON(mp))
Nathan Scott9a2a7de2006-03-31 13:04:49 +1000822 return 0;
823 if (XFS_IS_PQUOTA_ON(mp))
824 flags |= XFS_QMOPT_ENOSPC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
Chandra Seetharaman9cad19d2013-06-27 17:25:04 -0500826 ASSERT(!xfs_is_quota_inode(&mp->m_sb, ip->i_ino));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
Christoph Hellwig579aa9c2008-04-22 17:34:00 +1000828 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
Nathan Scott9a2a7de2006-03-31 13:04:49 +1000829 ASSERT((flags & ~(XFS_QMOPT_FORCE_RES | XFS_QMOPT_ENOSPC)) ==
830 XFS_TRANS_DQ_RES_RTBLKS ||
831 (flags & ~(XFS_QMOPT_FORCE_RES | XFS_QMOPT_ENOSPC)) ==
832 XFS_TRANS_DQ_RES_BLKS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
834 /*
835 * Reserve nblks against these dquots, with trans as the mediator.
836 */
Christoph Hellwig7d095252009-06-08 15:33:32 +0200837 return xfs_trans_reserve_quota_bydquots(tp, mp,
838 ip->i_udquot, ip->i_gdquot,
Chandra Seetharaman92f8ff72013-07-11 00:00:40 -0500839 ip->i_pdquot,
Christoph Hellwig7d095252009-06-08 15:33:32 +0200840 nblks, ninos, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841}
842
843/*
844 * This routine is called to allocate a quotaoff log item.
845 */
846xfs_qoff_logitem_t *
847xfs_trans_get_qoff_item(
848 xfs_trans_t *tp,
849 xfs_qoff_logitem_t *startqoff,
850 uint flags)
851{
852 xfs_qoff_logitem_t *q;
853
854 ASSERT(tp != NULL);
855
856 q = xfs_qm_qoff_logitem_init(tp->t_mountp, startqoff, flags);
857 ASSERT(q != NULL);
858
859 /*
860 * Get a log_item_desc to point at the new item.
861 */
Christoph Hellwige98c4142010-06-23 18:11:15 +1000862 xfs_trans_add_item(tp, &q->qql_item);
863 return q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864}
865
866
867/*
868 * This is called to mark the quotaoff logitem as needing
869 * to be logged when the transaction is committed. The logitem must
870 * already be associated with the given transaction.
871 */
872void
873xfs_trans_log_quotaoff_item(
874 xfs_trans_t *tp,
875 xfs_qoff_logitem_t *qlp)
876{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 tp->t_flags |= XFS_TRANS_DIRTY;
Christoph Hellwige98c4142010-06-23 18:11:15 +1000878 qlp->qql_item.li_desc->lid_flags |= XFS_LID_DIRTY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879}
880
881STATIC void
882xfs_trans_alloc_dqinfo(
883 xfs_trans_t *tp)
884{
Christoph Hellwiga05931c2012-03-13 08:52:37 +0000885 tp->t_dqinfo = kmem_zone_zalloc(xfs_qm_dqtrxzone, KM_SLEEP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886}
887
Christoph Hellwig7d095252009-06-08 15:33:32 +0200888void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889xfs_trans_free_dqinfo(
890 xfs_trans_t *tp)
891{
892 if (!tp->t_dqinfo)
893 return;
Christoph Hellwiga05931c2012-03-13 08:52:37 +0000894 kmem_zone_free(xfs_qm_dqtrxzone, tp->t_dqinfo);
Christoph Hellwig7d095252009-06-08 15:33:32 +0200895 tp->t_dqinfo = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896}