Line data Source code
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 sync_quota_sb(struct super_block *sb, int type);
23 : static inline void writeout_quota_sb(struct super_block *sb, int type)
24 : {
25 : if (sb->s_qcop->quota_sync)
26 : sb->s_qcop->quota_sync(sb, type);
27 : }
28 :
29 : void inode_add_rsv_space(struct inode *inode, qsize_t number);
30 : void inode_claim_rsv_space(struct inode *inode, qsize_t number);
31 : void inode_sub_rsv_space(struct inode *inode, qsize_t number);
32 :
33 : int dquot_initialize(struct inode *inode, int type);
34 : int dquot_drop(struct inode *inode);
35 : struct dquot *dqget(struct super_block *sb, unsigned int id, int type);
36 : void dqput(struct dquot *dquot);
37 : int dquot_scan_active(struct super_block *sb,
38 : int (*fn)(struct dquot *dquot, unsigned long priv),
39 : unsigned long priv);
40 : struct dquot *dquot_alloc(struct super_block *sb, int type);
41 : void dquot_destroy(struct dquot *dquot);
42 :
43 : int dquot_alloc_space(struct inode *inode, qsize_t number, int prealloc);
44 : int dquot_alloc_inode(const struct inode *inode, qsize_t number);
45 :
46 : int dquot_reserve_space(struct inode *inode, qsize_t number, int prealloc);
47 : int dquot_claim_space(struct inode *inode, qsize_t number);
48 : void dquot_release_reserved_space(struct inode *inode, qsize_t number);
49 :
50 : int dquot_free_space(struct inode *inode, qsize_t number);
51 : int dquot_free_inode(const struct inode *inode, qsize_t number);
52 :
53 : int dquot_transfer(struct inode *inode, struct iattr *iattr);
54 : int dquot_commit(struct dquot *dquot);
55 : int dquot_acquire(struct dquot *dquot);
56 : int dquot_release(struct dquot *dquot);
57 : int dquot_commit_info(struct super_block *sb, int type);
58 : int dquot_mark_dquot_dirty(struct dquot *dquot);
59 :
60 : int vfs_quota_on(struct super_block *sb, int type, int format_id,
61 : char *path, int remount);
62 : int vfs_quota_enable(struct inode *inode, int type, int format_id,
63 : unsigned int flags);
64 : int vfs_quota_on_path(struct super_block *sb, int type, int format_id,
65 : struct path *path);
66 : int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
67 : int format_id, int type);
68 : int vfs_quota_off(struct super_block *sb, int type, int remount);
69 : int vfs_quota_disable(struct super_block *sb, int type, unsigned int flags);
70 : int vfs_quota_sync(struct super_block *sb, int type);
71 : int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
72 : int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
73 : int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
74 : int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
75 :
76 : void vfs_dq_drop(struct inode *inode);
77 : int vfs_dq_transfer(struct inode *inode, struct iattr *iattr);
78 : int vfs_dq_quota_on_remount(struct super_block *sb);
79 :
80 : static inline struct mem_dqinfo *sb_dqinfo(struct super_block *sb, int type)
81 : {
82 : return sb_dqopt(sb)->info + type;
83 : }
84 :
85 : /*
86 : * Functions for checking status of quota
87 : */
88 :
89 : static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type)
90 : {
91 : return sb_dqopt(sb)->flags &
92 : dquot_state_flag(DQUOT_USAGE_ENABLED, type);
93 : }
94 :
95 : static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type)
96 : {
97 : return sb_dqopt(sb)->flags &
98 : dquot_state_flag(DQUOT_LIMITS_ENABLED, type);
99 : }
100 :
101 : static inline int sb_has_quota_suspended(struct super_block *sb, int type)
102 : {
103 : return sb_dqopt(sb)->flags &
104 : dquot_state_flag(DQUOT_SUSPENDED, type);
105 : }
106 :
107 : static inline int sb_any_quota_suspended(struct super_block *sb)
108 : {
109 : return sb_has_quota_suspended(sb, USRQUOTA) ||
110 : sb_has_quota_suspended(sb, GRPQUOTA);
111 : }
112 :
113 : /* Does kernel know about any quota information for given sb + type? */
114 : static inline int sb_has_quota_loaded(struct super_block *sb, int type)
115 : {
116 : /* Currently if anything is on, then quota usage is on as well */
117 : return sb_has_quota_usage_enabled(sb, type);
118 : }
119 :
120 : static inline int sb_any_quota_loaded(struct super_block *sb)
121 : {
122 : return sb_has_quota_loaded(sb, USRQUOTA) ||
123 : sb_has_quota_loaded(sb, GRPQUOTA);
124 : }
125 :
126 : static inline int sb_has_quota_active(struct super_block *sb, int type)
127 : {
128 : return sb_has_quota_loaded(sb, type) &&
129 : !sb_has_quota_suspended(sb, type);
130 : }
131 :
132 : static inline int sb_any_quota_active(struct super_block *sb)
133 : {
134 : return sb_has_quota_active(sb, USRQUOTA) ||
135 : sb_has_quota_active(sb, GRPQUOTA);
136 : }
137 :
138 : /*
139 : * Operations supported for diskquotas.
140 : */
141 : extern const struct dquot_operations dquot_operations;
142 : extern const struct quotactl_ops vfs_quotactl_ops;
143 :
144 : #define sb_dquot_ops (&dquot_operations)
145 : #define sb_quotactl_ops (&vfs_quotactl_ops)
146 :
147 : /* It is better to call this function outside of any transaction as it might
148 : * need a lot of space in journal for dquot structure allocation. */
149 : static inline void vfs_dq_init(struct inode *inode)
150 : {
151 : BUG_ON(!inode->i_sb);
152 : if (sb_any_quota_active(inode->i_sb) && !IS_NOQUOTA(inode))
153 : inode->i_sb->dq_op->initialize(inode, -1);
154 : }
155 :
156 : /* The following allocation/freeing/transfer functions *must* be called inside
157 : * a transaction (deadlocks possible otherwise) */
158 : static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
159 : {
160 : if (sb_any_quota_active(inode->i_sb)) {
161 : /* Used space is updated in alloc_space() */
162 : if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
163 : return 1;
164 : }
165 : else
166 : inode_add_bytes(inode, nr);
167 : return 0;
168 : }
169 :
170 : static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
171 : {
172 : int ret;
173 : if (!(ret = vfs_dq_prealloc_space_nodirty(inode, nr)))
174 : mark_inode_dirty(inode);
175 : return ret;
176 : }
177 :
178 : static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
179 : {
180 : if (sb_any_quota_active(inode->i_sb)) {
181 : /* Used space is updated in alloc_space() */
182 : if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
183 : return 1;
184 : }
185 : else
186 : inode_add_bytes(inode, nr);
187 : return 0;
188 : }
189 :
190 : static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
191 : {
192 : int ret;
193 : if (!(ret = vfs_dq_alloc_space_nodirty(inode, nr)))
194 : mark_inode_dirty(inode);
195 : return ret;
196 : }
197 :
198 : static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
199 : {
200 : if (sb_any_quota_active(inode->i_sb)) {
201 : /* Used space is updated in alloc_space() */
202 : if (inode->i_sb->dq_op->reserve_space(inode, nr, 0) == NO_QUOTA)
203 : return 1;
204 : }
205 : else
206 : inode_add_rsv_space(inode, nr);
207 : return 0;
208 : }
209 :
210 : static inline int vfs_dq_alloc_inode(struct inode *inode)
211 : {
212 : if (sb_any_quota_active(inode->i_sb)) {
213 : vfs_dq_init(inode);
214 : if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
215 : return 1;
216 : }
217 : return 0;
218 : }
219 :
220 : /*
221 : * Convert in-memory reserved quotas to real consumed quotas
222 : */
223 : static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
224 : {
225 : if (sb_any_quota_active(inode->i_sb)) {
226 : if (inode->i_sb->dq_op->claim_space(inode, nr) == NO_QUOTA)
227 : return 1;
228 : } else
229 : inode_claim_rsv_space(inode, nr);
230 :
231 : mark_inode_dirty(inode);
232 : return 0;
233 : }
234 :
235 : /*
236 : * Release reserved (in-memory) quotas
237 : */
238 : static inline
239 : void vfs_dq_release_reservation_space(struct inode *inode, qsize_t nr)
240 : {
241 : if (sb_any_quota_active(inode->i_sb))
242 : inode->i_sb->dq_op->release_rsv(inode, nr);
243 : else
244 : inode_sub_rsv_space(inode, nr);
245 : }
246 :
247 : static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
248 : {
249 : if (sb_any_quota_active(inode->i_sb))
250 : inode->i_sb->dq_op->free_space(inode, nr);
251 : else
252 : inode_sub_bytes(inode, nr);
253 : }
254 :
255 : static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
256 : {
257 : vfs_dq_free_space_nodirty(inode, nr);
258 : mark_inode_dirty(inode);
259 : }
260 :
261 : static inline void vfs_dq_free_inode(struct inode *inode)
262 : {
263 : if (sb_any_quota_active(inode->i_sb))
264 : inode->i_sb->dq_op->free_inode(inode, 1);
265 : }
266 :
267 : /* Cannot be called inside a transaction */
268 : static inline int vfs_dq_off(struct super_block *sb, int remount)
269 : {
270 : int ret = -ENOSYS;
271 :
272 : if (sb->s_qcop && sb->s_qcop->quota_off)
273 : ret = sb->s_qcop->quota_off(sb, -1, remount);
274 : return ret;
275 : }
276 :
277 : #else
278 :
279 : static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type)
280 : {
281 : return 0;
282 : }
283 :
284 : static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type)
285 : {
286 : return 0;
287 : }
288 :
289 : static inline int sb_has_quota_suspended(struct super_block *sb, int type)
290 : {
291 : return 0;
292 : }
293 :
294 : static inline int sb_any_quota_suspended(struct super_block *sb)
295 : {
296 : return 0;
297 : }
298 :
299 : /* Does kernel know about any quota information for given sb + type? */
300 : static inline int sb_has_quota_loaded(struct super_block *sb, int type)
301 : {
302 : return 0;
303 : }
304 :
305 : static inline int sb_any_quota_loaded(struct super_block *sb)
306 : {
307 : return 0;
308 : }
309 :
310 : static inline int sb_has_quota_active(struct super_block *sb, int type)
311 : {
312 : return 0;
313 : }
314 :
315 : static inline int sb_any_quota_active(struct super_block *sb)
316 : {
317 : return 0;
318 : }
319 :
320 : /*
321 : * NO-OP when quota not configured.
322 : */
323 : #define sb_dquot_ops (NULL)
324 : #define sb_quotactl_ops (NULL)
325 :
326 : static inline void vfs_dq_init(struct inode *inode)
327 : {
328 : }
329 :
330 : static inline void vfs_dq_drop(struct inode *inode)
331 : {
332 84 : }
333 :
334 : static inline int vfs_dq_alloc_inode(struct inode *inode)
335 : {
336 24 : return 0;
337 : }
338 :
339 : static inline void vfs_dq_free_inode(struct inode *inode)
340 : {
341 : }
342 :
343 : static inline void sync_quota_sb(struct super_block *sb, int type)
344 : {
345 : }
346 :
347 : static inline void writeout_quota_sb(struct super_block *sb, int type)
348 : {
349 : }
350 :
351 : static inline int vfs_dq_off(struct super_block *sb, int remount)
352 : {
353 : return 0;
354 : }
355 :
356 : static inline int vfs_dq_quota_on_remount(struct super_block *sb)
357 : {
358 : return 0;
359 : }
360 :
361 : static inline int vfs_dq_transfer(struct inode *inode, struct iattr *iattr)
362 : {
363 4 : return 0;
364 : }
365 :
366 : static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
367 : {
368 : inode_add_bytes(inode, nr);
369 : return 0;
370 : }
371 :
372 : static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
373 : {
374 : vfs_dq_prealloc_space_nodirty(inode, nr);
375 : mark_inode_dirty(inode);
376 : return 0;
377 : }
378 :
379 : static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
380 : {
381 200 : inode_add_bytes(inode, nr);
382 200 : return 0;
383 : }
384 :
385 : static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
386 : {
387 400 : vfs_dq_alloc_space_nodirty(inode, nr);
388 400 : mark_inode_dirty(inode);
389 200 : return 0;
390 : }
391 :
392 : static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
393 : {
394 : return 0;
395 : }
396 :
397 : static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
398 : {
399 : return vfs_dq_alloc_space(inode, nr);
400 : }
401 :
402 : static inline
403 : int vfs_dq_release_reservation_space(struct inode *inode, qsize_t nr)
404 : {
405 : return 0;
406 : }
407 :
408 : static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
409 : {
410 1304 : inode_sub_bytes(inode, nr);
411 1304 : }
412 :
413 : static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
414 : {
415 2608 : vfs_dq_free_space_nodirty(inode, nr);
416 2608 : mark_inode_dirty(inode);
417 1304 : }
418 :
419 : #endif /* CONFIG_QUOTA */
420 :
421 : static inline int vfs_dq_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
422 : {
423 : return vfs_dq_prealloc_space_nodirty(inode, nr << inode->i_blkbits);
424 : }
425 :
426 : static inline int vfs_dq_prealloc_block(struct inode *inode, qsize_t nr)
427 : {
428 : return vfs_dq_prealloc_space(inode, nr << inode->i_blkbits);
429 : }
430 :
431 : static inline int vfs_dq_alloc_block_nodirty(struct inode *inode, qsize_t nr)
432 : {
433 : return vfs_dq_alloc_space_nodirty(inode, nr << inode->i_blkbits);
434 : }
435 :
436 : static inline int vfs_dq_alloc_block(struct inode *inode, qsize_t nr)
437 : {
438 1000 : return vfs_dq_alloc_space(inode, nr << inode->i_blkbits);
439 : }
440 :
441 : static inline int vfs_dq_reserve_block(struct inode *inode, qsize_t nr)
442 : {
443 : return vfs_dq_reserve_space(inode, nr << inode->i_blkbits);
444 : }
445 :
446 : static inline int vfs_dq_claim_block(struct inode *inode, qsize_t nr)
447 : {
448 : return vfs_dq_claim_space(inode, nr << inode->i_blkbits);
449 : }
450 :
451 : static inline
452 : void vfs_dq_release_reservation_block(struct inode *inode, qsize_t nr)
453 : {
454 : vfs_dq_release_reservation_space(inode, nr << inode->i_blkbits);
455 : }
456 :
457 : static inline void vfs_dq_free_block_nodirty(struct inode *inode, qsize_t nr)
458 : {
459 : vfs_dq_free_space_nodirty(inode, nr << inode->i_blkbits);
460 : }
461 :
462 : static inline void vfs_dq_free_block(struct inode *inode, qsize_t nr)
463 : {
464 3912 : vfs_dq_free_space(inode, nr << inode->i_blkbits);
465 1304 : }
466 1 :
467 : #endif /* _LINUX_QUOTAOPS_ */
|