xfs_quota_defs.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Copyright (c) 2000-2005 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_DEFS_H__
  19. #define __XFS_QUOTA_DEFS_H__
  20. /*
  21. * Quota definitions shared between user and kernel source trees.
  22. */
  23. /*
  24. * Even though users may not have quota limits occupying all 64-bits,
  25. * they may need 64-bit accounting. Hence, 64-bit quota-counters,
  26. * and quota-limits. This is a waste in the common case, but hey ...
  27. */
  28. typedef __uint64_t xfs_qcnt_t;
  29. typedef __uint16_t xfs_qwarncnt_t;
  30. /*
  31. * flags for q_flags field in the dquot.
  32. */
  33. #define XFS_DQ_USER 0x0001 /* a user quota */
  34. #define XFS_DQ_PROJ 0x0002 /* project quota */
  35. #define XFS_DQ_GROUP 0x0004 /* a group quota */
  36. #define XFS_DQ_DIRTY 0x0008 /* dquot is dirty */
  37. #define XFS_DQ_FREEING 0x0010 /* dquot is beeing torn down */
  38. #define XFS_DQ_ALLTYPES (XFS_DQ_USER|XFS_DQ_PROJ|XFS_DQ_GROUP)
  39. #define XFS_DQ_FLAGS \
  40. { XFS_DQ_USER, "USER" }, \
  41. { XFS_DQ_PROJ, "PROJ" }, \
  42. { XFS_DQ_GROUP, "GROUP" }, \
  43. { XFS_DQ_DIRTY, "DIRTY" }, \
  44. { XFS_DQ_FREEING, "FREEING" }
  45. /*
  46. * We have the possibility of all three quota types being active at once, and
  47. * hence free space modification requires modification of all three current
  48. * dquots in a single transaction. For this case we need to have a reservation
  49. * of at least 3 dquots.
  50. *
  51. * However, a chmod operation can change both UID and GID in a single
  52. * transaction, resulting in requiring {old, new} x {uid, gid} dquots to be
  53. * modified. Hence for this case we need to reserve space for at least 4 dquots.
  54. *
  55. * And in the worst case, there's a rename operation that can be modifying up to
  56. * 4 inodes with dquots attached to them. In reality, the only inodes that can
  57. * have their dquots modified are the source and destination directory inodes
  58. * due to directory name creation and removal. That can require space allocation
  59. * and/or freeing on both directory inodes, and hence all three dquots on each
  60. * inode can be modified. And if the directories are world writeable, all the
  61. * dquots can be unique and so 6 dquots can be modified....
  62. *
  63. * And, of course, we also need to take into account the dquot log format item
  64. * used to describe each dquot.
  65. */
  66. #define XFS_DQUOT_LOGRES(mp) \
  67. ((sizeof(struct xfs_dq_logformat) + sizeof(struct xfs_disk_dquot)) * 6)
  68. #define XFS_IS_QUOTA_RUNNING(mp) ((mp)->m_qflags & XFS_ALL_QUOTA_ACCT)
  69. #define XFS_IS_UQUOTA_RUNNING(mp) ((mp)->m_qflags & XFS_UQUOTA_ACCT)
  70. #define XFS_IS_PQUOTA_RUNNING(mp) ((mp)->m_qflags & XFS_PQUOTA_ACCT)
  71. #define XFS_IS_GQUOTA_RUNNING(mp) ((mp)->m_qflags & XFS_GQUOTA_ACCT)
  72. #define XFS_IS_UQUOTA_ENFORCED(mp) ((mp)->m_qflags & XFS_UQUOTA_ENFD)
  73. #define XFS_IS_GQUOTA_ENFORCED(mp) ((mp)->m_qflags & XFS_GQUOTA_ENFD)
  74. #define XFS_IS_PQUOTA_ENFORCED(mp) ((mp)->m_qflags & XFS_PQUOTA_ENFD)
  75. /*
  76. * Incore only flags for quotaoff - these bits get cleared when quota(s)
  77. * are in the process of getting turned off. These flags are in m_qflags but
  78. * never in sb_qflags.
  79. */
  80. #define XFS_UQUOTA_ACTIVE 0x1000 /* uquotas are being turned off */
  81. #define XFS_GQUOTA_ACTIVE 0x2000 /* gquotas are being turned off */
  82. #define XFS_PQUOTA_ACTIVE 0x4000 /* pquotas are being turned off */
  83. #define XFS_ALL_QUOTA_ACTIVE \
  84. (XFS_UQUOTA_ACTIVE | XFS_GQUOTA_ACTIVE | XFS_PQUOTA_ACTIVE)
  85. /*
  86. * Checking XFS_IS_*QUOTA_ON() while holding any inode lock guarantees
  87. * quota will be not be switched off as long as that inode lock is held.
  88. */
  89. #define XFS_IS_QUOTA_ON(mp) ((mp)->m_qflags & (XFS_UQUOTA_ACTIVE | \
  90. XFS_GQUOTA_ACTIVE | \
  91. XFS_PQUOTA_ACTIVE))
  92. #define XFS_IS_UQUOTA_ON(mp) ((mp)->m_qflags & XFS_UQUOTA_ACTIVE)
  93. #define XFS_IS_GQUOTA_ON(mp) ((mp)->m_qflags & XFS_GQUOTA_ACTIVE)
  94. #define XFS_IS_PQUOTA_ON(mp) ((mp)->m_qflags & XFS_PQUOTA_ACTIVE)
  95. /*
  96. * Flags to tell various functions what to do. Not all of these are meaningful
  97. * to a single function. None of these XFS_QMOPT_* flags are meant to have
  98. * persistent values (ie. their values can and will change between versions)
  99. */
  100. #define XFS_QMOPT_DQALLOC 0x0000002 /* alloc dquot ondisk if needed */
  101. #define XFS_QMOPT_UQUOTA 0x0000004 /* user dquot requested */
  102. #define XFS_QMOPT_PQUOTA 0x0000008 /* project dquot requested */
  103. #define XFS_QMOPT_FORCE_RES 0x0000010 /* ignore quota limits */
  104. #define XFS_QMOPT_SBVERSION 0x0000040 /* change superblock version num */
  105. #define XFS_QMOPT_DOWARN 0x0000400 /* increase warning cnt if needed */
  106. #define XFS_QMOPT_DQREPAIR 0x0001000 /* repair dquot if damaged */
  107. #define XFS_QMOPT_GQUOTA 0x0002000 /* group dquot requested */
  108. #define XFS_QMOPT_ENOSPC 0x0004000 /* enospc instead of edquot (prj) */
  109. /*
  110. * flags to xfs_trans_mod_dquot to indicate which field needs to be
  111. * modified.
  112. */
  113. #define XFS_QMOPT_RES_REGBLKS 0x0010000
  114. #define XFS_QMOPT_RES_RTBLKS 0x0020000
  115. #define XFS_QMOPT_BCOUNT 0x0040000
  116. #define XFS_QMOPT_ICOUNT 0x0080000
  117. #define XFS_QMOPT_RTBCOUNT 0x0100000
  118. #define XFS_QMOPT_DELBCOUNT 0x0200000
  119. #define XFS_QMOPT_DELRTBCOUNT 0x0400000
  120. #define XFS_QMOPT_RES_INOS 0x0800000
  121. /*
  122. * flags for dqalloc.
  123. */
  124. #define XFS_QMOPT_INHERIT 0x1000000
  125. /*
  126. * flags to xfs_trans_mod_dquot.
  127. */
  128. #define XFS_TRANS_DQ_RES_BLKS XFS_QMOPT_RES_REGBLKS
  129. #define XFS_TRANS_DQ_RES_RTBLKS XFS_QMOPT_RES_RTBLKS
  130. #define XFS_TRANS_DQ_RES_INOS XFS_QMOPT_RES_INOS
  131. #define XFS_TRANS_DQ_BCOUNT XFS_QMOPT_BCOUNT
  132. #define XFS_TRANS_DQ_DELBCOUNT XFS_QMOPT_DELBCOUNT
  133. #define XFS_TRANS_DQ_ICOUNT XFS_QMOPT_ICOUNT
  134. #define XFS_TRANS_DQ_RTBCOUNT XFS_QMOPT_RTBCOUNT
  135. #define XFS_TRANS_DQ_DELRTBCOUNT XFS_QMOPT_DELRTBCOUNT
  136. #define XFS_QMOPT_QUOTALL \
  137. (XFS_QMOPT_UQUOTA | XFS_QMOPT_PQUOTA | XFS_QMOPT_GQUOTA)
  138. #define XFS_QMOPT_RESBLK_MASK (XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_RES_RTBLKS)
  139. extern int xfs_dqcheck(struct xfs_mount *mp, xfs_disk_dquot_t *ddq,
  140. xfs_dqid_t id, uint type, uint flags, const char *str);
  141. extern int xfs_calc_dquots_per_chunk(unsigned int nbblks);
  142. #endif /* __XFS_QUOTA_H__ */