blob: 811529241e33a6c4194144a9f1d10d1abbcaa858 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#ifndef _LINUX_QUOTAOPS_
8#define _LINUX_QUOTAOPS_
9
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/fs.h>
11
Jan Kara03b06342008-07-25 01:46:52 -070012static inline struct quota_info *sb_dqopt(struct super_block *sb)
13{
14 return &sb->s_dquot;
15}
Jan Kara74abb982008-07-25 01:46:51 -070016
Dmitry Monakhov12755622010-04-08 22:04:20 +040017/* 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#if defined(CONFIG_QUOTA)
26
27/*
28 * declaration of quota_function calls in kernel.
29 */
Dmitry Monakhovc4690702010-02-09 17:53:36 +010030void 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
Christoph Hellwig871a2932010-03-03 09:05:07 -050034void dquot_initialize(struct inode *inode);
Christoph Hellwig9f754752010-03-03 09:05:05 -050035void dquot_drop(struct inode *inode);
Jan Kara3d9ea252008-10-10 16:12:23 +020036struct dquot *dqget(struct super_block *sb, unsigned int id, int type);
37void dqput(struct dquot *dquot);
Jan Kara12c77522008-10-20 17:05:00 +020038int dquot_scan_active(struct super_block *sb,
39 int (*fn)(struct dquot *dquot, unsigned long priv),
40 unsigned long priv);
Jan Kara7d9056b2008-11-25 15:31:32 +010041struct dquot *dquot_alloc(struct super_block *sb, int type);
42void dquot_destroy(struct dquot *dquot);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Christoph Hellwig5dd40562010-03-03 09:05:00 -050044int __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);
47
Christoph Hellwig63936dd2010-03-03 09:05:01 -050048int dquot_alloc_inode(const struct inode *inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Christoph Hellwig5dd40562010-03-03 09:05:00 -050050int dquot_claim_space_nodirty(struct inode *inode, qsize_t number);
Christoph Hellwig63936dd2010-03-03 09:05:01 -050051void dquot_free_inode(const struct inode *inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Christoph Hellwig0f0dd622010-05-19 07:16:41 -040053int dquot_disable(struct super_block *sb, int type, unsigned int flags);
54/* Suspend quotas on remount RO */
55static inline int dquot_suspend(struct super_block *sb, int type)
56{
57 return dquot_disable(sb, type, DQUOT_SUSPENDED);
58}
59int dquot_resume(struct super_block *sb, int type);
60
Jan Karab85f4b82008-07-25 01:46:50 -070061int dquot_commit(struct dquot *dquot);
62int dquot_acquire(struct dquot *dquot);
63int dquot_release(struct dquot *dquot);
64int dquot_commit_info(struct super_block *sb, int type);
65int dquot_mark_dquot_dirty(struct dquot *dquot);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Christoph Hellwig907f4552010-03-03 09:05:06 -050067int dquot_file_open(struct inode *inode, struct file *file);
68
Jan Karab85f4b82008-07-25 01:46:50 -070069int vfs_quota_on(struct super_block *sb, int type, int format_id,
70 char *path, int remount);
Jan Karaf55abc02008-08-20 17:50:32 +020071int vfs_quota_enable(struct inode *inode, int type, int format_id,
72 unsigned int flags);
Al Viro77e69da2008-08-01 04:29:18 -040073int vfs_quota_on_path(struct super_block *sb, int type, int format_id,
74 struct path *path);
Jan Karab85f4b82008-07-25 01:46:50 -070075int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
76 int format_id, int type);
77int vfs_quota_off(struct super_block *sb, int type, int remount);
Christoph Hellwig5fb324a2010-02-16 03:44:52 -050078int vfs_quota_sync(struct super_block *sb, int type, int wait);
Jan Karab85f4b82008-07-25 01:46:50 -070079int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
80int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
Christoph Hellwigb9b2dd32010-05-06 17:04:58 -040081int vfs_get_dqblk(struct super_block *sb, int type, qid_t id,
82 struct fs_disk_quota *di);
Christoph Hellwigc472b432010-05-06 17:05:17 -040083int vfs_set_dqblk(struct super_block *sb, int type, qid_t id,
84 struct fs_disk_quota *di);
Jan Karab85f4b82008-07-25 01:46:50 -070085
Jan Karabc8e5f02010-05-13 19:58:50 +020086int __dquot_transfer(struct inode *inode, struct dquot **transfer_to);
Christoph Hellwigb43fa822010-03-03 09:05:03 -050087int dquot_transfer(struct inode *inode, struct iattr *iattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Jan Kara03b06342008-07-25 01:46:52 -070089static inline struct mem_dqinfo *sb_dqinfo(struct super_block *sb, int type)
90{
91 return sb_dqopt(sb)->info + type;
92}
Jan Kara74abb982008-07-25 01:46:51 -070093
94/*
95 * Functions for checking status of quota
96 */
97
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +030098static inline bool sb_has_quota_usage_enabled(struct super_block *sb, int type)
Jan Kara03b06342008-07-25 01:46:52 -070099{
Jan Karaf55abc02008-08-20 17:50:32 +0200100 return sb_dqopt(sb)->flags &
101 dquot_state_flag(DQUOT_USAGE_ENABLED, type);
Jan Kara03b06342008-07-25 01:46:52 -0700102}
Jan Kara74abb982008-07-25 01:46:51 -0700103
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300104static inline bool sb_has_quota_limits_enabled(struct super_block *sb, int type)
Jan Kara03b06342008-07-25 01:46:52 -0700105{
Jan Karaf55abc02008-08-20 17:50:32 +0200106 return sb_dqopt(sb)->flags &
107 dquot_state_flag(DQUOT_LIMITS_ENABLED, type);
Jan Kara03b06342008-07-25 01:46:52 -0700108}
Jan Kara74abb982008-07-25 01:46:51 -0700109
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300110static inline bool sb_has_quota_suspended(struct super_block *sb, int type)
Jan Kara03b06342008-07-25 01:46:52 -0700111{
Jan Karaf55abc02008-08-20 17:50:32 +0200112 return sb_dqopt(sb)->flags &
113 dquot_state_flag(DQUOT_SUSPENDED, type);
Jan Kara03b06342008-07-25 01:46:52 -0700114}
Jan Kara74abb982008-07-25 01:46:51 -0700115
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300116static inline unsigned sb_any_quota_suspended(struct super_block *sb)
Jan Kara03b06342008-07-25 01:46:52 -0700117{
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300118 unsigned type, tmsk = 0;
119 for (type = 0; type < MAXQUOTAS; type++)
120 tmsk |= sb_has_quota_suspended(sb, type) << type;
121 return tmsk;
Jan Kara03b06342008-07-25 01:46:52 -0700122}
Jan Kara74abb982008-07-25 01:46:51 -0700123
Jan Karaf55abc02008-08-20 17:50:32 +0200124/* Does kernel know about any quota information for given sb + type? */
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300125static inline bool sb_has_quota_loaded(struct super_block *sb, int type)
Jan Karaf55abc02008-08-20 17:50:32 +0200126{
127 /* Currently if anything is on, then quota usage is on as well */
128 return sb_has_quota_usage_enabled(sb, type);
129}
130
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300131static inline unsigned sb_any_quota_loaded(struct super_block *sb)
Jan Karaf55abc02008-08-20 17:50:32 +0200132{
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300133 unsigned type, tmsk = 0;
134 for (type = 0; type < MAXQUOTAS; type++)
135 tmsk |= sb_has_quota_loaded(sb, type) << type;
136 return tmsk;
Jan Karaf55abc02008-08-20 17:50:32 +0200137}
138
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300139static inline bool sb_has_quota_active(struct super_block *sb, int type)
Jan Karaf55abc02008-08-20 17:50:32 +0200140{
141 return sb_has_quota_loaded(sb, type) &&
142 !sb_has_quota_suspended(sb, type);
143}
144
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300145static inline unsigned sb_any_quota_active(struct super_block *sb)
Jan Karaf55abc02008-08-20 17:50:32 +0200146{
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300147 return sb_any_quota_loaded(sb) & ~sb_any_quota_suspended(sb);
Jan Karaf55abc02008-08-20 17:50:32 +0200148}
149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150/*
151 * Operations supported for diskquotas.
152 */
Alexey Dobriyan61e225d2009-09-21 17:01:08 -0700153extern const struct dquot_operations dquot_operations;
Alexey Dobriyan0d54b212009-09-21 17:01:09 -0700154extern const struct quotactl_ops vfs_quotactl_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
156#define sb_dquot_ops (&dquot_operations)
157#define sb_quotactl_ops (&vfs_quotactl_ops)
158
Christoph Hellwig850b2012009-04-27 16:43:54 +0200159/* Cannot be called inside a transaction */
Jan Karab85f4b82008-07-25 01:46:50 -0700160static inline int vfs_dq_off(struct super_block *sb, int remount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161{
162 int ret = -ENOSYS;
163
Jan Kara0ff5af82008-04-28 02:14:33 -0700164 if (sb->s_qcop && sb->s_qcop->quota_off)
165 ret = sb->s_qcop->quota_off(sb, -1, remount);
166 return ret;
167}
168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169#else
170
Jan Karaf55abc02008-08-20 17:50:32 +0200171static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type)
Jan Kara03b06342008-07-25 01:46:52 -0700172{
173 return 0;
174}
175
Jan Karaf55abc02008-08-20 17:50:32 +0200176static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type)
Jan Kara03b06342008-07-25 01:46:52 -0700177{
178 return 0;
179}
180
181static inline int sb_has_quota_suspended(struct super_block *sb, int type)
182{
183 return 0;
184}
185
186static inline int sb_any_quota_suspended(struct super_block *sb)
187{
188 return 0;
189}
Jan Kara74abb982008-07-25 01:46:51 -0700190
Jan Karaf55abc02008-08-20 17:50:32 +0200191/* Does kernel know about any quota information for given sb + type? */
192static inline int sb_has_quota_loaded(struct super_block *sb, int type)
193{
194 return 0;
195}
196
197static inline int sb_any_quota_loaded(struct super_block *sb)
198{
199 return 0;
200}
201
202static inline int sb_has_quota_active(struct super_block *sb, int type)
203{
204 return 0;
205}
206
207static inline int sb_any_quota_active(struct super_block *sb)
208{
209 return 0;
210}
211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212/*
213 * NO-OP when quota not configured.
214 */
215#define sb_dquot_ops (NULL)
216#define sb_quotactl_ops (NULL)
Andrew Morton50f8c372008-04-28 02:14:35 -0700217
Christoph Hellwig871a2932010-03-03 09:05:07 -0500218static inline void dquot_initialize(struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700219{
220}
221
Christoph Hellwig9f754752010-03-03 09:05:05 -0500222static inline void dquot_drop(struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700223{
224}
225
Christoph Hellwig63936dd2010-03-03 09:05:01 -0500226static inline int dquot_alloc_inode(const struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700227{
228 return 0;
229}
230
Christoph Hellwig63936dd2010-03-03 09:05:01 -0500231static inline void dquot_free_inode(const struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700232{
233}
234
Jan Karab85f4b82008-07-25 01:46:50 -0700235static inline int vfs_dq_off(struct super_block *sb, int remount)
Andrew Morton50f8c372008-04-28 02:14:35 -0700236{
237 return 0;
238}
239
Christoph Hellwigb43fa822010-03-03 09:05:03 -0500240static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
Andrew Morton50f8c372008-04-28 02:14:35 -0700241{
242 return 0;
243}
244
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500245static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
246 int warn, int reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500248 if (!reserve)
249 inode_add_bytes(inode, number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 return 0;
251}
252
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500253static inline void __dquot_free_space(struct inode *inode, qsize_t number,
254 int reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500256 if (!reserve)
257 inode_sub_bytes(inode, number);
258}
259
260static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
261{
262 inode_add_bytes(inode, number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 return 0;
264}
265
Christoph Hellwig0f0dd622010-05-19 07:16:41 -0400266static inline int dquot_disable(struct super_block *sb, int type,
267 unsigned int flags)
268{
269 return 0;
270}
271
272static inline int dquot_suspend(struct super_block *sb, int type)
273{
274 return 0;
275}
276
277static inline int dquot_resume(struct super_block *sb, int type)
278{
279 return 0;
280}
281
Christoph Hellwig871a2932010-03-03 09:05:07 -0500282#define dquot_file_open generic_file_open
283
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284#endif /* CONFIG_QUOTA */
285
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500286static inline int dquot_alloc_space_nodirty(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700287{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500288 return __dquot_alloc_space(inode, nr, 1, 0);
Jan Kara03f6e922008-04-28 02:14:32 -0700289}
290
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500291static inline int dquot_alloc_space(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700292{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500293 int ret;
294
295 ret = dquot_alloc_space_nodirty(inode, nr);
296 if (!ret)
297 mark_inode_dirty(inode);
298 return ret;
Jan Kara03f6e922008-04-28 02:14:32 -0700299}
300
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500301static inline int dquot_alloc_block_nodirty(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700302{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500303 return dquot_alloc_space_nodirty(inode, nr << inode->i_blkbits);
Jan Kara03f6e922008-04-28 02:14:32 -0700304}
305
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500306static inline int dquot_alloc_block(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700307{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500308 return dquot_alloc_space(inode, nr << inode->i_blkbits);
Jan Kara03f6e922008-04-28 02:14:32 -0700309}
310
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500311static inline int dquot_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
Mingming Caof18df222009-01-13 16:43:09 +0100312{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500313 return __dquot_alloc_space(inode, nr << inode->i_blkbits, 0, 0);
Mingming Caof18df222009-01-13 16:43:09 +0100314}
315
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500316static inline int dquot_prealloc_block(struct inode *inode, qsize_t nr)
Mingming Cao740d9dc2009-01-13 16:43:14 +0100317{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500318 int ret;
319
320 ret = dquot_prealloc_block_nodirty(inode, nr);
321 if (!ret)
322 mark_inode_dirty(inode);
323 return ret;
Mingming Cao740d9dc2009-01-13 16:43:14 +0100324}
325
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500326static inline int dquot_reserve_block(struct inode *inode, qsize_t nr)
Mingming Cao740d9dc2009-01-13 16:43:14 +0100327{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500328 return __dquot_alloc_space(inode, nr << inode->i_blkbits, 1, 1);
Mingming Cao740d9dc2009-01-13 16:43:14 +0100329}
330
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500331static inline int dquot_claim_block(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700332{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500333 int ret;
334
335 ret = dquot_claim_space_nodirty(inode, nr << inode->i_blkbits);
336 if (!ret)
337 mark_inode_dirty(inode);
338 return ret;
Jan Kara03f6e922008-04-28 02:14:32 -0700339}
340
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500341static inline void dquot_free_space_nodirty(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700342{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500343 __dquot_free_space(inode, nr, 0);
344}
345
346static inline void dquot_free_space(struct inode *inode, qsize_t nr)
347{
348 dquot_free_space_nodirty(inode, nr);
349 mark_inode_dirty(inode);
350}
351
352static inline void dquot_free_block_nodirty(struct inode *inode, qsize_t nr)
353{
354 dquot_free_space_nodirty(inode, nr << inode->i_blkbits);
355}
356
357static inline void dquot_free_block(struct inode *inode, qsize_t nr)
358{
359 dquot_free_space(inode, nr << inode->i_blkbits);
360}
361
362static inline void dquot_release_reservation_block(struct inode *inode,
363 qsize_t nr)
364{
365 __dquot_free_space(inode, nr << inode->i_blkbits, 1);
Jan Kara03f6e922008-04-28 02:14:32 -0700366}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368#endif /* _LINUX_QUOTAOPS_ */