]>
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 | ||
56246f9a ES |
12 | #define DQUOT_SPACE_WARN 0x1 |
13 | #define DQUOT_SPACE_RESERVE 0x2 | |
14 | ||
03b06343 JK |
15 | static inline struct quota_info *sb_dqopt(struct super_block *sb) |
16 | { | |
17 | return &sb->s_dquot; | |
18 | } | |
74abb989 | 19 | |
1da177e4 LT |
20 | #if defined(CONFIG_QUOTA) |
21 | ||
22 | /* | |
23 | * declaration of quota_function calls in kernel. | |
24 | */ | |
c469070a DM |
25 | void inode_add_rsv_space(struct inode *inode, qsize_t number); |
26 | void inode_claim_rsv_space(struct inode *inode, qsize_t number); | |
27 | void inode_sub_rsv_space(struct inode *inode, qsize_t number); | |
28 | ||
871a2931 | 29 | void dquot_initialize(struct inode *inode); |
9f754758 | 30 | void dquot_drop(struct inode *inode); |
3d9ea253 JK |
31 | struct dquot *dqget(struct super_block *sb, unsigned int id, int type); |
32 | void dqput(struct dquot *dquot); | |
12c77527 JK |
33 | int dquot_scan_active(struct super_block *sb, |
34 | int (*fn)(struct dquot *dquot, unsigned long priv), | |
35 | unsigned long priv); | |
7d9056ba JK |
36 | struct dquot *dquot_alloc(struct super_block *sb, int type); |
37 | void dquot_destroy(struct dquot *dquot); | |
b85f4b87 | 38 | |
56246f9a ES |
39 | int __dquot_alloc_space(struct inode *inode, qsize_t number, int flags); |
40 | void __dquot_free_space(struct inode *inode, qsize_t number, int flags); | |
b85f4b87 | 41 | |
63936dda | 42 | int dquot_alloc_inode(const struct inode *inode); |
740d9dcd | 43 | |
5dd4056d | 44 | int dquot_claim_space_nodirty(struct inode *inode, qsize_t number); |
63936dda | 45 | void dquot_free_inode(const struct inode *inode); |
b85f4b87 | 46 | |
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 | ||
907f4554 CH |
53 | int dquot_file_open(struct inode *inode, struct file *file); |
54 | ||
b85f4b87 JK |
55 | int vfs_quota_on(struct super_block *sb, int type, int format_id, |
56 | char *path, int remount); | |
f55abc0f JK |
57 | int vfs_quota_enable(struct inode *inode, int type, int format_id, |
58 | unsigned int flags); | |
77e69dac AV |
59 | int vfs_quota_on_path(struct super_block *sb, int type, int format_id, |
60 | struct path *path); | |
b85f4b87 JK |
61 | int vfs_quota_on_mount(struct super_block *sb, char *qf_name, |
62 | int format_id, int type); | |
63 | int vfs_quota_off(struct super_block *sb, int type, int remount); | |
f55abc0f | 64 | int vfs_quota_disable(struct super_block *sb, int type, unsigned int flags); |
5fb324ad | 65 | int vfs_quota_sync(struct super_block *sb, int type, int wait); |
b85f4b87 JK |
66 | int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii); |
67 | int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii); | |
68 | int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di); | |
69 | int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di); | |
70 | ||
b43fa828 | 71 | int dquot_transfer(struct inode *inode, struct iattr *iattr); |
b85f4b87 | 72 | int vfs_dq_quota_on_remount(struct super_block *sb); |
1da177e4 | 73 | |
03b06343 JK |
74 | static inline struct mem_dqinfo *sb_dqinfo(struct super_block *sb, int type) |
75 | { | |
76 | return sb_dqopt(sb)->info + type; | |
77 | } | |
74abb989 JK |
78 | |
79 | /* | |
80 | * Functions for checking status of quota | |
81 | */ | |
82 | ||
ad1e6e8d | 83 | static inline bool sb_has_quota_usage_enabled(struct super_block *sb, int type) |
03b06343 | 84 | { |
f55abc0f JK |
85 | return sb_dqopt(sb)->flags & |
86 | dquot_state_flag(DQUOT_USAGE_ENABLED, type); | |
03b06343 | 87 | } |
74abb989 | 88 | |
ad1e6e8d | 89 | static inline bool sb_has_quota_limits_enabled(struct super_block *sb, int type) |
03b06343 | 90 | { |
f55abc0f JK |
91 | return sb_dqopt(sb)->flags & |
92 | dquot_state_flag(DQUOT_LIMITS_ENABLED, type); | |
03b06343 | 93 | } |
74abb989 | 94 | |
ad1e6e8d | 95 | static inline bool sb_has_quota_suspended(struct super_block *sb, int type) |
03b06343 | 96 | { |
f55abc0f JK |
97 | return sb_dqopt(sb)->flags & |
98 | dquot_state_flag(DQUOT_SUSPENDED, type); | |
03b06343 | 99 | } |
74abb989 | 100 | |
ad1e6e8d | 101 | static inline unsigned sb_any_quota_suspended(struct super_block *sb) |
03b06343 | 102 | { |
ad1e6e8d DM |
103 | unsigned type, tmsk = 0; |
104 | for (type = 0; type < MAXQUOTAS; type++) | |
105 | tmsk |= sb_has_quota_suspended(sb, type) << type; | |
106 | return tmsk; | |
03b06343 | 107 | } |
74abb989 | 108 | |
f55abc0f | 109 | /* Does kernel know about any quota information for given sb + type? */ |
ad1e6e8d | 110 | static inline bool sb_has_quota_loaded(struct super_block *sb, int type) |
f55abc0f JK |
111 | { |
112 | /* Currently if anything is on, then quota usage is on as well */ | |
113 | return sb_has_quota_usage_enabled(sb, type); | |
114 | } | |
115 | ||
ad1e6e8d | 116 | static inline unsigned sb_any_quota_loaded(struct super_block *sb) |
f55abc0f | 117 | { |
ad1e6e8d DM |
118 | unsigned type, tmsk = 0; |
119 | for (type = 0; type < MAXQUOTAS; type++) | |
120 | tmsk |= sb_has_quota_loaded(sb, type) << type; | |
121 | return tmsk; | |
f55abc0f JK |
122 | } |
123 | ||
ad1e6e8d | 124 | static inline bool sb_has_quota_active(struct super_block *sb, int type) |
f55abc0f JK |
125 | { |
126 | return sb_has_quota_loaded(sb, type) && | |
127 | !sb_has_quota_suspended(sb, type); | |
128 | } | |
129 | ||
ad1e6e8d | 130 | static inline unsigned sb_any_quota_active(struct super_block *sb) |
f55abc0f | 131 | { |
ad1e6e8d | 132 | return sb_any_quota_loaded(sb) & ~sb_any_quota_suspended(sb); |
f55abc0f JK |
133 | } |
134 | ||
1da177e4 LT |
135 | /* |
136 | * Operations supported for diskquotas. | |
137 | */ | |
61e225dc | 138 | extern const struct dquot_operations dquot_operations; |
0d54b217 | 139 | extern const struct quotactl_ops vfs_quotactl_ops; |
1da177e4 LT |
140 | |
141 | #define sb_dquot_ops (&dquot_operations) | |
142 | #define sb_quotactl_ops (&vfs_quotactl_ops) | |
143 | ||
850b201b | 144 | /* Cannot be called inside a transaction */ |
b85f4b87 | 145 | static inline int vfs_dq_off(struct super_block *sb, int remount) |
1da177e4 LT |
146 | { |
147 | int ret = -ENOSYS; | |
148 | ||
0ff5af83 JK |
149 | if (sb->s_qcop && sb->s_qcop->quota_off) |
150 | ret = sb->s_qcop->quota_off(sb, -1, remount); | |
151 | return ret; | |
152 | } | |
153 | ||
1da177e4 LT |
154 | #else |
155 | ||
f55abc0f | 156 | static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type) |
03b06343 JK |
157 | { |
158 | return 0; | |
159 | } | |
160 | ||
f55abc0f | 161 | static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type) |
03b06343 JK |
162 | { |
163 | return 0; | |
164 | } | |
165 | ||
166 | static inline int sb_has_quota_suspended(struct super_block *sb, int type) | |
167 | { | |
168 | return 0; | |
169 | } | |
170 | ||
171 | static inline int sb_any_quota_suspended(struct super_block *sb) | |
172 | { | |
173 | return 0; | |
174 | } | |
74abb989 | 175 | |
f55abc0f JK |
176 | /* Does kernel know about any quota information for given sb + type? */ |
177 | static inline int sb_has_quota_loaded(struct super_block *sb, int type) | |
178 | { | |
179 | return 0; | |
180 | } | |
181 | ||
182 | static inline int sb_any_quota_loaded(struct super_block *sb) | |
183 | { | |
184 | return 0; | |
185 | } | |
186 | ||
187 | static inline int sb_has_quota_active(struct super_block *sb, int type) | |
188 | { | |
189 | return 0; | |
190 | } | |
191 | ||
192 | static inline int sb_any_quota_active(struct super_block *sb) | |
193 | { | |
194 | return 0; | |
195 | } | |
196 | ||
1da177e4 LT |
197 | /* |
198 | * NO-OP when quota not configured. | |
199 | */ | |
200 | #define sb_dquot_ops (NULL) | |
201 | #define sb_quotactl_ops (NULL) | |
50f8c370 | 202 | |
871a2931 | 203 | static inline void dquot_initialize(struct inode *inode) |
50f8c370 AM |
204 | { |
205 | } | |
206 | ||
9f754758 | 207 | static inline void dquot_drop(struct inode *inode) |
50f8c370 AM |
208 | { |
209 | } | |
210 | ||
63936dda | 211 | static inline int dquot_alloc_inode(const struct inode *inode) |
50f8c370 AM |
212 | { |
213 | return 0; | |
214 | } | |
215 | ||
63936dda | 216 | static inline void dquot_free_inode(const struct inode *inode) |
50f8c370 AM |
217 | { |
218 | } | |
219 | ||
b85f4b87 | 220 | static inline int vfs_dq_off(struct super_block *sb, int remount) |
50f8c370 AM |
221 | { |
222 | return 0; | |
223 | } | |
224 | ||
b85f4b87 | 225 | static inline int vfs_dq_quota_on_remount(struct super_block *sb) |
50f8c370 AM |
226 | { |
227 | return 0; | |
228 | } | |
229 | ||
b43fa828 | 230 | static inline int dquot_transfer(struct inode *inode, struct iattr *iattr) |
50f8c370 AM |
231 | { |
232 | return 0; | |
233 | } | |
234 | ||
5dd4056d | 235 | static inline int __dquot_alloc_space(struct inode *inode, qsize_t number, |
56246f9a | 236 | int flags) |
1da177e4 | 237 | { |
56246f9a | 238 | if (!(flags & DQUOT_SPACE_RESERVE)) |
5dd4056d | 239 | inode_add_bytes(inode, number); |
1da177e4 LT |
240 | return 0; |
241 | } | |
242 | ||
5dd4056d | 243 | static inline void __dquot_free_space(struct inode *inode, qsize_t number, |
56246f9a | 244 | int flags) |
1da177e4 | 245 | { |
56246f9a | 246 | if (!(flags & DQUOT_SPACE_RESERVE)) |
5dd4056d | 247 | inode_sub_bytes(inode, number); |
1da177e4 LT |
248 | } |
249 | ||
5dd4056d | 250 | static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number) |
1da177e4 | 251 | { |
5dd4056d | 252 | inode_add_bytes(inode, number); |
1da177e4 LT |
253 | return 0; |
254 | } | |
255 | ||
871a2931 CH |
256 | #define dquot_file_open generic_file_open |
257 | ||
5dd4056d CH |
258 | #endif /* CONFIG_QUOTA */ |
259 | ||
260 | static inline int dquot_alloc_space_nodirty(struct inode *inode, qsize_t nr) | |
1da177e4 | 261 | { |
56246f9a | 262 | return __dquot_alloc_space(inode, nr, DQUOT_SPACE_WARN); |
1da177e4 LT |
263 | } |
264 | ||
5dd4056d | 265 | static inline int dquot_alloc_space(struct inode *inode, qsize_t nr) |
f18df228 | 266 | { |
5dd4056d CH |
267 | int ret; |
268 | ||
269 | ret = dquot_alloc_space_nodirty(inode, nr); | |
270 | if (!ret) | |
271 | mark_inode_dirty(inode); | |
272 | return ret; | |
f18df228 MC |
273 | } |
274 | ||
5dd4056d | 275 | static inline int dquot_alloc_block_nodirty(struct inode *inode, qsize_t nr) |
740d9dcd | 276 | { |
5dd4056d | 277 | return dquot_alloc_space_nodirty(inode, nr << inode->i_blkbits); |
740d9dcd MC |
278 | } |
279 | ||
5dd4056d | 280 | static inline int dquot_alloc_block(struct inode *inode, qsize_t nr) |
740d9dcd | 281 | { |
5dd4056d | 282 | return dquot_alloc_space(inode, nr << inode->i_blkbits); |
740d9dcd MC |
283 | } |
284 | ||
5dd4056d | 285 | static inline int dquot_prealloc_block_nodirty(struct inode *inode, qsize_t nr) |
1da177e4 | 286 | { |
56246f9a | 287 | return __dquot_alloc_space(inode, nr << inode->i_blkbits, 0); |
1da177e4 LT |
288 | } |
289 | ||
5dd4056d | 290 | static inline int dquot_prealloc_block(struct inode *inode, qsize_t nr) |
1da177e4 | 291 | { |
5dd4056d | 292 | int ret; |
1da177e4 | 293 | |
5dd4056d CH |
294 | ret = dquot_prealloc_block_nodirty(inode, nr); |
295 | if (!ret) | |
296 | mark_inode_dirty(inode); | |
297 | return ret; | |
03f6e92b JK |
298 | } |
299 | ||
5dd4056d | 300 | static inline int dquot_reserve_block(struct inode *inode, qsize_t nr) |
03f6e92b | 301 | { |
56246f9a ES |
302 | return __dquot_alloc_space(inode, nr << inode->i_blkbits, |
303 | DQUOT_SPACE_WARN|DQUOT_SPACE_RESERVE); | |
03f6e92b JK |
304 | } |
305 | ||
5dd4056d | 306 | static inline int dquot_claim_block(struct inode *inode, qsize_t nr) |
03f6e92b | 307 | { |
5dd4056d | 308 | int ret; |
03f6e92b | 309 | |
5dd4056d CH |
310 | ret = dquot_claim_space_nodirty(inode, nr << inode->i_blkbits); |
311 | if (!ret) | |
312 | mark_inode_dirty(inode); | |
313 | return ret; | |
03f6e92b JK |
314 | } |
315 | ||
5dd4056d | 316 | static inline void dquot_free_space_nodirty(struct inode *inode, qsize_t nr) |
f18df228 | 317 | { |
5dd4056d | 318 | __dquot_free_space(inode, nr, 0); |
f18df228 MC |
319 | } |
320 | ||
5dd4056d | 321 | static inline void dquot_free_space(struct inode *inode, qsize_t nr) |
740d9dcd | 322 | { |
5dd4056d CH |
323 | dquot_free_space_nodirty(inode, nr); |
324 | mark_inode_dirty(inode); | |
740d9dcd MC |
325 | } |
326 | ||
5dd4056d | 327 | static inline void dquot_free_block_nodirty(struct inode *inode, qsize_t nr) |
740d9dcd | 328 | { |
5dd4056d | 329 | dquot_free_space_nodirty(inode, nr << inode->i_blkbits); |
740d9dcd MC |
330 | } |
331 | ||
5dd4056d | 332 | static inline void dquot_free_block(struct inode *inode, qsize_t nr) |
03f6e92b | 333 | { |
5dd4056d | 334 | dquot_free_space(inode, nr << inode->i_blkbits); |
03f6e92b JK |
335 | } |
336 | ||
5dd4056d CH |
337 | static inline void dquot_release_reservation_block(struct inode *inode, |
338 | qsize_t nr) | |
03f6e92b | 339 | { |
56246f9a | 340 | __dquot_free_space(inode, nr << inode->i_blkbits, DQUOT_SPACE_RESERVE); |
03f6e92b | 341 | } |
1da177e4 LT |
342 | |
343 | #endif /* _LINUX_QUOTAOPS_ */ |