quota: various style cleanups
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / linux / quotaops.h
CommitLineData
1da177e4
LT
1/*
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
1da177e4
LT
13#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
40extern int vfs_quota_on(struct super_block *sb, int type, int format_id, char *path);
84de856e
CH
41extern int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
42 int format_id, int type);
1da177e4 43extern int vfs_quota_off(struct super_block *sb, int type);
1da177e4
LT
44extern int vfs_quota_sync(struct super_block *sb, int type);
45extern int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
46extern int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
47extern int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
48extern int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
49
50/*
51 * Operations supported for diskquotas.
52 */
53extern struct dquot_operations dquot_operations;
54extern struct quotactl_ops vfs_quotactl_ops;
55
56#define sb_dquot_ops (&dquot_operations)
57#define sb_quotactl_ops (&vfs_quotactl_ops)
58
59/* It is better to call this function outside of any transaction as it might
60 * need a lot of space in journal for dquot structure allocation. */
03f6e92b 61static inline void DQUOT_INIT(struct inode *inode)
1da177e4
LT
62{
63 BUG_ON(!inode->i_sb);
64 if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode))
65 inode->i_sb->dq_op->initialize(inode, -1);
66}
67
68/* The same as with DQUOT_INIT */
03f6e92b 69static inline void DQUOT_DROP(struct inode *inode)
1da177e4
LT
70{
71 /* Here we can get arbitrary inode from clear_inode() so we have
72 * to be careful. OTOH we don't need locking as quota operations
73 * are allowed to change only at mount time */
74 if (!IS_NOQUOTA(inode) && inode->i_sb && inode->i_sb->dq_op
75 && inode->i_sb->dq_op->drop) {
76 int cnt;
77 /* Test before calling to rule out calls from proc and such
78 * where we are not allowed to block. Note that this is
79 * actually reliable test even without the lock - the caller
80 * must assure that nobody can come after the DQUOT_DROP and
81 * add quota pointers back anyway */
82 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
83 if (inode->i_dquot[cnt] != NODQUOT)
84 break;
85 if (cnt < MAXQUOTAS)
86 inode->i_sb->dq_op->drop(inode);
87 }
88}
89
90/* The following allocation/freeing/transfer functions *must* be called inside
91 * a transaction (deadlocks possible otherwise) */
03f6e92b 92static inline int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
1da177e4
LT
93{
94 if (sb_any_quota_enabled(inode->i_sb)) {
95 /* Used space is updated in alloc_space() */
96 if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
97 return 1;
98 }
99 else
100 inode_add_bytes(inode, nr);
101 return 0;
102}
103
03f6e92b 104static inline int DQUOT_PREALLOC_SPACE(struct inode *inode, qsize_t nr)
1da177e4
LT
105{
106 int ret;
107 if (!(ret = DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr)))
108 mark_inode_dirty(inode);
109 return ret;
110}
111
03f6e92b 112static inline int DQUOT_ALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
1da177e4
LT
113{
114 if (sb_any_quota_enabled(inode->i_sb)) {
115 /* Used space is updated in alloc_space() */
116 if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
117 return 1;
118 }
119 else
120 inode_add_bytes(inode, nr);
121 return 0;
122}
123
03f6e92b 124static inline int DQUOT_ALLOC_SPACE(struct inode *inode, qsize_t nr)
1da177e4
LT
125{
126 int ret;
127 if (!(ret = DQUOT_ALLOC_SPACE_NODIRTY(inode, nr)))
128 mark_inode_dirty(inode);
129 return ret;
130}
131
03f6e92b 132static inline int DQUOT_ALLOC_INODE(struct inode *inode)
1da177e4
LT
133{
134 if (sb_any_quota_enabled(inode->i_sb)) {
135 DQUOT_INIT(inode);
136 if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
137 return 1;
138 }
139 return 0;
140}
141
03f6e92b 142static inline void DQUOT_FREE_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
1da177e4
LT
143{
144 if (sb_any_quota_enabled(inode->i_sb))
145 inode->i_sb->dq_op->free_space(inode, nr);
146 else
147 inode_sub_bytes(inode, nr);
148}
149
03f6e92b 150static inline void DQUOT_FREE_SPACE(struct inode *inode, qsize_t nr)
1da177e4
LT
151{
152 DQUOT_FREE_SPACE_NODIRTY(inode, nr);
153 mark_inode_dirty(inode);
154}
155
03f6e92b 156static inline void DQUOT_FREE_INODE(struct inode *inode)
1da177e4
LT
157{
158 if (sb_any_quota_enabled(inode->i_sb))
159 inode->i_sb->dq_op->free_inode(inode, 1);
160}
161
03f6e92b 162static inline int DQUOT_TRANSFER(struct inode *inode, struct iattr *iattr)
1da177e4
LT
163{
164 if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode)) {
165 DQUOT_INIT(inode);
166 if (inode->i_sb->dq_op->transfer(inode, iattr) == NO_QUOTA)
167 return 1;
168 }
169 return 0;
170}
171
172/* The following two functions cannot be called inside a transaction */
03f6e92b
JK
173static inline void DQUOT_SYNC(struct super_block *sb)
174{
175 sync_dquots(sb, -1);
176}
1da177e4 177
03f6e92b 178static inline int DQUOT_OFF(struct super_block *sb)
1da177e4
LT
179{
180 int ret = -ENOSYS;
181
182 if (sb_any_quota_enabled(sb) && sb->s_qcop && sb->s_qcop->quota_off)
183 ret = sb->s_qcop->quota_off(sb, -1);
184 return ret;
185}
186
187#else
188
189/*
190 * NO-OP when quota not configured.
191 */
192#define sb_dquot_ops (NULL)
193#define sb_quotactl_ops (NULL)
1da177e4
LT
194#define DQUOT_INIT(inode) do { } while(0)
195#define DQUOT_DROP(inode) do { } while(0)
196#define DQUOT_ALLOC_INODE(inode) (0)
197#define DQUOT_FREE_INODE(inode) do { } while(0)
198#define DQUOT_SYNC(sb) do { } while(0)
03f6e92b 199#define DQUOT_OFF(sb) (0)
1da177e4 200#define DQUOT_TRANSFER(inode, iattr) (0)
be586bab 201static inline int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
1da177e4
LT
202{
203 inode_add_bytes(inode, nr);
204 return 0;
205}
206
be586bab 207static inline int DQUOT_PREALLOC_SPACE(struct inode *inode, qsize_t nr)
1da177e4
LT
208{
209 DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr);
210 mark_inode_dirty(inode);
211 return 0;
212}
213
be586bab 214static inline int DQUOT_ALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
1da177e4
LT
215{
216 inode_add_bytes(inode, nr);
217 return 0;
218}
219
be586bab 220static inline int DQUOT_ALLOC_SPACE(struct inode *inode, qsize_t nr)
1da177e4
LT
221{
222 DQUOT_ALLOC_SPACE_NODIRTY(inode, nr);
223 mark_inode_dirty(inode);
224 return 0;
225}
226
be586bab 227static inline void DQUOT_FREE_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
1da177e4
LT
228{
229 inode_sub_bytes(inode, nr);
230}
231
be586bab 232static inline void DQUOT_FREE_SPACE(struct inode *inode, qsize_t nr)
1da177e4
LT
233{
234 DQUOT_FREE_SPACE_NODIRTY(inode, nr);
235 mark_inode_dirty(inode);
236}
237
238#endif /* CONFIG_QUOTA */
239
03f6e92b
JK
240static inline int DQUOT_PREALLOC_BLOCK_NODIRTY(struct inode *inode, qsize_t nr)
241{
242 return DQUOT_PREALLOC_SPACE_NODIRTY(inode,
243 nr << inode->i_sb->s_blocksize_bits);
244}
245
246static inline int DQUOT_PREALLOC_BLOCK(struct inode *inode, qsize_t nr)
247{
248 return DQUOT_PREALLOC_SPACE(inode,
249 nr << inode->i_sb->s_blocksize_bits);
250}
251
252static inline int DQUOT_ALLOC_BLOCK_NODIRTY(struct inode *inode, qsize_t nr)
253{
254 return DQUOT_ALLOC_SPACE_NODIRTY(inode,
255 nr << inode->i_sb->s_blocksize_bits);
256}
257
258static inline int DQUOT_ALLOC_BLOCK(struct inode *inode, qsize_t nr)
259{
260 return DQUOT_ALLOC_SPACE(inode,
261 nr << inode->i_sb->s_blocksize_bits);
262}
263
264static inline void DQUOT_FREE_BLOCK_NODIRTY(struct inode *inode, qsize_t nr)
265{
266 DQUOT_FREE_SPACE_NODIRTY(inode, nr << inode->i_sb->s_blocksize_bits);
267}
268
269static inline void DQUOT_FREE_BLOCK(struct inode *inode, qsize_t nr)
270{
271 DQUOT_FREE_SPACE(inode, nr << inode->i_sb->s_blocksize_bits);
272}
1da177e4
LT
273
274#endif /* _LINUX_QUOTAOPS_ */