quota: move function-macros from quota.h to quotaops.h
[linux-2.6/mini2440.git] / include / linux / quotaops.h
blob38218c1334b175d4c53740952f77f993ea91756c
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>
7 * Version: $Id: quotaops.h,v 1.2 1998/01/15 16:22:26 ecd Exp $
9 */
10 #ifndef _LINUX_QUOTAOPS_
11 #define _LINUX_QUOTAOPS_
13 #include <linux/smp_lock.h>
15 #include <linux/fs.h>
17 #define sb_dqopt(sb) (&(sb)->s_dquot)
19 #if defined(CONFIG_QUOTA)
22 * declaration of quota_function calls in kernel.
24 void sync_dquots(struct super_block *sb, int type);
26 int dquot_initialize(struct inode *inode, int type);
27 int dquot_drop(struct inode *inode);
29 int dquot_alloc_space(struct inode *inode, qsize_t number, int prealloc);
30 int dquot_alloc_inode(const struct inode *inode, unsigned long number);
32 int dquot_free_space(struct inode *inode, qsize_t number);
33 int dquot_free_inode(const struct inode *inode, unsigned long number);
35 int dquot_transfer(struct inode *inode, struct iattr *iattr);
36 int dquot_commit(struct dquot *dquot);
37 int dquot_acquire(struct dquot *dquot);
38 int dquot_release(struct dquot *dquot);
39 int dquot_commit_info(struct super_block *sb, int type);
40 int dquot_mark_dquot_dirty(struct dquot *dquot);
42 int vfs_quota_on(struct super_block *sb, int type, int format_id,
43 char *path, int remount);
44 int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
45 int format_id, int type);
46 int vfs_quota_off(struct super_block *sb, int type, int remount);
47 int vfs_quota_sync(struct super_block *sb, int type);
48 int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
49 int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
50 int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
51 int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
53 void vfs_dq_drop(struct inode *inode);
54 int vfs_dq_transfer(struct inode *inode, struct iattr *iattr);
55 int vfs_dq_quota_on_remount(struct super_block *sb);
57 #define sb_dqinfo(sb, type) (sb_dqopt(sb)->info+(type))
60 * Functions for checking status of quota
63 #define sb_has_quota_enabled(sb, type) ((type)==USRQUOTA ? \
64 (sb_dqopt(sb)->flags & DQUOT_USR_ENABLED) : (sb_dqopt(sb)->flags & DQUOT_GRP_ENABLED))
66 #define sb_any_quota_enabled(sb) (sb_has_quota_enabled(sb, USRQUOTA) | \
67 sb_has_quota_enabled(sb, GRPQUOTA))
69 #define sb_has_quota_suspended(sb, type) \
70 ((type) == USRQUOTA ? (sb_dqopt(sb)->flags & DQUOT_USR_SUSPENDED) : \
71 (sb_dqopt(sb)->flags & DQUOT_GRP_SUSPENDED))
73 #define sb_any_quota_suspended(sb) (sb_has_quota_suspended(sb, USRQUOTA) | \
74 sb_has_quota_suspended(sb, GRPQUOTA))
77 * Operations supported for diskquotas.
79 extern struct dquot_operations dquot_operations;
80 extern struct quotactl_ops vfs_quotactl_ops;
82 #define sb_dquot_ops (&dquot_operations)
83 #define sb_quotactl_ops (&vfs_quotactl_ops)
85 /* It is better to call this function outside of any transaction as it might
86 * need a lot of space in journal for dquot structure allocation. */
87 static inline void vfs_dq_init(struct inode *inode)
89 BUG_ON(!inode->i_sb);
90 if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode))
91 inode->i_sb->dq_op->initialize(inode, -1);
94 /* The following allocation/freeing/transfer functions *must* be called inside
95 * a transaction (deadlocks possible otherwise) */
96 static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
98 if (sb_any_quota_enabled(inode->i_sb)) {
99 /* Used space is updated in alloc_space() */
100 if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
101 return 1;
103 else
104 inode_add_bytes(inode, nr);
105 return 0;
108 static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
110 int ret;
111 if (!(ret = vfs_dq_prealloc_space_nodirty(inode, nr)))
112 mark_inode_dirty(inode);
113 return ret;
116 static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
118 if (sb_any_quota_enabled(inode->i_sb)) {
119 /* Used space is updated in alloc_space() */
120 if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
121 return 1;
123 else
124 inode_add_bytes(inode, nr);
125 return 0;
128 static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
130 int ret;
131 if (!(ret = vfs_dq_alloc_space_nodirty(inode, nr)))
132 mark_inode_dirty(inode);
133 return ret;
136 static inline int vfs_dq_alloc_inode(struct inode *inode)
138 if (sb_any_quota_enabled(inode->i_sb)) {
139 vfs_dq_init(inode);
140 if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
141 return 1;
143 return 0;
146 static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
148 if (sb_any_quota_enabled(inode->i_sb))
149 inode->i_sb->dq_op->free_space(inode, nr);
150 else
151 inode_sub_bytes(inode, nr);
154 static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
156 vfs_dq_free_space_nodirty(inode, nr);
157 mark_inode_dirty(inode);
160 static inline void vfs_dq_free_inode(struct inode *inode)
162 if (sb_any_quota_enabled(inode->i_sb))
163 inode->i_sb->dq_op->free_inode(inode, 1);
166 /* The following two functions cannot be called inside a transaction */
167 static inline void vfs_dq_sync(struct super_block *sb)
169 sync_dquots(sb, -1);
172 static inline int vfs_dq_off(struct super_block *sb, int remount)
174 int ret = -ENOSYS;
176 if (sb->s_qcop && sb->s_qcop->quota_off)
177 ret = sb->s_qcop->quota_off(sb, -1, remount);
178 return ret;
181 #else
183 #define sb_has_quota_enabled(sb, type) 0
184 #define sb_any_quota_enabled(sb) 0
185 #define sb_has_quota_suspended(sb, type) 0
186 #define sb_any_quota_suspended(sb) 0
189 * NO-OP when quota not configured.
191 #define sb_dquot_ops (NULL)
192 #define sb_quotactl_ops (NULL)
194 static inline void vfs_dq_init(struct inode *inode)
198 static inline void vfs_dq_drop(struct inode *inode)
202 static inline int vfs_dq_alloc_inode(struct inode *inode)
204 return 0;
207 static inline void vfs_dq_free_inode(struct inode *inode)
211 static inline void vfs_dq_sync(struct super_block *sb)
215 static inline int vfs_dq_off(struct super_block *sb, int remount)
217 return 0;
220 static inline int vfs_dq_quota_on_remount(struct super_block *sb)
222 return 0;
225 static inline int vfs_dq_transfer(struct inode *inode, struct iattr *iattr)
227 return 0;
230 static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
232 inode_add_bytes(inode, nr);
233 return 0;
236 static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
238 vfs_dq_prealloc_space_nodirty(inode, nr);
239 mark_inode_dirty(inode);
240 return 0;
243 static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
245 inode_add_bytes(inode, nr);
246 return 0;
249 static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
251 vfs_dq_alloc_space_nodirty(inode, nr);
252 mark_inode_dirty(inode);
253 return 0;
256 static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
258 inode_sub_bytes(inode, nr);
261 static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
263 vfs_dq_free_space_nodirty(inode, nr);
264 mark_inode_dirty(inode);
267 #endif /* CONFIG_QUOTA */
269 static inline int vfs_dq_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
271 return vfs_dq_prealloc_space_nodirty(inode,
272 nr << inode->i_sb->s_blocksize_bits);
275 static inline int vfs_dq_prealloc_block(struct inode *inode, qsize_t nr)
277 return vfs_dq_prealloc_space(inode,
278 nr << inode->i_sb->s_blocksize_bits);
281 static inline int vfs_dq_alloc_block_nodirty(struct inode *inode, qsize_t nr)
283 return vfs_dq_alloc_space_nodirty(inode,
284 nr << inode->i_sb->s_blocksize_bits);
287 static inline int vfs_dq_alloc_block(struct inode *inode, qsize_t nr)
289 return vfs_dq_alloc_space(inode,
290 nr << inode->i_sb->s_blocksize_bits);
293 static inline void vfs_dq_free_block_nodirty(struct inode *inode, qsize_t nr)
295 vfs_dq_free_space_nodirty(inode, nr << inode->i_sb->s_blocksize_bits);
298 static inline void vfs_dq_free_block(struct inode *inode, qsize_t nr)
300 vfs_dq_free_space(inode, nr << inode->i_sb->s_blocksize_bits);
304 * Define uppercase equivalents for compatibility with old function names
305 * Can go away when we think all users have been converted (15/04/2008)
307 #define DQUOT_INIT(inode) vfs_dq_init(inode)
308 #define DQUOT_DROP(inode) vfs_dq_drop(inode)
309 #define DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr) \
310 vfs_dq_prealloc_space_nodirty(inode, nr)
311 #define DQUOT_PREALLOC_SPACE(inode, nr) vfs_dq_prealloc_space(inode, nr)
312 #define DQUOT_ALLOC_SPACE_NODIRTY(inode, nr) \
313 vfs_dq_alloc_space_nodirty(inode, nr)
314 #define DQUOT_ALLOC_SPACE(inode, nr) vfs_dq_alloc_space(inode, nr)
315 #define DQUOT_PREALLOC_BLOCK_NODIRTY(inode, nr) \
316 vfs_dq_prealloc_block_nodirty(inode, nr)
317 #define DQUOT_PREALLOC_BLOCK(inode, nr) vfs_dq_prealloc_block(inode, nr)
318 #define DQUOT_ALLOC_BLOCK_NODIRTY(inode, nr) \
319 vfs_dq_alloc_block_nodirty(inode, nr)
320 #define DQUOT_ALLOC_BLOCK(inode, nr) vfs_dq_alloc_block(inode, nr)
321 #define DQUOT_ALLOC_INODE(inode) vfs_dq_alloc_inode(inode)
322 #define DQUOT_FREE_SPACE_NODIRTY(inode, nr) \
323 vfs_dq_free_space_nodirty(inode, nr)
324 #define DQUOT_FREE_SPACE(inode, nr) vfs_dq_free_space(inode, nr)
325 #define DQUOT_FREE_BLOCK_NODIRTY(inode, nr) \
326 vfs_dq_free_block_nodirty(inode, nr)
327 #define DQUOT_FREE_BLOCK(inode, nr) vfs_dq_free_block(inode, nr)
328 #define DQUOT_FREE_INODE(inode) vfs_dq_free_inode(inode)
329 #define DQUOT_TRANSFER(inode, iattr) vfs_dq_transfer(inode, iattr)
330 #define DQUOT_SYNC(sb) vfs_dq_sync(sb)
331 #define DQUOT_OFF(sb, remount) vfs_dq_off(sb, remount)
332 #define DQUOT_ON_REMOUNT(sb) vfs_dq_quota_on_remount(sb)
334 #endif /* _LINUX_QUOTAOPS_ */