xfs_quota_priv.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. * Number of bmaps that we ask from bmapi when doing a quotacheck.
  36. * We make this restriction to keep the memory usage to a minimum.
  37. */
  38. #define XFS_DQITER_MAP_SIZE 10
  39. /* Number of dquots that fit in to a dquot block */
  40. #define XFS_QM_DQPERBLK(mp) ((mp)->m_quotainfo->qi_dqperchunk)
  41. #define XFS_ISLOCKED_INODE(ip) (ismrlocked(&(ip)->i_lock, \
  42. MR_UPDATE | MR_ACCESS) != 0)
  43. #define XFS_ISLOCKED_INODE_EXCL(ip) (ismrlocked(&(ip)->i_lock, \
  44. MR_UPDATE) != 0)
  45. #define XFS_DQ_IS_ADDEDTO_TRX(t, d) ((d)->q_transp == (t))
  46. #define XFS_QI_MPLRECLAIMS(mp) ((mp)->m_quotainfo->qi_dqreclaims)
  47. #define XFS_QI_UQIP(mp) ((mp)->m_quotainfo->qi_uquotaip)
  48. #define XFS_QI_GQIP(mp) ((mp)->m_quotainfo->qi_gquotaip)
  49. #define XFS_QI_DQCHUNKLEN(mp) ((mp)->m_quotainfo->qi_dqchunklen)
  50. #define XFS_QI_BTIMELIMIT(mp) ((mp)->m_quotainfo->qi_btimelimit)
  51. #define XFS_QI_RTBTIMELIMIT(mp) ((mp)->m_quotainfo->qi_rtbtimelimit)
  52. #define XFS_QI_ITIMELIMIT(mp) ((mp)->m_quotainfo->qi_itimelimit)
  53. #define XFS_QI_BWARNLIMIT(mp) ((mp)->m_quotainfo->qi_bwarnlimit)
  54. #define XFS_QI_RTBWARNLIMIT(mp) ((mp)->m_quotainfo->qi_rtbwarnlimit)
  55. #define XFS_QI_IWARNLIMIT(mp) ((mp)->m_quotainfo->qi_iwarnlimit)
  56. #define XFS_QI_QOFFLOCK(mp) ((mp)->m_quotainfo->qi_quotaofflock)
  57. #define XFS_QI_MPL_LIST(mp) ((mp)->m_quotainfo->qi_dqlist)
  58. #define XFS_QI_MPLLOCK(mp) ((mp)->m_quotainfo->qi_dqlist.qh_lock)
  59. #define XFS_QI_MPLNEXT(mp) ((mp)->m_quotainfo->qi_dqlist.qh_next)
  60. #define XFS_QI_MPLNDQUOTS(mp) ((mp)->m_quotainfo->qi_dqlist.qh_nelems)
  61. #define XQMLCK(h) (mutex_lock(&((h)->qh_lock), PINOD))
  62. #define XQMUNLCK(h) (mutex_unlock(&((h)->qh_lock)))
  63. #ifdef DEBUG
  64. struct xfs_dqhash;
  65. static inline int XQMISLCKD(struct xfs_dqhash *h)
  66. {
  67. if (mutex_trylock(&h->qh_lock)) {
  68. mutex_unlock(&h->qh_lock);
  69. return 0;
  70. }
  71. return 1;
  72. }
  73. #endif
  74. #define XFS_DQ_HASH_LOCK(h) XQMLCK(h)
  75. #define XFS_DQ_HASH_UNLOCK(h) XQMUNLCK(h)
  76. #define XFS_DQ_IS_HASH_LOCKED(h) XQMISLCKD(h)
  77. #define xfs_qm_mplist_lock(mp) XQMLCK(&(XFS_QI_MPL_LIST(mp)))
  78. #define xfs_qm_mplist_unlock(mp) XQMUNLCK(&(XFS_QI_MPL_LIST(mp)))
  79. #define XFS_QM_IS_MPLIST_LOCKED(mp) XQMISLCKD(&(XFS_QI_MPL_LIST(mp)))
  80. #define xfs_qm_freelist_lock(qm) XQMLCK(&((qm)->qm_dqfreelist))
  81. #define xfs_qm_freelist_unlock(qm) XQMUNLCK(&((qm)->qm_dqfreelist))
  82. #define XFS_QM_IS_FREELIST_LOCKED(qm) XQMISLCKD(&((qm)->qm_dqfreelist))
  83. /*
  84. * Hash into a bucket in the dquot hash table, based on <mp, id>.
  85. */
  86. #define XFS_DQ_HASHVAL(mp, id) (((__psunsigned_t)(mp) + \
  87. (__psunsigned_t)(id)) & \
  88. (xfs_Gqm->qm_dqhashmask - 1))
  89. #define XFS_DQ_HASH(mp, id, type) (type == XFS_DQ_USER ? \
  90. (xfs_Gqm->qm_usr_dqhtable + \
  91. XFS_DQ_HASHVAL(mp, id)) : \
  92. (xfs_Gqm->qm_grp_dqhtable + \
  93. XFS_DQ_HASHVAL(mp, id)))
  94. #define XFS_IS_DQTYPE_ON(mp, type) (type == XFS_DQ_USER ? \
  95. XFS_IS_UQUOTA_ON(mp) : \
  96. XFS_IS_OQUOTA_ON(mp))
  97. #define XFS_IS_DQUOT_UNINITIALIZED(dqp) ( \
  98. !dqp->q_core.d_blk_hardlimit && \
  99. !dqp->q_core.d_blk_softlimit && \
  100. !dqp->q_core.d_rtb_hardlimit && \
  101. !dqp->q_core.d_rtb_softlimit && \
  102. !dqp->q_core.d_ino_hardlimit && \
  103. !dqp->q_core.d_ino_softlimit && \
  104. !dqp->q_core.d_bcount && \
  105. !dqp->q_core.d_rtbcount && \
  106. !dqp->q_core.d_icount)
  107. #define HL_PREVP dq_hashlist.ql_prevp
  108. #define HL_NEXT dq_hashlist.ql_next
  109. #define MPL_PREVP dq_mplist.ql_prevp
  110. #define MPL_NEXT dq_mplist.ql_next
  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. #define _LIST_INSERT(h, dqp, PVP, NXT) \
  123. { \
  124. xfs_dquot_t *d; \
  125. if (((d) = (h)->qh_next)) \
  126. (d)->PVP = &((dqp)->NXT); \
  127. (dqp)->NXT = d; \
  128. (dqp)->PVP = &((h)->qh_next); \
  129. (h)->qh_next = dqp; \
  130. (h)->qh_version++; \
  131. (h)->qh_nelems++; \
  132. }
  133. #define FOREACH_DQUOT_IN_MP(dqp, mp) \
  134. for ((dqp) = XFS_QI_MPLNEXT(mp); (dqp) != NULL; (dqp) = (dqp)->MPL_NEXT)
  135. #define FOREACH_DQUOT_IN_FREELIST(dqp, qlist) \
  136. for ((dqp) = (qlist)->qh_next; (dqp) != (xfs_dquot_t *)(qlist); \
  137. (dqp) = (dqp)->dq_flnext)
  138. #define XQM_HASHLIST_INSERT(h, dqp) \
  139. _LIST_INSERT(h, dqp, HL_PREVP, HL_NEXT)
  140. #define XQM_FREELIST_INSERT(h, dqp) \
  141. xfs_qm_freelist_append(h, dqp)
  142. #define XQM_MPLIST_INSERT(h, dqp) \
  143. _LIST_INSERT(h, dqp, MPL_PREVP, MPL_NEXT)
  144. #define XQM_HASHLIST_REMOVE(h, dqp) \
  145. _LIST_REMOVE(h, dqp, HL_PREVP, HL_NEXT)
  146. #define XQM_FREELIST_REMOVE(dqp) \
  147. xfs_qm_freelist_unlink(dqp)
  148. #define XQM_MPLIST_REMOVE(h, dqp) \
  149. { _LIST_REMOVE(h, dqp, MPL_PREVP, MPL_NEXT); \
  150. XFS_QI_MPLRECLAIMS((dqp)->q_mount)++; }
  151. #define XFS_DQ_IS_LOGITEM_INITD(dqp) ((dqp)->q_logitem.qli_dquot == (dqp))
  152. #define XFS_QM_DQP_TO_DQACCT(tp, dqp) (XFS_QM_ISUDQ(dqp) ? \
  153. (tp)->t_dqinfo->dqa_usrdquots : \
  154. (tp)->t_dqinfo->dqa_grpdquots)
  155. #define XFS_IS_SUSER_DQUOT(dqp) \
  156. (!((dqp)->q_core.d_id))
  157. #define XFS_PURGE_INODE(ip) \
  158. IRELE(ip);
  159. #define DQFLAGTO_TYPESTR(d) (((d)->dq_flags & XFS_DQ_USER) ? "USR" : \
  160. (((d)->dq_flags & XFS_DQ_GROUP) ? "GRP" : \
  161. (((d)->dq_flags & XFS_DQ_PROJ) ? "PRJ":"???")))
  162. #define DQFLAGTO_DIRTYSTR(d) (XFS_DQ_IS_DIRTY(d) ? "DIRTY" : "NOTDIRTY")
  163. #endif /* __XFS_QUOTA_PRIV_H__ */