]>
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 | ||
871a2931 | 26 | void dquot_initialize(struct inode *inode); |
9f754758 | 27 | void 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 | 35 | |
5dd4056d CH |
36 | int __dquot_alloc_space(struct inode *inode, qsize_t number, |
37 | int warn, int reserve); | |
38 | void __dquot_free_space(struct inode *inode, qsize_t number, int reserve); | |
b85f4b87 | 39 | |
63936dda | 40 | int dquot_alloc_inode(const struct inode *inode); |
740d9dcd | 41 | |
5dd4056d | 42 | int dquot_claim_space_nodirty(struct inode *inode, qsize_t number); |
63936dda | 43 | void dquot_free_inode(const struct inode *inode); |
b85f4b87 | 44 | |
b85f4b87 JK |
45 | int dquot_commit(struct dquot *dquot); |
46 | int dquot_acquire(struct dquot *dquot); | |
47 | int dquot_release(struct dquot *dquot); | |
48 | int dquot_commit_info(struct super_block *sb, int type); | |
49 | int dquot_mark_dquot_dirty(struct dquot *dquot); | |
50 | ||
907f4554 CH |
51 | int dquot_file_open(struct inode *inode, struct file *file); |
52 | ||
b85f4b87 JK |
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); | |
b9b2dd36 CH |
66 | int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, |
67 | struct fs_disk_quota *di); | |
c472b432 CH |
68 | int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, |
69 | struct fs_disk_quota *di); | |
b85f4b87 | 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 CH |
235 | static inline int __dquot_alloc_space(struct inode *inode, qsize_t number, |
236 | int warn, int reserve) | |
1da177e4 | 237 | { |
5dd4056d CH |
238 | if (!reserve) |
239 | inode_add_bytes(inode, number); | |
1da177e4 LT |
240 | return 0; |
241 | } | |
242 | ||
5dd4056d CH |
243 | static inline void __dquot_free_space(struct inode *inode, qsize_t number, |
244 | int reserve) | |
1da177e4 | 245 | { |
5dd4056d CH |
246 | if (!reserve) |
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 | { |
5dd4056d | 262 | return __dquot_alloc_space(inode, nr, 1, 0); |
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 | { |
5dd4056d | 287 | return __dquot_alloc_space(inode, nr << inode->i_blkbits, 0, 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 | { |
5dd4056d | 302 | return __dquot_alloc_space(inode, nr << inode->i_blkbits, 1, 1); |
03f6e92b JK |
303 | } |
304 | ||
5dd4056d | 305 | static inline int dquot_claim_block(struct inode *inode, qsize_t nr) |
03f6e92b | 306 | { |
5dd4056d | 307 | int ret; |
03f6e92b | 308 | |
5dd4056d CH |
309 | ret = dquot_claim_space_nodirty(inode, nr << inode->i_blkbits); |
310 | if (!ret) | |
311 | mark_inode_dirty(inode); | |
312 | return ret; | |
03f6e92b JK |
313 | } |
314 | ||
5dd4056d | 315 | static inline void dquot_free_space_nodirty(struct inode *inode, qsize_t nr) |
f18df228 | 316 | { |
5dd4056d | 317 | __dquot_free_space(inode, nr, 0); |
f18df228 MC |
318 | } |
319 | ||
5dd4056d | 320 | static inline void dquot_free_space(struct inode *inode, qsize_t nr) |
740d9dcd | 321 | { |
5dd4056d CH |
322 | dquot_free_space_nodirty(inode, nr); |
323 | mark_inode_dirty(inode); | |
740d9dcd MC |
324 | } |
325 | ||
5dd4056d | 326 | static inline void dquot_free_block_nodirty(struct inode *inode, qsize_t nr) |
740d9dcd | 327 | { |
5dd4056d | 328 | dquot_free_space_nodirty(inode, nr << inode->i_blkbits); |
740d9dcd MC |
329 | } |
330 | ||
5dd4056d | 331 | static inline void dquot_free_block(struct inode *inode, qsize_t nr) |
03f6e92b | 332 | { |
5dd4056d | 333 | dquot_free_space(inode, nr << inode->i_blkbits); |
03f6e92b JK |
334 | } |
335 | ||
5dd4056d CH |
336 | static inline void dquot_release_reservation_block(struct inode *inode, |
337 | qsize_t nr) | |
03f6e92b | 338 | { |
5dd4056d | 339 | __dquot_free_space(inode, nr << inode->i_blkbits, 1); |
03f6e92b | 340 | } |
1da177e4 LT |
341 | |
342 | #endif /* _LINUX_QUOTAOPS_ */ |