1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
6 #ifndef __XFS_DQUOT_H__
7 #define __XFS_DQUOT_H__
10 * Dquots are structures that hold quota information about a user or a group,
11 * much like inodes are for files. In fact, dquots share many characteristics
12 * with inodes. However, dquots can also be a centralized resource, relative
13 * to a collection of inodes. In this respect, dquots share some characteristics
15 * XFS dquots exploit both those in its algorithms. They make every attempt
16 * to not be a bottleneck when quotas are on and have minimal impact, if any,
17 * when quotas are off.
24 XFS_QLOWSP_1_PCNT
= 0,
31 * The incore dquot structure
35 struct list_head q_lru
;
36 struct xfs_mount
*q_mount
;
40 xfs_fileoff_t q_fileoffset
;
42 struct xfs_disk_dquot q_core
;
43 struct xfs_dq_logitem q_logitem
;
44 /* total regular nblks used+reserved */
45 xfs_qcnt_t q_res_bcount
;
46 /* total inos allocd+reserved */
47 xfs_qcnt_t q_res_icount
;
48 /* total realtime blks used+reserved */
49 xfs_qcnt_t q_res_rtbcount
;
50 xfs_qcnt_t q_prealloc_lo_wmark
;
51 xfs_qcnt_t q_prealloc_hi_wmark
;
52 int64_t q_low_space
[XFS_QLOWSP_MAX
];
54 struct completion q_flush
;
56 struct wait_queue_head q_pinwait
;
60 * Lock hierarchy for q_qlock:
61 * XFS_QLOCK_NORMAL is the implicit default,
62 * XFS_QLOCK_NESTED is the dquot with the higher id in xfs_dqlock2
70 * Manage the q_flush completion queue embedded in the dquot. This completion
71 * queue synchronizes processes attempting to flush the in-core dquot back to
74 static inline void xfs_dqflock(struct xfs_dquot
*dqp
)
76 wait_for_completion(&dqp
->q_flush
);
79 static inline bool xfs_dqflock_nowait(struct xfs_dquot
*dqp
)
81 return try_wait_for_completion(&dqp
->q_flush
);
84 static inline void xfs_dqfunlock(struct xfs_dquot
*dqp
)
86 complete(&dqp
->q_flush
);
89 static inline int xfs_dqlock_nowait(struct xfs_dquot
*dqp
)
91 return mutex_trylock(&dqp
->q_qlock
);
94 static inline void xfs_dqlock(struct xfs_dquot
*dqp
)
96 mutex_lock(&dqp
->q_qlock
);
99 static inline void xfs_dqunlock(struct xfs_dquot
*dqp
)
101 mutex_unlock(&dqp
->q_qlock
);
104 static inline int xfs_this_quota_on(struct xfs_mount
*mp
, int type
)
106 switch (type
& XFS_DQ_ALLTYPES
) {
108 return XFS_IS_UQUOTA_ON(mp
);
110 return XFS_IS_GQUOTA_ON(mp
);
112 return XFS_IS_PQUOTA_ON(mp
);
118 static inline struct xfs_dquot
*xfs_inode_dquot(struct xfs_inode
*ip
, int type
)
120 switch (type
& XFS_DQ_ALLTYPES
) {
133 * Check whether a dquot is under low free space conditions. We assume the quota
134 * is enabled and enforced.
136 static inline bool xfs_dquot_lowsp(struct xfs_dquot
*dqp
)
140 freesp
= be64_to_cpu(dqp
->q_core
.d_blk_hardlimit
) - dqp
->q_res_bcount
;
141 if (freesp
< dqp
->q_low_space
[XFS_QLOWSP_1_PCNT
])
147 #define XFS_DQ_IS_LOCKED(dqp) (mutex_is_locked(&((dqp)->q_qlock)))
148 #define XFS_DQ_IS_DIRTY(dqp) ((dqp)->dq_flags & XFS_DQ_DIRTY)
149 #define XFS_QM_ISUDQ(dqp) ((dqp)->dq_flags & XFS_DQ_USER)
150 #define XFS_QM_ISPDQ(dqp) ((dqp)->dq_flags & XFS_DQ_PROJ)
151 #define XFS_QM_ISGDQ(dqp) ((dqp)->dq_flags & XFS_DQ_GROUP)
153 void xfs_qm_dqdestroy(struct xfs_dquot
*dqp
);
154 int xfs_qm_dqflush(struct xfs_dquot
*dqp
, struct xfs_buf
**bpp
);
155 void xfs_qm_dqunpin_wait(struct xfs_dquot
*dqp
);
156 void xfs_qm_adjust_dqtimers(struct xfs_mount
*mp
,
157 struct xfs_disk_dquot
*d
);
158 void xfs_qm_adjust_dqlimits(struct xfs_mount
*mp
,
159 struct xfs_dquot
*d
);
160 xfs_dqid_t
xfs_qm_id_for_quotatype(struct xfs_inode
*ip
, uint type
);
161 int xfs_qm_dqget(struct xfs_mount
*mp
, xfs_dqid_t id
,
162 uint type
, bool can_alloc
,
163 struct xfs_dquot
**dqpp
);
164 int xfs_qm_dqget_inode(struct xfs_inode
*ip
, uint type
,
166 struct xfs_dquot
**dqpp
);
167 int xfs_qm_dqget_next(struct xfs_mount
*mp
, xfs_dqid_t id
,
168 uint type
, struct xfs_dquot
**dqpp
);
169 int xfs_qm_dqget_uncached(struct xfs_mount
*mp
,
170 xfs_dqid_t id
, uint type
,
171 struct xfs_dquot
**dqpp
);
172 void xfs_qm_dqput(struct xfs_dquot
*dqp
);
174 void xfs_dqlock2(struct xfs_dquot
*, struct xfs_dquot
*);
176 void xfs_dquot_set_prealloc_limits(struct xfs_dquot
*);
178 static inline struct xfs_dquot
*xfs_qm_dqhold(struct xfs_dquot
*dqp
)
186 typedef int (*xfs_qm_dqiterate_fn
)(struct xfs_dquot
*dq
, uint dqtype
,
188 int xfs_qm_dqiterate(struct xfs_mount
*mp
, uint dqtype
,
189 xfs_qm_dqiterate_fn iter_fn
, void *priv
);
191 #endif /* __XFS_DQUOT_H__ */