blob: f8dbeb0fe0c9742a800c83b2bc6b97a876a8bb5a [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
Eric Sandeen56246f92010-05-16 09:00:00 -040012#define DQUOT_SPACE_WARN 0x1
13#define DQUOT_SPACE_RESERVE 0x2
Eric Sandeen0e058422010-05-16 10:00:00 -040014#define DQUOT_SPACE_NOFAIL 0x4
Eric Sandeen56246f92010-05-16 09:00:00 -040015
Jan Kara03b06342008-07-25 01:46:52 -070016static inline struct quota_info *sb_dqopt(struct super_block *sb)
17{
18 return &sb->s_dquot;
19}
Jan Kara74abb982008-07-25 01:46:51 -070020
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#if defined(CONFIG_QUOTA)
22
23/*
24 * declaration of quota_function calls in kernel.
25 */
Dmitry Monakhovc4690702010-02-09 17:53:36 +010026void inode_add_rsv_space(struct inode *inode, qsize_t number);
27void inode_claim_rsv_space(struct inode *inode, qsize_t number);
28void inode_sub_rsv_space(struct inode *inode, qsize_t number);
29
Christoph Hellwig871a2932010-03-03 09:05:07 -050030void dquot_initialize(struct inode *inode);
Christoph Hellwig9f754752010-03-03 09:05:05 -050031void dquot_drop(struct inode *inode);
Jan Kara3d9ea252008-10-10 16:12:23 +020032struct dquot *dqget(struct super_block *sb, unsigned int id, int type);
33void dqput(struct dquot *dquot);
Jan Kara12c77522008-10-20 17:05:00 +020034int dquot_scan_active(struct super_block *sb,
35 int (*fn)(struct dquot *dquot, unsigned long priv),
36 unsigned long priv);
Jan Kara7d9056b2008-11-25 15:31:32 +010037struct dquot *dquot_alloc(struct super_block *sb, int type);
38void dquot_destroy(struct dquot *dquot);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Eric Sandeen56246f92010-05-16 09:00:00 -040040int __dquot_alloc_space(struct inode *inode, qsize_t number, int flags);
41void __dquot_free_space(struct inode *inode, qsize_t number, int flags);
Christoph Hellwig5dd40562010-03-03 09:05:00 -050042
Christoph Hellwig63936dd2010-03-03 09:05:01 -050043int dquot_alloc_inode(const struct inode *inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Christoph Hellwig5dd40562010-03-03 09:05:00 -050045int dquot_claim_space_nodirty(struct inode *inode, qsize_t number);
Christoph Hellwig63936dd2010-03-03 09:05:01 -050046void dquot_free_inode(const struct inode *inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Jan Karab85f4b82008-07-25 01:46:50 -070048int dquot_commit(struct dquot *dquot);
49int dquot_acquire(struct dquot *dquot);
50int dquot_release(struct dquot *dquot);
51int dquot_commit_info(struct super_block *sb, int type);
52int dquot_mark_dquot_dirty(struct dquot *dquot);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Christoph Hellwig907f4552010-03-03 09:05:06 -050054int dquot_file_open(struct inode *inode, struct file *file);
55
Jan Karab85f4b82008-07-25 01:46:50 -070056int vfs_quota_on(struct super_block *sb, int type, int format_id,
57 char *path, int remount);
Jan Karaf55abc02008-08-20 17:50:32 +020058int vfs_quota_enable(struct inode *inode, int type, int format_id,
59 unsigned int flags);
Al Viro77e69da2008-08-01 04:29:18 -040060int vfs_quota_on_path(struct super_block *sb, int type, int format_id,
61 struct path *path);
Jan Karab85f4b82008-07-25 01:46:50 -070062int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
63 int format_id, int type);
64int vfs_quota_off(struct super_block *sb, int type, int remount);
Jan Karaf55abc02008-08-20 17:50:32 +020065int vfs_quota_disable(struct super_block *sb, int type, unsigned int flags);
Christoph Hellwig5fb324a2010-02-16 03:44:52 -050066int vfs_quota_sync(struct super_block *sb, int type, int wait);
Jan Karab85f4b82008-07-25 01:46:50 -070067int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
68int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
69int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
70int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
71
Christoph Hellwigb43fa822010-03-03 09:05:03 -050072int dquot_transfer(struct inode *inode, struct iattr *iattr);
Jan Karab85f4b82008-07-25 01:46:50 -070073int vfs_dq_quota_on_remount(struct super_block *sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Jan Kara03b06342008-07-25 01:46:52 -070075static inline struct mem_dqinfo *sb_dqinfo(struct super_block *sb, int type)
76{
77 return sb_dqopt(sb)->info + type;
78}
Jan Kara74abb982008-07-25 01:46:51 -070079
80/*
81 * Functions for checking status of quota
82 */
83
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +030084static inline bool sb_has_quota_usage_enabled(struct super_block *sb, int type)
Jan Kara03b06342008-07-25 01:46:52 -070085{
Jan Karaf55abc02008-08-20 17:50:32 +020086 return sb_dqopt(sb)->flags &
87 dquot_state_flag(DQUOT_USAGE_ENABLED, type);
Jan Kara03b06342008-07-25 01:46:52 -070088}
Jan Kara74abb982008-07-25 01:46:51 -070089
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +030090static inline bool sb_has_quota_limits_enabled(struct super_block *sb, int type)
Jan Kara03b06342008-07-25 01:46:52 -070091{
Jan Karaf55abc02008-08-20 17:50:32 +020092 return sb_dqopt(sb)->flags &
93 dquot_state_flag(DQUOT_LIMITS_ENABLED, type);
Jan Kara03b06342008-07-25 01:46:52 -070094}
Jan Kara74abb982008-07-25 01:46:51 -070095
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +030096static inline bool sb_has_quota_suspended(struct super_block *sb, int type)
Jan Kara03b06342008-07-25 01:46:52 -070097{
Jan Karaf55abc02008-08-20 17:50:32 +020098 return sb_dqopt(sb)->flags &
99 dquot_state_flag(DQUOT_SUSPENDED, type);
Jan Kara03b06342008-07-25 01:46:52 -0700100}
Jan Kara74abb982008-07-25 01:46:51 -0700101
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300102static inline unsigned sb_any_quota_suspended(struct super_block *sb)
Jan Kara03b06342008-07-25 01:46:52 -0700103{
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300104 unsigned type, tmsk = 0;
105 for (type = 0; type < MAXQUOTAS; type++)
106 tmsk |= sb_has_quota_suspended(sb, type) << type;
107 return tmsk;
Jan Kara03b06342008-07-25 01:46:52 -0700108}
Jan Kara74abb982008-07-25 01:46:51 -0700109
Jan Karaf55abc02008-08-20 17:50:32 +0200110/* Does kernel know about any quota information for given sb + type? */
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300111static inline bool sb_has_quota_loaded(struct super_block *sb, int type)
Jan Karaf55abc02008-08-20 17:50:32 +0200112{
113 /* Currently if anything is on, then quota usage is on as well */
114 return sb_has_quota_usage_enabled(sb, type);
115}
116
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300117static inline unsigned sb_any_quota_loaded(struct super_block *sb)
Jan Karaf55abc02008-08-20 17:50:32 +0200118{
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300119 unsigned type, tmsk = 0;
120 for (type = 0; type < MAXQUOTAS; type++)
121 tmsk |= sb_has_quota_loaded(sb, type) << type;
122 return tmsk;
Jan Karaf55abc02008-08-20 17:50:32 +0200123}
124
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300125static inline bool sb_has_quota_active(struct super_block *sb, int type)
Jan Karaf55abc02008-08-20 17:50:32 +0200126{
127 return sb_has_quota_loaded(sb, type) &&
128 !sb_has_quota_suspended(sb, type);
129}
130
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300131static inline unsigned sb_any_quota_active(struct super_block *sb)
Jan Karaf55abc02008-08-20 17:50:32 +0200132{
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300133 return sb_any_quota_loaded(sb) & ~sb_any_quota_suspended(sb);
Jan Karaf55abc02008-08-20 17:50:32 +0200134}
135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136/*
137 * Operations supported for diskquotas.
138 */
Alexey Dobriyan61e225d2009-09-21 17:01:08 -0700139extern const struct dquot_operations dquot_operations;
Alexey Dobriyan0d54b212009-09-21 17:01:09 -0700140extern const struct quotactl_ops vfs_quotactl_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142#define sb_dquot_ops (&dquot_operations)
143#define sb_quotactl_ops (&vfs_quotactl_ops)
144
Christoph Hellwig850b2012009-04-27 16:43:54 +0200145/* Cannot be called inside a transaction */
Jan Karab85f4b82008-07-25 01:46:50 -0700146static inline int vfs_dq_off(struct super_block *sb, int remount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147{
148 int ret = -ENOSYS;
149
Jan Kara0ff5af82008-04-28 02:14:33 -0700150 if (sb->s_qcop && sb->s_qcop->quota_off)
151 ret = sb->s_qcop->quota_off(sb, -1, remount);
152 return ret;
153}
154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155#else
156
Jan Karaf55abc02008-08-20 17:50:32 +0200157static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type)
Jan Kara03b06342008-07-25 01:46:52 -0700158{
159 return 0;
160}
161
Jan Karaf55abc02008-08-20 17:50:32 +0200162static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type)
Jan Kara03b06342008-07-25 01:46:52 -0700163{
164 return 0;
165}
166
167static inline int sb_has_quota_suspended(struct super_block *sb, int type)
168{
169 return 0;
170}
171
172static inline int sb_any_quota_suspended(struct super_block *sb)
173{
174 return 0;
175}
Jan Kara74abb982008-07-25 01:46:51 -0700176
Jan Karaf55abc02008-08-20 17:50:32 +0200177/* Does kernel know about any quota information for given sb + type? */
178static inline int sb_has_quota_loaded(struct super_block *sb, int type)
179{
180 return 0;
181}
182
183static inline int sb_any_quota_loaded(struct super_block *sb)
184{
185 return 0;
186}
187
188static inline int sb_has_quota_active(struct super_block *sb, int type)
189{
190 return 0;
191}
192
193static inline int sb_any_quota_active(struct super_block *sb)
194{
195 return 0;
196}
197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198/*
199 * NO-OP when quota not configured.
200 */
201#define sb_dquot_ops (NULL)
202#define sb_quotactl_ops (NULL)
Andrew Morton50f8c372008-04-28 02:14:35 -0700203
Christoph Hellwig871a2932010-03-03 09:05:07 -0500204static inline void dquot_initialize(struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700205{
206}
207
Christoph Hellwig9f754752010-03-03 09:05:05 -0500208static inline void dquot_drop(struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700209{
210}
211
Christoph Hellwig63936dd2010-03-03 09:05:01 -0500212static inline int dquot_alloc_inode(const struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700213{
214 return 0;
215}
216
Christoph Hellwig63936dd2010-03-03 09:05:01 -0500217static inline void dquot_free_inode(const struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700218{
219}
220
Jan Karab85f4b82008-07-25 01:46:50 -0700221static inline int vfs_dq_off(struct super_block *sb, int remount)
Andrew Morton50f8c372008-04-28 02:14:35 -0700222{
223 return 0;
224}
225
Jan Karab85f4b82008-07-25 01:46:50 -0700226static inline int vfs_dq_quota_on_remount(struct super_block *sb)
Andrew Morton50f8c372008-04-28 02:14:35 -0700227{
228 return 0;
229}
230
Christoph Hellwigb43fa822010-03-03 09:05:03 -0500231static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
Andrew Morton50f8c372008-04-28 02:14:35 -0700232{
233 return 0;
234}
235
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500236static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
Eric Sandeen56246f92010-05-16 09:00:00 -0400237 int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238{
Eric Sandeen56246f92010-05-16 09:00:00 -0400239 if (!(flags & DQUOT_SPACE_RESERVE))
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500240 inode_add_bytes(inode, number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 return 0;
242}
243
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500244static inline void __dquot_free_space(struct inode *inode, qsize_t number,
Eric Sandeen56246f92010-05-16 09:00:00 -0400245 int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246{
Eric Sandeen56246f92010-05-16 09:00:00 -0400247 if (!(flags & DQUOT_SPACE_RESERVE))
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500248 inode_sub_bytes(inode, number);
249}
250
251static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
252{
253 inode_add_bytes(inode, number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 return 0;
255}
256
Christoph Hellwig871a2932010-03-03 09:05:07 -0500257#define dquot_file_open generic_file_open
258
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259#endif /* CONFIG_QUOTA */
260
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500261static inline int dquot_alloc_space_nodirty(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700262{
Eric Sandeen56246f92010-05-16 09:00:00 -0400263 return __dquot_alloc_space(inode, nr, DQUOT_SPACE_WARN);
Jan Kara03f6e922008-04-28 02:14:32 -0700264}
265
Eric Sandeen0e058422010-05-16 10:00:00 -0400266static inline void dquot_alloc_space_nofail(struct inode *inode, qsize_t nr)
267{
268 __dquot_alloc_space(inode, nr, DQUOT_SPACE_WARN|DQUOT_SPACE_NOFAIL);
269 mark_inode_dirty(inode);
270}
271
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500272static inline int dquot_alloc_space(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700273{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500274 int ret;
275
276 ret = dquot_alloc_space_nodirty(inode, nr);
277 if (!ret)
278 mark_inode_dirty(inode);
279 return ret;
Jan Kara03f6e922008-04-28 02:14:32 -0700280}
281
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500282static inline int dquot_alloc_block_nodirty(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700283{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500284 return dquot_alloc_space_nodirty(inode, nr << inode->i_blkbits);
Jan Kara03f6e922008-04-28 02:14:32 -0700285}
286
Eric Sandeen0e058422010-05-16 10:00:00 -0400287static inline void dquot_alloc_block_nofail(struct inode *inode, qsize_t nr)
288{
289 dquot_alloc_space_nofail(inode, nr << inode->i_blkbits);
290}
291
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500292static inline int dquot_alloc_block(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700293{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500294 return dquot_alloc_space(inode, nr << inode->i_blkbits);
Jan Kara03f6e922008-04-28 02:14:32 -0700295}
296
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500297static inline int dquot_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
Mingming Caof18df222009-01-13 16:43:09 +0100298{
Eric Sandeen56246f92010-05-16 09:00:00 -0400299 return __dquot_alloc_space(inode, nr << inode->i_blkbits, 0);
Mingming Caof18df222009-01-13 16:43:09 +0100300}
301
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500302static inline int dquot_prealloc_block(struct inode *inode, qsize_t nr)
Mingming Cao740d9dc2009-01-13 16:43:14 +0100303{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500304 int ret;
305
306 ret = dquot_prealloc_block_nodirty(inode, nr);
307 if (!ret)
308 mark_inode_dirty(inode);
309 return ret;
Mingming Cao740d9dc2009-01-13 16:43:14 +0100310}
311
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500312static inline int dquot_reserve_block(struct inode *inode, qsize_t nr)
Mingming Cao740d9dc2009-01-13 16:43:14 +0100313{
Eric Sandeen56246f92010-05-16 09:00:00 -0400314 return __dquot_alloc_space(inode, nr << inode->i_blkbits,
315 DQUOT_SPACE_WARN|DQUOT_SPACE_RESERVE);
Mingming Cao740d9dc2009-01-13 16:43:14 +0100316}
317
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500318static inline int dquot_claim_block(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700319{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500320 int ret;
321
322 ret = dquot_claim_space_nodirty(inode, nr << inode->i_blkbits);
323 if (!ret)
324 mark_inode_dirty(inode);
325 return ret;
Jan Kara03f6e922008-04-28 02:14:32 -0700326}
327
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500328static inline void dquot_free_space_nodirty(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700329{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500330 __dquot_free_space(inode, nr, 0);
331}
332
333static inline void dquot_free_space(struct inode *inode, qsize_t nr)
334{
335 dquot_free_space_nodirty(inode, nr);
336 mark_inode_dirty(inode);
337}
338
339static inline void dquot_free_block_nodirty(struct inode *inode, qsize_t nr)
340{
341 dquot_free_space_nodirty(inode, nr << inode->i_blkbits);
342}
343
344static inline void dquot_free_block(struct inode *inode, qsize_t nr)
345{
346 dquot_free_space(inode, nr << inode->i_blkbits);
347}
348
349static inline void dquot_release_reservation_block(struct inode *inode,
350 qsize_t nr)
351{
Eric Sandeen56246f92010-05-16 09:00:00 -0400352 __dquot_free_space(inode, nr << inode->i_blkbits, DQUOT_SPACE_RESERVE);
Jan Kara03f6e922008-04-28 02:14:32 -0700353}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355#endif /* _LINUX_QUOTAOPS_ */