xfs_quota_priv.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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_DQ_IS_ADDEDTO_TRX(t, d) ((d)->q_transp == (t))
  28. #define XFS_QI_MPLRECLAIMS(mp) ((mp)->m_quotainfo->qi_dqreclaims)
  29. #define XFS_QI_UQIP(mp) ((mp)->m_quotainfo->qi_uquotaip)
  30. #define XFS_QI_GQIP(mp) ((mp)->m_quotainfo->qi_gquotaip)
  31. #define XFS_QI_DQCHUNKLEN(mp) ((mp)->m_quotainfo->qi_dqchunklen)
  32. #define XFS_QI_BTIMELIMIT(mp) ((mp)->m_quotainfo->qi_btimelimit)
  33. #define XFS_QI_RTBTIMELIMIT(mp) ((mp)->m_quotainfo->qi_rtbtimelimit)
  34. #define XFS_QI_ITIMELIMIT(mp) ((mp)->m_quotainfo->qi_itimelimit)
  35. #define XFS_QI_BWARNLIMIT(mp) ((mp)->m_quotainfo->qi_bwarnlimit)
  36. #define XFS_QI_RTBWARNLIMIT(mp) ((mp)->m_quotainfo->qi_rtbwarnlimit)
  37. #define XFS_QI_IWARNLIMIT(mp) ((mp)->m_quotainfo->qi_iwarnlimit)
  38. #define XFS_QI_QOFFLOCK(mp) ((mp)->m_quotainfo->qi_quotaofflock)
  39. #define XFS_QI_MPL_LIST(mp) ((mp)->m_quotainfo->qi_dqlist)
  40. #define XFS_QI_MPLNEXT(mp) ((mp)->m_quotainfo->qi_dqlist.qh_next)
  41. #define XFS_QI_MPLNDQUOTS(mp) ((mp)->m_quotainfo->qi_dqlist.qh_nelems)
  42. #define xfs_qm_mplist_lock(mp) \
  43. mutex_lock(&(XFS_QI_MPL_LIST(mp).qh_lock))
  44. #define xfs_qm_mplist_nowait(mp) \
  45. mutex_trylock(&(XFS_QI_MPL_LIST(mp).qh_lock))
  46. #define xfs_qm_mplist_unlock(mp) \
  47. mutex_unlock(&(XFS_QI_MPL_LIST(mp).qh_lock))
  48. #define XFS_QM_IS_MPLIST_LOCKED(mp) \
  49. mutex_is_locked(&(XFS_QI_MPL_LIST(mp).qh_lock))
  50. #define xfs_qm_freelist_lock(qm) \
  51. mutex_lock(&((qm)->qm_dqfreelist.qh_lock))
  52. #define xfs_qm_freelist_lock_nowait(qm) \
  53. mutex_trylock(&((qm)->qm_dqfreelist.qh_lock))
  54. #define xfs_qm_freelist_unlock(qm) \
  55. mutex_unlock(&((qm)->qm_dqfreelist.qh_lock))
  56. /*
  57. * Hash into a bucket in the dquot hash table, based on <mp, id>.
  58. */
  59. #define XFS_DQ_HASHVAL(mp, id) (((__psunsigned_t)(mp) + \
  60. (__psunsigned_t)(id)) & \
  61. (xfs_Gqm->qm_dqhashmask - 1))
  62. #define XFS_DQ_HASH(mp, id, type) (type == XFS_DQ_USER ? \
  63. (xfs_Gqm->qm_usr_dqhtable + \
  64. XFS_DQ_HASHVAL(mp, id)) : \
  65. (xfs_Gqm->qm_grp_dqhtable + \
  66. XFS_DQ_HASHVAL(mp, id)))
  67. #define XFS_IS_DQTYPE_ON(mp, type) (type == XFS_DQ_USER ? \
  68. XFS_IS_UQUOTA_ON(mp) : \
  69. XFS_IS_OQUOTA_ON(mp))
  70. #define XFS_IS_DQUOT_UNINITIALIZED(dqp) ( \
  71. !dqp->q_core.d_blk_hardlimit && \
  72. !dqp->q_core.d_blk_softlimit && \
  73. !dqp->q_core.d_rtb_hardlimit && \
  74. !dqp->q_core.d_rtb_softlimit && \
  75. !dqp->q_core.d_ino_hardlimit && \
  76. !dqp->q_core.d_ino_softlimit && \
  77. !dqp->q_core.d_bcount && \
  78. !dqp->q_core.d_rtbcount && \
  79. !dqp->q_core.d_icount)
  80. #define HL_PREVP dq_hashlist.ql_prevp
  81. #define HL_NEXT dq_hashlist.ql_next
  82. #define MPL_PREVP dq_mplist.ql_prevp
  83. #define MPL_NEXT dq_mplist.ql_next
  84. #define _LIST_REMOVE(h, dqp, PVP, NXT) \
  85. { \
  86. xfs_dquot_t *d; \
  87. if (((d) = (dqp)->NXT)) \
  88. (d)->PVP = (dqp)->PVP; \
  89. *((dqp)->PVP) = d; \
  90. (dqp)->NXT = NULL; \
  91. (dqp)->PVP = NULL; \
  92. (h)->qh_version++; \
  93. (h)->qh_nelems--; \
  94. }
  95. #define _LIST_INSERT(h, dqp, PVP, NXT) \
  96. { \
  97. xfs_dquot_t *d; \
  98. if (((d) = (h)->qh_next)) \
  99. (d)->PVP = &((dqp)->NXT); \
  100. (dqp)->NXT = d; \
  101. (dqp)->PVP = &((h)->qh_next); \
  102. (h)->qh_next = dqp; \
  103. (h)->qh_version++; \
  104. (h)->qh_nelems++; \
  105. }
  106. #define FOREACH_DQUOT_IN_MP(dqp, mp) \
  107. for ((dqp) = XFS_QI_MPLNEXT(mp); (dqp) != NULL; (dqp) = (dqp)->MPL_NEXT)
  108. #define FOREACH_DQUOT_IN_FREELIST(dqp, qlist) \
  109. for ((dqp) = (qlist)->qh_next; (dqp) != (xfs_dquot_t *)(qlist); \
  110. (dqp) = (dqp)->dq_flnext)
  111. #define XQM_HASHLIST_INSERT(h, dqp) \
  112. _LIST_INSERT(h, dqp, HL_PREVP, HL_NEXT)
  113. #define XQM_FREELIST_INSERT(h, dqp) \
  114. xfs_qm_freelist_append(h, dqp)
  115. #define XQM_MPLIST_INSERT(h, dqp) \
  116. _LIST_INSERT(h, dqp, MPL_PREVP, MPL_NEXT)
  117. #define XQM_HASHLIST_REMOVE(h, dqp) \
  118. _LIST_REMOVE(h, dqp, HL_PREVP, HL_NEXT)
  119. #define XQM_FREELIST_REMOVE(dqp) \
  120. xfs_qm_freelist_unlink(dqp)
  121. #define XQM_MPLIST_REMOVE(h, dqp) \
  122. { _LIST_REMOVE(h, dqp, MPL_PREVP, MPL_NEXT); \
  123. XFS_QI_MPLRECLAIMS((dqp)->q_mount)++; }
  124. #define XFS_DQ_IS_LOGITEM_INITD(dqp) ((dqp)->q_logitem.qli_dquot == (dqp))
  125. #define XFS_QM_DQP_TO_DQACCT(tp, dqp) (XFS_QM_ISUDQ(dqp) ? \
  126. (tp)->t_dqinfo->dqa_usrdquots : \
  127. (tp)->t_dqinfo->dqa_grpdquots)
  128. #define XFS_IS_SUSER_DQUOT(dqp) \
  129. (!((dqp)->q_core.d_id))
  130. #define DQFLAGTO_TYPESTR(d) (((d)->dq_flags & XFS_DQ_USER) ? "USR" : \
  131. (((d)->dq_flags & XFS_DQ_GROUP) ? "GRP" : \
  132. (((d)->dq_flags & XFS_DQ_PROJ) ? "PRJ":"???")))
  133. #endif /* __XFS_QUOTA_PRIV_H__ */