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 struct dquot *dqget(struct super_block *sb, unsigned int id, int type);
28 void dqput(struct dquot *dquot);
29 int dquot_scan_active(struct super_block *sb,
30 int (*fn)(struct dquot *dquot, unsigned long priv),
32 struct dquot *dquot_alloc(struct super_block *sb, int type);
33 void dquot_destroy(struct dquot *dquot);
35 int dquot_alloc_space(struct inode *inode, qsize_t number, int prealloc);
36 int dquot_alloc_inode(const struct inode *inode, qsize_t number);
38 int dquot_reserve_space(struct inode *inode, qsize_t number, int prealloc);
39 int dquot_claim_space(struct inode *inode, qsize_t number);
40 void dquot_release_reserved_space(struct inode *inode, qsize_t number);
41 qsize_t dquot_get_reserved_space(struct inode *inode);
43 int dquot_free_space(struct inode *inode, qsize_t number);
44 int dquot_free_inode(const struct inode *inode, qsize_t number);
46 int dquot_transfer(struct inode *inode, struct iattr *iattr);
47 int dquot_commit(struct dquot *dquot);
48 int dquot_acquire(struct dquot *dquot);
49 int dquot_release(struct dquot *dquot);
50 int dquot_commit_info(struct super_block *sb, int type);
51 int dquot_mark_dquot_dirty(struct dquot *dquot);
53 int vfs_quota_on(struct super_block *sb, int type, int format_id,
54 char *path, int remount);
55 int vfs_quota_enable(struct inode *inode, int type, int format_id,
57 int vfs_quota_on_path(struct super_block *sb, int type, int format_id,
59 int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
60 int format_id, int type);
61 int vfs_quota_off(struct super_block *sb, int type, int remount);
62 int vfs_quota_disable(struct super_block *sb, int type, unsigned int flags);
63 int vfs_quota_sync(struct super_block *sb, int type);
64 int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
65 int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
66 int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
67 int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
69 void vfs_dq_drop(struct inode *inode);
70 int vfs_dq_transfer(struct inode *inode, struct iattr *iattr);
71 int vfs_dq_quota_on_remount(struct super_block *sb);
73 static inline struct mem_dqinfo *sb_dqinfo(struct super_block *sb, int type)
75 return sb_dqopt(sb)->info + type;
79 * Functions for checking status of quota
82 static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type)
84 return sb_dqopt(sb)->flags &
85 dquot_state_flag(DQUOT_USAGE_ENABLED, type);
88 static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type)
90 return sb_dqopt(sb)->flags &
91 dquot_state_flag(DQUOT_LIMITS_ENABLED, type);
94 static inline int sb_has_quota_suspended(struct super_block *sb, int type)
96 return sb_dqopt(sb)->flags &
97 dquot_state_flag(DQUOT_SUSPENDED, type);
100 static inline int sb_any_quota_suspended(struct super_block *sb)
102 return sb_has_quota_suspended(sb, USRQUOTA) ||
103 sb_has_quota_suspended(sb, GRPQUOTA);
106 /* Does kernel know about any quota information for given sb + type? */
107 static inline int sb_has_quota_loaded(struct super_block *sb, int type)
109 /* Currently if anything is on, then quota usage is on as well */
110 return sb_has_quota_usage_enabled(sb, type);
113 static inline int sb_any_quota_loaded(struct super_block *sb)
115 return sb_has_quota_loaded(sb, USRQUOTA) ||
116 sb_has_quota_loaded(sb, GRPQUOTA);
119 static inline int sb_has_quota_active(struct super_block *sb, int type)
121 return sb_has_quota_loaded(sb, type) &&
122 !sb_has_quota_suspended(sb, type);
125 static inline int sb_any_quota_active(struct super_block *sb)
127 return sb_has_quota_active(sb, USRQUOTA) ||
128 sb_has_quota_active(sb, GRPQUOTA);
132 * Operations supported for diskquotas.
134 extern struct dquot_operations dquot_operations;
135 extern struct quotactl_ops vfs_quotactl_ops;
137 #define sb_dquot_ops (&dquot_operations)
138 #define sb_quotactl_ops (&vfs_quotactl_ops)
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. */
142 static inline void vfs_dq_init(struct inode *inode)
144 BUG_ON(!inode->i_sb);
145 if (sb_any_quota_active(inode->i_sb) && !IS_NOQUOTA(inode))
146 inode->i_sb->dq_op->initialize(inode, -1);
149 /* The following allocation/freeing/transfer functions *must* be called inside
150 * a transaction (deadlocks possible otherwise) */
151 static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
153 if (sb_any_quota_active(inode->i_sb)) {
154 /* Used space is updated in alloc_space() */
155 if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
159 inode_add_bytes(inode, nr);
163 static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
166 if (!(ret = vfs_dq_prealloc_space_nodirty(inode, nr)))
167 mark_inode_dirty(inode);
171 static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
173 if (sb_any_quota_active(inode->i_sb)) {
174 /* Used space is updated in alloc_space() */
175 if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
179 inode_add_bytes(inode, nr);
183 static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
186 if (!(ret = vfs_dq_alloc_space_nodirty(inode, nr)))
187 mark_inode_dirty(inode);
191 static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
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)
201 static inline int vfs_dq_alloc_inode(struct inode *inode)
203 if (sb_any_quota_active(inode->i_sb)) {
205 if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
212 * Convert in-memory reserved quotas to real consumed quotas
214 static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
216 if (sb_any_quota_active(inode->i_sb)) {
217 if (inode->i_sb->dq_op->claim_space(inode, nr) == NO_QUOTA)
220 inode_add_bytes(inode, nr);
222 mark_inode_dirty(inode);
227 * Release reserved (in-memory) quotas
230 void vfs_dq_release_reservation_space(struct inode *inode, qsize_t nr)
232 if (sb_any_quota_active(inode->i_sb))
233 inode->i_sb->dq_op->release_rsv(inode, nr);
236 static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
238 if (sb_any_quota_active(inode->i_sb))
239 inode->i_sb->dq_op->free_space(inode, nr);
241 inode_sub_bytes(inode, nr);
244 static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
246 vfs_dq_free_space_nodirty(inode, nr);
247 mark_inode_dirty(inode);
250 static inline void vfs_dq_free_inode(struct inode *inode)
252 if (sb_any_quota_active(inode->i_sb))
253 inode->i_sb->dq_op->free_inode(inode, 1);
256 /* The following two functions cannot be called inside a transaction */
257 static inline void vfs_dq_sync(struct super_block *sb)
262 static inline int vfs_dq_off(struct super_block *sb, int remount)
266 if (sb->s_qcop && sb->s_qcop->quota_off)
267 ret = sb->s_qcop->quota_off(sb, -1, remount);
273 static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type)
278 static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type)
283 static inline int sb_has_quota_suspended(struct super_block *sb, int type)
288 static inline int sb_any_quota_suspended(struct super_block *sb)
293 /* Does kernel know about any quota information for given sb + type? */
294 static inline int sb_has_quota_loaded(struct super_block *sb, int type)
299 static inline int sb_any_quota_loaded(struct super_block *sb)
304 static inline int sb_has_quota_active(struct super_block *sb, int type)
309 static inline int sb_any_quota_active(struct super_block *sb)
315 * NO-OP when quota not configured.
317 #define sb_dquot_ops (NULL)
318 #define sb_quotactl_ops (NULL)
320 static inline void vfs_dq_init(struct inode *inode)
324 static inline void vfs_dq_drop(struct inode *inode)
328 static inline int vfs_dq_alloc_inode(struct inode *inode)
333 static inline void vfs_dq_free_inode(struct inode *inode)
337 static inline void vfs_dq_sync(struct super_block *sb)
341 static inline int vfs_dq_off(struct super_block *sb, int remount)
346 static inline int vfs_dq_quota_on_remount(struct super_block *sb)
351 static inline int vfs_dq_transfer(struct inode *inode, struct iattr *iattr)
356 static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
358 inode_add_bytes(inode, nr);
362 static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
364 vfs_dq_prealloc_space_nodirty(inode, nr);
365 mark_inode_dirty(inode);
369 static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
371 inode_add_bytes(inode, nr);
375 static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
377 vfs_dq_alloc_space_nodirty(inode, nr);
378 mark_inode_dirty(inode);
382 static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
387 static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
389 return vfs_dq_alloc_space(inode, nr);
393 int vfs_dq_release_reservation_space(struct inode *inode, qsize_t nr)
398 static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
400 inode_sub_bytes(inode, nr);
403 static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
405 vfs_dq_free_space_nodirty(inode, nr);
406 mark_inode_dirty(inode);
409 #endif /* CONFIG_QUOTA */
411 static inline int vfs_dq_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
413 return vfs_dq_prealloc_space_nodirty(inode, nr << inode->i_blkbits);
416 static inline int vfs_dq_prealloc_block(struct inode *inode, qsize_t nr)
418 return vfs_dq_prealloc_space(inode, nr << inode->i_blkbits);
421 static inline int vfs_dq_alloc_block_nodirty(struct inode *inode, qsize_t nr)
423 return vfs_dq_alloc_space_nodirty(inode, nr << inode->i_blkbits);
426 static inline int vfs_dq_alloc_block(struct inode *inode, qsize_t nr)
428 return vfs_dq_alloc_space(inode, nr << inode->i_blkbits);
431 static inline int vfs_dq_reserve_block(struct inode *inode, qsize_t nr)
433 return vfs_dq_reserve_space(inode, nr << inode->i_blkbits);
436 static inline int vfs_dq_claim_block(struct inode *inode, qsize_t nr)
438 return vfs_dq_claim_space(inode, nr << inode->i_blkbits);
442 void vfs_dq_release_reservation_block(struct inode *inode, qsize_t nr)
444 vfs_dq_release_reservation_space(inode, nr << inode->i_blkbits);
447 static inline void vfs_dq_free_block_nodirty(struct inode *inode, qsize_t nr)
449 vfs_dq_free_space_nodirty(inode, nr << inode->i_blkbits);
452 static inline void vfs_dq_free_block(struct inode *inode, qsize_t nr)
454 vfs_dq_free_space(inode, nr << inode->i_blkbits);
457 #endif /* _LINUX_QUOTAOPS_ */