xfs: flatten the dquot lock ordering
[deliverable/linux.git] / fs / xfs / xfs_quota.h
CommitLineData
1da177e4 1/*
7b718769
NS
2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
1da177e4 4 *
7b718769
NS
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
1da177e4
LT
7 * published by the Free Software Foundation.
8 *
7b718769
NS
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
1da177e4 13 *
7b718769
NS
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1da177e4
LT
17 */
18#ifndef __XFS_QUOTA_H__
19#define __XFS_QUOTA_H__
20
fcafb71b
CH
21struct xfs_trans;
22
1da177e4
LT
23/*
24 * The ondisk form of a dquot structure.
25 */
26#define XFS_DQUOT_MAGIC 0x4451 /* 'DQ' */
27#define XFS_DQUOT_VERSION (u_int8_t)0x01 /* latest version number */
28
29/*
30 * uid_t and gid_t are hard-coded to 32 bits in the inode.
31 * Hence, an 'id' in a dquot is 32 bits..
32 */
c310ab6c 33typedef __uint32_t xfs_dqid_t;
1da177e4
LT
34
35/*
c41564b5 36 * Even though users may not have quota limits occupying all 64-bits,
1da177e4
LT
37 * they may need 64-bit accounting. Hence, 64-bit quota-counters,
38 * and quota-limits. This is a waste in the common case, but hey ...
39 */
40typedef __uint64_t xfs_qcnt_t;
41typedef __uint16_t xfs_qwarncnt_t;
42
43/*
44 * This is the main portion of the on-disk representation of quota
45 * information for a user. This is the q_core of the xfs_dquot_t that
46 * is kept in kernel memory. We pad this with some more expansion room
47 * to construct the on disk structure.
48 */
49typedef struct xfs_disk_dquot {
1149d96a
CH
50 __be16 d_magic; /* dquot magic = XFS_DQUOT_MAGIC */
51 __u8 d_version; /* dquot version */
52 __u8 d_flags; /* XFS_DQ_USER/PROJ/GROUP */
53 __be32 d_id; /* user,project,group id */
54 __be64 d_blk_hardlimit;/* absolute limit on disk blks */
55 __be64 d_blk_softlimit;/* preferred limit on disk blks */
56 __be64 d_ino_hardlimit;/* maximum # allocated inodes */
57 __be64 d_ino_softlimit;/* preferred inode limit */
58 __be64 d_bcount; /* disk blocks owned by the user */
59 __be64 d_icount; /* inodes owned by the user */
60 __be32 d_itimer; /* zero if within inode limits if not,
1da177e4 61 this is when we refuse service */
1149d96a
CH
62 __be32 d_btimer; /* similar to above; for disk blocks */
63 __be16 d_iwarns; /* warnings issued wrt num inodes */
64 __be16 d_bwarns; /* warnings issued wrt disk blocks */
65 __be32 d_pad0; /* 64 bit align */
66 __be64 d_rtb_hardlimit;/* absolute limit on realtime blks */
67 __be64 d_rtb_softlimit;/* preferred limit on RT disk blks */
68 __be64 d_rtbcount; /* realtime blocks owned */
69 __be32 d_rtbtimer; /* similar to above; for RT disk blocks */
70 __be16 d_rtbwarns; /* warnings issued wrt RT disk blocks */
71 __be16 d_pad;
1da177e4
LT
72} xfs_disk_dquot_t;
73
74/*
75 * This is what goes on disk. This is separated from the xfs_disk_dquot because
76 * carrying the unnecessary padding would be a waste of memory.
77 */
78typedef struct xfs_dqblk {
79 xfs_disk_dquot_t dd_diskdq; /* portion that lives incore as well */
80 char dd_fill[32]; /* filling for posterity */
81} xfs_dqblk_t;
82
83/*
84 * flags for q_flags field in the dquot.
85 */
86#define XFS_DQ_USER 0x0001 /* a user quota */
c8ad20ff 87#define XFS_DQ_PROJ 0x0002 /* project quota */
1da177e4 88#define XFS_DQ_GROUP 0x0004 /* a group quota */
df6771bd 89#define XFS_DQ_DIRTY 0x0008 /* dquot is dirty */
92678554 90#define XFS_DQ_FREEING 0x0010 /* dquot is beeing torn down */
1da177e4 91
c8ad20ff
NS
92#define XFS_DQ_ALLTYPES (XFS_DQ_USER|XFS_DQ_PROJ|XFS_DQ_GROUP)
93
0b1b213f
CH
94#define XFS_DQ_FLAGS \
95 { XFS_DQ_USER, "USER" }, \
96 { XFS_DQ_PROJ, "PROJ" }, \
97 { XFS_DQ_GROUP, "GROUP" }, \
92678554
CH
98 { XFS_DQ_DIRTY, "DIRTY" }, \
99 { XFS_DQ_FREEING, "FREEING" }
0b1b213f 100
1da177e4
LT
101/*
102 * In the worst case, when both user and group quotas are on,
103 * we can have a max of three dquots changing in a single transaction.
104 */
105#define XFS_DQUOT_LOGRES(mp) (sizeof(xfs_disk_dquot_t) * 3)
106
107
108/*
109 * These are the structures used to lay out dquots and quotaoff
110 * records on the log. Quite similar to those of inodes.
111 */
112
113/*
114 * log format struct for dquots.
115 * The first two fields must be the type and size fitting into
116 * 32 bits : log_recovery code assumes that.
117 */
118typedef struct xfs_dq_logformat {
119 __uint16_t qlf_type; /* dquot log item type */
120 __uint16_t qlf_size; /* size of this item */
c8ad20ff 121 xfs_dqid_t qlf_id; /* usr/grp/proj id : 32 bits */
1da177e4
LT
122 __int64_t qlf_blkno; /* blkno of dquot buffer */
123 __int32_t qlf_len; /* len of dquot buffer */
124 __uint32_t qlf_boffset; /* off of dquot in buffer */
125} xfs_dq_logformat_t;
126
127/*
128 * log format struct for QUOTAOFF records.
129 * The first two fields must be the type and size fitting into
130 * 32 bits : log_recovery code assumes that.
131 * We write two LI_QUOTAOFF logitems per quotaoff, the last one keeps a pointer
132 * to the first and ensures that the first logitem is taken out of the AIL
133 * only when the last one is securely committed.
134 */
135typedef struct xfs_qoff_logformat {
136 unsigned short qf_type; /* quotaoff log item type */
137 unsigned short qf_size; /* size of this item */
138 unsigned int qf_flags; /* USR and/or GRP */
139 char qf_pad[12]; /* padding for future */
140} xfs_qoff_logformat_t;
141
142
143/*
144 * Disk quotas status in m_qflags, and also sb_qflags. 16 bits.
145 */
146#define XFS_UQUOTA_ACCT 0x0001 /* user quota accounting ON */
147#define XFS_UQUOTA_ENFD 0x0002 /* user quota limits enforced */
148#define XFS_UQUOTA_CHKD 0x0004 /* quotacheck run on usr quotas */
c8ad20ff
NS
149#define XFS_PQUOTA_ACCT 0x0008 /* project quota accounting ON */
150#define XFS_OQUOTA_ENFD 0x0010 /* other (grp/prj) quota limits enforced */
151#define XFS_OQUOTA_CHKD 0x0020 /* quotacheck run on other (grp/prj) quotas */
1da177e4
LT
152#define XFS_GQUOTA_ACCT 0x0040 /* group quota accounting ON */
153
4cd4a034
TS
154/*
155 * Quota Accounting/Enforcement flags
156 */
157#define XFS_ALL_QUOTA_ACCT \
158 (XFS_UQUOTA_ACCT | XFS_GQUOTA_ACCT | XFS_PQUOTA_ACCT)
159#define XFS_ALL_QUOTA_ENFD (XFS_UQUOTA_ENFD | XFS_OQUOTA_ENFD)
160#define XFS_ALL_QUOTA_CHKD (XFS_UQUOTA_CHKD | XFS_OQUOTA_CHKD)
161
162#define XFS_IS_QUOTA_RUNNING(mp) ((mp)->m_qflags & XFS_ALL_QUOTA_ACCT)
4cd4a034
TS
163#define XFS_IS_UQUOTA_RUNNING(mp) ((mp)->m_qflags & XFS_UQUOTA_ACCT)
164#define XFS_IS_PQUOTA_RUNNING(mp) ((mp)->m_qflags & XFS_PQUOTA_ACCT)
165#define XFS_IS_GQUOTA_RUNNING(mp) ((mp)->m_qflags & XFS_GQUOTA_ACCT)
e6d29426
KO
166#define XFS_IS_UQUOTA_ENFORCED(mp) ((mp)->m_qflags & XFS_UQUOTA_ENFD)
167#define XFS_IS_OQUOTA_ENFORCED(mp) ((mp)->m_qflags & XFS_OQUOTA_ENFD)
4cd4a034 168
1da177e4
LT
169/*
170 * Incore only flags for quotaoff - these bits get cleared when quota(s)
171 * are in the process of getting turned off. These flags are in m_qflags but
172 * never in sb_qflags.
173 */
c8ad20ff
NS
174#define XFS_UQUOTA_ACTIVE 0x0100 /* uquotas are being turned off */
175#define XFS_PQUOTA_ACTIVE 0x0200 /* pquotas are being turned off */
176#define XFS_GQUOTA_ACTIVE 0x0400 /* gquotas are being turned off */
1da177e4
LT
177
178/*
179 * Checking XFS_IS_*QUOTA_ON() while holding any inode lock guarantees
180 * quota will be not be switched off as long as that inode lock is held.
181 */
182#define XFS_IS_QUOTA_ON(mp) ((mp)->m_qflags & (XFS_UQUOTA_ACTIVE | \
c8ad20ff
NS
183 XFS_GQUOTA_ACTIVE | \
184 XFS_PQUOTA_ACTIVE))
185#define XFS_IS_OQUOTA_ON(mp) ((mp)->m_qflags & (XFS_GQUOTA_ACTIVE | \
186 XFS_PQUOTA_ACTIVE))
1da177e4
LT
187#define XFS_IS_UQUOTA_ON(mp) ((mp)->m_qflags & XFS_UQUOTA_ACTIVE)
188#define XFS_IS_GQUOTA_ON(mp) ((mp)->m_qflags & XFS_GQUOTA_ACTIVE)
c8ad20ff 189#define XFS_IS_PQUOTA_ON(mp) ((mp)->m_qflags & XFS_PQUOTA_ACTIVE)
1da177e4
LT
190
191/*
192 * Flags to tell various functions what to do. Not all of these are meaningful
193 * to a single function. None of these XFS_QMOPT_* flags are meant to have
194 * persistent values (ie. their values can and will change between versions)
195 */
1da177e4
LT
196#define XFS_QMOPT_DQALLOC 0x0000002 /* alloc dquot ondisk if needed */
197#define XFS_QMOPT_UQUOTA 0x0000004 /* user dquot requested */
c8ad20ff 198#define XFS_QMOPT_PQUOTA 0x0000008 /* project dquot requested */
1da177e4
LT
199#define XFS_QMOPT_FORCE_RES 0x0000010 /* ignore quota limits */
200#define XFS_QMOPT_DQSUSER 0x0000020 /* don't cache super users dquot */
201#define XFS_QMOPT_SBVERSION 0x0000040 /* change superblock version num */
9a2a7de2 202#define XFS_QMOPT_DOWARN 0x0000400 /* increase warning cnt if needed */
9a2a7de2 203#define XFS_QMOPT_DQREPAIR 0x0001000 /* repair dquot if damaged */
c8ad20ff 204#define XFS_QMOPT_GQUOTA 0x0002000 /* group dquot requested */
9a2a7de2 205#define XFS_QMOPT_ENOSPC 0x0004000 /* enospc instead of edquot (prj) */
1da177e4
LT
206
207/*
208 * flags to xfs_trans_mod_dquot to indicate which field needs to be
209 * modified.
210 */
211#define XFS_QMOPT_RES_REGBLKS 0x0010000
212#define XFS_QMOPT_RES_RTBLKS 0x0020000
213#define XFS_QMOPT_BCOUNT 0x0040000
214#define XFS_QMOPT_ICOUNT 0x0080000
215#define XFS_QMOPT_RTBCOUNT 0x0100000
216#define XFS_QMOPT_DELBCOUNT 0x0200000
217#define XFS_QMOPT_DELRTBCOUNT 0x0400000
218#define XFS_QMOPT_RES_INOS 0x0800000
219
1da177e4
LT
220/*
221 * flags for dqalloc.
222 */
20026d92 223#define XFS_QMOPT_INHERIT 0x1000000
1da177e4
LT
224
225/*
226 * flags to xfs_trans_mod_dquot.
227 */
228#define XFS_TRANS_DQ_RES_BLKS XFS_QMOPT_RES_REGBLKS
229#define XFS_TRANS_DQ_RES_RTBLKS XFS_QMOPT_RES_RTBLKS
230#define XFS_TRANS_DQ_RES_INOS XFS_QMOPT_RES_INOS
231#define XFS_TRANS_DQ_BCOUNT XFS_QMOPT_BCOUNT
232#define XFS_TRANS_DQ_DELBCOUNT XFS_QMOPT_DELBCOUNT
233#define XFS_TRANS_DQ_ICOUNT XFS_QMOPT_ICOUNT
234#define XFS_TRANS_DQ_RTBCOUNT XFS_QMOPT_RTBCOUNT
235#define XFS_TRANS_DQ_DELRTBCOUNT XFS_QMOPT_DELRTBCOUNT
236
237
c8ad20ff
NS
238#define XFS_QMOPT_QUOTALL \
239 (XFS_QMOPT_UQUOTA | XFS_QMOPT_PQUOTA | XFS_QMOPT_GQUOTA)
1da177e4
LT
240#define XFS_QMOPT_RESBLK_MASK (XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_RES_RTBLKS)
241
242#ifdef __KERNEL__
243/*
244 * This check is done typically without holding the inode lock;
c41564b5 245 * that may seem racy, but it is harmless in the context that it is used.
1da177e4
LT
246 * The inode cannot go inactive as long a reference is kept, and
247 * therefore if dquot(s) were attached, they'll stay consistent.
248 * If, for example, the ownership of the inode changes while
249 * we didn't have the inode locked, the appropriate dquot(s) will be
250 * attached atomically.
251 */
252#define XFS_NOT_DQATTACHED(mp, ip) ((XFS_IS_UQUOTA_ON(mp) &&\
253 (ip)->i_udquot == NULL) || \
c8ad20ff 254 (XFS_IS_OQUOTA_ON(mp) && \
1da177e4
LT
255 (ip)->i_gdquot == NULL))
256
c8ad20ff
NS
257#define XFS_QM_NEED_QUOTACHECK(mp) \
258 ((XFS_IS_UQUOTA_ON(mp) && \
259 (mp->m_sb.sb_qflags & XFS_UQUOTA_CHKD) == 0) || \
260 (XFS_IS_GQUOTA_ON(mp) && \
261 ((mp->m_sb.sb_qflags & XFS_OQUOTA_CHKD) == 0 || \
262 (mp->m_sb.sb_qflags & XFS_PQUOTA_ACCT))) || \
263 (XFS_IS_PQUOTA_ON(mp) && \
264 ((mp->m_sb.sb_qflags & XFS_OQUOTA_CHKD) == 0 || \
265 (mp->m_sb.sb_qflags & XFS_GQUOTA_ACCT))))
1da177e4 266
c8ad20ff
NS
267#define XFS_MOUNT_QUOTA_SET1 (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD|\
268 XFS_UQUOTA_CHKD|XFS_PQUOTA_ACCT|\
269 XFS_OQUOTA_ENFD|XFS_OQUOTA_CHKD)
270
271#define XFS_MOUNT_QUOTA_SET2 (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD|\
1da177e4 272 XFS_UQUOTA_CHKD|XFS_GQUOTA_ACCT|\
c8ad20ff
NS
273 XFS_OQUOTA_ENFD|XFS_OQUOTA_CHKD)
274
275#define XFS_MOUNT_QUOTA_ALL (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD|\
276 XFS_UQUOTA_CHKD|XFS_PQUOTA_ACCT|\
277 XFS_OQUOTA_ENFD|XFS_OQUOTA_CHKD|\
278 XFS_GQUOTA_ACCT)
1da177e4
LT
279
280
281/*
282 * The structure kept inside the xfs_trans_t keep track of dquot changes
283 * within a transaction and apply them later.
284 */
285typedef struct xfs_dqtrx {
286 struct xfs_dquot *qt_dquot; /* the dquot this refers to */
287 ulong qt_blk_res; /* blks reserved on a dquot */
288 ulong qt_blk_res_used; /* blks used from the reservation */
289 ulong qt_ino_res; /* inode reserved on a dquot */
290 ulong qt_ino_res_used; /* inodes used from the reservation */
291 long qt_bcount_delta; /* dquot blk count changes */
292 long qt_delbcnt_delta; /* delayed dquot blk count changes */
293 long qt_icount_delta; /* dquot inode count changes */
294 ulong qt_rtblk_res; /* # blks reserved on a dquot */
295 ulong qt_rtblk_res_used;/* # blks used from reservation */
296 long qt_rtbcount_delta;/* dquot realtime blk changes */
297 long qt_delrtb_delta; /* delayed RT blk count changes */
298} xfs_dqtrx_t;
299
7d095257
CH
300#ifdef CONFIG_XFS_QUOTA
301extern void xfs_trans_dup_dqinfo(struct xfs_trans *, struct xfs_trans *);
302extern void xfs_trans_free_dqinfo(struct xfs_trans *);
303extern void xfs_trans_mod_dquot_byino(struct xfs_trans *, struct xfs_inode *,
304 uint, long);
305extern void xfs_trans_apply_dquot_deltas(struct xfs_trans *);
306extern void xfs_trans_unreserve_and_mod_dquots(struct xfs_trans *);
307extern int xfs_trans_reserve_quota_nblks(struct xfs_trans *,
308 struct xfs_inode *, long, long, uint);
309extern int xfs_trans_reserve_quota_bydquots(struct xfs_trans *,
310 struct xfs_mount *, struct xfs_dquot *,
311 struct xfs_dquot *, long, long, uint);
312
313extern int xfs_qm_vop_dqalloc(struct xfs_inode *, uid_t, gid_t, prid_t, uint,
314 struct xfs_dquot **, struct xfs_dquot **);
315extern void xfs_qm_vop_create_dqattach(struct xfs_trans *, struct xfs_inode *,
316 struct xfs_dquot *, struct xfs_dquot *);
317extern int xfs_qm_vop_rename_dqattach(struct xfs_inode **);
318extern struct xfs_dquot *xfs_qm_vop_chown(struct xfs_trans *,
319 struct xfs_inode *, struct xfs_dquot **, struct xfs_dquot *);
320extern int xfs_qm_vop_chown_reserve(struct xfs_trans *, struct xfs_inode *,
321 struct xfs_dquot *, struct xfs_dquot *, uint);
322extern int xfs_qm_dqattach(struct xfs_inode *, uint);
323extern int xfs_qm_dqattach_locked(struct xfs_inode *, uint);
324extern void xfs_qm_dqdetach(struct xfs_inode *);
325extern void xfs_qm_dqrele(struct xfs_dquot *);
326extern void xfs_qm_statvfs(struct xfs_inode *, struct kstatfs *);
7d095257
CH
327extern int xfs_qm_newmount(struct xfs_mount *, uint *, uint *);
328extern void xfs_qm_mount_quotas(struct xfs_mount *);
329extern void xfs_qm_unmount(struct xfs_mount *);
330extern void xfs_qm_unmount_quotas(struct xfs_mount *);
331
332#else
493b87e5
CH
333static inline int
334xfs_qm_vop_dqalloc(struct xfs_inode *ip, uid_t uid, gid_t gid, prid_t prid,
335 uint flags, struct xfs_dquot **udqp, struct xfs_dquot **gdqp)
336{
337 *udqp = NULL;
338 *gdqp = NULL;
339 return 0;
340}
7d095257
CH
341#define xfs_trans_dup_dqinfo(tp, tp2)
342#define xfs_trans_free_dqinfo(tp)
343#define xfs_trans_mod_dquot_byino(tp, ip, fields, delta)
344#define xfs_trans_apply_dquot_deltas(tp)
345#define xfs_trans_unreserve_and_mod_dquots(tp)
5d2bf8a5
CH
346static inline int xfs_trans_reserve_quota_nblks(struct xfs_trans *tp,
347 struct xfs_inode *ip, long nblks, long ninos, uint flags)
348{
349 return 0;
350}
351static inline int xfs_trans_reserve_quota_bydquots(struct xfs_trans *tp,
352 struct xfs_mount *mp, struct xfs_dquot *udqp,
353 struct xfs_dquot *gdqp, long nblks, long nions, uint flags)
354{
355 return 0;
356}
7d095257
CH
357#define xfs_qm_vop_create_dqattach(tp, ip, u, g)
358#define xfs_qm_vop_rename_dqattach(it) (0)
359#define xfs_qm_vop_chown(tp, ip, old, new) (NULL)
360#define xfs_qm_vop_chown_reserve(tp, ip, u, g, fl) (0)
361#define xfs_qm_dqattach(ip, fl) (0)
362#define xfs_qm_dqattach_locked(ip, fl) (0)
363#define xfs_qm_dqdetach(ip)
364#define xfs_qm_dqrele(d)
365#define xfs_qm_statvfs(ip, s)
7d095257
CH
366#define xfs_qm_newmount(mp, a, b) (0)
367#define xfs_qm_mount_quotas(mp)
368#define xfs_qm_unmount(mp)
5d2bf8a5 369#define xfs_qm_unmount_quotas(mp)
7d095257
CH
370#endif /* CONFIG_XFS_QUOTA */
371
372#define xfs_trans_unreserve_quota_nblks(tp, ip, nblks, ninos, flags) \
373 xfs_trans_reserve_quota_nblks(tp, ip, -(nblks), -(ninos), flags)
374#define xfs_trans_reserve_quota(tp, mp, ud, gd, nb, ni, f) \
375 xfs_trans_reserve_quota_bydquots(tp, mp, ud, gd, nb, ni, \
1da177e4
LT
376 f | XFS_QMOPT_RES_REGBLKS)
377
a0fa2b67
DC
378extern int xfs_qm_dqcheck(struct xfs_mount *, xfs_disk_dquot_t *,
379 xfs_dqid_t, uint, uint, char *);
4cd4a034 380extern int xfs_mount_reset_sbqflags(struct xfs_mount *);
1da177e4 381
1da177e4 382#endif /* __KERNEL__ */
1da177e4 383#endif /* __XFS_QUOTA_H__ */
This page took 0.516613 seconds and 5 git commands to generate.