xref: /linux/fs/xfs/xfs_quota.h (revision 0b61f8a4079d904b1b1d47946cca898313de8c26)
1*0b61f8a4SDave 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;
16fcafb71bSChristoph Hellwig 
171da177e4SLinus Torvalds /*
181da177e4SLinus Torvalds  * This check is done typically without holding the inode lock;
19c41564b5SNathan Scott  * that may seem racy, but it is harmless in the context that it is used.
201da177e4SLinus Torvalds  * The inode cannot go inactive as long a reference is kept, and
211da177e4SLinus Torvalds  * therefore if dquot(s) were attached, they'll stay consistent.
221da177e4SLinus Torvalds  * If, for example, the ownership of the inode changes while
231da177e4SLinus Torvalds  * we didn't have the inode locked, the appropriate dquot(s) will be
241da177e4SLinus Torvalds  * attached atomically.
251da177e4SLinus Torvalds  */
2692f8ff73SChandra Seetharaman #define XFS_NOT_DQATTACHED(mp, ip) \
2792f8ff73SChandra Seetharaman 	((XFS_IS_UQUOTA_ON(mp) && (ip)->i_udquot == NULL) || \
2892f8ff73SChandra Seetharaman 	 (XFS_IS_GQUOTA_ON(mp) && (ip)->i_gdquot == NULL) || \
2992f8ff73SChandra Seetharaman 	 (XFS_IS_PQUOTA_ON(mp) && (ip)->i_pdquot == NULL))
301da177e4SLinus Torvalds 
31c8ad20ffSNathan Scott #define XFS_QM_NEED_QUOTACHECK(mp) \
32c8ad20ffSNathan Scott 	((XFS_IS_UQUOTA_ON(mp) && \
33c8ad20ffSNathan Scott 		(mp->m_sb.sb_qflags & XFS_UQUOTA_CHKD) == 0) || \
341da177e4SLinus Torvalds 	 (XFS_IS_GQUOTA_ON(mp) && \
3583e782e1SChandra Seetharaman 		(mp->m_sb.sb_qflags & XFS_GQUOTA_CHKD) == 0) || \
36c8ad20ffSNathan Scott 	 (XFS_IS_PQUOTA_ON(mp) && \
3783e782e1SChandra Seetharaman 		(mp->m_sb.sb_qflags & XFS_PQUOTA_CHKD) == 0))
38c8ad20ffSNathan Scott 
397e85bc6cSDarrick J. Wong static inline uint
407e85bc6cSDarrick J. Wong xfs_quota_chkd_flag(
417e85bc6cSDarrick J. Wong 	uint		dqtype)
427e85bc6cSDarrick J. Wong {
437e85bc6cSDarrick J. Wong 	switch (dqtype) {
447e85bc6cSDarrick J. Wong 	case XFS_DQ_USER:
457e85bc6cSDarrick J. Wong 		return XFS_UQUOTA_CHKD;
467e85bc6cSDarrick J. Wong 	case XFS_DQ_GROUP:
477e85bc6cSDarrick J. Wong 		return XFS_GQUOTA_CHKD;
487e85bc6cSDarrick J. Wong 	case XFS_DQ_PROJ:
497e85bc6cSDarrick J. Wong 		return XFS_PQUOTA_CHKD;
507e85bc6cSDarrick J. Wong 	default:
517e85bc6cSDarrick J. Wong 		return 0;
527e85bc6cSDarrick J. Wong 	}
537e85bc6cSDarrick J. Wong }
547e85bc6cSDarrick J. Wong 
551da177e4SLinus Torvalds /*
561da177e4SLinus Torvalds  * The structure kept inside the xfs_trans_t keep track of dquot changes
571da177e4SLinus Torvalds  * within a transaction and apply them later.
581da177e4SLinus Torvalds  */
591da177e4SLinus Torvalds typedef struct xfs_dqtrx {
601da177e4SLinus Torvalds 	struct xfs_dquot *qt_dquot;	  /* the dquot this refers to */
611da177e4SLinus Torvalds 	ulong		qt_blk_res;	  /* blks reserved on a dquot */
621da177e4SLinus Torvalds 	ulong		qt_ino_res;	  /* inode reserved on a dquot */
631da177e4SLinus Torvalds 	ulong		qt_ino_res_used;  /* inodes used from the reservation */
641da177e4SLinus Torvalds 	long		qt_bcount_delta;  /* dquot blk count changes */
651da177e4SLinus Torvalds 	long		qt_delbcnt_delta; /* delayed dquot blk count changes */
661da177e4SLinus Torvalds 	long		qt_icount_delta;  /* dquot inode count changes */
671da177e4SLinus Torvalds 	ulong		qt_rtblk_res;	  /* # blks reserved on a dquot */
681da177e4SLinus Torvalds 	ulong		qt_rtblk_res_used;/* # blks used from reservation */
691da177e4SLinus Torvalds 	long		qt_rtbcount_delta;/* dquot realtime blk changes */
701da177e4SLinus Torvalds 	long		qt_delrtb_delta;  /* delayed RT blk count changes */
711da177e4SLinus Torvalds } xfs_dqtrx_t;
721da177e4SLinus Torvalds 
737d095257SChristoph Hellwig #ifdef CONFIG_XFS_QUOTA
747d095257SChristoph Hellwig extern void xfs_trans_dup_dqinfo(struct xfs_trans *, struct xfs_trans *);
757d095257SChristoph Hellwig extern void xfs_trans_free_dqinfo(struct xfs_trans *);
767d095257SChristoph Hellwig extern void xfs_trans_mod_dquot_byino(struct xfs_trans *, struct xfs_inode *,
777d095257SChristoph Hellwig 		uint, long);
787d095257SChristoph Hellwig extern void xfs_trans_apply_dquot_deltas(struct xfs_trans *);
797d095257SChristoph Hellwig extern void xfs_trans_unreserve_and_mod_dquots(struct xfs_trans *);
807d095257SChristoph Hellwig extern int xfs_trans_reserve_quota_nblks(struct xfs_trans *,
811da177e4SLinus Torvalds 		struct xfs_inode *, long, long, uint);
827d095257SChristoph Hellwig extern int xfs_trans_reserve_quota_bydquots(struct xfs_trans *,
837d095257SChristoph Hellwig 		struct xfs_mount *, struct xfs_dquot *,
8492f8ff73SChandra Seetharaman 		struct xfs_dquot *, struct xfs_dquot *, long, long, uint);
851da177e4SLinus Torvalds 
867aab1b28SDwight Engen extern int xfs_qm_vop_dqalloc(struct xfs_inode *, xfs_dqid_t, xfs_dqid_t,
877aab1b28SDwight Engen 		prid_t, uint, struct xfs_dquot **, struct xfs_dquot **,
887aab1b28SDwight Engen 		struct xfs_dquot **);
897d095257SChristoph Hellwig extern void xfs_qm_vop_create_dqattach(struct xfs_trans *, struct xfs_inode *,
9092f8ff73SChandra Seetharaman 		struct xfs_dquot *, struct xfs_dquot *, struct xfs_dquot *);
917d095257SChristoph Hellwig extern int xfs_qm_vop_rename_dqattach(struct xfs_inode **);
927d095257SChristoph Hellwig extern struct xfs_dquot *xfs_qm_vop_chown(struct xfs_trans *,
937d095257SChristoph Hellwig 		struct xfs_inode *, struct xfs_dquot **, struct xfs_dquot *);
947d095257SChristoph Hellwig extern int xfs_qm_vop_chown_reserve(struct xfs_trans *, struct xfs_inode *,
9592f8ff73SChandra Seetharaman 		struct xfs_dquot *, struct xfs_dquot *,
9692f8ff73SChandra Seetharaman 		struct xfs_dquot *, uint);
97c14cfccaSDarrick J. Wong extern int xfs_qm_dqattach(struct xfs_inode *);
984882c19dSDarrick J. Wong extern int xfs_qm_dqattach_locked(struct xfs_inode *ip, bool doalloc);
997d095257SChristoph Hellwig extern void xfs_qm_dqdetach(struct xfs_inode *);
1007d095257SChristoph Hellwig extern void xfs_qm_dqrele(struct xfs_dquot *);
1017d095257SChristoph Hellwig extern void xfs_qm_statvfs(struct xfs_inode *, struct kstatfs *);
1027d095257SChristoph Hellwig extern int xfs_qm_newmount(struct xfs_mount *, uint *, uint *);
1037d095257SChristoph Hellwig extern void xfs_qm_mount_quotas(struct xfs_mount *);
1047d095257SChristoph Hellwig extern void xfs_qm_unmount(struct xfs_mount *);
1057d095257SChristoph Hellwig extern void xfs_qm_unmount_quotas(struct xfs_mount *);
1061da177e4SLinus Torvalds 
1077d095257SChristoph Hellwig #else
108493b87e5SChristoph Hellwig static inline int
1097aab1b28SDwight Engen xfs_qm_vop_dqalloc(struct xfs_inode *ip, xfs_dqid_t uid, xfs_dqid_t gid,
1107aab1b28SDwight Engen 		prid_t prid, uint flags, struct xfs_dquot **udqp,
1117aab1b28SDwight Engen 		struct xfs_dquot **gdqp, struct xfs_dquot **pdqp)
112493b87e5SChristoph Hellwig {
113493b87e5SChristoph Hellwig 	*udqp = NULL;
114493b87e5SChristoph Hellwig 	*gdqp = NULL;
11592f8ff73SChandra Seetharaman 	*pdqp = NULL;
116493b87e5SChristoph Hellwig 	return 0;
117493b87e5SChristoph Hellwig }
1187d095257SChristoph Hellwig #define xfs_trans_dup_dqinfo(tp, tp2)
1197d095257SChristoph Hellwig #define xfs_trans_free_dqinfo(tp)
1207d095257SChristoph Hellwig #define xfs_trans_mod_dquot_byino(tp, ip, fields, delta)
1217d095257SChristoph Hellwig #define xfs_trans_apply_dquot_deltas(tp)
1227d095257SChristoph Hellwig #define xfs_trans_unreserve_and_mod_dquots(tp)
1235d2bf8a5SChristoph Hellwig static inline int xfs_trans_reserve_quota_nblks(struct xfs_trans *tp,
1245d2bf8a5SChristoph Hellwig 		struct xfs_inode *ip, long nblks, long ninos, uint flags)
1255d2bf8a5SChristoph Hellwig {
1265d2bf8a5SChristoph Hellwig 	return 0;
1275d2bf8a5SChristoph Hellwig }
1285d2bf8a5SChristoph Hellwig static inline int xfs_trans_reserve_quota_bydquots(struct xfs_trans *tp,
1295d2bf8a5SChristoph Hellwig 		struct xfs_mount *mp, struct xfs_dquot *udqp,
13092f8ff73SChandra Seetharaman 		struct xfs_dquot *gdqp, struct xfs_dquot *pdqp,
13192f8ff73SChandra Seetharaman 		long nblks, long nions, uint flags)
1325d2bf8a5SChristoph Hellwig {
1335d2bf8a5SChristoph Hellwig 	return 0;
1345d2bf8a5SChristoph Hellwig }
13592f8ff73SChandra Seetharaman #define xfs_qm_vop_create_dqattach(tp, ip, u, g, p)
1367d095257SChristoph Hellwig #define xfs_qm_vop_rename_dqattach(it)					(0)
1377d095257SChristoph Hellwig #define xfs_qm_vop_chown(tp, ip, old, new)				(NULL)
13892f8ff73SChandra Seetharaman #define xfs_qm_vop_chown_reserve(tp, ip, u, g, p, fl)			(0)
139c14cfccaSDarrick J. Wong #define xfs_qm_dqattach(ip)						(0)
1407d095257SChristoph Hellwig #define xfs_qm_dqattach_locked(ip, fl)					(0)
1417d095257SChristoph Hellwig #define xfs_qm_dqdetach(ip)
1427d095257SChristoph Hellwig #define xfs_qm_dqrele(d)
1437d095257SChristoph Hellwig #define xfs_qm_statvfs(ip, s)
1447d095257SChristoph Hellwig #define xfs_qm_newmount(mp, a, b)					(0)
1457d095257SChristoph Hellwig #define xfs_qm_mount_quotas(mp)
1467d095257SChristoph Hellwig #define xfs_qm_unmount(mp)
1475d2bf8a5SChristoph Hellwig #define xfs_qm_unmount_quotas(mp)
1487d095257SChristoph Hellwig #endif /* CONFIG_XFS_QUOTA */
1491da177e4SLinus Torvalds 
1507d095257SChristoph Hellwig #define xfs_trans_unreserve_quota_nblks(tp, ip, nblks, ninos, flags) \
1517d095257SChristoph Hellwig 	xfs_trans_reserve_quota_nblks(tp, ip, -(nblks), -(ninos), flags)
15292f8ff73SChandra Seetharaman #define xfs_trans_reserve_quota(tp, mp, ud, gd, pd, nb, ni, f) \
15392f8ff73SChandra Seetharaman 	xfs_trans_reserve_quota_bydquots(tp, mp, ud, gd, pd, nb, ni, \
1541da177e4SLinus Torvalds 				f | XFS_QMOPT_RES_REGBLKS)
1551da177e4SLinus Torvalds 
1564cd4a034STim Shimmin extern int xfs_mount_reset_sbqflags(struct xfs_mount *);
1571da177e4SLinus Torvalds 
1581da177e4SLinus Torvalds #endif	/* __XFS_QUOTA_H__ */
159