]>
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 | 45 | |
8ddd69d6 | 46 | int dquot_transfer(struct inode *inode, qid_t *chid, unsigned long mask); |
b85f4b87 JK |
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 | ||
ad1e6e8d | 82 | static inline bool 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 | |
ad1e6e8d | 88 | static inline bool 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 | |
ad1e6e8d | 94 | static inline bool sb_has_quota_suspended(struct super_block *sb, int type) |
03b06343 | 95 | { |
f55abc0f JK |
96 | return sb_dqopt(sb)->flags & |
97 | dquot_state_flag(DQUOT_SUSPENDED, type); | |
03b06343 | 98 | } |
74abb989 | 99 | |
ad1e6e8d | 100 | static inline unsigned sb_any_quota_suspended(struct super_block *sb) |
03b06343 | 101 | { |
ad1e6e8d DM |
102 | unsigned type, tmsk = 0; |
103 | for (type = 0; type < MAXQUOTAS; type++) | |
104 | tmsk |= sb_has_quota_suspended(sb, type) << type; | |
105 | return tmsk; | |
03b06343 | 106 | } |
74abb989 | 107 | |
f55abc0f | 108 | /* Does kernel know about any quota information for given sb + type? */ |
ad1e6e8d | 109 | static inline bool sb_has_quota_loaded(struct super_block *sb, int type) |
f55abc0f JK |
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 | ||
ad1e6e8d | 115 | static inline unsigned sb_any_quota_loaded(struct super_block *sb) |
f55abc0f | 116 | { |
ad1e6e8d DM |
117 | unsigned type, tmsk = 0; |
118 | for (type = 0; type < MAXQUOTAS; type++) | |
119 | tmsk |= sb_has_quota_loaded(sb, type) << type; | |
120 | return tmsk; | |
f55abc0f JK |
121 | } |
122 | ||
ad1e6e8d | 123 | static inline bool sb_has_quota_active(struct super_block *sb, int type) |
f55abc0f JK |
124 | { |
125 | return sb_has_quota_loaded(sb, type) && | |
126 | !sb_has_quota_suspended(sb, type); | |
127 | } | |
128 | ||
ad1e6e8d | 129 | static inline unsigned sb_any_quota_active(struct super_block *sb) |
f55abc0f | 130 | { |
ad1e6e8d | 131 | return sb_any_quota_loaded(sb) & ~sb_any_quota_suspended(sb); |
f55abc0f JK |
132 | } |
133 | ||
1da177e4 LT |
134 | /* |
135 | * Operations supported for diskquotas. | |
136 | */ | |
61e225dc | 137 | extern const struct dquot_operations dquot_operations; |
0d54b217 | 138 | extern const struct quotactl_ops vfs_quotactl_ops; |
1da177e4 LT |
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. */ | |
b85f4b87 | 145 | static inline void vfs_dq_init(struct inode *inode) |
1da177e4 LT |
146 | { |
147 | BUG_ON(!inode->i_sb); | |
f55abc0f | 148 | if (sb_any_quota_active(inode->i_sb) && !IS_NOQUOTA(inode)) |
1da177e4 LT |
149 | inode->i_sb->dq_op->initialize(inode, -1); |
150 | } | |
151 | ||
1da177e4 LT |
152 | /* The following allocation/freeing/transfer functions *must* be called inside |
153 | * a transaction (deadlocks possible otherwise) */ | |
b85f4b87 | 154 | static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr) |
1da177e4 | 155 | { |
f55abc0f | 156 | if (sb_any_quota_active(inode->i_sb)) { |
1da177e4 LT |
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 | ||
b85f4b87 | 166 | static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr) |
1da177e4 LT |
167 | { |
168 | int ret; | |
b85f4b87 | 169 | if (!(ret = vfs_dq_prealloc_space_nodirty(inode, nr))) |
1da177e4 LT |
170 | mark_inode_dirty(inode); |
171 | return ret; | |
172 | } | |
173 | ||
b85f4b87 | 174 | static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr) |
1da177e4 | 175 | { |
f55abc0f | 176 | if (sb_any_quota_active(inode->i_sb)) { |
1da177e4 LT |
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 | ||
b85f4b87 | 186 | static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr) |
1da177e4 LT |
187 | { |
188 | int ret; | |
b85f4b87 | 189 | if (!(ret = vfs_dq_alloc_space_nodirty(inode, nr))) |
1da177e4 LT |
190 | mark_inode_dirty(inode); |
191 | return ret; | |
192 | } | |
193 | ||
f18df228 MC |
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 | } | |
c469070a DM |
201 | else |
202 | inode_add_rsv_space(inode, nr); | |
f18df228 MC |
203 | return 0; |
204 | } | |
205 | ||
b85f4b87 | 206 | static inline int vfs_dq_alloc_inode(struct inode *inode) |
1da177e4 | 207 | { |
f55abc0f | 208 | if (sb_any_quota_active(inode->i_sb)) { |
b85f4b87 | 209 | vfs_dq_init(inode); |
1da177e4 LT |
210 | if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA) |
211 | return 1; | |
212 | } | |
213 | return 0; | |
214 | } | |
215 | ||
740d9dcd MC |
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 | |
c469070a | 225 | inode_claim_rsv_space(inode, nr); |
740d9dcd MC |
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); | |
c469070a DM |
239 | else |
240 | inode_sub_rsv_space(inode, nr); | |
740d9dcd MC |
241 | } |
242 | ||
b85f4b87 | 243 | static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr) |
1da177e4 | 244 | { |
f55abc0f | 245 | if (sb_any_quota_active(inode->i_sb)) |
1da177e4 LT |
246 | inode->i_sb->dq_op->free_space(inode, nr); |
247 | else | |
248 | inode_sub_bytes(inode, nr); | |
249 | } | |
250 | ||
b85f4b87 | 251 | static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr) |
1da177e4 | 252 | { |
b85f4b87 | 253 | vfs_dq_free_space_nodirty(inode, nr); |
1da177e4 LT |
254 | mark_inode_dirty(inode); |
255 | } | |
256 | ||
b85f4b87 | 257 | static inline void vfs_dq_free_inode(struct inode *inode) |
1da177e4 | 258 | { |
f55abc0f | 259 | if (sb_any_quota_active(inode->i_sb)) |
1da177e4 LT |
260 | inode->i_sb->dq_op->free_inode(inode, 1); |
261 | } | |
262 | ||
850b201b | 263 | /* Cannot be called inside a transaction */ |
b85f4b87 | 264 | static inline int vfs_dq_off(struct super_block *sb, int remount) |
1da177e4 LT |
265 | { |
266 | int ret = -ENOSYS; | |
267 | ||
0ff5af83 JK |
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 | ||
1da177e4 LT |
273 | #else |
274 | ||
f55abc0f | 275 | static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type) |
03b06343 JK |
276 | { |
277 | return 0; | |
278 | } | |
279 | ||
f55abc0f | 280 | static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type) |
03b06343 JK |
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 | } | |
74abb989 | 294 | |
f55abc0f JK |
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 | ||
1da177e4 LT |
316 | /* |
317 | * NO-OP when quota not configured. | |
318 | */ | |
319 | #define sb_dquot_ops (NULL) | |
320 | #define sb_quotactl_ops (NULL) | |
50f8c370 | 321 | |
b85f4b87 | 322 | static inline void vfs_dq_init(struct inode *inode) |
50f8c370 AM |
323 | { |
324 | } | |
325 | ||
b85f4b87 | 326 | static inline void vfs_dq_drop(struct inode *inode) |
50f8c370 AM |
327 | { |
328 | } | |
329 | ||
b85f4b87 | 330 | static inline int vfs_dq_alloc_inode(struct inode *inode) |
50f8c370 AM |
331 | { |
332 | return 0; | |
333 | } | |
334 | ||
b85f4b87 | 335 | static inline void vfs_dq_free_inode(struct inode *inode) |
50f8c370 AM |
336 | { |
337 | } | |
338 | ||
b85f4b87 | 339 | static inline int vfs_dq_off(struct super_block *sb, int remount) |
50f8c370 AM |
340 | { |
341 | return 0; | |
342 | } | |
343 | ||
b85f4b87 | 344 | static inline int vfs_dq_quota_on_remount(struct super_block *sb) |
50f8c370 AM |
345 | { |
346 | return 0; | |
347 | } | |
348 | ||
b85f4b87 | 349 | static inline int vfs_dq_transfer(struct inode *inode, struct iattr *iattr) |
50f8c370 AM |
350 | { |
351 | return 0; | |
352 | } | |
353 | ||
b85f4b87 | 354 | static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr) |
1da177e4 LT |
355 | { |
356 | inode_add_bytes(inode, nr); | |
357 | return 0; | |
358 | } | |
359 | ||
b85f4b87 | 360 | static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr) |
1da177e4 | 361 | { |
b85f4b87 | 362 | vfs_dq_prealloc_space_nodirty(inode, nr); |
1da177e4 LT |
363 | mark_inode_dirty(inode); |
364 | return 0; | |
365 | } | |
366 | ||
b85f4b87 | 367 | static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr) |
1da177e4 LT |
368 | { |
369 | inode_add_bytes(inode, nr); | |
370 | return 0; | |
371 | } | |
372 | ||
b85f4b87 | 373 | static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr) |
1da177e4 | 374 | { |
b85f4b87 | 375 | vfs_dq_alloc_space_nodirty(inode, nr); |
1da177e4 LT |
376 | mark_inode_dirty(inode); |
377 | return 0; | |
378 | } | |
379 | ||
f18df228 MC |
380 | static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr) |
381 | { | |
382 | return 0; | |
383 | } | |
384 | ||
740d9dcd MC |
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 | ||
b85f4b87 | 396 | static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr) |
1da177e4 LT |
397 | { |
398 | inode_sub_bytes(inode, nr); | |
399 | } | |
400 | ||
b85f4b87 | 401 | static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr) |
1da177e4 | 402 | { |
b85f4b87 | 403 | vfs_dq_free_space_nodirty(inode, nr); |
1da177e4 LT |
404 | mark_inode_dirty(inode); |
405 | } | |
406 | ||
407 | #endif /* CONFIG_QUOTA */ | |
408 | ||
b85f4b87 | 409 | static inline int vfs_dq_prealloc_block_nodirty(struct inode *inode, qsize_t nr) |
03f6e92b | 410 | { |
9900ba34 | 411 | return vfs_dq_prealloc_space_nodirty(inode, nr << inode->i_blkbits); |
03f6e92b JK |
412 | } |
413 | ||
b85f4b87 | 414 | static inline int vfs_dq_prealloc_block(struct inode *inode, qsize_t nr) |
03f6e92b | 415 | { |
9900ba34 | 416 | return vfs_dq_prealloc_space(inode, nr << inode->i_blkbits); |
03f6e92b JK |
417 | } |
418 | ||
b85f4b87 | 419 | static inline int vfs_dq_alloc_block_nodirty(struct inode *inode, qsize_t nr) |
03f6e92b | 420 | { |
9900ba34 | 421 | return vfs_dq_alloc_space_nodirty(inode, nr << inode->i_blkbits); |
03f6e92b JK |
422 | } |
423 | ||
b85f4b87 | 424 | static inline int vfs_dq_alloc_block(struct inode *inode, qsize_t nr) |
03f6e92b | 425 | { |
9900ba34 | 426 | return vfs_dq_alloc_space(inode, nr << inode->i_blkbits); |
03f6e92b JK |
427 | } |
428 | ||
f18df228 MC |
429 | static inline int vfs_dq_reserve_block(struct inode *inode, qsize_t nr) |
430 | { | |
9900ba34 | 431 | return vfs_dq_reserve_space(inode, nr << inode->i_blkbits); |
f18df228 MC |
432 | } |
433 | ||
740d9dcd MC |
434 | static inline int vfs_dq_claim_block(struct inode *inode, qsize_t nr) |
435 | { | |
9900ba34 | 436 | return vfs_dq_claim_space(inode, nr << inode->i_blkbits); |
740d9dcd MC |
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 | ||
b85f4b87 | 445 | static inline void vfs_dq_free_block_nodirty(struct inode *inode, qsize_t nr) |
03f6e92b | 446 | { |
9900ba34 | 447 | vfs_dq_free_space_nodirty(inode, nr << inode->i_blkbits); |
03f6e92b JK |
448 | } |
449 | ||
b85f4b87 | 450 | static inline void vfs_dq_free_block(struct inode *inode, qsize_t nr) |
03f6e92b | 451 | { |
9900ba34 | 452 | vfs_dq_free_space(inode, nr << inode->i_blkbits); |
03f6e92b | 453 | } |
1da177e4 LT |
454 | |
455 | #endif /* _LINUX_QUOTAOPS_ */ |