]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - fs/xfs/xfs_trans_dquot.c
2 * Copyright (c) 2000-2002 Silicon Graphics, Inc.
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
7 * published by the Free Software Foundation.
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.
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
20 #include "xfs_format.h"
21 #include "xfs_shared.h"
23 #include "xfs_trans.h"
26 #include "xfs_alloc.h"
27 #include "xfs_quota.h"
28 #include "xfs_mount.h"
29 #include "xfs_bmap_btree.h"
30 #include "xfs_inode.h"
31 #include "xfs_itable.h"
33 #include "xfs_rtalloc.h"
34 #include "xfs_error.h"
36 #include "xfs_buf_item.h"
37 #include "xfs_trans_priv.h"
40 STATIC
void xfs_trans_alloc_dqinfo(xfs_trans_t
*);
43 * Add the locked dquot to the transaction.
44 * The dquot must be locked, and it cannot be associated with any
52 ASSERT(dqp
->q_transp
!= tp
);
53 ASSERT(XFS_DQ_IS_LOCKED(dqp
));
54 ASSERT(dqp
->q_logitem
.qli_dquot
== dqp
);
57 * Get a log_item_desc to point at the new item.
59 xfs_trans_add_item(tp
, &dqp
->q_logitem
.qli_item
);
62 * Initialize d_transp so we can later determine if this dquot is
63 * associated with this transaction.
70 * This is called to mark the dquot as needing
71 * to be logged when the transaction is committed. The dquot must
72 * already be associated with the given transaction.
73 * Note that it marks the entire transaction as dirty. In the ordinary
74 * case, this gets called via xfs_trans_commit, after the transaction
75 * is already dirty. However, there's nothing stop this from getting
76 * called directly, as done by xfs_qm_scall_setqlim. Hence, the TRANS_DIRTY
84 ASSERT(dqp
->q_transp
== tp
);
85 ASSERT(XFS_DQ_IS_LOCKED(dqp
));
87 tp
->t_flags
|= XFS_TRANS_DIRTY
;
88 dqp
->q_logitem
.qli_item
.li_desc
->lid_flags
|= XFS_LID_DIRTY
;
92 * Carry forward whatever is left of the quota blk reservation to
93 * the spanky new transaction
100 xfs_dqtrx_t
*oq
, *nq
;
102 xfs_dqtrx_t
*oqa
, *nqa
;
107 xfs_trans_alloc_dqinfo(ntp
);
110 * Because the quota blk reservation is carried forward,
111 * it is also necessary to carry forward the DQ_DIRTY flag.
113 if(otp
->t_flags
& XFS_TRANS_DQ_DIRTY
)
114 ntp
->t_flags
|= XFS_TRANS_DQ_DIRTY
;
116 for (j
= 0; j
< XFS_QM_TRANS_DQTYPES
; j
++) {
117 oqa
= otp
->t_dqinfo
->dqs
[j
];
118 nqa
= ntp
->t_dqinfo
->dqs
[j
];
119 for (i
= 0; i
< XFS_QM_TRANS_MAXDQS
; i
++) {
120 if (oqa
[i
].qt_dquot
== NULL
)
125 nq
->qt_dquot
= oq
->qt_dquot
;
126 nq
->qt_bcount_delta
= nq
->qt_icount_delta
= 0;
127 nq
->qt_rtbcount_delta
= 0;
130 * Transfer whatever is left of the reservations.
132 nq
->qt_blk_res
= oq
->qt_blk_res
- oq
->qt_blk_res_used
;
133 oq
->qt_blk_res
= oq
->qt_blk_res_used
;
135 nq
->qt_rtblk_res
= oq
->qt_rtblk_res
-
136 oq
->qt_rtblk_res_used
;
137 oq
->qt_rtblk_res
= oq
->qt_rtblk_res_used
;
139 nq
->qt_ino_res
= oq
->qt_ino_res
- oq
->qt_ino_res_used
;
140 oq
->qt_ino_res
= oq
->qt_ino_res_used
;
147 * Wrap around mod_dquot to account for both user and group quotas.
150 xfs_trans_mod_dquot_byino(
156 xfs_mount_t
*mp
= tp
->t_mountp
;
158 if (!XFS_IS_QUOTA_RUNNING(mp
) ||
159 !XFS_IS_QUOTA_ON(mp
) ||
160 xfs_is_quota_inode(&mp
->m_sb
, ip
->i_ino
))
163 if (tp
->t_dqinfo
== NULL
)
164 xfs_trans_alloc_dqinfo(tp
);
166 if (XFS_IS_UQUOTA_ON(mp
) && ip
->i_udquot
)
167 (void) xfs_trans_mod_dquot(tp
, ip
->i_udquot
, field
, delta
);
168 if (XFS_IS_GQUOTA_ON(mp
) && ip
->i_gdquot
)
169 (void) xfs_trans_mod_dquot(tp
, ip
->i_gdquot
, field
, delta
);
170 if (XFS_IS_PQUOTA_ON(mp
) && ip
->i_pdquot
)
171 (void) xfs_trans_mod_dquot(tp
, ip
->i_pdquot
, field
, delta
);
174 STATIC
struct xfs_dqtrx
*
176 struct xfs_trans
*tp
,
177 struct xfs_dquot
*dqp
)
180 struct xfs_dqtrx
*qa
;
182 if (XFS_QM_ISUDQ(dqp
))
183 qa
= tp
->t_dqinfo
->dqs
[XFS_QM_TRANS_USR
];
184 else if (XFS_QM_ISGDQ(dqp
))
185 qa
= tp
->t_dqinfo
->dqs
[XFS_QM_TRANS_GRP
];
186 else if (XFS_QM_ISPDQ(dqp
))
187 qa
= tp
->t_dqinfo
->dqs
[XFS_QM_TRANS_PRJ
];
191 for (i
= 0; i
< XFS_QM_TRANS_MAXDQS
; i
++) {
192 if (qa
[i
].qt_dquot
== NULL
||
193 qa
[i
].qt_dquot
== dqp
)
201 * Make the changes in the transaction structure.
202 * The moral equivalent to xfs_trans_mod_sb().
203 * We don't touch any fields in the dquot, so we don't care
204 * if it's locked or not (most of the time it won't be).
216 ASSERT(XFS_IS_QUOTA_RUNNING(tp
->t_mountp
));
219 if (tp
->t_dqinfo
== NULL
)
220 xfs_trans_alloc_dqinfo(tp
);
222 * Find either the first free slot or the slot that belongs
225 qtrx
= xfs_trans_get_dqtrx(tp
, dqp
);
227 if (qtrx
->qt_dquot
== NULL
)
228 qtrx
->qt_dquot
= dqp
;
233 * regular disk blk reservation
235 case XFS_TRANS_DQ_RES_BLKS
:
236 qtrx
->qt_blk_res
+= (ulong
)delta
;
242 case XFS_TRANS_DQ_RES_INOS
:
243 qtrx
->qt_ino_res
+= (ulong
)delta
;
249 case XFS_TRANS_DQ_BCOUNT
:
250 if (qtrx
->qt_blk_res
&& delta
> 0) {
251 qtrx
->qt_blk_res_used
+= (ulong
)delta
;
252 ASSERT(qtrx
->qt_blk_res
>= qtrx
->qt_blk_res_used
);
254 qtrx
->qt_bcount_delta
+= delta
;
257 case XFS_TRANS_DQ_DELBCOUNT
:
258 qtrx
->qt_delbcnt_delta
+= delta
;
264 case XFS_TRANS_DQ_ICOUNT
:
265 if (qtrx
->qt_ino_res
&& delta
> 0) {
266 qtrx
->qt_ino_res_used
+= (ulong
)delta
;
267 ASSERT(qtrx
->qt_ino_res
>= qtrx
->qt_ino_res_used
);
269 qtrx
->qt_icount_delta
+= delta
;
275 case XFS_TRANS_DQ_RES_RTBLKS
:
276 qtrx
->qt_rtblk_res
+= (ulong
)delta
;
282 case XFS_TRANS_DQ_RTBCOUNT
:
283 if (qtrx
->qt_rtblk_res
&& delta
> 0) {
284 qtrx
->qt_rtblk_res_used
+= (ulong
)delta
;
285 ASSERT(qtrx
->qt_rtblk_res
>= qtrx
->qt_rtblk_res_used
);
287 qtrx
->qt_rtbcount_delta
+= delta
;
290 case XFS_TRANS_DQ_DELRTBCOUNT
:
291 qtrx
->qt_delrtb_delta
+= delta
;
297 tp
->t_flags
|= XFS_TRANS_DQ_DIRTY
;
302 * Given an array of dqtrx structures, lock all the dquots associated and join
303 * them to the transaction, provided they have been modified. We know that the
304 * highest number of dquots of one type - usr, grp OR prj - involved in a
305 * transaction is 2 so we don't need to make this very generic.
308 xfs_trans_dqlockedjoin(
312 ASSERT(q
[0].qt_dquot
!= NULL
);
313 if (q
[1].qt_dquot
== NULL
) {
314 xfs_dqlock(q
[0].qt_dquot
);
315 xfs_trans_dqjoin(tp
, q
[0].qt_dquot
);
317 ASSERT(XFS_QM_TRANS_MAXDQS
== 2);
318 xfs_dqlock2(q
[0].qt_dquot
, q
[1].qt_dquot
);
319 xfs_trans_dqjoin(tp
, q
[0].qt_dquot
);
320 xfs_trans_dqjoin(tp
, q
[1].qt_dquot
);
326 * Called by xfs_trans_commit() and similar in spirit to
327 * xfs_trans_apply_sb_deltas().
328 * Go thru all the dquots belonging to this transaction and modify the
329 * INCORE dquot to reflect the actual usages.
330 * Unreserve just the reservations done by this transaction.
331 * dquot is still left locked at exit.
334 xfs_trans_apply_dquot_deltas(
335 struct xfs_trans
*tp
)
338 struct xfs_dquot
*dqp
;
339 struct xfs_dqtrx
*qtrx
, *qa
;
340 struct xfs_disk_dquot
*d
;
344 if (!(tp
->t_flags
& XFS_TRANS_DQ_DIRTY
))
347 ASSERT(tp
->t_dqinfo
);
348 for (j
= 0; j
< XFS_QM_TRANS_DQTYPES
; j
++) {
349 qa
= tp
->t_dqinfo
->dqs
[j
];
350 if (qa
[0].qt_dquot
== NULL
)
354 * Lock all of the dquots and join them to the transaction.
356 xfs_trans_dqlockedjoin(tp
, qa
);
358 for (i
= 0; i
< XFS_QM_TRANS_MAXDQS
; i
++) {
361 * The array of dquots is filled
362 * sequentially, not sparsely.
364 if ((dqp
= qtrx
->qt_dquot
) == NULL
)
367 ASSERT(XFS_DQ_IS_LOCKED(dqp
));
368 ASSERT(dqp
->q_transp
== tp
);
371 * adjust the actual number of blocks used
376 * The issue here is - sometimes we don't make a blkquota
377 * reservation intentionally to be fair to users
378 * (when the amount is small). On the other hand,
379 * delayed allocs do make reservations, but that's
380 * outside of a transaction, so we have no
381 * idea how much was really reserved.
382 * So, here we've accumulated delayed allocation blks and
383 * non-delay blks. The assumption is that the
384 * delayed ones are always reserved (outside of a
385 * transaction), and the others may or may not have
386 * quota reservations.
388 totalbdelta
= qtrx
->qt_bcount_delta
+
389 qtrx
->qt_delbcnt_delta
;
390 totalrtbdelta
= qtrx
->qt_rtbcount_delta
+
391 qtrx
->qt_delrtb_delta
;
394 ASSERT(be64_to_cpu(d
->d_bcount
) >=
397 if (totalrtbdelta
< 0)
398 ASSERT(be64_to_cpu(d
->d_rtbcount
) >=
401 if (qtrx
->qt_icount_delta
< 0)
402 ASSERT(be64_to_cpu(d
->d_icount
) >=
403 -qtrx
->qt_icount_delta
);
406 be64_add_cpu(&d
->d_bcount
, (xfs_qcnt_t
)totalbdelta
);
408 if (qtrx
->qt_icount_delta
)
409 be64_add_cpu(&d
->d_icount
, (xfs_qcnt_t
)qtrx
->qt_icount_delta
);
412 be64_add_cpu(&d
->d_rtbcount
, (xfs_qcnt_t
)totalrtbdelta
);
415 * Get any default limits in use.
416 * Start/reset the timer(s) if needed.
419 xfs_qm_adjust_dqlimits(tp
->t_mountp
, dqp
);
420 xfs_qm_adjust_dqtimers(tp
->t_mountp
, d
);
423 dqp
->dq_flags
|= XFS_DQ_DIRTY
;
425 * add this to the list of items to get logged
427 xfs_trans_log_dquot(tp
, dqp
);
429 * Take off what's left of the original reservation.
430 * In case of delayed allocations, there's no
431 * reservation that a transaction structure knows of.
433 if (qtrx
->qt_blk_res
!= 0) {
434 if (qtrx
->qt_blk_res
!= qtrx
->qt_blk_res_used
) {
435 if (qtrx
->qt_blk_res
>
436 qtrx
->qt_blk_res_used
)
437 dqp
->q_res_bcount
-= (xfs_qcnt_t
)
439 qtrx
->qt_blk_res_used
);
441 dqp
->q_res_bcount
-= (xfs_qcnt_t
)
442 (qtrx
->qt_blk_res_used
-
447 * These blks were never reserved, either inside
448 * a transaction or outside one (in a delayed
449 * allocation). Also, this isn't always a
450 * negative number since we sometimes
451 * deliberately skip quota reservations.
453 if (qtrx
->qt_bcount_delta
) {
455 (xfs_qcnt_t
)qtrx
->qt_bcount_delta
;
459 * Adjust the RT reservation.
461 if (qtrx
->qt_rtblk_res
!= 0) {
462 if (qtrx
->qt_rtblk_res
!= qtrx
->qt_rtblk_res_used
) {
463 if (qtrx
->qt_rtblk_res
>
464 qtrx
->qt_rtblk_res_used
)
465 dqp
->q_res_rtbcount
-= (xfs_qcnt_t
)
466 (qtrx
->qt_rtblk_res
-
467 qtrx
->qt_rtblk_res_used
);
469 dqp
->q_res_rtbcount
-= (xfs_qcnt_t
)
470 (qtrx
->qt_rtblk_res_used
-
474 if (qtrx
->qt_rtbcount_delta
)
475 dqp
->q_res_rtbcount
+=
476 (xfs_qcnt_t
)qtrx
->qt_rtbcount_delta
;
480 * Adjust the inode reservation.
482 if (qtrx
->qt_ino_res
!= 0) {
483 ASSERT(qtrx
->qt_ino_res
>=
484 qtrx
->qt_ino_res_used
);
485 if (qtrx
->qt_ino_res
> qtrx
->qt_ino_res_used
)
486 dqp
->q_res_icount
-= (xfs_qcnt_t
)
488 qtrx
->qt_ino_res_used
);
490 if (qtrx
->qt_icount_delta
)
492 (xfs_qcnt_t
)qtrx
->qt_icount_delta
;
495 ASSERT(dqp
->q_res_bcount
>=
496 be64_to_cpu(dqp
->q_core
.d_bcount
));
497 ASSERT(dqp
->q_res_icount
>=
498 be64_to_cpu(dqp
->q_core
.d_icount
));
499 ASSERT(dqp
->q_res_rtbcount
>=
500 be64_to_cpu(dqp
->q_core
.d_rtbcount
));
506 * Release the reservations, and adjust the dquots accordingly.
507 * This is called only when the transaction is being aborted. If by
508 * any chance we have done dquot modifications incore (ie. deltas) already,
509 * we simply throw those away, since that's the expected behavior
510 * when a transaction is curtailed without a commit.
513 xfs_trans_unreserve_and_mod_dquots(
518 xfs_dqtrx_t
*qtrx
, *qa
;
521 if (!tp
->t_dqinfo
|| !(tp
->t_flags
& XFS_TRANS_DQ_DIRTY
))
524 for (j
= 0; j
< XFS_QM_TRANS_DQTYPES
; j
++) {
525 qa
= tp
->t_dqinfo
->dqs
[j
];
527 for (i
= 0; i
< XFS_QM_TRANS_MAXDQS
; i
++) {
530 * We assume that the array of dquots is filled
531 * sequentially, not sparsely.
533 if ((dqp
= qtrx
->qt_dquot
) == NULL
)
536 * Unreserve the original reservation. We don't care
537 * about the number of blocks used field, or deltas.
538 * Also we don't bother to zero the fields.
541 if (qtrx
->qt_blk_res
) {
545 (xfs_qcnt_t
)qtrx
->qt_blk_res
;
547 if (qtrx
->qt_ino_res
) {
553 (xfs_qcnt_t
)qtrx
->qt_ino_res
;
556 if (qtrx
->qt_rtblk_res
) {
561 dqp
->q_res_rtbcount
-=
562 (xfs_qcnt_t
)qtrx
->qt_rtblk_res
;
573 struct xfs_mount
*mp
,
574 struct xfs_dquot
*dqp
,
577 /* no warnings for project quotas - we just return ENOSPC later */
578 if (dqp
->dq_flags
& XFS_DQ_PROJ
)
580 quota_send_warning(make_kqid(&init_user_ns
,
581 (dqp
->dq_flags
& XFS_DQ_USER
) ?
583 be32_to_cpu(dqp
->q_core
.d_id
)),
584 mp
->m_super
->s_dev
, type
);
588 * This reserves disk blocks and inodes against a dquot.
589 * Flags indicate if the dquot is to be locked here and also
590 * if the blk reservation is for RT or regular blocks.
591 * Sending in XFS_QMOPT_FORCE_RES flag skips the quota check.
602 xfs_qcnt_t hardlimit
;
603 xfs_qcnt_t softlimit
;
605 xfs_qwarncnt_t warns
;
606 xfs_qwarncnt_t warnlimit
;
607 xfs_qcnt_t total_count
;
608 xfs_qcnt_t
*resbcountp
;
609 xfs_quotainfo_t
*q
= mp
->m_quotainfo
;
614 if (flags
& XFS_TRANS_DQ_RES_BLKS
) {
615 hardlimit
= be64_to_cpu(dqp
->q_core
.d_blk_hardlimit
);
617 hardlimit
= q
->qi_bhardlimit
;
618 softlimit
= be64_to_cpu(dqp
->q_core
.d_blk_softlimit
);
620 softlimit
= q
->qi_bsoftlimit
;
621 timer
= be32_to_cpu(dqp
->q_core
.d_btimer
);
622 warns
= be16_to_cpu(dqp
->q_core
.d_bwarns
);
623 warnlimit
= dqp
->q_mount
->m_quotainfo
->qi_bwarnlimit
;
624 resbcountp
= &dqp
->q_res_bcount
;
626 ASSERT(flags
& XFS_TRANS_DQ_RES_RTBLKS
);
627 hardlimit
= be64_to_cpu(dqp
->q_core
.d_rtb_hardlimit
);
629 hardlimit
= q
->qi_rtbhardlimit
;
630 softlimit
= be64_to_cpu(dqp
->q_core
.d_rtb_softlimit
);
632 softlimit
= q
->qi_rtbsoftlimit
;
633 timer
= be32_to_cpu(dqp
->q_core
.d_rtbtimer
);
634 warns
= be16_to_cpu(dqp
->q_core
.d_rtbwarns
);
635 warnlimit
= dqp
->q_mount
->m_quotainfo
->qi_rtbwarnlimit
;
636 resbcountp
= &dqp
->q_res_rtbcount
;
639 if ((flags
& XFS_QMOPT_FORCE_RES
) == 0 &&
641 ((XFS_IS_UQUOTA_ENFORCED(dqp
->q_mount
) && XFS_QM_ISUDQ(dqp
)) ||
642 (XFS_IS_GQUOTA_ENFORCED(dqp
->q_mount
) && XFS_QM_ISGDQ(dqp
)) ||
643 (XFS_IS_PQUOTA_ENFORCED(dqp
->q_mount
) && XFS_QM_ISPDQ(dqp
)))) {
646 * dquot is locked already. See if we'd go over the
647 * hardlimit or exceed the timelimit if we allocate
650 total_count
= *resbcountp
+ nblks
;
651 if (hardlimit
&& total_count
> hardlimit
) {
652 xfs_quota_warn(mp
, dqp
, QUOTA_NL_BHARDWARN
);
655 if (softlimit
&& total_count
> softlimit
) {
656 if ((timer
!= 0 && get_seconds() > timer
) ||
657 (warns
!= 0 && warns
>= warnlimit
)) {
658 xfs_quota_warn(mp
, dqp
,
659 QUOTA_NL_BSOFTLONGWARN
);
663 xfs_quota_warn(mp
, dqp
, QUOTA_NL_BSOFTWARN
);
667 total_count
= be64_to_cpu(dqp
->q_core
.d_icount
) + ninos
;
668 timer
= be32_to_cpu(dqp
->q_core
.d_itimer
);
669 warns
= be16_to_cpu(dqp
->q_core
.d_iwarns
);
670 warnlimit
= dqp
->q_mount
->m_quotainfo
->qi_iwarnlimit
;
671 hardlimit
= be64_to_cpu(dqp
->q_core
.d_ino_hardlimit
);
673 hardlimit
= q
->qi_ihardlimit
;
674 softlimit
= be64_to_cpu(dqp
->q_core
.d_ino_softlimit
);
676 softlimit
= q
->qi_isoftlimit
;
678 if (hardlimit
&& total_count
> hardlimit
) {
679 xfs_quota_warn(mp
, dqp
, QUOTA_NL_IHARDWARN
);
682 if (softlimit
&& total_count
> softlimit
) {
683 if ((timer
!= 0 && get_seconds() > timer
) ||
684 (warns
!= 0 && warns
>= warnlimit
)) {
685 xfs_quota_warn(mp
, dqp
,
686 QUOTA_NL_ISOFTLONGWARN
);
689 xfs_quota_warn(mp
, dqp
, QUOTA_NL_ISOFTWARN
);
695 * Change the reservation, but not the actual usage.
696 * Note that q_res_bcount = q_core.d_bcount + resv
698 (*resbcountp
) += (xfs_qcnt_t
)nblks
;
700 dqp
->q_res_icount
+= (xfs_qcnt_t
)ninos
;
703 * note the reservation amt in the trans struct too,
704 * so that the transaction knows how much was reserved by
705 * it against this particular dquot.
706 * We don't do this when we are reserving for a delayed allocation,
707 * because we don't have the luxury of a transaction envelope then.
710 ASSERT(tp
->t_dqinfo
);
711 ASSERT(flags
& XFS_QMOPT_RESBLK_MASK
);
713 xfs_trans_mod_dquot(tp
, dqp
,
714 flags
& XFS_QMOPT_RESBLK_MASK
,
717 xfs_trans_mod_dquot(tp
, dqp
,
718 XFS_TRANS_DQ_RES_INOS
,
721 ASSERT(dqp
->q_res_bcount
>= be64_to_cpu(dqp
->q_core
.d_bcount
));
722 ASSERT(dqp
->q_res_rtbcount
>= be64_to_cpu(dqp
->q_core
.d_rtbcount
));
723 ASSERT(dqp
->q_res_icount
>= be64_to_cpu(dqp
->q_core
.d_icount
));
730 if (flags
& XFS_QMOPT_ENOSPC
)
737 * Given dquot(s), make disk block and/or inode reservations against them.
738 * The fact that this does the reservation against user, group and
739 * project quotas is important, because this follows a all-or-nothing
742 * flags = XFS_QMOPT_FORCE_RES evades limit enforcement. Used by chown.
743 * XFS_QMOPT_ENOSPC returns ENOSPC not EDQUOT. Used by pquota.
744 * XFS_TRANS_DQ_RES_BLKS reserves regular disk blocks
745 * XFS_TRANS_DQ_RES_RTBLKS reserves realtime disk blocks
746 * dquots are unlocked on return, if they were not locked by caller.
749 xfs_trans_reserve_quota_bydquots(
750 struct xfs_trans
*tp
,
751 struct xfs_mount
*mp
,
752 struct xfs_dquot
*udqp
,
753 struct xfs_dquot
*gdqp
,
754 struct xfs_dquot
*pdqp
,
761 if (!XFS_IS_QUOTA_RUNNING(mp
) || !XFS_IS_QUOTA_ON(mp
))
764 if (tp
&& tp
->t_dqinfo
== NULL
)
765 xfs_trans_alloc_dqinfo(tp
);
767 ASSERT(flags
& XFS_QMOPT_RESBLK_MASK
);
770 error
= xfs_trans_dqresv(tp
, mp
, udqp
, nblks
, ninos
,
771 (flags
& ~XFS_QMOPT_ENOSPC
));
777 error
= xfs_trans_dqresv(tp
, mp
, gdqp
, nblks
, ninos
, flags
);
783 error
= xfs_trans_dqresv(tp
, mp
, pdqp
, nblks
, ninos
, flags
);
789 * Didn't change anything critical, so, no need to log
794 flags
|= XFS_QMOPT_FORCE_RES
;
796 xfs_trans_dqresv(tp
, mp
, gdqp
, -nblks
, -ninos
, flags
);
798 flags
|= XFS_QMOPT_FORCE_RES
;
800 xfs_trans_dqresv(tp
, mp
, udqp
, -nblks
, -ninos
, flags
);
806 * Lock the dquot and change the reservation if we can.
807 * This doesn't change the actual usage, just the reservation.
808 * The inode sent in is locked.
811 xfs_trans_reserve_quota_nblks(
812 struct xfs_trans
*tp
,
813 struct xfs_inode
*ip
,
818 struct xfs_mount
*mp
= ip
->i_mount
;
820 if (!XFS_IS_QUOTA_RUNNING(mp
) || !XFS_IS_QUOTA_ON(mp
))
822 if (XFS_IS_PQUOTA_ON(mp
))
823 flags
|= XFS_QMOPT_ENOSPC
;
825 ASSERT(!xfs_is_quota_inode(&mp
->m_sb
, ip
->i_ino
));
827 ASSERT(xfs_isilocked(ip
, XFS_ILOCK_EXCL
));
828 ASSERT((flags
& ~(XFS_QMOPT_FORCE_RES
| XFS_QMOPT_ENOSPC
)) ==
829 XFS_TRANS_DQ_RES_RTBLKS
||
830 (flags
& ~(XFS_QMOPT_FORCE_RES
| XFS_QMOPT_ENOSPC
)) ==
831 XFS_TRANS_DQ_RES_BLKS
);
834 * Reserve nblks against these dquots, with trans as the mediator.
836 return xfs_trans_reserve_quota_bydquots(tp
, mp
,
837 ip
->i_udquot
, ip
->i_gdquot
,
839 nblks
, ninos
, flags
);
843 * This routine is called to allocate a quotaoff log item.
846 xfs_trans_get_qoff_item(
848 xfs_qoff_logitem_t
*startqoff
,
851 xfs_qoff_logitem_t
*q
;
855 q
= xfs_qm_qoff_logitem_init(tp
->t_mountp
, startqoff
, flags
);
859 * Get a log_item_desc to point at the new item.
861 xfs_trans_add_item(tp
, &q
->qql_item
);
867 * This is called to mark the quotaoff logitem as needing
868 * to be logged when the transaction is committed. The logitem must
869 * already be associated with the given transaction.
872 xfs_trans_log_quotaoff_item(
874 xfs_qoff_logitem_t
*qlp
)
876 tp
->t_flags
|= XFS_TRANS_DIRTY
;
877 qlp
->qql_item
.li_desc
->lid_flags
|= XFS_LID_DIRTY
;
881 xfs_trans_alloc_dqinfo(
884 tp
->t_dqinfo
= kmem_zone_zalloc(xfs_qm_dqtrxzone
, KM_SLEEP
);
888 xfs_trans_free_dqinfo(
893 kmem_zone_free(xfs_qm_dqtrxzone
, tp
->t_dqinfo
);