blob: 742187f7a05c54051da11975373acd5cc3de56e2 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/fs.h>
15
Jan Kara03b06342008-07-25 01:46:52 -070016static inline struct quota_info *sb_dqopt(struct super_block *sb)
17{
18 return &sb->s_dquot;
19}
Jan Kara74abb982008-07-25 01:46:51 -070020
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#if defined(CONFIG_QUOTA)
22
23/*
24 * declaration of quota_function calls in kernel.
25 */
Jan Karab85f4b82008-07-25 01:46:50 -070026void sync_dquots(struct super_block *sb, int type);
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Jan Karab85f4b82008-07-25 01:46:50 -070028int dquot_initialize(struct inode *inode, int type);
29int dquot_drop(struct inode *inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Jan Karab85f4b82008-07-25 01:46:50 -070031int dquot_alloc_space(struct inode *inode, qsize_t number, int prealloc);
32int dquot_alloc_inode(const struct inode *inode, unsigned long number);
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Jan Karab85f4b82008-07-25 01:46:50 -070034int dquot_free_space(struct inode *inode, qsize_t number);
35int dquot_free_inode(const struct inode *inode, unsigned long number);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Jan Karab85f4b82008-07-25 01:46:50 -070037int dquot_transfer(struct inode *inode, struct iattr *iattr);
38int dquot_commit(struct dquot *dquot);
39int dquot_acquire(struct dquot *dquot);
40int dquot_release(struct dquot *dquot);
41int dquot_commit_info(struct super_block *sb, int type);
42int dquot_mark_dquot_dirty(struct dquot *dquot);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Jan Karab85f4b82008-07-25 01:46:50 -070044int vfs_quota_on(struct super_block *sb, int type, int format_id,
45 char *path, int remount);
46int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
47 int format_id, int type);
48int vfs_quota_off(struct super_block *sb, int type, int remount);
49int vfs_quota_sync(struct super_block *sb, int type);
50int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
51int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
52int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
53int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
54
55void vfs_dq_drop(struct inode *inode);
56int vfs_dq_transfer(struct inode *inode, struct iattr *iattr);
57int vfs_dq_quota_on_remount(struct super_block *sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Jan Kara03b06342008-07-25 01:46:52 -070059static inline struct mem_dqinfo *sb_dqinfo(struct super_block *sb, int type)
60{
61 return sb_dqopt(sb)->info + type;
62}
Jan Kara74abb982008-07-25 01:46:51 -070063
64/*
65 * Functions for checking status of quota
66 */
67
Jan Kara03b06342008-07-25 01:46:52 -070068static inline int sb_has_quota_enabled(struct super_block *sb, int type)
69{
70 if (type == USRQUOTA)
71 return sb_dqopt(sb)->flags & DQUOT_USR_ENABLED;
72 return sb_dqopt(sb)->flags & DQUOT_GRP_ENABLED;
73}
Jan Kara74abb982008-07-25 01:46:51 -070074
Jan Kara03b06342008-07-25 01:46:52 -070075static inline int sb_any_quota_enabled(struct super_block *sb)
76{
77 return sb_has_quota_enabled(sb, USRQUOTA) ||
78 sb_has_quota_enabled(sb, GRPQUOTA);
79}
Jan Kara74abb982008-07-25 01:46:51 -070080
Jan Kara03b06342008-07-25 01:46:52 -070081static inline int sb_has_quota_suspended(struct super_block *sb, int type)
82{
83 if (type == USRQUOTA)
84 return sb_dqopt(sb)->flags & DQUOT_USR_SUSPENDED;
85 return sb_dqopt(sb)->flags & DQUOT_GRP_SUSPENDED;
86}
Jan Kara74abb982008-07-25 01:46:51 -070087
Jan Kara03b06342008-07-25 01:46:52 -070088static inline int sb_any_quota_suspended(struct super_block *sb)
89{
90 return sb_has_quota_suspended(sb, USRQUOTA) ||
91 sb_has_quota_suspended(sb, GRPQUOTA);
92}
Jan Kara74abb982008-07-25 01:46:51 -070093
Linus Torvalds1da177e2005-04-16 15:20:36 -070094/*
95 * Operations supported for diskquotas.
96 */
97extern struct dquot_operations dquot_operations;
98extern struct quotactl_ops vfs_quotactl_ops;
99
100#define sb_dquot_ops (&dquot_operations)
101#define sb_quotactl_ops (&vfs_quotactl_ops)
102
103/* It is better to call this function outside of any transaction as it might
104 * need a lot of space in journal for dquot structure allocation. */
Jan Karab85f4b82008-07-25 01:46:50 -0700105static inline void vfs_dq_init(struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
107 BUG_ON(!inode->i_sb);
108 if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode))
109 inode->i_sb->dq_op->initialize(inode, -1);
110}
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112/* The following allocation/freeing/transfer functions *must* be called inside
113 * a transaction (deadlocks possible otherwise) */
Jan Karab85f4b82008-07-25 01:46:50 -0700114static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
116 if (sb_any_quota_enabled(inode->i_sb)) {
117 /* Used space is updated in alloc_space() */
118 if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
119 return 1;
120 }
121 else
122 inode_add_bytes(inode, nr);
123 return 0;
124}
125
Jan Karab85f4b82008-07-25 01:46:50 -0700126static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
128 int ret;
Jan Karab85f4b82008-07-25 01:46:50 -0700129 if (!(ret = vfs_dq_prealloc_space_nodirty(inode, nr)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 mark_inode_dirty(inode);
131 return ret;
132}
133
Jan Karab85f4b82008-07-25 01:46:50 -0700134static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135{
136 if (sb_any_quota_enabled(inode->i_sb)) {
137 /* Used space is updated in alloc_space() */
138 if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
139 return 1;
140 }
141 else
142 inode_add_bytes(inode, nr);
143 return 0;
144}
145
Jan Karab85f4b82008-07-25 01:46:50 -0700146static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147{
148 int ret;
Jan Karab85f4b82008-07-25 01:46:50 -0700149 if (!(ret = vfs_dq_alloc_space_nodirty(inode, nr)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 mark_inode_dirty(inode);
151 return ret;
152}
153
Jan Karab85f4b82008-07-25 01:46:50 -0700154static inline int vfs_dq_alloc_inode(struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155{
156 if (sb_any_quota_enabled(inode->i_sb)) {
Jan Karab85f4b82008-07-25 01:46:50 -0700157 vfs_dq_init(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
159 return 1;
160 }
161 return 0;
162}
163
Jan Karab85f4b82008-07-25 01:46:50 -0700164static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165{
166 if (sb_any_quota_enabled(inode->i_sb))
167 inode->i_sb->dq_op->free_space(inode, nr);
168 else
169 inode_sub_bytes(inode, nr);
170}
171
Jan Karab85f4b82008-07-25 01:46:50 -0700172static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
Jan Karab85f4b82008-07-25 01:46:50 -0700174 vfs_dq_free_space_nodirty(inode, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 mark_inode_dirty(inode);
176}
177
Jan Karab85f4b82008-07-25 01:46:50 -0700178static inline void vfs_dq_free_inode(struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179{
180 if (sb_any_quota_enabled(inode->i_sb))
181 inode->i_sb->dq_op->free_inode(inode, 1);
182}
183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184/* The following two functions cannot be called inside a transaction */
Jan Karab85f4b82008-07-25 01:46:50 -0700185static inline void vfs_dq_sync(struct super_block *sb)
Jan Kara03f6e922008-04-28 02:14:32 -0700186{
187 sync_dquots(sb, -1);
188}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
Jan Karab85f4b82008-07-25 01:46:50 -0700190static inline int vfs_dq_off(struct super_block *sb, int remount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191{
192 int ret = -ENOSYS;
193
Jan Kara0ff5af82008-04-28 02:14:33 -0700194 if (sb->s_qcop && sb->s_qcop->quota_off)
195 ret = sb->s_qcop->quota_off(sb, -1, remount);
196 return ret;
197}
198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199#else
200
Jan Kara03b06342008-07-25 01:46:52 -0700201static inline int sb_has_quota_enabled(struct super_block *sb, int type)
202{
203 return 0;
204}
205
206static inline int sb_any_quota_enabled(struct super_block *sb)
207{
208 return 0;
209}
210
211static inline int sb_has_quota_suspended(struct super_block *sb, int type)
212{
213 return 0;
214}
215
216static inline int sb_any_quota_suspended(struct super_block *sb)
217{
218 return 0;
219}
Jan Kara74abb982008-07-25 01:46:51 -0700220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221/*
222 * NO-OP when quota not configured.
223 */
224#define sb_dquot_ops (NULL)
225#define sb_quotactl_ops (NULL)
Andrew Morton50f8c372008-04-28 02:14:35 -0700226
Jan Karab85f4b82008-07-25 01:46:50 -0700227static inline void vfs_dq_init(struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700228{
229}
230
Jan Karab85f4b82008-07-25 01:46:50 -0700231static inline void vfs_dq_drop(struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700232{
233}
234
Jan Karab85f4b82008-07-25 01:46:50 -0700235static inline int vfs_dq_alloc_inode(struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700236{
237 return 0;
238}
239
Jan Karab85f4b82008-07-25 01:46:50 -0700240static inline void vfs_dq_free_inode(struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700241{
242}
243
Jan Karab85f4b82008-07-25 01:46:50 -0700244static inline void vfs_dq_sync(struct super_block *sb)
Andrew Morton50f8c372008-04-28 02:14:35 -0700245{
246}
247
Jan Karab85f4b82008-07-25 01:46:50 -0700248static inline int vfs_dq_off(struct super_block *sb, int remount)
Andrew Morton50f8c372008-04-28 02:14:35 -0700249{
250 return 0;
251}
252
Jan Karab85f4b82008-07-25 01:46:50 -0700253static inline int vfs_dq_quota_on_remount(struct super_block *sb)
Andrew Morton50f8c372008-04-28 02:14:35 -0700254{
255 return 0;
256}
257
Jan Karab85f4b82008-07-25 01:46:50 -0700258static inline int vfs_dq_transfer(struct inode *inode, struct iattr *iattr)
Andrew Morton50f8c372008-04-28 02:14:35 -0700259{
260 return 0;
261}
262
Jan Karab85f4b82008-07-25 01:46:50 -0700263static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264{
265 inode_add_bytes(inode, nr);
266 return 0;
267}
268
Jan Karab85f4b82008-07-25 01:46:50 -0700269static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270{
Jan Karab85f4b82008-07-25 01:46:50 -0700271 vfs_dq_prealloc_space_nodirty(inode, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 mark_inode_dirty(inode);
273 return 0;
274}
275
Jan Karab85f4b82008-07-25 01:46:50 -0700276static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277{
278 inode_add_bytes(inode, nr);
279 return 0;
280}
281
Jan Karab85f4b82008-07-25 01:46:50 -0700282static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
Jan Karab85f4b82008-07-25 01:46:50 -0700284 vfs_dq_alloc_space_nodirty(inode, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 mark_inode_dirty(inode);
286 return 0;
287}
288
Jan Karab85f4b82008-07-25 01:46:50 -0700289static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290{
291 inode_sub_bytes(inode, nr);
292}
293
Jan Karab85f4b82008-07-25 01:46:50 -0700294static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
Jan Karab85f4b82008-07-25 01:46:50 -0700296 vfs_dq_free_space_nodirty(inode, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 mark_inode_dirty(inode);
298}
299
300#endif /* CONFIG_QUOTA */
301
Jan Karab85f4b82008-07-25 01:46:50 -0700302static inline int vfs_dq_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700303{
Jan Karab85f4b82008-07-25 01:46:50 -0700304 return vfs_dq_prealloc_space_nodirty(inode,
Jan Kara03f6e922008-04-28 02:14:32 -0700305 nr << inode->i_sb->s_blocksize_bits);
306}
307
Jan Karab85f4b82008-07-25 01:46:50 -0700308static inline int vfs_dq_prealloc_block(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700309{
Jan Karab85f4b82008-07-25 01:46:50 -0700310 return vfs_dq_prealloc_space(inode,
Jan Kara03f6e922008-04-28 02:14:32 -0700311 nr << inode->i_sb->s_blocksize_bits);
312}
313
Jan Karab85f4b82008-07-25 01:46:50 -0700314static inline int vfs_dq_alloc_block_nodirty(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700315{
Jan Karab85f4b82008-07-25 01:46:50 -0700316 return vfs_dq_alloc_space_nodirty(inode,
Jan Kara03f6e922008-04-28 02:14:32 -0700317 nr << inode->i_sb->s_blocksize_bits);
318}
319
Jan Karab85f4b82008-07-25 01:46:50 -0700320static inline int vfs_dq_alloc_block(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700321{
Jan Karab85f4b82008-07-25 01:46:50 -0700322 return vfs_dq_alloc_space(inode,
Jan Kara03f6e922008-04-28 02:14:32 -0700323 nr << inode->i_sb->s_blocksize_bits);
324}
325
Jan Karab85f4b82008-07-25 01:46:50 -0700326static inline void vfs_dq_free_block_nodirty(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700327{
Jan Karab85f4b82008-07-25 01:46:50 -0700328 vfs_dq_free_space_nodirty(inode, nr << inode->i_sb->s_blocksize_bits);
Jan Kara03f6e922008-04-28 02:14:32 -0700329}
330
Jan Karab85f4b82008-07-25 01:46:50 -0700331static inline void vfs_dq_free_block(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700332{
Jan Karab85f4b82008-07-25 01:46:50 -0700333 vfs_dq_free_space(inode, nr << inode->i_sb->s_blocksize_bits);
Jan Kara03f6e922008-04-28 02:14:32 -0700334}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
Jan Karab85f4b82008-07-25 01:46:50 -0700336/*
337 * Define uppercase equivalents for compatibility with old function names
338 * Can go away when we think all users have been converted (15/04/2008)
339 */
340#define DQUOT_INIT(inode) vfs_dq_init(inode)
341#define DQUOT_DROP(inode) vfs_dq_drop(inode)
342#define DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr) \
343 vfs_dq_prealloc_space_nodirty(inode, nr)
344#define DQUOT_PREALLOC_SPACE(inode, nr) vfs_dq_prealloc_space(inode, nr)
345#define DQUOT_ALLOC_SPACE_NODIRTY(inode, nr) \
346 vfs_dq_alloc_space_nodirty(inode, nr)
347#define DQUOT_ALLOC_SPACE(inode, nr) vfs_dq_alloc_space(inode, nr)
348#define DQUOT_PREALLOC_BLOCK_NODIRTY(inode, nr) \
349 vfs_dq_prealloc_block_nodirty(inode, nr)
350#define DQUOT_PREALLOC_BLOCK(inode, nr) vfs_dq_prealloc_block(inode, nr)
351#define DQUOT_ALLOC_BLOCK_NODIRTY(inode, nr) \
352 vfs_dq_alloc_block_nodirty(inode, nr)
353#define DQUOT_ALLOC_BLOCK(inode, nr) vfs_dq_alloc_block(inode, nr)
354#define DQUOT_ALLOC_INODE(inode) vfs_dq_alloc_inode(inode)
355#define DQUOT_FREE_SPACE_NODIRTY(inode, nr) \
356 vfs_dq_free_space_nodirty(inode, nr)
357#define DQUOT_FREE_SPACE(inode, nr) vfs_dq_free_space(inode, nr)
358#define DQUOT_FREE_BLOCK_NODIRTY(inode, nr) \
359 vfs_dq_free_block_nodirty(inode, nr)
360#define DQUOT_FREE_BLOCK(inode, nr) vfs_dq_free_block(inode, nr)
361#define DQUOT_FREE_INODE(inode) vfs_dq_free_inode(inode)
362#define DQUOT_TRANSFER(inode, iattr) vfs_dq_transfer(inode, iattr)
363#define DQUOT_SYNC(sb) vfs_dq_sync(sb)
364#define DQUOT_OFF(sb, remount) vfs_dq_off(sb, remount)
365#define DQUOT_ON_REMOUNT(sb) vfs_dq_quota_on_remount(sb)
366
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367#endif /* _LINUX_QUOTAOPS_ */