quota: generalize quota transfer interface
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / linux / quotaops.h
blobe1cae204b5d9a0c10c4fb49f24de862fdba47749
1 /*
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>
6 */
7 #ifndef _LINUX_QUOTAOPS_
8 #define _LINUX_QUOTAOPS_
10 #include <linux/fs.h>
12 static inline struct quota_info *sb_dqopt(struct super_block *sb)
14 return &sb->s_dquot;
17 #if defined(CONFIG_QUOTA)
20 * declaration of quota_function calls in kernel.
22 void inode_add_rsv_space(struct inode *inode, qsize_t number);
23 void inode_claim_rsv_space(struct inode *inode, qsize_t number);
24 void inode_sub_rsv_space(struct inode *inode, qsize_t number);
26 int dquot_initialize(struct inode *inode, int type);
27 int dquot_drop(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_scan_active(struct super_block *sb,
31 int (*fn)(struct dquot *dquot, unsigned long priv),
32 unsigned long priv);
33 struct dquot *dquot_alloc(struct super_block *sb, int type);
34 void dquot_destroy(struct dquot *dquot);
36 int dquot_alloc_space(struct inode *inode, qsize_t number, int prealloc);
37 int dquot_alloc_inode(const struct inode *inode, qsize_t number);
39 int dquot_reserve_space(struct inode *inode, qsize_t number, int prealloc);
40 int dquot_claim_space(struct inode *inode, qsize_t number);
41 void dquot_release_reserved_space(struct inode *inode, qsize_t number);
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, qid_t *chid, unsigned long mask);
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,
56 unsigned int flags);
57 int vfs_quota_on_path(struct super_block *sb, int type, int format_id,
58 struct path *path);
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, int wait);
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 bool 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 bool 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 bool 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 unsigned sb_any_quota_suspended(struct super_block *sb)
102 unsigned type, tmsk = 0;
103 for (type = 0; type < MAXQUOTAS; type++)
104 tmsk |= sb_has_quota_suspended(sb, type) << type;
105 return tmsk;
108 /* Does kernel know about any quota information for given sb + type? */
109 static inline bool sb_has_quota_loaded(struct super_block *sb, int type)
111 /* Currently if anything is on, then quota usage is on as well */
112 return sb_has_quota_usage_enabled(sb, type);
115 static inline unsigned sb_any_quota_loaded(struct super_block *sb)
117 unsigned type, tmsk = 0;
118 for (type = 0; type < MAXQUOTAS; type++)
119 tmsk |= sb_has_quota_loaded(sb, type) << type;
120 return tmsk;
123 static inline bool sb_has_quota_active(struct super_block *sb, int type)
125 return sb_has_quota_loaded(sb, type) &&
126 !sb_has_quota_suspended(sb, type);
129 static inline unsigned sb_any_quota_active(struct super_block *sb)
131 return sb_any_quota_loaded(sb) & ~sb_any_quota_suspended(sb);
135 * Operations supported for diskquotas.
137 extern const struct dquot_operations dquot_operations;
138 extern const struct quotactl_ops vfs_quotactl_ops;
140 #define sb_dquot_ops (&dquot_operations)
141 #define sb_quotactl_ops (&vfs_quotactl_ops)
143 /* It is better to call this function outside of any transaction as it might
144 * need a lot of space in journal for dquot structure allocation. */
145 static inline void vfs_dq_init(struct inode *inode)
147 BUG_ON(!inode->i_sb);
148 if (sb_any_quota_active(inode->i_sb) && !IS_NOQUOTA(inode))
149 inode->i_sb->dq_op->initialize(inode, -1);
152 /* The following allocation/freeing/transfer functions *must* be called inside
153 * a transaction (deadlocks possible otherwise) */
154 static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
156 if (sb_any_quota_active(inode->i_sb)) {
157 /* Used space is updated in alloc_space() */
158 if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
159 return 1;
161 else
162 inode_add_bytes(inode, nr);
163 return 0;
166 static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
168 int ret;
169 if (!(ret = vfs_dq_prealloc_space_nodirty(inode, nr)))
170 mark_inode_dirty(inode);
171 return ret;
174 static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
176 if (sb_any_quota_active(inode->i_sb)) {
177 /* Used space is updated in alloc_space() */
178 if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
179 return 1;
181 else
182 inode_add_bytes(inode, nr);
183 return 0;
186 static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
188 int ret;
189 if (!(ret = vfs_dq_alloc_space_nodirty(inode, nr)))
190 mark_inode_dirty(inode);
191 return ret;
194 static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
196 if (sb_any_quota_active(inode->i_sb)) {
197 /* Used space is updated in alloc_space() */
198 if (inode->i_sb->dq_op->reserve_space(inode, nr, 0) == NO_QUOTA)
199 return 1;
201 else
202 inode_add_rsv_space(inode, nr);
203 return 0;
206 static inline int vfs_dq_alloc_inode(struct inode *inode)
208 if (sb_any_quota_active(inode->i_sb)) {
209 vfs_dq_init(inode);
210 if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
211 return 1;
213 return 0;
217 * Convert in-memory reserved quotas to real consumed quotas
219 static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
221 if (sb_any_quota_active(inode->i_sb)) {
222 if (inode->i_sb->dq_op->claim_space(inode, nr) == NO_QUOTA)
223 return 1;
224 } else
225 inode_claim_rsv_space(inode, nr);
227 mark_inode_dirty(inode);
228 return 0;
232 * Release reserved (in-memory) quotas
234 static inline
235 void vfs_dq_release_reservation_space(struct inode *inode, qsize_t nr)
237 if (sb_any_quota_active(inode->i_sb))
238 inode->i_sb->dq_op->release_rsv(inode, nr);
239 else
240 inode_sub_rsv_space(inode, nr);
243 static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
245 if (sb_any_quota_active(inode->i_sb))
246 inode->i_sb->dq_op->free_space(inode, nr);
247 else
248 inode_sub_bytes(inode, nr);
251 static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
253 vfs_dq_free_space_nodirty(inode, nr);
254 mark_inode_dirty(inode);
257 static inline void vfs_dq_free_inode(struct inode *inode)
259 if (sb_any_quota_active(inode->i_sb))
260 inode->i_sb->dq_op->free_inode(inode, 1);
263 /* Cannot be called inside a transaction */
264 static inline int vfs_dq_off(struct super_block *sb, int remount)
266 int ret = -ENOSYS;
268 if (sb->s_qcop && sb->s_qcop->quota_off)
269 ret = sb->s_qcop->quota_off(sb, -1, remount);
270 return ret;
273 #else
275 static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type)
277 return 0;
280 static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type)
282 return 0;
285 static inline int sb_has_quota_suspended(struct super_block *sb, int type)
287 return 0;
290 static inline int sb_any_quota_suspended(struct super_block *sb)
292 return 0;
295 /* Does kernel know about any quota information for given sb + type? */
296 static inline int sb_has_quota_loaded(struct super_block *sb, int type)
298 return 0;
301 static inline int sb_any_quota_loaded(struct super_block *sb)
303 return 0;
306 static inline int sb_has_quota_active(struct super_block *sb, int type)
308 return 0;
311 static inline int sb_any_quota_active(struct super_block *sb)
313 return 0;
317 * NO-OP when quota not configured.
319 #define sb_dquot_ops (NULL)
320 #define sb_quotactl_ops (NULL)
322 static inline void vfs_dq_init(struct inode *inode)
326 static inline void vfs_dq_drop(struct inode *inode)
330 static inline int vfs_dq_alloc_inode(struct inode *inode)
332 return 0;
335 static inline void vfs_dq_free_inode(struct inode *inode)
339 static inline int vfs_dq_off(struct super_block *sb, int remount)
341 return 0;
344 static inline int vfs_dq_quota_on_remount(struct super_block *sb)
346 return 0;
349 static inline int vfs_dq_transfer(struct inode *inode, struct iattr *iattr)
351 return 0;
354 static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
356 inode_add_bytes(inode, nr);
357 return 0;
360 static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
362 vfs_dq_prealloc_space_nodirty(inode, nr);
363 mark_inode_dirty(inode);
364 return 0;
367 static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
369 inode_add_bytes(inode, nr);
370 return 0;
373 static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
375 vfs_dq_alloc_space_nodirty(inode, nr);
376 mark_inode_dirty(inode);
377 return 0;
380 static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
382 return 0;
385 static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
387 return vfs_dq_alloc_space(inode, nr);
390 static inline
391 int vfs_dq_release_reservation_space(struct inode *inode, qsize_t nr)
393 return 0;
396 static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
398 inode_sub_bytes(inode, nr);
401 static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
403 vfs_dq_free_space_nodirty(inode, nr);
404 mark_inode_dirty(inode);
407 #endif /* CONFIG_QUOTA */
409 static inline int vfs_dq_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
411 return vfs_dq_prealloc_space_nodirty(inode, nr << inode->i_blkbits);
414 static inline int vfs_dq_prealloc_block(struct inode *inode, qsize_t nr)
416 return vfs_dq_prealloc_space(inode, nr << inode->i_blkbits);
419 static inline int vfs_dq_alloc_block_nodirty(struct inode *inode, qsize_t nr)
421 return vfs_dq_alloc_space_nodirty(inode, nr << inode->i_blkbits);
424 static inline int vfs_dq_alloc_block(struct inode *inode, qsize_t nr)
426 return vfs_dq_alloc_space(inode, nr << inode->i_blkbits);
429 static inline int vfs_dq_reserve_block(struct inode *inode, qsize_t nr)
431 return vfs_dq_reserve_space(inode, nr << inode->i_blkbits);
434 static inline int vfs_dq_claim_block(struct inode *inode, qsize_t nr)
436 return vfs_dq_claim_space(inode, nr << inode->i_blkbits);
439 static inline
440 void vfs_dq_release_reservation_block(struct inode *inode, qsize_t nr)
442 vfs_dq_release_reservation_space(inode, nr << inode->i_blkbits);
445 static inline void vfs_dq_free_block_nodirty(struct inode *inode, qsize_t nr)
447 vfs_dq_free_space_nodirty(inode, nr << inode->i_blkbits);
450 static inline void vfs_dq_free_block(struct inode *inode, qsize_t nr)
452 vfs_dq_free_space(inode, nr << inode->i_blkbits);
455 #endif /* _LINUX_QUOTAOPS_ */