blob: 370abb1e99cbda13b2615e8353cf5d8a67e41caf [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
Jan Karabc8e5f02010-05-13 19:58:50 +020079int __dquot_transfer(struct inode *inode, struct dquot **transfer_to);
Christoph Hellwigb43fa822010-03-03 09:05:03 -050080int dquot_transfer(struct inode *inode, struct iattr *iattr);
Jan Karab85f4b82008-07-25 01:46:50 -070081int vfs_dq_quota_on_remount(struct super_block *sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Jan Kara03b06342008-07-25 01:46:52 -070083static inline struct mem_dqinfo *sb_dqinfo(struct super_block *sb, int type)
84{
85 return sb_dqopt(sb)->info + type;
86}
Jan Kara74abb982008-07-25 01:46:51 -070087
88/*
89 * Functions for checking status of quota
90 */
91
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +030092static inline bool sb_has_quota_usage_enabled(struct super_block *sb, int type)
Jan Kara03b06342008-07-25 01:46:52 -070093{
Jan Karaf55abc02008-08-20 17:50:32 +020094 return sb_dqopt(sb)->flags &
95 dquot_state_flag(DQUOT_USAGE_ENABLED, type);
Jan Kara03b06342008-07-25 01:46:52 -070096}
Jan Kara74abb982008-07-25 01:46:51 -070097
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +030098static inline bool sb_has_quota_limits_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_LIMITS_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_suspended(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_SUSPENDED, 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 unsigned sb_any_quota_suspended(struct super_block *sb)
Jan Kara03b06342008-07-25 01:46:52 -0700111{
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300112 unsigned type, tmsk = 0;
113 for (type = 0; type < MAXQUOTAS; type++)
114 tmsk |= sb_has_quota_suspended(sb, type) << type;
115 return tmsk;
Jan Kara03b06342008-07-25 01:46:52 -0700116}
Jan Kara74abb982008-07-25 01:46:51 -0700117
Jan Karaf55abc02008-08-20 17:50:32 +0200118/* Does kernel know about any quota information for given sb + type? */
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300119static inline bool sb_has_quota_loaded(struct super_block *sb, int type)
Jan Karaf55abc02008-08-20 17:50:32 +0200120{
121 /* Currently if anything is on, then quota usage is on as well */
122 return sb_has_quota_usage_enabled(sb, type);
123}
124
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300125static inline unsigned sb_any_quota_loaded(struct super_block *sb)
Jan Karaf55abc02008-08-20 17:50:32 +0200126{
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300127 unsigned type, tmsk = 0;
128 for (type = 0; type < MAXQUOTAS; type++)
129 tmsk |= sb_has_quota_loaded(sb, type) << type;
130 return tmsk;
Jan Karaf55abc02008-08-20 17:50:32 +0200131}
132
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300133static inline bool sb_has_quota_active(struct super_block *sb, int type)
Jan Karaf55abc02008-08-20 17:50:32 +0200134{
135 return sb_has_quota_loaded(sb, type) &&
136 !sb_has_quota_suspended(sb, type);
137}
138
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300139static inline unsigned sb_any_quota_active(struct super_block *sb)
Jan Karaf55abc02008-08-20 17:50:32 +0200140{
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300141 return sb_any_quota_loaded(sb) & ~sb_any_quota_suspended(sb);
Jan Karaf55abc02008-08-20 17:50:32 +0200142}
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144/*
145 * Operations supported for diskquotas.
146 */
Alexey Dobriyan61e225d2009-09-21 17:01:08 -0700147extern const struct dquot_operations dquot_operations;
Alexey Dobriyan0d54b212009-09-21 17:01:09 -0700148extern const struct quotactl_ops vfs_quotactl_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150#define sb_dquot_ops (&dquot_operations)
151#define sb_quotactl_ops (&vfs_quotactl_ops)
152
Christoph Hellwig850b2012009-04-27 16:43:54 +0200153/* Cannot be called inside a transaction */
Jan Karab85f4b82008-07-25 01:46:50 -0700154static inline int vfs_dq_off(struct super_block *sb, int remount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155{
156 int ret = -ENOSYS;
157
Jan Kara0ff5af82008-04-28 02:14:33 -0700158 if (sb->s_qcop && sb->s_qcop->quota_off)
159 ret = sb->s_qcop->quota_off(sb, -1, remount);
160 return ret;
161}
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163#else
164
Jan Karaf55abc02008-08-20 17:50:32 +0200165static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type)
Jan Kara03b06342008-07-25 01:46:52 -0700166{
167 return 0;
168}
169
Jan Karaf55abc02008-08-20 17:50:32 +0200170static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type)
Jan Kara03b06342008-07-25 01:46:52 -0700171{
172 return 0;
173}
174
175static inline int sb_has_quota_suspended(struct super_block *sb, int type)
176{
177 return 0;
178}
179
180static inline int sb_any_quota_suspended(struct super_block *sb)
181{
182 return 0;
183}
Jan Kara74abb982008-07-25 01:46:51 -0700184
Jan Karaf55abc02008-08-20 17:50:32 +0200185/* Does kernel know about any quota information for given sb + type? */
186static inline int sb_has_quota_loaded(struct super_block *sb, int type)
187{
188 return 0;
189}
190
191static inline int sb_any_quota_loaded(struct super_block *sb)
192{
193 return 0;
194}
195
196static inline int sb_has_quota_active(struct super_block *sb, int type)
197{
198 return 0;
199}
200
201static inline int sb_any_quota_active(struct super_block *sb)
202{
203 return 0;
204}
205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206/*
207 * NO-OP when quota not configured.
208 */
209#define sb_dquot_ops (NULL)
210#define sb_quotactl_ops (NULL)
Andrew Morton50f8c372008-04-28 02:14:35 -0700211
Christoph Hellwig871a2932010-03-03 09:05:07 -0500212static inline void dquot_initialize(struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700213{
214}
215
Christoph Hellwig9f754752010-03-03 09:05:05 -0500216static inline void dquot_drop(struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700217{
218}
219
Christoph Hellwig63936dd2010-03-03 09:05:01 -0500220static inline int dquot_alloc_inode(const struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700221{
222 return 0;
223}
224
Christoph Hellwig63936dd2010-03-03 09:05:01 -0500225static inline void dquot_free_inode(const struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700226{
227}
228
Jan Karab85f4b82008-07-25 01:46:50 -0700229static inline int vfs_dq_off(struct super_block *sb, int remount)
Andrew Morton50f8c372008-04-28 02:14:35 -0700230{
231 return 0;
232}
233
Jan Karab85f4b82008-07-25 01:46:50 -0700234static inline int vfs_dq_quota_on_remount(struct super_block *sb)
Andrew Morton50f8c372008-04-28 02:14:35 -0700235{
236 return 0;
237}
238
Christoph Hellwigb43fa822010-03-03 09:05:03 -0500239static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
Andrew Morton50f8c372008-04-28 02:14:35 -0700240{
241 return 0;
242}
243
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500244static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
245 int warn, int reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500247 if (!reserve)
248 inode_add_bytes(inode, number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 return 0;
250}
251
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500252static inline void __dquot_free_space(struct inode *inode, qsize_t number,
253 int reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500255 if (!reserve)
256 inode_sub_bytes(inode, number);
257}
258
259static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
260{
261 inode_add_bytes(inode, number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 return 0;
263}
264
Christoph Hellwig871a2932010-03-03 09:05:07 -0500265#define dquot_file_open generic_file_open
266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267#endif /* CONFIG_QUOTA */
268
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500269static inline int dquot_alloc_space_nodirty(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700270{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500271 return __dquot_alloc_space(inode, nr, 1, 0);
Jan Kara03f6e922008-04-28 02:14:32 -0700272}
273
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500274static inline int dquot_alloc_space(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700275{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500276 int ret;
277
278 ret = dquot_alloc_space_nodirty(inode, nr);
279 if (!ret)
280 mark_inode_dirty(inode);
281 return ret;
Jan Kara03f6e922008-04-28 02:14:32 -0700282}
283
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500284static inline int dquot_alloc_block_nodirty(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700285{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500286 return dquot_alloc_space_nodirty(inode, nr << inode->i_blkbits);
Jan Kara03f6e922008-04-28 02:14:32 -0700287}
288
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500289static inline int dquot_alloc_block(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700290{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500291 return dquot_alloc_space(inode, nr << inode->i_blkbits);
Jan Kara03f6e922008-04-28 02:14:32 -0700292}
293
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500294static inline int dquot_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
Mingming Caof18df222009-01-13 16:43:09 +0100295{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500296 return __dquot_alloc_space(inode, nr << inode->i_blkbits, 0, 0);
Mingming Caof18df222009-01-13 16:43:09 +0100297}
298
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500299static inline int dquot_prealloc_block(struct inode *inode, qsize_t nr)
Mingming Cao740d9dc2009-01-13 16:43:14 +0100300{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500301 int ret;
302
303 ret = dquot_prealloc_block_nodirty(inode, nr);
304 if (!ret)
305 mark_inode_dirty(inode);
306 return ret;
Mingming Cao740d9dc2009-01-13 16:43:14 +0100307}
308
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500309static inline int dquot_reserve_block(struct inode *inode, qsize_t nr)
Mingming Cao740d9dc2009-01-13 16:43:14 +0100310{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500311 return __dquot_alloc_space(inode, nr << inode->i_blkbits, 1, 1);
Mingming Cao740d9dc2009-01-13 16:43:14 +0100312}
313
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500314static inline int dquot_claim_block(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700315{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500316 int ret;
317
318 ret = dquot_claim_space_nodirty(inode, nr << inode->i_blkbits);
319 if (!ret)
320 mark_inode_dirty(inode);
321 return ret;
Jan Kara03f6e922008-04-28 02:14:32 -0700322}
323
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500324static inline void dquot_free_space_nodirty(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700325{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500326 __dquot_free_space(inode, nr, 0);
327}
328
329static inline void dquot_free_space(struct inode *inode, qsize_t nr)
330{
331 dquot_free_space_nodirty(inode, nr);
332 mark_inode_dirty(inode);
333}
334
335static inline void dquot_free_block_nodirty(struct inode *inode, qsize_t nr)
336{
337 dquot_free_space_nodirty(inode, nr << inode->i_blkbits);
338}
339
340static inline void dquot_free_block(struct inode *inode, qsize_t nr)
341{
342 dquot_free_space(inode, nr << inode->i_blkbits);
343}
344
345static inline void dquot_release_reservation_block(struct inode *inode,
346 qsize_t nr)
347{
348 __dquot_free_space(inode, nr << inode->i_blkbits, 1);
Jan Kara03f6e922008-04-28 02:14:32 -0700349}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351#endif /* _LINUX_QUOTAOPS_ */