1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Copyright (c) 2000-2005 Silicon Graphics, Inc.
4*4882a593Smuzhiyun * All Rights Reserved.
5*4882a593Smuzhiyun */
6*4882a593Smuzhiyun #ifndef __XFS_QM_H__
7*4882a593Smuzhiyun #define __XFS_QM_H__
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun #include "xfs_dquot_item.h"
10*4882a593Smuzhiyun #include "xfs_dquot.h"
11*4882a593Smuzhiyun
12*4882a593Smuzhiyun struct xfs_inode;
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun extern struct kmem_zone *xfs_qm_dqtrxzone;
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun /*
17*4882a593Smuzhiyun * Number of bmaps that we ask from bmapi when doing a quotacheck.
18*4882a593Smuzhiyun * We make this restriction to keep the memory usage to a minimum.
19*4882a593Smuzhiyun */
20*4882a593Smuzhiyun #define XFS_DQITER_MAP_SIZE 10
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun #define XFS_IS_DQUOT_UNINITIALIZED(dqp) ( \
23*4882a593Smuzhiyun !dqp->q_blk.hardlimit && \
24*4882a593Smuzhiyun !dqp->q_blk.softlimit && \
25*4882a593Smuzhiyun !dqp->q_rtb.hardlimit && \
26*4882a593Smuzhiyun !dqp->q_rtb.softlimit && \
27*4882a593Smuzhiyun !dqp->q_ino.hardlimit && \
28*4882a593Smuzhiyun !dqp->q_ino.softlimit && \
29*4882a593Smuzhiyun !dqp->q_blk.count && \
30*4882a593Smuzhiyun !dqp->q_rtb.count && \
31*4882a593Smuzhiyun !dqp->q_ino.count)
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun struct xfs_quota_limits {
34*4882a593Smuzhiyun xfs_qcnt_t hard; /* default hard limit */
35*4882a593Smuzhiyun xfs_qcnt_t soft; /* default soft limit */
36*4882a593Smuzhiyun time64_t time; /* limit for timers */
37*4882a593Smuzhiyun xfs_qwarncnt_t warn; /* limit for warnings */
38*4882a593Smuzhiyun };
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun /* Defaults for each quota type: time limits, warn limits, usage limits */
41*4882a593Smuzhiyun struct xfs_def_quota {
42*4882a593Smuzhiyun struct xfs_quota_limits blk;
43*4882a593Smuzhiyun struct xfs_quota_limits ino;
44*4882a593Smuzhiyun struct xfs_quota_limits rtb;
45*4882a593Smuzhiyun };
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun /*
48*4882a593Smuzhiyun * Various quota information for individual filesystems.
49*4882a593Smuzhiyun * The mount structure keeps a pointer to this.
50*4882a593Smuzhiyun */
51*4882a593Smuzhiyun struct xfs_quotainfo {
52*4882a593Smuzhiyun struct radix_tree_root qi_uquota_tree;
53*4882a593Smuzhiyun struct radix_tree_root qi_gquota_tree;
54*4882a593Smuzhiyun struct radix_tree_root qi_pquota_tree;
55*4882a593Smuzhiyun struct mutex qi_tree_lock;
56*4882a593Smuzhiyun struct xfs_inode *qi_uquotaip; /* user quota inode */
57*4882a593Smuzhiyun struct xfs_inode *qi_gquotaip; /* group quota inode */
58*4882a593Smuzhiyun struct xfs_inode *qi_pquotaip; /* project quota inode */
59*4882a593Smuzhiyun struct list_lru qi_lru;
60*4882a593Smuzhiyun int qi_dquots;
61*4882a593Smuzhiyun struct mutex qi_quotaofflock;/* to serialize quotaoff */
62*4882a593Smuzhiyun xfs_filblks_t qi_dqchunklen; /* # BBs in a chunk of dqs */
63*4882a593Smuzhiyun uint qi_dqperchunk; /* # ondisk dq in above chunk */
64*4882a593Smuzhiyun struct xfs_def_quota qi_usr_default;
65*4882a593Smuzhiyun struct xfs_def_quota qi_grp_default;
66*4882a593Smuzhiyun struct xfs_def_quota qi_prj_default;
67*4882a593Smuzhiyun struct shrinker qi_shrinker;
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun /* Minimum and maximum quota expiration timestamp values. */
70*4882a593Smuzhiyun time64_t qi_expiry_min;
71*4882a593Smuzhiyun time64_t qi_expiry_max;
72*4882a593Smuzhiyun };
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun static inline struct radix_tree_root *
xfs_dquot_tree(struct xfs_quotainfo * qi,xfs_dqtype_t type)75*4882a593Smuzhiyun xfs_dquot_tree(
76*4882a593Smuzhiyun struct xfs_quotainfo *qi,
77*4882a593Smuzhiyun xfs_dqtype_t type)
78*4882a593Smuzhiyun {
79*4882a593Smuzhiyun switch (type) {
80*4882a593Smuzhiyun case XFS_DQTYPE_USER:
81*4882a593Smuzhiyun return &qi->qi_uquota_tree;
82*4882a593Smuzhiyun case XFS_DQTYPE_GROUP:
83*4882a593Smuzhiyun return &qi->qi_gquota_tree;
84*4882a593Smuzhiyun case XFS_DQTYPE_PROJ:
85*4882a593Smuzhiyun return &qi->qi_pquota_tree;
86*4882a593Smuzhiyun default:
87*4882a593Smuzhiyun ASSERT(0);
88*4882a593Smuzhiyun }
89*4882a593Smuzhiyun return NULL;
90*4882a593Smuzhiyun }
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun static inline struct xfs_inode *
xfs_quota_inode(struct xfs_mount * mp,xfs_dqtype_t type)93*4882a593Smuzhiyun xfs_quota_inode(struct xfs_mount *mp, xfs_dqtype_t type)
94*4882a593Smuzhiyun {
95*4882a593Smuzhiyun switch (type) {
96*4882a593Smuzhiyun case XFS_DQTYPE_USER:
97*4882a593Smuzhiyun return mp->m_quotainfo->qi_uquotaip;
98*4882a593Smuzhiyun case XFS_DQTYPE_GROUP:
99*4882a593Smuzhiyun return mp->m_quotainfo->qi_gquotaip;
100*4882a593Smuzhiyun case XFS_DQTYPE_PROJ:
101*4882a593Smuzhiyun return mp->m_quotainfo->qi_pquotaip;
102*4882a593Smuzhiyun default:
103*4882a593Smuzhiyun ASSERT(0);
104*4882a593Smuzhiyun }
105*4882a593Smuzhiyun return NULL;
106*4882a593Smuzhiyun }
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun extern void xfs_trans_mod_dquot(struct xfs_trans *tp, struct xfs_dquot *dqp,
109*4882a593Smuzhiyun uint field, int64_t delta);
110*4882a593Smuzhiyun extern void xfs_trans_dqjoin(struct xfs_trans *, struct xfs_dquot *);
111*4882a593Smuzhiyun extern void xfs_trans_log_dquot(struct xfs_trans *, struct xfs_dquot *);
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun /*
114*4882a593Smuzhiyun * We keep the usr, grp, and prj dquots separately so that locking will be
115*4882a593Smuzhiyun * easier to do at commit time. All transactions that we know of at this point
116*4882a593Smuzhiyun * affect no more than two dquots of one type. Hence, the TRANS_MAXDQS value.
117*4882a593Smuzhiyun */
118*4882a593Smuzhiyun enum {
119*4882a593Smuzhiyun XFS_QM_TRANS_USR = 0,
120*4882a593Smuzhiyun XFS_QM_TRANS_GRP,
121*4882a593Smuzhiyun XFS_QM_TRANS_PRJ,
122*4882a593Smuzhiyun XFS_QM_TRANS_DQTYPES
123*4882a593Smuzhiyun };
124*4882a593Smuzhiyun #define XFS_QM_TRANS_MAXDQS 2
125*4882a593Smuzhiyun struct xfs_dquot_acct {
126*4882a593Smuzhiyun struct xfs_dqtrx dqs[XFS_QM_TRANS_DQTYPES][XFS_QM_TRANS_MAXDQS];
127*4882a593Smuzhiyun };
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun /*
130*4882a593Smuzhiyun * Users are allowed to have a usage exceeding their softlimit for
131*4882a593Smuzhiyun * a period this long.
132*4882a593Smuzhiyun */
133*4882a593Smuzhiyun #define XFS_QM_BTIMELIMIT (7 * 24*60*60) /* 1 week */
134*4882a593Smuzhiyun #define XFS_QM_RTBTIMELIMIT (7 * 24*60*60) /* 1 week */
135*4882a593Smuzhiyun #define XFS_QM_ITIMELIMIT (7 * 24*60*60) /* 1 week */
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun #define XFS_QM_BWARNLIMIT 5
138*4882a593Smuzhiyun #define XFS_QM_IWARNLIMIT 5
139*4882a593Smuzhiyun #define XFS_QM_RTBWARNLIMIT 5
140*4882a593Smuzhiyun
141*4882a593Smuzhiyun extern void xfs_qm_destroy_quotainfo(struct xfs_mount *);
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun /* dquot stuff */
144*4882a593Smuzhiyun extern void xfs_qm_dqpurge_all(struct xfs_mount *, uint);
145*4882a593Smuzhiyun extern void xfs_qm_dqrele_all_inodes(struct xfs_mount *, uint);
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun /* quota ops */
148*4882a593Smuzhiyun extern int xfs_qm_scall_trunc_qfiles(struct xfs_mount *, uint);
149*4882a593Smuzhiyun extern int xfs_qm_scall_getquota(struct xfs_mount *mp,
150*4882a593Smuzhiyun xfs_dqid_t id,
151*4882a593Smuzhiyun xfs_dqtype_t type,
152*4882a593Smuzhiyun struct qc_dqblk *dst);
153*4882a593Smuzhiyun extern int xfs_qm_scall_getquota_next(struct xfs_mount *mp,
154*4882a593Smuzhiyun xfs_dqid_t *id,
155*4882a593Smuzhiyun xfs_dqtype_t type,
156*4882a593Smuzhiyun struct qc_dqblk *dst);
157*4882a593Smuzhiyun extern int xfs_qm_scall_setqlim(struct xfs_mount *mp,
158*4882a593Smuzhiyun xfs_dqid_t id,
159*4882a593Smuzhiyun xfs_dqtype_t type,
160*4882a593Smuzhiyun struct qc_dqblk *newlim);
161*4882a593Smuzhiyun extern int xfs_qm_scall_quotaon(struct xfs_mount *, uint);
162*4882a593Smuzhiyun extern int xfs_qm_scall_quotaoff(struct xfs_mount *, uint);
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun static inline struct xfs_def_quota *
xfs_get_defquota(struct xfs_quotainfo * qi,xfs_dqtype_t type)165*4882a593Smuzhiyun xfs_get_defquota(struct xfs_quotainfo *qi, xfs_dqtype_t type)
166*4882a593Smuzhiyun {
167*4882a593Smuzhiyun switch (type) {
168*4882a593Smuzhiyun case XFS_DQTYPE_USER:
169*4882a593Smuzhiyun return &qi->qi_usr_default;
170*4882a593Smuzhiyun case XFS_DQTYPE_GROUP:
171*4882a593Smuzhiyun return &qi->qi_grp_default;
172*4882a593Smuzhiyun case XFS_DQTYPE_PROJ:
173*4882a593Smuzhiyun return &qi->qi_prj_default;
174*4882a593Smuzhiyun default:
175*4882a593Smuzhiyun ASSERT(0);
176*4882a593Smuzhiyun return NULL;
177*4882a593Smuzhiyun }
178*4882a593Smuzhiyun }
179*4882a593Smuzhiyun
180*4882a593Smuzhiyun #endif /* __XFS_QM_H__ */
181