blob: 0c8f9fe462af726d8d82e1ed6ccb1c4dcb44e34f [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>
6 *
7 * Version: $Id: quotaops.h,v 1.2 1998/01/15 16:22:26 ecd Exp $
8 *
9 */
10#ifndef _LINUX_QUOTAOPS_
11#define _LINUX_QUOTAOPS_
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/smp_lock.h>
14
15#include <linux/fs.h>
16
17#if defined(CONFIG_QUOTA)
18
19/*
20 * declaration of quota_function calls in kernel.
21 */
Jan Karab85f4b82008-07-25 01:46:50 -070022void sync_dquots(struct super_block *sb, int type);
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Jan Karab85f4b82008-07-25 01:46:50 -070024int dquot_initialize(struct inode *inode, int type);
25int dquot_drop(struct inode *inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Jan Karab85f4b82008-07-25 01:46:50 -070027int dquot_alloc_space(struct inode *inode, qsize_t number, int prealloc);
28int dquot_alloc_inode(const struct inode *inode, unsigned long number);
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Jan Karab85f4b82008-07-25 01:46:50 -070030int dquot_free_space(struct inode *inode, qsize_t number);
31int dquot_free_inode(const struct inode *inode, unsigned long number);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Jan Karab85f4b82008-07-25 01:46:50 -070033int dquot_transfer(struct inode *inode, struct iattr *iattr);
34int dquot_commit(struct dquot *dquot);
35int dquot_acquire(struct dquot *dquot);
36int dquot_release(struct dquot *dquot);
37int dquot_commit_info(struct super_block *sb, int type);
38int dquot_mark_dquot_dirty(struct dquot *dquot);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Jan Karab85f4b82008-07-25 01:46:50 -070040int vfs_quota_on(struct super_block *sb, int type, int format_id,
41 char *path, int remount);
42int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
43 int format_id, int type);
44int vfs_quota_off(struct super_block *sb, int type, int remount);
45int vfs_quota_sync(struct super_block *sb, int type);
46int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
47int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
48int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
49int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
50
51void vfs_dq_drop(struct inode *inode);
52int vfs_dq_transfer(struct inode *inode, struct iattr *iattr);
53int vfs_dq_quota_on_remount(struct super_block *sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55/*
56 * Operations supported for diskquotas.
57 */
58extern struct dquot_operations dquot_operations;
59extern struct quotactl_ops vfs_quotactl_ops;
60
61#define sb_dquot_ops (&dquot_operations)
62#define sb_quotactl_ops (&vfs_quotactl_ops)
63
64/* It is better to call this function outside of any transaction as it might
65 * need a lot of space in journal for dquot structure allocation. */
Jan Karab85f4b82008-07-25 01:46:50 -070066static inline void vfs_dq_init(struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
68 BUG_ON(!inode->i_sb);
69 if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode))
70 inode->i_sb->dq_op->initialize(inode, -1);
71}
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073/* The following allocation/freeing/transfer functions *must* be called inside
74 * a transaction (deadlocks possible otherwise) */
Jan Karab85f4b82008-07-25 01:46:50 -070075static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
77 if (sb_any_quota_enabled(inode->i_sb)) {
78 /* Used space is updated in alloc_space() */
79 if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
80 return 1;
81 }
82 else
83 inode_add_bytes(inode, nr);
84 return 0;
85}
86
Jan Karab85f4b82008-07-25 01:46:50 -070087static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088{
89 int ret;
Jan Karab85f4b82008-07-25 01:46:50 -070090 if (!(ret = vfs_dq_prealloc_space_nodirty(inode, nr)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 mark_inode_dirty(inode);
92 return ret;
93}
94
Jan Karab85f4b82008-07-25 01:46:50 -070095static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096{
97 if (sb_any_quota_enabled(inode->i_sb)) {
98 /* Used space is updated in alloc_space() */
99 if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
100 return 1;
101 }
102 else
103 inode_add_bytes(inode, nr);
104 return 0;
105}
106
Jan Karab85f4b82008-07-25 01:46:50 -0700107static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
109 int ret;
Jan Karab85f4b82008-07-25 01:46:50 -0700110 if (!(ret = vfs_dq_alloc_space_nodirty(inode, nr)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 mark_inode_dirty(inode);
112 return ret;
113}
114
Jan Karab85f4b82008-07-25 01:46:50 -0700115static inline int vfs_dq_alloc_inode(struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116{
117 if (sb_any_quota_enabled(inode->i_sb)) {
Jan Karab85f4b82008-07-25 01:46:50 -0700118 vfs_dq_init(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
120 return 1;
121 }
122 return 0;
123}
124
Jan Karab85f4b82008-07-25 01:46:50 -0700125static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
127 if (sb_any_quota_enabled(inode->i_sb))
128 inode->i_sb->dq_op->free_space(inode, nr);
129 else
130 inode_sub_bytes(inode, nr);
131}
132
Jan Karab85f4b82008-07-25 01:46:50 -0700133static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134{
Jan Karab85f4b82008-07-25 01:46:50 -0700135 vfs_dq_free_space_nodirty(inode, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 mark_inode_dirty(inode);
137}
138
Jan Karab85f4b82008-07-25 01:46:50 -0700139static inline void vfs_dq_free_inode(struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140{
141 if (sb_any_quota_enabled(inode->i_sb))
142 inode->i_sb->dq_op->free_inode(inode, 1);
143}
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145/* The following two functions cannot be called inside a transaction */
Jan Karab85f4b82008-07-25 01:46:50 -0700146static inline void vfs_dq_sync(struct super_block *sb)
Jan Kara03f6e922008-04-28 02:14:32 -0700147{
148 sync_dquots(sb, -1);
149}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
Jan Karab85f4b82008-07-25 01:46:50 -0700151static inline int vfs_dq_off(struct super_block *sb, int remount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152{
153 int ret = -ENOSYS;
154
Jan Kara0ff5af82008-04-28 02:14:33 -0700155 if (sb->s_qcop && sb->s_qcop->quota_off)
156 ret = sb->s_qcop->quota_off(sb, -1, remount);
157 return ret;
158}
159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160#else
161
162/*
163 * NO-OP when quota not configured.
164 */
165#define sb_dquot_ops (NULL)
166#define sb_quotactl_ops (NULL)
Andrew Morton50f8c372008-04-28 02:14:35 -0700167
Jan Karab85f4b82008-07-25 01:46:50 -0700168static inline void vfs_dq_init(struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700169{
170}
171
Jan Karab85f4b82008-07-25 01:46:50 -0700172static inline void vfs_dq_drop(struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700173{
174}
175
Jan Karab85f4b82008-07-25 01:46:50 -0700176static inline int vfs_dq_alloc_inode(struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700177{
178 return 0;
179}
180
Jan Karab85f4b82008-07-25 01:46:50 -0700181static inline void vfs_dq_free_inode(struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700182{
183}
184
Jan Karab85f4b82008-07-25 01:46:50 -0700185static inline void vfs_dq_sync(struct super_block *sb)
Andrew Morton50f8c372008-04-28 02:14:35 -0700186{
187}
188
Jan Karab85f4b82008-07-25 01:46:50 -0700189static inline int vfs_dq_off(struct super_block *sb, int remount)
Andrew Morton50f8c372008-04-28 02:14:35 -0700190{
191 return 0;
192}
193
Jan Karab85f4b82008-07-25 01:46:50 -0700194static inline int vfs_dq_quota_on_remount(struct super_block *sb)
Andrew Morton50f8c372008-04-28 02:14:35 -0700195{
196 return 0;
197}
198
Jan Karab85f4b82008-07-25 01:46:50 -0700199static inline int vfs_dq_transfer(struct inode *inode, struct iattr *iattr)
Andrew Morton50f8c372008-04-28 02:14:35 -0700200{
201 return 0;
202}
203
Jan Karab85f4b82008-07-25 01:46:50 -0700204static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205{
206 inode_add_bytes(inode, nr);
207 return 0;
208}
209
Jan Karab85f4b82008-07-25 01:46:50 -0700210static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211{
Jan Karab85f4b82008-07-25 01:46:50 -0700212 vfs_dq_prealloc_space_nodirty(inode, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 mark_inode_dirty(inode);
214 return 0;
215}
216
Jan Karab85f4b82008-07-25 01:46:50 -0700217static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
219 inode_add_bytes(inode, nr);
220 return 0;
221}
222
Jan Karab85f4b82008-07-25 01:46:50 -0700223static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224{
Jan Karab85f4b82008-07-25 01:46:50 -0700225 vfs_dq_alloc_space_nodirty(inode, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 mark_inode_dirty(inode);
227 return 0;
228}
229
Jan Karab85f4b82008-07-25 01:46:50 -0700230static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
232 inode_sub_bytes(inode, nr);
233}
234
Jan Karab85f4b82008-07-25 01:46:50 -0700235static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236{
Jan Karab85f4b82008-07-25 01:46:50 -0700237 vfs_dq_free_space_nodirty(inode, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 mark_inode_dirty(inode);
239}
240
241#endif /* CONFIG_QUOTA */
242
Jan Karab85f4b82008-07-25 01:46:50 -0700243static inline int vfs_dq_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700244{
Jan Karab85f4b82008-07-25 01:46:50 -0700245 return vfs_dq_prealloc_space_nodirty(inode,
Jan Kara03f6e922008-04-28 02:14:32 -0700246 nr << inode->i_sb->s_blocksize_bits);
247}
248
Jan Karab85f4b82008-07-25 01:46:50 -0700249static inline int vfs_dq_prealloc_block(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700250{
Jan Karab85f4b82008-07-25 01:46:50 -0700251 return vfs_dq_prealloc_space(inode,
Jan Kara03f6e922008-04-28 02:14:32 -0700252 nr << inode->i_sb->s_blocksize_bits);
253}
254
Jan Karab85f4b82008-07-25 01:46:50 -0700255static inline int vfs_dq_alloc_block_nodirty(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700256{
Jan Karab85f4b82008-07-25 01:46:50 -0700257 return vfs_dq_alloc_space_nodirty(inode,
Jan Kara03f6e922008-04-28 02:14:32 -0700258 nr << inode->i_sb->s_blocksize_bits);
259}
260
Jan Karab85f4b82008-07-25 01:46:50 -0700261static inline int vfs_dq_alloc_block(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700262{
Jan Karab85f4b82008-07-25 01:46:50 -0700263 return vfs_dq_alloc_space(inode,
Jan Kara03f6e922008-04-28 02:14:32 -0700264 nr << inode->i_sb->s_blocksize_bits);
265}
266
Jan Karab85f4b82008-07-25 01:46:50 -0700267static inline void vfs_dq_free_block_nodirty(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700268{
Jan Karab85f4b82008-07-25 01:46:50 -0700269 vfs_dq_free_space_nodirty(inode, nr << inode->i_sb->s_blocksize_bits);
Jan Kara03f6e922008-04-28 02:14:32 -0700270}
271
Jan Karab85f4b82008-07-25 01:46:50 -0700272static inline void vfs_dq_free_block(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700273{
Jan Karab85f4b82008-07-25 01:46:50 -0700274 vfs_dq_free_space(inode, nr << inode->i_sb->s_blocksize_bits);
Jan Kara03f6e922008-04-28 02:14:32 -0700275}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Jan Karab85f4b82008-07-25 01:46:50 -0700277/*
278 * Define uppercase equivalents for compatibility with old function names
279 * Can go away when we think all users have been converted (15/04/2008)
280 */
281#define DQUOT_INIT(inode) vfs_dq_init(inode)
282#define DQUOT_DROP(inode) vfs_dq_drop(inode)
283#define DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr) \
284 vfs_dq_prealloc_space_nodirty(inode, nr)
285#define DQUOT_PREALLOC_SPACE(inode, nr) vfs_dq_prealloc_space(inode, nr)
286#define DQUOT_ALLOC_SPACE_NODIRTY(inode, nr) \
287 vfs_dq_alloc_space_nodirty(inode, nr)
288#define DQUOT_ALLOC_SPACE(inode, nr) vfs_dq_alloc_space(inode, nr)
289#define DQUOT_PREALLOC_BLOCK_NODIRTY(inode, nr) \
290 vfs_dq_prealloc_block_nodirty(inode, nr)
291#define DQUOT_PREALLOC_BLOCK(inode, nr) vfs_dq_prealloc_block(inode, nr)
292#define DQUOT_ALLOC_BLOCK_NODIRTY(inode, nr) \
293 vfs_dq_alloc_block_nodirty(inode, nr)
294#define DQUOT_ALLOC_BLOCK(inode, nr) vfs_dq_alloc_block(inode, nr)
295#define DQUOT_ALLOC_INODE(inode) vfs_dq_alloc_inode(inode)
296#define DQUOT_FREE_SPACE_NODIRTY(inode, nr) \
297 vfs_dq_free_space_nodirty(inode, nr)
298#define DQUOT_FREE_SPACE(inode, nr) vfs_dq_free_space(inode, nr)
299#define DQUOT_FREE_BLOCK_NODIRTY(inode, nr) \
300 vfs_dq_free_block_nodirty(inode, nr)
301#define DQUOT_FREE_BLOCK(inode, nr) vfs_dq_free_block(inode, nr)
302#define DQUOT_FREE_INODE(inode) vfs_dq_free_inode(inode)
303#define DQUOT_TRANSFER(inode, iattr) vfs_dq_transfer(inode, iattr)
304#define DQUOT_SYNC(sb) vfs_dq_sync(sb)
305#define DQUOT_OFF(sb, remount) vfs_dq_off(sb, remount)
306#define DQUOT_ON_REMOUNT(sb) vfs_dq_quota_on_remount(sb)
307
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308#endif /* _LINUX_QUOTAOPS_ */