]>
Commit | Line | Data |
---|---|---|
2bd0ea18 NS |
1 | /* |
2 | * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify it | |
5 | * under the terms of version 2 of the GNU General Public License as | |
6 | * published by the Free Software Foundation. | |
7 | * | |
8 | * This program is distributed in the hope that it would be useful, but | |
9 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
11 | * | |
12 | * Further, this software is distributed without any warranty that it is | |
13 | * free of the rightful claim of any third person regarding infringement | |
14 | * or the like. Any license provided herein, whether implied or | |
15 | * otherwise, applies only to this software file. Patent licenses, if | |
16 | * any, provided herein do not apply to combinations of this program with | |
17 | * other software, or any other product whatsoever. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License along | |
20 | * with this program; if not, write the Free Software Foundation, Inc., 59 | |
21 | * Temple Place - Suite 330, Boston MA 02111-1307, USA. | |
22 | * | |
23 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, | |
24 | * Mountain View, CA 94043, or: | |
25 | * | |
26 | * http://www.sgi.com | |
27 | * | |
28 | * For further information regarding this notice, see: | |
29 | * | |
30 | * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ | |
31 | */ | |
32 | #ifndef __XFS_QUOTA_H__ | |
33 | #define __XFS_QUOTA_H__ | |
34 | ||
35 | /* | |
b36eef04 NS |
36 | * uid_t and gid_t are hard-coded to 32 bits in the inode. |
37 | * Hence, an 'id' in a dquot is 32 bits.. | |
2bd0ea18 NS |
38 | */ |
39 | typedef __int32_t xfs_dqid_t; | |
b36eef04 | 40 | |
2bd0ea18 NS |
41 | /* |
42 | * Eventhough users may not have quota limits occupying all 64-bits, | |
43 | * they may need 64-bit accounting. Hence, 64-bit quota-counters, | |
b36eef04 | 44 | * and quota-limits. This is a waste in the common case, but hey ... |
2bd0ea18 NS |
45 | */ |
46 | typedef __uint64_t xfs_qcnt_t; | |
47 | typedef __uint16_t xfs_qwarncnt_t; | |
48 | ||
49 | /* | |
50 | * Disk quotas status in m_qflags, and also sb_qflags. 16 bits. | |
51 | */ | |
52 | #define XFS_UQUOTA_ACCT 0x0001 /* user quota accounting ON */ | |
53 | #define XFS_UQUOTA_ENFD 0x0002 /* user quota limits enforced */ | |
54 | #define XFS_UQUOTA_CHKD 0x0004 /* quotacheck run on usr quotas */ | |
b36eef04 NS |
55 | #define XFS_PQUOTA_ACCT 0x0008 /* (IRIX) project quota accounting ON */ |
56 | #define XFS_GQUOTA_ENFD 0x0010 /* group quota limits enforced */ | |
57 | #define XFS_GQUOTA_CHKD 0x0020 /* quotacheck run on grp quotas */ | |
58 | #define XFS_GQUOTA_ACCT 0x0040 /* group quota accounting ON */ | |
2bd0ea18 NS |
59 | |
60 | /* | |
61 | * Incore only flags for quotaoff - these bits get cleared when quota(s) | |
62 | * are in the process of getting turned off. These flags are in m_qflags but | |
63 | * never in sb_qflags. | |
64 | */ | |
b36eef04 NS |
65 | #define XFS_UQUOTA_ACTIVE 0x0080 /* uquotas are being turned off */ |
66 | #define XFS_GQUOTA_ACTIVE 0x0100 /* gquotas are being turned off */ | |
2bd0ea18 NS |
67 | |
68 | /* | |
69 | * Typically, we turn quotas off if we weren't explicitly asked to | |
70 | * mount quotas. This is the mount option not to do that. | |
71 | * This option is handy in the miniroot, when trying to mount /root. | |
72 | * We can't really know what's in /etc/fstab until /root is already mounted! | |
73 | * This stops quotas getting turned off in the root filesystem everytime | |
74 | * the system boots up a miniroot. | |
75 | */ | |
b36eef04 | 76 | #define XFS_QUOTA_MAYBE 0x0200 /* Turn quotas on if SB has quotas on */ |
2bd0ea18 NS |
77 | |
78 | /* | |
79 | * Checking XFS_IS_*QUOTA_ON() while holding any inode lock guarantees | |
80 | * quota will be not be switched off as long as that inode lock is held. | |
81 | */ | |
82 | #define XFS_IS_QUOTA_ON(mp) ((mp)->m_qflags & (XFS_UQUOTA_ACTIVE | \ | |
b36eef04 | 83 | XFS_GQUOTA_ACTIVE)) |
2bd0ea18 | 84 | #define XFS_IS_UQUOTA_ON(mp) ((mp)->m_qflags & XFS_UQUOTA_ACTIVE) |
b36eef04 | 85 | #define XFS_IS_GQUOTA_ON(mp) ((mp)->m_qflags & XFS_GQUOTA_ACTIVE) |
2bd0ea18 NS |
86 | |
87 | /* | |
88 | * Flags to tell various functions what to do. Not all of these are meaningful | |
89 | * to a single function. None of these XFS_QMOPT_* flags are meant to have | |
90 | * persistent values (ie. their values can and will change between versions) | |
91 | */ | |
92 | #define XFS_QMOPT_DQLOCK 0x0000001 /* dqlock */ | |
93 | #define XFS_QMOPT_DQALLOC 0x0000002 /* alloc dquot ondisk if needed */ | |
94 | #define XFS_QMOPT_UQUOTA 0x0000004 /* user dquot requested */ | |
b36eef04 | 95 | #define XFS_QMOPT_GQUOTA 0x0000008 /* group dquot requested */ |
2bd0ea18 NS |
96 | #define XFS_QMOPT_FORCE_RES 0x0000010 /* ignore quota limits */ |
97 | #define XFS_QMOPT_DQSUSER 0x0000020 /* don't cache super users dquot */ | |
98 | #define XFS_QMOPT_SBVERSION 0x0000040 /* change superblock version num */ | |
99 | #define XFS_QMOPT_QUOTAOFF 0x0000080 /* quotas are being turned off */ | |
100 | #define XFS_QMOPT_UMOUNTING 0x0000100 /* filesys is being unmounted */ | |
101 | #define XFS_QMOPT_DOLOG 0x0000200 /* log buf changes (in quotacheck) */ | |
102 | #define XFS_QMOPT_DOWARN 0x0000400 /* increase warning cnt if necessary */ | |
103 | #define XFS_QMOPT_ILOCKED 0x0000800 /* inode is already locked (excl) */ | |
104 | #define XFS_QMOPT_DQREPAIR 0x0001000 /* repair dquot, if damaged. */ | |
105 | ||
106 | /* | |
107 | * flags to xfs_trans_mod_dquot to indicate which field needs to be | |
108 | * modified. | |
109 | */ | |
110 | #define XFS_QMOPT_RES_REGBLKS 0x0010000 | |
111 | #define XFS_QMOPT_RES_RTBLKS 0x0020000 | |
112 | #define XFS_QMOPT_BCOUNT 0x0040000 | |
113 | #define XFS_QMOPT_ICOUNT 0x0080000 | |
114 | #define XFS_QMOPT_RTBCOUNT 0x0100000 | |
115 | #define XFS_QMOPT_DELBCOUNT 0x0200000 | |
116 | #define XFS_QMOPT_DELRTBCOUNT 0x0400000 | |
117 | #define XFS_QMOPT_RES_INOS 0x0800000 | |
118 | ||
119 | /* | |
120 | * flags for dqflush and dqflush_all. | |
121 | */ | |
122 | #define XFS_QMOPT_SYNC 0x1000000 | |
123 | #define XFS_QMOPT_ASYNC 0x2000000 | |
124 | #define XFS_QMOPT_DELWRI 0x4000000 | |
125 | ||
7e039a24 NS |
126 | /* |
127 | * flags for dqalloc. | |
128 | */ | |
129 | #define XFS_QMOPT_INHERIT 0x8000000 | |
130 | ||
2bd0ea18 NS |
131 | /* |
132 | * flags to xfs_trans_mod_dquot. | |
133 | */ | |
134 | #define XFS_TRANS_DQ_RES_BLKS XFS_QMOPT_RES_REGBLKS | |
135 | #define XFS_TRANS_DQ_RES_RTBLKS XFS_QMOPT_RES_RTBLKS | |
136 | #define XFS_TRANS_DQ_RES_INOS XFS_QMOPT_RES_INOS | |
137 | #define XFS_TRANS_DQ_BCOUNT XFS_QMOPT_BCOUNT | |
138 | #define XFS_TRANS_DQ_DELBCOUNT XFS_QMOPT_DELBCOUNT | |
139 | #define XFS_TRANS_DQ_ICOUNT XFS_QMOPT_ICOUNT | |
140 | #define XFS_TRANS_DQ_RTBCOUNT XFS_QMOPT_RTBCOUNT | |
141 | #define XFS_TRANS_DQ_DELRTBCOUNT XFS_QMOPT_DELRTBCOUNT | |
142 | ||
143 | ||
b36eef04 | 144 | #define XFS_QMOPT_QUOTALL (XFS_QMOPT_UQUOTA|XFS_QMOPT_GQUOTA) |
2bd0ea18 NS |
145 | #define XFS_QMOPT_RESBLK_MASK (XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_RES_RTBLKS) |
146 | ||
147 | /* | |
148 | * This check is done typically without holding the inode lock; | |
149 | * that may seem racey, but it is harmless in the context that it is used. | |
150 | * The inode cannot go inactive as long a reference is kept, and | |
151 | * therefore if dquot(s) were attached, they'll stay consistent. | |
152 | * If, for example, the ownership of the inode changes while | |
153 | * we didnt have the inode locked, the appropriate dquot(s) will be | |
154 | * attached atomically. | |
155 | */ | |
156 | #define XFS_NOT_DQATTACHED(mp, ip) ((XFS_IS_UQUOTA_ON(mp) &&\ | |
157 | (ip)->i_udquot == NULL) || \ | |
b36eef04 NS |
158 | (XFS_IS_GQUOTA_ON(mp) && \ |
159 | (ip)->i_gdquot == NULL)) | |
2bd0ea18 NS |
160 | |
161 | #define XFS_QM_NEED_QUOTACHECK(mp) ((XFS_IS_UQUOTA_ON(mp) && \ | |
162 | (mp->m_sb.sb_qflags & \ | |
163 | XFS_UQUOTA_CHKD) == 0) || \ | |
b36eef04 | 164 | (XFS_IS_GQUOTA_ON(mp) && \ |
2bd0ea18 | 165 | (mp->m_sb.sb_qflags & \ |
b36eef04 | 166 | XFS_GQUOTA_CHKD) == 0)) |
2bd0ea18 NS |
167 | |
168 | #define XFS_MOUNT_QUOTA_ALL (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD|\ | |
b36eef04 NS |
169 | XFS_UQUOTA_CHKD|XFS_GQUOTA_ACCT|\ |
170 | XFS_GQUOTA_ENFD|XFS_GQUOTA_CHKD) | |
2bd0ea18 | 171 | #define XFS_MOUNT_QUOTA_MASK (XFS_MOUNT_QUOTA_ALL | XFS_UQUOTA_ACTIVE | \ |
b36eef04 | 172 | XFS_GQUOTA_ACTIVE) |
2bd0ea18 NS |
173 | |
174 | #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME) | |
175 | ||
176 | ||
177 | #ifdef __KERNEL__ | |
178 | /* | |
179 | * External Interface to the XFS disk quota subsystem. | |
180 | */ | |
181 | struct bhv_desc; | |
182 | struct vfs; | |
183 | struct xfs_disk_dquot; | |
184 | struct xfs_dqhash; | |
185 | struct xfs_dquot; | |
186 | struct xfs_inode; | |
187 | struct xfs_mount; | |
188 | struct xfs_trans; | |
189 | ||
190 | /* | |
191 | * Quota Manager Interface. | |
192 | */ | |
193 | extern struct xfs_qm *xfs_qm_init(void); | |
194 | extern void xfs_qm_destroy(struct xfs_qm *); | |
195 | extern int xfs_qm_dqflush_all(struct xfs_mount *, int); | |
196 | extern int xfs_qm_dqattach(struct xfs_inode *, uint); | |
197 | extern int xfs_qm_dqpurge_all(struct xfs_mount *, uint); | |
198 | extern void xfs_qm_mount_quotainit(struct xfs_mount *, uint); | |
199 | extern void xfs_qm_unmount_quotadestroy(struct xfs_mount *); | |
200 | extern int xfs_qm_mount_quotas(struct xfs_mount *); | |
201 | extern int xfs_qm_unmount_quotas(struct xfs_mount *); | |
202 | extern void xfs_qm_dqdettach_inode(struct xfs_inode *); | |
203 | extern int xfs_qm_sync(struct xfs_mount *, short); | |
204 | ||
205 | ||
206 | /* | |
207 | * system call interface | |
208 | */ | |
209 | extern int xfs_quotactl(xfs_mount_t *, struct vfs *, int, int, | |
210 | int, xfs_caddr_t); | |
211 | ||
212 | /* | |
213 | * dquot interface. | |
214 | */ | |
215 | extern void xfs_dqlock(struct xfs_dquot *); | |
216 | extern void xfs_dqunlock(struct xfs_dquot *); | |
217 | extern void xfs_dqunlock_nonotify(struct xfs_dquot *); | |
218 | extern void xfs_dqlock2(struct xfs_dquot *, struct xfs_dquot *); | |
219 | extern void xfs_qm_dqput(struct xfs_dquot *); | |
220 | extern void xfs_qm_dqrele(struct xfs_dquot *); | |
221 | extern xfs_dqid_t xfs_qm_dqid(struct xfs_dquot *); | |
222 | extern int xfs_qm_dqget(struct xfs_mount *, | |
223 | struct xfs_inode *, xfs_dqid_t, | |
224 | uint, uint, struct xfs_dquot **); | |
225 | extern int xfs_qm_dqcheck(struct xfs_disk_dquot *, | |
226 | xfs_dqid_t, uint, uint, char *); | |
227 | ||
228 | /* | |
229 | * Vnodeops specific code that should actually be _in_ xfs_vnodeops.c, but | |
230 | * is here because it's nicer to keep vnodeops (therefore, XFS) lean | |
231 | * and clean. | |
232 | */ | |
233 | extern struct xfs_dquot * xfs_qm_vop_chown(struct xfs_trans *, | |
234 | struct xfs_inode *, | |
235 | struct xfs_dquot **, | |
236 | struct xfs_dquot *); | |
237 | extern int xfs_qm_vop_dqalloc(struct xfs_mount *, | |
238 | struct xfs_inode *, | |
b36eef04 | 239 | uid_t, gid_t, uint, |
2bd0ea18 NS |
240 | struct xfs_dquot **, |
241 | struct xfs_dquot **); | |
242 | ||
243 | extern int xfs_qm_vop_chown_dqalloc(struct xfs_mount *, | |
244 | struct xfs_inode *, | |
b36eef04 | 245 | int, uid_t, gid_t, |
2bd0ea18 NS |
246 | struct xfs_dquot **, |
247 | struct xfs_dquot **); | |
248 | ||
249 | extern int xfs_qm_vop_chown_reserve(struct xfs_trans *, | |
250 | struct xfs_inode *, | |
251 | struct xfs_dquot *, | |
252 | struct xfs_dquot *, | |
253 | uint); | |
254 | ||
255 | extern int xfs_qm_vop_rename_dqattach(struct xfs_inode **); | |
256 | extern void xfs_qm_vop_dqattach_and_dqmod_newinode( | |
257 | struct xfs_trans *, | |
258 | struct xfs_inode *, | |
259 | struct xfs_dquot *, | |
260 | struct xfs_dquot *); | |
261 | ||
262 | ||
263 | /* | |
264 | * Dquot Transaction interface | |
265 | */ | |
266 | extern void xfs_trans_alloc_dqinfo(struct xfs_trans *); | |
267 | extern void xfs_trans_free_dqinfo(struct xfs_trans *); | |
268 | extern void xfs_trans_dup_dqinfo(struct xfs_trans *, | |
269 | struct xfs_trans *); | |
270 | extern void xfs_trans_mod_dquot(struct xfs_trans *, | |
271 | struct xfs_dquot *, | |
272 | uint, long); | |
273 | extern int xfs_trans_mod_dquot_byino(struct xfs_trans *, | |
274 | struct xfs_inode *, | |
275 | uint, long); | |
276 | extern void xfs_trans_apply_dquot_deltas(struct xfs_trans *); | |
277 | extern void xfs_trans_unreserve_and_mod_dquots(struct xfs_trans *); | |
278 | ||
279 | extern int xfs_trans_reserve_quota_nblks(struct xfs_trans *, | |
280 | struct xfs_inode *, | |
281 | long, long, uint); | |
282 | ||
283 | ||
284 | extern int xfs_trans_reserve_quota_bydquots(struct xfs_trans *, | |
285 | struct xfs_dquot *, | |
286 | struct xfs_dquot *, | |
287 | long, long, uint); | |
288 | extern void xfs_trans_log_dquot(struct xfs_trans *, | |
289 | struct xfs_dquot *); | |
290 | extern void xfs_trans_dqjoin(struct xfs_trans *, | |
291 | struct xfs_dquot *); | |
292 | extern void xfs_qm_dqrele_all_inodes(struct xfs_mount *, uint); | |
293 | ||
294 | /* | |
295 | * Regular disk block quota reservations | |
296 | */ | |
297 | #define xfs_trans_reserve_blkquota(tp, ip, nblks) \ | |
298 | xfs_trans_reserve_quota_nblks(tp, ip, nblks, 0, XFS_QMOPT_RES_REGBLKS) | |
63be04eb NS |
299 | |
300 | #define xfs_trans_reserve_blkquota_force(tp, ip, nblks) \ | |
301 | xfs_trans_reserve_quota_nblks(tp, ip, nblks, 0, \ | |
302 | XFS_QMOPT_RES_REGBLKS|XFS_QMOPT_FORCE_RES) | |
303 | ||
2bd0ea18 NS |
304 | #define xfs_trans_unreserve_blkquota(tp, ip, nblks) \ |
305 | xfs_trans_reserve_quota_nblks(tp, ip, -(nblks), 0, XFS_QMOPT_RES_REGBLKS) | |
306 | ||
b36eef04 NS |
307 | #define xfs_trans_reserve_quota(tp, udq, gdq, nb, ni, f) \ |
308 | xfs_trans_reserve_quota_bydquots(tp, udq, gdq, nb, ni, f|XFS_QMOPT_RES_REGBLKS) | |
2bd0ea18 | 309 | |
b36eef04 NS |
310 | #define xfs_trans_unreserve_quota(tp, ud, gd, b, i, f) \ |
311 | xfs_trans_reserve_quota_bydquots(tp, ud, gd, -(b), -(i), f|XFS_QMOPT_RES_REGBLKS) | |
2bd0ea18 NS |
312 | |
313 | /* | |
314 | * Realtime disk block quota reservations | |
315 | */ | |
316 | #define xfs_trans_reserve_rtblkquota(mp, tp, ip, nblks) \ | |
317 | xfs_trans_reserve_quota_nblks(tp, ip, nblks, 0, XFS_QMOPT_RES_RTBLKS) | |
318 | ||
319 | #define xfs_trans_unreserve_rtblkquota(tp, ip, nblks) \ | |
320 | xfs_trans_reserve_quota_nblks(tp, ip, -(nblks), 0, XFS_QMOPT_RES_RTBLKS) | |
321 | ||
322 | #define xfs_trans_reserve_rtquota(mp, tp, uq, pq, blks, f) \ | |
323 | xfs_trans_reserve_quota_bydquots(mp, tp, uq, pq, blks, 0, f|XFS_QMOPT_RES_RTBLKS) | |
324 | ||
325 | #define xfs_trans_unreserve_rtquota(tp, uq, pq, blks) \ | |
326 | xfs_trans_reserve_quota_bydquots(tp, uq, pq, -(blks), XFS_QMOPT_RES_RTBLKS) | |
327 | ||
328 | #endif /* __KERNEL__ */ | |
329 | ||
330 | #endif /* __XFS_QUOTA_H__ */ |