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