xfs_qm.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2000-2005 Silicon Graphics, Inc.
  4. * All Rights Reserved.
  5. */
  6. #ifndef __XFS_QM_H__
  7. #define __XFS_QM_H__
  8. #include "xfs_dquot_item.h"
  9. #include "xfs_dquot.h"
  10. struct xfs_inode;
  11. extern struct kmem_zone *xfs_qm_dqtrxzone;
  12. /*
  13. * Number of bmaps that we ask from bmapi when doing a quotacheck.
  14. * We make this restriction to keep the memory usage to a minimum.
  15. */
  16. #define XFS_DQITER_MAP_SIZE 10
  17. #define XFS_IS_DQUOT_UNINITIALIZED(dqp) ( \
  18. !dqp->q_blk.hardlimit && \
  19. !dqp->q_blk.softlimit && \
  20. !dqp->q_rtb.hardlimit && \
  21. !dqp->q_rtb.softlimit && \
  22. !dqp->q_ino.hardlimit && \
  23. !dqp->q_ino.softlimit && \
  24. !dqp->q_blk.count && \
  25. !dqp->q_rtb.count && \
  26. !dqp->q_ino.count)
  27. struct xfs_quota_limits {
  28. xfs_qcnt_t hard; /* default hard limit */
  29. xfs_qcnt_t soft; /* default soft limit */
  30. time64_t time; /* limit for timers */
  31. xfs_qwarncnt_t warn; /* limit for warnings */
  32. };
  33. /* Defaults for each quota type: time limits, warn limits, usage limits */
  34. struct xfs_def_quota {
  35. struct xfs_quota_limits blk;
  36. struct xfs_quota_limits ino;
  37. struct xfs_quota_limits rtb;
  38. };
  39. /*
  40. * Various quota information for individual filesystems.
  41. * The mount structure keeps a pointer to this.
  42. */
  43. struct xfs_quotainfo {
  44. struct radix_tree_root qi_uquota_tree;
  45. struct radix_tree_root qi_gquota_tree;
  46. struct radix_tree_root qi_pquota_tree;
  47. struct mutex qi_tree_lock;
  48. struct xfs_inode *qi_uquotaip; /* user quota inode */
  49. struct xfs_inode *qi_gquotaip; /* group quota inode */
  50. struct xfs_inode *qi_pquotaip; /* project quota inode */
  51. struct list_lru qi_lru;
  52. int qi_dquots;
  53. struct mutex qi_quotaofflock;/* to serialize quotaoff */
  54. xfs_filblks_t qi_dqchunklen; /* # BBs in a chunk of dqs */
  55. uint qi_dqperchunk; /* # ondisk dq in above chunk */
  56. struct xfs_def_quota qi_usr_default;
  57. struct xfs_def_quota qi_grp_default;
  58. struct xfs_def_quota qi_prj_default;
  59. struct shrinker qi_shrinker;
  60. /* Minimum and maximum quota expiration timestamp values. */
  61. time64_t qi_expiry_min;
  62. time64_t qi_expiry_max;
  63. };
  64. static inline struct radix_tree_root *
  65. xfs_dquot_tree(
  66. struct xfs_quotainfo *qi,
  67. xfs_dqtype_t type)
  68. {
  69. switch (type) {
  70. case XFS_DQTYPE_USER:
  71. return &qi->qi_uquota_tree;
  72. case XFS_DQTYPE_GROUP:
  73. return &qi->qi_gquota_tree;
  74. case XFS_DQTYPE_PROJ:
  75. return &qi->qi_pquota_tree;
  76. default:
  77. ASSERT(0);
  78. }
  79. return NULL;
  80. }
  81. static inline struct xfs_inode *
  82. xfs_quota_inode(struct xfs_mount *mp, xfs_dqtype_t type)
  83. {
  84. switch (type) {
  85. case XFS_DQTYPE_USER:
  86. return mp->m_quotainfo->qi_uquotaip;
  87. case XFS_DQTYPE_GROUP:
  88. return mp->m_quotainfo->qi_gquotaip;
  89. case XFS_DQTYPE_PROJ:
  90. return mp->m_quotainfo->qi_pquotaip;
  91. default:
  92. ASSERT(0);
  93. }
  94. return NULL;
  95. }
  96. extern void xfs_trans_mod_dquot(struct xfs_trans *tp, struct xfs_dquot *dqp,
  97. uint field, int64_t delta);
  98. extern void xfs_trans_dqjoin(struct xfs_trans *, struct xfs_dquot *);
  99. extern void xfs_trans_log_dquot(struct xfs_trans *, struct xfs_dquot *);
  100. /*
  101. * We keep the usr, grp, and prj dquots separately so that locking will be
  102. * easier to do at commit time. All transactions that we know of at this point
  103. * affect no more than two dquots of one type. Hence, the TRANS_MAXDQS value.
  104. */
  105. enum {
  106. XFS_QM_TRANS_USR = 0,
  107. XFS_QM_TRANS_GRP,
  108. XFS_QM_TRANS_PRJ,
  109. XFS_QM_TRANS_DQTYPES
  110. };
  111. #define XFS_QM_TRANS_MAXDQS 2
  112. struct xfs_dquot_acct {
  113. struct xfs_dqtrx dqs[XFS_QM_TRANS_DQTYPES][XFS_QM_TRANS_MAXDQS];
  114. };
  115. /*
  116. * Users are allowed to have a usage exceeding their softlimit for
  117. * a period this long.
  118. */
  119. #define XFS_QM_BTIMELIMIT (7 * 24*60*60) /* 1 week */
  120. #define XFS_QM_RTBTIMELIMIT (7 * 24*60*60) /* 1 week */
  121. #define XFS_QM_ITIMELIMIT (7 * 24*60*60) /* 1 week */
  122. #define XFS_QM_BWARNLIMIT 5
  123. #define XFS_QM_IWARNLIMIT 5
  124. #define XFS_QM_RTBWARNLIMIT 5
  125. extern void xfs_qm_destroy_quotainfo(struct xfs_mount *);
  126. /* dquot stuff */
  127. extern void xfs_qm_dqpurge_all(struct xfs_mount *, uint);
  128. extern void xfs_qm_dqrele_all_inodes(struct xfs_mount *, uint);
  129. /* quota ops */
  130. extern int xfs_qm_scall_trunc_qfiles(struct xfs_mount *, uint);
  131. extern int xfs_qm_scall_getquota(struct xfs_mount *mp,
  132. xfs_dqid_t id,
  133. xfs_dqtype_t type,
  134. struct qc_dqblk *dst);
  135. extern int xfs_qm_scall_getquota_next(struct xfs_mount *mp,
  136. xfs_dqid_t *id,
  137. xfs_dqtype_t type,
  138. struct qc_dqblk *dst);
  139. extern int xfs_qm_scall_setqlim(struct xfs_mount *mp,
  140. xfs_dqid_t id,
  141. xfs_dqtype_t type,
  142. struct qc_dqblk *newlim);
  143. extern int xfs_qm_scall_quotaon(struct xfs_mount *, uint);
  144. extern int xfs_qm_scall_quotaoff(struct xfs_mount *, uint);
  145. static inline struct xfs_def_quota *
  146. xfs_get_defquota(struct xfs_quotainfo *qi, xfs_dqtype_t type)
  147. {
  148. switch (type) {
  149. case XFS_DQTYPE_USER:
  150. return &qi->qi_usr_default;
  151. case XFS_DQTYPE_GROUP:
  152. return &qi->qi_grp_default;
  153. case XFS_DQTYPE_PROJ:
  154. return &qi->qi_prj_default;
  155. default:
  156. ASSERT(0);
  157. return NULL;
  158. }
  159. }
  160. #endif /* __XFS_QM_H__ */