Commit | Line | Data |
---|---|---|
1da177e4 LT |
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> | |
1da177e4 LT |
6 | */ |
7 | #ifndef _LINUX_QUOTAOPS_ | |
8 | #define _LINUX_QUOTAOPS_ | |
9 | ||
1da177e4 LT |
10 | #include <linux/fs.h> |
11 | ||
03b06343 JK |
12 | static inline struct quota_info *sb_dqopt(struct super_block *sb) |
13 | { | |
14 | return &sb->s_dquot; | |
15 | } | |
74abb989 | 16 | |
1da177e4 LT |
17 | #if defined(CONFIG_QUOTA) |
18 | ||
19 | /* | |
20 | * declaration of quota_function calls in kernel. | |
21 | */ | |
850b201b | 22 | void sync_quota_sb(struct super_block *sb, int type); |
c3f8a40c JK |
23 | static inline void writeout_quota_sb(struct super_block *sb, int type) |
24 | { | |
8c4e4acd | 25 | if (sb->s_qcop && sb->s_qcop->quota_sync) |
c3f8a40c JK |
26 | sb->s_qcop->quota_sync(sb, type); |
27 | } | |
b85f4b87 | 28 | |
c469070a DM |
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 | ||
b85f4b87 JK |
33 | int dquot_initialize(struct inode *inode, int type); |
34 | int dquot_drop(struct inode *inode); | |
3d9ea253 JK |
35 | struct dquot *dqget(struct super_block *sb, unsigned int id, int type); |
36 | void dqput(struct dquot *dquot); | |
12c77527 JK |
37 | int dquot_scan_active(struct super_block *sb, |
38 | int (*fn)(struct dquot *dquot, unsigned long priv), | |
39 | unsigned long priv); | |
7d9056ba JK |
40 | struct dquot *dquot_alloc(struct super_block *sb, int type); |
41 | void dquot_destroy(struct dquot *dquot); | |
b85f4b87 JK |
42 | |
43 | int dquot_alloc_space(struct inode *inode, qsize_t number, int prealloc); | |
12095460 | 44 | int dquot_alloc_inode(const struct inode *inode, qsize_t number); |
b85f4b87 | 45 | |
740d9dcd MC |
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); | |
740d9dcd | 49 | |
b85f4b87 | 50 | int dquot_free_space(struct inode *inode, qsize_t number); |
12095460 | 51 | int dquot_free_inode(const struct inode *inode, qsize_t number); |
b85f4b87 JK |
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); | |
f55abc0f JK |
62 | int vfs_quota_enable(struct inode *inode, int type, int format_id, |
63 | unsigned int flags); | |
77e69dac AV |
64 | int vfs_quota_on_path(struct super_block *sb, int type, int format_id, |
65 | struct path *path); | |
b85f4b87 JK |
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); | |
f55abc0f | 69 | int vfs_quota_disable(struct super_block *sb, int type, unsigned int flags); |
b85f4b87 JK |
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); | |
1da177e4 | 79 | |
03b06343 JK |
80 | static inline struct mem_dqinfo *sb_dqinfo(struct super_block *sb, int type) |
81 | { | |
82 | return sb_dqopt(sb)->info + type; | |
83 | } | |
74abb989 JK |
84 | |
85 | /* | |
86 | * Functions for checking status of quota | |
87 | */ | |
88 | ||
f55abc0f | 89 | static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type) |
03b06343 | 90 | { |
f55abc0f JK |
91 | return sb_dqopt(sb)->flags & |
92 | dquot_state_flag(DQUOT_USAGE_ENABLED, type); | |
03b06343 | 93 | } |
74abb989 | 94 | |
f55abc0f | 95 | static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type) |
03b06343 | 96 | { |
f55abc0f JK |
97 | return sb_dqopt(sb)->flags & |
98 | dquot_state_flag(DQUOT_LIMITS_ENABLED, type); | |
03b06343 | 99 | } |
74abb989 | 100 | |
03b06343 JK |
101 | static inline int sb_has_quota_suspended(struct super_block *sb, int type) |
102 | { | |
f55abc0f JK |
103 | return sb_dqopt(sb)->flags & |
104 | dquot_state_flag(DQUOT_SUSPENDED, type); | |
03b06343 | 105 | } |
74abb989 | 106 | |
03b06343 JK |
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 | } | |
74abb989 | 112 | |
f55abc0f JK |
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 | ||
1da177e4 LT |
138 | /* |
139 | * Operations supported for diskquotas. | |
140 | */ | |
61e225dc | 141 | extern const struct dquot_operations dquot_operations; |
0d54b217 | 142 | extern const struct quotactl_ops vfs_quotactl_ops; |
1da177e4 LT |
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. */ | |
b85f4b87 | 149 | static inline void vfs_dq_init(struct inode *inode) |
1da177e4 LT |
150 | { |
151 | BUG_ON(!inode->i_sb); | |
f55abc0f | 152 | if (sb_any_quota_active(inode->i_sb) && !IS_NOQUOTA(inode)) |
1da177e4 LT |
153 | inode->i_sb->dq_op->initialize(inode, -1); |
154 | } | |
155 | ||
1da177e4 LT |
156 | /* The following allocation/freeing/transfer functions *must* be called inside |
157 | * a transaction (deadlocks possible otherwise) */ | |
b85f4b87 | 158 | static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr) |
1da177e4 | 159 | { |
f55abc0f | 160 | if (sb_any_quota_active(inode->i_sb)) { |
1da177e4 LT |
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 | ||
b85f4b87 | 170 | static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr) |
1da177e4 LT |
171 | { |
172 | int ret; | |
b85f4b87 | 173 | if (!(ret = vfs_dq_prealloc_space_nodirty(inode, nr))) |
1da177e4 LT |
174 | mark_inode_dirty(inode); |
175 | return ret; | |
176 | } | |
177 | ||
b85f4b87 | 178 | static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr) |
1da177e4 | 179 | { |
f55abc0f | 180 | if (sb_any_quota_active(inode->i_sb)) { |
1da177e4 LT |
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 | ||
b85f4b87 | 190 | static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr) |
1da177e4 LT |
191 | { |
192 | int ret; | |
b85f4b87 | 193 | if (!(ret = vfs_dq_alloc_space_nodirty(inode, nr))) |
1da177e4 LT |
194 | mark_inode_dirty(inode); |
195 | return ret; | |
196 | } | |
197 | ||
f18df228 MC |
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 | } | |
c469070a DM |
205 | else |
206 | inode_add_rsv_space(inode, nr); | |
f18df228 MC |
207 | return 0; |
208 | } | |
209 | ||
b85f4b87 | 210 | static inline int vfs_dq_alloc_inode(struct inode *inode) |
1da177e4 | 211 | { |
f55abc0f | 212 | if (sb_any_quota_active(inode->i_sb)) { |
b85f4b87 | 213 | vfs_dq_init(inode); |
1da177e4 LT |
214 | if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA) |
215 | return 1; | |
216 | } | |
217 | return 0; | |
218 | } | |
219 | ||
740d9dcd MC |
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 | |
c469070a | 229 | inode_claim_rsv_space(inode, nr); |
740d9dcd MC |
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); | |
c469070a DM |
243 | else |
244 | inode_sub_rsv_space(inode, nr); | |
740d9dcd MC |
245 | } |
246 | ||
b85f4b87 | 247 | static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr) |
1da177e4 | 248 | { |
f55abc0f | 249 | if (sb_any_quota_active(inode->i_sb)) |
1da177e4 LT |
250 | inode->i_sb->dq_op->free_space(inode, nr); |
251 | else | |
252 | inode_sub_bytes(inode, nr); | |
253 | } | |
254 | ||
b85f4b87 | 255 | static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr) |
1da177e4 | 256 | { |
b85f4b87 | 257 | vfs_dq_free_space_nodirty(inode, nr); |
1da177e4 LT |
258 | mark_inode_dirty(inode); |
259 | } | |
260 | ||
b85f4b87 | 261 | static inline void vfs_dq_free_inode(struct inode *inode) |
1da177e4 | 262 | { |
f55abc0f | 263 | if (sb_any_quota_active(inode->i_sb)) |
1da177e4 LT |
264 | inode->i_sb->dq_op->free_inode(inode, 1); |
265 | } | |
266 | ||
850b201b | 267 | /* Cannot be called inside a transaction */ |
b85f4b87 | 268 | static inline int vfs_dq_off(struct super_block *sb, int remount) |
1da177e4 LT |
269 | { |
270 | int ret = -ENOSYS; | |
271 | ||
0ff5af83 JK |
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 | ||
1da177e4 LT |
277 | #else |
278 | ||
f55abc0f | 279 | static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type) |
03b06343 JK |
280 | { |
281 | return 0; | |
282 | } | |
283 | ||
f55abc0f | 284 | static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type) |
03b06343 JK |
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 | } | |
74abb989 | 298 | |
f55abc0f JK |
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 | ||
1da177e4 LT |
320 | /* |
321 | * NO-OP when quota not configured. | |
322 | */ | |
323 | #define sb_dquot_ops (NULL) | |
324 | #define sb_quotactl_ops (NULL) | |
50f8c370 | 325 | |
b85f4b87 | 326 | static inline void vfs_dq_init(struct inode *inode) |
50f8c370 AM |
327 | { |
328 | } | |
329 | ||
b85f4b87 | 330 | static inline void vfs_dq_drop(struct inode *inode) |
50f8c370 AM |
331 | { |
332 | } | |
333 | ||
b85f4b87 | 334 | static inline int vfs_dq_alloc_inode(struct inode *inode) |
50f8c370 AM |
335 | { |
336 | return 0; | |
337 | } | |
338 | ||
b85f4b87 | 339 | static inline void vfs_dq_free_inode(struct inode *inode) |
50f8c370 AM |
340 | { |
341 | } | |
342 | ||
850b201b | 343 | static inline void sync_quota_sb(struct super_block *sb, int type) |
50f8c370 AM |
344 | { |
345 | } | |
346 | ||
c3f8a40c JK |
347 | static inline void writeout_quota_sb(struct super_block *sb, int type) |
348 | { | |
349 | } | |
350 | ||
b85f4b87 | 351 | static inline int vfs_dq_off(struct super_block *sb, int remount) |
50f8c370 AM |
352 | { |
353 | return 0; | |
354 | } | |
355 | ||
b85f4b87 | 356 | static inline int vfs_dq_quota_on_remount(struct super_block *sb) |
50f8c370 AM |
357 | { |
358 | return 0; | |
359 | } | |
360 | ||
b85f4b87 | 361 | static inline int vfs_dq_transfer(struct inode *inode, struct iattr *iattr) |
50f8c370 AM |
362 | { |
363 | return 0; | |
364 | } | |
365 | ||
b85f4b87 | 366 | static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr) |
1da177e4 LT |
367 | { |
368 | inode_add_bytes(inode, nr); | |
369 | return 0; | |
370 | } | |
371 | ||
b85f4b87 | 372 | static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr) |
1da177e4 | 373 | { |
b85f4b87 | 374 | vfs_dq_prealloc_space_nodirty(inode, nr); |
1da177e4 LT |
375 | mark_inode_dirty(inode); |
376 | return 0; | |
377 | } | |
378 | ||
b85f4b87 | 379 | static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr) |
1da177e4 LT |
380 | { |
381 | inode_add_bytes(inode, nr); | |
382 | return 0; | |
383 | } | |
384 | ||
b85f4b87 | 385 | static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr) |
1da177e4 | 386 | { |
b85f4b87 | 387 | vfs_dq_alloc_space_nodirty(inode, nr); |
1da177e4 LT |
388 | mark_inode_dirty(inode); |
389 | return 0; | |
390 | } | |
391 | ||
f18df228 MC |
392 | static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr) |
393 | { | |
394 | return 0; | |
395 | } | |
396 | ||
740d9dcd MC |
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 | ||
b85f4b87 | 408 | static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr) |
1da177e4 LT |
409 | { |
410 | inode_sub_bytes(inode, nr); | |
411 | } | |
412 | ||
b85f4b87 | 413 | static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr) |
1da177e4 | 414 | { |
b85f4b87 | 415 | vfs_dq_free_space_nodirty(inode, nr); |
1da177e4 LT |
416 | mark_inode_dirty(inode); |
417 | } | |
418 | ||
419 | #endif /* CONFIG_QUOTA */ | |
420 | ||
b85f4b87 | 421 | static inline int vfs_dq_prealloc_block_nodirty(struct inode *inode, qsize_t nr) |
03f6e92b | 422 | { |
9900ba34 | 423 | return vfs_dq_prealloc_space_nodirty(inode, nr << inode->i_blkbits); |
03f6e92b JK |
424 | } |
425 | ||
b85f4b87 | 426 | static inline int vfs_dq_prealloc_block(struct inode *inode, qsize_t nr) |
03f6e92b | 427 | { |
9900ba34 | 428 | return vfs_dq_prealloc_space(inode, nr << inode->i_blkbits); |
03f6e92b JK |
429 | } |
430 | ||
b85f4b87 | 431 | static inline int vfs_dq_alloc_block_nodirty(struct inode *inode, qsize_t nr) |
03f6e92b | 432 | { |
9900ba34 | 433 | return vfs_dq_alloc_space_nodirty(inode, nr << inode->i_blkbits); |
03f6e92b JK |
434 | } |
435 | ||
b85f4b87 | 436 | static inline int vfs_dq_alloc_block(struct inode *inode, qsize_t nr) |
03f6e92b | 437 | { |
9900ba34 | 438 | return vfs_dq_alloc_space(inode, nr << inode->i_blkbits); |
03f6e92b JK |
439 | } |
440 | ||
f18df228 MC |
441 | static inline int vfs_dq_reserve_block(struct inode *inode, qsize_t nr) |
442 | { | |
9900ba34 | 443 | return vfs_dq_reserve_space(inode, nr << inode->i_blkbits); |
f18df228 MC |
444 | } |
445 | ||
740d9dcd MC |
446 | static inline int vfs_dq_claim_block(struct inode *inode, qsize_t nr) |
447 | { | |
9900ba34 | 448 | return vfs_dq_claim_space(inode, nr << inode->i_blkbits); |
740d9dcd MC |
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 | ||
b85f4b87 | 457 | static inline void vfs_dq_free_block_nodirty(struct inode *inode, qsize_t nr) |
03f6e92b | 458 | { |
9900ba34 | 459 | vfs_dq_free_space_nodirty(inode, nr << inode->i_blkbits); |
03f6e92b JK |
460 | } |
461 | ||
b85f4b87 | 462 | static inline void vfs_dq_free_block(struct inode *inode, qsize_t nr) |
03f6e92b | 463 | { |
9900ba34 | 464 | vfs_dq_free_space(inode, nr << inode->i_blkbits); |
03f6e92b | 465 | } |
1da177e4 LT |
466 | |
467 | #endif /* _LINUX_QUOTAOPS_ */ |