blob: 0c77cd8d2822f3cf23f8143edb83ab945b735f4c [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
Christoph Hellwig287a8092010-05-19 07:16:45 -040069int dquot_quota_on(struct super_block *sb, int type, int format_id,
Christoph Hellwig307ae182010-05-19 07:16:43 -040070 char *path);
Christoph Hellwig287a8092010-05-19 07:16:45 -040071int dquot_enable(struct inode *inode, int type, int format_id,
Jan Karaf55abc02008-08-20 17:50:32 +020072 unsigned int flags);
Christoph Hellwig287a8092010-05-19 07:16:45 -040073int dquot_quota_on_path(struct super_block *sb, int type, int format_id,
Al Viro77e69da2008-08-01 04:29:18 -040074 struct path *path);
Christoph Hellwig287a8092010-05-19 07:16:45 -040075int dquot_quota_on_mount(struct super_block *sb, char *qf_name,
Jan Karab85f4b82008-07-25 01:46:50 -070076 int format_id, int type);
Christoph Hellwig287a8092010-05-19 07:16:45 -040077int dquot_quota_off(struct super_block *sb, int type);
78int dquot_quota_sync(struct super_block *sb, int type, int wait);
79int dquot_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
80int dquot_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
81int dquot_get_dqblk(struct super_block *sb, int type, qid_t id,
Christoph Hellwigb9b2dd32010-05-06 17:04:58 -040082 struct fs_disk_quota *di);
Christoph Hellwig287a8092010-05-19 07:16:45 -040083int dquot_set_dqblk(struct super_block *sb, int type, qid_t id,
Christoph Hellwigc472b432010-05-06 17:05:17 -040084 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;
Christoph Hellwig287a8092010-05-19 07:16:45 -0400154extern const struct quotactl_ops dquot_quotactl_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156#else
157
Jan Karaf55abc02008-08-20 17:50:32 +0200158static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type)
Jan Kara03b06342008-07-25 01:46:52 -0700159{
160 return 0;
161}
162
Jan Karaf55abc02008-08-20 17:50:32 +0200163static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type)
Jan Kara03b06342008-07-25 01:46:52 -0700164{
165 return 0;
166}
167
168static inline int sb_has_quota_suspended(struct super_block *sb, int type)
169{
170 return 0;
171}
172
173static inline int sb_any_quota_suspended(struct super_block *sb)
174{
175 return 0;
176}
Jan Kara74abb982008-07-25 01:46:51 -0700177
Jan Karaf55abc02008-08-20 17:50:32 +0200178/* Does kernel know about any quota information for given sb + type? */
179static inline int sb_has_quota_loaded(struct super_block *sb, int type)
180{
181 return 0;
182}
183
184static inline int sb_any_quota_loaded(struct super_block *sb)
185{
186 return 0;
187}
188
189static inline int sb_has_quota_active(struct super_block *sb, int type)
190{
191 return 0;
192}
193
194static inline int sb_any_quota_active(struct super_block *sb)
195{
196 return 0;
197}
198
Christoph Hellwig871a2932010-03-03 09:05:07 -0500199static inline void dquot_initialize(struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700200{
201}
202
Christoph Hellwig9f754752010-03-03 09:05:05 -0500203static inline void dquot_drop(struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700204{
205}
206
Christoph Hellwig63936dd2010-03-03 09:05:01 -0500207static inline int dquot_alloc_inode(const struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700208{
209 return 0;
210}
211
Christoph Hellwig63936dd2010-03-03 09:05:01 -0500212static inline void dquot_free_inode(const struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700213{
214}
215
Christoph Hellwigb43fa822010-03-03 09:05:03 -0500216static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
Andrew Morton50f8c372008-04-28 02:14:35 -0700217{
218 return 0;
219}
220
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500221static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
222 int warn, int reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500224 if (!reserve)
225 inode_add_bytes(inode, number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 return 0;
227}
228
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500229static inline void __dquot_free_space(struct inode *inode, qsize_t number,
230 int reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500232 if (!reserve)
233 inode_sub_bytes(inode, number);
234}
235
236static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
237{
238 inode_add_bytes(inode, number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 return 0;
240}
241
Christoph Hellwig0f0dd622010-05-19 07:16:41 -0400242static inline int dquot_disable(struct super_block *sb, int type,
243 unsigned int flags)
244{
245 return 0;
246}
247
248static inline int dquot_suspend(struct super_block *sb, int type)
249{
250 return 0;
251}
252
253static inline int dquot_resume(struct super_block *sb, int type)
254{
255 return 0;
256}
257
Christoph Hellwig871a2932010-03-03 09:05:07 -0500258#define dquot_file_open generic_file_open
259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260#endif /* CONFIG_QUOTA */
261
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500262static inline int dquot_alloc_space_nodirty(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700263{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500264 return __dquot_alloc_space(inode, nr, 1, 0);
Jan Kara03f6e922008-04-28 02:14:32 -0700265}
266
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500267static inline int dquot_alloc_space(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700268{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500269 int ret;
270
271 ret = dquot_alloc_space_nodirty(inode, nr);
272 if (!ret)
273 mark_inode_dirty(inode);
274 return ret;
Jan Kara03f6e922008-04-28 02:14:32 -0700275}
276
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500277static inline int dquot_alloc_block_nodirty(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700278{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500279 return dquot_alloc_space_nodirty(inode, nr << inode->i_blkbits);
Jan Kara03f6e922008-04-28 02:14:32 -0700280}
281
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500282static inline int dquot_alloc_block(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(inode, nr << inode->i_blkbits);
Jan Kara03f6e922008-04-28 02:14:32 -0700285}
286
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500287static inline int dquot_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
Mingming Caof18df222009-01-13 16:43:09 +0100288{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500289 return __dquot_alloc_space(inode, nr << inode->i_blkbits, 0, 0);
Mingming Caof18df222009-01-13 16:43:09 +0100290}
291
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500292static inline int dquot_prealloc_block(struct inode *inode, qsize_t nr)
Mingming Cao740d9dc2009-01-13 16:43:14 +0100293{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500294 int ret;
295
296 ret = dquot_prealloc_block_nodirty(inode, nr);
297 if (!ret)
298 mark_inode_dirty(inode);
299 return ret;
Mingming Cao740d9dc2009-01-13 16:43:14 +0100300}
301
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500302static inline int dquot_reserve_block(struct inode *inode, qsize_t nr)
Mingming Cao740d9dc2009-01-13 16:43:14 +0100303{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500304 return __dquot_alloc_space(inode, nr << inode->i_blkbits, 1, 1);
Mingming Cao740d9dc2009-01-13 16:43:14 +0100305}
306
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500307static inline int dquot_claim_block(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700308{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500309 int ret;
310
311 ret = dquot_claim_space_nodirty(inode, nr << inode->i_blkbits);
312 if (!ret)
313 mark_inode_dirty(inode);
314 return ret;
Jan Kara03f6e922008-04-28 02:14:32 -0700315}
316
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500317static inline void dquot_free_space_nodirty(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700318{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500319 __dquot_free_space(inode, nr, 0);
320}
321
322static inline void dquot_free_space(struct inode *inode, qsize_t nr)
323{
324 dquot_free_space_nodirty(inode, nr);
325 mark_inode_dirty(inode);
326}
327
328static inline void dquot_free_block_nodirty(struct inode *inode, qsize_t nr)
329{
330 dquot_free_space_nodirty(inode, nr << inode->i_blkbits);
331}
332
333static inline void dquot_free_block(struct inode *inode, qsize_t nr)
334{
335 dquot_free_space(inode, nr << inode->i_blkbits);
336}
337
338static inline void dquot_release_reservation_block(struct inode *inode,
339 qsize_t nr)
340{
341 __dquot_free_space(inode, nr << inode->i_blkbits, 1);
Jan Kara03f6e922008-04-28 02:14:32 -0700342}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344#endif /* _LINUX_QUOTAOPS_ */