xref: /openbmc/linux/fs/xfs/xfs_qm.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
10b61f8a4SDave Chinner // SPDX-License-Identifier: GPL-2.0
2c59d87c4SChristoph Hellwig /*
3c59d87c4SChristoph Hellwig  * Copyright (c) 2000-2005 Silicon Graphics, Inc.
4c59d87c4SChristoph Hellwig  * All Rights Reserved.
5c59d87c4SChristoph Hellwig  */
6c59d87c4SChristoph Hellwig #ifndef __XFS_QM_H__
7c59d87c4SChristoph Hellwig #define __XFS_QM_H__
8c59d87c4SChristoph Hellwig 
9c59d87c4SChristoph Hellwig #include "xfs_dquot_item.h"
10c59d87c4SChristoph Hellwig #include "xfs_dquot.h"
11c59d87c4SChristoph Hellwig 
12c59d87c4SChristoph Hellwig struct xfs_inode;
13c59d87c4SChristoph Hellwig 
14*182696fbSDarrick J. Wong extern struct kmem_cache	*xfs_dqtrx_cache;
15c59d87c4SChristoph Hellwig 
16c59d87c4SChristoph Hellwig /*
17afbd123dSJie Liu  * Number of bmaps that we ask from bmapi when doing a quotacheck.
18afbd123dSJie Liu  * We make this restriction to keep the memory usage to a minimum.
19afbd123dSJie Liu  */
20afbd123dSJie Liu #define XFS_DQITER_MAP_SIZE	10
21afbd123dSJie Liu 
22afbd123dSJie Liu #define XFS_IS_DQUOT_UNINITIALIZED(dqp) ( \
23d3537cf9SDarrick J. Wong 	!dqp->q_blk.hardlimit && \
24d3537cf9SDarrick J. Wong 	!dqp->q_blk.softlimit && \
25d3537cf9SDarrick J. Wong 	!dqp->q_rtb.hardlimit && \
26d3537cf9SDarrick J. Wong 	!dqp->q_rtb.softlimit && \
27d3537cf9SDarrick J. Wong 	!dqp->q_ino.hardlimit && \
28d3537cf9SDarrick J. Wong 	!dqp->q_ino.softlimit && \
29be37d40cSDarrick J. Wong 	!dqp->q_blk.count && \
30be37d40cSDarrick J. Wong 	!dqp->q_rtb.count && \
31be37d40cSDarrick J. Wong 	!dqp->q_ino.count)
32afbd123dSJie Liu 
33438769e3SDarrick J. Wong struct xfs_quota_limits {
34438769e3SDarrick J. Wong 	xfs_qcnt_t		hard;	/* default hard limit */
35438769e3SDarrick J. Wong 	xfs_qcnt_t		soft;	/* default soft limit */
36438769e3SDarrick J. Wong 	time64_t		time;	/* limit for timers */
37438769e3SDarrick J. Wong };
38438769e3SDarrick J. Wong 
39e850301fSEric Sandeen /* Defaults for each quota type: time limits, warn limits, usage limits */
40be607946SCarlos Maiolino struct xfs_def_quota {
41438769e3SDarrick J. Wong 	struct xfs_quota_limits	blk;
42438769e3SDarrick J. Wong 	struct xfs_quota_limits	ino;
43438769e3SDarrick J. Wong 	struct xfs_quota_limits	rtb;
44be607946SCarlos Maiolino };
45be607946SCarlos Maiolino 
46c59d87c4SChristoph Hellwig /*
47c59d87c4SChristoph Hellwig  * Various quota information for individual filesystems.
48c59d87c4SChristoph Hellwig  * The mount structure keeps a pointer to this.
49c59d87c4SChristoph Hellwig  */
50c072fbefSPavel Reichl struct xfs_quotainfo {
519f920f11SChristoph Hellwig 	struct radix_tree_root	qi_uquota_tree;
529f920f11SChristoph Hellwig 	struct radix_tree_root	qi_gquota_tree;
5392f8ff73SChandra Seetharaman 	struct radix_tree_root	qi_pquota_tree;
549f920f11SChristoph Hellwig 	struct mutex		qi_tree_lock;
5592f8ff73SChandra Seetharaman 	struct xfs_inode	*qi_uquotaip;	/* user quota inode */
5692f8ff73SChandra Seetharaman 	struct xfs_inode	*qi_gquotaip;	/* group quota inode */
5792f8ff73SChandra Seetharaman 	struct xfs_inode	*qi_pquotaip;	/* project quota inode */
58cd56a39aSDave Chinner 	struct list_lru		qi_lru;
59c59d87c4SChristoph Hellwig 	int			qi_dquots;
60c59d87c4SChristoph Hellwig 	struct mutex		qi_quotaofflock;/* to serialize quotaoff */
61c59d87c4SChristoph Hellwig 	xfs_filblks_t		qi_dqchunklen;	/* # BBs in a chunk of dqs */
628d077f5bSEric Sandeen 	uint			qi_dqperchunk;	/* # ondisk dq in above chunk */
63be607946SCarlos Maiolino 	struct xfs_def_quota	qi_usr_default;
64be607946SCarlos Maiolino 	struct xfs_def_quota	qi_grp_default;
65be607946SCarlos Maiolino 	struct xfs_def_quota	qi_prj_default;
66f8739c3cSChristoph Hellwig 	struct shrinker		qi_shrinker;
6711d8a919SDarrick J. Wong 
6811d8a919SDarrick J. Wong 	/* Minimum and maximum quota expiration timestamp values. */
6911d8a919SDarrick J. Wong 	time64_t		qi_expiry_min;
7011d8a919SDarrick J. Wong 	time64_t		qi_expiry_max;
71c072fbefSPavel Reichl };
72c59d87c4SChristoph Hellwig 
73329e0875SChandra Seetharaman static inline struct radix_tree_root *
xfs_dquot_tree(struct xfs_quotainfo * qi,xfs_dqtype_t type)74329e0875SChandra Seetharaman xfs_dquot_tree(
75329e0875SChandra Seetharaman 	struct xfs_quotainfo	*qi,
761a7ed271SDarrick J. Wong 	xfs_dqtype_t		type)
77329e0875SChandra Seetharaman {
78329e0875SChandra Seetharaman 	switch (type) {
798cd4901dSDarrick J. Wong 	case XFS_DQTYPE_USER:
80329e0875SChandra Seetharaman 		return &qi->qi_uquota_tree;
818cd4901dSDarrick J. Wong 	case XFS_DQTYPE_GROUP:
82329e0875SChandra Seetharaman 		return &qi->qi_gquota_tree;
838cd4901dSDarrick J. Wong 	case XFS_DQTYPE_PROJ:
8492f8ff73SChandra Seetharaman 		return &qi->qi_pquota_tree;
85329e0875SChandra Seetharaman 	default:
86329e0875SChandra Seetharaman 		ASSERT(0);
87329e0875SChandra Seetharaman 	}
88329e0875SChandra Seetharaman 	return NULL;
89329e0875SChandra Seetharaman }
90995961c4SChandra Seetharaman 
91995961c4SChandra Seetharaman static inline struct xfs_inode *
xfs_quota_inode(struct xfs_mount * mp,xfs_dqtype_t type)921a7ed271SDarrick J. Wong xfs_quota_inode(struct xfs_mount *mp, xfs_dqtype_t type)
93995961c4SChandra Seetharaman {
941a7ed271SDarrick J. Wong 	switch (type) {
958cd4901dSDarrick J. Wong 	case XFS_DQTYPE_USER:
964d4d9523SEric Sandeen 		return mp->m_quotainfo->qi_uquotaip;
978cd4901dSDarrick J. Wong 	case XFS_DQTYPE_GROUP:
984d4d9523SEric Sandeen 		return mp->m_quotainfo->qi_gquotaip;
998cd4901dSDarrick J. Wong 	case XFS_DQTYPE_PROJ:
1004d4d9523SEric Sandeen 		return mp->m_quotainfo->qi_pquotaip;
101995961c4SChandra Seetharaman 	default:
102995961c4SChandra Seetharaman 		ASSERT(0);
103995961c4SChandra Seetharaman 	}
104995961c4SChandra Seetharaman 	return NULL;
105995961c4SChandra Seetharaman }
106995961c4SChandra Seetharaman 
107903b1fc2SDarrick J. Wong extern void	xfs_trans_mod_dquot(struct xfs_trans *tp, struct xfs_dquot *dqp,
108903b1fc2SDarrick J. Wong 				    uint field, int64_t delta);
109113a5683SChandra Seetharaman extern void	xfs_trans_dqjoin(struct xfs_trans *, struct xfs_dquot *);
110113a5683SChandra Seetharaman extern void	xfs_trans_log_dquot(struct xfs_trans *, struct xfs_dquot *);
111c59d87c4SChristoph Hellwig 
112c59d87c4SChristoph Hellwig /*
11392f8ff73SChandra Seetharaman  * We keep the usr, grp, and prj dquots separately so that locking will be
11492f8ff73SChandra Seetharaman  * easier to do at commit time. All transactions that we know of at this point
115c59d87c4SChristoph Hellwig  * affect no more than two dquots of one type. Hence, the TRANS_MAXDQS value.
116c59d87c4SChristoph Hellwig  */
1170e6436d9SChandra Seetharaman enum {
1180e6436d9SChandra Seetharaman 	XFS_QM_TRANS_USR = 0,
1190e6436d9SChandra Seetharaman 	XFS_QM_TRANS_GRP,
12092f8ff73SChandra Seetharaman 	XFS_QM_TRANS_PRJ,
1210e6436d9SChandra Seetharaman 	XFS_QM_TRANS_DQTYPES
1220e6436d9SChandra Seetharaman };
123c59d87c4SChristoph Hellwig #define XFS_QM_TRANS_MAXDQS		2
1240e6436d9SChandra Seetharaman struct xfs_dquot_acct {
1250e6436d9SChandra Seetharaman 	struct xfs_dqtrx	dqs[XFS_QM_TRANS_DQTYPES][XFS_QM_TRANS_MAXDQS];
1260e6436d9SChandra Seetharaman };
127c59d87c4SChristoph Hellwig 
128c59d87c4SChristoph Hellwig /*
129c59d87c4SChristoph Hellwig  * Users are allowed to have a usage exceeding their softlimit for
130c59d87c4SChristoph Hellwig  * a period this long.
131c59d87c4SChristoph Hellwig  */
132c59d87c4SChristoph Hellwig #define XFS_QM_BTIMELIMIT	(7 * 24*60*60)          /* 1 week */
133c59d87c4SChristoph Hellwig #define XFS_QM_RTBTIMELIMIT	(7 * 24*60*60)          /* 1 week */
134c59d87c4SChristoph Hellwig #define XFS_QM_ITIMELIMIT	(7 * 24*60*60)          /* 1 week */
135c59d87c4SChristoph Hellwig 
136113a5683SChandra Seetharaman extern void		xfs_qm_destroy_quotainfo(struct xfs_mount *);
137c59d87c4SChristoph Hellwig 
138c59d87c4SChristoph Hellwig /* quota ops */
139113a5683SChandra Seetharaman extern int		xfs_qm_scall_trunc_qfiles(struct xfs_mount *, uint);
1401a7ed271SDarrick J. Wong extern int		xfs_qm_scall_getquota(struct xfs_mount *mp,
1411a7ed271SDarrick J. Wong 					xfs_dqid_t id,
1421a7ed271SDarrick J. Wong 					xfs_dqtype_t type,
1431a7ed271SDarrick J. Wong 					struct qc_dqblk *dst);
1441a7ed271SDarrick J. Wong extern int		xfs_qm_scall_getquota_next(struct xfs_mount *mp,
1451a7ed271SDarrick J. Wong 					xfs_dqid_t *id,
1461a7ed271SDarrick J. Wong 					xfs_dqtype_t type,
1471a7ed271SDarrick J. Wong 					struct qc_dqblk *dst);
1481a7ed271SDarrick J. Wong extern int		xfs_qm_scall_setqlim(struct xfs_mount *mp,
1491a7ed271SDarrick J. Wong 					xfs_dqid_t id,
1501a7ed271SDarrick J. Wong 					xfs_dqtype_t type,
1511a7ed271SDarrick J. Wong 					struct qc_dqblk *newlim);
152113a5683SChandra Seetharaman extern int		xfs_qm_scall_quotaon(struct xfs_mount *, uint);
153113a5683SChandra Seetharaman extern int		xfs_qm_scall_quotaoff(struct xfs_mount *, uint);
154c59d87c4SChristoph Hellwig 
155be607946SCarlos Maiolino static inline struct xfs_def_quota *
xfs_get_defquota(struct xfs_quotainfo * qi,xfs_dqtype_t type)1561a7ed271SDarrick J. Wong xfs_get_defquota(struct xfs_quotainfo *qi, xfs_dqtype_t type)
157be607946SCarlos Maiolino {
158ce6e7e79SEric Sandeen 	switch (type) {
1598cd4901dSDarrick J. Wong 	case XFS_DQTYPE_USER:
160ce6e7e79SEric Sandeen 		return &qi->qi_usr_default;
1618cd4901dSDarrick J. Wong 	case XFS_DQTYPE_GROUP:
162ce6e7e79SEric Sandeen 		return &qi->qi_grp_default;
1638cd4901dSDarrick J. Wong 	case XFS_DQTYPE_PROJ:
164ce6e7e79SEric Sandeen 		return &qi->qi_prj_default;
165ce6e7e79SEric Sandeen 	default:
166ce6e7e79SEric Sandeen 		ASSERT(0);
167ce6e7e79SEric Sandeen 		return NULL;
168be607946SCarlos Maiolino 	}
169be607946SCarlos Maiolino }
170be607946SCarlos Maiolino 
171c59d87c4SChristoph Hellwig #endif /* __XFS_QM_H__ */
172