]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - include/linux/quotaops.h
38218c1334b175d4c53740952f77f993ea91756c
[linux-2.6-omap-h63xx.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 #define sb_dqopt(sb) (&(sb)->s_dquot)
18
19 #if defined(CONFIG_QUOTA)
20
21 /*
22  * declaration of quota_function calls in kernel.
23  */
24 void sync_dquots(struct super_block *sb, int type);
25
26 int dquot_initialize(struct inode *inode, int type);
27 int dquot_drop(struct inode *inode);
28
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);
31
32 int dquot_free_space(struct inode *inode, qsize_t number);
33 int dquot_free_inode(const struct inode *inode, unsigned long number);
34
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);
41
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);
52
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);
56
57 #define sb_dqinfo(sb, type) (sb_dqopt(sb)->info+(type))
58
59 /*
60  * Functions for checking status of quota
61  */
62
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))
65
66 #define sb_any_quota_enabled(sb) (sb_has_quota_enabled(sb, USRQUOTA) | \
67                                   sb_has_quota_enabled(sb, GRPQUOTA))
68
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))
72
73 #define sb_any_quota_suspended(sb) (sb_has_quota_suspended(sb, USRQUOTA) | \
74                                   sb_has_quota_suspended(sb, GRPQUOTA))
75
76 /*
77  * Operations supported for diskquotas.
78  */
79 extern struct dquot_operations dquot_operations;
80 extern struct quotactl_ops vfs_quotactl_ops;
81
82 #define sb_dquot_ops (&dquot_operations)
83 #define sb_quotactl_ops (&vfs_quotactl_ops)
84
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)
88 {
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);
92 }
93
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)
97 {
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;
102         }
103         else
104                 inode_add_bytes(inode, nr);
105         return 0;
106 }
107
108 static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
109 {
110         int ret;
111         if (!(ret =  vfs_dq_prealloc_space_nodirty(inode, nr)))
112                 mark_inode_dirty(inode);
113         return ret;
114 }
115
116 static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
117 {
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;
122         }
123         else
124                 inode_add_bytes(inode, nr);
125         return 0;
126 }
127
128 static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
129 {
130         int ret;
131         if (!(ret = vfs_dq_alloc_space_nodirty(inode, nr)))
132                 mark_inode_dirty(inode);
133         return ret;
134 }
135
136 static inline int vfs_dq_alloc_inode(struct inode *inode)
137 {
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;
142         }
143         return 0;
144 }
145
146 static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
147 {
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);
152 }
153
154 static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
155 {
156         vfs_dq_free_space_nodirty(inode, nr);
157         mark_inode_dirty(inode);
158 }
159
160 static inline void vfs_dq_free_inode(struct inode *inode)
161 {
162         if (sb_any_quota_enabled(inode->i_sb))
163                 inode->i_sb->dq_op->free_inode(inode, 1);
164 }
165
166 /* The following two functions cannot be called inside a transaction */
167 static inline void vfs_dq_sync(struct super_block *sb)
168 {
169         sync_dquots(sb, -1);
170 }
171
172 static inline int vfs_dq_off(struct super_block *sb, int remount)
173 {
174         int ret = -ENOSYS;
175
176         if (sb->s_qcop && sb->s_qcop->quota_off)
177                 ret = sb->s_qcop->quota_off(sb, -1, remount);
178         return ret;
179 }
180
181 #else
182
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
187
188 /*
189  * NO-OP when quota not configured.
190  */
191 #define sb_dquot_ops                            (NULL)
192 #define sb_quotactl_ops                         (NULL)
193
194 static inline void vfs_dq_init(struct inode *inode)
195 {
196 }
197
198 static inline void vfs_dq_drop(struct inode *inode)
199 {
200 }
201
202 static inline int vfs_dq_alloc_inode(struct inode *inode)
203 {
204         return 0;
205 }
206
207 static inline void vfs_dq_free_inode(struct inode *inode)
208 {
209 }
210
211 static inline void vfs_dq_sync(struct super_block *sb)
212 {
213 }
214
215 static inline int vfs_dq_off(struct super_block *sb, int remount)
216 {
217         return 0;
218 }
219
220 static inline int vfs_dq_quota_on_remount(struct super_block *sb)
221 {
222         return 0;
223 }
224
225 static inline int vfs_dq_transfer(struct inode *inode, struct iattr *iattr)
226 {
227         return 0;
228 }
229
230 static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
231 {
232         inode_add_bytes(inode, nr);
233         return 0;
234 }
235
236 static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
237 {
238         vfs_dq_prealloc_space_nodirty(inode, nr);
239         mark_inode_dirty(inode);
240         return 0;
241 }
242
243 static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
244 {
245         inode_add_bytes(inode, nr);
246         return 0;
247 }
248
249 static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
250 {
251         vfs_dq_alloc_space_nodirty(inode, nr);
252         mark_inode_dirty(inode);
253         return 0;
254 }
255
256 static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
257 {
258         inode_sub_bytes(inode, nr);
259 }
260
261 static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
262 {
263         vfs_dq_free_space_nodirty(inode, nr);
264         mark_inode_dirty(inode);
265 }       
266
267 #endif /* CONFIG_QUOTA */
268
269 static inline int vfs_dq_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
270 {
271         return vfs_dq_prealloc_space_nodirty(inode,
272                         nr << inode->i_sb->s_blocksize_bits);
273 }
274
275 static inline int vfs_dq_prealloc_block(struct inode *inode, qsize_t nr)
276 {
277         return vfs_dq_prealloc_space(inode,
278                         nr << inode->i_sb->s_blocksize_bits);
279 }
280
281 static inline int vfs_dq_alloc_block_nodirty(struct inode *inode, qsize_t nr)
282 {
283         return vfs_dq_alloc_space_nodirty(inode,
284                         nr << inode->i_sb->s_blocksize_bits);
285 }
286
287 static inline int vfs_dq_alloc_block(struct inode *inode, qsize_t nr)
288 {
289         return vfs_dq_alloc_space(inode,
290                         nr << inode->i_sb->s_blocksize_bits);
291 }
292
293 static inline void vfs_dq_free_block_nodirty(struct inode *inode, qsize_t nr)
294 {
295         vfs_dq_free_space_nodirty(inode, nr << inode->i_sb->s_blocksize_bits);
296 }
297
298 static inline void vfs_dq_free_block(struct inode *inode, qsize_t nr)
299 {
300         vfs_dq_free_space(inode, nr << inode->i_sb->s_blocksize_bits);
301 }
302
303 /*
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)
306  */
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)
333
334 #endif /* _LINUX_QUOTAOPS_ */