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