xref: /linux/fs/xfs/xfs_qm.h (revision ebf68996de0ab250c5d520eb2291ab65643e9a1e)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2000-2005 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6 #ifndef __XFS_QM_H__
7 #define __XFS_QM_H__
8 
9 #include "xfs_dquot_item.h"
10 #include "xfs_dquot.h"
11 
12 struct xfs_inode;
13 
14 extern struct kmem_zone	*xfs_qm_dqtrxzone;
15 
16 /*
17  * Number of bmaps that we ask from bmapi when doing a quotacheck.
18  * We make this restriction to keep the memory usage to a minimum.
19  */
20 #define XFS_DQITER_MAP_SIZE	10
21 
22 #define XFS_IS_DQUOT_UNINITIALIZED(dqp) ( \
23 	!dqp->q_core.d_blk_hardlimit && \
24 	!dqp->q_core.d_blk_softlimit && \
25 	!dqp->q_core.d_rtb_hardlimit && \
26 	!dqp->q_core.d_rtb_softlimit && \
27 	!dqp->q_core.d_ino_hardlimit && \
28 	!dqp->q_core.d_ino_softlimit && \
29 	!dqp->q_core.d_bcount && \
30 	!dqp->q_core.d_rtbcount && \
31 	!dqp->q_core.d_icount)
32 
33 /*
34  * This defines the unit of allocation of dquots.
35  * Currently, it is just one file system block, and a 4K blk contains 30
36  * (136 * 30 = 4080) dquots. It's probably not worth trying to make
37  * this more dynamic.
38  * XXXsup However, if this number is changed, we have to make sure that we don't
39  * implicitly assume that we do allocations in chunks of a single filesystem
40  * block in the dquot/xqm code.
41  */
42 #define XFS_DQUOT_CLUSTER_SIZE_FSB	(xfs_filblks_t)1
43 
44 struct xfs_def_quota {
45 	xfs_qcnt_t       bhardlimit;     /* default data blk hard limit */
46 	xfs_qcnt_t       bsoftlimit;	 /* default data blk soft limit */
47 	xfs_qcnt_t       ihardlimit;	 /* default inode count hard limit */
48 	xfs_qcnt_t       isoftlimit;	 /* default inode count soft limit */
49 	xfs_qcnt_t	 rtbhardlimit;   /* default realtime blk hard limit */
50 	xfs_qcnt_t	 rtbsoftlimit;   /* default realtime blk soft limit */
51 };
52 
53 /*
54  * Various quota information for individual filesystems.
55  * The mount structure keeps a pointer to this.
56  */
57 typedef struct xfs_quotainfo {
58 	struct radix_tree_root qi_uquota_tree;
59 	struct radix_tree_root qi_gquota_tree;
60 	struct radix_tree_root qi_pquota_tree;
61 	struct mutex qi_tree_lock;
62 	struct xfs_inode	*qi_uquotaip;	/* user quota inode */
63 	struct xfs_inode	*qi_gquotaip;	/* group quota inode */
64 	struct xfs_inode	*qi_pquotaip;	/* project quota inode */
65 	struct list_lru	 qi_lru;
66 	int		 qi_dquots;
67 	time_t		 qi_btimelimit;	 /* limit for blks timer */
68 	time_t		 qi_itimelimit;	 /* limit for inodes timer */
69 	time_t		 qi_rtbtimelimit;/* limit for rt blks timer */
70 	xfs_qwarncnt_t	 qi_bwarnlimit;	 /* limit for blks warnings */
71 	xfs_qwarncnt_t	 qi_iwarnlimit;	 /* limit for inodes warnings */
72 	xfs_qwarncnt_t	 qi_rtbwarnlimit;/* limit for rt blks warnings */
73 	struct mutex	 qi_quotaofflock;/* to serialize quotaoff */
74 	xfs_filblks_t	 qi_dqchunklen;	 /* # BBs in a chunk of dqs */
75 	uint		 qi_dqperchunk;	 /* # ondisk dqs in above chunk */
76 	struct xfs_def_quota	qi_usr_default;
77 	struct xfs_def_quota	qi_grp_default;
78 	struct xfs_def_quota	qi_prj_default;
79 	struct shrinker  qi_shrinker;
80 } xfs_quotainfo_t;
81 
82 static inline struct radix_tree_root *
83 xfs_dquot_tree(
84 	struct xfs_quotainfo	*qi,
85 	int			type)
86 {
87 	switch (type) {
88 	case XFS_DQ_USER:
89 		return &qi->qi_uquota_tree;
90 	case XFS_DQ_GROUP:
91 		return &qi->qi_gquota_tree;
92 	case XFS_DQ_PROJ:
93 		return &qi->qi_pquota_tree;
94 	default:
95 		ASSERT(0);
96 	}
97 	return NULL;
98 }
99 
100 static inline struct xfs_inode *
101 xfs_quota_inode(xfs_mount_t *mp, uint dq_flags)
102 {
103 	switch (dq_flags & XFS_DQ_ALLTYPES) {
104 	case XFS_DQ_USER:
105 		return mp->m_quotainfo->qi_uquotaip;
106 	case XFS_DQ_GROUP:
107 		return mp->m_quotainfo->qi_gquotaip;
108 	case XFS_DQ_PROJ:
109 		return mp->m_quotainfo->qi_pquotaip;
110 	default:
111 		ASSERT(0);
112 	}
113 	return NULL;
114 }
115 
116 extern void	xfs_trans_mod_dquot(struct xfs_trans *tp, struct xfs_dquot *dqp,
117 				    uint field, int64_t delta);
118 extern void	xfs_trans_dqjoin(struct xfs_trans *, struct xfs_dquot *);
119 extern void	xfs_trans_log_dquot(struct xfs_trans *, struct xfs_dquot *);
120 
121 /*
122  * We keep the usr, grp, and prj dquots separately so that locking will be
123  * easier to do at commit time. All transactions that we know of at this point
124  * affect no more than two dquots of one type. Hence, the TRANS_MAXDQS value.
125  */
126 enum {
127 	XFS_QM_TRANS_USR = 0,
128 	XFS_QM_TRANS_GRP,
129 	XFS_QM_TRANS_PRJ,
130 	XFS_QM_TRANS_DQTYPES
131 };
132 #define XFS_QM_TRANS_MAXDQS		2
133 struct xfs_dquot_acct {
134 	struct xfs_dqtrx	dqs[XFS_QM_TRANS_DQTYPES][XFS_QM_TRANS_MAXDQS];
135 };
136 
137 /*
138  * Users are allowed to have a usage exceeding their softlimit for
139  * a period this long.
140  */
141 #define XFS_QM_BTIMELIMIT	(7 * 24*60*60)          /* 1 week */
142 #define XFS_QM_RTBTIMELIMIT	(7 * 24*60*60)          /* 1 week */
143 #define XFS_QM_ITIMELIMIT	(7 * 24*60*60)          /* 1 week */
144 
145 #define XFS_QM_BWARNLIMIT	5
146 #define XFS_QM_IWARNLIMIT	5
147 #define XFS_QM_RTBWARNLIMIT	5
148 
149 extern void		xfs_qm_destroy_quotainfo(struct xfs_mount *);
150 
151 /* dquot stuff */
152 extern void		xfs_qm_dqpurge_all(struct xfs_mount *, uint);
153 extern void		xfs_qm_dqrele_all_inodes(struct xfs_mount *, uint);
154 
155 /* quota ops */
156 extern int		xfs_qm_scall_trunc_qfiles(struct xfs_mount *, uint);
157 extern int		xfs_qm_scall_getquota(struct xfs_mount *, xfs_dqid_t,
158 					uint, struct qc_dqblk *);
159 extern int		xfs_qm_scall_getquota_next(struct xfs_mount *,
160 					xfs_dqid_t *, uint, struct qc_dqblk *);
161 extern int		xfs_qm_scall_setqlim(struct xfs_mount *, xfs_dqid_t, uint,
162 					struct qc_dqblk *);
163 extern int		xfs_qm_scall_quotaon(struct xfs_mount *, uint);
164 extern int		xfs_qm_scall_quotaoff(struct xfs_mount *, uint);
165 
166 static inline struct xfs_def_quota *
167 xfs_get_defquota(struct xfs_dquot *dqp, struct xfs_quotainfo *qi)
168 {
169 	struct xfs_def_quota *defq;
170 
171 	if (XFS_QM_ISUDQ(dqp))
172 		defq = &qi->qi_usr_default;
173 	else if (XFS_QM_ISGDQ(dqp))
174 		defq = &qi->qi_grp_default;
175 	else {
176 		ASSERT(XFS_QM_ISPDQ(dqp));
177 		defq = &qi->qi_prj_default;
178 	}
179 	return defq;
180 }
181 
182 #endif /* __XFS_QM_H__ */
183