blob: 8a7818764a678118ed8d2d8358657a5b4042ec1f [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
Jan Karab85f4b82008-07-25 01:46:50 -070053int 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Christoph Hellwig907f4552010-03-03 09:05:06 -050059int dquot_file_open(struct inode *inode, struct file *file);
60
Jan Karab85f4b82008-07-25 01:46:50 -070061int vfs_quota_on(struct super_block *sb, int type, int format_id,
62 char *path, int remount);
Jan Karaf55abc02008-08-20 17:50:32 +020063int vfs_quota_enable(struct inode *inode, int type, int format_id,
64 unsigned int flags);
Al Viro77e69da2008-08-01 04:29:18 -040065int vfs_quota_on_path(struct super_block *sb, int type, int format_id,
66 struct path *path);
Jan Karab85f4b82008-07-25 01:46:50 -070067int 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);
Jan Karaf55abc02008-08-20 17:50:32 +020070int vfs_quota_disable(struct super_block *sb, int type, unsigned int flags);
Christoph Hellwig5fb324a2010-02-16 03:44:52 -050071int vfs_quota_sync(struct super_block *sb, int type, int wait);
Jan Karab85f4b82008-07-25 01:46:50 -070072int 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);
Christoph Hellwigb9b2dd32010-05-06 17:04:58 -040074int vfs_get_dqblk(struct super_block *sb, int type, qid_t id,
75 struct fs_disk_quota *di);
Christoph Hellwigc472b432010-05-06 17:05:17 -040076int vfs_set_dqblk(struct super_block *sb, int type, qid_t id,
77 struct fs_disk_quota *di);
Jan Karab85f4b82008-07-25 01:46:50 -070078
Christoph Hellwigb43fa822010-03-03 09:05:03 -050079int dquot_transfer(struct inode *inode, struct iattr *iattr);
Jan Karab85f4b82008-07-25 01:46:50 -070080int vfs_dq_quota_on_remount(struct super_block *sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Jan Kara03b06342008-07-25 01:46:52 -070082static inline struct mem_dqinfo *sb_dqinfo(struct super_block *sb, int type)
83{
84 return sb_dqopt(sb)->info + type;
85}
Jan Kara74abb982008-07-25 01:46:51 -070086
87/*
88 * Functions for checking status of quota
89 */
90
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +030091static inline bool sb_has_quota_usage_enabled(struct super_block *sb, int type)
Jan Kara03b06342008-07-25 01:46:52 -070092{
Jan Karaf55abc02008-08-20 17:50:32 +020093 return sb_dqopt(sb)->flags &
94 dquot_state_flag(DQUOT_USAGE_ENABLED, type);
Jan Kara03b06342008-07-25 01:46:52 -070095}
Jan Kara74abb982008-07-25 01:46:51 -070096
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +030097static inline bool sb_has_quota_limits_enabled(struct super_block *sb, int type)
Jan Kara03b06342008-07-25 01:46:52 -070098{
Jan Karaf55abc02008-08-20 17:50:32 +020099 return sb_dqopt(sb)->flags &
100 dquot_state_flag(DQUOT_LIMITS_ENABLED, type);
Jan Kara03b06342008-07-25 01:46:52 -0700101}
Jan Kara74abb982008-07-25 01:46:51 -0700102
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300103static inline bool sb_has_quota_suspended(struct super_block *sb, int type)
Jan Kara03b06342008-07-25 01:46:52 -0700104{
Jan Karaf55abc02008-08-20 17:50:32 +0200105 return sb_dqopt(sb)->flags &
106 dquot_state_flag(DQUOT_SUSPENDED, type);
Jan Kara03b06342008-07-25 01:46:52 -0700107}
Jan Kara74abb982008-07-25 01:46:51 -0700108
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300109static inline unsigned sb_any_quota_suspended(struct super_block *sb)
Jan Kara03b06342008-07-25 01:46:52 -0700110{
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300111 unsigned type, tmsk = 0;
112 for (type = 0; type < MAXQUOTAS; type++)
113 tmsk |= sb_has_quota_suspended(sb, type) << type;
114 return tmsk;
Jan Kara03b06342008-07-25 01:46:52 -0700115}
Jan Kara74abb982008-07-25 01:46:51 -0700116
Jan Karaf55abc02008-08-20 17:50:32 +0200117/* Does kernel know about any quota information for given sb + type? */
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300118static inline bool sb_has_quota_loaded(struct super_block *sb, int type)
Jan Karaf55abc02008-08-20 17:50:32 +0200119{
120 /* Currently if anything is on, then quota usage is on as well */
121 return sb_has_quota_usage_enabled(sb, type);
122}
123
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300124static inline unsigned sb_any_quota_loaded(struct super_block *sb)
Jan Karaf55abc02008-08-20 17:50:32 +0200125{
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300126 unsigned type, tmsk = 0;
127 for (type = 0; type < MAXQUOTAS; type++)
128 tmsk |= sb_has_quota_loaded(sb, type) << type;
129 return tmsk;
Jan Karaf55abc02008-08-20 17:50:32 +0200130}
131
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300132static inline bool sb_has_quota_active(struct super_block *sb, int type)
Jan Karaf55abc02008-08-20 17:50:32 +0200133{
134 return sb_has_quota_loaded(sb, type) &&
135 !sb_has_quota_suspended(sb, type);
136}
137
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300138static inline unsigned sb_any_quota_active(struct super_block *sb)
Jan Karaf55abc02008-08-20 17:50:32 +0200139{
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300140 return sb_any_quota_loaded(sb) & ~sb_any_quota_suspended(sb);
Jan Karaf55abc02008-08-20 17:50:32 +0200141}
142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143/*
144 * Operations supported for diskquotas.
145 */
Alexey Dobriyan61e225d2009-09-21 17:01:08 -0700146extern const struct dquot_operations dquot_operations;
Alexey Dobriyan0d54b212009-09-21 17:01:09 -0700147extern const struct quotactl_ops vfs_quotactl_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
149#define sb_dquot_ops (&dquot_operations)
150#define sb_quotactl_ops (&vfs_quotactl_ops)
151
Christoph Hellwig850b2012009-04-27 16:43:54 +0200152/* Cannot be called inside a transaction */
Jan Karab85f4b82008-07-25 01:46:50 -0700153static inline int vfs_dq_off(struct super_block *sb, int remount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
155 int ret = -ENOSYS;
156
Jan Kara0ff5af82008-04-28 02:14:33 -0700157 if (sb->s_qcop && sb->s_qcop->quota_off)
158 ret = sb->s_qcop->quota_off(sb, -1, remount);
159 return ret;
160}
161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162#else
163
Jan Karaf55abc02008-08-20 17:50:32 +0200164static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type)
Jan Kara03b06342008-07-25 01:46:52 -0700165{
166 return 0;
167}
168
Jan Karaf55abc02008-08-20 17:50:32 +0200169static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type)
Jan Kara03b06342008-07-25 01:46:52 -0700170{
171 return 0;
172}
173
174static inline int sb_has_quota_suspended(struct super_block *sb, int type)
175{
176 return 0;
177}
178
179static inline int sb_any_quota_suspended(struct super_block *sb)
180{
181 return 0;
182}
Jan Kara74abb982008-07-25 01:46:51 -0700183
Jan Karaf55abc02008-08-20 17:50:32 +0200184/* Does kernel know about any quota information for given sb + type? */
185static inline int sb_has_quota_loaded(struct super_block *sb, int type)
186{
187 return 0;
188}
189
190static inline int sb_any_quota_loaded(struct super_block *sb)
191{
192 return 0;
193}
194
195static inline int sb_has_quota_active(struct super_block *sb, int type)
196{
197 return 0;
198}
199
200static inline int sb_any_quota_active(struct super_block *sb)
201{
202 return 0;
203}
204
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205/*
206 * NO-OP when quota not configured.
207 */
208#define sb_dquot_ops (NULL)
209#define sb_quotactl_ops (NULL)
Andrew Morton50f8c372008-04-28 02:14:35 -0700210
Christoph Hellwig871a2932010-03-03 09:05:07 -0500211static inline void dquot_initialize(struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700212{
213}
214
Christoph Hellwig9f754752010-03-03 09:05:05 -0500215static inline void dquot_drop(struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700216{
217}
218
Christoph Hellwig63936dd2010-03-03 09:05:01 -0500219static inline int dquot_alloc_inode(const struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700220{
221 return 0;
222}
223
Christoph Hellwig63936dd2010-03-03 09:05:01 -0500224static inline void dquot_free_inode(const struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700225{
226}
227
Jan Karab85f4b82008-07-25 01:46:50 -0700228static inline int vfs_dq_off(struct super_block *sb, int remount)
Andrew Morton50f8c372008-04-28 02:14:35 -0700229{
230 return 0;
231}
232
Jan Karab85f4b82008-07-25 01:46:50 -0700233static inline int vfs_dq_quota_on_remount(struct super_block *sb)
Andrew Morton50f8c372008-04-28 02:14:35 -0700234{
235 return 0;
236}
237
Christoph Hellwigb43fa822010-03-03 09:05:03 -0500238static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
Andrew Morton50f8c372008-04-28 02:14:35 -0700239{
240 return 0;
241}
242
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500243static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
244 int warn, int reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500246 if (!reserve)
247 inode_add_bytes(inode, number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 return 0;
249}
250
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500251static inline void __dquot_free_space(struct inode *inode, qsize_t number,
252 int reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500254 if (!reserve)
255 inode_sub_bytes(inode, number);
256}
257
258static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
259{
260 inode_add_bytes(inode, number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 return 0;
262}
263
Christoph Hellwig871a2932010-03-03 09:05:07 -0500264#define dquot_file_open generic_file_open
265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266#endif /* CONFIG_QUOTA */
267
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500268static inline int dquot_alloc_space_nodirty(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700269{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500270 return __dquot_alloc_space(inode, nr, 1, 0);
Jan Kara03f6e922008-04-28 02:14:32 -0700271}
272
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500273static inline int dquot_alloc_space(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700274{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500275 int ret;
276
277 ret = dquot_alloc_space_nodirty(inode, nr);
278 if (!ret)
279 mark_inode_dirty(inode);
280 return ret;
Jan Kara03f6e922008-04-28 02:14:32 -0700281}
282
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500283static inline int dquot_alloc_block_nodirty(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700284{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500285 return dquot_alloc_space_nodirty(inode, nr << inode->i_blkbits);
Jan Kara03f6e922008-04-28 02:14:32 -0700286}
287
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500288static inline int dquot_alloc_block(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700289{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500290 return dquot_alloc_space(inode, nr << inode->i_blkbits);
Jan Kara03f6e922008-04-28 02:14:32 -0700291}
292
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500293static inline int dquot_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
Mingming Caof18df222009-01-13 16:43:09 +0100294{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500295 return __dquot_alloc_space(inode, nr << inode->i_blkbits, 0, 0);
Mingming Caof18df222009-01-13 16:43:09 +0100296}
297
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500298static inline int dquot_prealloc_block(struct inode *inode, qsize_t nr)
Mingming Cao740d9dc2009-01-13 16:43:14 +0100299{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500300 int ret;
301
302 ret = dquot_prealloc_block_nodirty(inode, nr);
303 if (!ret)
304 mark_inode_dirty(inode);
305 return ret;
Mingming Cao740d9dc2009-01-13 16:43:14 +0100306}
307
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500308static inline int dquot_reserve_block(struct inode *inode, qsize_t nr)
Mingming Cao740d9dc2009-01-13 16:43:14 +0100309{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500310 return __dquot_alloc_space(inode, nr << inode->i_blkbits, 1, 1);
Mingming Cao740d9dc2009-01-13 16:43:14 +0100311}
312
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500313static inline int dquot_claim_block(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700314{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500315 int ret;
316
317 ret = dquot_claim_space_nodirty(inode, nr << inode->i_blkbits);
318 if (!ret)
319 mark_inode_dirty(inode);
320 return ret;
Jan Kara03f6e922008-04-28 02:14:32 -0700321}
322
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500323static inline void dquot_free_space_nodirty(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700324{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500325 __dquot_free_space(inode, nr, 0);
326}
327
328static inline void dquot_free_space(struct inode *inode, qsize_t nr)
329{
330 dquot_free_space_nodirty(inode, nr);
331 mark_inode_dirty(inode);
332}
333
334static inline void dquot_free_block_nodirty(struct inode *inode, qsize_t nr)
335{
336 dquot_free_space_nodirty(inode, nr << inode->i_blkbits);
337}
338
339static inline void dquot_free_block(struct inode *inode, qsize_t nr)
340{
341 dquot_free_space(inode, nr << inode->i_blkbits);
342}
343
344static inline void dquot_release_reservation_block(struct inode *inode,
345 qsize_t nr)
346{
347 __dquot_free_space(inode, nr << inode->i_blkbits, 1);
Jan Kara03f6e922008-04-28 02:14:32 -0700348}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350#endif /* _LINUX_QUOTAOPS_ */