xfs_quota.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /*
  2. * Copyright (c) 2000-2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef __XFS_QUOTA_H__
  19. #define __XFS_QUOTA_H__
  20. struct xfs_trans;
  21. /*
  22. * Even though users may not have quota limits occupying all 64-bits,
  23. * they may need 64-bit accounting. Hence, 64-bit quota-counters,
  24. * and quota-limits. This is a waste in the common case, but hey ...
  25. */
  26. typedef __uint64_t xfs_qcnt_t;
  27. typedef __uint16_t xfs_qwarncnt_t;
  28. /*
  29. * flags for q_flags field in the dquot.
  30. */
  31. #define XFS_DQ_USER 0x0001 /* a user quota */
  32. #define XFS_DQ_PROJ 0x0002 /* project quota */
  33. #define XFS_DQ_GROUP 0x0004 /* a group quota */
  34. #define XFS_DQ_DIRTY 0x0008 /* dquot is dirty */
  35. #define XFS_DQ_FREEING 0x0010 /* dquot is beeing torn down */
  36. #define XFS_DQ_ALLTYPES (XFS_DQ_USER|XFS_DQ_PROJ|XFS_DQ_GROUP)
  37. #define XFS_DQ_FLAGS \
  38. { XFS_DQ_USER, "USER" }, \
  39. { XFS_DQ_PROJ, "PROJ" }, \
  40. { XFS_DQ_GROUP, "GROUP" }, \
  41. { XFS_DQ_DIRTY, "DIRTY" }, \
  42. { XFS_DQ_FREEING, "FREEING" }
  43. /*
  44. * We have the possibility of all three quota types being active at once, and
  45. * hence free space modification requires modification of all three current
  46. * dquots in a single transaction. For this case we need to have a reservation
  47. * of at least 3 dquots.
  48. *
  49. * However, a chmod operation can change both UID and GID in a single
  50. * transaction, resulting in requiring {old, new} x {uid, gid} dquots to be
  51. * modified. Hence for this case we need to reserve space for at least 4 dquots.
  52. *
  53. * And in the worst case, there's a rename operation that can be modifying up to
  54. * 4 inodes with dquots attached to them. In reality, the only inodes that can
  55. * have their dquots modified are the source and destination directory inodes
  56. * due to directory name creation and removal. That can require space allocation
  57. * and/or freeing on both directory inodes, and hence all three dquots on each
  58. * inode can be modified. And if the directories are world writeable, all the
  59. * dquots can be unique and so 6 dquots can be modified....
  60. *
  61. * And, of course, we also need to take into account the dquot log format item
  62. * used to describe each dquot.
  63. */
  64. #define XFS_DQUOT_LOGRES(mp) \
  65. ((sizeof(struct xfs_dq_logformat) + sizeof(struct xfs_disk_dquot)) * 6)
  66. #define XFS_IS_QUOTA_RUNNING(mp) ((mp)->m_qflags & XFS_ALL_QUOTA_ACCT)
  67. #define XFS_IS_UQUOTA_RUNNING(mp) ((mp)->m_qflags & XFS_UQUOTA_ACCT)
  68. #define XFS_IS_PQUOTA_RUNNING(mp) ((mp)->m_qflags & XFS_PQUOTA_ACCT)
  69. #define XFS_IS_GQUOTA_RUNNING(mp) ((mp)->m_qflags & XFS_GQUOTA_ACCT)
  70. #define XFS_IS_UQUOTA_ENFORCED(mp) ((mp)->m_qflags & XFS_UQUOTA_ENFD)
  71. #define XFS_IS_GQUOTA_ENFORCED(mp) ((mp)->m_qflags & XFS_GQUOTA_ENFD)
  72. #define XFS_IS_PQUOTA_ENFORCED(mp) ((mp)->m_qflags & XFS_PQUOTA_ENFD)
  73. /*
  74. * Incore only flags for quotaoff - these bits get cleared when quota(s)
  75. * are in the process of getting turned off. These flags are in m_qflags but
  76. * never in sb_qflags.
  77. */
  78. #define XFS_UQUOTA_ACTIVE 0x1000 /* uquotas are being turned off */
  79. #define XFS_GQUOTA_ACTIVE 0x2000 /* gquotas are being turned off */
  80. #define XFS_PQUOTA_ACTIVE 0x4000 /* pquotas are being turned off */
  81. #define XFS_ALL_QUOTA_ACTIVE \
  82. (XFS_UQUOTA_ACTIVE | XFS_GQUOTA_ACTIVE | XFS_PQUOTA_ACTIVE)
  83. /*
  84. * Checking XFS_IS_*QUOTA_ON() while holding any inode lock guarantees
  85. * quota will be not be switched off as long as that inode lock is held.
  86. */
  87. #define XFS_IS_QUOTA_ON(mp) ((mp)->m_qflags & (XFS_UQUOTA_ACTIVE | \
  88. XFS_GQUOTA_ACTIVE | \
  89. XFS_PQUOTA_ACTIVE))
  90. #define XFS_IS_OQUOTA_ON(mp) ((mp)->m_qflags & (XFS_GQUOTA_ACTIVE | \
  91. XFS_PQUOTA_ACTIVE))
  92. #define XFS_IS_UQUOTA_ON(mp) ((mp)->m_qflags & XFS_UQUOTA_ACTIVE)
  93. #define XFS_IS_GQUOTA_ON(mp) ((mp)->m_qflags & XFS_GQUOTA_ACTIVE)
  94. #define XFS_IS_PQUOTA_ON(mp) ((mp)->m_qflags & XFS_PQUOTA_ACTIVE)
  95. /*
  96. * Flags to tell various functions what to do. Not all of these are meaningful
  97. * to a single function. None of these XFS_QMOPT_* flags are meant to have
  98. * persistent values (ie. their values can and will change between versions)
  99. */
  100. #define XFS_QMOPT_DQALLOC 0x0000002 /* alloc dquot ondisk if needed */
  101. #define XFS_QMOPT_UQUOTA 0x0000004 /* user dquot requested */
  102. #define XFS_QMOPT_PQUOTA 0x0000008 /* project dquot requested */
  103. #define XFS_QMOPT_FORCE_RES 0x0000010 /* ignore quota limits */
  104. #define XFS_QMOPT_SBVERSION 0x0000040 /* change superblock version num */
  105. #define XFS_QMOPT_DOWARN 0x0000400 /* increase warning cnt if needed */
  106. #define XFS_QMOPT_DQREPAIR 0x0001000 /* repair dquot if damaged */
  107. #define XFS_QMOPT_GQUOTA 0x0002000 /* group dquot requested */
  108. #define XFS_QMOPT_ENOSPC 0x0004000 /* enospc instead of edquot (prj) */
  109. /*
  110. * flags to xfs_trans_mod_dquot to indicate which field needs to be
  111. * modified.
  112. */
  113. #define XFS_QMOPT_RES_REGBLKS 0x0010000
  114. #define XFS_QMOPT_RES_RTBLKS 0x0020000
  115. #define XFS_QMOPT_BCOUNT 0x0040000
  116. #define XFS_QMOPT_ICOUNT 0x0080000
  117. #define XFS_QMOPT_RTBCOUNT 0x0100000
  118. #define XFS_QMOPT_DELBCOUNT 0x0200000
  119. #define XFS_QMOPT_DELRTBCOUNT 0x0400000
  120. #define XFS_QMOPT_RES_INOS 0x0800000
  121. /*
  122. * flags for dqalloc.
  123. */
  124. #define XFS_QMOPT_INHERIT 0x1000000
  125. /*
  126. * flags to xfs_trans_mod_dquot.
  127. */
  128. #define XFS_TRANS_DQ_RES_BLKS XFS_QMOPT_RES_REGBLKS
  129. #define XFS_TRANS_DQ_RES_RTBLKS XFS_QMOPT_RES_RTBLKS
  130. #define XFS_TRANS_DQ_RES_INOS XFS_QMOPT_RES_INOS
  131. #define XFS_TRANS_DQ_BCOUNT XFS_QMOPT_BCOUNT
  132. #define XFS_TRANS_DQ_DELBCOUNT XFS_QMOPT_DELBCOUNT
  133. #define XFS_TRANS_DQ_ICOUNT XFS_QMOPT_ICOUNT
  134. #define XFS_TRANS_DQ_RTBCOUNT XFS_QMOPT_RTBCOUNT
  135. #define XFS_TRANS_DQ_DELRTBCOUNT XFS_QMOPT_DELRTBCOUNT
  136. #define XFS_QMOPT_QUOTALL \
  137. (XFS_QMOPT_UQUOTA | XFS_QMOPT_PQUOTA | XFS_QMOPT_GQUOTA)
  138. #define XFS_QMOPT_RESBLK_MASK (XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_RES_RTBLKS)
  139. #ifdef __KERNEL__
  140. /*
  141. * This check is done typically without holding the inode lock;
  142. * that may seem racy, but it is harmless in the context that it is used.
  143. * The inode cannot go inactive as long a reference is kept, and
  144. * therefore if dquot(s) were attached, they'll stay consistent.
  145. * If, for example, the ownership of the inode changes while
  146. * we didn't have the inode locked, the appropriate dquot(s) will be
  147. * attached atomically.
  148. */
  149. #define XFS_NOT_DQATTACHED(mp, ip) \
  150. ((XFS_IS_UQUOTA_ON(mp) && (ip)->i_udquot == NULL) || \
  151. (XFS_IS_GQUOTA_ON(mp) && (ip)->i_gdquot == NULL) || \
  152. (XFS_IS_PQUOTA_ON(mp) && (ip)->i_pdquot == NULL))
  153. #define XFS_QM_NEED_QUOTACHECK(mp) \
  154. ((XFS_IS_UQUOTA_ON(mp) && \
  155. (mp->m_sb.sb_qflags & XFS_UQUOTA_CHKD) == 0) || \
  156. (XFS_IS_GQUOTA_ON(mp) && \
  157. (mp->m_sb.sb_qflags & XFS_GQUOTA_CHKD) == 0) || \
  158. (XFS_IS_PQUOTA_ON(mp) && \
  159. (mp->m_sb.sb_qflags & XFS_PQUOTA_CHKD) == 0))
  160. #define XFS_MOUNT_QUOTA_ALL (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD|\
  161. XFS_UQUOTA_CHKD|XFS_GQUOTA_ACCT|\
  162. XFS_GQUOTA_ENFD|XFS_GQUOTA_CHKD|\
  163. XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD|\
  164. XFS_PQUOTA_CHKD)
  165. /*
  166. * The structure kept inside the xfs_trans_t keep track of dquot changes
  167. * within a transaction and apply them later.
  168. */
  169. typedef struct xfs_dqtrx {
  170. struct xfs_dquot *qt_dquot; /* the dquot this refers to */
  171. ulong qt_blk_res; /* blks reserved on a dquot */
  172. ulong qt_blk_res_used; /* blks used from the reservation */
  173. ulong qt_ino_res; /* inode reserved on a dquot */
  174. ulong qt_ino_res_used; /* inodes used from the reservation */
  175. long qt_bcount_delta; /* dquot blk count changes */
  176. long qt_delbcnt_delta; /* delayed dquot blk count changes */
  177. long qt_icount_delta; /* dquot inode count changes */
  178. ulong qt_rtblk_res; /* # blks reserved on a dquot */
  179. ulong qt_rtblk_res_used;/* # blks used from reservation */
  180. long qt_rtbcount_delta;/* dquot realtime blk changes */
  181. long qt_delrtb_delta; /* delayed RT blk count changes */
  182. } xfs_dqtrx_t;
  183. #ifdef CONFIG_XFS_QUOTA
  184. extern void xfs_trans_dup_dqinfo(struct xfs_trans *, struct xfs_trans *);
  185. extern void xfs_trans_free_dqinfo(struct xfs_trans *);
  186. extern void xfs_trans_mod_dquot_byino(struct xfs_trans *, struct xfs_inode *,
  187. uint, long);
  188. extern void xfs_trans_apply_dquot_deltas(struct xfs_trans *);
  189. extern void xfs_trans_unreserve_and_mod_dquots(struct xfs_trans *);
  190. extern int xfs_trans_reserve_quota_nblks(struct xfs_trans *,
  191. struct xfs_inode *, long, long, uint);
  192. extern int xfs_trans_reserve_quota_bydquots(struct xfs_trans *,
  193. struct xfs_mount *, struct xfs_dquot *,
  194. struct xfs_dquot *, struct xfs_dquot *, long, long, uint);
  195. extern int xfs_qm_vop_dqalloc(struct xfs_inode *, uid_t, gid_t, prid_t, uint,
  196. struct xfs_dquot **, struct xfs_dquot **, struct xfs_dquot **);
  197. extern void xfs_qm_vop_create_dqattach(struct xfs_trans *, struct xfs_inode *,
  198. struct xfs_dquot *, struct xfs_dquot *, struct xfs_dquot *);
  199. extern int xfs_qm_vop_rename_dqattach(struct xfs_inode **);
  200. extern struct xfs_dquot *xfs_qm_vop_chown(struct xfs_trans *,
  201. struct xfs_inode *, struct xfs_dquot **, struct xfs_dquot *);
  202. extern int xfs_qm_vop_chown_reserve(struct xfs_trans *, struct xfs_inode *,
  203. struct xfs_dquot *, struct xfs_dquot *,
  204. struct xfs_dquot *, uint);
  205. extern int xfs_qm_dqattach(struct xfs_inode *, uint);
  206. extern int xfs_qm_dqattach_locked(struct xfs_inode *, uint);
  207. extern void xfs_qm_dqdetach(struct xfs_inode *);
  208. extern void xfs_qm_dqrele(struct xfs_dquot *);
  209. extern void xfs_qm_statvfs(struct xfs_inode *, struct kstatfs *);
  210. extern int xfs_qm_newmount(struct xfs_mount *, uint *, uint *);
  211. extern void xfs_qm_mount_quotas(struct xfs_mount *);
  212. extern void xfs_qm_unmount(struct xfs_mount *);
  213. extern void xfs_qm_unmount_quotas(struct xfs_mount *);
  214. #else
  215. static inline int
  216. xfs_qm_vop_dqalloc(struct xfs_inode *ip, uid_t uid, gid_t gid, prid_t prid,
  217. uint flags, struct xfs_dquot **udqp, struct xfs_dquot **gdqp,
  218. struct xfs_dquot **pdqp)
  219. {
  220. *udqp = NULL;
  221. *gdqp = NULL;
  222. *pdqp = NULL;
  223. return 0;
  224. }
  225. #define xfs_trans_dup_dqinfo(tp, tp2)
  226. #define xfs_trans_free_dqinfo(tp)
  227. #define xfs_trans_mod_dquot_byino(tp, ip, fields, delta)
  228. #define xfs_trans_apply_dquot_deltas(tp)
  229. #define xfs_trans_unreserve_and_mod_dquots(tp)
  230. static inline int xfs_trans_reserve_quota_nblks(struct xfs_trans *tp,
  231. struct xfs_inode *ip, long nblks, long ninos, uint flags)
  232. {
  233. return 0;
  234. }
  235. static inline int xfs_trans_reserve_quota_bydquots(struct xfs_trans *tp,
  236. struct xfs_mount *mp, struct xfs_dquot *udqp,
  237. struct xfs_dquot *gdqp, struct xfs_dquot *pdqp,
  238. long nblks, long nions, uint flags)
  239. {
  240. return 0;
  241. }
  242. #define xfs_qm_vop_create_dqattach(tp, ip, u, g, p)
  243. #define xfs_qm_vop_rename_dqattach(it) (0)
  244. #define xfs_qm_vop_chown(tp, ip, old, new) (NULL)
  245. #define xfs_qm_vop_chown_reserve(tp, ip, u, g, p, fl) (0)
  246. #define xfs_qm_dqattach(ip, fl) (0)
  247. #define xfs_qm_dqattach_locked(ip, fl) (0)
  248. #define xfs_qm_dqdetach(ip)
  249. #define xfs_qm_dqrele(d)
  250. #define xfs_qm_statvfs(ip, s)
  251. #define xfs_qm_newmount(mp, a, b) (0)
  252. #define xfs_qm_mount_quotas(mp)
  253. #define xfs_qm_unmount(mp)
  254. #define xfs_qm_unmount_quotas(mp)
  255. #endif /* CONFIG_XFS_QUOTA */
  256. #define xfs_trans_unreserve_quota_nblks(tp, ip, nblks, ninos, flags) \
  257. xfs_trans_reserve_quota_nblks(tp, ip, -(nblks), -(ninos), flags)
  258. #define xfs_trans_reserve_quota(tp, mp, ud, gd, pd, nb, ni, f) \
  259. xfs_trans_reserve_quota_bydquots(tp, mp, ud, gd, pd, nb, ni, \
  260. f | XFS_QMOPT_RES_REGBLKS)
  261. extern int xfs_qm_dqcheck(struct xfs_mount *, xfs_disk_dquot_t *,
  262. xfs_dqid_t, uint, uint, char *);
  263. extern int xfs_mount_reset_sbqflags(struct xfs_mount *);
  264. extern const struct xfs_buf_ops xfs_dquot_buf_ops;
  265. #endif /* __KERNEL__ */
  266. #endif /* __XFS_QUOTA_H__ */