blob: f867020538539738cafa8ac22130379889452833 [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 */
22extern void sync_dquots(struct super_block *sb, int type);
23
24extern int dquot_initialize(struct inode *inode, int type);
25extern int dquot_drop(struct inode *inode);
26
27extern int dquot_alloc_space(struct inode *inode, qsize_t number, int prealloc);
28extern int dquot_alloc_inode(const struct inode *inode, unsigned long number);
29
30extern int dquot_free_space(struct inode *inode, qsize_t number);
31extern int dquot_free_inode(const struct inode *inode, unsigned long number);
32
33extern int dquot_transfer(struct inode *inode, struct iattr *iattr);
34extern int dquot_commit(struct dquot *dquot);
35extern int dquot_acquire(struct dquot *dquot);
36extern int dquot_release(struct dquot *dquot);
37extern int dquot_commit_info(struct super_block *sb, int type);
38extern int dquot_mark_dquot_dirty(struct dquot *dquot);
39
Jan Kara0ff5af82008-04-28 02:14:33 -070040extern int vfs_quota_on(struct super_block *sb, int type, int format_id,
41 char *path, int remount);
Christoph Hellwig84de8562005-06-23 00:09:16 -070042extern int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
43 int format_id, int type);
Jan Kara0ff5af82008-04-28 02:14:33 -070044extern int vfs_quota_off(struct super_block *sb, int type, int remount);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045extern int vfs_quota_sync(struct super_block *sb, int type);
46extern int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
47extern int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
48extern int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
49extern int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
50
51/*
52 * Operations supported for diskquotas.
53 */
54extern struct dquot_operations dquot_operations;
55extern struct quotactl_ops vfs_quotactl_ops;
56
57#define sb_dquot_ops (&dquot_operations)
58#define sb_quotactl_ops (&vfs_quotactl_ops)
59
60/* It is better to call this function outside of any transaction as it might
61 * need a lot of space in journal for dquot structure allocation. */
Jan Kara03f6e922008-04-28 02:14:32 -070062static inline void DQUOT_INIT(struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
64 BUG_ON(!inode->i_sb);
65 if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode))
66 inode->i_sb->dq_op->initialize(inode, -1);
67}
68
69/* The same as with DQUOT_INIT */
Jan Kara03f6e922008-04-28 02:14:32 -070070static inline void DQUOT_DROP(struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
72 /* Here we can get arbitrary inode from clear_inode() so we have
73 * to be careful. OTOH we don't need locking as quota operations
74 * are allowed to change only at mount time */
75 if (!IS_NOQUOTA(inode) && inode->i_sb && inode->i_sb->dq_op
76 && inode->i_sb->dq_op->drop) {
77 int cnt;
78 /* Test before calling to rule out calls from proc and such
79 * where we are not allowed to block. Note that this is
80 * actually reliable test even without the lock - the caller
81 * must assure that nobody can come after the DQUOT_DROP and
82 * add quota pointers back anyway */
83 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
84 if (inode->i_dquot[cnt] != NODQUOT)
85 break;
86 if (cnt < MAXQUOTAS)
87 inode->i_sb->dq_op->drop(inode);
88 }
89}
90
91/* The following allocation/freeing/transfer functions *must* be called inside
92 * a transaction (deadlocks possible otherwise) */
Jan Kara03f6e922008-04-28 02:14:32 -070093static inline int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094{
95 if (sb_any_quota_enabled(inode->i_sb)) {
96 /* Used space is updated in alloc_space() */
97 if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
98 return 1;
99 }
100 else
101 inode_add_bytes(inode, nr);
102 return 0;
103}
104
Jan Kara03f6e922008-04-28 02:14:32 -0700105static inline int DQUOT_PREALLOC_SPACE(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
107 int ret;
108 if (!(ret = DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr)))
109 mark_inode_dirty(inode);
110 return ret;
111}
112
Jan Kara03f6e922008-04-28 02:14:32 -0700113static inline int DQUOT_ALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{
115 if (sb_any_quota_enabled(inode->i_sb)) {
116 /* Used space is updated in alloc_space() */
117 if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
118 return 1;
119 }
120 else
121 inode_add_bytes(inode, nr);
122 return 0;
123}
124
Jan Kara03f6e922008-04-28 02:14:32 -0700125static inline int DQUOT_ALLOC_SPACE(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
127 int ret;
128 if (!(ret = DQUOT_ALLOC_SPACE_NODIRTY(inode, nr)))
129 mark_inode_dirty(inode);
130 return ret;
131}
132
Jan Kara03f6e922008-04-28 02:14:32 -0700133static inline int DQUOT_ALLOC_INODE(struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134{
135 if (sb_any_quota_enabled(inode->i_sb)) {
136 DQUOT_INIT(inode);
137 if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
138 return 1;
139 }
140 return 0;
141}
142
Jan Kara03f6e922008-04-28 02:14:32 -0700143static inline void DQUOT_FREE_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144{
145 if (sb_any_quota_enabled(inode->i_sb))
146 inode->i_sb->dq_op->free_space(inode, nr);
147 else
148 inode_sub_bytes(inode, nr);
149}
150
Jan Kara03f6e922008-04-28 02:14:32 -0700151static inline void DQUOT_FREE_SPACE(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152{
153 DQUOT_FREE_SPACE_NODIRTY(inode, nr);
154 mark_inode_dirty(inode);
155}
156
Jan Kara03f6e922008-04-28 02:14:32 -0700157static inline void DQUOT_FREE_INODE(struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
159 if (sb_any_quota_enabled(inode->i_sb))
160 inode->i_sb->dq_op->free_inode(inode, 1);
161}
162
Jan Kara03f6e922008-04-28 02:14:32 -0700163static inline int DQUOT_TRANSFER(struct inode *inode, struct iattr *iattr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164{
165 if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode)) {
166 DQUOT_INIT(inode);
167 if (inode->i_sb->dq_op->transfer(inode, iattr) == NO_QUOTA)
168 return 1;
169 }
170 return 0;
171}
172
173/* The following two functions cannot be called inside a transaction */
Jan Kara03f6e922008-04-28 02:14:32 -0700174static inline void DQUOT_SYNC(struct super_block *sb)
175{
176 sync_dquots(sb, -1);
177}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Jan Kara0ff5af82008-04-28 02:14:33 -0700179static inline int DQUOT_OFF(struct super_block *sb, int remount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180{
181 int ret = -ENOSYS;
182
Jan Kara0ff5af82008-04-28 02:14:33 -0700183 if (sb->s_qcop && sb->s_qcop->quota_off)
184 ret = sb->s_qcop->quota_off(sb, -1, remount);
185 return ret;
186}
187
188static inline int DQUOT_ON_REMOUNT(struct super_block *sb)
189{
190 int cnt;
191 int ret = 0, err;
192
193 if (!sb->s_qcop || !sb->s_qcop->quota_on)
194 return -ENOSYS;
195 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
196 err = sb->s_qcop->quota_on(sb, cnt, 0, NULL, 1);
197 if (err < 0 && !ret)
198 ret = err;
199 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 return ret;
201}
202
203#else
204
205/*
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
211static inline void DQUOT_INIT(struct inode *inode)
212{
213}
214
215static inline void DQUOT_DROP(struct inode *inode)
216{
217}
218
219static inline int DQUOT_ALLOC_INODE(struct inode *inode)
220{
221 return 0;
222}
223
224static inline void DQUOT_FREE_INODE(struct inode *inode)
225{
226}
227
228static inline void DQUOT_SYNC(struct super_block *sb)
229{
230}
231
232static inline int DQUOT_OFF(struct super_block *sb, int remount)
233{
234 return 0;
235}
236
237static inline int DQUOT_ON_REMOUNT(struct super_block *sb)
238{
239 return 0;
240}
241
242static inline int DQUOT_TRANSFER(struct inode *inode, struct iattr *iattr)
243{
244 return 0;
245}
246
Adrian Bunkbe586ba2005-11-07 00:59:35 -0800247static inline int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248{
249 inode_add_bytes(inode, nr);
250 return 0;
251}
252
Adrian Bunkbe586ba2005-11-07 00:59:35 -0800253static inline int DQUOT_PREALLOC_SPACE(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
255 DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr);
256 mark_inode_dirty(inode);
257 return 0;
258}
259
Adrian Bunkbe586ba2005-11-07 00:59:35 -0800260static inline int DQUOT_ALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261{
262 inode_add_bytes(inode, nr);
263 return 0;
264}
265
Adrian Bunkbe586ba2005-11-07 00:59:35 -0800266static inline int DQUOT_ALLOC_SPACE(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267{
268 DQUOT_ALLOC_SPACE_NODIRTY(inode, nr);
269 mark_inode_dirty(inode);
270 return 0;
271}
272
Adrian Bunkbe586ba2005-11-07 00:59:35 -0800273static inline void DQUOT_FREE_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274{
275 inode_sub_bytes(inode, nr);
276}
277
Adrian Bunkbe586ba2005-11-07 00:59:35 -0800278static inline void DQUOT_FREE_SPACE(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279{
280 DQUOT_FREE_SPACE_NODIRTY(inode, nr);
281 mark_inode_dirty(inode);
282}
283
284#endif /* CONFIG_QUOTA */
285
Jan Kara03f6e922008-04-28 02:14:32 -0700286static inline int DQUOT_PREALLOC_BLOCK_NODIRTY(struct inode *inode, qsize_t nr)
287{
288 return DQUOT_PREALLOC_SPACE_NODIRTY(inode,
289 nr << inode->i_sb->s_blocksize_bits);
290}
291
292static inline int DQUOT_PREALLOC_BLOCK(struct inode *inode, qsize_t nr)
293{
294 return DQUOT_PREALLOC_SPACE(inode,
295 nr << inode->i_sb->s_blocksize_bits);
296}
297
298static inline int DQUOT_ALLOC_BLOCK_NODIRTY(struct inode *inode, qsize_t nr)
299{
300 return DQUOT_ALLOC_SPACE_NODIRTY(inode,
301 nr << inode->i_sb->s_blocksize_bits);
302}
303
304static inline int DQUOT_ALLOC_BLOCK(struct inode *inode, qsize_t nr)
305{
306 return DQUOT_ALLOC_SPACE(inode,
307 nr << inode->i_sb->s_blocksize_bits);
308}
309
310static inline void DQUOT_FREE_BLOCK_NODIRTY(struct inode *inode, qsize_t nr)
311{
312 DQUOT_FREE_SPACE_NODIRTY(inode, nr << inode->i_sb->s_blocksize_bits);
313}
314
315static inline void DQUOT_FREE_BLOCK(struct inode *inode, qsize_t nr)
316{
317 DQUOT_FREE_SPACE(inode, nr << inode->i_sb->s_blocksize_bits);
318}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
320#endif /* _LINUX_QUOTAOPS_ */