xfs_quota.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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_H__
  7. #define __XFS_QUOTA_H__
  8. #include "xfs_quota_defs.h"
  9. /*
  10. * Kernel only quota definitions and functions
  11. */
  12. struct xfs_trans;
  13. struct xfs_buf;
  14. /*
  15. * This check is done typically without holding the inode lock;
  16. * that may seem racy, but it is harmless in the context that it is used.
  17. * The inode cannot go inactive as long a reference is kept, and
  18. * therefore if dquot(s) were attached, they'll stay consistent.
  19. * If, for example, the ownership of the inode changes while
  20. * we didn't have the inode locked, the appropriate dquot(s) will be
  21. * attached atomically.
  22. */
  23. #define XFS_NOT_DQATTACHED(mp, ip) \
  24. ((XFS_IS_UQUOTA_ON(mp) && (ip)->i_udquot == NULL) || \
  25. (XFS_IS_GQUOTA_ON(mp) && (ip)->i_gdquot == NULL) || \
  26. (XFS_IS_PQUOTA_ON(mp) && (ip)->i_pdquot == NULL))
  27. #define XFS_QM_NEED_QUOTACHECK(mp) \
  28. ((XFS_IS_UQUOTA_ON(mp) && \
  29. (mp->m_sb.sb_qflags & XFS_UQUOTA_CHKD) == 0) || \
  30. (XFS_IS_GQUOTA_ON(mp) && \
  31. (mp->m_sb.sb_qflags & XFS_GQUOTA_CHKD) == 0) || \
  32. (XFS_IS_PQUOTA_ON(mp) && \
  33. (mp->m_sb.sb_qflags & XFS_PQUOTA_CHKD) == 0))
  34. static inline uint
  35. xfs_quota_chkd_flag(
  36. xfs_dqtype_t type)
  37. {
  38. switch (type) {
  39. case XFS_DQTYPE_USER:
  40. return XFS_UQUOTA_CHKD;
  41. case XFS_DQTYPE_GROUP:
  42. return XFS_GQUOTA_CHKD;
  43. case XFS_DQTYPE_PROJ:
  44. return XFS_PQUOTA_CHKD;
  45. default:
  46. return 0;
  47. }
  48. }
  49. /*
  50. * The structure kept inside the xfs_trans_t keep track of dquot changes
  51. * within a transaction and apply them later.
  52. */
  53. struct xfs_dqtrx {
  54. struct xfs_dquot *qt_dquot; /* the dquot this refers to */
  55. uint64_t qt_blk_res; /* blks reserved on a dquot */
  56. int64_t qt_bcount_delta; /* dquot blk count changes */
  57. int64_t qt_delbcnt_delta; /* delayed dquot blk count changes */
  58. uint64_t qt_rtblk_res; /* # blks reserved on a dquot */
  59. uint64_t qt_rtblk_res_used;/* # blks used from reservation */
  60. int64_t qt_rtbcount_delta;/* dquot realtime blk changes */
  61. int64_t qt_delrtb_delta; /* delayed RT blk count changes */
  62. uint64_t qt_ino_res; /* inode reserved on a dquot */
  63. uint64_t qt_ino_res_used; /* inodes used from the reservation */
  64. int64_t qt_icount_delta; /* dquot inode count changes */
  65. };
  66. enum xfs_apply_dqtrx_type {
  67. XFS_APPLY_DQTRX_COMMIT = 0,
  68. XFS_APPLY_DQTRX_UNRESERVE,
  69. };
  70. /*
  71. * Parameters for applying dqtrx changes to a dquot. The hook function arg
  72. * parameter is enum xfs_apply_dqtrx_type.
  73. */
  74. struct xfs_apply_dqtrx_params {
  75. uintptr_t tx_id;
  76. xfs_ino_t ino;
  77. xfs_dqtype_t q_type;
  78. xfs_dqid_t q_id;
  79. };
  80. #ifdef CONFIG_XFS_QUOTA
  81. extern void xfs_trans_dup_dqinfo(struct xfs_trans *, struct xfs_trans *);
  82. extern void xfs_trans_free_dqinfo(struct xfs_trans *);
  83. extern void xfs_trans_mod_dquot_byino(struct xfs_trans *, struct xfs_inode *,
  84. uint, int64_t);
  85. extern void xfs_trans_apply_dquot_deltas(struct xfs_trans *);
  86. void xfs_trans_unreserve_and_mod_dquots(struct xfs_trans *tp,
  87. bool already_locked);
  88. int xfs_trans_reserve_quota_nblks(struct xfs_trans *tp, struct xfs_inode *ip,
  89. int64_t dblocks, int64_t rblocks, bool force);
  90. extern int xfs_trans_reserve_quota_bydquots(struct xfs_trans *,
  91. struct xfs_mount *, struct xfs_dquot *,
  92. struct xfs_dquot *, struct xfs_dquot *, int64_t, long, uint);
  93. int xfs_trans_reserve_quota_icreate(struct xfs_trans *tp,
  94. struct xfs_dquot *udqp, struct xfs_dquot *gdqp,
  95. struct xfs_dquot *pdqp, int64_t dblocks);
  96. extern int xfs_qm_vop_dqalloc(struct xfs_inode *, kuid_t, kgid_t,
  97. prid_t, uint, struct xfs_dquot **, struct xfs_dquot **,
  98. struct xfs_dquot **);
  99. extern void xfs_qm_vop_create_dqattach(struct xfs_trans *, struct xfs_inode *,
  100. struct xfs_dquot *, struct xfs_dquot *, struct xfs_dquot *);
  101. extern int xfs_qm_vop_rename_dqattach(struct xfs_inode **);
  102. extern struct xfs_dquot *xfs_qm_vop_chown(struct xfs_trans *,
  103. struct xfs_inode *, struct xfs_dquot **, struct xfs_dquot *);
  104. extern int xfs_qm_dqattach(struct xfs_inode *);
  105. extern int xfs_qm_dqattach_locked(struct xfs_inode *ip, bool doalloc);
  106. extern void xfs_qm_dqdetach(struct xfs_inode *);
  107. extern void xfs_qm_dqrele(struct xfs_dquot *);
  108. extern void xfs_qm_statvfs(struct xfs_inode *, struct kstatfs *);
  109. extern int xfs_qm_newmount(struct xfs_mount *, uint *, uint *);
  110. extern void xfs_qm_mount_quotas(struct xfs_mount *);
  111. extern void xfs_qm_unmount(struct xfs_mount *);
  112. extern void xfs_qm_unmount_quotas(struct xfs_mount *);
  113. bool xfs_inode_near_dquot_enforcement(struct xfs_inode *ip, xfs_dqtype_t type);
  114. # ifdef CONFIG_XFS_LIVE_HOOKS
  115. void xfs_trans_mod_ino_dquot(struct xfs_trans *tp, struct xfs_inode *ip,
  116. struct xfs_dquot *dqp, unsigned int field, int64_t delta);
  117. struct xfs_quotainfo;
  118. struct xfs_dqtrx_hook {
  119. struct xfs_hook mod_hook;
  120. struct xfs_hook apply_hook;
  121. };
  122. void xfs_dqtrx_hook_disable(void);
  123. void xfs_dqtrx_hook_enable(void);
  124. int xfs_dqtrx_hook_add(struct xfs_quotainfo *qi, struct xfs_dqtrx_hook *hook);
  125. void xfs_dqtrx_hook_del(struct xfs_quotainfo *qi, struct xfs_dqtrx_hook *hook);
  126. void xfs_dqtrx_hook_setup(struct xfs_dqtrx_hook *hook, notifier_fn_t mod_fn,
  127. notifier_fn_t apply_fn);
  128. # else
  129. # define xfs_trans_mod_ino_dquot(tp, ip, dqp, field, delta) \
  130. xfs_trans_mod_dquot((tp), (dqp), (field), (delta))
  131. # endif /* CONFIG_XFS_LIVE_HOOKS */
  132. #else
  133. static inline int
  134. xfs_qm_vop_dqalloc(struct xfs_inode *ip, kuid_t kuid, kgid_t kgid,
  135. prid_t prid, uint flags, struct xfs_dquot **udqp,
  136. struct xfs_dquot **gdqp, struct xfs_dquot **pdqp)
  137. {
  138. *udqp = NULL;
  139. *gdqp = NULL;
  140. *pdqp = NULL;
  141. return 0;
  142. }
  143. #define xfs_trans_dup_dqinfo(tp, tp2)
  144. #define xfs_trans_free_dqinfo(tp)
  145. static inline void xfs_trans_mod_dquot_byino(struct xfs_trans *tp,
  146. struct xfs_inode *ip, uint field, int64_t delta)
  147. {
  148. }
  149. #define xfs_trans_apply_dquot_deltas(tp)
  150. #define xfs_trans_unreserve_and_mod_dquots(tp, a)
  151. static inline int xfs_trans_reserve_quota_nblks(struct xfs_trans *tp,
  152. struct xfs_inode *ip, int64_t dblocks, int64_t rblocks,
  153. bool force)
  154. {
  155. return 0;
  156. }
  157. static inline int xfs_trans_reserve_quota_bydquots(struct xfs_trans *tp,
  158. struct xfs_mount *mp, struct xfs_dquot *udqp,
  159. struct xfs_dquot *gdqp, struct xfs_dquot *pdqp,
  160. int64_t nblks, long nions, uint flags)
  161. {
  162. return 0;
  163. }
  164. static inline int
  165. xfs_trans_reserve_quota_icreate(struct xfs_trans *tp, struct xfs_dquot *udqp,
  166. struct xfs_dquot *gdqp, struct xfs_dquot *pdqp, int64_t dblocks)
  167. {
  168. return 0;
  169. }
  170. #define xfs_qm_vop_create_dqattach(tp, ip, u, g, p)
  171. #define xfs_qm_vop_rename_dqattach(it) (0)
  172. #define xfs_qm_vop_chown(tp, ip, old, new) (NULL)
  173. #define xfs_qm_dqattach(ip) (0)
  174. #define xfs_qm_dqattach_locked(ip, fl) (0)
  175. #define xfs_qm_dqdetach(ip)
  176. #define xfs_qm_dqrele(d) do { (d) = (d); } while(0)
  177. #define xfs_qm_statvfs(ip, s) do { } while(0)
  178. #define xfs_qm_newmount(mp, a, b) (0)
  179. #define xfs_qm_mount_quotas(mp)
  180. #define xfs_qm_unmount(mp)
  181. #define xfs_qm_unmount_quotas(mp)
  182. #define xfs_inode_near_dquot_enforcement(ip, type) (false)
  183. # ifdef CONFIG_XFS_LIVE_HOOKS
  184. # define xfs_dqtrx_hook_enable() ((void)0)
  185. # define xfs_dqtrx_hook_disable() ((void)0)
  186. # endif /* CONFIG_XFS_LIVE_HOOKS */
  187. #endif /* CONFIG_XFS_QUOTA */
  188. static inline int
  189. xfs_quota_reserve_blkres(struct xfs_inode *ip, int64_t blocks)
  190. {
  191. return xfs_trans_reserve_quota_nblks(NULL, ip, blocks, 0, false);
  192. }
  193. static inline void
  194. xfs_quota_unreserve_blkres(struct xfs_inode *ip, uint64_t blocks)
  195. {
  196. /* don't return an error as unreserving quotas can't fail */
  197. xfs_quota_reserve_blkres(ip, -(int64_t)blocks);
  198. }
  199. extern int xfs_mount_reset_sbqflags(struct xfs_mount *);
  200. #endif /* __XFS_QUOTA_H__ */