quota: sb_quota state flags cleanup
[safe/jmp/linux-2.6] / 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 #ifndef _LINUX_QUOTAOPS_
8 #define _LINUX_QUOTAOPS_
9
10 #include <linux/fs.h>
11
12 static inline struct quota_info *sb_dqopt(struct super_block *sb)
13 {
14         return &sb->s_dquot;
15 }
16
17 #if defined(CONFIG_QUOTA)
18
19 /*
20  * declaration of quota_function calls in kernel.
21  */
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);
25
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);
35
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);
38
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);
42
43 int dquot_free_space(struct inode *inode, qsize_t number);
44 int dquot_free_inode(const struct inode *inode, qsize_t number);
45
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);
52
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);
68
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);
72
73 static inline struct mem_dqinfo *sb_dqinfo(struct super_block *sb, int type)
74 {
75         return sb_dqopt(sb)->info + type;
76 }
77
78 /*
79  * Functions for checking status of quota
80  */
81
82 static inline bool sb_has_quota_usage_enabled(struct super_block *sb, int type)
83 {
84         return sb_dqopt(sb)->flags &
85                                 dquot_state_flag(DQUOT_USAGE_ENABLED, type);
86 }
87
88 static inline bool sb_has_quota_limits_enabled(struct super_block *sb, int type)
89 {
90         return sb_dqopt(sb)->flags &
91                                 dquot_state_flag(DQUOT_LIMITS_ENABLED, type);
92 }
93
94 static inline bool sb_has_quota_suspended(struct super_block *sb, int type)
95 {
96         return sb_dqopt(sb)->flags &
97                                 dquot_state_flag(DQUOT_SUSPENDED, type);
98 }
99
100 static inline unsigned sb_any_quota_suspended(struct super_block *sb)
101 {
102         unsigned type, tmsk = 0;
103         for (type = 0; type < MAXQUOTAS; type++)
104                 tmsk |= sb_has_quota_suspended(sb, type) << type;
105         return tmsk;
106 }
107
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)
110 {
111         /* Currently if anything is on, then quota usage is on as well */
112         return sb_has_quota_usage_enabled(sb, type);
113 }
114
115 static inline unsigned sb_any_quota_loaded(struct super_block *sb)
116 {
117         unsigned type, tmsk = 0;
118         for (type = 0; type < MAXQUOTAS; type++)
119                 tmsk |= sb_has_quota_loaded(sb, type) << type;
120         return  tmsk;
121 }
122
123 static inline bool sb_has_quota_active(struct super_block *sb, int type)
124 {
125         return sb_has_quota_loaded(sb, type) &&
126                !sb_has_quota_suspended(sb, type);
127 }
128
129 static inline unsigned sb_any_quota_active(struct super_block *sb)
130 {
131         return sb_any_quota_loaded(sb) & ~sb_any_quota_suspended(sb);
132 }
133
134 /*
135  * Operations supported for diskquotas.
136  */
137 extern const struct dquot_operations dquot_operations;
138 extern const struct quotactl_ops vfs_quotactl_ops;
139
140 #define sb_dquot_ops (&dquot_operations)
141 #define sb_quotactl_ops (&vfs_quotactl_ops)
142
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)
146 {
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);
150 }
151
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)
155 {
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;
160         }
161         else
162                 inode_add_bytes(inode, nr);
163         return 0;
164 }
165
166 static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
167 {
168         int ret;
169         if (!(ret =  vfs_dq_prealloc_space_nodirty(inode, nr)))
170                 mark_inode_dirty(inode);
171         return ret;
172 }
173
174 static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
175 {
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;
180         }
181         else
182                 inode_add_bytes(inode, nr);
183         return 0;
184 }
185
186 static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
187 {
188         int ret;
189         if (!(ret = vfs_dq_alloc_space_nodirty(inode, nr)))
190                 mark_inode_dirty(inode);
191         return ret;
192 }
193
194 static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
195 {
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;
200         }
201         else
202                 inode_add_rsv_space(inode, nr);
203         return 0;
204 }
205
206 static inline int vfs_dq_alloc_inode(struct inode *inode)
207 {
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;
212         }
213         return 0;
214 }
215
216 /*
217  * Convert in-memory reserved quotas to real consumed quotas
218  */
219 static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
220 {
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);
226
227         mark_inode_dirty(inode);
228         return 0;
229 }
230
231 /*
232  * Release reserved (in-memory) quotas
233  */
234 static inline
235 void vfs_dq_release_reservation_space(struct inode *inode, qsize_t nr)
236 {
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);
241 }
242
243 static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
244 {
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);
249 }
250
251 static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
252 {
253         vfs_dq_free_space_nodirty(inode, nr);
254         mark_inode_dirty(inode);
255 }
256
257 static inline void vfs_dq_free_inode(struct inode *inode)
258 {
259         if (sb_any_quota_active(inode->i_sb))
260                 inode->i_sb->dq_op->free_inode(inode, 1);
261 }
262
263 /* Cannot be called inside a transaction */
264 static inline int vfs_dq_off(struct super_block *sb, int remount)
265 {
266         int ret = -ENOSYS;
267
268         if (sb->s_qcop && sb->s_qcop->quota_off)
269                 ret = sb->s_qcop->quota_off(sb, -1, remount);
270         return ret;
271 }
272
273 #else
274
275 static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type)
276 {
277         return 0;
278 }
279
280 static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type)
281 {
282         return 0;
283 }
284
285 static inline int sb_has_quota_suspended(struct super_block *sb, int type)
286 {
287         return 0;
288 }
289
290 static inline int sb_any_quota_suspended(struct super_block *sb)
291 {
292         return 0;
293 }
294
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)
297 {
298         return 0;
299 }
300
301 static inline int sb_any_quota_loaded(struct super_block *sb)
302 {
303         return 0;
304 }
305
306 static inline int sb_has_quota_active(struct super_block *sb, int type)
307 {
308         return 0;
309 }
310
311 static inline int sb_any_quota_active(struct super_block *sb)
312 {
313         return 0;
314 }
315
316 /*
317  * NO-OP when quota not configured.
318  */
319 #define sb_dquot_ops                            (NULL)
320 #define sb_quotactl_ops                         (NULL)
321
322 static inline void vfs_dq_init(struct inode *inode)
323 {
324 }
325
326 static inline void vfs_dq_drop(struct inode *inode)
327 {
328 }
329
330 static inline int vfs_dq_alloc_inode(struct inode *inode)
331 {
332         return 0;
333 }
334
335 static inline void vfs_dq_free_inode(struct inode *inode)
336 {
337 }
338
339 static inline int vfs_dq_off(struct super_block *sb, int remount)
340 {
341         return 0;
342 }
343
344 static inline int vfs_dq_quota_on_remount(struct super_block *sb)
345 {
346         return 0;
347 }
348
349 static inline int vfs_dq_transfer(struct inode *inode, struct iattr *iattr)
350 {
351         return 0;
352 }
353
354 static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
355 {
356         inode_add_bytes(inode, nr);
357         return 0;
358 }
359
360 static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
361 {
362         vfs_dq_prealloc_space_nodirty(inode, nr);
363         mark_inode_dirty(inode);
364         return 0;
365 }
366
367 static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
368 {
369         inode_add_bytes(inode, nr);
370         return 0;
371 }
372
373 static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
374 {
375         vfs_dq_alloc_space_nodirty(inode, nr);
376         mark_inode_dirty(inode);
377         return 0;
378 }
379
380 static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
381 {
382         return 0;
383 }
384
385 static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
386 {
387         return vfs_dq_alloc_space(inode, nr);
388 }
389
390 static inline
391 int vfs_dq_release_reservation_space(struct inode *inode, qsize_t nr)
392 {
393         return 0;
394 }
395
396 static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
397 {
398         inode_sub_bytes(inode, nr);
399 }
400
401 static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
402 {
403         vfs_dq_free_space_nodirty(inode, nr);
404         mark_inode_dirty(inode);
405 }       
406
407 #endif /* CONFIG_QUOTA */
408
409 static inline int vfs_dq_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
410 {
411         return vfs_dq_prealloc_space_nodirty(inode, nr << inode->i_blkbits);
412 }
413
414 static inline int vfs_dq_prealloc_block(struct inode *inode, qsize_t nr)
415 {
416         return vfs_dq_prealloc_space(inode, nr << inode->i_blkbits);
417 }
418
419 static inline int vfs_dq_alloc_block_nodirty(struct inode *inode, qsize_t nr)
420 {
421         return vfs_dq_alloc_space_nodirty(inode, nr << inode->i_blkbits);
422 }
423
424 static inline int vfs_dq_alloc_block(struct inode *inode, qsize_t nr)
425 {
426         return vfs_dq_alloc_space(inode, nr << inode->i_blkbits);
427 }
428
429 static inline int vfs_dq_reserve_block(struct inode *inode, qsize_t nr)
430 {
431         return vfs_dq_reserve_space(inode, nr << inode->i_blkbits);
432 }
433
434 static inline int vfs_dq_claim_block(struct inode *inode, qsize_t nr)
435 {
436         return vfs_dq_claim_space(inode, nr << inode->i_blkbits);
437 }
438
439 static inline
440 void vfs_dq_release_reservation_block(struct inode *inode, qsize_t nr)
441 {
442         vfs_dq_release_reservation_space(inode, nr << inode->i_blkbits);
443 }
444
445 static inline void vfs_dq_free_block_nodirty(struct inode *inode, qsize_t nr)
446 {
447         vfs_dq_free_space_nodirty(inode, nr << inode->i_blkbits);
448 }
449
450 static inline void vfs_dq_free_block(struct inode *inode, qsize_t nr)
451 {
452         vfs_dq_free_space(inode, nr << inode->i_blkbits);
453 }
454
455 #endif /* _LINUX_QUOTAOPS_ */