Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved. |
| 3 | * |
| 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. |
| 7 | * |
| 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. |
| 11 | * |
| 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. |
| 18 | * |
| 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. |
| 22 | * |
| 23 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 24 | * Mountain View, CA 94043, or: |
| 25 | * |
| 26 | * http://www.sgi.com |
| 27 | * |
| 28 | * For further information regarding this notice, see: |
| 29 | * |
| 30 | * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ |
| 31 | */ |
| 32 | #ifndef __XFS_QUOTA_PRIV_H__ |
| 33 | #define __XFS_QUOTA_PRIV_H__ |
| 34 | |
| 35 | /* |
| 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. |
| 38 | */ |
| 39 | #define XFS_DQITER_MAP_SIZE 10 |
| 40 | |
| 41 | /* Number of dquots that fit in to a dquot block */ |
| 42 | #define XFS_QM_DQPERBLK(mp) ((mp)->m_quotainfo->qi_dqperchunk) |
| 43 | |
| 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) |
| 48 | |
| 49 | #define XFS_DQ_IS_ADDEDTO_TRX(t, d) ((d)->q_transp == (t)) |
| 50 | |
| 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) |
| 61 | |
| 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) |
| 66 | |
| 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) |
| 72 | { |
| 73 | if (mutex_trylock(&h->qh_lock)) { |
| 74 | mutex_unlock(&h->qh_lock); |
| 75 | return 0; |
| 76 | } |
| 77 | return 1; |
| 78 | } |
| 79 | #endif |
| 80 | |
| 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) |
| 84 | |
| 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))) |
| 88 | |
| 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)) |
| 92 | |
| 93 | /* |
| 94 | * Hash into a bucket in the dquot hash table, based on <mp, id>. |
| 95 | */ |
| 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 ? \ |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame^] | 105 | XFS_IS_UQUOTA_ON(mp) : \ |
| 106 | XFS_IS_OQUOTA_ON(mp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | #define XFS_IS_DQUOT_UNINITIALIZED(dqp) ( \ |
| 108 | !dqp->q_core.d_blk_hardlimit && \ |
| 109 | !dqp->q_core.d_blk_softlimit && \ |
| 110 | !dqp->q_core.d_rtb_hardlimit && \ |
| 111 | !dqp->q_core.d_rtb_softlimit && \ |
| 112 | !dqp->q_core.d_ino_hardlimit && \ |
| 113 | !dqp->q_core.d_ino_softlimit && \ |
| 114 | !dqp->q_core.d_bcount && \ |
| 115 | !dqp->q_core.d_rtbcount && \ |
| 116 | !dqp->q_core.d_icount) |
| 117 | |
| 118 | #define HL_PREVP dq_hashlist.ql_prevp |
| 119 | #define HL_NEXT dq_hashlist.ql_next |
| 120 | #define MPL_PREVP dq_mplist.ql_prevp |
| 121 | #define MPL_NEXT dq_mplist.ql_next |
| 122 | |
| 123 | |
| 124 | #define _LIST_REMOVE(h, dqp, PVP, NXT) \ |
| 125 | { \ |
| 126 | xfs_dquot_t *d; \ |
| 127 | if (((d) = (dqp)->NXT)) \ |
| 128 | (d)->PVP = (dqp)->PVP; \ |
| 129 | *((dqp)->PVP) = d; \ |
| 130 | (dqp)->NXT = NULL; \ |
| 131 | (dqp)->PVP = NULL; \ |
| 132 | (h)->qh_version++; \ |
| 133 | (h)->qh_nelems--; \ |
| 134 | } |
| 135 | |
| 136 | #define _LIST_INSERT(h, dqp, PVP, NXT) \ |
| 137 | { \ |
| 138 | xfs_dquot_t *d; \ |
| 139 | if (((d) = (h)->qh_next)) \ |
| 140 | (d)->PVP = &((dqp)->NXT); \ |
| 141 | (dqp)->NXT = d; \ |
| 142 | (dqp)->PVP = &((h)->qh_next); \ |
| 143 | (h)->qh_next = dqp; \ |
| 144 | (h)->qh_version++; \ |
| 145 | (h)->qh_nelems++; \ |
| 146 | } |
| 147 | |
| 148 | #define FOREACH_DQUOT_IN_MP(dqp, mp) \ |
| 149 | for ((dqp) = XFS_QI_MPLNEXT(mp); (dqp) != NULL; (dqp) = (dqp)->MPL_NEXT) |
| 150 | |
| 151 | #define FOREACH_DQUOT_IN_FREELIST(dqp, qlist) \ |
| 152 | for ((dqp) = (qlist)->qh_next; (dqp) != (xfs_dquot_t *)(qlist); \ |
| 153 | (dqp) = (dqp)->dq_flnext) |
| 154 | |
| 155 | #define XQM_HASHLIST_INSERT(h, dqp) \ |
| 156 | _LIST_INSERT(h, dqp, HL_PREVP, HL_NEXT) |
| 157 | |
| 158 | #define XQM_FREELIST_INSERT(h, dqp) \ |
| 159 | xfs_qm_freelist_append(h, dqp) |
| 160 | |
| 161 | #define XQM_MPLIST_INSERT(h, dqp) \ |
| 162 | _LIST_INSERT(h, dqp, MPL_PREVP, MPL_NEXT) |
| 163 | |
| 164 | #define XQM_HASHLIST_REMOVE(h, dqp) \ |
| 165 | _LIST_REMOVE(h, dqp, HL_PREVP, HL_NEXT) |
| 166 | #define XQM_FREELIST_REMOVE(dqp) \ |
| 167 | xfs_qm_freelist_unlink(dqp) |
| 168 | #define XQM_MPLIST_REMOVE(h, dqp) \ |
| 169 | { _LIST_REMOVE(h, dqp, MPL_PREVP, MPL_NEXT); \ |
| 170 | XFS_QI_MPLRECLAIMS((dqp)->q_mount)++; } |
| 171 | |
| 172 | #define XFS_DQ_IS_LOGITEM_INITD(dqp) ((dqp)->q_logitem.qli_dquot == (dqp)) |
| 173 | |
| 174 | #define XFS_QM_DQP_TO_DQACCT(tp, dqp) (XFS_QM_ISUDQ(dqp) ? \ |
| 175 | (tp)->t_dqinfo->dqa_usrdquots : \ |
| 176 | (tp)->t_dqinfo->dqa_grpdquots) |
| 177 | #define XFS_IS_SUSER_DQUOT(dqp) \ |
| 178 | (!((dqp)->q_core.d_id)) |
| 179 | |
| 180 | #define XFS_PURGE_INODE(ip) \ |
Christoph Hellwig | 66f58d2 | 2005-06-21 15:37:43 +1000 | [diff] [blame] | 181 | IRELE(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
| 183 | #define DQFLAGTO_TYPESTR(d) (((d)->dq_flags & XFS_DQ_USER) ? "USR" : \ |
Nathan Scott | c8ad20f | 2005-06-21 15:38:48 +1000 | [diff] [blame^] | 184 | (((d)->dq_flags & XFS_DQ_GROUP) ? "GRP" : \ |
| 185 | (((d)->dq_flags & XFS_DQ_PROJ) ? "PRJ":"???"))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | #define DQFLAGTO_DIRTYSTR(d) (XFS_DQ_IS_DIRTY(d) ? "DIRTY" : "NOTDIRTY") |
| 187 | |
| 188 | #endif /* __XFS_QUOTA_PRIV_H__ */ |