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