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