2 * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
32 #ifndef __XFS_QUOTA_PRIV_H__
33 #define __XFS_QUOTA_PRIV_H__
36 * Number of bmaps that we ask from bmapi when doing a quotacheck.
37 * We make this restriction to keep the memory usage to a minimum.
39 #define XFS_DQITER_MAP_SIZE 10
41 /* Number of dquots that fit in to a dquot block */
42 #define XFS_QM_DQPERBLK(mp) ((mp)->m_quotainfo->qi_dqperchunk)
44 #define XFS_ISLOCKED_INODE(ip) (ismrlocked(&(ip)->i_lock, \
45 MR_UPDATE | MR_ACCESS) != 0)
46 #define XFS_ISLOCKED_INODE_EXCL(ip) (ismrlocked(&(ip)->i_lock, \
49 #define XFS_DQ_IS_ADDEDTO_TRX(t, d) ((d)->q_transp == (t))
51 #define XFS_QI_MPLRECLAIMS(mp) ((mp)->m_quotainfo->qi_dqreclaims)
52 #define XFS_QI_UQIP(mp) ((mp)->m_quotainfo->qi_uquotaip)
53 #define XFS_QI_GQIP(mp) ((mp)->m_quotainfo->qi_gquotaip)
54 #define XFS_QI_DQCHUNKLEN(mp) ((mp)->m_quotainfo->qi_dqchunklen)
55 #define XFS_QI_BTIMELIMIT(mp) ((mp)->m_quotainfo->qi_btimelimit)
56 #define XFS_QI_RTBTIMELIMIT(mp) ((mp)->m_quotainfo->qi_rtbtimelimit)
57 #define XFS_QI_ITIMELIMIT(mp) ((mp)->m_quotainfo->qi_itimelimit)
58 #define XFS_QI_BWARNLIMIT(mp) ((mp)->m_quotainfo->qi_bwarnlimit)
59 #define XFS_QI_RTBWARNLIMIT(mp) ((mp)->m_quotainfo->qi_rtbwarnlimit)
60 #define XFS_QI_IWARNLIMIT(mp) ((mp)->m_quotainfo->qi_iwarnlimit)
61 #define XFS_QI_QOFFLOCK(mp) ((mp)->m_quotainfo->qi_quotaofflock)
63 #define XFS_QI_MPL_LIST(mp) ((mp)->m_quotainfo->qi_dqlist)
64 #define XFS_QI_MPLLOCK(mp) ((mp)->m_quotainfo->qi_dqlist.qh_lock)
65 #define XFS_QI_MPLNEXT(mp) ((mp)->m_quotainfo->qi_dqlist.qh_next)
66 #define XFS_QI_MPLNDQUOTS(mp) ((mp)->m_quotainfo->qi_dqlist.qh_nelems)
68 #define XQMLCK(h) (mutex_lock(&((h)->qh_lock), PINOD))
69 #define XQMUNLCK(h) (mutex_unlock(&((h)->qh_lock)))
72 static inline int XQMISLCKD(struct xfs_dqhash *h)
74 if (mutex_trylock(&h->qh_lock)) {
75 mutex_unlock(&h->qh_lock);
82 #define XFS_DQ_HASH_LOCK(h) XQMLCK(h)
83 #define XFS_DQ_HASH_UNLOCK(h) XQMUNLCK(h)
84 #define XFS_DQ_IS_HASH_LOCKED(h) XQMISLCKD(h)
86 #define xfs_qm_mplist_lock(mp) XQMLCK(&(XFS_QI_MPL_LIST(mp)))
87 #define xfs_qm_mplist_unlock(mp) XQMUNLCK(&(XFS_QI_MPL_LIST(mp)))
88 #define XFS_QM_IS_MPLIST_LOCKED(mp) XQMISLCKD(&(XFS_QI_MPL_LIST(mp)))
90 #define xfs_qm_freelist_lock(qm) XQMLCK(&((qm)->qm_dqfreelist))
91 #define xfs_qm_freelist_unlock(qm) XQMUNLCK(&((qm)->qm_dqfreelist))
92 #define XFS_QM_IS_FREELIST_LOCKED(qm) XQMISLCKD(&((qm)->qm_dqfreelist))
95 * Hash into a bucket in the dquot hash table, based on <mp, id>.
97 #define XFS_DQ_HASHVAL(mp, id) (((__psunsigned_t)(mp) + \
98 (__psunsigned_t)(id)) & \
99 (xfs_Gqm->qm_dqhashmask - 1))
100 #define XFS_DQ_HASH(mp, id, type) (type == XFS_DQ_USER ? \
101 (xfs_Gqm->qm_usr_dqhtable + \
102 XFS_DQ_HASHVAL(mp, id)) : \
103 (xfs_Gqm->qm_grp_dqhtable + \
104 XFS_DQ_HASHVAL(mp, id)))
105 #define XFS_IS_DQTYPE_ON(mp, type) (type == XFS_DQ_USER ? \
106 XFS_IS_UQUOTA_ON(mp) : \
107 XFS_IS_OQUOTA_ON(mp))
108 #define XFS_IS_DQUOT_UNINITIALIZED(dqp) ( \
109 !dqp->q_core.d_blk_hardlimit && \
110 !dqp->q_core.d_blk_softlimit && \
111 !dqp->q_core.d_rtb_hardlimit && \
112 !dqp->q_core.d_rtb_softlimit && \
113 !dqp->q_core.d_ino_hardlimit && \
114 !dqp->q_core.d_ino_softlimit && \
115 !dqp->q_core.d_bcount && \
116 !dqp->q_core.d_rtbcount && \
117 !dqp->q_core.d_icount)
119 #define HL_PREVP dq_hashlist.ql_prevp
120 #define HL_NEXT dq_hashlist.ql_next
121 #define MPL_PREVP dq_mplist.ql_prevp
122 #define MPL_NEXT dq_mplist.ql_next
125 #define _LIST_REMOVE(h, dqp, PVP, NXT) \
128 if (((d) = (dqp)->NXT)) \
129 (d)->PVP = (dqp)->PVP; \
137 #define _LIST_INSERT(h, dqp, PVP, NXT) \
140 if (((d) = (h)->qh_next)) \
141 (d)->PVP = &((dqp)->NXT); \
143 (dqp)->PVP = &((h)->qh_next); \
144 (h)->qh_next = dqp; \
149 #define FOREACH_DQUOT_IN_MP(dqp, mp) \
150 for ((dqp) = XFS_QI_MPLNEXT(mp); (dqp) != NULL; (dqp) = (dqp)->MPL_NEXT)
152 #define FOREACH_DQUOT_IN_FREELIST(dqp, qlist) \
153 for ((dqp) = (qlist)->qh_next; (dqp) != (xfs_dquot_t *)(qlist); \
154 (dqp) = (dqp)->dq_flnext)
156 #define XQM_HASHLIST_INSERT(h, dqp) \
157 _LIST_INSERT(h, dqp, HL_PREVP, HL_NEXT)
159 #define XQM_FREELIST_INSERT(h, dqp) \
160 xfs_qm_freelist_append(h, dqp)
162 #define XQM_MPLIST_INSERT(h, dqp) \
163 _LIST_INSERT(h, dqp, MPL_PREVP, MPL_NEXT)
165 #define XQM_HASHLIST_REMOVE(h, dqp) \
166 _LIST_REMOVE(h, dqp, HL_PREVP, HL_NEXT)
167 #define XQM_FREELIST_REMOVE(dqp) \
168 xfs_qm_freelist_unlink(dqp)
169 #define XQM_MPLIST_REMOVE(h, dqp) \
170 { _LIST_REMOVE(h, dqp, MPL_PREVP, MPL_NEXT); \
171 XFS_QI_MPLRECLAIMS((dqp)->q_mount)++; }
173 #define XFS_DQ_IS_LOGITEM_INITD(dqp) ((dqp)->q_logitem.qli_dquot == (dqp))
175 #define XFS_QM_DQP_TO_DQACCT(tp, dqp) (XFS_QM_ISUDQ(dqp) ? \
176 (tp)->t_dqinfo->dqa_usrdquots : \
177 (tp)->t_dqinfo->dqa_grpdquots)
178 #define XFS_IS_SUSER_DQUOT(dqp) \
179 (!((dqp)->q_core.d_id))
181 #define XFS_PURGE_INODE(ip) \
184 #define DQFLAGTO_TYPESTR(d) (((d)->dq_flags & XFS_DQ_USER) ? "USR" : \
185 (((d)->dq_flags & XFS_DQ_GROUP) ? "GRP" : \
186 (((d)->dq_flags & XFS_DQ_PROJ) ? "PRJ":"???")))
187 #define DQFLAGTO_DIRTYSTR(d) (XFS_DQ_IS_DIRTY(d) ? "DIRTY" : "NOTDIRTY")
189 #endif /* __XFS_QUOTA_PRIV_H__ */