Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/shaggy...
[linux-2.6] / fs / xfs / quota / xfs_quota_priv.h
1 /*
2  * Copyright (c) 2000-2003 Silicon Graphics, Inc.
3  * All Rights Reserved.
4  *
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.
8  *
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.
13  *
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
17  */
18 #ifndef __XFS_QUOTA_PRIV_H__
19 #define __XFS_QUOTA_PRIV_H__
20
21 /*
22  * Number of bmaps that we ask from bmapi when doing a quotacheck.
23  * We make this restriction to keep the memory usage to a minimum.
24  */
25 #define XFS_DQITER_MAP_SIZE     10
26
27 /* Number of dquots that fit in to a dquot block */
28 #define XFS_QM_DQPERBLK(mp)     ((mp)->m_quotainfo->qi_dqperchunk)
29
30 #define XFS_DQ_IS_ADDEDTO_TRX(t, d)     ((d)->q_transp == (t))
31
32 #define XFS_QI_MPLRECLAIMS(mp)  ((mp)->m_quotainfo->qi_dqreclaims)
33 #define XFS_QI_UQIP(mp)         ((mp)->m_quotainfo->qi_uquotaip)
34 #define XFS_QI_GQIP(mp)         ((mp)->m_quotainfo->qi_gquotaip)
35 #define XFS_QI_DQCHUNKLEN(mp)   ((mp)->m_quotainfo->qi_dqchunklen)
36 #define XFS_QI_BTIMELIMIT(mp)   ((mp)->m_quotainfo->qi_btimelimit)
37 #define XFS_QI_RTBTIMELIMIT(mp) ((mp)->m_quotainfo->qi_rtbtimelimit)
38 #define XFS_QI_ITIMELIMIT(mp)   ((mp)->m_quotainfo->qi_itimelimit)
39 #define XFS_QI_BWARNLIMIT(mp)   ((mp)->m_quotainfo->qi_bwarnlimit)
40 #define XFS_QI_RTBWARNLIMIT(mp) ((mp)->m_quotainfo->qi_rtbwarnlimit)
41 #define XFS_QI_IWARNLIMIT(mp)   ((mp)->m_quotainfo->qi_iwarnlimit)
42 #define XFS_QI_QOFFLOCK(mp)     ((mp)->m_quotainfo->qi_quotaofflock)
43
44 #define XFS_QI_MPL_LIST(mp)     ((mp)->m_quotainfo->qi_dqlist)
45 #define XFS_QI_MPLNEXT(mp)      ((mp)->m_quotainfo->qi_dqlist.qh_next)
46 #define XFS_QI_MPLNDQUOTS(mp)   ((mp)->m_quotainfo->qi_dqlist.qh_nelems)
47
48 #define xfs_qm_mplist_lock(mp) \
49         mutex_lock(&(XFS_QI_MPL_LIST(mp).qh_lock))
50 #define xfs_qm_mplist_nowait(mp) \
51         mutex_trylock(&(XFS_QI_MPL_LIST(mp).qh_lock))
52 #define xfs_qm_mplist_unlock(mp) \
53         mutex_unlock(&(XFS_QI_MPL_LIST(mp).qh_lock))
54 #define XFS_QM_IS_MPLIST_LOCKED(mp) \
55         mutex_is_locked(&(XFS_QI_MPL_LIST(mp).qh_lock))
56
57 #define xfs_qm_freelist_lock(qm) \
58         mutex_lock(&((qm)->qm_dqfreelist.qh_lock))
59 #define xfs_qm_freelist_lock_nowait(qm) \
60         mutex_trylock(&((qm)->qm_dqfreelist.qh_lock))
61 #define xfs_qm_freelist_unlock(qm) \
62         mutex_unlock(&((qm)->qm_dqfreelist.qh_lock))
63
64 /*
65  * Hash into a bucket in the dquot hash table, based on <mp, id>.
66  */
67 #define XFS_DQ_HASHVAL(mp, id) (((__psunsigned_t)(mp) + \
68                                  (__psunsigned_t)(id)) & \
69                                 (xfs_Gqm->qm_dqhashmask - 1))
70 #define XFS_DQ_HASH(mp, id, type)   (type == XFS_DQ_USER ? \
71                                      (xfs_Gqm->qm_usr_dqhtable + \
72                                       XFS_DQ_HASHVAL(mp, id)) : \
73                                      (xfs_Gqm->qm_grp_dqhtable + \
74                                       XFS_DQ_HASHVAL(mp, id)))
75 #define XFS_IS_DQTYPE_ON(mp, type)   (type == XFS_DQ_USER ? \
76                                         XFS_IS_UQUOTA_ON(mp) : \
77                                         XFS_IS_OQUOTA_ON(mp))
78 #define XFS_IS_DQUOT_UNINITIALIZED(dqp) ( \
79         !dqp->q_core.d_blk_hardlimit && \
80         !dqp->q_core.d_blk_softlimit && \
81         !dqp->q_core.d_rtb_hardlimit && \
82         !dqp->q_core.d_rtb_softlimit && \
83         !dqp->q_core.d_ino_hardlimit && \
84         !dqp->q_core.d_ino_softlimit && \
85         !dqp->q_core.d_bcount && \
86         !dqp->q_core.d_rtbcount && \
87         !dqp->q_core.d_icount)
88
89 #define HL_PREVP        dq_hashlist.ql_prevp
90 #define HL_NEXT         dq_hashlist.ql_next
91 #define MPL_PREVP       dq_mplist.ql_prevp
92 #define MPL_NEXT        dq_mplist.ql_next
93
94
95 #define _LIST_REMOVE(h, dqp, PVP, NXT)                          \
96         {                                                       \
97                  xfs_dquot_t *d;                                \
98                  if (((d) = (dqp)->NXT))                                \
99                          (d)->PVP = (dqp)->PVP;                 \
100                  *((dqp)->PVP) = d;                             \
101                  (dqp)->NXT = NULL;                             \
102                  (dqp)->PVP = NULL;                             \
103                  (h)->qh_version++;                             \
104                  (h)->qh_nelems--;                              \
105         }
106
107 #define _LIST_INSERT(h, dqp, PVP, NXT)                          \
108         {                                                       \
109                  xfs_dquot_t *d;                                \
110                  if (((d) = (h)->qh_next))                      \
111                          (d)->PVP = &((dqp)->NXT);              \
112                  (dqp)->NXT = d;                                \
113                  (dqp)->PVP = &((h)->qh_next);                  \
114                  (h)->qh_next = dqp;                            \
115                  (h)->qh_version++;                             \
116                  (h)->qh_nelems++;                              \
117          }
118
119 #define FOREACH_DQUOT_IN_MP(dqp, mp) \
120         for ((dqp) = XFS_QI_MPLNEXT(mp); (dqp) != NULL; (dqp) = (dqp)->MPL_NEXT)
121
122 #define FOREACH_DQUOT_IN_FREELIST(dqp, qlist)   \
123 for ((dqp) = (qlist)->qh_next; (dqp) != (xfs_dquot_t *)(qlist); \
124      (dqp) = (dqp)->dq_flnext)
125
126 #define XQM_HASHLIST_INSERT(h, dqp)     \
127          _LIST_INSERT(h, dqp, HL_PREVP, HL_NEXT)
128
129 #define XQM_FREELIST_INSERT(h, dqp)     \
130          xfs_qm_freelist_append(h, dqp)
131
132 #define XQM_MPLIST_INSERT(h, dqp)       \
133          _LIST_INSERT(h, dqp, MPL_PREVP, MPL_NEXT)
134
135 #define XQM_HASHLIST_REMOVE(h, dqp)     \
136          _LIST_REMOVE(h, dqp, HL_PREVP, HL_NEXT)
137 #define XQM_FREELIST_REMOVE(dqp)        \
138          xfs_qm_freelist_unlink(dqp)
139 #define XQM_MPLIST_REMOVE(h, dqp)       \
140         { _LIST_REMOVE(h, dqp, MPL_PREVP, MPL_NEXT); \
141           XFS_QI_MPLRECLAIMS((dqp)->q_mount)++; }
142
143 #define XFS_DQ_IS_LOGITEM_INITD(dqp)    ((dqp)->q_logitem.qli_dquot == (dqp))
144
145 #define XFS_QM_DQP_TO_DQACCT(tp, dqp)   (XFS_QM_ISUDQ(dqp) ? \
146                                          (tp)->t_dqinfo->dqa_usrdquots : \
147                                          (tp)->t_dqinfo->dqa_grpdquots)
148 #define XFS_IS_SUSER_DQUOT(dqp)         \
149         (!((dqp)->q_core.d_id))
150
151 #define DQFLAGTO_TYPESTR(d)     (((d)->dq_flags & XFS_DQ_USER) ? "USR" : \
152                                  (((d)->dq_flags & XFS_DQ_GROUP) ? "GRP" : \
153                                  (((d)->dq_flags & XFS_DQ_PROJ) ? "PRJ":"???")))
154
155 #endif  /* __XFS_QUOTA_PRIV_H__ */