xfs_quota.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. #ifdef CONFIG_XFS_QUOTA
  67. extern void xfs_trans_dup_dqinfo(struct xfs_trans *, struct xfs_trans *);
  68. extern void xfs_trans_free_dqinfo(struct xfs_trans *);
  69. extern void xfs_trans_mod_dquot_byino(struct xfs_trans *, struct xfs_inode *,
  70. uint, int64_t);
  71. extern void xfs_trans_apply_dquot_deltas(struct xfs_trans *);
  72. extern void xfs_trans_unreserve_and_mod_dquots(struct xfs_trans *);
  73. extern int xfs_trans_reserve_quota_nblks(struct xfs_trans *,
  74. struct xfs_inode *, int64_t, long, uint);
  75. extern int xfs_trans_reserve_quota_bydquots(struct xfs_trans *,
  76. struct xfs_mount *, struct xfs_dquot *,
  77. struct xfs_dquot *, struct xfs_dquot *, int64_t, long, uint);
  78. extern int xfs_qm_vop_dqalloc(struct xfs_inode *, kuid_t, kgid_t,
  79. prid_t, uint, struct xfs_dquot **, struct xfs_dquot **,
  80. struct xfs_dquot **);
  81. extern void xfs_qm_vop_create_dqattach(struct xfs_trans *, struct xfs_inode *,
  82. struct xfs_dquot *, struct xfs_dquot *, struct xfs_dquot *);
  83. extern int xfs_qm_vop_rename_dqattach(struct xfs_inode **);
  84. extern struct xfs_dquot *xfs_qm_vop_chown(struct xfs_trans *,
  85. struct xfs_inode *, struct xfs_dquot **, struct xfs_dquot *);
  86. extern int xfs_qm_vop_chown_reserve(struct xfs_trans *, struct xfs_inode *,
  87. struct xfs_dquot *, struct xfs_dquot *,
  88. struct xfs_dquot *, uint);
  89. extern int xfs_qm_dqattach(struct xfs_inode *);
  90. extern int xfs_qm_dqattach_locked(struct xfs_inode *ip, bool doalloc);
  91. extern void xfs_qm_dqdetach(struct xfs_inode *);
  92. extern void xfs_qm_dqrele(struct xfs_dquot *);
  93. extern void xfs_qm_statvfs(struct xfs_inode *, struct kstatfs *);
  94. extern int xfs_qm_newmount(struct xfs_mount *, uint *, uint *);
  95. extern void xfs_qm_mount_quotas(struct xfs_mount *);
  96. extern void xfs_qm_unmount(struct xfs_mount *);
  97. extern void xfs_qm_unmount_quotas(struct xfs_mount *);
  98. #else
  99. static inline int
  100. xfs_qm_vop_dqalloc(struct xfs_inode *ip, kuid_t kuid, kgid_t kgid,
  101. prid_t prid, uint flags, struct xfs_dquot **udqp,
  102. struct xfs_dquot **gdqp, struct xfs_dquot **pdqp)
  103. {
  104. *udqp = NULL;
  105. *gdqp = NULL;
  106. *pdqp = NULL;
  107. return 0;
  108. }
  109. #define xfs_trans_dup_dqinfo(tp, tp2)
  110. #define xfs_trans_free_dqinfo(tp)
  111. #define xfs_trans_mod_dquot_byino(tp, ip, fields, delta)
  112. #define xfs_trans_apply_dquot_deltas(tp)
  113. #define xfs_trans_unreserve_and_mod_dquots(tp)
  114. static inline int xfs_trans_reserve_quota_nblks(struct xfs_trans *tp,
  115. struct xfs_inode *ip, int64_t nblks, long ninos, uint flags)
  116. {
  117. return 0;
  118. }
  119. static inline int xfs_trans_reserve_quota_bydquots(struct xfs_trans *tp,
  120. struct xfs_mount *mp, struct xfs_dquot *udqp,
  121. struct xfs_dquot *gdqp, struct xfs_dquot *pdqp,
  122. int64_t nblks, long nions, uint flags)
  123. {
  124. return 0;
  125. }
  126. #define xfs_qm_vop_create_dqattach(tp, ip, u, g, p)
  127. #define xfs_qm_vop_rename_dqattach(it) (0)
  128. #define xfs_qm_vop_chown(tp, ip, old, new) (NULL)
  129. #define xfs_qm_vop_chown_reserve(tp, ip, u, g, p, fl) (0)
  130. #define xfs_qm_dqattach(ip) (0)
  131. #define xfs_qm_dqattach_locked(ip, fl) (0)
  132. #define xfs_qm_dqdetach(ip)
  133. #define xfs_qm_dqrele(d)
  134. #define xfs_qm_statvfs(ip, s)
  135. #define xfs_qm_newmount(mp, a, b) (0)
  136. #define xfs_qm_mount_quotas(mp)
  137. #define xfs_qm_unmount(mp)
  138. #define xfs_qm_unmount_quotas(mp)
  139. #endif /* CONFIG_XFS_QUOTA */
  140. #define xfs_trans_unreserve_quota_nblks(tp, ip, nblks, ninos, flags) \
  141. xfs_trans_reserve_quota_nblks(tp, ip, -(nblks), -(ninos), flags)
  142. #define xfs_trans_reserve_quota(tp, mp, ud, gd, pd, nb, ni, f) \
  143. xfs_trans_reserve_quota_bydquots(tp, mp, ud, gd, pd, nb, ni, \
  144. f | XFS_QMOPT_RES_REGBLKS)
  145. extern int xfs_mount_reset_sbqflags(struct xfs_mount *);
  146. #endif /* __XFS_QUOTA_H__ */