10b61f8a4SDave Chinner // SPDX-License-Identifier: GPL-2.0 21da177e4SLinus Torvalds /* 37b718769SNathan Scott * Copyright (c) 2000-2005 Silicon Graphics, Inc. 47b718769SNathan Scott * All Rights Reserved. 51da177e4SLinus Torvalds */ 61da177e4SLinus Torvalds #ifndef __XFS_QUOTA_H__ 71da177e4SLinus Torvalds #define __XFS_QUOTA_H__ 81da177e4SLinus Torvalds 976456fc2SDave Chinner #include "xfs_quota_defs.h" 1076456fc2SDave Chinner 1176456fc2SDave Chinner /* 1276456fc2SDave Chinner * Kernel only quota definitions and functions 1376456fc2SDave Chinner */ 1476456fc2SDave Chinner 15fcafb71bSChristoph Hellwig struct xfs_trans; 166f5de180SDave Chinner struct xfs_buf; 17fcafb71bSChristoph Hellwig 181da177e4SLinus Torvalds /* 191da177e4SLinus Torvalds * This check is done typically without holding the inode lock; 20c41564b5SNathan Scott * that may seem racy, but it is harmless in the context that it is used. 211da177e4SLinus Torvalds * The inode cannot go inactive as long a reference is kept, and 221da177e4SLinus Torvalds * therefore if dquot(s) were attached, they'll stay consistent. 231da177e4SLinus Torvalds * If, for example, the ownership of the inode changes while 241da177e4SLinus Torvalds * we didn't have the inode locked, the appropriate dquot(s) will be 251da177e4SLinus Torvalds * attached atomically. 261da177e4SLinus Torvalds */ 2792f8ff73SChandra Seetharaman #define XFS_NOT_DQATTACHED(mp, ip) \ 2892f8ff73SChandra Seetharaman ((XFS_IS_UQUOTA_ON(mp) && (ip)->i_udquot == NULL) || \ 2992f8ff73SChandra Seetharaman (XFS_IS_GQUOTA_ON(mp) && (ip)->i_gdquot == NULL) || \ 3092f8ff73SChandra Seetharaman (XFS_IS_PQUOTA_ON(mp) && (ip)->i_pdquot == NULL)) 311da177e4SLinus Torvalds 32c8ad20ffSNathan Scott #define XFS_QM_NEED_QUOTACHECK(mp) \ 33c8ad20ffSNathan Scott ((XFS_IS_UQUOTA_ON(mp) && \ 34c8ad20ffSNathan Scott (mp->m_sb.sb_qflags & XFS_UQUOTA_CHKD) == 0) || \ 351da177e4SLinus Torvalds (XFS_IS_GQUOTA_ON(mp) && \ 3683e782e1SChandra Seetharaman (mp->m_sb.sb_qflags & XFS_GQUOTA_CHKD) == 0) || \ 37c8ad20ffSNathan Scott (XFS_IS_PQUOTA_ON(mp) && \ 3883e782e1SChandra Seetharaman (mp->m_sb.sb_qflags & XFS_PQUOTA_CHKD) == 0)) 39c8ad20ffSNathan Scott 407e85bc6cSDarrick J. Wong static inline uint 417e85bc6cSDarrick J. Wong xfs_quota_chkd_flag( 421a7ed271SDarrick J. Wong xfs_dqtype_t type) 437e85bc6cSDarrick J. Wong { 441a7ed271SDarrick J. Wong switch (type) { 458cd4901dSDarrick J. Wong case XFS_DQTYPE_USER: 467e85bc6cSDarrick J. Wong return XFS_UQUOTA_CHKD; 478cd4901dSDarrick J. Wong case XFS_DQTYPE_GROUP: 487e85bc6cSDarrick J. Wong return XFS_GQUOTA_CHKD; 498cd4901dSDarrick J. Wong case XFS_DQTYPE_PROJ: 507e85bc6cSDarrick J. Wong return XFS_PQUOTA_CHKD; 517e85bc6cSDarrick J. Wong default: 527e85bc6cSDarrick J. Wong return 0; 537e85bc6cSDarrick J. Wong } 547e85bc6cSDarrick J. Wong } 557e85bc6cSDarrick J. Wong 561da177e4SLinus Torvalds /* 571da177e4SLinus Torvalds * The structure kept inside the xfs_trans_t keep track of dquot changes 581da177e4SLinus Torvalds * within a transaction and apply them later. 591da177e4SLinus Torvalds */ 60078f4a7dSDarrick J. Wong struct xfs_dqtrx { 611da177e4SLinus Torvalds struct xfs_dquot *qt_dquot; /* the dquot this refers to */ 62903b1fc2SDarrick J. Wong 63903b1fc2SDarrick J. Wong uint64_t qt_blk_res; /* blks reserved on a dquot */ 64903b1fc2SDarrick J. Wong int64_t qt_bcount_delta; /* dquot blk count changes */ 65903b1fc2SDarrick J. Wong int64_t qt_delbcnt_delta; /* delayed dquot blk count changes */ 66903b1fc2SDarrick J. Wong 67903b1fc2SDarrick J. Wong uint64_t qt_rtblk_res; /* # blks reserved on a dquot */ 68903b1fc2SDarrick J. Wong uint64_t qt_rtblk_res_used;/* # blks used from reservation */ 69903b1fc2SDarrick J. Wong int64_t qt_rtbcount_delta;/* dquot realtime blk changes */ 70903b1fc2SDarrick J. Wong int64_t qt_delrtb_delta; /* delayed RT blk count changes */ 71903b1fc2SDarrick J. Wong 72903b1fc2SDarrick J. Wong uint64_t qt_ino_res; /* inode reserved on a dquot */ 73903b1fc2SDarrick J. Wong uint64_t qt_ino_res_used; /* inodes used from the reservation */ 74903b1fc2SDarrick J. Wong int64_t qt_icount_delta; /* dquot inode count changes */ 75078f4a7dSDarrick J. Wong }; 761da177e4SLinus Torvalds 7720049187SDarrick J. Wong enum xfs_apply_dqtrx_type { 7820049187SDarrick J. Wong XFS_APPLY_DQTRX_COMMIT = 0, 7920049187SDarrick J. Wong XFS_APPLY_DQTRX_UNRESERVE, 8020049187SDarrick J. Wong }; 8120049187SDarrick J. Wong 8220049187SDarrick J. Wong /* 8320049187SDarrick J. Wong * Parameters for applying dqtrx changes to a dquot. The hook function arg 8420049187SDarrick J. Wong * parameter is enum xfs_apply_dqtrx_type. 8520049187SDarrick J. Wong */ 8620049187SDarrick J. Wong struct xfs_apply_dqtrx_params { 8720049187SDarrick J. Wong uintptr_t tx_id; 8820049187SDarrick J. Wong xfs_ino_t ino; 8920049187SDarrick J. Wong xfs_dqtype_t q_type; 9020049187SDarrick J. Wong xfs_dqid_t q_id; 9120049187SDarrick J. Wong }; 9220049187SDarrick J. Wong 937d095257SChristoph Hellwig #ifdef CONFIG_XFS_QUOTA 947d095257SChristoph Hellwig extern void xfs_trans_dup_dqinfo(struct xfs_trans *, struct xfs_trans *); 957d095257SChristoph Hellwig extern void xfs_trans_free_dqinfo(struct xfs_trans *); 967d095257SChristoph Hellwig extern void xfs_trans_mod_dquot_byino(struct xfs_trans *, struct xfs_inode *, 97903b1fc2SDarrick J. Wong uint, int64_t); 987d095257SChristoph Hellwig extern void xfs_trans_apply_dquot_deltas(struct xfs_trans *); 997d095257SChristoph Hellwig extern void xfs_trans_unreserve_and_mod_dquots(struct xfs_trans *); 10002b7ee4eSDarrick J. Wong int xfs_trans_reserve_quota_nblks(struct xfs_trans *tp, struct xfs_inode *ip, 10102b7ee4eSDarrick J. Wong int64_t dblocks, int64_t rblocks, bool force); 1027d095257SChristoph Hellwig extern int xfs_trans_reserve_quota_bydquots(struct xfs_trans *, 1037d095257SChristoph Hellwig struct xfs_mount *, struct xfs_dquot *, 104903b1fc2SDarrick J. Wong struct xfs_dquot *, struct xfs_dquot *, int64_t, long, uint); 105ad4a7473SDarrick J. Wong int xfs_trans_reserve_quota_icreate(struct xfs_trans *tp, 106ad4a7473SDarrick J. Wong struct xfs_dquot *udqp, struct xfs_dquot *gdqp, 107ad4a7473SDarrick J. Wong struct xfs_dquot *pdqp, int64_t dblocks); 1081da177e4SLinus Torvalds 10954295159SChristoph Hellwig extern int xfs_qm_vop_dqalloc(struct xfs_inode *, kuid_t, kgid_t, 1107aab1b28SDwight Engen prid_t, uint, struct xfs_dquot **, struct xfs_dquot **, 1117aab1b28SDwight Engen struct xfs_dquot **); 1127d095257SChristoph Hellwig extern void xfs_qm_vop_create_dqattach(struct xfs_trans *, struct xfs_inode *, 11392f8ff73SChandra Seetharaman struct xfs_dquot *, struct xfs_dquot *, struct xfs_dquot *); 1147d095257SChristoph Hellwig extern int xfs_qm_vop_rename_dqattach(struct xfs_inode **); 1157d095257SChristoph Hellwig extern struct xfs_dquot *xfs_qm_vop_chown(struct xfs_trans *, 1167d095257SChristoph Hellwig struct xfs_inode *, struct xfs_dquot **, struct xfs_dquot *); 117c14cfccaSDarrick J. Wong extern int xfs_qm_dqattach(struct xfs_inode *); 1184882c19dSDarrick J. Wong extern int xfs_qm_dqattach_locked(struct xfs_inode *ip, bool doalloc); 1197d095257SChristoph Hellwig extern void xfs_qm_dqdetach(struct xfs_inode *); 1207d095257SChristoph Hellwig extern void xfs_qm_dqrele(struct xfs_dquot *); 1217d095257SChristoph Hellwig extern void xfs_qm_statvfs(struct xfs_inode *, struct kstatfs *); 1227d095257SChristoph Hellwig extern int xfs_qm_newmount(struct xfs_mount *, uint *, uint *); 1237d095257SChristoph Hellwig extern void xfs_qm_mount_quotas(struct xfs_mount *); 1247d095257SChristoph Hellwig extern void xfs_qm_unmount(struct xfs_mount *); 1257d095257SChristoph Hellwig extern void xfs_qm_unmount_quotas(struct xfs_mount *); 126108523b8SDarrick J. Wong bool xfs_inode_near_dquot_enforcement(struct xfs_inode *ip, xfs_dqtype_t type); 12720049187SDarrick J. Wong 12820049187SDarrick J. Wong # ifdef CONFIG_XFS_LIVE_HOOKS 12920049187SDarrick J. Wong void xfs_trans_mod_ino_dquot(struct xfs_trans *tp, struct xfs_inode *ip, 13020049187SDarrick J. Wong struct xfs_dquot *dqp, unsigned int field, int64_t delta); 13120049187SDarrick J. Wong 13220049187SDarrick J. Wong struct xfs_quotainfo; 13320049187SDarrick J. Wong 13420049187SDarrick J. Wong struct xfs_dqtrx_hook { 13520049187SDarrick J. Wong struct xfs_hook mod_hook; 13620049187SDarrick J. Wong struct xfs_hook apply_hook; 13720049187SDarrick J. Wong }; 13820049187SDarrick J. Wong 13920049187SDarrick J. Wong void xfs_dqtrx_hook_disable(void); 14020049187SDarrick J. Wong void xfs_dqtrx_hook_enable(void); 14120049187SDarrick J. Wong 14220049187SDarrick J. Wong int xfs_dqtrx_hook_add(struct xfs_quotainfo *qi, struct xfs_dqtrx_hook *hook); 14320049187SDarrick J. Wong void xfs_dqtrx_hook_del(struct xfs_quotainfo *qi, struct xfs_dqtrx_hook *hook); 14420049187SDarrick J. Wong void xfs_dqtrx_hook_setup(struct xfs_dqtrx_hook *hook, notifier_fn_t mod_fn, 14520049187SDarrick J. Wong notifier_fn_t apply_fn); 14620049187SDarrick J. Wong # else 14720049187SDarrick J. Wong # define xfs_trans_mod_ino_dquot(tp, ip, dqp, field, delta) \ 14820049187SDarrick J. Wong xfs_trans_mod_dquot((tp), (dqp), (field), (delta)) 14920049187SDarrick J. Wong # endif /* CONFIG_XFS_LIVE_HOOKS */ 15020049187SDarrick J. Wong 1517d095257SChristoph Hellwig #else 152493b87e5SChristoph Hellwig static inline int 15354295159SChristoph Hellwig xfs_qm_vop_dqalloc(struct xfs_inode *ip, kuid_t kuid, kgid_t kgid, 1547aab1b28SDwight Engen prid_t prid, uint flags, struct xfs_dquot **udqp, 1557aab1b28SDwight Engen struct xfs_dquot **gdqp, struct xfs_dquot **pdqp) 156493b87e5SChristoph Hellwig { 157493b87e5SChristoph Hellwig *udqp = NULL; 158493b87e5SChristoph Hellwig *gdqp = NULL; 15992f8ff73SChandra Seetharaman *pdqp = NULL; 160493b87e5SChristoph Hellwig return 0; 161493b87e5SChristoph Hellwig } 1627d095257SChristoph Hellwig #define xfs_trans_dup_dqinfo(tp, tp2) 1637d095257SChristoph Hellwig #define xfs_trans_free_dqinfo(tp) 164825b49e4SChristoph Hellwig static inline void xfs_trans_mod_dquot_byino(struct xfs_trans *tp, 165825b49e4SChristoph Hellwig struct xfs_inode *ip, uint field, int64_t delta) 166825b49e4SChristoph Hellwig { 167825b49e4SChristoph Hellwig } 1687d095257SChristoph Hellwig #define xfs_trans_apply_dquot_deltas(tp) 1697d095257SChristoph Hellwig #define xfs_trans_unreserve_and_mod_dquots(tp) 1705d2bf8a5SChristoph Hellwig static inline int xfs_trans_reserve_quota_nblks(struct xfs_trans *tp, 17102b7ee4eSDarrick J. Wong struct xfs_inode *ip, int64_t dblocks, int64_t rblocks, 17202b7ee4eSDarrick J. Wong bool force) 1735d2bf8a5SChristoph Hellwig { 1745d2bf8a5SChristoph Hellwig return 0; 1755d2bf8a5SChristoph Hellwig } 1765d2bf8a5SChristoph Hellwig static inline int xfs_trans_reserve_quota_bydquots(struct xfs_trans *tp, 1775d2bf8a5SChristoph Hellwig struct xfs_mount *mp, struct xfs_dquot *udqp, 17892f8ff73SChandra Seetharaman struct xfs_dquot *gdqp, struct xfs_dquot *pdqp, 179903b1fc2SDarrick J. Wong int64_t nblks, long nions, uint flags) 1805d2bf8a5SChristoph Hellwig { 1815d2bf8a5SChristoph Hellwig return 0; 1825d2bf8a5SChristoph Hellwig } 18385546500SDarrick J. Wong 18485546500SDarrick J. Wong static inline int 185ad4a7473SDarrick J. Wong xfs_trans_reserve_quota_icreate(struct xfs_trans *tp, struct xfs_dquot *udqp, 186ad4a7473SDarrick J. Wong struct xfs_dquot *gdqp, struct xfs_dquot *pdqp, int64_t dblocks) 187ad4a7473SDarrick J. Wong { 188ad4a7473SDarrick J. Wong return 0; 189ad4a7473SDarrick J. Wong } 190ad4a7473SDarrick J. Wong 19192f8ff73SChandra Seetharaman #define xfs_qm_vop_create_dqattach(tp, ip, u, g, p) 1927d095257SChristoph Hellwig #define xfs_qm_vop_rename_dqattach(it) (0) 1937d095257SChristoph Hellwig #define xfs_qm_vop_chown(tp, ip, old, new) (NULL) 194c14cfccaSDarrick J. Wong #define xfs_qm_dqattach(ip) (0) 1957d095257SChristoph Hellwig #define xfs_qm_dqattach_locked(ip, fl) (0) 1967d095257SChristoph Hellwig #define xfs_qm_dqdetach(ip) 1977ac6eb46SDarrick J. Wong #define xfs_qm_dqrele(d) do { (d) = (d); } while(0) 1987ac6eb46SDarrick J. Wong #define xfs_qm_statvfs(ip, s) do { } while(0) 1997d095257SChristoph Hellwig #define xfs_qm_newmount(mp, a, b) (0) 2007d095257SChristoph Hellwig #define xfs_qm_mount_quotas(mp) 2017d095257SChristoph Hellwig #define xfs_qm_unmount(mp) 2025d2bf8a5SChristoph Hellwig #define xfs_qm_unmount_quotas(mp) 203108523b8SDarrick J. Wong #define xfs_inode_near_dquot_enforcement(ip, type) (false) 20420049187SDarrick J. Wong 20520049187SDarrick J. Wong # ifdef CONFIG_XFS_LIVE_HOOKS 20620049187SDarrick J. Wong # define xfs_dqtrx_hook_enable() ((void)0) 20720049187SDarrick J. Wong # define xfs_dqtrx_hook_disable() ((void)0) 20820049187SDarrick J. Wong # endif /* CONFIG_XFS_LIVE_HOOKS */ 20920049187SDarrick J. Wong 2107d095257SChristoph Hellwig #endif /* CONFIG_XFS_QUOTA */ 2111da177e4SLinus Torvalds 21285546500SDarrick J. Wong static inline int 213f7b9ee78SChristoph Hellwig xfs_quota_reserve_blkres(struct xfs_inode *ip, int64_t blocks) 214f7b9ee78SChristoph Hellwig { 215f7b9ee78SChristoph Hellwig return xfs_trans_reserve_quota_nblks(NULL, ip, blocks, 0, false); 216f7b9ee78SChristoph Hellwig } 217f7b9ee78SChristoph Hellwig 218*cc3c92e7SChristoph Hellwig static inline void 219*cc3c92e7SChristoph Hellwig xfs_quota_unreserve_blkres(struct xfs_inode *ip, uint64_t blocks) 22085546500SDarrick J. Wong { 221*cc3c92e7SChristoph Hellwig /* don't return an error as unreserving quotas can't fail */ 222*cc3c92e7SChristoph Hellwig xfs_quota_reserve_blkres(ip, -(int64_t)blocks); 22385546500SDarrick J. Wong } 22485546500SDarrick J. Wong 2254cd4a034STim Shimmin extern int xfs_mount_reset_sbqflags(struct xfs_mount *); 2261da177e4SLinus Torvalds 2271da177e4SLinus Torvalds #endif /* __XFS_QUOTA_H__ */ 228