xref: /openbmc/linux/include/linux/quotaops.h (revision 56246f9a)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * Definitions for diskquota-operations. When diskquota is configured these
31da177e4SLinus Torvalds  * macros expand to the right source-code.
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  * Author:  Marco van Wieringen <mvw@planets.elm.net>
61da177e4SLinus Torvalds  */
71da177e4SLinus Torvalds #ifndef _LINUX_QUOTAOPS_
81da177e4SLinus Torvalds #define _LINUX_QUOTAOPS_
91da177e4SLinus Torvalds 
101da177e4SLinus Torvalds #include <linux/fs.h>
111da177e4SLinus Torvalds 
1256246f9aSEric Sandeen #define DQUOT_SPACE_WARN	0x1
1356246f9aSEric Sandeen #define DQUOT_SPACE_RESERVE	0x2
1456246f9aSEric Sandeen 
1503b06343SJan Kara static inline struct quota_info *sb_dqopt(struct super_block *sb)
1603b06343SJan Kara {
1703b06343SJan Kara 	return &sb->s_dquot;
1803b06343SJan Kara }
1974abb989SJan Kara 
201da177e4SLinus Torvalds #if defined(CONFIG_QUOTA)
211da177e4SLinus Torvalds 
221da177e4SLinus Torvalds /*
231da177e4SLinus Torvalds  * declaration of quota_function calls in kernel.
241da177e4SLinus Torvalds  */
25c469070aSDmitry Monakhov void inode_add_rsv_space(struct inode *inode, qsize_t number);
26c469070aSDmitry Monakhov void inode_claim_rsv_space(struct inode *inode, qsize_t number);
27c469070aSDmitry Monakhov void inode_sub_rsv_space(struct inode *inode, qsize_t number);
28c469070aSDmitry Monakhov 
29871a2931SChristoph Hellwig void dquot_initialize(struct inode *inode);
309f754758SChristoph Hellwig void dquot_drop(struct inode *inode);
313d9ea253SJan Kara struct dquot *dqget(struct super_block *sb, unsigned int id, int type);
323d9ea253SJan Kara void dqput(struct dquot *dquot);
3312c77527SJan Kara int dquot_scan_active(struct super_block *sb,
3412c77527SJan Kara 		      int (*fn)(struct dquot *dquot, unsigned long priv),
3512c77527SJan Kara 		      unsigned long priv);
367d9056baSJan Kara struct dquot *dquot_alloc(struct super_block *sb, int type);
377d9056baSJan Kara void dquot_destroy(struct dquot *dquot);
381da177e4SLinus Torvalds 
3956246f9aSEric Sandeen int __dquot_alloc_space(struct inode *inode, qsize_t number, int flags);
4056246f9aSEric Sandeen void __dquot_free_space(struct inode *inode, qsize_t number, int flags);
415dd4056dSChristoph Hellwig 
4263936ddaSChristoph Hellwig int dquot_alloc_inode(const struct inode *inode);
431da177e4SLinus Torvalds 
445dd4056dSChristoph Hellwig int dquot_claim_space_nodirty(struct inode *inode, qsize_t number);
4563936ddaSChristoph Hellwig void dquot_free_inode(const struct inode *inode);
461da177e4SLinus Torvalds 
47b85f4b87SJan Kara int dquot_commit(struct dquot *dquot);
48b85f4b87SJan Kara int dquot_acquire(struct dquot *dquot);
49b85f4b87SJan Kara int dquot_release(struct dquot *dquot);
50b85f4b87SJan Kara int dquot_commit_info(struct super_block *sb, int type);
51b85f4b87SJan Kara int dquot_mark_dquot_dirty(struct dquot *dquot);
521da177e4SLinus Torvalds 
53907f4554SChristoph Hellwig int dquot_file_open(struct inode *inode, struct file *file);
54907f4554SChristoph Hellwig 
55b85f4b87SJan Kara int vfs_quota_on(struct super_block *sb, int type, int format_id,
560ff5af83SJan Kara  	char *path, int remount);
57f55abc0fSJan Kara int vfs_quota_enable(struct inode *inode, int type, int format_id,
58f55abc0fSJan Kara 	unsigned int flags);
5977e69dacSAl Viro int vfs_quota_on_path(struct super_block *sb, int type, int format_id,
6077e69dacSAl Viro  	struct path *path);
61b85f4b87SJan Kara int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
6284de856eSChristoph Hellwig  	int format_id, int type);
63b85f4b87SJan Kara int vfs_quota_off(struct super_block *sb, int type, int remount);
64f55abc0fSJan Kara int vfs_quota_disable(struct super_block *sb, int type, unsigned int flags);
655fb324adSChristoph Hellwig int vfs_quota_sync(struct super_block *sb, int type, int wait);
66b85f4b87SJan Kara int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
67b85f4b87SJan Kara int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
68b85f4b87SJan Kara int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
69b85f4b87SJan Kara int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
70b85f4b87SJan Kara 
71b43fa828SChristoph Hellwig int dquot_transfer(struct inode *inode, struct iattr *iattr);
72b85f4b87SJan Kara int vfs_dq_quota_on_remount(struct super_block *sb);
731da177e4SLinus Torvalds 
7403b06343SJan Kara static inline struct mem_dqinfo *sb_dqinfo(struct super_block *sb, int type)
7503b06343SJan Kara {
7603b06343SJan Kara 	return sb_dqopt(sb)->info + type;
7703b06343SJan Kara }
7874abb989SJan Kara 
7974abb989SJan Kara /*
8074abb989SJan Kara  * Functions for checking status of quota
8174abb989SJan Kara  */
8274abb989SJan Kara 
83ad1e6e8dSDmitry Monakhov static inline bool sb_has_quota_usage_enabled(struct super_block *sb, int type)
8403b06343SJan Kara {
85f55abc0fSJan Kara 	return sb_dqopt(sb)->flags &
86f55abc0fSJan Kara 				dquot_state_flag(DQUOT_USAGE_ENABLED, type);
8703b06343SJan Kara }
8874abb989SJan Kara 
89ad1e6e8dSDmitry Monakhov static inline bool sb_has_quota_limits_enabled(struct super_block *sb, int type)
9003b06343SJan Kara {
91f55abc0fSJan Kara 	return sb_dqopt(sb)->flags &
92f55abc0fSJan Kara 				dquot_state_flag(DQUOT_LIMITS_ENABLED, type);
9303b06343SJan Kara }
9474abb989SJan Kara 
95ad1e6e8dSDmitry Monakhov static inline bool sb_has_quota_suspended(struct super_block *sb, int type)
9603b06343SJan Kara {
97f55abc0fSJan Kara 	return sb_dqopt(sb)->flags &
98f55abc0fSJan Kara 				dquot_state_flag(DQUOT_SUSPENDED, type);
9903b06343SJan Kara }
10074abb989SJan Kara 
101ad1e6e8dSDmitry Monakhov static inline unsigned sb_any_quota_suspended(struct super_block *sb)
10203b06343SJan Kara {
103ad1e6e8dSDmitry Monakhov 	unsigned type, tmsk = 0;
104ad1e6e8dSDmitry Monakhov 	for (type = 0; type < MAXQUOTAS; type++)
105ad1e6e8dSDmitry Monakhov 		tmsk |= sb_has_quota_suspended(sb, type) << type;
106ad1e6e8dSDmitry Monakhov 	return tmsk;
10703b06343SJan Kara }
10874abb989SJan Kara 
109f55abc0fSJan Kara /* Does kernel know about any quota information for given sb + type? */
110ad1e6e8dSDmitry Monakhov static inline bool sb_has_quota_loaded(struct super_block *sb, int type)
111f55abc0fSJan Kara {
112f55abc0fSJan Kara 	/* Currently if anything is on, then quota usage is on as well */
113f55abc0fSJan Kara 	return sb_has_quota_usage_enabled(sb, type);
114f55abc0fSJan Kara }
115f55abc0fSJan Kara 
116ad1e6e8dSDmitry Monakhov static inline unsigned sb_any_quota_loaded(struct super_block *sb)
117f55abc0fSJan Kara {
118ad1e6e8dSDmitry Monakhov 	unsigned type, tmsk = 0;
119ad1e6e8dSDmitry Monakhov 	for (type = 0; type < MAXQUOTAS; type++)
120ad1e6e8dSDmitry Monakhov 		tmsk |= sb_has_quota_loaded(sb, type) << type;
121ad1e6e8dSDmitry Monakhov 	return	tmsk;
122f55abc0fSJan Kara }
123f55abc0fSJan Kara 
124ad1e6e8dSDmitry Monakhov static inline bool sb_has_quota_active(struct super_block *sb, int type)
125f55abc0fSJan Kara {
126f55abc0fSJan Kara 	return sb_has_quota_loaded(sb, type) &&
127f55abc0fSJan Kara 	       !sb_has_quota_suspended(sb, type);
128f55abc0fSJan Kara }
129f55abc0fSJan Kara 
130ad1e6e8dSDmitry Monakhov static inline unsigned sb_any_quota_active(struct super_block *sb)
131f55abc0fSJan Kara {
132ad1e6e8dSDmitry Monakhov 	return sb_any_quota_loaded(sb) & ~sb_any_quota_suspended(sb);
133f55abc0fSJan Kara }
134f55abc0fSJan Kara 
1351da177e4SLinus Torvalds /*
1361da177e4SLinus Torvalds  * Operations supported for diskquotas.
1371da177e4SLinus Torvalds  */
13861e225dcSAlexey Dobriyan extern const struct dquot_operations dquot_operations;
1390d54b217SAlexey Dobriyan extern const struct quotactl_ops vfs_quotactl_ops;
1401da177e4SLinus Torvalds 
1411da177e4SLinus Torvalds #define sb_dquot_ops (&dquot_operations)
1421da177e4SLinus Torvalds #define sb_quotactl_ops (&vfs_quotactl_ops)
1431da177e4SLinus Torvalds 
144850b201bSChristoph Hellwig /* Cannot be called inside a transaction */
145b85f4b87SJan Kara static inline int vfs_dq_off(struct super_block *sb, int remount)
1461da177e4SLinus Torvalds {
1471da177e4SLinus Torvalds 	int ret = -ENOSYS;
1481da177e4SLinus Torvalds 
1490ff5af83SJan Kara 	if (sb->s_qcop && sb->s_qcop->quota_off)
1500ff5af83SJan Kara 		ret = sb->s_qcop->quota_off(sb, -1, remount);
1510ff5af83SJan Kara 	return ret;
1520ff5af83SJan Kara }
1530ff5af83SJan Kara 
1541da177e4SLinus Torvalds #else
1551da177e4SLinus Torvalds 
156f55abc0fSJan Kara static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type)
15703b06343SJan Kara {
15803b06343SJan Kara 	return 0;
15903b06343SJan Kara }
16003b06343SJan Kara 
161f55abc0fSJan Kara static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type)
16203b06343SJan Kara {
16303b06343SJan Kara 	return 0;
16403b06343SJan Kara }
16503b06343SJan Kara 
16603b06343SJan Kara static inline int sb_has_quota_suspended(struct super_block *sb, int type)
16703b06343SJan Kara {
16803b06343SJan Kara 	return 0;
16903b06343SJan Kara }
17003b06343SJan Kara 
17103b06343SJan Kara static inline int sb_any_quota_suspended(struct super_block *sb)
17203b06343SJan Kara {
17303b06343SJan Kara 	return 0;
17403b06343SJan Kara }
17574abb989SJan Kara 
176f55abc0fSJan Kara /* Does kernel know about any quota information for given sb + type? */
177f55abc0fSJan Kara static inline int sb_has_quota_loaded(struct super_block *sb, int type)
178f55abc0fSJan Kara {
179f55abc0fSJan Kara 	return 0;
180f55abc0fSJan Kara }
181f55abc0fSJan Kara 
182f55abc0fSJan Kara static inline int sb_any_quota_loaded(struct super_block *sb)
183f55abc0fSJan Kara {
184f55abc0fSJan Kara 	return 0;
185f55abc0fSJan Kara }
186f55abc0fSJan Kara 
187f55abc0fSJan Kara static inline int sb_has_quota_active(struct super_block *sb, int type)
188f55abc0fSJan Kara {
189f55abc0fSJan Kara 	return 0;
190f55abc0fSJan Kara }
191f55abc0fSJan Kara 
192f55abc0fSJan Kara static inline int sb_any_quota_active(struct super_block *sb)
193f55abc0fSJan Kara {
194f55abc0fSJan Kara 	return 0;
195f55abc0fSJan Kara }
196f55abc0fSJan Kara 
1971da177e4SLinus Torvalds /*
1981da177e4SLinus Torvalds  * NO-OP when quota not configured.
1991da177e4SLinus Torvalds  */
2001da177e4SLinus Torvalds #define sb_dquot_ops				(NULL)
2011da177e4SLinus Torvalds #define sb_quotactl_ops				(NULL)
20250f8c370SAndrew Morton 
203871a2931SChristoph Hellwig static inline void dquot_initialize(struct inode *inode)
20450f8c370SAndrew Morton {
20550f8c370SAndrew Morton }
20650f8c370SAndrew Morton 
2079f754758SChristoph Hellwig static inline void dquot_drop(struct inode *inode)
20850f8c370SAndrew Morton {
20950f8c370SAndrew Morton }
21050f8c370SAndrew Morton 
21163936ddaSChristoph Hellwig static inline int dquot_alloc_inode(const struct inode *inode)
21250f8c370SAndrew Morton {
21350f8c370SAndrew Morton 	return 0;
21450f8c370SAndrew Morton }
21550f8c370SAndrew Morton 
21663936ddaSChristoph Hellwig static inline void dquot_free_inode(const struct inode *inode)
21750f8c370SAndrew Morton {
21850f8c370SAndrew Morton }
21950f8c370SAndrew Morton 
220b85f4b87SJan Kara static inline int vfs_dq_off(struct super_block *sb, int remount)
22150f8c370SAndrew Morton {
22250f8c370SAndrew Morton 	return 0;
22350f8c370SAndrew Morton }
22450f8c370SAndrew Morton 
225b85f4b87SJan Kara static inline int vfs_dq_quota_on_remount(struct super_block *sb)
22650f8c370SAndrew Morton {
22750f8c370SAndrew Morton 	return 0;
22850f8c370SAndrew Morton }
22950f8c370SAndrew Morton 
230b43fa828SChristoph Hellwig static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
23150f8c370SAndrew Morton {
23250f8c370SAndrew Morton 	return 0;
23350f8c370SAndrew Morton }
23450f8c370SAndrew Morton 
2355dd4056dSChristoph Hellwig static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
23656246f9aSEric Sandeen 		int flags)
2371da177e4SLinus Torvalds {
23856246f9aSEric Sandeen 	if (!(flags & DQUOT_SPACE_RESERVE))
2395dd4056dSChristoph Hellwig 		inode_add_bytes(inode, number);
2401da177e4SLinus Torvalds 	return 0;
2411da177e4SLinus Torvalds }
2421da177e4SLinus Torvalds 
2435dd4056dSChristoph Hellwig static inline void __dquot_free_space(struct inode *inode, qsize_t number,
24456246f9aSEric Sandeen 		int flags)
2451da177e4SLinus Torvalds {
24656246f9aSEric Sandeen 	if (!(flags & DQUOT_SPACE_RESERVE))
2475dd4056dSChristoph Hellwig 		inode_sub_bytes(inode, number);
2485dd4056dSChristoph Hellwig }
2495dd4056dSChristoph Hellwig 
2505dd4056dSChristoph Hellwig static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
2515dd4056dSChristoph Hellwig {
2525dd4056dSChristoph Hellwig 	inode_add_bytes(inode, number);
2531da177e4SLinus Torvalds 	return 0;
2541da177e4SLinus Torvalds }
2551da177e4SLinus Torvalds 
256871a2931SChristoph Hellwig #define dquot_file_open		generic_file_open
257871a2931SChristoph Hellwig 
2581da177e4SLinus Torvalds #endif /* CONFIG_QUOTA */
2591da177e4SLinus Torvalds 
2605dd4056dSChristoph Hellwig static inline int dquot_alloc_space_nodirty(struct inode *inode, qsize_t nr)
26103f6e92bSJan Kara {
26256246f9aSEric Sandeen 	return __dquot_alloc_space(inode, nr, DQUOT_SPACE_WARN);
26303f6e92bSJan Kara }
26403f6e92bSJan Kara 
2655dd4056dSChristoph Hellwig static inline int dquot_alloc_space(struct inode *inode, qsize_t nr)
26603f6e92bSJan Kara {
2675dd4056dSChristoph Hellwig 	int ret;
2685dd4056dSChristoph Hellwig 
2695dd4056dSChristoph Hellwig 	ret = dquot_alloc_space_nodirty(inode, nr);
2705dd4056dSChristoph Hellwig 	if (!ret)
2715dd4056dSChristoph Hellwig 		mark_inode_dirty(inode);
2725dd4056dSChristoph Hellwig 	return ret;
27303f6e92bSJan Kara }
27403f6e92bSJan Kara 
2755dd4056dSChristoph Hellwig static inline int dquot_alloc_block_nodirty(struct inode *inode, qsize_t nr)
27603f6e92bSJan Kara {
2775dd4056dSChristoph Hellwig 	return dquot_alloc_space_nodirty(inode, nr << inode->i_blkbits);
27803f6e92bSJan Kara }
27903f6e92bSJan Kara 
2805dd4056dSChristoph Hellwig static inline int dquot_alloc_block(struct inode *inode, qsize_t nr)
28103f6e92bSJan Kara {
2825dd4056dSChristoph Hellwig 	return dquot_alloc_space(inode, nr << inode->i_blkbits);
28303f6e92bSJan Kara }
28403f6e92bSJan Kara 
2855dd4056dSChristoph Hellwig static inline int dquot_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
286f18df228SMingming Cao {
28756246f9aSEric Sandeen 	return __dquot_alloc_space(inode, nr << inode->i_blkbits, 0);
288f18df228SMingming Cao }
289f18df228SMingming Cao 
2905dd4056dSChristoph Hellwig static inline int dquot_prealloc_block(struct inode *inode, qsize_t nr)
291740d9dcdSMingming Cao {
2925dd4056dSChristoph Hellwig 	int ret;
2935dd4056dSChristoph Hellwig 
2945dd4056dSChristoph Hellwig 	ret = dquot_prealloc_block_nodirty(inode, nr);
2955dd4056dSChristoph Hellwig 	if (!ret)
2965dd4056dSChristoph Hellwig 		mark_inode_dirty(inode);
2975dd4056dSChristoph Hellwig 	return ret;
298740d9dcdSMingming Cao }
299740d9dcdSMingming Cao 
3005dd4056dSChristoph Hellwig static inline int dquot_reserve_block(struct inode *inode, qsize_t nr)
301740d9dcdSMingming Cao {
30256246f9aSEric Sandeen 	return __dquot_alloc_space(inode, nr << inode->i_blkbits,
30356246f9aSEric Sandeen 				DQUOT_SPACE_WARN|DQUOT_SPACE_RESERVE);
304740d9dcdSMingming Cao }
305740d9dcdSMingming Cao 
3065dd4056dSChristoph Hellwig static inline int dquot_claim_block(struct inode *inode, qsize_t nr)
30703f6e92bSJan Kara {
3085dd4056dSChristoph Hellwig 	int ret;
3095dd4056dSChristoph Hellwig 
3105dd4056dSChristoph Hellwig 	ret = dquot_claim_space_nodirty(inode, nr << inode->i_blkbits);
3115dd4056dSChristoph Hellwig 	if (!ret)
3125dd4056dSChristoph Hellwig 		mark_inode_dirty(inode);
3135dd4056dSChristoph Hellwig 	return ret;
31403f6e92bSJan Kara }
31503f6e92bSJan Kara 
3165dd4056dSChristoph Hellwig static inline void dquot_free_space_nodirty(struct inode *inode, qsize_t nr)
31703f6e92bSJan Kara {
3185dd4056dSChristoph Hellwig 	__dquot_free_space(inode, nr, 0);
3195dd4056dSChristoph Hellwig }
3205dd4056dSChristoph Hellwig 
3215dd4056dSChristoph Hellwig static inline void dquot_free_space(struct inode *inode, qsize_t nr)
3225dd4056dSChristoph Hellwig {
3235dd4056dSChristoph Hellwig 	dquot_free_space_nodirty(inode, nr);
3245dd4056dSChristoph Hellwig 	mark_inode_dirty(inode);
3255dd4056dSChristoph Hellwig }
3265dd4056dSChristoph Hellwig 
3275dd4056dSChristoph Hellwig static inline void dquot_free_block_nodirty(struct inode *inode, qsize_t nr)
3285dd4056dSChristoph Hellwig {
3295dd4056dSChristoph Hellwig 	dquot_free_space_nodirty(inode, nr << inode->i_blkbits);
3305dd4056dSChristoph Hellwig }
3315dd4056dSChristoph Hellwig 
3325dd4056dSChristoph Hellwig static inline void dquot_free_block(struct inode *inode, qsize_t nr)
3335dd4056dSChristoph Hellwig {
3345dd4056dSChristoph Hellwig 	dquot_free_space(inode, nr << inode->i_blkbits);
3355dd4056dSChristoph Hellwig }
3365dd4056dSChristoph Hellwig 
3375dd4056dSChristoph Hellwig static inline void dquot_release_reservation_block(struct inode *inode,
3385dd4056dSChristoph Hellwig 		qsize_t nr)
3395dd4056dSChristoph Hellwig {
34056246f9aSEric Sandeen 	__dquot_free_space(inode, nr << inode->i_blkbits, DQUOT_SPACE_RESERVE);
34103f6e92bSJan Kara }
3421da177e4SLinus Torvalds 
3431da177e4SLinus Torvalds #endif /* _LINUX_QUOTAOPS_ */
344