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
23 #include "xfs_trans.h"
27 #include "xfs_alloc.h"
28 #include "xfs_dmapi.h"
29 #include "xfs_quota.h"
30 #include "xfs_mount.h"
31 #include "xfs_bmap_btree.h"
32 #include "xfs_alloc_btree.h"
33 #include "xfs_ialloc_btree.h"
34 #include "xfs_attr_sf.h"
35 #include "xfs_dir2_sf.h"
36 #include "xfs_dinode.h"
37 #include "xfs_inode.h"
38 #include "xfs_ialloc.h"
39 #include "xfs_itable.h"
40 #include "xfs_btree.h"
42 #include "xfs_rtalloc.h"
43 #include "xfs_error.h"
46 #include "xfs_buf_item.h"
47 #include "xfs_trans_priv.h"
50 STATIC
void xfs_trans_alloc_dqinfo(xfs_trans_t
*);
53 * Add the locked dquot to the transaction.
54 * The dquot must be locked, and it cannot be associated with any
62 xfs_dq_logitem_t
*lp
= &dqp
->q_logitem
;
64 ASSERT(dqp
->q_transp
!= tp
);
65 ASSERT(XFS_DQ_IS_LOCKED(dqp
));
66 ASSERT(lp
->qli_dquot
== dqp
);
69 * Get a log_item_desc to point at the new item.
71 (void) xfs_trans_add_item(tp
, (xfs_log_item_t
*)(lp
));
74 * Initialize i_transp so we can later determine if this dquot is
75 * associated with this transaction.
82 * This is called to mark the dquot as needing
83 * to be logged when the transaction is committed. The dquot must
84 * already be associated with the given transaction.
85 * Note that it marks the entire transaction as dirty. In the ordinary
86 * case, this gets called via xfs_trans_commit, after the transaction
87 * is already dirty. However, there's nothing stop this from getting
88 * called directly, as done by xfs_qm_scall_setqlim. Hence, the TRANS_DIRTY
96 xfs_log_item_desc_t
*lidp
;
98 ASSERT(dqp
->q_transp
== tp
);
99 ASSERT(XFS_DQ_IS_LOCKED(dqp
));
101 lidp
= xfs_trans_find_item(tp
, (xfs_log_item_t
*)(&dqp
->q_logitem
));
102 ASSERT(lidp
!= NULL
);
104 tp
->t_flags
|= XFS_TRANS_DIRTY
;
105 lidp
->lid_flags
|= XFS_LID_DIRTY
;
109 * Carry forward whatever is left of the quota blk reservation to
110 * the spanky new transaction
113 xfs_trans_dup_dqinfo(
117 xfs_dqtrx_t
*oq
, *nq
;
119 xfs_dqtrx_t
*oqa
, *nqa
;
124 xfs_trans_alloc_dqinfo(ntp
);
125 oqa
= otp
->t_dqinfo
->dqa_usrdquots
;
126 nqa
= ntp
->t_dqinfo
->dqa_usrdquots
;
129 * Because the quota blk reservation is carried forward,
130 * it is also necessary to carry forward the DQ_DIRTY flag.
132 if(otp
->t_flags
& XFS_TRANS_DQ_DIRTY
)
133 ntp
->t_flags
|= XFS_TRANS_DQ_DIRTY
;
135 for (j
= 0; j
< 2; j
++) {
136 for (i
= 0; i
< XFS_QM_TRANS_MAXDQS
; i
++) {
137 if (oqa
[i
].qt_dquot
== NULL
)
142 nq
->qt_dquot
= oq
->qt_dquot
;
143 nq
->qt_bcount_delta
= nq
->qt_icount_delta
= 0;
144 nq
->qt_rtbcount_delta
= 0;
147 * Transfer whatever is left of the reservations.
149 nq
->qt_blk_res
= oq
->qt_blk_res
- oq
->qt_blk_res_used
;
150 oq
->qt_blk_res
= oq
->qt_blk_res_used
;
152 nq
->qt_rtblk_res
= oq
->qt_rtblk_res
-
153 oq
->qt_rtblk_res_used
;
154 oq
->qt_rtblk_res
= oq
->qt_rtblk_res_used
;
156 nq
->qt_ino_res
= oq
->qt_ino_res
- oq
->qt_ino_res_used
;
157 oq
->qt_ino_res
= oq
->qt_ino_res_used
;
160 oqa
= otp
->t_dqinfo
->dqa_grpdquots
;
161 nqa
= ntp
->t_dqinfo
->dqa_grpdquots
;
166 * Wrap around mod_dquot to account for both user and group quotas.
169 xfs_trans_mod_dquot_byino(
175 xfs_mount_t
*mp
= tp
->t_mountp
;
177 if (!XFS_IS_QUOTA_RUNNING(mp
) ||
178 !XFS_IS_QUOTA_ON(mp
) ||
179 ip
->i_ino
== mp
->m_sb
.sb_uquotino
||
180 ip
->i_ino
== mp
->m_sb
.sb_gquotino
)
183 if (tp
->t_dqinfo
== NULL
)
184 xfs_trans_alloc_dqinfo(tp
);
186 if (XFS_IS_UQUOTA_ON(mp
) && ip
->i_udquot
)
187 (void) xfs_trans_mod_dquot(tp
, ip
->i_udquot
, field
, delta
);
188 if (XFS_IS_OQUOTA_ON(mp
) && ip
->i_gdquot
)
189 (void) xfs_trans_mod_dquot(tp
, ip
->i_gdquot
, field
, delta
);
200 qa
= XFS_QM_ISUDQ(dqp
) ?
201 tp
->t_dqinfo
->dqa_usrdquots
: tp
->t_dqinfo
->dqa_grpdquots
;
203 for (i
= 0; i
< XFS_QM_TRANS_MAXDQS
; i
++) {
204 if (qa
[i
].qt_dquot
== NULL
||
205 qa
[i
].qt_dquot
== dqp
)
213 * Make the changes in the transaction structure.
214 * The moral equivalent to xfs_trans_mod_sb().
215 * We don't touch any fields in the dquot, so we don't care
216 * if it's locked or not (most of the time it won't be).
228 ASSERT(XFS_IS_QUOTA_RUNNING(tp
->t_mountp
));
231 if (tp
->t_dqinfo
== NULL
)
232 xfs_trans_alloc_dqinfo(tp
);
234 * Find either the first free slot or the slot that belongs
237 qtrx
= xfs_trans_get_dqtrx(tp
, dqp
);
239 if (qtrx
->qt_dquot
== NULL
)
240 qtrx
->qt_dquot
= dqp
;
245 * regular disk blk reservation
247 case XFS_TRANS_DQ_RES_BLKS
:
248 qtrx
->qt_blk_res
+= (ulong
)delta
;
254 case XFS_TRANS_DQ_RES_INOS
:
255 qtrx
->qt_ino_res
+= (ulong
)delta
;
261 case XFS_TRANS_DQ_BCOUNT
:
262 if (qtrx
->qt_blk_res
&& delta
> 0) {
263 qtrx
->qt_blk_res_used
+= (ulong
)delta
;
264 ASSERT(qtrx
->qt_blk_res
>= qtrx
->qt_blk_res_used
);
266 qtrx
->qt_bcount_delta
+= delta
;
269 case XFS_TRANS_DQ_DELBCOUNT
:
270 qtrx
->qt_delbcnt_delta
+= delta
;
276 case XFS_TRANS_DQ_ICOUNT
:
277 if (qtrx
->qt_ino_res
&& delta
> 0) {
278 qtrx
->qt_ino_res_used
+= (ulong
)delta
;
279 ASSERT(qtrx
->qt_ino_res
>= qtrx
->qt_ino_res_used
);
281 qtrx
->qt_icount_delta
+= delta
;
287 case XFS_TRANS_DQ_RES_RTBLKS
:
288 qtrx
->qt_rtblk_res
+= (ulong
)delta
;
294 case XFS_TRANS_DQ_RTBCOUNT
:
295 if (qtrx
->qt_rtblk_res
&& delta
> 0) {
296 qtrx
->qt_rtblk_res_used
+= (ulong
)delta
;
297 ASSERT(qtrx
->qt_rtblk_res
>= qtrx
->qt_rtblk_res_used
);
299 qtrx
->qt_rtbcount_delta
+= delta
;
302 case XFS_TRANS_DQ_DELRTBCOUNT
:
303 qtrx
->qt_delrtb_delta
+= delta
;
309 tp
->t_flags
|= XFS_TRANS_DQ_DIRTY
;
314 * Given an array of dqtrx structures, lock all the dquots associated
315 * and join them to the transaction, provided they have been modified.
316 * We know that the highest number of dquots (of one type - usr OR grp),
317 * involved in a transaction is 2 and that both usr and grp combined - 3.
318 * So, we don't attempt to make this very generic.
321 xfs_trans_dqlockedjoin(
325 ASSERT(q
[0].qt_dquot
!= NULL
);
326 if (q
[1].qt_dquot
== NULL
) {
327 xfs_dqlock(q
[0].qt_dquot
);
328 xfs_trans_dqjoin(tp
, q
[0].qt_dquot
);
330 ASSERT(XFS_QM_TRANS_MAXDQS
== 2);
331 xfs_dqlock2(q
[0].qt_dquot
, q
[1].qt_dquot
);
332 xfs_trans_dqjoin(tp
, q
[0].qt_dquot
);
333 xfs_trans_dqjoin(tp
, q
[1].qt_dquot
);
339 * Called by xfs_trans_commit() and similar in spirit to
340 * xfs_trans_apply_sb_deltas().
341 * Go thru all the dquots belonging to this transaction and modify the
342 * INCORE dquot to reflect the actual usages.
343 * Unreserve just the reservations done by this transaction.
344 * dquot is still left locked at exit.
347 xfs_trans_apply_dquot_deltas(
352 xfs_dqtrx_t
*qtrx
, *qa
;
357 if (!(tp
->t_flags
& XFS_TRANS_DQ_DIRTY
))
360 ASSERT(tp
->t_dqinfo
);
361 qa
= tp
->t_dqinfo
->dqa_usrdquots
;
362 for (j
= 0; j
< 2; j
++) {
363 if (qa
[0].qt_dquot
== NULL
) {
364 qa
= tp
->t_dqinfo
->dqa_grpdquots
;
369 * Lock all of the dquots and join them to the transaction.
371 xfs_trans_dqlockedjoin(tp
, qa
);
373 for (i
= 0; i
< XFS_QM_TRANS_MAXDQS
; i
++) {
376 * The array of dquots is filled
377 * sequentially, not sparsely.
379 if ((dqp
= qtrx
->qt_dquot
) == NULL
)
382 ASSERT(XFS_DQ_IS_LOCKED(dqp
));
383 ASSERT(dqp
->q_transp
== tp
);
386 * adjust the actual number of blocks used
391 * The issue here is - sometimes we don't make a blkquota
392 * reservation intentionally to be fair to users
393 * (when the amount is small). On the other hand,
394 * delayed allocs do make reservations, but that's
395 * outside of a transaction, so we have no
396 * idea how much was really reserved.
397 * So, here we've accumulated delayed allocation blks and
398 * non-delay blks. The assumption is that the
399 * delayed ones are always reserved (outside of a
400 * transaction), and the others may or may not have
401 * quota reservations.
403 totalbdelta
= qtrx
->qt_bcount_delta
+
404 qtrx
->qt_delbcnt_delta
;
405 totalrtbdelta
= qtrx
->qt_rtbcount_delta
+
406 qtrx
->qt_delrtb_delta
;
409 ASSERT(be64_to_cpu(d
->d_bcount
) >=
410 (xfs_qcnt_t
) -totalbdelta
);
412 if (totalrtbdelta
< 0)
413 ASSERT(be64_to_cpu(d
->d_rtbcount
) >=
414 (xfs_qcnt_t
) -totalrtbdelta
);
416 if (qtrx
->qt_icount_delta
< 0)
417 ASSERT(be64_to_cpu(d
->d_icount
) >=
418 (xfs_qcnt_t
) -qtrx
->qt_icount_delta
);
421 be64_add_cpu(&d
->d_bcount
, (xfs_qcnt_t
)totalbdelta
);
423 if (qtrx
->qt_icount_delta
)
424 be64_add_cpu(&d
->d_icount
, (xfs_qcnt_t
)qtrx
->qt_icount_delta
);
427 be64_add_cpu(&d
->d_rtbcount
, (xfs_qcnt_t
)totalrtbdelta
);
430 * Get any default limits in use.
431 * Start/reset the timer(s) if needed.
434 xfs_qm_adjust_dqlimits(tp
->t_mountp
, d
);
435 xfs_qm_adjust_dqtimers(tp
->t_mountp
, d
);
438 dqp
->dq_flags
|= XFS_DQ_DIRTY
;
440 * add this to the list of items to get logged
442 xfs_trans_log_dquot(tp
, dqp
);
444 * Take off what's left of the original reservation.
445 * In case of delayed allocations, there's no
446 * reservation that a transaction structure knows of.
448 if (qtrx
->qt_blk_res
!= 0) {
449 if (qtrx
->qt_blk_res
!= qtrx
->qt_blk_res_used
) {
450 if (qtrx
->qt_blk_res
>
451 qtrx
->qt_blk_res_used
)
452 dqp
->q_res_bcount
-= (xfs_qcnt_t
)
454 qtrx
->qt_blk_res_used
);
456 dqp
->q_res_bcount
-= (xfs_qcnt_t
)
457 (qtrx
->qt_blk_res_used
-
462 * These blks were never reserved, either inside
463 * a transaction or outside one (in a delayed
464 * allocation). Also, this isn't always a
465 * negative number since we sometimes
466 * deliberately skip quota reservations.
468 if (qtrx
->qt_bcount_delta
) {
470 (xfs_qcnt_t
)qtrx
->qt_bcount_delta
;
474 * Adjust the RT reservation.
476 if (qtrx
->qt_rtblk_res
!= 0) {
477 if (qtrx
->qt_rtblk_res
!= qtrx
->qt_rtblk_res_used
) {
478 if (qtrx
->qt_rtblk_res
>
479 qtrx
->qt_rtblk_res_used
)
480 dqp
->q_res_rtbcount
-= (xfs_qcnt_t
)
481 (qtrx
->qt_rtblk_res
-
482 qtrx
->qt_rtblk_res_used
);
484 dqp
->q_res_rtbcount
-= (xfs_qcnt_t
)
485 (qtrx
->qt_rtblk_res_used
-
489 if (qtrx
->qt_rtbcount_delta
)
490 dqp
->q_res_rtbcount
+=
491 (xfs_qcnt_t
)qtrx
->qt_rtbcount_delta
;
495 * Adjust the inode reservation.
497 if (qtrx
->qt_ino_res
!= 0) {
498 ASSERT(qtrx
->qt_ino_res
>=
499 qtrx
->qt_ino_res_used
);
500 if (qtrx
->qt_ino_res
> qtrx
->qt_ino_res_used
)
501 dqp
->q_res_icount
-= (xfs_qcnt_t
)
503 qtrx
->qt_ino_res_used
);
505 if (qtrx
->qt_icount_delta
)
507 (xfs_qcnt_t
)qtrx
->qt_icount_delta
;
510 ASSERT(dqp
->q_res_bcount
>=
511 be64_to_cpu(dqp
->q_core
.d_bcount
));
512 ASSERT(dqp
->q_res_icount
>=
513 be64_to_cpu(dqp
->q_core
.d_icount
));
514 ASSERT(dqp
->q_res_rtbcount
>=
515 be64_to_cpu(dqp
->q_core
.d_rtbcount
));
518 * Do the group quotas next
520 qa
= tp
->t_dqinfo
->dqa_grpdquots
;
525 * Release the reservations, and adjust the dquots accordingly.
526 * This is called only when the transaction is being aborted. If by
527 * any chance we have done dquot modifications incore (ie. deltas) already,
528 * we simply throw those away, since that's the expected behavior
529 * when a transaction is curtailed without a commit.
532 xfs_trans_unreserve_and_mod_dquots(
537 xfs_dqtrx_t
*qtrx
, *qa
;
540 if (!tp
->t_dqinfo
|| !(tp
->t_flags
& XFS_TRANS_DQ_DIRTY
))
543 qa
= tp
->t_dqinfo
->dqa_usrdquots
;
545 for (j
= 0; j
< 2; j
++) {
546 for (i
= 0; i
< XFS_QM_TRANS_MAXDQS
; i
++) {
549 * We assume that the array of dquots is filled
550 * sequentially, not sparsely.
552 if ((dqp
= qtrx
->qt_dquot
) == NULL
)
555 * Unreserve the original reservation. We don't care
556 * about the number of blocks used field, or deltas.
557 * Also we don't bother to zero the fields.
560 if (qtrx
->qt_blk_res
) {
564 (xfs_qcnt_t
)qtrx
->qt_blk_res
;
566 if (qtrx
->qt_ino_res
) {
572 (xfs_qcnt_t
)qtrx
->qt_ino_res
;
575 if (qtrx
->qt_rtblk_res
) {
580 dqp
->q_res_rtbcount
-=
581 (xfs_qcnt_t
)qtrx
->qt_rtblk_res
;
587 qa
= tp
->t_dqinfo
->dqa_grpdquots
;
593 struct xfs_mount
*mp
,
594 struct xfs_dquot
*dqp
,
597 /* no warnings for project quotas - we just return ENOSPC later */
598 if (dqp
->dq_flags
& XFS_DQ_PROJ
)
600 quota_send_warning((dqp
->dq_flags
& XFS_DQ_USER
) ? USRQUOTA
: GRPQUOTA
,
601 be32_to_cpu(dqp
->q_core
.d_id
), mp
->m_super
->s_dev
,
606 * This reserves disk blocks and inodes against a dquot.
607 * Flags indicate if the dquot is to be locked here and also
608 * if the blk reservation is for RT or regular blocks.
609 * Sending in XFS_QMOPT_FORCE_RES flag skips the quota check.
620 xfs_qcnt_t hardlimit
;
621 xfs_qcnt_t softlimit
;
623 xfs_qwarncnt_t warns
;
624 xfs_qwarncnt_t warnlimit
;
626 xfs_qcnt_t
*resbcountp
;
627 xfs_quotainfo_t
*q
= mp
->m_quotainfo
;
632 if (flags
& XFS_TRANS_DQ_RES_BLKS
) {
633 hardlimit
= be64_to_cpu(dqp
->q_core
.d_blk_hardlimit
);
635 hardlimit
= q
->qi_bhardlimit
;
636 softlimit
= be64_to_cpu(dqp
->q_core
.d_blk_softlimit
);
638 softlimit
= q
->qi_bsoftlimit
;
639 timer
= be32_to_cpu(dqp
->q_core
.d_btimer
);
640 warns
= be16_to_cpu(dqp
->q_core
.d_bwarns
);
641 warnlimit
= dqp
->q_mount
->m_quotainfo
->qi_bwarnlimit
;
642 resbcountp
= &dqp
->q_res_bcount
;
644 ASSERT(flags
& XFS_TRANS_DQ_RES_RTBLKS
);
645 hardlimit
= be64_to_cpu(dqp
->q_core
.d_rtb_hardlimit
);
647 hardlimit
= q
->qi_rtbhardlimit
;
648 softlimit
= be64_to_cpu(dqp
->q_core
.d_rtb_softlimit
);
650 softlimit
= q
->qi_rtbsoftlimit
;
651 timer
= be32_to_cpu(dqp
->q_core
.d_rtbtimer
);
652 warns
= be16_to_cpu(dqp
->q_core
.d_rtbwarns
);
653 warnlimit
= dqp
->q_mount
->m_quotainfo
->qi_rtbwarnlimit
;
654 resbcountp
= &dqp
->q_res_rtbcount
;
657 if ((flags
& XFS_QMOPT_FORCE_RES
) == 0 &&
659 ((XFS_IS_UQUOTA_ENFORCED(dqp
->q_mount
) && XFS_QM_ISUDQ(dqp
)) ||
660 (XFS_IS_OQUOTA_ENFORCED(dqp
->q_mount
) &&
661 (XFS_QM_ISPDQ(dqp
) || XFS_QM_ISGDQ(dqp
))))) {
663 cmn_err(CE_DEBUG
, "BLK Res: nblks=%ld + resbcount=%Ld"
664 " > hardlimit=%Ld?", nblks
, *resbcountp
, hardlimit
);
668 * dquot is locked already. See if we'd go over the
669 * hardlimit or exceed the timelimit if we allocate
672 if (hardlimit
> 0ULL &&
673 hardlimit
<= nblks
+ *resbcountp
) {
674 xfs_quota_warn(mp
, dqp
, QUOTA_NL_BHARDWARN
);
677 if (softlimit
> 0ULL &&
678 softlimit
<= nblks
+ *resbcountp
) {
679 if ((timer
!= 0 && get_seconds() > timer
) ||
680 (warns
!= 0 && warns
>= warnlimit
)) {
681 xfs_quota_warn(mp
, dqp
,
682 QUOTA_NL_BSOFTLONGWARN
);
686 xfs_quota_warn(mp
, dqp
, QUOTA_NL_BSOFTWARN
);
690 count
= be64_to_cpu(dqp
->q_core
.d_icount
);
691 timer
= be32_to_cpu(dqp
->q_core
.d_itimer
);
692 warns
= be16_to_cpu(dqp
->q_core
.d_iwarns
);
693 warnlimit
= dqp
->q_mount
->m_quotainfo
->qi_iwarnlimit
;
694 hardlimit
= be64_to_cpu(dqp
->q_core
.d_ino_hardlimit
);
696 hardlimit
= q
->qi_ihardlimit
;
697 softlimit
= be64_to_cpu(dqp
->q_core
.d_ino_softlimit
);
699 softlimit
= q
->qi_isoftlimit
;
701 if (hardlimit
> 0ULL && count
>= hardlimit
) {
702 xfs_quota_warn(mp
, dqp
, QUOTA_NL_IHARDWARN
);
705 if (softlimit
> 0ULL && count
>= softlimit
) {
706 if ((timer
!= 0 && get_seconds() > timer
) ||
707 (warns
!= 0 && warns
>= warnlimit
)) {
708 xfs_quota_warn(mp
, dqp
,
709 QUOTA_NL_ISOFTLONGWARN
);
712 xfs_quota_warn(mp
, dqp
, QUOTA_NL_ISOFTWARN
);
718 * Change the reservation, but not the actual usage.
719 * Note that q_res_bcount = q_core.d_bcount + resv
721 (*resbcountp
) += (xfs_qcnt_t
)nblks
;
723 dqp
->q_res_icount
+= (xfs_qcnt_t
)ninos
;
726 * note the reservation amt in the trans struct too,
727 * so that the transaction knows how much was reserved by
728 * it against this particular dquot.
729 * We don't do this when we are reserving for a delayed allocation,
730 * because we don't have the luxury of a transaction envelope then.
733 ASSERT(tp
->t_dqinfo
);
734 ASSERT(flags
& XFS_QMOPT_RESBLK_MASK
);
736 xfs_trans_mod_dquot(tp
, dqp
,
737 flags
& XFS_QMOPT_RESBLK_MASK
,
740 xfs_trans_mod_dquot(tp
, dqp
,
741 XFS_TRANS_DQ_RES_INOS
,
744 ASSERT(dqp
->q_res_bcount
>= be64_to_cpu(dqp
->q_core
.d_bcount
));
745 ASSERT(dqp
->q_res_rtbcount
>= be64_to_cpu(dqp
->q_core
.d_rtbcount
));
746 ASSERT(dqp
->q_res_icount
>= be64_to_cpu(dqp
->q_core
.d_icount
));
753 if (flags
& XFS_QMOPT_ENOSPC
)
760 * Given dquot(s), make disk block and/or inode reservations against them.
761 * The fact that this does the reservation against both the usr and
762 * grp/prj quotas is important, because this follows a both-or-nothing
765 * flags = XFS_QMOPT_FORCE_RES evades limit enforcement. Used by chown.
766 * XFS_QMOPT_ENOSPC returns ENOSPC not EDQUOT. Used by pquota.
767 * XFS_TRANS_DQ_RES_BLKS reserves regular disk blocks
768 * XFS_TRANS_DQ_RES_RTBLKS reserves realtime disk blocks
769 * dquots are unlocked on return, if they were not locked by caller.
772 xfs_trans_reserve_quota_bydquots(
781 int resvd
= 0, error
;
783 if (!XFS_IS_QUOTA_RUNNING(mp
) || !XFS_IS_QUOTA_ON(mp
))
786 if (tp
&& tp
->t_dqinfo
== NULL
)
787 xfs_trans_alloc_dqinfo(tp
);
789 ASSERT(flags
& XFS_QMOPT_RESBLK_MASK
);
792 error
= xfs_trans_dqresv(tp
, mp
, udqp
, nblks
, ninos
,
793 (flags
& ~XFS_QMOPT_ENOSPC
));
800 error
= xfs_trans_dqresv(tp
, mp
, gdqp
, nblks
, ninos
, flags
);
803 * can't do it, so backout previous reservation
806 flags
|= XFS_QMOPT_FORCE_RES
;
807 xfs_trans_dqresv(tp
, mp
, udqp
,
808 -nblks
, -ninos
, flags
);
815 * Didn't change anything critical, so, no need to log
822 * Lock the dquot and change the reservation if we can.
823 * This doesn't change the actual usage, just the reservation.
824 * The inode sent in is locked.
827 xfs_trans_reserve_quota_nblks(
828 struct xfs_trans
*tp
,
829 struct xfs_inode
*ip
,
834 struct xfs_mount
*mp
= ip
->i_mount
;
836 if (!XFS_IS_QUOTA_RUNNING(mp
) || !XFS_IS_QUOTA_ON(mp
))
838 if (XFS_IS_PQUOTA_ON(mp
))
839 flags
|= XFS_QMOPT_ENOSPC
;
841 ASSERT(ip
->i_ino
!= mp
->m_sb
.sb_uquotino
);
842 ASSERT(ip
->i_ino
!= mp
->m_sb
.sb_gquotino
);
844 ASSERT(xfs_isilocked(ip
, XFS_ILOCK_EXCL
));
845 ASSERT((flags
& ~(XFS_QMOPT_FORCE_RES
| XFS_QMOPT_ENOSPC
)) ==
846 XFS_TRANS_DQ_RES_RTBLKS
||
847 (flags
& ~(XFS_QMOPT_FORCE_RES
| XFS_QMOPT_ENOSPC
)) ==
848 XFS_TRANS_DQ_RES_BLKS
);
851 * Reserve nblks against these dquots, with trans as the mediator.
853 return xfs_trans_reserve_quota_bydquots(tp
, mp
,
854 ip
->i_udquot
, ip
->i_gdquot
,
855 nblks
, ninos
, flags
);
859 * This routine is called to allocate a quotaoff log item.
862 xfs_trans_get_qoff_item(
864 xfs_qoff_logitem_t
*startqoff
,
867 xfs_qoff_logitem_t
*q
;
871 q
= xfs_qm_qoff_logitem_init(tp
->t_mountp
, startqoff
, flags
);
875 * Get a log_item_desc to point at the new item.
877 (void) xfs_trans_add_item(tp
, (xfs_log_item_t
*)q
);
884 * This is called to mark the quotaoff logitem as needing
885 * to be logged when the transaction is committed. The logitem must
886 * already be associated with the given transaction.
889 xfs_trans_log_quotaoff_item(
891 xfs_qoff_logitem_t
*qlp
)
893 xfs_log_item_desc_t
*lidp
;
895 lidp
= xfs_trans_find_item(tp
, (xfs_log_item_t
*)qlp
);
896 ASSERT(lidp
!= NULL
);
898 tp
->t_flags
|= XFS_TRANS_DIRTY
;
899 lidp
->lid_flags
|= XFS_LID_DIRTY
;
903 xfs_trans_alloc_dqinfo(
906 tp
->t_dqinfo
= kmem_zone_zalloc(xfs_Gqm
->qm_dqtrxzone
, KM_SLEEP
);
910 xfs_trans_free_dqinfo(
915 kmem_zone_free(xfs_Gqm
->qm_dqtrxzone
, tp
->t_dqinfo
);