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_QUOTA_H__
7*4882a593Smuzhiyun #define __XFS_QUOTA_H__
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun #include "xfs_quota_defs.h"
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun /*
12*4882a593Smuzhiyun * Kernel only quota definitions and functions
13*4882a593Smuzhiyun */
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun struct xfs_trans;
16*4882a593Smuzhiyun struct xfs_buf;
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun /*
19*4882a593Smuzhiyun * This check is done typically without holding the inode lock;
20*4882a593Smuzhiyun * that may seem racy, but it is harmless in the context that it is used.
21*4882a593Smuzhiyun * The inode cannot go inactive as long a reference is kept, and
22*4882a593Smuzhiyun * therefore if dquot(s) were attached, they'll stay consistent.
23*4882a593Smuzhiyun * If, for example, the ownership of the inode changes while
24*4882a593Smuzhiyun * we didn't have the inode locked, the appropriate dquot(s) will be
25*4882a593Smuzhiyun * attached atomically.
26*4882a593Smuzhiyun */
27*4882a593Smuzhiyun #define XFS_NOT_DQATTACHED(mp, ip) \
28*4882a593Smuzhiyun ((XFS_IS_UQUOTA_ON(mp) && (ip)->i_udquot == NULL) || \
29*4882a593Smuzhiyun (XFS_IS_GQUOTA_ON(mp) && (ip)->i_gdquot == NULL) || \
30*4882a593Smuzhiyun (XFS_IS_PQUOTA_ON(mp) && (ip)->i_pdquot == NULL))
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun #define XFS_QM_NEED_QUOTACHECK(mp) \
33*4882a593Smuzhiyun ((XFS_IS_UQUOTA_ON(mp) && \
34*4882a593Smuzhiyun (mp->m_sb.sb_qflags & XFS_UQUOTA_CHKD) == 0) || \
35*4882a593Smuzhiyun (XFS_IS_GQUOTA_ON(mp) && \
36*4882a593Smuzhiyun (mp->m_sb.sb_qflags & XFS_GQUOTA_CHKD) == 0) || \
37*4882a593Smuzhiyun (XFS_IS_PQUOTA_ON(mp) && \
38*4882a593Smuzhiyun (mp->m_sb.sb_qflags & XFS_PQUOTA_CHKD) == 0))
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun static inline uint
xfs_quota_chkd_flag(xfs_dqtype_t type)41*4882a593Smuzhiyun xfs_quota_chkd_flag(
42*4882a593Smuzhiyun xfs_dqtype_t type)
43*4882a593Smuzhiyun {
44*4882a593Smuzhiyun switch (type) {
45*4882a593Smuzhiyun case XFS_DQTYPE_USER:
46*4882a593Smuzhiyun return XFS_UQUOTA_CHKD;
47*4882a593Smuzhiyun case XFS_DQTYPE_GROUP:
48*4882a593Smuzhiyun return XFS_GQUOTA_CHKD;
49*4882a593Smuzhiyun case XFS_DQTYPE_PROJ:
50*4882a593Smuzhiyun return XFS_PQUOTA_CHKD;
51*4882a593Smuzhiyun default:
52*4882a593Smuzhiyun return 0;
53*4882a593Smuzhiyun }
54*4882a593Smuzhiyun }
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun /*
57*4882a593Smuzhiyun * The structure kept inside the xfs_trans_t keep track of dquot changes
58*4882a593Smuzhiyun * within a transaction and apply them later.
59*4882a593Smuzhiyun */
60*4882a593Smuzhiyun struct xfs_dqtrx {
61*4882a593Smuzhiyun struct xfs_dquot *qt_dquot; /* the dquot this refers to */
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun uint64_t qt_blk_res; /* blks reserved on a dquot */
64*4882a593Smuzhiyun int64_t qt_bcount_delta; /* dquot blk count changes */
65*4882a593Smuzhiyun int64_t qt_delbcnt_delta; /* delayed dquot blk count changes */
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun uint64_t qt_rtblk_res; /* # blks reserved on a dquot */
68*4882a593Smuzhiyun uint64_t qt_rtblk_res_used;/* # blks used from reservation */
69*4882a593Smuzhiyun int64_t qt_rtbcount_delta;/* dquot realtime blk changes */
70*4882a593Smuzhiyun int64_t qt_delrtb_delta; /* delayed RT blk count changes */
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun uint64_t qt_ino_res; /* inode reserved on a dquot */
73*4882a593Smuzhiyun uint64_t qt_ino_res_used; /* inodes used from the reservation */
74*4882a593Smuzhiyun int64_t qt_icount_delta; /* dquot inode count changes */
75*4882a593Smuzhiyun };
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun #ifdef CONFIG_XFS_QUOTA
78*4882a593Smuzhiyun extern void xfs_trans_dup_dqinfo(struct xfs_trans *, struct xfs_trans *);
79*4882a593Smuzhiyun extern void xfs_trans_free_dqinfo(struct xfs_trans *);
80*4882a593Smuzhiyun extern void xfs_trans_mod_dquot_byino(struct xfs_trans *, struct xfs_inode *,
81*4882a593Smuzhiyun uint, int64_t);
82*4882a593Smuzhiyun extern void xfs_trans_apply_dquot_deltas(struct xfs_trans *);
83*4882a593Smuzhiyun extern void xfs_trans_unreserve_and_mod_dquots(struct xfs_trans *);
84*4882a593Smuzhiyun extern int xfs_trans_reserve_quota_nblks(struct xfs_trans *,
85*4882a593Smuzhiyun struct xfs_inode *, int64_t, long, uint);
86*4882a593Smuzhiyun extern int xfs_trans_reserve_quota_bydquots(struct xfs_trans *,
87*4882a593Smuzhiyun struct xfs_mount *, struct xfs_dquot *,
88*4882a593Smuzhiyun struct xfs_dquot *, struct xfs_dquot *, int64_t, long, uint);
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun extern int xfs_qm_vop_dqalloc(struct xfs_inode *, kuid_t, kgid_t,
91*4882a593Smuzhiyun prid_t, uint, struct xfs_dquot **, struct xfs_dquot **,
92*4882a593Smuzhiyun struct xfs_dquot **);
93*4882a593Smuzhiyun extern void xfs_qm_vop_create_dqattach(struct xfs_trans *, struct xfs_inode *,
94*4882a593Smuzhiyun struct xfs_dquot *, struct xfs_dquot *, struct xfs_dquot *);
95*4882a593Smuzhiyun extern int xfs_qm_vop_rename_dqattach(struct xfs_inode **);
96*4882a593Smuzhiyun extern struct xfs_dquot *xfs_qm_vop_chown(struct xfs_trans *,
97*4882a593Smuzhiyun struct xfs_inode *, struct xfs_dquot **, struct xfs_dquot *);
98*4882a593Smuzhiyun extern int xfs_qm_vop_chown_reserve(struct xfs_trans *, struct xfs_inode *,
99*4882a593Smuzhiyun struct xfs_dquot *, struct xfs_dquot *,
100*4882a593Smuzhiyun struct xfs_dquot *, uint);
101*4882a593Smuzhiyun extern int xfs_qm_dqattach(struct xfs_inode *);
102*4882a593Smuzhiyun extern int xfs_qm_dqattach_locked(struct xfs_inode *ip, bool doalloc);
103*4882a593Smuzhiyun extern void xfs_qm_dqdetach(struct xfs_inode *);
104*4882a593Smuzhiyun extern void xfs_qm_dqrele(struct xfs_dquot *);
105*4882a593Smuzhiyun extern void xfs_qm_statvfs(struct xfs_inode *, struct kstatfs *);
106*4882a593Smuzhiyun extern int xfs_qm_newmount(struct xfs_mount *, uint *, uint *);
107*4882a593Smuzhiyun extern void xfs_qm_mount_quotas(struct xfs_mount *);
108*4882a593Smuzhiyun extern void xfs_qm_unmount(struct xfs_mount *);
109*4882a593Smuzhiyun extern void xfs_qm_unmount_quotas(struct xfs_mount *);
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun #else
112*4882a593Smuzhiyun static inline int
xfs_qm_vop_dqalloc(struct xfs_inode * ip,kuid_t kuid,kgid_t kgid,prid_t prid,uint flags,struct xfs_dquot ** udqp,struct xfs_dquot ** gdqp,struct xfs_dquot ** pdqp)113*4882a593Smuzhiyun xfs_qm_vop_dqalloc(struct xfs_inode *ip, kuid_t kuid, kgid_t kgid,
114*4882a593Smuzhiyun prid_t prid, uint flags, struct xfs_dquot **udqp,
115*4882a593Smuzhiyun struct xfs_dquot **gdqp, struct xfs_dquot **pdqp)
116*4882a593Smuzhiyun {
117*4882a593Smuzhiyun *udqp = NULL;
118*4882a593Smuzhiyun *gdqp = NULL;
119*4882a593Smuzhiyun *pdqp = NULL;
120*4882a593Smuzhiyun return 0;
121*4882a593Smuzhiyun }
122*4882a593Smuzhiyun #define xfs_trans_dup_dqinfo(tp, tp2)
123*4882a593Smuzhiyun #define xfs_trans_free_dqinfo(tp)
124*4882a593Smuzhiyun #define xfs_trans_mod_dquot_byino(tp, ip, fields, delta)
125*4882a593Smuzhiyun #define xfs_trans_apply_dquot_deltas(tp)
126*4882a593Smuzhiyun #define xfs_trans_unreserve_and_mod_dquots(tp)
xfs_trans_reserve_quota_nblks(struct xfs_trans * tp,struct xfs_inode * ip,int64_t nblks,long ninos,uint flags)127*4882a593Smuzhiyun static inline int xfs_trans_reserve_quota_nblks(struct xfs_trans *tp,
128*4882a593Smuzhiyun struct xfs_inode *ip, int64_t nblks, long ninos, uint flags)
129*4882a593Smuzhiyun {
130*4882a593Smuzhiyun return 0;
131*4882a593Smuzhiyun }
xfs_trans_reserve_quota_bydquots(struct xfs_trans * tp,struct xfs_mount * mp,struct xfs_dquot * udqp,struct xfs_dquot * gdqp,struct xfs_dquot * pdqp,int64_t nblks,long nions,uint flags)132*4882a593Smuzhiyun static inline int xfs_trans_reserve_quota_bydquots(struct xfs_trans *tp,
133*4882a593Smuzhiyun struct xfs_mount *mp, struct xfs_dquot *udqp,
134*4882a593Smuzhiyun struct xfs_dquot *gdqp, struct xfs_dquot *pdqp,
135*4882a593Smuzhiyun int64_t nblks, long nions, uint flags)
136*4882a593Smuzhiyun {
137*4882a593Smuzhiyun return 0;
138*4882a593Smuzhiyun }
139*4882a593Smuzhiyun #define xfs_qm_vop_create_dqattach(tp, ip, u, g, p)
140*4882a593Smuzhiyun #define xfs_qm_vop_rename_dqattach(it) (0)
141*4882a593Smuzhiyun #define xfs_qm_vop_chown(tp, ip, old, new) (NULL)
142*4882a593Smuzhiyun #define xfs_qm_vop_chown_reserve(tp, ip, u, g, p, fl) (0)
143*4882a593Smuzhiyun #define xfs_qm_dqattach(ip) (0)
144*4882a593Smuzhiyun #define xfs_qm_dqattach_locked(ip, fl) (0)
145*4882a593Smuzhiyun #define xfs_qm_dqdetach(ip)
146*4882a593Smuzhiyun #define xfs_qm_dqrele(d)
147*4882a593Smuzhiyun #define xfs_qm_statvfs(ip, s)
148*4882a593Smuzhiyun #define xfs_qm_newmount(mp, a, b) (0)
149*4882a593Smuzhiyun #define xfs_qm_mount_quotas(mp)
150*4882a593Smuzhiyun #define xfs_qm_unmount(mp)
151*4882a593Smuzhiyun #define xfs_qm_unmount_quotas(mp)
152*4882a593Smuzhiyun #endif /* CONFIG_XFS_QUOTA */
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun #define xfs_trans_unreserve_quota_nblks(tp, ip, nblks, ninos, flags) \
155*4882a593Smuzhiyun xfs_trans_reserve_quota_nblks(tp, ip, -(nblks), -(ninos), flags)
156*4882a593Smuzhiyun #define xfs_trans_reserve_quota(tp, mp, ud, gd, pd, nb, ni, f) \
157*4882a593Smuzhiyun xfs_trans_reserve_quota_bydquots(tp, mp, ud, gd, pd, nb, ni, \
158*4882a593Smuzhiyun f | XFS_QMOPT_RES_REGBLKS)
159*4882a593Smuzhiyun
160*4882a593Smuzhiyun extern int xfs_mount_reset_sbqflags(struct xfs_mount *);
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun #endif /* __XFS_QUOTA_H__ */
163