xfs_qm.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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_cache *xfs_dqtrx_cache;
  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. };
  32. /* Defaults for each quota type: time limits, warn limits, usage limits */
  33. struct xfs_def_quota {
  34. struct xfs_quota_limits blk;
  35. struct xfs_quota_limits ino;
  36. struct xfs_quota_limits rtb;
  37. };
  38. /*
  39. * Various quota information for individual filesystems.
  40. * The mount structure keeps a pointer to this.
  41. */
  42. struct xfs_quotainfo {
  43. struct radix_tree_root qi_uquota_tree;
  44. struct radix_tree_root qi_gquota_tree;
  45. struct radix_tree_root qi_pquota_tree;
  46. struct mutex qi_tree_lock;
  47. struct xfs_inode *qi_uquotaip; /* user quota inode */
  48. struct xfs_inode *qi_gquotaip; /* group quota inode */
  49. struct xfs_inode *qi_pquotaip; /* project quota inode */
  50. struct list_lru qi_lru;
  51. int qi_dquots;
  52. struct mutex qi_quotaofflock;/* to serialize quotaoff */
  53. xfs_filblks_t qi_dqchunklen; /* # BBs in a chunk of dqs */
  54. uint qi_dqperchunk; /* # ondisk dq in above chunk */
  55. struct xfs_def_quota qi_usr_default;
  56. struct xfs_def_quota qi_grp_default;
  57. struct xfs_def_quota qi_prj_default;
  58. struct shrinker qi_shrinker;
  59. /* Minimum and maximum quota expiration timestamp values. */
  60. time64_t qi_expiry_min;
  61. time64_t qi_expiry_max;
  62. };
  63. static inline struct radix_tree_root *
  64. xfs_dquot_tree(
  65. struct xfs_quotainfo *qi,
  66. xfs_dqtype_t type)
  67. {
  68. switch (type) {
  69. case XFS_DQTYPE_USER:
  70. return &qi->qi_uquota_tree;
  71. case XFS_DQTYPE_GROUP:
  72. return &qi->qi_gquota_tree;
  73. case XFS_DQTYPE_PROJ:
  74. return &qi->qi_pquota_tree;
  75. default:
  76. ASSERT(0);
  77. }
  78. return NULL;
  79. }
  80. static inline struct xfs_inode *
  81. xfs_quota_inode(struct xfs_mount *mp, xfs_dqtype_t type)
  82. {
  83. switch (type) {
  84. case XFS_DQTYPE_USER:
  85. return mp->m_quotainfo->qi_uquotaip;
  86. case XFS_DQTYPE_GROUP:
  87. return mp->m_quotainfo->qi_gquotaip;
  88. case XFS_DQTYPE_PROJ:
  89. return mp->m_quotainfo->qi_pquotaip;
  90. default:
  91. ASSERT(0);
  92. }
  93. return NULL;
  94. }
  95. extern void xfs_trans_mod_dquot(struct xfs_trans *tp, struct xfs_dquot *dqp,
  96. uint field, int64_t delta);
  97. extern void xfs_trans_dqjoin(struct xfs_trans *, struct xfs_dquot *);
  98. extern void xfs_trans_log_dquot(struct xfs_trans *, struct xfs_dquot *);
  99. /*
  100. * We keep the usr, grp, and prj dquots separately so that locking will be
  101. * easier to do at commit time. All transactions that we know of at this point
  102. * affect no more than two dquots of one type. Hence, the TRANS_MAXDQS value.
  103. */
  104. enum {
  105. XFS_QM_TRANS_USR = 0,
  106. XFS_QM_TRANS_GRP,
  107. XFS_QM_TRANS_PRJ,
  108. XFS_QM_TRANS_DQTYPES
  109. };
  110. #define XFS_QM_TRANS_MAXDQS 2
  111. struct xfs_dquot_acct {
  112. struct xfs_dqtrx dqs[XFS_QM_TRANS_DQTYPES][XFS_QM_TRANS_MAXDQS];
  113. };
  114. /*
  115. * Users are allowed to have a usage exceeding their softlimit for
  116. * a period this long.
  117. */
  118. #define XFS_QM_BTIMELIMIT (7 * 24*60*60) /* 1 week */
  119. #define XFS_QM_RTBTIMELIMIT (7 * 24*60*60) /* 1 week */
  120. #define XFS_QM_ITIMELIMIT (7 * 24*60*60) /* 1 week */
  121. extern void xfs_qm_destroy_quotainfo(struct xfs_mount *);
  122. /* quota ops */
  123. extern int xfs_qm_scall_trunc_qfiles(struct xfs_mount *, uint);
  124. extern int xfs_qm_scall_getquota(struct xfs_mount *mp,
  125. xfs_dqid_t id,
  126. xfs_dqtype_t type,
  127. struct qc_dqblk *dst);
  128. extern int xfs_qm_scall_getquota_next(struct xfs_mount *mp,
  129. xfs_dqid_t *id,
  130. xfs_dqtype_t type,
  131. struct qc_dqblk *dst);
  132. extern int xfs_qm_scall_setqlim(struct xfs_mount *mp,
  133. xfs_dqid_t id,
  134. xfs_dqtype_t type,
  135. struct qc_dqblk *newlim);
  136. extern int xfs_qm_scall_quotaon(struct xfs_mount *, uint);
  137. extern int xfs_qm_scall_quotaoff(struct xfs_mount *, uint);
  138. static inline struct xfs_def_quota *
  139. xfs_get_defquota(struct xfs_quotainfo *qi, xfs_dqtype_t type)
  140. {
  141. switch (type) {
  142. case XFS_DQTYPE_USER:
  143. return &qi->qi_usr_default;
  144. case XFS_DQTYPE_GROUP:
  145. return &qi->qi_grp_default;
  146. case XFS_DQTYPE_PROJ:
  147. return &qi->qi_prj_default;
  148. default:
  149. ASSERT(0);
  150. return NULL;
  151. }
  152. }
  153. #endif /* __XFS_QM_H__ */