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_shared.h"
21 #include "xfs_format.h"
22 #include "xfs_log_format.h"
23 #include "xfs_trans_resv.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_trans.h"
37 #include "xfs_buf_item.h"
38 #include "xfs_trans_priv.h"
41 STATIC
void xfs_trans_alloc_dqinfo(xfs_trans_t
*);
44 * Add the locked dquot to the transaction.
45 * The dquot must be locked, and it cannot be associated with any
53 ASSERT(dqp
->q_transp
!= tp
);
54 ASSERT(XFS_DQ_IS_LOCKED(dqp
));
55 ASSERT(dqp
->q_logitem
.qli_dquot
== dqp
);
58 * Get a log_item_desc to point at the new item.
60 xfs_trans_add_item(tp
, &dqp
->q_logitem
.qli_item
);
63 * Initialize d_transp so we can later determine if this dquot is
64 * associated with this transaction.
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
85 ASSERT(dqp
->q_transp
== tp
);
86 ASSERT(XFS_DQ_IS_LOCKED(dqp
));
88 tp
->t_flags
|= XFS_TRANS_DIRTY
;
89 dqp
->q_logitem
.qli_item
.li_desc
->lid_flags
|= XFS_LID_DIRTY
;
93 * Carry forward whatever is left of the quota blk reservation to
94 * the spanky new transaction
101 xfs_dqtrx_t
*oq
, *nq
;
103 xfs_dqtrx_t
*oqa
, *nqa
;
108 xfs_trans_alloc_dqinfo(ntp
);
111 * Because the quota blk reservation is carried forward,
112 * it is also necessary to carry forward the DQ_DIRTY flag.
114 if(otp
->t_flags
& XFS_TRANS_DQ_DIRTY
)
115 ntp
->t_flags
|= XFS_TRANS_DQ_DIRTY
;
117 for (j
= 0; j
< XFS_QM_TRANS_DQTYPES
; j
++) {
118 oqa
= otp
->t_dqinfo
->dqs
[j
];
119 nqa
= ntp
->t_dqinfo
->dqs
[j
];
120 for (i
= 0; i
< XFS_QM_TRANS_MAXDQS
; i
++) {
121 if (oqa
[i
].qt_dquot
== NULL
)
126 nq
->qt_dquot
= oq
->qt_dquot
;
127 nq
->qt_bcount_delta
= nq
->qt_icount_delta
= 0;
128 nq
->qt_rtbcount_delta
= 0;
131 * Transfer whatever is left of the reservations.
133 nq
->qt_blk_res
= oq
->qt_blk_res
- oq
->qt_blk_res_used
;
134 oq
->qt_blk_res
= oq
->qt_blk_res_used
;
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
;
140 nq
->qt_ino_res
= oq
->qt_ino_res
- oq
->qt_ino_res_used
;
141 oq
->qt_ino_res
= oq
->qt_ino_res_used
;
148 * Wrap around mod_dquot to account for both user and group quotas.
151 xfs_trans_mod_dquot_byino(
157 xfs_mount_t
*mp
= tp
->t_mountp
;
159 if (!XFS_IS_QUOTA_RUNNING(mp
) ||
160 !XFS_IS_QUOTA_ON(mp
) ||
161 xfs_is_quota_inode(&mp
->m_sb
, ip
->i_ino
))
164 if (tp
->t_dqinfo
== NULL
)
165 xfs_trans_alloc_dqinfo(tp
);
167 if (XFS_IS_UQUOTA_ON(mp
) && ip
->i_udquot
)
168 (void) xfs_trans_mod_dquot(tp
, ip
->i_udquot
, field
, delta
);
169 if (XFS_IS_GQUOTA_ON(mp
) && ip
->i_gdquot
)
170 (void) xfs_trans_mod_dquot(tp
, ip
->i_gdquot
, field
, delta
);
171 if (XFS_IS_PQUOTA_ON(mp
) && ip
->i_pdquot
)
172 (void) xfs_trans_mod_dquot(tp
, ip
->i_pdquot
, field
, delta
);
175 STATIC
struct xfs_dqtrx
*
177 struct xfs_trans
*tp
,
178 struct xfs_dquot
*dqp
)
181 struct xfs_dqtrx
*qa
;
183 if (XFS_QM_ISUDQ(dqp
))
184 qa
= tp
->t_dqinfo
->dqs
[XFS_QM_TRANS_USR
];
185 else if (XFS_QM_ISGDQ(dqp
))
186 qa
= tp
->t_dqinfo
->dqs
[XFS_QM_TRANS_GRP
];
187 else if (XFS_QM_ISPDQ(dqp
))
188 qa
= tp
->t_dqinfo
->dqs
[XFS_QM_TRANS_PRJ
];
192 for (i
= 0; i
< XFS_QM_TRANS_MAXDQS
; i
++) {
193 if (qa
[i
].qt_dquot
== NULL
||
194 qa
[i
].qt_dquot
== dqp
)
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).
217 ASSERT(XFS_IS_QUOTA_RUNNING(tp
->t_mountp
));
220 if (tp
->t_dqinfo
== NULL
)
221 xfs_trans_alloc_dqinfo(tp
);
223 * Find either the first free slot or the slot that belongs
226 qtrx
= xfs_trans_get_dqtrx(tp
, dqp
);
228 if (qtrx
->qt_dquot
== NULL
)
229 qtrx
->qt_dquot
= dqp
;
234 * regular disk blk reservation
236 case XFS_TRANS_DQ_RES_BLKS
:
237 qtrx
->qt_blk_res
+= (ulong
)delta
;
243 case XFS_TRANS_DQ_RES_INOS
:
244 qtrx
->qt_ino_res
+= (ulong
)delta
;
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
);
255 qtrx
->qt_bcount_delta
+= delta
;
258 case XFS_TRANS_DQ_DELBCOUNT
:
259 qtrx
->qt_delbcnt_delta
+= delta
;
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
);
270 qtrx
->qt_icount_delta
+= delta
;
276 case XFS_TRANS_DQ_RES_RTBLKS
:
277 qtrx
->qt_rtblk_res
+= (ulong
)delta
;
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
);
288 qtrx
->qt_rtbcount_delta
+= delta
;
291 case XFS_TRANS_DQ_DELRTBCOUNT
:
292 qtrx
->qt_delrtb_delta
+= delta
;
298 tp
->t_flags
|= XFS_TRANS_DQ_DIRTY
;
303 * 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.
309 xfs_trans_dqlockedjoin(
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
);
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
);
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.
335 xfs_trans_apply_dquot_deltas(
336 struct xfs_trans
*tp
)
339 struct xfs_dquot
*dqp
;
340 struct xfs_dqtrx
*qtrx
, *qa
;
341 struct xfs_disk_dquot
*d
;
345 if (!(tp
->t_flags
& XFS_TRANS_DQ_DIRTY
))
348 ASSERT(tp
->t_dqinfo
);
349 for (j
= 0; j
< XFS_QM_TRANS_DQTYPES
; j
++) {
350 qa
= tp
->t_dqinfo
->dqs
[j
];
351 if (qa
[0].qt_dquot
== NULL
)
355 * Lock all of the dquots and join them to the transaction.
357 xfs_trans_dqlockedjoin(tp
, qa
);
359 for (i
= 0; i
< XFS_QM_TRANS_MAXDQS
; i
++) {
362 * The array of dquots is filled
363 * sequentially, not sparsely.
365 if ((dqp
= qtrx
->qt_dquot
) == NULL
)
368 ASSERT(XFS_DQ_IS_LOCKED(dqp
));
369 ASSERT(dqp
->q_transp
== tp
);
372 * adjust the actual number of blocks used
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.
389 totalbdelta
= qtrx
->qt_bcount_delta
+
390 qtrx
->qt_delbcnt_delta
;
391 totalrtbdelta
= qtrx
->qt_rtbcount_delta
+
392 qtrx
->qt_delrtb_delta
;
395 ASSERT(be64_to_cpu(d
->d_bcount
) >=
398 if (totalrtbdelta
< 0)
399 ASSERT(be64_to_cpu(d
->d_rtbcount
) >=
402 if (qtrx
->qt_icount_delta
< 0)
403 ASSERT(be64_to_cpu(d
->d_icount
) >=
404 -qtrx
->qt_icount_delta
);
407 be64_add_cpu(&d
->d_bcount
, (xfs_qcnt_t
)totalbdelta
);
409 if (qtrx
->qt_icount_delta
)
410 be64_add_cpu(&d
->d_icount
, (xfs_qcnt_t
)qtrx
->qt_icount_delta
);
413 be64_add_cpu(&d
->d_rtbcount
, (xfs_qcnt_t
)totalrtbdelta
);
416 * Get any default limits in use.
417 * Start/reset the timer(s) if needed.
420 xfs_qm_adjust_dqlimits(tp
->t_mountp
, dqp
);
421 xfs_qm_adjust_dqtimers(tp
->t_mountp
, d
);
424 dqp
->dq_flags
|= XFS_DQ_DIRTY
;
426 * add this to the list of items to get logged
428 xfs_trans_log_dquot(tp
, dqp
);
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.
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
)
440 qtrx
->qt_blk_res_used
);
442 dqp
->q_res_bcount
-= (xfs_qcnt_t
)
443 (qtrx
->qt_blk_res_used
-
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.
454 if (qtrx
->qt_bcount_delta
) {
456 (xfs_qcnt_t
)qtrx
->qt_bcount_delta
;
460 * Adjust the RT reservation.
462 if (qtrx
->qt_rtblk_res
!= 0) {
463 if (qtrx
->qt_rtblk_res
!= qtrx
->qt_rtblk_res_used
) {
464 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
);
470 dqp
->q_res_rtbcount
-= (xfs_qcnt_t
)
471 (qtrx
->qt_rtblk_res_used
-
475 if (qtrx
->qt_rtbcount_delta
)
476 dqp
->q_res_rtbcount
+=
477 (xfs_qcnt_t
)qtrx
->qt_rtbcount_delta
;
481 * Adjust the inode reservation.
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
)
489 qtrx
->qt_ino_res_used
);
491 if (qtrx
->qt_icount_delta
)
493 (xfs_qcnt_t
)qtrx
->qt_icount_delta
;
496 ASSERT(dqp
->q_res_bcount
>=
497 be64_to_cpu(dqp
->q_core
.d_bcount
));
498 ASSERT(dqp
->q_res_icount
>=
499 be64_to_cpu(dqp
->q_core
.d_icount
));
500 ASSERT(dqp
->q_res_rtbcount
>=
501 be64_to_cpu(dqp
->q_core
.d_rtbcount
));
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.
514 xfs_trans_unreserve_and_mod_dquots(
519 xfs_dqtrx_t
*qtrx
, *qa
;
522 if (!tp
->t_dqinfo
|| !(tp
->t_flags
& XFS_TRANS_DQ_DIRTY
))
525 for (j
= 0; j
< XFS_QM_TRANS_DQTYPES
; j
++) {
526 qa
= tp
->t_dqinfo
->dqs
[j
];
528 for (i
= 0; i
< XFS_QM_TRANS_MAXDQS
; i
++) {
531 * We assume that the array of dquots is filled
532 * sequentially, not sparsely.
534 if ((dqp
= qtrx
->qt_dquot
) == NULL
)
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.
542 if (qtrx
->qt_blk_res
) {
546 (xfs_qcnt_t
)qtrx
->qt_blk_res
;
548 if (qtrx
->qt_ino_res
) {
554 (xfs_qcnt_t
)qtrx
->qt_ino_res
;
557 if (qtrx
->qt_rtblk_res
) {
562 dqp
->q_res_rtbcount
-=
563 (xfs_qcnt_t
)qtrx
->qt_rtblk_res
;
574 struct xfs_mount
*mp
,
575 struct xfs_dquot
*dqp
,
578 /* no warnings for project quotas - we just return ENOSPC later */
579 if (dqp
->dq_flags
& XFS_DQ_PROJ
)
581 quota_send_warning(make_kqid(&init_user_ns
,
582 (dqp
->dq_flags
& XFS_DQ_USER
) ?
584 be32_to_cpu(dqp
->q_core
.d_id
)),
585 mp
->m_super
->s_dev
, type
);
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.
603 xfs_qcnt_t hardlimit
;
604 xfs_qcnt_t softlimit
;
606 xfs_qwarncnt_t warns
;
607 xfs_qwarncnt_t warnlimit
;
608 xfs_qcnt_t total_count
;
609 xfs_qcnt_t
*resbcountp
;
610 xfs_quotainfo_t
*q
= mp
->m_quotainfo
;
615 if (flags
& XFS_TRANS_DQ_RES_BLKS
) {
616 hardlimit
= be64_to_cpu(dqp
->q_core
.d_blk_hardlimit
);
618 hardlimit
= q
->qi_bhardlimit
;
619 softlimit
= be64_to_cpu(dqp
->q_core
.d_blk_softlimit
);
621 softlimit
= q
->qi_bsoftlimit
;
622 timer
= be32_to_cpu(dqp
->q_core
.d_btimer
);
623 warns
= be16_to_cpu(dqp
->q_core
.d_bwarns
);
624 warnlimit
= dqp
->q_mount
->m_quotainfo
->qi_bwarnlimit
;
625 resbcountp
= &dqp
->q_res_bcount
;
627 ASSERT(flags
& XFS_TRANS_DQ_RES_RTBLKS
);
628 hardlimit
= be64_to_cpu(dqp
->q_core
.d_rtb_hardlimit
);
630 hardlimit
= q
->qi_rtbhardlimit
;
631 softlimit
= be64_to_cpu(dqp
->q_core
.d_rtb_softlimit
);
633 softlimit
= q
->qi_rtbsoftlimit
;
634 timer
= be32_to_cpu(dqp
->q_core
.d_rtbtimer
);
635 warns
= be16_to_cpu(dqp
->q_core
.d_rtbwarns
);
636 warnlimit
= dqp
->q_mount
->m_quotainfo
->qi_rtbwarnlimit
;
637 resbcountp
= &dqp
->q_res_rtbcount
;
640 if ((flags
& XFS_QMOPT_FORCE_RES
) == 0 &&
642 ((XFS_IS_UQUOTA_ENFORCED(dqp
->q_mount
) && XFS_QM_ISUDQ(dqp
)) ||
643 (XFS_IS_GQUOTA_ENFORCED(dqp
->q_mount
) && XFS_QM_ISGDQ(dqp
)) ||
644 (XFS_IS_PQUOTA_ENFORCED(dqp
->q_mount
) && XFS_QM_ISPDQ(dqp
)))) {
647 * dquot is locked already. See if we'd go over the
648 * hardlimit or exceed the timelimit if we allocate
651 total_count
= *resbcountp
+ nblks
;
652 if (hardlimit
&& total_count
> hardlimit
) {
653 xfs_quota_warn(mp
, dqp
, QUOTA_NL_BHARDWARN
);
656 if (softlimit
&& total_count
> softlimit
) {
657 if ((timer
!= 0 && get_seconds() > timer
) ||
658 (warns
!= 0 && warns
>= warnlimit
)) {
659 xfs_quota_warn(mp
, dqp
,
660 QUOTA_NL_BSOFTLONGWARN
);
664 xfs_quota_warn(mp
, dqp
, QUOTA_NL_BSOFTWARN
);
668 total_count
= be64_to_cpu(dqp
->q_core
.d_icount
) + ninos
;
669 timer
= be32_to_cpu(dqp
->q_core
.d_itimer
);
670 warns
= be16_to_cpu(dqp
->q_core
.d_iwarns
);
671 warnlimit
= dqp
->q_mount
->m_quotainfo
->qi_iwarnlimit
;
672 hardlimit
= be64_to_cpu(dqp
->q_core
.d_ino_hardlimit
);
674 hardlimit
= q
->qi_ihardlimit
;
675 softlimit
= be64_to_cpu(dqp
->q_core
.d_ino_softlimit
);
677 softlimit
= q
->qi_isoftlimit
;
679 if (hardlimit
&& total_count
> hardlimit
) {
680 xfs_quota_warn(mp
, dqp
, QUOTA_NL_IHARDWARN
);
683 if (softlimit
&& total_count
> softlimit
) {
684 if ((timer
!= 0 && get_seconds() > timer
) ||
685 (warns
!= 0 && warns
>= warnlimit
)) {
686 xfs_quota_warn(mp
, dqp
,
687 QUOTA_NL_ISOFTLONGWARN
);
690 xfs_quota_warn(mp
, dqp
, QUOTA_NL_ISOFTWARN
);
696 * Change the reservation, but not the actual usage.
697 * Note that q_res_bcount = q_core.d_bcount + resv
699 (*resbcountp
) += (xfs_qcnt_t
)nblks
;
701 dqp
->q_res_icount
+= (xfs_qcnt_t
)ninos
;
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.
711 ASSERT(tp
->t_dqinfo
);
712 ASSERT(flags
& XFS_QMOPT_RESBLK_MASK
);
714 xfs_trans_mod_dquot(tp
, dqp
,
715 flags
& XFS_QMOPT_RESBLK_MASK
,
718 xfs_trans_mod_dquot(tp
, dqp
,
719 XFS_TRANS_DQ_RES_INOS
,
722 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
));
731 if (flags
& XFS_QMOPT_ENOSPC
)
738 * Given dquot(s), make disk block and/or inode reservations against them.
739 * The fact that this does the reservation against user, group and
740 * project quotas is important, because this follows a all-or-nothing
743 * flags = XFS_QMOPT_FORCE_RES evades limit enforcement. Used by chown.
744 * XFS_QMOPT_ENOSPC returns ENOSPC not EDQUOT. Used by pquota.
745 * 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.
750 xfs_trans_reserve_quota_bydquots(
751 struct xfs_trans
*tp
,
752 struct xfs_mount
*mp
,
753 struct xfs_dquot
*udqp
,
754 struct xfs_dquot
*gdqp
,
755 struct xfs_dquot
*pdqp
,
762 if (!XFS_IS_QUOTA_RUNNING(mp
) || !XFS_IS_QUOTA_ON(mp
))
765 if (tp
&& tp
->t_dqinfo
== NULL
)
766 xfs_trans_alloc_dqinfo(tp
);
768 ASSERT(flags
& XFS_QMOPT_RESBLK_MASK
);
771 error
= xfs_trans_dqresv(tp
, mp
, udqp
, nblks
, ninos
,
772 (flags
& ~XFS_QMOPT_ENOSPC
));
778 error
= xfs_trans_dqresv(tp
, mp
, gdqp
, nblks
, ninos
, flags
);
784 error
= xfs_trans_dqresv(tp
, mp
, pdqp
, nblks
, ninos
, flags
);
790 * Didn't change anything critical, so, no need to log
795 flags
|= XFS_QMOPT_FORCE_RES
;
797 xfs_trans_dqresv(tp
, mp
, gdqp
, -nblks
, -ninos
, flags
);
799 flags
|= XFS_QMOPT_FORCE_RES
;
801 xfs_trans_dqresv(tp
, mp
, udqp
, -nblks
, -ninos
, flags
);
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.
812 xfs_trans_reserve_quota_nblks(
813 struct xfs_trans
*tp
,
814 struct xfs_inode
*ip
,
819 struct xfs_mount
*mp
= ip
->i_mount
;
821 if (!XFS_IS_QUOTA_RUNNING(mp
) || !XFS_IS_QUOTA_ON(mp
))
823 if (XFS_IS_PQUOTA_ON(mp
))
824 flags
|= XFS_QMOPT_ENOSPC
;
826 ASSERT(!xfs_is_quota_inode(&mp
->m_sb
, ip
->i_ino
));
828 ASSERT(xfs_isilocked(ip
, XFS_ILOCK_EXCL
));
829 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
);
835 * Reserve nblks against these dquots, with trans as the mediator.
837 return xfs_trans_reserve_quota_bydquots(tp
, mp
,
838 ip
->i_udquot
, ip
->i_gdquot
,
840 nblks
, ninos
, flags
);
844 * This routine is called to allocate a quotaoff log item.
847 xfs_trans_get_qoff_item(
849 xfs_qoff_logitem_t
*startqoff
,
852 xfs_qoff_logitem_t
*q
;
856 q
= xfs_qm_qoff_logitem_init(tp
->t_mountp
, startqoff
, flags
);
860 * Get a log_item_desc to point at the new item.
862 xfs_trans_add_item(tp
, &q
->qql_item
);
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.
873 xfs_trans_log_quotaoff_item(
875 xfs_qoff_logitem_t
*qlp
)
877 tp
->t_flags
|= XFS_TRANS_DIRTY
;
878 qlp
->qql_item
.li_desc
->lid_flags
|= XFS_LID_DIRTY
;
882 xfs_trans_alloc_dqinfo(
885 tp
->t_dqinfo
= kmem_zone_zalloc(xfs_qm_dqtrxzone
, KM_SLEEP
);
889 xfs_trans_free_dqinfo(
894 kmem_zone_free(xfs_qm_dqtrxzone
, tp
->t_dqinfo
);
This page took 0.059681 seconds and 5 git commands to generate.