Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / fs / xfs / quota / xfs_quota_priv.h
blob414b6004af2160ce5a16c8f86b5f50d7c17a87f2
1 /*
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:
26 * http://www.sgi.com
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, \
47 MR_UPDATE) != 0)
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_IWARNLIMIT(mp) ((mp)->m_quotainfo->qi_iwarnlimit)
60 #define XFS_QI_QOFFLOCK(mp) ((mp)->m_quotainfo->qi_quotaofflock)
62 #define XFS_QI_MPL_LIST(mp) ((mp)->m_quotainfo->qi_dqlist)
63 #define XFS_QI_MPLLOCK(mp) ((mp)->m_quotainfo->qi_dqlist.qh_lock)
64 #define XFS_QI_MPLNEXT(mp) ((mp)->m_quotainfo->qi_dqlist.qh_next)
65 #define XFS_QI_MPLNDQUOTS(mp) ((mp)->m_quotainfo->qi_dqlist.qh_nelems)
67 #define XQMLCK(h) (mutex_lock(&((h)->qh_lock), PINOD))
68 #define XQMUNLCK(h) (mutex_unlock(&((h)->qh_lock)))
69 #ifdef DEBUG
70 struct xfs_dqhash;
71 static inline int XQMISLCKD(struct xfs_dqhash *h)
73 if (mutex_trylock(&h->qh_lock)) {
74 mutex_unlock(&h->qh_lock);
75 return 0;
77 return 1;
79 #endif
81 #define XFS_DQ_HASH_LOCK(h) XQMLCK(h)
82 #define XFS_DQ_HASH_UNLOCK(h) XQMUNLCK(h)
83 #define XFS_DQ_IS_HASH_LOCKED(h) XQMISLCKD(h)
85 #define xfs_qm_mplist_lock(mp) XQMLCK(&(XFS_QI_MPL_LIST(mp)))
86 #define xfs_qm_mplist_unlock(mp) XQMUNLCK(&(XFS_QI_MPL_LIST(mp)))
87 #define XFS_QM_IS_MPLIST_LOCKED(mp) XQMISLCKD(&(XFS_QI_MPL_LIST(mp)))
89 #define xfs_qm_freelist_lock(qm) XQMLCK(&((qm)->qm_dqfreelist))
90 #define xfs_qm_freelist_unlock(qm) XQMUNLCK(&((qm)->qm_dqfreelist))
91 #define XFS_QM_IS_FREELIST_LOCKED(qm) XQMISLCKD(&((qm)->qm_dqfreelist))
94 * Hash into a bucket in the dquot hash table, based on <mp, id>.
96 #define XFS_DQ_HASHVAL(mp, id) (((__psunsigned_t)(mp) + \
97 (__psunsigned_t)(id)) & \
98 (xfs_Gqm->qm_dqhashmask - 1))
99 #define XFS_DQ_HASH(mp, id, type) (type == XFS_DQ_USER ? \
100 (xfs_Gqm->qm_usr_dqhtable + \
101 XFS_DQ_HASHVAL(mp, id)) : \
102 (xfs_Gqm->qm_grp_dqhtable + \
103 XFS_DQ_HASHVAL(mp, id)))
104 #define XFS_IS_DQTYPE_ON(mp, type) (type == XFS_DQ_USER ? \
105 XFS_IS_UQUOTA_ON(mp):XFS_IS_GQUOTA_ON(mp))
106 #define XFS_IS_DQUOT_UNINITIALIZED(dqp) ( \
107 !dqp->q_core.d_blk_hardlimit && \
108 !dqp->q_core.d_blk_softlimit && \
109 !dqp->q_core.d_rtb_hardlimit && \
110 !dqp->q_core.d_rtb_softlimit && \
111 !dqp->q_core.d_ino_hardlimit && \
112 !dqp->q_core.d_ino_softlimit && \
113 !dqp->q_core.d_bcount && \
114 !dqp->q_core.d_rtbcount && \
115 !dqp->q_core.d_icount)
117 #define HL_PREVP dq_hashlist.ql_prevp
118 #define HL_NEXT dq_hashlist.ql_next
119 #define MPL_PREVP dq_mplist.ql_prevp
120 #define MPL_NEXT dq_mplist.ql_next
123 #define _LIST_REMOVE(h, dqp, PVP, NXT) \
125 xfs_dquot_t *d; \
126 if (((d) = (dqp)->NXT)) \
127 (d)->PVP = (dqp)->PVP; \
128 *((dqp)->PVP) = d; \
129 (dqp)->NXT = NULL; \
130 (dqp)->PVP = NULL; \
131 (h)->qh_version++; \
132 (h)->qh_nelems--; \
135 #define _LIST_INSERT(h, dqp, PVP, NXT) \
137 xfs_dquot_t *d; \
138 if (((d) = (h)->qh_next)) \
139 (d)->PVP = &((dqp)->NXT); \
140 (dqp)->NXT = d; \
141 (dqp)->PVP = &((h)->qh_next); \
142 (h)->qh_next = dqp; \
143 (h)->qh_version++; \
144 (h)->qh_nelems++; \
147 #define FOREACH_DQUOT_IN_MP(dqp, mp) \
148 for ((dqp) = XFS_QI_MPLNEXT(mp); (dqp) != NULL; (dqp) = (dqp)->MPL_NEXT)
150 #define FOREACH_DQUOT_IN_FREELIST(dqp, qlist) \
151 for ((dqp) = (qlist)->qh_next; (dqp) != (xfs_dquot_t *)(qlist); \
152 (dqp) = (dqp)->dq_flnext)
154 #define XQM_HASHLIST_INSERT(h, dqp) \
155 _LIST_INSERT(h, dqp, HL_PREVP, HL_NEXT)
157 #define XQM_FREELIST_INSERT(h, dqp) \
158 xfs_qm_freelist_append(h, dqp)
160 #define XQM_MPLIST_INSERT(h, dqp) \
161 _LIST_INSERT(h, dqp, MPL_PREVP, MPL_NEXT)
163 #define XQM_HASHLIST_REMOVE(h, dqp) \
164 _LIST_REMOVE(h, dqp, HL_PREVP, HL_NEXT)
165 #define XQM_FREELIST_REMOVE(dqp) \
166 xfs_qm_freelist_unlink(dqp)
167 #define XQM_MPLIST_REMOVE(h, dqp) \
168 { _LIST_REMOVE(h, dqp, MPL_PREVP, MPL_NEXT); \
169 XFS_QI_MPLRECLAIMS((dqp)->q_mount)++; }
171 #define XFS_DQ_IS_LOGITEM_INITD(dqp) ((dqp)->q_logitem.qli_dquot == (dqp))
173 #define XFS_QM_DQP_TO_DQACCT(tp, dqp) (XFS_QM_ISUDQ(dqp) ? \
174 (tp)->t_dqinfo->dqa_usrdquots : \
175 (tp)->t_dqinfo->dqa_grpdquots)
176 #define XFS_IS_SUSER_DQUOT(dqp) \
177 (!((dqp)->q_core.d_id))
179 #define XFS_PURGE_INODE(ip) \
181 vmap_t dqvmap; \
182 vnode_t *dqvp; \
183 dqvp = XFS_ITOV(ip); \
184 VMAP(dqvp, dqvmap); \
185 VN_RELE(dqvp); \
188 #define DQFLAGTO_TYPESTR(d) (((d)->dq_flags & XFS_DQ_USER) ? "USR" : \
189 (((d)->dq_flags & XFS_DQ_GROUP) ? "GRP" : "???"))
190 #define DQFLAGTO_DIRTYSTR(d) (XFS_DQ_IS_DIRTY(d) ? "DIRTY" : "NOTDIRTY")
192 #endif /* __XFS_QUOTA_PRIV_H__ */