]> err.no Git - linux-2.6/blob - fs/xfs/quota/xfs_quota_priv.h
Merge master.kernel.org:/pub/scm/linux/kernel/git/dtor/input
[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_ISLOCKED_INODE(ip)          (ismrlocked(&(ip)->i_lock, \
31                                             MR_UPDATE | MR_ACCESS) != 0)
32 #define XFS_ISLOCKED_INODE_EXCL(ip)     (ismrlocked(&(ip)->i_lock, \
33                                             MR_UPDATE) != 0)
34
35 #define XFS_DQ_IS_ADDEDTO_TRX(t, d)     ((d)->q_transp == (t))
36
37 #define XFS_QI_MPLRECLAIMS(mp)  ((mp)->m_quotainfo->qi_dqreclaims)
38 #define XFS_QI_UQIP(mp)         ((mp)->m_quotainfo->qi_uquotaip)
39 #define XFS_QI_GQIP(mp)         ((mp)->m_quotainfo->qi_gquotaip)
40 #define XFS_QI_DQCHUNKLEN(mp)   ((mp)->m_quotainfo->qi_dqchunklen)
41 #define XFS_QI_BTIMELIMIT(mp)   ((mp)->m_quotainfo->qi_btimelimit)
42 #define XFS_QI_RTBTIMELIMIT(mp) ((mp)->m_quotainfo->qi_rtbtimelimit)
43 #define XFS_QI_ITIMELIMIT(mp)   ((mp)->m_quotainfo->qi_itimelimit)
44 #define XFS_QI_BWARNLIMIT(mp)   ((mp)->m_quotainfo->qi_bwarnlimit)
45 #define XFS_QI_RTBWARNLIMIT(mp) ((mp)->m_quotainfo->qi_rtbwarnlimit)
46 #define XFS_QI_IWARNLIMIT(mp)   ((mp)->m_quotainfo->qi_iwarnlimit)
47 #define XFS_QI_QOFFLOCK(mp)     ((mp)->m_quotainfo->qi_quotaofflock)
48
49 #define XFS_QI_MPL_LIST(mp)     ((mp)->m_quotainfo->qi_dqlist)
50 #define XFS_QI_MPLLOCK(mp)      ((mp)->m_quotainfo->qi_dqlist.qh_lock)
51 #define XFS_QI_MPLNEXT(mp)      ((mp)->m_quotainfo->qi_dqlist.qh_next)
52 #define XFS_QI_MPLNDQUOTS(mp)   ((mp)->m_quotainfo->qi_dqlist.qh_nelems)
53
54 #define XQMLCK(h)                       (mutex_lock(&((h)->qh_lock)))
55 #define XQMUNLCK(h)                     (mutex_unlock(&((h)->qh_lock)))
56 #ifdef DEBUG
57 struct xfs_dqhash;
58 static inline int XQMISLCKD(struct xfs_dqhash *h)
59 {
60         if (mutex_trylock(&h->qh_lock)) {
61                 mutex_unlock(&h->qh_lock);
62                 return 0;
63         }
64         return 1;
65 }
66 #endif
67
68 #define XFS_DQ_HASH_LOCK(h)             XQMLCK(h)
69 #define XFS_DQ_HASH_UNLOCK(h)           XQMUNLCK(h)
70 #define XFS_DQ_IS_HASH_LOCKED(h)        XQMISLCKD(h)
71
72 #define xfs_qm_mplist_lock(mp)          XQMLCK(&(XFS_QI_MPL_LIST(mp)))
73 #define xfs_qm_mplist_unlock(mp)        XQMUNLCK(&(XFS_QI_MPL_LIST(mp)))
74 #define XFS_QM_IS_MPLIST_LOCKED(mp)     XQMISLCKD(&(XFS_QI_MPL_LIST(mp)))
75
76 #define xfs_qm_freelist_lock(qm)        XQMLCK(&((qm)->qm_dqfreelist))
77 #define xfs_qm_freelist_unlock(qm)      XQMUNLCK(&((qm)->qm_dqfreelist))
78 #define XFS_QM_IS_FREELIST_LOCKED(qm)   XQMISLCKD(&((qm)->qm_dqfreelist))
79
80 /*
81  * Hash into a bucket in the dquot hash table, based on <mp, id>.
82  */
83 #define XFS_DQ_HASHVAL(mp, id) (((__psunsigned_t)(mp) + \
84                                  (__psunsigned_t)(id)) & \
85                                 (xfs_Gqm->qm_dqhashmask - 1))
86 #define XFS_DQ_HASH(mp, id, type)   (type == XFS_DQ_USER ? \
87                                      (xfs_Gqm->qm_usr_dqhtable + \
88                                       XFS_DQ_HASHVAL(mp, id)) : \
89                                      (xfs_Gqm->qm_grp_dqhtable + \
90                                       XFS_DQ_HASHVAL(mp, id)))
91 #define XFS_IS_DQTYPE_ON(mp, type)   (type == XFS_DQ_USER ? \
92                                         XFS_IS_UQUOTA_ON(mp) : \
93                                         XFS_IS_OQUOTA_ON(mp))
94 #define XFS_IS_DQUOT_UNINITIALIZED(dqp) ( \
95         !dqp->q_core.d_blk_hardlimit && \
96         !dqp->q_core.d_blk_softlimit && \
97         !dqp->q_core.d_rtb_hardlimit && \
98         !dqp->q_core.d_rtb_softlimit && \
99         !dqp->q_core.d_ino_hardlimit && \
100         !dqp->q_core.d_ino_softlimit && \
101         !dqp->q_core.d_bcount && \
102         !dqp->q_core.d_rtbcount && \
103         !dqp->q_core.d_icount)
104
105 #define HL_PREVP        dq_hashlist.ql_prevp
106 #define HL_NEXT         dq_hashlist.ql_next
107 #define MPL_PREVP       dq_mplist.ql_prevp
108 #define MPL_NEXT        dq_mplist.ql_next
109
110
111 #define _LIST_REMOVE(h, dqp, PVP, NXT)                          \
112         {                                                       \
113                  xfs_dquot_t *d;                                \
114                  if (((d) = (dqp)->NXT))                                \
115                          (d)->PVP = (dqp)->PVP;                 \
116                  *((dqp)->PVP) = d;                             \
117                  (dqp)->NXT = NULL;                             \
118                  (dqp)->PVP = NULL;                             \
119                  (h)->qh_version++;                             \
120                  (h)->qh_nelems--;                              \
121         }
122
123 #define _LIST_INSERT(h, dqp, PVP, NXT)                          \
124         {                                                       \
125                  xfs_dquot_t *d;                                \
126                  if (((d) = (h)->qh_next))                      \
127                          (d)->PVP = &((dqp)->NXT);              \
128                  (dqp)->NXT = d;                                \
129                  (dqp)->PVP = &((h)->qh_next);                  \
130                  (h)->qh_next = dqp;                            \
131                  (h)->qh_version++;                             \
132                  (h)->qh_nelems++;                              \
133          }
134
135 #define FOREACH_DQUOT_IN_MP(dqp, mp) \
136         for ((dqp) = XFS_QI_MPLNEXT(mp); (dqp) != NULL; (dqp) = (dqp)->MPL_NEXT)
137
138 #define FOREACH_DQUOT_IN_FREELIST(dqp, qlist)   \
139 for ((dqp) = (qlist)->qh_next; (dqp) != (xfs_dquot_t *)(qlist); \
140      (dqp) = (dqp)->dq_flnext)
141
142 #define XQM_HASHLIST_INSERT(h, dqp)     \
143          _LIST_INSERT(h, dqp, HL_PREVP, HL_NEXT)
144
145 #define XQM_FREELIST_INSERT(h, dqp)     \
146          xfs_qm_freelist_append(h, dqp)
147
148 #define XQM_MPLIST_INSERT(h, dqp)       \
149          _LIST_INSERT(h, dqp, MPL_PREVP, MPL_NEXT)
150
151 #define XQM_HASHLIST_REMOVE(h, dqp)     \
152          _LIST_REMOVE(h, dqp, HL_PREVP, HL_NEXT)
153 #define XQM_FREELIST_REMOVE(dqp)        \
154          xfs_qm_freelist_unlink(dqp)
155 #define XQM_MPLIST_REMOVE(h, dqp)       \
156         { _LIST_REMOVE(h, dqp, MPL_PREVP, MPL_NEXT); \
157           XFS_QI_MPLRECLAIMS((dqp)->q_mount)++; }
158
159 #define XFS_DQ_IS_LOGITEM_INITD(dqp)    ((dqp)->q_logitem.qli_dquot == (dqp))
160
161 #define XFS_QM_DQP_TO_DQACCT(tp, dqp)   (XFS_QM_ISUDQ(dqp) ? \
162                                          (tp)->t_dqinfo->dqa_usrdquots : \
163                                          (tp)->t_dqinfo->dqa_grpdquots)
164 #define XFS_IS_SUSER_DQUOT(dqp)         \
165         (!((dqp)->q_core.d_id))
166
167 #define XFS_PURGE_INODE(ip)             \
168         IRELE(ip);
169
170 #define DQFLAGTO_TYPESTR(d)     (((d)->dq_flags & XFS_DQ_USER) ? "USR" : \
171                                  (((d)->dq_flags & XFS_DQ_GROUP) ? "GRP" : \
172                                  (((d)->dq_flags & XFS_DQ_PROJ) ? "PRJ":"???")))
173 #define DQFLAGTO_DIRTYSTR(d)    (XFS_DQ_IS_DIRTY(d) ? "DIRTY" : "NOTDIRTY")
174
175 #endif  /* __XFS_QUOTA_PRIV_H__ */