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