2 * Definitions for diskquota-operations. When diskquota is configured these
3 * macros expand to the right source-code.
5 * Author: Marco van Wieringen <mvw@planets.elm.net>
7 #ifndef _LINUX_QUOTAOPS_
8 #define _LINUX_QUOTAOPS_
10 #include <linux/smp_lock.h>
13 static inline struct quota_info *sb_dqopt(struct super_block *sb)
18 #if defined(CONFIG_QUOTA)
21 * declaration of quota_function calls in kernel.
23 void sync_dquots(struct super_block *sb, int type);
25 int dquot_initialize(struct inode *inode, int type);
26 int dquot_drop(struct inode *inode);
27 int dquot_drop_locked(struct inode *inode);
28 struct dquot *dqget(struct super_block *sb, unsigned int id, int type);
29 void dqput(struct dquot *dquot);
30 int dquot_is_cached(struct super_block *sb, unsigned int id, int type);
31 int dquot_scan_active(struct super_block *sb,
32 int (*fn)(struct dquot *dquot, unsigned long priv),
34 struct dquot *dquot_alloc(struct super_block *sb, int type);
35 void dquot_destroy(struct dquot *dquot);
37 int dquot_alloc_space(struct inode *inode, qsize_t number, int prealloc);
38 int dquot_alloc_inode(const struct inode *inode, qsize_t number);
40 int dquot_free_space(struct inode *inode, qsize_t number);
41 int dquot_free_inode(const struct inode *inode, qsize_t number);
43 int dquot_transfer(struct inode *inode, struct iattr *iattr);
44 int dquot_commit(struct dquot *dquot);
45 int dquot_acquire(struct dquot *dquot);
46 int dquot_release(struct dquot *dquot);
47 int dquot_commit_info(struct super_block *sb, int type);
48 int dquot_mark_dquot_dirty(struct dquot *dquot);
50 int vfs_quota_on(struct super_block *sb, int type, int format_id,
51 char *path, int remount);
52 int vfs_quota_enable(struct inode *inode, int type, int format_id,
54 int vfs_quota_on_path(struct super_block *sb, int type, int format_id,
56 int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
57 int format_id, int type);
58 int vfs_quota_off(struct super_block *sb, int type, int remount);
59 int vfs_quota_disable(struct super_block *sb, int type, unsigned int flags);
60 int vfs_quota_sync(struct super_block *sb, int type);
61 int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
62 int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
63 int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
64 int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
66 void vfs_dq_drop(struct inode *inode);
67 int vfs_dq_transfer(struct inode *inode, struct iattr *iattr);
68 int vfs_dq_quota_on_remount(struct super_block *sb);
70 static inline struct mem_dqinfo *sb_dqinfo(struct super_block *sb, int type)
72 return sb_dqopt(sb)->info + type;
76 * Functions for checking status of quota
79 static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type)
81 return sb_dqopt(sb)->flags &
82 dquot_state_flag(DQUOT_USAGE_ENABLED, type);
85 static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type)
87 return sb_dqopt(sb)->flags &
88 dquot_state_flag(DQUOT_LIMITS_ENABLED, type);
91 static inline int sb_has_quota_suspended(struct super_block *sb, int type)
93 return sb_dqopt(sb)->flags &
94 dquot_state_flag(DQUOT_SUSPENDED, type);
97 static inline int sb_any_quota_suspended(struct super_block *sb)
99 return sb_has_quota_suspended(sb, USRQUOTA) ||
100 sb_has_quota_suspended(sb, GRPQUOTA);
103 /* Does kernel know about any quota information for given sb + type? */
104 static inline int sb_has_quota_loaded(struct super_block *sb, int type)
106 /* Currently if anything is on, then quota usage is on as well */
107 return sb_has_quota_usage_enabled(sb, type);
110 static inline int sb_any_quota_loaded(struct super_block *sb)
112 return sb_has_quota_loaded(sb, USRQUOTA) ||
113 sb_has_quota_loaded(sb, GRPQUOTA);
116 static inline int sb_has_quota_active(struct super_block *sb, int type)
118 return sb_has_quota_loaded(sb, type) &&
119 !sb_has_quota_suspended(sb, type);
122 static inline int sb_any_quota_active(struct super_block *sb)
124 return sb_has_quota_active(sb, USRQUOTA) ||
125 sb_has_quota_active(sb, GRPQUOTA);
129 * Operations supported for diskquotas.
131 extern struct dquot_operations dquot_operations;
132 extern struct quotactl_ops vfs_quotactl_ops;
134 #define sb_dquot_ops (&dquot_operations)
135 #define sb_quotactl_ops (&vfs_quotactl_ops)
137 /* It is better to call this function outside of any transaction as it might
138 * need a lot of space in journal for dquot structure allocation. */
139 static inline void vfs_dq_init(struct inode *inode)
141 BUG_ON(!inode->i_sb);
142 if (sb_any_quota_active(inode->i_sb) && !IS_NOQUOTA(inode))
143 inode->i_sb->dq_op->initialize(inode, -1);
146 /* The following allocation/freeing/transfer functions *must* be called inside
147 * a transaction (deadlocks possible otherwise) */
148 static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
150 if (sb_any_quota_active(inode->i_sb)) {
151 /* Used space is updated in alloc_space() */
152 if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
156 inode_add_bytes(inode, nr);
160 static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
163 if (!(ret = vfs_dq_prealloc_space_nodirty(inode, nr)))
164 mark_inode_dirty(inode);
168 static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
170 if (sb_any_quota_active(inode->i_sb)) {
171 /* Used space is updated in alloc_space() */
172 if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
176 inode_add_bytes(inode, nr);
180 static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
183 if (!(ret = vfs_dq_alloc_space_nodirty(inode, nr)))
184 mark_inode_dirty(inode);
188 static inline int vfs_dq_alloc_inode(struct inode *inode)
190 if (sb_any_quota_active(inode->i_sb)) {
192 if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
198 static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
200 if (sb_any_quota_active(inode->i_sb))
201 inode->i_sb->dq_op->free_space(inode, nr);
203 inode_sub_bytes(inode, nr);
206 static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
208 vfs_dq_free_space_nodirty(inode, nr);
209 mark_inode_dirty(inode);
212 static inline void vfs_dq_free_inode(struct inode *inode)
214 if (sb_any_quota_active(inode->i_sb))
215 inode->i_sb->dq_op->free_inode(inode, 1);
218 /* The following two functions cannot be called inside a transaction */
219 static inline void vfs_dq_sync(struct super_block *sb)
224 static inline int vfs_dq_off(struct super_block *sb, int remount)
228 if (sb->s_qcop && sb->s_qcop->quota_off)
229 ret = sb->s_qcop->quota_off(sb, -1, remount);
235 static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type)
240 static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type)
245 static inline int sb_has_quota_suspended(struct super_block *sb, int type)
250 static inline int sb_any_quota_suspended(struct super_block *sb)
255 /* Does kernel know about any quota information for given sb + type? */
256 static inline int sb_has_quota_loaded(struct super_block *sb, int type)
261 static inline int sb_any_quota_loaded(struct super_block *sb)
266 static inline int sb_has_quota_active(struct super_block *sb, int type)
271 static inline int sb_any_quota_active(struct super_block *sb)
277 * NO-OP when quota not configured.
279 #define sb_dquot_ops (NULL)
280 #define sb_quotactl_ops (NULL)
282 static inline void vfs_dq_init(struct inode *inode)
286 static inline void vfs_dq_drop(struct inode *inode)
290 static inline int vfs_dq_alloc_inode(struct inode *inode)
295 static inline void vfs_dq_free_inode(struct inode *inode)
299 static inline void vfs_dq_sync(struct super_block *sb)
303 static inline int vfs_dq_off(struct super_block *sb, int remount)
308 static inline int vfs_dq_quota_on_remount(struct super_block *sb)
313 static inline int vfs_dq_transfer(struct inode *inode, struct iattr *iattr)
318 static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
320 inode_add_bytes(inode, nr);
324 static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
326 vfs_dq_prealloc_space_nodirty(inode, nr);
327 mark_inode_dirty(inode);
331 static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
333 inode_add_bytes(inode, nr);
337 static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
339 vfs_dq_alloc_space_nodirty(inode, nr);
340 mark_inode_dirty(inode);
344 static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
346 inode_sub_bytes(inode, nr);
349 static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
351 vfs_dq_free_space_nodirty(inode, nr);
352 mark_inode_dirty(inode);
355 #endif /* CONFIG_QUOTA */
357 static inline int vfs_dq_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
359 return vfs_dq_prealloc_space_nodirty(inode,
360 nr << inode->i_sb->s_blocksize_bits);
363 static inline int vfs_dq_prealloc_block(struct inode *inode, qsize_t nr)
365 return vfs_dq_prealloc_space(inode,
366 nr << inode->i_sb->s_blocksize_bits);
369 static inline int vfs_dq_alloc_block_nodirty(struct inode *inode, qsize_t nr)
371 return vfs_dq_alloc_space_nodirty(inode,
372 nr << inode->i_sb->s_blocksize_bits);
375 static inline int vfs_dq_alloc_block(struct inode *inode, qsize_t nr)
377 return vfs_dq_alloc_space(inode,
378 nr << inode->i_sb->s_blocksize_bits);
381 static inline void vfs_dq_free_block_nodirty(struct inode *inode, qsize_t nr)
383 vfs_dq_free_space_nodirty(inode, nr << inode->i_sb->s_blocksize_bits);
386 static inline void vfs_dq_free_block(struct inode *inode, qsize_t nr)
388 vfs_dq_free_space(inode, nr << inode->i_sb->s_blocksize_bits);
392 * Define uppercase equivalents for compatibility with old function names
393 * Can go away when we think all users have been converted (15/04/2008)
395 #define DQUOT_INIT(inode) vfs_dq_init(inode)
396 #define DQUOT_DROP(inode) vfs_dq_drop(inode)
397 #define DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr) \
398 vfs_dq_prealloc_space_nodirty(inode, nr)
399 #define DQUOT_PREALLOC_SPACE(inode, nr) vfs_dq_prealloc_space(inode, nr)
400 #define DQUOT_ALLOC_SPACE_NODIRTY(inode, nr) \
401 vfs_dq_alloc_space_nodirty(inode, nr)
402 #define DQUOT_ALLOC_SPACE(inode, nr) vfs_dq_alloc_space(inode, nr)
403 #define DQUOT_PREALLOC_BLOCK_NODIRTY(inode, nr) \
404 vfs_dq_prealloc_block_nodirty(inode, nr)
405 #define DQUOT_PREALLOC_BLOCK(inode, nr) vfs_dq_prealloc_block(inode, nr)
406 #define DQUOT_ALLOC_BLOCK_NODIRTY(inode, nr) \
407 vfs_dq_alloc_block_nodirty(inode, nr)
408 #define DQUOT_ALLOC_BLOCK(inode, nr) vfs_dq_alloc_block(inode, nr)
409 #define DQUOT_ALLOC_INODE(inode) vfs_dq_alloc_inode(inode)
410 #define DQUOT_FREE_SPACE_NODIRTY(inode, nr) \
411 vfs_dq_free_space_nodirty(inode, nr)
412 #define DQUOT_FREE_SPACE(inode, nr) vfs_dq_free_space(inode, nr)
413 #define DQUOT_FREE_BLOCK_NODIRTY(inode, nr) \
414 vfs_dq_free_block_nodirty(inode, nr)
415 #define DQUOT_FREE_BLOCK(inode, nr) vfs_dq_free_block(inode, nr)
416 #define DQUOT_FREE_INODE(inode) vfs_dq_free_inode(inode)
417 #define DQUOT_TRANSFER(inode, iattr) vfs_dq_transfer(inode, iattr)
418 #define DQUOT_SYNC(sb) vfs_dq_sync(sb)
419 #define DQUOT_OFF(sb, remount) vfs_dq_off(sb, remount)
420 #define DQUOT_ON_REMOUNT(sb) vfs_dq_quota_on_remount(sb)
422 #endif /* _LINUX_QUOTAOPS_ */