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