]> bbs.cooldavid.org Git - net-next-2.6.git/blame - include/linux/quotaops.h
quota: unify ->get_dqblk
[net-next-2.6.git] / include / linux / quotaops.h
CommitLineData
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
12static 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
22void inode_add_rsv_space(struct inode *inode, qsize_t number);
23void inode_claim_rsv_space(struct inode *inode, qsize_t number);
24void inode_sub_rsv_space(struct inode *inode, qsize_t number);
25
871a2931 26void dquot_initialize(struct inode *inode);
9f754758 27void dquot_drop(struct inode *inode);
3d9ea253
JK
28struct dquot *dqget(struct super_block *sb, unsigned int id, int type);
29void dqput(struct dquot *dquot);
12c77527
JK
30int dquot_scan_active(struct super_block *sb,
31 int (*fn)(struct dquot *dquot, unsigned long priv),
32 unsigned long priv);
7d9056ba
JK
33struct dquot *dquot_alloc(struct super_block *sb, int type);
34void dquot_destroy(struct dquot *dquot);
b85f4b87 35
5dd4056d
CH
36int __dquot_alloc_space(struct inode *inode, qsize_t number,
37 int warn, int reserve);
38void __dquot_free_space(struct inode *inode, qsize_t number, int reserve);
b85f4b87 39
63936dda 40int dquot_alloc_inode(const struct inode *inode);
740d9dcd 41
5dd4056d 42int dquot_claim_space_nodirty(struct inode *inode, qsize_t number);
63936dda 43void dquot_free_inode(const struct inode *inode);
b85f4b87 44
b85f4b87
JK
45int dquot_commit(struct dquot *dquot);
46int dquot_acquire(struct dquot *dquot);
47int dquot_release(struct dquot *dquot);
48int dquot_commit_info(struct super_block *sb, int type);
49int dquot_mark_dquot_dirty(struct dquot *dquot);
50
907f4554
CH
51int dquot_file_open(struct inode *inode, struct file *file);
52
b85f4b87
JK
53int vfs_quota_on(struct super_block *sb, int type, int format_id,
54 char *path, int remount);
f55abc0f
JK
55int vfs_quota_enable(struct inode *inode, int type, int format_id,
56 unsigned int flags);
77e69dac
AV
57int vfs_quota_on_path(struct super_block *sb, int type, int format_id,
58 struct path *path);
b85f4b87
JK
59int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
60 int format_id, int type);
61int vfs_quota_off(struct super_block *sb, int type, int remount);
f55abc0f 62int vfs_quota_disable(struct super_block *sb, int type, unsigned int flags);
5fb324ad 63int vfs_quota_sync(struct super_block *sb, int type, int wait);
b85f4b87
JK
64int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
65int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
b9b2dd36
CH
66int vfs_get_dqblk(struct super_block *sb, int type, qid_t id,
67 struct fs_disk_quota *di);
b85f4b87
JK
68int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
69
b43fa828 70int dquot_transfer(struct inode *inode, struct iattr *iattr);
b85f4b87 71int vfs_dq_quota_on_remount(struct super_block *sb);
1da177e4 72
03b06343
JK
73static 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 82static 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 88static 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 94static 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 100static 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 109static 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 115static 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 123static 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 129static 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 137extern const struct dquot_operations dquot_operations;
0d54b217 138extern 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
850b201b 143/* Cannot be called inside a transaction */
b85f4b87 144static inline int vfs_dq_off(struct super_block *sb, int remount)
1da177e4
LT
145{
146 int ret = -ENOSYS;
147
0ff5af83
JK
148 if (sb->s_qcop && sb->s_qcop->quota_off)
149 ret = sb->s_qcop->quota_off(sb, -1, remount);
150 return ret;
151}
152
1da177e4
LT
153#else
154
f55abc0f 155static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type)
03b06343
JK
156{
157 return 0;
158}
159
f55abc0f 160static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type)
03b06343
JK
161{
162 return 0;
163}
164
165static inline int sb_has_quota_suspended(struct super_block *sb, int type)
166{
167 return 0;
168}
169
170static inline int sb_any_quota_suspended(struct super_block *sb)
171{
172 return 0;
173}
74abb989 174
f55abc0f
JK
175/* Does kernel know about any quota information for given sb + type? */
176static inline int sb_has_quota_loaded(struct super_block *sb, int type)
177{
178 return 0;
179}
180
181static inline int sb_any_quota_loaded(struct super_block *sb)
182{
183 return 0;
184}
185
186static inline int sb_has_quota_active(struct super_block *sb, int type)
187{
188 return 0;
189}
190
191static inline int sb_any_quota_active(struct super_block *sb)
192{
193 return 0;
194}
195
1da177e4
LT
196/*
197 * NO-OP when quota not configured.
198 */
199#define sb_dquot_ops (NULL)
200#define sb_quotactl_ops (NULL)
50f8c370 201
871a2931 202static inline void dquot_initialize(struct inode *inode)
50f8c370
AM
203{
204}
205
9f754758 206static inline void dquot_drop(struct inode *inode)
50f8c370
AM
207{
208}
209
63936dda 210static inline int dquot_alloc_inode(const struct inode *inode)
50f8c370
AM
211{
212 return 0;
213}
214
63936dda 215static inline void dquot_free_inode(const struct inode *inode)
50f8c370
AM
216{
217}
218
b85f4b87 219static inline int vfs_dq_off(struct super_block *sb, int remount)
50f8c370
AM
220{
221 return 0;
222}
223
b85f4b87 224static inline int vfs_dq_quota_on_remount(struct super_block *sb)
50f8c370
AM
225{
226 return 0;
227}
228
b43fa828 229static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
50f8c370
AM
230{
231 return 0;
232}
233
5dd4056d
CH
234static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
235 int warn, int reserve)
1da177e4 236{
5dd4056d
CH
237 if (!reserve)
238 inode_add_bytes(inode, number);
1da177e4
LT
239 return 0;
240}
241
5dd4056d
CH
242static inline void __dquot_free_space(struct inode *inode, qsize_t number,
243 int reserve)
1da177e4 244{
5dd4056d
CH
245 if (!reserve)
246 inode_sub_bytes(inode, number);
1da177e4
LT
247}
248
5dd4056d 249static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
1da177e4 250{
5dd4056d 251 inode_add_bytes(inode, number);
1da177e4
LT
252 return 0;
253}
254
871a2931
CH
255#define dquot_file_open generic_file_open
256
5dd4056d
CH
257#endif /* CONFIG_QUOTA */
258
259static inline int dquot_alloc_space_nodirty(struct inode *inode, qsize_t nr)
1da177e4 260{
5dd4056d 261 return __dquot_alloc_space(inode, nr, 1, 0);
1da177e4
LT
262}
263
5dd4056d 264static inline int dquot_alloc_space(struct inode *inode, qsize_t nr)
f18df228 265{
5dd4056d
CH
266 int ret;
267
268 ret = dquot_alloc_space_nodirty(inode, nr);
269 if (!ret)
270 mark_inode_dirty(inode);
271 return ret;
f18df228
MC
272}
273
5dd4056d 274static inline int dquot_alloc_block_nodirty(struct inode *inode, qsize_t nr)
740d9dcd 275{
5dd4056d 276 return dquot_alloc_space_nodirty(inode, nr << inode->i_blkbits);
740d9dcd
MC
277}
278
5dd4056d 279static inline int dquot_alloc_block(struct inode *inode, qsize_t nr)
740d9dcd 280{
5dd4056d 281 return dquot_alloc_space(inode, nr << inode->i_blkbits);
740d9dcd
MC
282}
283
5dd4056d 284static inline int dquot_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
1da177e4 285{
5dd4056d 286 return __dquot_alloc_space(inode, nr << inode->i_blkbits, 0, 0);
1da177e4
LT
287}
288
5dd4056d 289static inline int dquot_prealloc_block(struct inode *inode, qsize_t nr)
1da177e4 290{
5dd4056d 291 int ret;
1da177e4 292
5dd4056d
CH
293 ret = dquot_prealloc_block_nodirty(inode, nr);
294 if (!ret)
295 mark_inode_dirty(inode);
296 return ret;
03f6e92b
JK
297}
298
5dd4056d 299static inline int dquot_reserve_block(struct inode *inode, qsize_t nr)
03f6e92b 300{
5dd4056d 301 return __dquot_alloc_space(inode, nr << inode->i_blkbits, 1, 1);
03f6e92b
JK
302}
303
5dd4056d 304static inline int dquot_claim_block(struct inode *inode, qsize_t nr)
03f6e92b 305{
5dd4056d 306 int ret;
03f6e92b 307
5dd4056d
CH
308 ret = dquot_claim_space_nodirty(inode, nr << inode->i_blkbits);
309 if (!ret)
310 mark_inode_dirty(inode);
311 return ret;
03f6e92b
JK
312}
313
5dd4056d 314static inline void dquot_free_space_nodirty(struct inode *inode, qsize_t nr)
f18df228 315{
5dd4056d 316 __dquot_free_space(inode, nr, 0);
f18df228
MC
317}
318
5dd4056d 319static inline void dquot_free_space(struct inode *inode, qsize_t nr)
740d9dcd 320{
5dd4056d
CH
321 dquot_free_space_nodirty(inode, nr);
322 mark_inode_dirty(inode);
740d9dcd
MC
323}
324
5dd4056d 325static inline void dquot_free_block_nodirty(struct inode *inode, qsize_t nr)
740d9dcd 326{
5dd4056d 327 dquot_free_space_nodirty(inode, nr << inode->i_blkbits);
740d9dcd
MC
328}
329
5dd4056d 330static inline void dquot_free_block(struct inode *inode, qsize_t nr)
03f6e92b 331{
5dd4056d 332 dquot_free_space(inode, nr << inode->i_blkbits);
03f6e92b
JK
333}
334
5dd4056d
CH
335static inline void dquot_release_reservation_block(struct inode *inode,
336 qsize_t nr)
03f6e92b 337{
5dd4056d 338 __dquot_free_space(inode, nr << inode->i_blkbits, 1);
03f6e92b 339}
1da177e4
LT
340
341#endif /* _LINUX_QUOTAOPS_ */