]>
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 | 10 | #include <linux/smp_lock.h> |
1da177e4 LT |
11 | #include <linux/fs.h> |
12 | ||
03b06343 JK |
13 | static inline struct quota_info *sb_dqopt(struct super_block *sb) |
14 | { | |
15 | return &sb->s_dquot; | |
16 | } | |
74abb989 | 17 | |
1da177e4 LT |
18 | #if defined(CONFIG_QUOTA) |
19 | ||
20 | /* | |
21 | * declaration of quota_function calls in kernel. | |
22 | */ | |
b85f4b87 JK |
23 | void sync_dquots(struct super_block *sb, int type); |
24 | ||
25 | int dquot_initialize(struct inode *inode, int type); | |
26 | int dquot_drop(struct inode *inode); | |
27 | ||
28 | int dquot_alloc_space(struct inode *inode, qsize_t number, int prealloc); | |
12095460 | 29 | int dquot_alloc_inode(const struct inode *inode, qsize_t number); |
b85f4b87 JK |
30 | |
31 | int dquot_free_space(struct inode *inode, qsize_t number); | |
12095460 | 32 | int dquot_free_inode(const struct inode *inode, qsize_t number); |
b85f4b87 JK |
33 | |
34 | int dquot_transfer(struct inode *inode, struct iattr *iattr); | |
35 | int dquot_commit(struct dquot *dquot); | |
36 | int dquot_acquire(struct dquot *dquot); | |
37 | int dquot_release(struct dquot *dquot); | |
38 | int dquot_commit_info(struct super_block *sb, int type); | |
39 | int dquot_mark_dquot_dirty(struct dquot *dquot); | |
40 | ||
41 | int vfs_quota_on(struct super_block *sb, int type, int format_id, | |
42 | char *path, int remount); | |
f55abc0f JK |
43 | int vfs_quota_enable(struct inode *inode, int type, int format_id, |
44 | unsigned int flags); | |
77e69dac AV |
45 | int vfs_quota_on_path(struct super_block *sb, int type, int format_id, |
46 | struct path *path); | |
b85f4b87 JK |
47 | int vfs_quota_on_mount(struct super_block *sb, char *qf_name, |
48 | int format_id, int type); | |
49 | int vfs_quota_off(struct super_block *sb, int type, int remount); | |
f55abc0f | 50 | int vfs_quota_disable(struct super_block *sb, int type, unsigned int flags); |
b85f4b87 JK |
51 | int vfs_quota_sync(struct super_block *sb, int type); |
52 | int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii); | |
53 | int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii); | |
54 | int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di); | |
55 | int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di); | |
56 | ||
57 | void vfs_dq_drop(struct inode *inode); | |
58 | int vfs_dq_transfer(struct inode *inode, struct iattr *iattr); | |
59 | int vfs_dq_quota_on_remount(struct super_block *sb); | |
1da177e4 | 60 | |
03b06343 JK |
61 | static inline struct mem_dqinfo *sb_dqinfo(struct super_block *sb, int type) |
62 | { | |
63 | return sb_dqopt(sb)->info + type; | |
64 | } | |
74abb989 JK |
65 | |
66 | /* | |
67 | * Functions for checking status of quota | |
68 | */ | |
69 | ||
f55abc0f | 70 | static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type) |
03b06343 | 71 | { |
f55abc0f JK |
72 | return sb_dqopt(sb)->flags & |
73 | dquot_state_flag(DQUOT_USAGE_ENABLED, type); | |
03b06343 | 74 | } |
74abb989 | 75 | |
f55abc0f | 76 | static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type) |
03b06343 | 77 | { |
f55abc0f JK |
78 | return sb_dqopt(sb)->flags & |
79 | dquot_state_flag(DQUOT_LIMITS_ENABLED, type); | |
03b06343 | 80 | } |
74abb989 | 81 | |
03b06343 JK |
82 | static inline int sb_has_quota_suspended(struct super_block *sb, int type) |
83 | { | |
f55abc0f JK |
84 | return sb_dqopt(sb)->flags & |
85 | dquot_state_flag(DQUOT_SUSPENDED, type); | |
03b06343 | 86 | } |
74abb989 | 87 | |
03b06343 JK |
88 | static inline int sb_any_quota_suspended(struct super_block *sb) |
89 | { | |
90 | return sb_has_quota_suspended(sb, USRQUOTA) || | |
91 | sb_has_quota_suspended(sb, GRPQUOTA); | |
92 | } | |
74abb989 | 93 | |
f55abc0f JK |
94 | /* Does kernel know about any quota information for given sb + type? */ |
95 | static inline int sb_has_quota_loaded(struct super_block *sb, int type) | |
96 | { | |
97 | /* Currently if anything is on, then quota usage is on as well */ | |
98 | return sb_has_quota_usage_enabled(sb, type); | |
99 | } | |
100 | ||
101 | static inline int sb_any_quota_loaded(struct super_block *sb) | |
102 | { | |
103 | return sb_has_quota_loaded(sb, USRQUOTA) || | |
104 | sb_has_quota_loaded(sb, GRPQUOTA); | |
105 | } | |
106 | ||
107 | static inline int sb_has_quota_active(struct super_block *sb, int type) | |
108 | { | |
109 | return sb_has_quota_loaded(sb, type) && | |
110 | !sb_has_quota_suspended(sb, type); | |
111 | } | |
112 | ||
113 | static inline int sb_any_quota_active(struct super_block *sb) | |
114 | { | |
115 | return sb_has_quota_active(sb, USRQUOTA) || | |
116 | sb_has_quota_active(sb, GRPQUOTA); | |
117 | } | |
118 | ||
1da177e4 LT |
119 | /* |
120 | * Operations supported for diskquotas. | |
121 | */ | |
122 | extern struct dquot_operations dquot_operations; | |
123 | extern struct quotactl_ops vfs_quotactl_ops; | |
124 | ||
125 | #define sb_dquot_ops (&dquot_operations) | |
126 | #define sb_quotactl_ops (&vfs_quotactl_ops) | |
127 | ||
128 | /* It is better to call this function outside of any transaction as it might | |
129 | * need a lot of space in journal for dquot structure allocation. */ | |
b85f4b87 | 130 | static inline void vfs_dq_init(struct inode *inode) |
1da177e4 LT |
131 | { |
132 | BUG_ON(!inode->i_sb); | |
f55abc0f | 133 | if (sb_any_quota_active(inode->i_sb) && !IS_NOQUOTA(inode)) |
1da177e4 LT |
134 | inode->i_sb->dq_op->initialize(inode, -1); |
135 | } | |
136 | ||
1da177e4 LT |
137 | /* The following allocation/freeing/transfer functions *must* be called inside |
138 | * a transaction (deadlocks possible otherwise) */ | |
b85f4b87 | 139 | static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr) |
1da177e4 | 140 | { |
f55abc0f | 141 | if (sb_any_quota_active(inode->i_sb)) { |
1da177e4 LT |
142 | /* Used space is updated in alloc_space() */ |
143 | if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA) | |
144 | return 1; | |
145 | } | |
146 | else | |
147 | inode_add_bytes(inode, nr); | |
148 | return 0; | |
149 | } | |
150 | ||
b85f4b87 | 151 | static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr) |
1da177e4 LT |
152 | { |
153 | int ret; | |
b85f4b87 | 154 | if (!(ret = vfs_dq_prealloc_space_nodirty(inode, nr))) |
1da177e4 LT |
155 | mark_inode_dirty(inode); |
156 | return ret; | |
157 | } | |
158 | ||
b85f4b87 | 159 | static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr) |
1da177e4 | 160 | { |
f55abc0f | 161 | if (sb_any_quota_active(inode->i_sb)) { |
1da177e4 LT |
162 | /* Used space is updated in alloc_space() */ |
163 | if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA) | |
164 | return 1; | |
165 | } | |
166 | else | |
167 | inode_add_bytes(inode, nr); | |
168 | return 0; | |
169 | } | |
170 | ||
b85f4b87 | 171 | static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr) |
1da177e4 LT |
172 | { |
173 | int ret; | |
b85f4b87 | 174 | if (!(ret = vfs_dq_alloc_space_nodirty(inode, nr))) |
1da177e4 LT |
175 | mark_inode_dirty(inode); |
176 | return ret; | |
177 | } | |
178 | ||
b85f4b87 | 179 | static inline int vfs_dq_alloc_inode(struct inode *inode) |
1da177e4 | 180 | { |
f55abc0f | 181 | if (sb_any_quota_active(inode->i_sb)) { |
b85f4b87 | 182 | vfs_dq_init(inode); |
1da177e4 LT |
183 | if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA) |
184 | return 1; | |
185 | } | |
186 | return 0; | |
187 | } | |
188 | ||
b85f4b87 | 189 | static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr) |
1da177e4 | 190 | { |
f55abc0f | 191 | if (sb_any_quota_active(inode->i_sb)) |
1da177e4 LT |
192 | inode->i_sb->dq_op->free_space(inode, nr); |
193 | else | |
194 | inode_sub_bytes(inode, nr); | |
195 | } | |
196 | ||
b85f4b87 | 197 | static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr) |
1da177e4 | 198 | { |
b85f4b87 | 199 | vfs_dq_free_space_nodirty(inode, nr); |
1da177e4 LT |
200 | mark_inode_dirty(inode); |
201 | } | |
202 | ||
b85f4b87 | 203 | static inline void vfs_dq_free_inode(struct inode *inode) |
1da177e4 | 204 | { |
f55abc0f | 205 | if (sb_any_quota_active(inode->i_sb)) |
1da177e4 LT |
206 | inode->i_sb->dq_op->free_inode(inode, 1); |
207 | } | |
208 | ||
1da177e4 | 209 | /* The following two functions cannot be called inside a transaction */ |
b85f4b87 | 210 | static inline void vfs_dq_sync(struct super_block *sb) |
03f6e92b JK |
211 | { |
212 | sync_dquots(sb, -1); | |
213 | } | |
1da177e4 | 214 | |
b85f4b87 | 215 | static inline int vfs_dq_off(struct super_block *sb, int remount) |
1da177e4 LT |
216 | { |
217 | int ret = -ENOSYS; | |
218 | ||
0ff5af83 JK |
219 | if (sb->s_qcop && sb->s_qcop->quota_off) |
220 | ret = sb->s_qcop->quota_off(sb, -1, remount); | |
221 | return ret; | |
222 | } | |
223 | ||
1da177e4 LT |
224 | #else |
225 | ||
f55abc0f | 226 | static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type) |
03b06343 JK |
227 | { |
228 | return 0; | |
229 | } | |
230 | ||
f55abc0f | 231 | static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type) |
03b06343 JK |
232 | { |
233 | return 0; | |
234 | } | |
235 | ||
236 | static inline int sb_has_quota_suspended(struct super_block *sb, int type) | |
237 | { | |
238 | return 0; | |
239 | } | |
240 | ||
241 | static inline int sb_any_quota_suspended(struct super_block *sb) | |
242 | { | |
243 | return 0; | |
244 | } | |
74abb989 | 245 | |
f55abc0f JK |
246 | /* Does kernel know about any quota information for given sb + type? */ |
247 | static inline int sb_has_quota_loaded(struct super_block *sb, int type) | |
248 | { | |
249 | return 0; | |
250 | } | |
251 | ||
252 | static inline int sb_any_quota_loaded(struct super_block *sb) | |
253 | { | |
254 | return 0; | |
255 | } | |
256 | ||
257 | static inline int sb_has_quota_active(struct super_block *sb, int type) | |
258 | { | |
259 | return 0; | |
260 | } | |
261 | ||
262 | static inline int sb_any_quota_active(struct super_block *sb) | |
263 | { | |
264 | return 0; | |
265 | } | |
266 | ||
1da177e4 LT |
267 | /* |
268 | * NO-OP when quota not configured. | |
269 | */ | |
270 | #define sb_dquot_ops (NULL) | |
271 | #define sb_quotactl_ops (NULL) | |
50f8c370 | 272 | |
b85f4b87 | 273 | static inline void vfs_dq_init(struct inode *inode) |
50f8c370 AM |
274 | { |
275 | } | |
276 | ||
b85f4b87 | 277 | static inline void vfs_dq_drop(struct inode *inode) |
50f8c370 AM |
278 | { |
279 | } | |
280 | ||
b85f4b87 | 281 | static inline int vfs_dq_alloc_inode(struct inode *inode) |
50f8c370 AM |
282 | { |
283 | return 0; | |
284 | } | |
285 | ||
b85f4b87 | 286 | static inline void vfs_dq_free_inode(struct inode *inode) |
50f8c370 AM |
287 | { |
288 | } | |
289 | ||
b85f4b87 | 290 | static inline void vfs_dq_sync(struct super_block *sb) |
50f8c370 AM |
291 | { |
292 | } | |
293 | ||
b85f4b87 | 294 | static inline int vfs_dq_off(struct super_block *sb, int remount) |
50f8c370 AM |
295 | { |
296 | return 0; | |
297 | } | |
298 | ||
b85f4b87 | 299 | static inline int vfs_dq_quota_on_remount(struct super_block *sb) |
50f8c370 AM |
300 | { |
301 | return 0; | |
302 | } | |
303 | ||
b85f4b87 | 304 | static inline int vfs_dq_transfer(struct inode *inode, struct iattr *iattr) |
50f8c370 AM |
305 | { |
306 | return 0; | |
307 | } | |
308 | ||
b85f4b87 | 309 | static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr) |
1da177e4 LT |
310 | { |
311 | inode_add_bytes(inode, nr); | |
312 | return 0; | |
313 | } | |
314 | ||
b85f4b87 | 315 | static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr) |
1da177e4 | 316 | { |
b85f4b87 | 317 | vfs_dq_prealloc_space_nodirty(inode, nr); |
1da177e4 LT |
318 | mark_inode_dirty(inode); |
319 | return 0; | |
320 | } | |
321 | ||
b85f4b87 | 322 | static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr) |
1da177e4 LT |
323 | { |
324 | inode_add_bytes(inode, nr); | |
325 | return 0; | |
326 | } | |
327 | ||
b85f4b87 | 328 | static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr) |
1da177e4 | 329 | { |
b85f4b87 | 330 | vfs_dq_alloc_space_nodirty(inode, nr); |
1da177e4 LT |
331 | mark_inode_dirty(inode); |
332 | return 0; | |
333 | } | |
334 | ||
b85f4b87 | 335 | static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr) |
1da177e4 LT |
336 | { |
337 | inode_sub_bytes(inode, nr); | |
338 | } | |
339 | ||
b85f4b87 | 340 | static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr) |
1da177e4 | 341 | { |
b85f4b87 | 342 | vfs_dq_free_space_nodirty(inode, nr); |
1da177e4 LT |
343 | mark_inode_dirty(inode); |
344 | } | |
345 | ||
346 | #endif /* CONFIG_QUOTA */ | |
347 | ||
b85f4b87 | 348 | static inline int vfs_dq_prealloc_block_nodirty(struct inode *inode, qsize_t nr) |
03f6e92b | 349 | { |
b85f4b87 | 350 | return vfs_dq_prealloc_space_nodirty(inode, |
03f6e92b JK |
351 | nr << inode->i_sb->s_blocksize_bits); |
352 | } | |
353 | ||
b85f4b87 | 354 | static inline int vfs_dq_prealloc_block(struct inode *inode, qsize_t nr) |
03f6e92b | 355 | { |
b85f4b87 | 356 | return vfs_dq_prealloc_space(inode, |
03f6e92b JK |
357 | nr << inode->i_sb->s_blocksize_bits); |
358 | } | |
359 | ||
b85f4b87 | 360 | static inline int vfs_dq_alloc_block_nodirty(struct inode *inode, qsize_t nr) |
03f6e92b | 361 | { |
b85f4b87 | 362 | return vfs_dq_alloc_space_nodirty(inode, |
03f6e92b JK |
363 | nr << inode->i_sb->s_blocksize_bits); |
364 | } | |
365 | ||
b85f4b87 | 366 | static inline int vfs_dq_alloc_block(struct inode *inode, qsize_t nr) |
03f6e92b | 367 | { |
b85f4b87 | 368 | return vfs_dq_alloc_space(inode, |
03f6e92b JK |
369 | nr << inode->i_sb->s_blocksize_bits); |
370 | } | |
371 | ||
b85f4b87 | 372 | static inline void vfs_dq_free_block_nodirty(struct inode *inode, qsize_t nr) |
03f6e92b | 373 | { |
b85f4b87 | 374 | vfs_dq_free_space_nodirty(inode, nr << inode->i_sb->s_blocksize_bits); |
03f6e92b JK |
375 | } |
376 | ||
b85f4b87 | 377 | static inline void vfs_dq_free_block(struct inode *inode, qsize_t nr) |
03f6e92b | 378 | { |
b85f4b87 | 379 | vfs_dq_free_space(inode, nr << inode->i_sb->s_blocksize_bits); |
03f6e92b | 380 | } |
1da177e4 | 381 | |
b85f4b87 JK |
382 | /* |
383 | * Define uppercase equivalents for compatibility with old function names | |
384 | * Can go away when we think all users have been converted (15/04/2008) | |
385 | */ | |
386 | #define DQUOT_INIT(inode) vfs_dq_init(inode) | |
387 | #define DQUOT_DROP(inode) vfs_dq_drop(inode) | |
388 | #define DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr) \ | |
389 | vfs_dq_prealloc_space_nodirty(inode, nr) | |
390 | #define DQUOT_PREALLOC_SPACE(inode, nr) vfs_dq_prealloc_space(inode, nr) | |
391 | #define DQUOT_ALLOC_SPACE_NODIRTY(inode, nr) \ | |
392 | vfs_dq_alloc_space_nodirty(inode, nr) | |
393 | #define DQUOT_ALLOC_SPACE(inode, nr) vfs_dq_alloc_space(inode, nr) | |
394 | #define DQUOT_PREALLOC_BLOCK_NODIRTY(inode, nr) \ | |
395 | vfs_dq_prealloc_block_nodirty(inode, nr) | |
396 | #define DQUOT_PREALLOC_BLOCK(inode, nr) vfs_dq_prealloc_block(inode, nr) | |
397 | #define DQUOT_ALLOC_BLOCK_NODIRTY(inode, nr) \ | |
398 | vfs_dq_alloc_block_nodirty(inode, nr) | |
399 | #define DQUOT_ALLOC_BLOCK(inode, nr) vfs_dq_alloc_block(inode, nr) | |
400 | #define DQUOT_ALLOC_INODE(inode) vfs_dq_alloc_inode(inode) | |
401 | #define DQUOT_FREE_SPACE_NODIRTY(inode, nr) \ | |
402 | vfs_dq_free_space_nodirty(inode, nr) | |
403 | #define DQUOT_FREE_SPACE(inode, nr) vfs_dq_free_space(inode, nr) | |
404 | #define DQUOT_FREE_BLOCK_NODIRTY(inode, nr) \ | |
405 | vfs_dq_free_block_nodirty(inode, nr) | |
406 | #define DQUOT_FREE_BLOCK(inode, nr) vfs_dq_free_block(inode, nr) | |
407 | #define DQUOT_FREE_INODE(inode) vfs_dq_free_inode(inode) | |
408 | #define DQUOT_TRANSFER(inode, iattr) vfs_dq_transfer(inode, iattr) | |
409 | #define DQUOT_SYNC(sb) vfs_dq_sync(sb) | |
410 | #define DQUOT_OFF(sb, remount) vfs_dq_off(sb, remount) | |
411 | #define DQUOT_ON_REMOUNT(sb) vfs_dq_quota_on_remount(sb) | |
412 | ||
1da177e4 | 413 | #endif /* _LINUX_QUOTAOPS_ */ |