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);
28 int dquot_alloc_space(struct inode *inode, qsize_t number, int prealloc);
29 int dquot_alloc_inode(const struct inode *inode, qsize_t number);
31 int dquot_free_space(struct inode *inode, qsize_t number);
32 int dquot_free_inode(const struct inode *inode, qsize_t number);
34 int dquot_transfer(struct inode *inode, struct iattr *iattr);
35 int dquot_commit(struct dquot *dquot);
36 int dquot_acquire(struct dquot *dquot);
37 int dquot_release(struct dquot *dquot);
38 int dquot_commit_info(struct super_block *sb, int type);
39 int dquot_mark_dquot_dirty(struct dquot *dquot);
41 int vfs_quota_on(struct super_block *sb, int type, int format_id,
42 char *path, int remount);
43 int vfs_quota_enable(struct inode *inode, int type, int format_id,
45 int vfs_quota_on_path(struct super_block *sb, int type, int format_id,
47 int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
48 int format_id, int type);
49 int vfs_quota_off(struct super_block *sb, int type, int remount);
50 int vfs_quota_disable(struct super_block *sb, int type, unsigned int flags);
51 int vfs_quota_sync(struct super_block *sb, int type);
52 int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
53 int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
54 int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
55 int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
57 void vfs_dq_drop(struct inode *inode);
58 int vfs_dq_transfer(struct inode *inode, struct iattr *iattr);
59 int vfs_dq_quota_on_remount(struct super_block *sb);
61 static inline struct mem_dqinfo *sb_dqinfo(struct super_block *sb, int type)
63 return sb_dqopt(sb)->info + type;
67 * Functions for checking status of quota
70 static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type)
72 return sb_dqopt(sb)->flags &
73 dquot_state_flag(DQUOT_USAGE_ENABLED, type);
76 static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type)
78 return sb_dqopt(sb)->flags &
79 dquot_state_flag(DQUOT_LIMITS_ENABLED, type);
82 static inline int sb_has_quota_suspended(struct super_block *sb, int type)
84 return sb_dqopt(sb)->flags &
85 dquot_state_flag(DQUOT_SUSPENDED, type);
88 static inline int sb_any_quota_suspended(struct super_block *sb)
90 return sb_has_quota_suspended(sb, USRQUOTA) ||
91 sb_has_quota_suspended(sb, GRPQUOTA);
94 /* Does kernel know about any quota information for given sb + type? */
95 static inline int sb_has_quota_loaded(struct super_block *sb, int type)
97 /* Currently if anything is on, then quota usage is on as well */
98 return sb_has_quota_usage_enabled(sb, type);
101 static inline int sb_any_quota_loaded(struct super_block *sb)
103 return sb_has_quota_loaded(sb, USRQUOTA) ||
104 sb_has_quota_loaded(sb, GRPQUOTA);
107 static inline int sb_has_quota_active(struct super_block *sb, int type)
109 return sb_has_quota_loaded(sb, type) &&
110 !sb_has_quota_suspended(sb, type);
113 static inline int sb_any_quota_active(struct super_block *sb)
115 return sb_has_quota_active(sb, USRQUOTA) ||
116 sb_has_quota_active(sb, GRPQUOTA);
119 /* For backward compatibility until we remove all users */
120 #define sb_any_quota_enabled(sb) sb_any_quota_active(sb)
123 * Operations supported for diskquotas.
125 extern struct dquot_operations dquot_operations;
126 extern struct quotactl_ops vfs_quotactl_ops;
128 #define sb_dquot_ops (&dquot_operations)
129 #define sb_quotactl_ops (&vfs_quotactl_ops)
131 /* It is better to call this function outside of any transaction as it might
132 * need a lot of space in journal for dquot structure allocation. */
133 static inline void vfs_dq_init(struct inode *inode)
135 BUG_ON(!inode->i_sb);
136 if (sb_any_quota_active(inode->i_sb) && !IS_NOQUOTA(inode))
137 inode->i_sb->dq_op->initialize(inode, -1);
140 /* The following allocation/freeing/transfer functions *must* be called inside
141 * a transaction (deadlocks possible otherwise) */
142 static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
144 if (sb_any_quota_active(inode->i_sb)) {
145 /* Used space is updated in alloc_space() */
146 if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
150 inode_add_bytes(inode, nr);
154 static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
157 if (!(ret = vfs_dq_prealloc_space_nodirty(inode, nr)))
158 mark_inode_dirty(inode);
162 static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
164 if (sb_any_quota_active(inode->i_sb)) {
165 /* Used space is updated in alloc_space() */
166 if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
170 inode_add_bytes(inode, nr);
174 static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
177 if (!(ret = vfs_dq_alloc_space_nodirty(inode, nr)))
178 mark_inode_dirty(inode);
182 static inline int vfs_dq_alloc_inode(struct inode *inode)
184 if (sb_any_quota_active(inode->i_sb)) {
186 if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
192 static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
194 if (sb_any_quota_active(inode->i_sb))
195 inode->i_sb->dq_op->free_space(inode, nr);
197 inode_sub_bytes(inode, nr);
200 static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
202 vfs_dq_free_space_nodirty(inode, nr);
203 mark_inode_dirty(inode);
206 static inline void vfs_dq_free_inode(struct inode *inode)
208 if (sb_any_quota_active(inode->i_sb))
209 inode->i_sb->dq_op->free_inode(inode, 1);
212 /* The following two functions cannot be called inside a transaction */
213 static inline void vfs_dq_sync(struct super_block *sb)
218 static inline int vfs_dq_off(struct super_block *sb, int remount)
222 if (sb->s_qcop && sb->s_qcop->quota_off)
223 ret = sb->s_qcop->quota_off(sb, -1, remount);
229 static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type)
234 static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type)
239 static inline int sb_has_quota_suspended(struct super_block *sb, int type)
244 static inline int sb_any_quota_suspended(struct super_block *sb)
249 /* Does kernel know about any quota information for given sb + type? */
250 static inline int sb_has_quota_loaded(struct super_block *sb, int type)
255 static inline int sb_any_quota_loaded(struct super_block *sb)
260 static inline int sb_has_quota_active(struct super_block *sb, int type)
265 static inline int sb_any_quota_active(struct super_block *sb)
270 /* For backward compatibility until we remove all users */
271 #define sb_any_quota_enabled(sb) sb_any_quota_active(sb)
274 * NO-OP when quota not configured.
276 #define sb_dquot_ops (NULL)
277 #define sb_quotactl_ops (NULL)
279 static inline void vfs_dq_init(struct inode *inode)
283 static inline void vfs_dq_drop(struct inode *inode)
287 static inline int vfs_dq_alloc_inode(struct inode *inode)
292 static inline void vfs_dq_free_inode(struct inode *inode)
296 static inline void vfs_dq_sync(struct super_block *sb)
300 static inline int vfs_dq_off(struct super_block *sb, int remount)
305 static inline int vfs_dq_quota_on_remount(struct super_block *sb)
310 static inline int vfs_dq_transfer(struct inode *inode, struct iattr *iattr)
315 static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
317 inode_add_bytes(inode, nr);
321 static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
323 vfs_dq_prealloc_space_nodirty(inode, nr);
324 mark_inode_dirty(inode);
328 static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
330 inode_add_bytes(inode, nr);
334 static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
336 vfs_dq_alloc_space_nodirty(inode, nr);
337 mark_inode_dirty(inode);
341 static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
343 inode_sub_bytes(inode, nr);
346 static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
348 vfs_dq_free_space_nodirty(inode, nr);
349 mark_inode_dirty(inode);
352 #endif /* CONFIG_QUOTA */
354 static inline int vfs_dq_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
356 return vfs_dq_prealloc_space_nodirty(inode,
357 nr << inode->i_sb->s_blocksize_bits);
360 static inline int vfs_dq_prealloc_block(struct inode *inode, qsize_t nr)
362 return vfs_dq_prealloc_space(inode,
363 nr << inode->i_sb->s_blocksize_bits);
366 static inline int vfs_dq_alloc_block_nodirty(struct inode *inode, qsize_t nr)
368 return vfs_dq_alloc_space_nodirty(inode,
369 nr << inode->i_sb->s_blocksize_bits);
372 static inline int vfs_dq_alloc_block(struct inode *inode, qsize_t nr)
374 return vfs_dq_alloc_space(inode,
375 nr << inode->i_sb->s_blocksize_bits);
378 static inline void vfs_dq_free_block_nodirty(struct inode *inode, qsize_t nr)
380 vfs_dq_free_space_nodirty(inode, nr << inode->i_sb->s_blocksize_bits);
383 static inline void vfs_dq_free_block(struct inode *inode, qsize_t nr)
385 vfs_dq_free_space(inode, nr << inode->i_sb->s_blocksize_bits);
389 * Define uppercase equivalents for compatibility with old function names
390 * Can go away when we think all users have been converted (15/04/2008)
392 #define DQUOT_INIT(inode) vfs_dq_init(inode)
393 #define DQUOT_DROP(inode) vfs_dq_drop(inode)
394 #define DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr) \
395 vfs_dq_prealloc_space_nodirty(inode, nr)
396 #define DQUOT_PREALLOC_SPACE(inode, nr) vfs_dq_prealloc_space(inode, nr)
397 #define DQUOT_ALLOC_SPACE_NODIRTY(inode, nr) \
398 vfs_dq_alloc_space_nodirty(inode, nr)
399 #define DQUOT_ALLOC_SPACE(inode, nr) vfs_dq_alloc_space(inode, nr)
400 #define DQUOT_PREALLOC_BLOCK_NODIRTY(inode, nr) \
401 vfs_dq_prealloc_block_nodirty(inode, nr)
402 #define DQUOT_PREALLOC_BLOCK(inode, nr) vfs_dq_prealloc_block(inode, nr)
403 #define DQUOT_ALLOC_BLOCK_NODIRTY(inode, nr) \
404 vfs_dq_alloc_block_nodirty(inode, nr)
405 #define DQUOT_ALLOC_BLOCK(inode, nr) vfs_dq_alloc_block(inode, nr)
406 #define DQUOT_ALLOC_INODE(inode) vfs_dq_alloc_inode(inode)
407 #define DQUOT_FREE_SPACE_NODIRTY(inode, nr) \
408 vfs_dq_free_space_nodirty(inode, nr)
409 #define DQUOT_FREE_SPACE(inode, nr) vfs_dq_free_space(inode, nr)
410 #define DQUOT_FREE_BLOCK_NODIRTY(inode, nr) \
411 vfs_dq_free_block_nodirty(inode, nr)
412 #define DQUOT_FREE_BLOCK(inode, nr) vfs_dq_free_block(inode, nr)
413 #define DQUOT_FREE_INODE(inode) vfs_dq_free_inode(inode)
414 #define DQUOT_TRANSFER(inode, iattr) vfs_dq_transfer(inode, iattr)
415 #define DQUOT_SYNC(sb) vfs_dq_sync(sb)
416 #define DQUOT_OFF(sb, remount) vfs_dq_off(sb, remount)
417 #define DQUOT_ON_REMOUNT(sb) vfs_dq_quota_on_remount(sb)
419 #endif /* _LINUX_QUOTAOPS_ */