]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - include/linux/quotaops.h
Merge tag 'iio-for-4.13b' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23...
[mirror_ubuntu-artful-kernel.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) ||
8e96e3b7
EB
25 (ia->ia_valid & ATTR_UID && !uid_eq(ia->ia_uid, inode->i_uid)) ||
26 (ia->ia_valid & ATTR_GID && !gid_eq(ia->ia_gid, inode->i_gid));
12755627
DM
27}
28
1da177e4
LT
29#if defined(CONFIG_QUOTA)
30
fb5ffb0e
JZ
31#define quota_error(sb, fmt, args...) \
32 __quota_error((sb), __func__, fmt , ## args)
33
b9075fa9 34extern __printf(3, 4)
055adcbd
JP
35void __quota_error(struct super_block *sb, const char *func,
36 const char *fmt, ...);
fb5ffb0e 37
1da177e4
LT
38/*
39 * declaration of quota_function calls in kernel.
40 */
c469070a
DM
41void inode_add_rsv_space(struct inode *inode, qsize_t number);
42void inode_claim_rsv_space(struct inode *inode, qsize_t number);
43void inode_sub_rsv_space(struct inode *inode, qsize_t number);
1c8924eb 44void inode_reclaim_rsv_space(struct inode *inode, qsize_t number);
c469070a 45
6184fc0b 46int dquot_initialize(struct inode *inode);
b8cb5a54 47bool dquot_initialize_needed(struct inode *inode);
9f754758 48void dquot_drop(struct inode *inode);
aca645a6 49struct dquot *dqget(struct super_block *sb, struct kqid qid);
9f985cb6
JK
50static inline struct dquot *dqgrab(struct dquot *dquot)
51{
52 /* Make sure someone else has active reference to dquot */
53 WARN_ON_ONCE(!atomic_read(&dquot->dq_count));
54 WARN_ON_ONCE(!test_bit(DQ_ACTIVE_B, &dquot->dq_flags));
55 atomic_inc(&dquot->dq_count);
56 return dquot;
57}
3d9ea253 58void dqput(struct dquot *dquot);
12c77527
JK
59int dquot_scan_active(struct super_block *sb,
60 int (*fn)(struct dquot *dquot, unsigned long priv),
61 unsigned long priv);
7d9056ba
JK
62struct dquot *dquot_alloc(struct super_block *sb, int type);
63void dquot_destroy(struct dquot *dquot);
b85f4b87 64
56246f9a
ES
65int __dquot_alloc_space(struct inode *inode, qsize_t number, int flags);
66void __dquot_free_space(struct inode *inode, qsize_t number, int flags);
b85f4b87 67
6bab3596 68int dquot_alloc_inode(struct inode *inode);
740d9dcd 69
5dd4056d 70int dquot_claim_space_nodirty(struct inode *inode, qsize_t number);
6bab3596 71void dquot_free_inode(struct inode *inode);
1c8924eb 72void dquot_reclaim_space_nodirty(struct inode *inode, qsize_t number);
b85f4b87 73
0f0dd62f
CH
74int dquot_disable(struct super_block *sb, int type, unsigned int flags);
75/* Suspend quotas on remount RO */
76static inline int dquot_suspend(struct super_block *sb, int type)
77{
78 return dquot_disable(sb, type, DQUOT_SUSPENDED);
79}
80int dquot_resume(struct super_block *sb, int type);
81
b85f4b87
JK
82int dquot_commit(struct dquot *dquot);
83int dquot_acquire(struct dquot *dquot);
84int dquot_release(struct dquot *dquot);
85int dquot_commit_info(struct super_block *sb, int type);
be6257b2 86int dquot_get_next_id(struct super_block *sb, struct kqid *qid);
b85f4b87
JK
87int dquot_mark_dquot_dirty(struct dquot *dquot);
88
907f4554
CH
89int dquot_file_open(struct inode *inode, struct file *file);
90
287a8095 91int dquot_enable(struct inode *inode, int type, int format_id,
f55abc0f 92 unsigned int flags);
f00c9e44 93int dquot_quota_on(struct super_block *sb, int type, int format_id,
8c54ca9c 94 const struct path *path);
287a8095 95int dquot_quota_on_mount(struct super_block *sb, char *qf_name,
b85f4b87 96 int format_id, int type);
287a8095 97int dquot_quota_off(struct super_block *sb, int type);
ceed1723
JK
98int dquot_writeback_dquots(struct super_block *sb, int type);
99int dquot_quota_sync(struct super_block *sb, int type);
0a240339 100int dquot_get_state(struct super_block *sb, struct qc_state *state);
5eacb2ac 101int dquot_set_dqinfo(struct super_block *sb, int type, struct qc_info *ii);
74a8a103 102int dquot_get_dqblk(struct super_block *sb, struct kqid id,
14bf61ff 103 struct qc_dqblk *di);
be6257b2
JK
104int dquot_get_next_dqblk(struct super_block *sb, struct kqid *id,
105 struct qc_dqblk *di);
74a8a103 106int dquot_set_dqblk(struct super_block *sb, struct kqid id,
14bf61ff 107 struct qc_dqblk *di);
b85f4b87 108
bc8e5f07 109int __dquot_transfer(struct inode *inode, struct dquot **transfer_to);
b43fa828 110int dquot_transfer(struct inode *inode, struct iattr *iattr);
1da177e4 111
03b06343
JK
112static inline struct mem_dqinfo *sb_dqinfo(struct super_block *sb, int type)
113{
114 return sb_dqopt(sb)->info + type;
115}
74abb989
JK
116
117/*
118 * Functions for checking status of quota
119 */
120
ad1e6e8d 121static inline bool sb_has_quota_usage_enabled(struct super_block *sb, int type)
03b06343 122{
f55abc0f
JK
123 return sb_dqopt(sb)->flags &
124 dquot_state_flag(DQUOT_USAGE_ENABLED, type);
03b06343 125}
74abb989 126
ad1e6e8d 127static inline bool sb_has_quota_limits_enabled(struct super_block *sb, int type)
03b06343 128{
f55abc0f
JK
129 return sb_dqopt(sb)->flags &
130 dquot_state_flag(DQUOT_LIMITS_ENABLED, type);
03b06343 131}
74abb989 132
ad1e6e8d 133static inline bool sb_has_quota_suspended(struct super_block *sb, int type)
03b06343 134{
f55abc0f
JK
135 return sb_dqopt(sb)->flags &
136 dquot_state_flag(DQUOT_SUSPENDED, type);
03b06343 137}
74abb989 138
ad1e6e8d 139static inline unsigned sb_any_quota_suspended(struct super_block *sb)
03b06343 140{
78197024 141 return dquot_state_types(sb_dqopt(sb)->flags, DQUOT_SUSPENDED);
03b06343 142}
74abb989 143
f55abc0f 144/* Does kernel know about any quota information for given sb + type? */
ad1e6e8d 145static inline bool sb_has_quota_loaded(struct super_block *sb, int type)
f55abc0f
JK
146{
147 /* Currently if anything is on, then quota usage is on as well */
148 return sb_has_quota_usage_enabled(sb, type);
149}
150
ad1e6e8d 151static inline unsigned sb_any_quota_loaded(struct super_block *sb)
f55abc0f 152{
78197024 153 return dquot_state_types(sb_dqopt(sb)->flags, DQUOT_USAGE_ENABLED);
f55abc0f
JK
154}
155
ad1e6e8d 156static inline bool sb_has_quota_active(struct super_block *sb, int type)
f55abc0f
JK
157{
158 return sb_has_quota_loaded(sb, type) &&
159 !sb_has_quota_suspended(sb, type);
160}
161
1da177e4
LT
162/*
163 * Operations supported for diskquotas.
164 */
61e225dc 165extern const struct dquot_operations dquot_operations;
3e2af67e 166extern const struct quotactl_ops dquot_quotactl_sysfile_ops;
0ff5af83 167
1da177e4
LT
168#else
169
f55abc0f 170static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type)
03b06343
JK
171{
172 return 0;
173}
174
f55abc0f 175static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type)
03b06343
JK
176{
177 return 0;
178}
179
180static inline int sb_has_quota_suspended(struct super_block *sb, int type)
181{
182 return 0;
183}
184
185static inline int sb_any_quota_suspended(struct super_block *sb)
186{
187 return 0;
188}
74abb989 189
f55abc0f
JK
190/* Does kernel know about any quota information for given sb + type? */
191static inline int sb_has_quota_loaded(struct super_block *sb, int type)
192{
193 return 0;
194}
195
196static inline int sb_any_quota_loaded(struct super_block *sb)
197{
198 return 0;
199}
200
201static inline int sb_has_quota_active(struct super_block *sb, int type)
202{
203 return 0;
204}
205
6184fc0b 206static inline int dquot_initialize(struct inode *inode)
50f8c370 207{
6184fc0b 208 return 0;
50f8c370
AM
209}
210
b8cb5a54
TE
211static inline bool dquot_initialize_needed(struct inode *inode)
212{
213 return false;
214}
215
9f754758 216static inline void dquot_drop(struct inode *inode)
50f8c370
AM
217{
218}
219
6bab3596 220static inline int dquot_alloc_inode(struct inode *inode)
50f8c370
AM
221{
222 return 0;
223}
224
6bab3596 225static inline void dquot_free_inode(struct inode *inode)
50f8c370
AM
226{
227}
228
b43fa828 229static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
50f8c370
AM
230{
231 return 0;
232}
233
5dd4056d 234static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
56246f9a 235 int flags)
1da177e4 236{
56246f9a 237 if (!(flags & DQUOT_SPACE_RESERVE))
5dd4056d 238 inode_add_bytes(inode, number);
1da177e4
LT
239 return 0;
240}
241
5dd4056d 242static inline void __dquot_free_space(struct inode *inode, qsize_t number,
56246f9a 243 int flags)
1da177e4 244{
56246f9a 245 if (!(flags & DQUOT_SPACE_RESERVE))
5dd4056d 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
1c8924eb
JK
255static inline int dquot_reclaim_space_nodirty(struct inode *inode,
256 qsize_t number)
257{
258 inode_sub_bytes(inode, number);
259 return 0;
260}
261
0f0dd62f
CH
262static inline int dquot_disable(struct super_block *sb, int type,
263 unsigned int flags)
264{
265 return 0;
266}
267
268static inline int dquot_suspend(struct super_block *sb, int type)
269{
270 return 0;
271}
272
273static inline int dquot_resume(struct super_block *sb, int type)
274{
275 return 0;
1da177e4
LT
276}
277
871a2931
CH
278#define dquot_file_open generic_file_open
279
ceed1723
JK
280static inline int dquot_writeback_dquots(struct super_block *sb, int type)
281{
282 return 0;
283}
284
5dd4056d
CH
285#endif /* CONFIG_QUOTA */
286
287static inline int dquot_alloc_space_nodirty(struct inode *inode, qsize_t nr)
1da177e4 288{
56246f9a 289 return __dquot_alloc_space(inode, nr, DQUOT_SPACE_WARN);
1da177e4
LT
290}
291
0e05842b
ES
292static inline void dquot_alloc_space_nofail(struct inode *inode, qsize_t nr)
293{
294 __dquot_alloc_space(inode, nr, DQUOT_SPACE_WARN|DQUOT_SPACE_NOFAIL);
43d2932d 295 mark_inode_dirty_sync(inode);
1da177e4
LT
296}
297
5dd4056d 298static inline int dquot_alloc_space(struct inode *inode, qsize_t nr)
f18df228 299{
5dd4056d
CH
300 int ret;
301
302 ret = dquot_alloc_space_nodirty(inode, nr);
d530148a
SL
303 if (!ret) {
304 /*
305 * Mark inode fully dirty. Since we are allocating blocks, inode
306 * would become fully dirty soon anyway and it reportedly
250df6ed 307 * reduces lock contention.
d530148a
SL
308 */
309 mark_inode_dirty(inode);
310 }
5dd4056d 311 return ret;
f18df228
MC
312}
313
5dd4056d 314static inline int dquot_alloc_block_nodirty(struct inode *inode, qsize_t nr)
740d9dcd 315{
5dd4056d 316 return dquot_alloc_space_nodirty(inode, nr << inode->i_blkbits);
740d9dcd
MC
317}
318
0e05842b
ES
319static inline void dquot_alloc_block_nofail(struct inode *inode, qsize_t nr)
320{
321 dquot_alloc_space_nofail(inode, nr << inode->i_blkbits);
322}
323
5dd4056d 324static inline int dquot_alloc_block(struct inode *inode, qsize_t nr)
740d9dcd 325{
5dd4056d 326 return dquot_alloc_space(inode, nr << inode->i_blkbits);
740d9dcd
MC
327}
328
5dd4056d 329static inline int dquot_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
1da177e4 330{
56246f9a 331 return __dquot_alloc_space(inode, nr << inode->i_blkbits, 0);
1da177e4
LT
332}
333
5dd4056d 334static inline int dquot_prealloc_block(struct inode *inode, qsize_t nr)
1da177e4 335{
5dd4056d 336 int ret;
1da177e4 337
5dd4056d
CH
338 ret = dquot_prealloc_block_nodirty(inode, nr);
339 if (!ret)
43d2932d 340 mark_inode_dirty_sync(inode);
5dd4056d 341 return ret;
03f6e92b
JK
342}
343
5dd4056d 344static inline int dquot_reserve_block(struct inode *inode, qsize_t nr)
03f6e92b 345{
56246f9a
ES
346 return __dquot_alloc_space(inode, nr << inode->i_blkbits,
347 DQUOT_SPACE_WARN|DQUOT_SPACE_RESERVE);
03f6e92b
JK
348}
349
5dd4056d 350static inline int dquot_claim_block(struct inode *inode, qsize_t nr)
03f6e92b 351{
5dd4056d 352 int ret;
03f6e92b 353
5dd4056d
CH
354 ret = dquot_claim_space_nodirty(inode, nr << inode->i_blkbits);
355 if (!ret)
43d2932d 356 mark_inode_dirty_sync(inode);
5dd4056d 357 return ret;
03f6e92b
JK
358}
359
1c8924eb
JK
360static inline void dquot_reclaim_block(struct inode *inode, qsize_t nr)
361{
362 dquot_reclaim_space_nodirty(inode, nr << inode->i_blkbits);
363 mark_inode_dirty_sync(inode);
364}
365
5dd4056d 366static inline void dquot_free_space_nodirty(struct inode *inode, qsize_t nr)
f18df228 367{
5dd4056d 368 __dquot_free_space(inode, nr, 0);
f18df228
MC
369}
370
5dd4056d 371static inline void dquot_free_space(struct inode *inode, qsize_t nr)
740d9dcd 372{
5dd4056d 373 dquot_free_space_nodirty(inode, nr);
43d2932d 374 mark_inode_dirty_sync(inode);
740d9dcd
MC
375}
376
5dd4056d 377static inline void dquot_free_block_nodirty(struct inode *inode, qsize_t nr)
740d9dcd 378{
5dd4056d 379 dquot_free_space_nodirty(inode, nr << inode->i_blkbits);
740d9dcd
MC
380}
381
5dd4056d 382static inline void dquot_free_block(struct inode *inode, qsize_t nr)
03f6e92b 383{
5dd4056d 384 dquot_free_space(inode, nr << inode->i_blkbits);
03f6e92b
JK
385}
386
5dd4056d
CH
387static inline void dquot_release_reservation_block(struct inode *inode,
388 qsize_t nr)
03f6e92b 389{
56246f9a 390 __dquot_free_space(inode, nr << inode->i_blkbits, DQUOT_SPACE_RESERVE);
03f6e92b 391}
1da177e4 392
d3b86324
JK
393unsigned int qtype_enforce_flag(int type);
394
1da177e4 395#endif /* _LINUX_QUOTAOPS_ */