quota: rename quota functions from upper case, make bigger ones non-inline
[pandora-kernel.git] / include / linux / quotaops.h
1 /*
2  * Definitions for diskquota-operations. When diskquota is configured these
3  * macros expand to the right source-code.
4  *
5  * Author:  Marco van Wieringen <mvw@planets.elm.net>
6  *
7  * Version: $Id: quotaops.h,v 1.2 1998/01/15 16:22:26 ecd Exp $
8  *
9  */
10 #ifndef _LINUX_QUOTAOPS_
11 #define _LINUX_QUOTAOPS_
12
13 #include <linux/smp_lock.h>
14
15 #include <linux/fs.h>
16
17 #if defined(CONFIG_QUOTA)
18
19 /*
20  * declaration of quota_function calls in kernel.
21  */
22 void sync_dquots(struct super_block *sb, int type);
23
24 int dquot_initialize(struct inode *inode, int type);
25 int dquot_drop(struct inode *inode);
26
27 int dquot_alloc_space(struct inode *inode, qsize_t number, int prealloc);
28 int dquot_alloc_inode(const struct inode *inode, unsigned long number);
29
30 int dquot_free_space(struct inode *inode, qsize_t number);
31 int dquot_free_inode(const struct inode *inode, unsigned long number);
32
33 int dquot_transfer(struct inode *inode, struct iattr *iattr);
34 int dquot_commit(struct dquot *dquot);
35 int dquot_acquire(struct dquot *dquot);
36 int dquot_release(struct dquot *dquot);
37 int dquot_commit_info(struct super_block *sb, int type);
38 int dquot_mark_dquot_dirty(struct dquot *dquot);
39
40 int vfs_quota_on(struct super_block *sb, int type, int format_id,
41         char *path, int remount);
42 int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
43         int format_id, int type);
44 int vfs_quota_off(struct super_block *sb, int type, int remount);
45 int vfs_quota_sync(struct super_block *sb, int type);
46 int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
47 int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
48 int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
49 int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
50
51 void vfs_dq_drop(struct inode *inode);
52 int vfs_dq_transfer(struct inode *inode, struct iattr *iattr);
53 int vfs_dq_quota_on_remount(struct super_block *sb);
54
55 /*
56  * Operations supported for diskquotas.
57  */
58 extern struct dquot_operations dquot_operations;
59 extern struct quotactl_ops vfs_quotactl_ops;
60
61 #define sb_dquot_ops (&dquot_operations)
62 #define sb_quotactl_ops (&vfs_quotactl_ops)
63
64 /* It is better to call this function outside of any transaction as it might
65  * need a lot of space in journal for dquot structure allocation. */
66 static inline void vfs_dq_init(struct inode *inode)
67 {
68         BUG_ON(!inode->i_sb);
69         if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode))
70                 inode->i_sb->dq_op->initialize(inode, -1);
71 }
72
73 /* The following allocation/freeing/transfer functions *must* be called inside
74  * a transaction (deadlocks possible otherwise) */
75 static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
76 {
77         if (sb_any_quota_enabled(inode->i_sb)) {
78                 /* Used space is updated in alloc_space() */
79                 if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
80                         return 1;
81         }
82         else
83                 inode_add_bytes(inode, nr);
84         return 0;
85 }
86
87 static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
88 {
89         int ret;
90         if (!(ret =  vfs_dq_prealloc_space_nodirty(inode, nr)))
91                 mark_inode_dirty(inode);
92         return ret;
93 }
94
95 static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
96 {
97         if (sb_any_quota_enabled(inode->i_sb)) {
98                 /* Used space is updated in alloc_space() */
99                 if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
100                         return 1;
101         }
102         else
103                 inode_add_bytes(inode, nr);
104         return 0;
105 }
106
107 static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
108 {
109         int ret;
110         if (!(ret = vfs_dq_alloc_space_nodirty(inode, nr)))
111                 mark_inode_dirty(inode);
112         return ret;
113 }
114
115 static inline int vfs_dq_alloc_inode(struct inode *inode)
116 {
117         if (sb_any_quota_enabled(inode->i_sb)) {
118                 vfs_dq_init(inode);
119                 if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
120                         return 1;
121         }
122         return 0;
123 }
124
125 static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
126 {
127         if (sb_any_quota_enabled(inode->i_sb))
128                 inode->i_sb->dq_op->free_space(inode, nr);
129         else
130                 inode_sub_bytes(inode, nr);
131 }
132
133 static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
134 {
135         vfs_dq_free_space_nodirty(inode, nr);
136         mark_inode_dirty(inode);
137 }
138
139 static inline void vfs_dq_free_inode(struct inode *inode)
140 {
141         if (sb_any_quota_enabled(inode->i_sb))
142                 inode->i_sb->dq_op->free_inode(inode, 1);
143 }
144
145 /* The following two functions cannot be called inside a transaction */
146 static inline void vfs_dq_sync(struct super_block *sb)
147 {
148         sync_dquots(sb, -1);
149 }
150
151 static inline int vfs_dq_off(struct super_block *sb, int remount)
152 {
153         int ret = -ENOSYS;
154
155         if (sb->s_qcop && sb->s_qcop->quota_off)
156                 ret = sb->s_qcop->quota_off(sb, -1, remount);
157         return ret;
158 }
159
160 #else
161
162 /*
163  * NO-OP when quota not configured.
164  */
165 #define sb_dquot_ops                            (NULL)
166 #define sb_quotactl_ops                         (NULL)
167
168 static inline void vfs_dq_init(struct inode *inode)
169 {
170 }
171
172 static inline void vfs_dq_drop(struct inode *inode)
173 {
174 }
175
176 static inline int vfs_dq_alloc_inode(struct inode *inode)
177 {
178         return 0;
179 }
180
181 static inline void vfs_dq_free_inode(struct inode *inode)
182 {
183 }
184
185 static inline void vfs_dq_sync(struct super_block *sb)
186 {
187 }
188
189 static inline int vfs_dq_off(struct super_block *sb, int remount)
190 {
191         return 0;
192 }
193
194 static inline int vfs_dq_quota_on_remount(struct super_block *sb)
195 {
196         return 0;
197 }
198
199 static inline int vfs_dq_transfer(struct inode *inode, struct iattr *iattr)
200 {
201         return 0;
202 }
203
204 static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
205 {
206         inode_add_bytes(inode, nr);
207         return 0;
208 }
209
210 static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
211 {
212         vfs_dq_prealloc_space_nodirty(inode, nr);
213         mark_inode_dirty(inode);
214         return 0;
215 }
216
217 static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
218 {
219         inode_add_bytes(inode, nr);
220         return 0;
221 }
222
223 static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
224 {
225         vfs_dq_alloc_space_nodirty(inode, nr);
226         mark_inode_dirty(inode);
227         return 0;
228 }
229
230 static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
231 {
232         inode_sub_bytes(inode, nr);
233 }
234
235 static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
236 {
237         vfs_dq_free_space_nodirty(inode, nr);
238         mark_inode_dirty(inode);
239 }       
240
241 #endif /* CONFIG_QUOTA */
242
243 static inline int vfs_dq_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
244 {
245         return vfs_dq_prealloc_space_nodirty(inode,
246                         nr << inode->i_sb->s_blocksize_bits);
247 }
248
249 static inline int vfs_dq_prealloc_block(struct inode *inode, qsize_t nr)
250 {
251         return vfs_dq_prealloc_space(inode,
252                         nr << inode->i_sb->s_blocksize_bits);
253 }
254
255 static inline int vfs_dq_alloc_block_nodirty(struct inode *inode, qsize_t nr)
256 {
257         return vfs_dq_alloc_space_nodirty(inode,
258                         nr << inode->i_sb->s_blocksize_bits);
259 }
260
261 static inline int vfs_dq_alloc_block(struct inode *inode, qsize_t nr)
262 {
263         return vfs_dq_alloc_space(inode,
264                         nr << inode->i_sb->s_blocksize_bits);
265 }
266
267 static inline void vfs_dq_free_block_nodirty(struct inode *inode, qsize_t nr)
268 {
269         vfs_dq_free_space_nodirty(inode, nr << inode->i_sb->s_blocksize_bits);
270 }
271
272 static inline void vfs_dq_free_block(struct inode *inode, qsize_t nr)
273 {
274         vfs_dq_free_space(inode, nr << inode->i_sb->s_blocksize_bits);
275 }
276
277 /*
278  * Define uppercase equivalents for compatibility with old function names
279  * Can go away when we think all users have been converted (15/04/2008)
280  */
281 #define DQUOT_INIT(inode) vfs_dq_init(inode)
282 #define DQUOT_DROP(inode) vfs_dq_drop(inode)
283 #define DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr) \
284                                 vfs_dq_prealloc_space_nodirty(inode, nr)
285 #define DQUOT_PREALLOC_SPACE(inode, nr) vfs_dq_prealloc_space(inode, nr)
286 #define DQUOT_ALLOC_SPACE_NODIRTY(inode, nr) \
287                                 vfs_dq_alloc_space_nodirty(inode, nr)
288 #define DQUOT_ALLOC_SPACE(inode, nr) vfs_dq_alloc_space(inode, nr)
289 #define DQUOT_PREALLOC_BLOCK_NODIRTY(inode, nr) \
290                                 vfs_dq_prealloc_block_nodirty(inode, nr)
291 #define DQUOT_PREALLOC_BLOCK(inode, nr) vfs_dq_prealloc_block(inode, nr)
292 #define DQUOT_ALLOC_BLOCK_NODIRTY(inode, nr) \
293                                 vfs_dq_alloc_block_nodirty(inode, nr)
294 #define DQUOT_ALLOC_BLOCK(inode, nr) vfs_dq_alloc_block(inode, nr)
295 #define DQUOT_ALLOC_INODE(inode) vfs_dq_alloc_inode(inode)
296 #define DQUOT_FREE_SPACE_NODIRTY(inode, nr) \
297                                 vfs_dq_free_space_nodirty(inode, nr)
298 #define DQUOT_FREE_SPACE(inode, nr) vfs_dq_free_space(inode, nr)
299 #define DQUOT_FREE_BLOCK_NODIRTY(inode, nr) \
300                                 vfs_dq_free_block_nodirty(inode, nr)
301 #define DQUOT_FREE_BLOCK(inode, nr) vfs_dq_free_block(inode, nr)
302 #define DQUOT_FREE_INODE(inode) vfs_dq_free_inode(inode)
303 #define DQUOT_TRANSFER(inode, iattr) vfs_dq_transfer(inode, iattr)
304 #define DQUOT_SYNC(sb) vfs_dq_sync(sb)
305 #define DQUOT_OFF(sb, remount) vfs_dq_off(sb, remount)
306 #define DQUOT_ON_REMOUNT(sb) vfs_dq_quota_on_remount(sb)
307
308 #endif /* _LINUX_QUOTAOPS_ */