Merge branch 'x86-mce-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / include / linux / quotaops.h
CommitLineData
1da177e4
LT
1/*
2 * Definitions for diskquota-operations. When diskquota is configured these
3 * macros expand to the right source-code.
4 *
5 * Author: Marco van Wieringen <mvw@planets.elm.net>
1da177e4
LT
6 */
7#ifndef _LINUX_QUOTAOPS_
8#define _LINUX_QUOTAOPS_
9
1da177e4 10#include <linux/smp_lock.h>
1da177e4
LT
11#include <linux/fs.h>
12
03b06343
JK
13static inline struct quota_info *sb_dqopt(struct super_block *sb)
14{
15 return &sb->s_dquot;
16}
74abb989 17
1da177e4
LT
18#if defined(CONFIG_QUOTA)
19
20/*
21 * declaration of quota_function calls in kernel.
22 */
b85f4b87
JK
23void sync_dquots(struct super_block *sb, int type);
24
25int dquot_initialize(struct inode *inode, int type);
26int dquot_drop(struct inode *inode);
3d9ea253
JK
27struct dquot *dqget(struct super_block *sb, unsigned int id, int type);
28void dqput(struct dquot *dquot);
12c77527
JK
29int dquot_scan_active(struct super_block *sb,
30 int (*fn)(struct dquot *dquot, unsigned long priv),
31 unsigned long priv);
7d9056ba
JK
32struct dquot *dquot_alloc(struct super_block *sb, int type);
33void dquot_destroy(struct dquot *dquot);
b85f4b87
JK
34
35int dquot_alloc_space(struct inode *inode, qsize_t number, int prealloc);
12095460 36int dquot_alloc_inode(const struct inode *inode, qsize_t number);
b85f4b87 37
740d9dcd
MC
38int dquot_reserve_space(struct inode *inode, qsize_t number, int prealloc);
39int dquot_claim_space(struct inode *inode, qsize_t number);
40void dquot_release_reserved_space(struct inode *inode, qsize_t number);
41qsize_t dquot_get_reserved_space(struct inode *inode);
42
b85f4b87 43int dquot_free_space(struct inode *inode, qsize_t number);
12095460 44int dquot_free_inode(const struct inode *inode, qsize_t number);
b85f4b87
JK
45
46int dquot_transfer(struct inode *inode, struct iattr *iattr);
47int dquot_commit(struct dquot *dquot);
48int dquot_acquire(struct dquot *dquot);
49int dquot_release(struct dquot *dquot);
50int dquot_commit_info(struct super_block *sb, int type);
51int dquot_mark_dquot_dirty(struct dquot *dquot);
52
53int vfs_quota_on(struct super_block *sb, int type, int format_id,
54 char *path, int remount);
f55abc0f
JK
55int vfs_quota_enable(struct inode *inode, int type, int format_id,
56 unsigned int flags);
77e69dac
AV
57int vfs_quota_on_path(struct super_block *sb, int type, int format_id,
58 struct path *path);
b85f4b87
JK
59int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
60 int format_id, int type);
61int vfs_quota_off(struct super_block *sb, int type, int remount);
f55abc0f 62int vfs_quota_disable(struct super_block *sb, int type, unsigned int flags);
b85f4b87
JK
63int vfs_quota_sync(struct super_block *sb, int type);
64int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
65int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
66int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
67int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
68
69void vfs_dq_drop(struct inode *inode);
70int vfs_dq_transfer(struct inode *inode, struct iattr *iattr);
71int vfs_dq_quota_on_remount(struct super_block *sb);
1da177e4 72
03b06343
JK
73static inline struct mem_dqinfo *sb_dqinfo(struct super_block *sb, int type)
74{
75 return sb_dqopt(sb)->info + type;
76}
74abb989
JK
77
78/*
79 * Functions for checking status of quota
80 */
81
f55abc0f 82static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type)
03b06343 83{
f55abc0f
JK
84 return sb_dqopt(sb)->flags &
85 dquot_state_flag(DQUOT_USAGE_ENABLED, type);
03b06343 86}
74abb989 87
f55abc0f 88static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type)
03b06343 89{
f55abc0f
JK
90 return sb_dqopt(sb)->flags &
91 dquot_state_flag(DQUOT_LIMITS_ENABLED, type);
03b06343 92}
74abb989 93
03b06343
JK
94static inline int sb_has_quota_suspended(struct super_block *sb, int type)
95{
f55abc0f
JK
96 return sb_dqopt(sb)->flags &
97 dquot_state_flag(DQUOT_SUSPENDED, type);
03b06343 98}
74abb989 99
03b06343
JK
100static inline int sb_any_quota_suspended(struct super_block *sb)
101{
102 return sb_has_quota_suspended(sb, USRQUOTA) ||
103 sb_has_quota_suspended(sb, GRPQUOTA);
104}
74abb989 105
f55abc0f
JK
106/* Does kernel know about any quota information for given sb + type? */
107static inline int sb_has_quota_loaded(struct super_block *sb, int type)
108{
109 /* Currently if anything is on, then quota usage is on as well */
110 return sb_has_quota_usage_enabled(sb, type);
111}
112
113static inline int sb_any_quota_loaded(struct super_block *sb)
114{
115 return sb_has_quota_loaded(sb, USRQUOTA) ||
116 sb_has_quota_loaded(sb, GRPQUOTA);
117}
118
119static inline int sb_has_quota_active(struct super_block *sb, int type)
120{
121 return sb_has_quota_loaded(sb, type) &&
122 !sb_has_quota_suspended(sb, type);
123}
124
125static inline int sb_any_quota_active(struct super_block *sb)
126{
127 return sb_has_quota_active(sb, USRQUOTA) ||
128 sb_has_quota_active(sb, GRPQUOTA);
129}
130
1da177e4
LT
131/*
132 * Operations supported for diskquotas.
133 */
134extern struct dquot_operations dquot_operations;
135extern struct quotactl_ops vfs_quotactl_ops;
136
137#define sb_dquot_ops (&dquot_operations)
138#define sb_quotactl_ops (&vfs_quotactl_ops)
139
140/* It is better to call this function outside of any transaction as it might
141 * need a lot of space in journal for dquot structure allocation. */
b85f4b87 142static inline void vfs_dq_init(struct inode *inode)
1da177e4
LT
143{
144 BUG_ON(!inode->i_sb);
f55abc0f 145 if (sb_any_quota_active(inode->i_sb) && !IS_NOQUOTA(inode))
1da177e4
LT
146 inode->i_sb->dq_op->initialize(inode, -1);
147}
148
1da177e4
LT
149/* The following allocation/freeing/transfer functions *must* be called inside
150 * a transaction (deadlocks possible otherwise) */
b85f4b87 151static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
1da177e4 152{
f55abc0f 153 if (sb_any_quota_active(inode->i_sb)) {
1da177e4
LT
154 /* Used space is updated in alloc_space() */
155 if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
156 return 1;
157 }
158 else
159 inode_add_bytes(inode, nr);
160 return 0;
161}
162
b85f4b87 163static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
1da177e4
LT
164{
165 int ret;
b85f4b87 166 if (!(ret = vfs_dq_prealloc_space_nodirty(inode, nr)))
1da177e4
LT
167 mark_inode_dirty(inode);
168 return ret;
169}
170
b85f4b87 171static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
1da177e4 172{
f55abc0f 173 if (sb_any_quota_active(inode->i_sb)) {
1da177e4
LT
174 /* Used space is updated in alloc_space() */
175 if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
176 return 1;
177 }
178 else
179 inode_add_bytes(inode, nr);
180 return 0;
181}
182
b85f4b87 183static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
1da177e4
LT
184{
185 int ret;
b85f4b87 186 if (!(ret = vfs_dq_alloc_space_nodirty(inode, nr)))
1da177e4
LT
187 mark_inode_dirty(inode);
188 return ret;
189}
190
f18df228
MC
191static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
192{
193 if (sb_any_quota_active(inode->i_sb)) {
194 /* Used space is updated in alloc_space() */
195 if (inode->i_sb->dq_op->reserve_space(inode, nr, 0) == NO_QUOTA)
196 return 1;
197 }
198 return 0;
199}
200
b85f4b87 201static inline int vfs_dq_alloc_inode(struct inode *inode)
1da177e4 202{
f55abc0f 203 if (sb_any_quota_active(inode->i_sb)) {
b85f4b87 204 vfs_dq_init(inode);
1da177e4
LT
205 if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
206 return 1;
207 }
208 return 0;
209}
210
740d9dcd
MC
211/*
212 * Convert in-memory reserved quotas to real consumed quotas
213 */
214static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
215{
216 if (sb_any_quota_active(inode->i_sb)) {
217 if (inode->i_sb->dq_op->claim_space(inode, nr) == NO_QUOTA)
218 return 1;
219 } else
220 inode_add_bytes(inode, nr);
221
222 mark_inode_dirty(inode);
223 return 0;
224}
225
226/*
227 * Release reserved (in-memory) quotas
228 */
229static inline
230void vfs_dq_release_reservation_space(struct inode *inode, qsize_t nr)
231{
232 if (sb_any_quota_active(inode->i_sb))
233 inode->i_sb->dq_op->release_rsv(inode, nr);
234}
235
b85f4b87 236static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
1da177e4 237{
f55abc0f 238 if (sb_any_quota_active(inode->i_sb))
1da177e4
LT
239 inode->i_sb->dq_op->free_space(inode, nr);
240 else
241 inode_sub_bytes(inode, nr);
242}
243
b85f4b87 244static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
1da177e4 245{
b85f4b87 246 vfs_dq_free_space_nodirty(inode, nr);
1da177e4
LT
247 mark_inode_dirty(inode);
248}
249
b85f4b87 250static inline void vfs_dq_free_inode(struct inode *inode)
1da177e4 251{
f55abc0f 252 if (sb_any_quota_active(inode->i_sb))
1da177e4
LT
253 inode->i_sb->dq_op->free_inode(inode, 1);
254}
255
1da177e4 256/* The following two functions cannot be called inside a transaction */
b85f4b87 257static inline void vfs_dq_sync(struct super_block *sb)
03f6e92b
JK
258{
259 sync_dquots(sb, -1);
260}
1da177e4 261
b85f4b87 262static inline int vfs_dq_off(struct super_block *sb, int remount)
1da177e4
LT
263{
264 int ret = -ENOSYS;
265
0ff5af83
JK
266 if (sb->s_qcop && sb->s_qcop->quota_off)
267 ret = sb->s_qcop->quota_off(sb, -1, remount);
268 return ret;
269}
270
1da177e4
LT
271#else
272
f55abc0f 273static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type)
03b06343
JK
274{
275 return 0;
276}
277
f55abc0f 278static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type)
03b06343
JK
279{
280 return 0;
281}
282
283static inline int sb_has_quota_suspended(struct super_block *sb, int type)
284{
285 return 0;
286}
287
288static inline int sb_any_quota_suspended(struct super_block *sb)
289{
290 return 0;
291}
74abb989 292
f55abc0f
JK
293/* Does kernel know about any quota information for given sb + type? */
294static inline int sb_has_quota_loaded(struct super_block *sb, int type)
295{
296 return 0;
297}
298
299static inline int sb_any_quota_loaded(struct super_block *sb)
300{
301 return 0;
302}
303
304static inline int sb_has_quota_active(struct super_block *sb, int type)
305{
306 return 0;
307}
308
309static inline int sb_any_quota_active(struct super_block *sb)
310{
311 return 0;
312}
313
1da177e4
LT
314/*
315 * NO-OP when quota not configured.
316 */
317#define sb_dquot_ops (NULL)
318#define sb_quotactl_ops (NULL)
50f8c370 319
b85f4b87 320static inline void vfs_dq_init(struct inode *inode)
50f8c370
AM
321{
322}
323
b85f4b87 324static inline void vfs_dq_drop(struct inode *inode)
50f8c370
AM
325{
326}
327
b85f4b87 328static inline int vfs_dq_alloc_inode(struct inode *inode)
50f8c370
AM
329{
330 return 0;
331}
332
b85f4b87 333static inline void vfs_dq_free_inode(struct inode *inode)
50f8c370
AM
334{
335}
336
b85f4b87 337static inline void vfs_dq_sync(struct super_block *sb)
50f8c370
AM
338{
339}
340
b85f4b87 341static inline int vfs_dq_off(struct super_block *sb, int remount)
50f8c370
AM
342{
343 return 0;
344}
345
b85f4b87 346static inline int vfs_dq_quota_on_remount(struct super_block *sb)
50f8c370
AM
347{
348 return 0;
349}
350
b85f4b87 351static inline int vfs_dq_transfer(struct inode *inode, struct iattr *iattr)
50f8c370
AM
352{
353 return 0;
354}
355
b85f4b87 356static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
1da177e4
LT
357{
358 inode_add_bytes(inode, nr);
359 return 0;
360}
361
b85f4b87 362static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
1da177e4 363{
b85f4b87 364 vfs_dq_prealloc_space_nodirty(inode, nr);
1da177e4
LT
365 mark_inode_dirty(inode);
366 return 0;
367}
368
b85f4b87 369static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
1da177e4
LT
370{
371 inode_add_bytes(inode, nr);
372 return 0;
373}
374
b85f4b87 375static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
1da177e4 376{
b85f4b87 377 vfs_dq_alloc_space_nodirty(inode, nr);
1da177e4
LT
378 mark_inode_dirty(inode);
379 return 0;
380}
381
f18df228
MC
382static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
383{
384 return 0;
385}
386
740d9dcd
MC
387static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
388{
389 return vfs_dq_alloc_space(inode, nr);
390}
391
392static inline
393int vfs_dq_release_reservation_space(struct inode *inode, qsize_t nr)
394{
395 return 0;
396}
397
b85f4b87 398static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
1da177e4
LT
399{
400 inode_sub_bytes(inode, nr);
401}
402
b85f4b87 403static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
1da177e4 404{
b85f4b87 405 vfs_dq_free_space_nodirty(inode, nr);
1da177e4
LT
406 mark_inode_dirty(inode);
407}
408
409#endif /* CONFIG_QUOTA */
410
b85f4b87 411static inline int vfs_dq_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
03f6e92b 412{
9900ba34 413 return vfs_dq_prealloc_space_nodirty(inode, nr << inode->i_blkbits);
03f6e92b
JK
414}
415
b85f4b87 416static inline int vfs_dq_prealloc_block(struct inode *inode, qsize_t nr)
03f6e92b 417{
9900ba34 418 return vfs_dq_prealloc_space(inode, nr << inode->i_blkbits);
03f6e92b
JK
419}
420
b85f4b87 421static inline int vfs_dq_alloc_block_nodirty(struct inode *inode, qsize_t nr)
03f6e92b 422{
9900ba34 423 return vfs_dq_alloc_space_nodirty(inode, nr << inode->i_blkbits);
03f6e92b
JK
424}
425
b85f4b87 426static inline int vfs_dq_alloc_block(struct inode *inode, qsize_t nr)
03f6e92b 427{
9900ba34 428 return vfs_dq_alloc_space(inode, nr << inode->i_blkbits);
03f6e92b
JK
429}
430
f18df228
MC
431static inline int vfs_dq_reserve_block(struct inode *inode, qsize_t nr)
432{
9900ba34 433 return vfs_dq_reserve_space(inode, nr << inode->i_blkbits);
f18df228
MC
434}
435
740d9dcd
MC
436static inline int vfs_dq_claim_block(struct inode *inode, qsize_t nr)
437{
9900ba34 438 return vfs_dq_claim_space(inode, nr << inode->i_blkbits);
740d9dcd
MC
439}
440
441static inline
442void vfs_dq_release_reservation_block(struct inode *inode, qsize_t nr)
443{
444 vfs_dq_release_reservation_space(inode, nr << inode->i_blkbits);
445}
446
b85f4b87 447static inline void vfs_dq_free_block_nodirty(struct inode *inode, qsize_t nr)
03f6e92b 448{
9900ba34 449 vfs_dq_free_space_nodirty(inode, nr << inode->i_blkbits);
03f6e92b
JK
450}
451
b85f4b87 452static inline void vfs_dq_free_block(struct inode *inode, qsize_t nr)
03f6e92b 453{
9900ba34 454 vfs_dq_free_space(inode, nr << inode->i_blkbits);
03f6e92b 455}
1da177e4
LT
456
457#endif /* _LINUX_QUOTAOPS_ */