xfs_quota_priv.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. * Number of bmaps that we ask from bmapi when doing a quotacheck.
  22. * We make this restriction to keep the memory usage to a minimum.
  23. */
  24. #define XFS_DQITER_MAP_SIZE 10
  25. /* Number of dquots that fit in to a dquot block */
  26. #define XFS_QM_DQPERBLK(mp) ((mp)->m_quotainfo->qi_dqperchunk)
  27. #define XFS_ISLOCKED_INODE(ip) (ismrlocked(&(ip)->i_lock, \
  28. MR_UPDATE | MR_ACCESS) != 0)
  29. #define XFS_ISLOCKED_INODE_EXCL(ip) (ismrlocked(&(ip)->i_lock, \
  30. MR_UPDATE) != 0)
  31. #define XFS_DQ_IS_ADDEDTO_TRX(t, d) ((d)->q_transp == (t))
  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. #define XFS_QI_MPL_LIST(mp) ((mp)->m_quotainfo->qi_dqlist)
  44. #define XFS_QI_MPLLOCK(mp) ((mp)->m_quotainfo->qi_dqlist.qh_lock)
  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. #define XQMLCK(h) (mutex_lock(&((h)->qh_lock)))
  48. #define XQMUNLCK(h) (mutex_unlock(&((h)->qh_lock)))
  49. #ifdef DEBUG
  50. struct xfs_dqhash;
  51. static inline int XQMISLCKD(struct xfs_dqhash *h)
  52. {
  53. if (mutex_trylock(&h->qh_lock)) {
  54. mutex_unlock(&h->qh_lock);
  55. return 0;
  56. }
  57. return 1;
  58. }
  59. #endif
  60. #define XFS_DQ_HASH_LOCK(h) XQMLCK(h)
  61. #define XFS_DQ_HASH_UNLOCK(h) XQMUNLCK(h)
  62. #define XFS_DQ_IS_HASH_LOCKED(h) XQMISLCKD(h)
  63. #define xfs_qm_mplist_lock(mp) XQMLCK(&(XFS_QI_MPL_LIST(mp)))
  64. #define xfs_qm_mplist_unlock(mp) XQMUNLCK(&(XFS_QI_MPL_LIST(mp)))
  65. #define XFS_QM_IS_MPLIST_LOCKED(mp) XQMISLCKD(&(XFS_QI_MPL_LIST(mp)))
  66. #define xfs_qm_freelist_lock(qm) XQMLCK(&((qm)->qm_dqfreelist))
  67. #define xfs_qm_freelist_unlock(qm) XQMUNLCK(&((qm)->qm_dqfreelist))
  68. /*
  69. * Hash into a bucket in the dquot hash table, based on <mp, id>.
  70. */
  71. #define XFS_DQ_HASHVAL(mp, id) (((__psunsigned_t)(mp) + \
  72. (__psunsigned_t)(id)) & \
  73. (xfs_Gqm->qm_dqhashmask - 1))
  74. #define XFS_DQ_HASH(mp, id, type) (type == XFS_DQ_USER ? \
  75. (xfs_Gqm->qm_usr_dqhtable + \
  76. XFS_DQ_HASHVAL(mp, id)) : \
  77. (xfs_Gqm->qm_grp_dqhtable + \
  78. XFS_DQ_HASHVAL(mp, id)))
  79. #define XFS_IS_DQTYPE_ON(mp, type) (type == XFS_DQ_USER ? \
  80. XFS_IS_UQUOTA_ON(mp) : \
  81. XFS_IS_OQUOTA_ON(mp))
  82. #define XFS_IS_DQUOT_UNINITIALIZED(dqp) ( \
  83. !dqp->q_core.d_blk_hardlimit && \
  84. !dqp->q_core.d_blk_softlimit && \
  85. !dqp->q_core.d_rtb_hardlimit && \
  86. !dqp->q_core.d_rtb_softlimit && \
  87. !dqp->q_core.d_ino_hardlimit && \
  88. !dqp->q_core.d_ino_softlimit && \
  89. !dqp->q_core.d_bcount && \
  90. !dqp->q_core.d_rtbcount && \
  91. !dqp->q_core.d_icount)
  92. #define HL_PREVP dq_hashlist.ql_prevp
  93. #define HL_NEXT dq_hashlist.ql_next
  94. #define MPL_PREVP dq_mplist.ql_prevp
  95. #define MPL_NEXT dq_mplist.ql_next
  96. #define _LIST_REMOVE(h, dqp, PVP, NXT) \
  97. { \
  98. xfs_dquot_t *d; \
  99. if (((d) = (dqp)->NXT)) \
  100. (d)->PVP = (dqp)->PVP; \
  101. *((dqp)->PVP) = d; \
  102. (dqp)->NXT = NULL; \
  103. (dqp)->PVP = NULL; \
  104. (h)->qh_version++; \
  105. (h)->qh_nelems--; \
  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. #define FOREACH_DQUOT_IN_MP(dqp, mp) \
  119. for ((dqp) = XFS_QI_MPLNEXT(mp); (dqp) != NULL; (dqp) = (dqp)->MPL_NEXT)
  120. #define FOREACH_DQUOT_IN_FREELIST(dqp, qlist) \
  121. for ((dqp) = (qlist)->qh_next; (dqp) != (xfs_dquot_t *)(qlist); \
  122. (dqp) = (dqp)->dq_flnext)
  123. #define XQM_HASHLIST_INSERT(h, dqp) \
  124. _LIST_INSERT(h, dqp, HL_PREVP, HL_NEXT)
  125. #define XQM_FREELIST_INSERT(h, dqp) \
  126. xfs_qm_freelist_append(h, dqp)
  127. #define XQM_MPLIST_INSERT(h, dqp) \
  128. _LIST_INSERT(h, dqp, MPL_PREVP, MPL_NEXT)
  129. #define XQM_HASHLIST_REMOVE(h, dqp) \
  130. _LIST_REMOVE(h, dqp, HL_PREVP, HL_NEXT)
  131. #define XQM_FREELIST_REMOVE(dqp) \
  132. xfs_qm_freelist_unlink(dqp)
  133. #define XQM_MPLIST_REMOVE(h, dqp) \
  134. { _LIST_REMOVE(h, dqp, MPL_PREVP, MPL_NEXT); \
  135. XFS_QI_MPLRECLAIMS((dqp)->q_mount)++; }
  136. #define XFS_DQ_IS_LOGITEM_INITD(dqp) ((dqp)->q_logitem.qli_dquot == (dqp))
  137. #define XFS_QM_DQP_TO_DQACCT(tp, dqp) (XFS_QM_ISUDQ(dqp) ? \
  138. (tp)->t_dqinfo->dqa_usrdquots : \
  139. (tp)->t_dqinfo->dqa_grpdquots)
  140. #define XFS_IS_SUSER_DQUOT(dqp) \
  141. (!((dqp)->q_core.d_id))
  142. #define XFS_PURGE_INODE(ip) \
  143. IRELE(ip);
  144. #define DQFLAGTO_TYPESTR(d) (((d)->dq_flags & XFS_DQ_USER) ? "USR" : \
  145. (((d)->dq_flags & XFS_DQ_GROUP) ? "GRP" : \
  146. (((d)->dq_flags & XFS_DQ_PROJ) ? "PRJ":"???")))
  147. #endif /* __XFS_QUOTA_PRIV_H__ */