xfs_quota_defs.h 5.8 KB

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