xfs: remove the xfs_quotainfo_t typedef
[linux-2.6-block.git] / fs / xfs / xfs_dquot.h
CommitLineData
0b61f8a4 1// SPDX-License-Identifier: GPL-2.0
1da177e4 2/*
4ce3121f
NS
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
1da177e4
LT
5 */
6#ifndef __XFS_DQUOT_H__
7#define __XFS_DQUOT_H__
8
9/*
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
14 * of the superblock.
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.
18 */
19
1da177e4
LT
20struct xfs_mount;
21struct xfs_trans;
22
b1366451
BF
23enum {
24 XFS_QLOWSP_1_PCNT = 0,
25 XFS_QLOWSP_3_PCNT,
26 XFS_QLOWSP_5_PCNT,
27 XFS_QLOWSP_MAX
28};
29
1da177e4
LT
30/*
31 * The incore dquot structure
32 */
aefe69a4
PR
33struct xfs_dquot {
34 uint dq_flags;
35 struct list_head q_lru;
36 struct xfs_mount *q_mount;
37 uint q_nrefs;
38 xfs_daddr_t q_blkno;
39 int q_bufoffset;
40 xfs_fileoff_t q_fileoffset;
41
42 struct xfs_disk_dquot q_core;
43 xfs_dq_logitem_t 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];
53 struct mutex q_qlock;
54 struct completion q_flush;
55 atomic_t q_pincount;
56 struct wait_queue_head q_pinwait;
57};
1da177e4 58
5bb87a33 59/*
af901ca1 60 * Lock hierarchy for q_qlock:
5bb87a33 61 * XFS_QLOCK_NORMAL is the implicit default,
aefe69a4 62 * XFS_QLOCK_NESTED is the dquot with the higher id in xfs_dqlock2
5bb87a33
CH
63 */
64enum {
65 XFS_QLOCK_NORMAL = 0,
66 XFS_QLOCK_NESTED,
67};
68
1da177e4 69/*
aefe69a4 70 * Manage the q_flush completion queue embedded in the dquot. This completion
e1f49cf2
DC
71 * queue synchronizes processes attempting to flush the in-core dquot back to
72 * disk.
1da177e4 73 */
aefe69a4 74static inline void xfs_dqflock(struct xfs_dquot *dqp)
e1f49cf2
DC
75{
76 wait_for_completion(&dqp->q_flush);
77}
78
aefe69a4 79static inline bool xfs_dqflock_nowait(struct xfs_dquot *dqp)
e1f49cf2
DC
80{
81 return try_wait_for_completion(&dqp->q_flush);
82}
83
aefe69a4 84static inline void xfs_dqfunlock(struct xfs_dquot *dqp)
e1f49cf2
DC
85{
86 complete(&dqp->q_flush);
87}
1da177e4 88
800b484e
CH
89static inline int xfs_dqlock_nowait(struct xfs_dquot *dqp)
90{
91 return mutex_trylock(&dqp->q_qlock);
92}
93
94static inline void xfs_dqlock(struct xfs_dquot *dqp)
95{
96 mutex_lock(&dqp->q_qlock);
97}
98
5b03ff1b 99static inline void xfs_dqunlock(struct xfs_dquot *dqp)
800b484e
CH
100{
101 mutex_unlock(&dqp->q_qlock);
102}
103
6967b964
CS
104static inline int xfs_this_quota_on(struct xfs_mount *mp, int type)
105{
106 switch (type & XFS_DQ_ALLTYPES) {
107 case XFS_DQ_USER:
108 return XFS_IS_UQUOTA_ON(mp);
109 case XFS_DQ_GROUP:
92f8ff73 110 return XFS_IS_GQUOTA_ON(mp);
6967b964 111 case XFS_DQ_PROJ:
92f8ff73 112 return XFS_IS_PQUOTA_ON(mp);
6967b964
CS
113 default:
114 return 0;
115 }
116}
117
aefe69a4 118static inline struct xfs_dquot *xfs_inode_dquot(struct xfs_inode *ip, int type)
36731410
CS
119{
120 switch (type & XFS_DQ_ALLTYPES) {
121 case XFS_DQ_USER:
122 return ip->i_udquot;
123 case XFS_DQ_GROUP:
36731410 124 return ip->i_gdquot;
92f8ff73
CS
125 case XFS_DQ_PROJ:
126 return ip->i_pdquot;
36731410
CS
127 default:
128 return NULL;
129 }
130}
131
dc06f398
BF
132/*
133 * Check whether a dquot is under low free space conditions. We assume the quota
134 * is enabled and enforced.
135 */
136static inline bool xfs_dquot_lowsp(struct xfs_dquot *dqp)
137{
138 int64_t freesp;
139
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])
142 return true;
143
144 return false;
145}
146
7201813b 147#define XFS_DQ_IS_LOCKED(dqp) (mutex_is_locked(&((dqp)->q_qlock)))
1da177e4
LT
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)
c8ad20ff
NS
150#define XFS_QM_ISPDQ(dqp) ((dqp)->dq_flags & XFS_DQ_PROJ)
151#define XFS_QM_ISGDQ(dqp) ((dqp)->dq_flags & XFS_DQ_GROUP)
1da177e4 152
aefe69a4
PR
153void xfs_qm_dqdestroy(struct xfs_dquot *dqp);
154int xfs_qm_dqflush(struct xfs_dquot *dqp, struct xfs_buf **bpp);
155void xfs_qm_dqunpin_wait(struct xfs_dquot *dqp);
156void xfs_qm_adjust_dqtimers(struct xfs_mount *mp,
157 struct xfs_disk_dquot *d);
158void xfs_qm_adjust_dqlimits(struct xfs_mount *mp,
159 struct xfs_dquot *d);
160xfs_dqid_t xfs_qm_id_for_quotatype(struct xfs_inode *ip, uint type);
161int xfs_qm_dqget(struct xfs_mount *mp, xfs_dqid_t id,
30ab2dcf 162 uint type, bool can_alloc,
4882c19d 163 struct xfs_dquot **dqpp);
aefe69a4
PR
164int xfs_qm_dqget_inode(struct xfs_inode *ip, uint type,
165 bool can_alloc,
166 struct xfs_dquot **dqpp);
167int xfs_qm_dqget_next(struct xfs_mount *mp, xfs_dqid_t id,
2e330e76 168 uint type, struct xfs_dquot **dqpp);
aefe69a4
PR
169int xfs_qm_dqget_uncached(struct xfs_mount *mp,
170 xfs_dqid_t id, uint type,
171 struct xfs_dquot **dqpp);
172void xfs_qm_dqput(struct xfs_dquot *dqp);
800b484e 173
aefe69a4 174void xfs_dqlock2(struct xfs_dquot *, struct xfs_dquot *);
1da177e4 175
aefe69a4 176void xfs_dquot_set_prealloc_limits(struct xfs_dquot *);
b1366451 177
78e55892
CH
178static inline struct xfs_dquot *xfs_qm_dqhold(struct xfs_dquot *dqp)
179{
180 xfs_dqlock(dqp);
181 dqp->q_nrefs++;
182 xfs_dqunlock(dqp);
183 return dqp;
184}
185
554ba965
DW
186typedef int (*xfs_qm_dqiterate_fn)(struct xfs_dquot *dq, uint dqtype,
187 void *priv);
188int xfs_qm_dqiterate(struct xfs_mount *mp, uint dqtype,
189 xfs_qm_dqiterate_fn iter_fn, void *priv);
190
1da177e4 191#endif /* __XFS_DQUOT_H__ */