xfs_qm.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. /* Hook to feed quota counter updates to an active online repair. */
  63. struct xfs_hooks qi_mod_ino_dqtrx_hooks;
  64. struct xfs_hooks qi_apply_dqtrx_hooks;
  65. };
  66. static inline struct radix_tree_root *
  67. xfs_dquot_tree(
  68. struct xfs_quotainfo *qi,
  69. xfs_dqtype_t type)
  70. {
  71. switch (type) {
  72. case XFS_DQTYPE_USER:
  73. return &qi->qi_uquota_tree;
  74. case XFS_DQTYPE_GROUP:
  75. return &qi->qi_gquota_tree;
  76. case XFS_DQTYPE_PROJ:
  77. return &qi->qi_pquota_tree;
  78. default:
  79. ASSERT(0);
  80. }
  81. return NULL;
  82. }
  83. static inline struct xfs_inode *
  84. xfs_quota_inode(struct xfs_mount *mp, xfs_dqtype_t type)
  85. {
  86. switch (type) {
  87. case XFS_DQTYPE_USER:
  88. return mp->m_quotainfo->qi_uquotaip;
  89. case XFS_DQTYPE_GROUP:
  90. return mp->m_quotainfo->qi_gquotaip;
  91. case XFS_DQTYPE_PROJ:
  92. return mp->m_quotainfo->qi_pquotaip;
  93. default:
  94. ASSERT(0);
  95. }
  96. return NULL;
  97. }
  98. /*
  99. * Parameters for tracking dqtrx changes on behalf of an inode. The hook
  100. * function arg parameter is the field being updated.
  101. */
  102. struct xfs_mod_ino_dqtrx_params {
  103. uintptr_t tx_id;
  104. xfs_ino_t ino;
  105. xfs_dqtype_t q_type;
  106. xfs_dqid_t q_id;
  107. int64_t delta;
  108. };
  109. extern void xfs_trans_mod_dquot(struct xfs_trans *tp, struct xfs_dquot *dqp,
  110. uint field, int64_t delta);
  111. extern void xfs_trans_dqjoin(struct xfs_trans *, struct xfs_dquot *);
  112. extern void xfs_trans_log_dquot(struct xfs_trans *, struct xfs_dquot *);
  113. /*
  114. * We keep the usr, grp, and prj dquots separately so that locking will be
  115. * easier to do at commit time. All transactions that we know of at this point
  116. * affect no more than two dquots of one type. Hence, the TRANS_MAXDQS value.
  117. */
  118. enum {
  119. XFS_QM_TRANS_USR = 0,
  120. XFS_QM_TRANS_GRP,
  121. XFS_QM_TRANS_PRJ,
  122. XFS_QM_TRANS_DQTYPES
  123. };
  124. #define XFS_QM_TRANS_MAXDQS 5
  125. struct xfs_dquot_acct {
  126. struct xfs_dqtrx dqs[XFS_QM_TRANS_DQTYPES][XFS_QM_TRANS_MAXDQS];
  127. };
  128. /*
  129. * Users are allowed to have a usage exceeding their softlimit for
  130. * a period this long.
  131. */
  132. #define XFS_QM_BTIMELIMIT (7 * 24*60*60) /* 1 week */
  133. #define XFS_QM_RTBTIMELIMIT (7 * 24*60*60) /* 1 week */
  134. #define XFS_QM_ITIMELIMIT (7 * 24*60*60) /* 1 week */
  135. extern void xfs_qm_destroy_quotainfo(struct xfs_mount *);
  136. /* quota ops */
  137. extern int xfs_qm_scall_trunc_qfiles(struct xfs_mount *, uint);
  138. extern int xfs_qm_scall_getquota(struct xfs_mount *mp,
  139. xfs_dqid_t id,
  140. xfs_dqtype_t type,
  141. struct qc_dqblk *dst);
  142. extern int xfs_qm_scall_getquota_next(struct xfs_mount *mp,
  143. xfs_dqid_t *id,
  144. xfs_dqtype_t type,
  145. struct qc_dqblk *dst);
  146. extern int xfs_qm_scall_setqlim(struct xfs_mount *mp,
  147. xfs_dqid_t id,
  148. xfs_dqtype_t type,
  149. struct qc_dqblk *newlim);
  150. extern int xfs_qm_scall_quotaon(struct xfs_mount *, uint);
  151. extern int xfs_qm_scall_quotaoff(struct xfs_mount *, uint);
  152. static inline struct xfs_def_quota *
  153. xfs_get_defquota(struct xfs_quotainfo *qi, xfs_dqtype_t type)
  154. {
  155. switch (type) {
  156. case XFS_DQTYPE_USER:
  157. return &qi->qi_usr_default;
  158. case XFS_DQTYPE_GROUP:
  159. return &qi->qi_grp_default;
  160. case XFS_DQTYPE_PROJ:
  161. return &qi->qi_prj_default;
  162. default:
  163. ASSERT(0);
  164. return NULL;
  165. }
  166. }
  167. int xfs_qm_qino_load(struct xfs_mount *mp, xfs_dqtype_t type,
  168. struct xfs_inode **ipp);
  169. #endif /* __XFS_QM_H__ */