blob: 38218c1334b175d4c53740952f77f993ea91756c [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
Jan Kara74abb982008-07-25 01:46:51 -070017#define sb_dqopt(sb) (&(sb)->s_dquot)
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#if defined(CONFIG_QUOTA)
20
21/*
22 * declaration of quota_function calls in kernel.
23 */
Jan Karab85f4b82008-07-25 01:46:50 -070024void sync_dquots(struct super_block *sb, int type);
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Jan Karab85f4b82008-07-25 01:46:50 -070026int dquot_initialize(struct inode *inode, int type);
27int dquot_drop(struct inode *inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Jan Karab85f4b82008-07-25 01:46:50 -070029int dquot_alloc_space(struct inode *inode, qsize_t number, int prealloc);
30int dquot_alloc_inode(const struct inode *inode, unsigned long number);
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Jan Karab85f4b82008-07-25 01:46:50 -070032int dquot_free_space(struct inode *inode, qsize_t number);
33int dquot_free_inode(const struct inode *inode, unsigned long number);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Jan Karab85f4b82008-07-25 01:46:50 -070035int dquot_transfer(struct inode *inode, struct iattr *iattr);
36int dquot_commit(struct dquot *dquot);
37int dquot_acquire(struct dquot *dquot);
38int dquot_release(struct dquot *dquot);
39int dquot_commit_info(struct super_block *sb, int type);
40int dquot_mark_dquot_dirty(struct dquot *dquot);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Jan Karab85f4b82008-07-25 01:46:50 -070042int vfs_quota_on(struct super_block *sb, int type, int format_id,
43 char *path, int remount);
44int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
45 int format_id, int type);
46int vfs_quota_off(struct super_block *sb, int type, int remount);
47int vfs_quota_sync(struct super_block *sb, int type);
48int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
49int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
50int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
51int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
52
53void vfs_dq_drop(struct inode *inode);
54int vfs_dq_transfer(struct inode *inode, struct iattr *iattr);
55int vfs_dq_quota_on_remount(struct super_block *sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Jan Kara74abb982008-07-25 01:46:51 -070057#define sb_dqinfo(sb, type) (sb_dqopt(sb)->info+(type))
58
59/*
60 * Functions for checking status of quota
61 */
62
63#define sb_has_quota_enabled(sb, type) ((type)==USRQUOTA ? \
64 (sb_dqopt(sb)->flags & DQUOT_USR_ENABLED) : (sb_dqopt(sb)->flags & DQUOT_GRP_ENABLED))
65
66#define sb_any_quota_enabled(sb) (sb_has_quota_enabled(sb, USRQUOTA) | \
67 sb_has_quota_enabled(sb, GRPQUOTA))
68
69#define sb_has_quota_suspended(sb, type) \
70 ((type) == USRQUOTA ? (sb_dqopt(sb)->flags & DQUOT_USR_SUSPENDED) : \
71 (sb_dqopt(sb)->flags & DQUOT_GRP_SUSPENDED))
72
73#define sb_any_quota_suspended(sb) (sb_has_quota_suspended(sb, USRQUOTA) | \
74 sb_has_quota_suspended(sb, GRPQUOTA))
75
Linus Torvalds1da177e2005-04-16 15:20:36 -070076/*
77 * Operations supported for diskquotas.
78 */
79extern struct dquot_operations dquot_operations;
80extern struct quotactl_ops vfs_quotactl_ops;
81
82#define sb_dquot_ops (&dquot_operations)
83#define sb_quotactl_ops (&vfs_quotactl_ops)
84
85/* It is better to call this function outside of any transaction as it might
86 * need a lot of space in journal for dquot structure allocation. */
Jan Karab85f4b82008-07-25 01:46:50 -070087static inline void vfs_dq_init(struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088{
89 BUG_ON(!inode->i_sb);
90 if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode))
91 inode->i_sb->dq_op->initialize(inode, -1);
92}
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094/* The following allocation/freeing/transfer functions *must* be called inside
95 * a transaction (deadlocks possible otherwise) */
Jan Karab85f4b82008-07-25 01:46:50 -070096static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
98 if (sb_any_quota_enabled(inode->i_sb)) {
99 /* Used space is updated in alloc_space() */
100 if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
101 return 1;
102 }
103 else
104 inode_add_bytes(inode, nr);
105 return 0;
106}
107
Jan Karab85f4b82008-07-25 01:46:50 -0700108static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109{
110 int ret;
Jan Karab85f4b82008-07-25 01:46:50 -0700111 if (!(ret = vfs_dq_prealloc_space_nodirty(inode, nr)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 mark_inode_dirty(inode);
113 return ret;
114}
115
Jan Karab85f4b82008-07-25 01:46:50 -0700116static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117{
118 if (sb_any_quota_enabled(inode->i_sb)) {
119 /* Used space is updated in alloc_space() */
120 if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
121 return 1;
122 }
123 else
124 inode_add_bytes(inode, nr);
125 return 0;
126}
127
Jan Karab85f4b82008-07-25 01:46:50 -0700128static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
130 int ret;
Jan Karab85f4b82008-07-25 01:46:50 -0700131 if (!(ret = vfs_dq_alloc_space_nodirty(inode, nr)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 mark_inode_dirty(inode);
133 return ret;
134}
135
Jan Karab85f4b82008-07-25 01:46:50 -0700136static inline int vfs_dq_alloc_inode(struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137{
138 if (sb_any_quota_enabled(inode->i_sb)) {
Jan Karab85f4b82008-07-25 01:46:50 -0700139 vfs_dq_init(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
141 return 1;
142 }
143 return 0;
144}
145
Jan Karab85f4b82008-07-25 01:46:50 -0700146static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147{
148 if (sb_any_quota_enabled(inode->i_sb))
149 inode->i_sb->dq_op->free_space(inode, nr);
150 else
151 inode_sub_bytes(inode, nr);
152}
153
Jan Karab85f4b82008-07-25 01:46:50 -0700154static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155{
Jan Karab85f4b82008-07-25 01:46:50 -0700156 vfs_dq_free_space_nodirty(inode, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 mark_inode_dirty(inode);
158}
159
Jan Karab85f4b82008-07-25 01:46:50 -0700160static inline void vfs_dq_free_inode(struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161{
162 if (sb_any_quota_enabled(inode->i_sb))
163 inode->i_sb->dq_op->free_inode(inode, 1);
164}
165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166/* The following two functions cannot be called inside a transaction */
Jan Karab85f4b82008-07-25 01:46:50 -0700167static inline void vfs_dq_sync(struct super_block *sb)
Jan Kara03f6e922008-04-28 02:14:32 -0700168{
169 sync_dquots(sb, -1);
170}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Jan Karab85f4b82008-07-25 01:46:50 -0700172static inline int vfs_dq_off(struct super_block *sb, int remount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
174 int ret = -ENOSYS;
175
Jan Kara0ff5af82008-04-28 02:14:33 -0700176 if (sb->s_qcop && sb->s_qcop->quota_off)
177 ret = sb->s_qcop->quota_off(sb, -1, remount);
178 return ret;
179}
180
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181#else
182
Jan Kara74abb982008-07-25 01:46:51 -0700183#define sb_has_quota_enabled(sb, type) 0
184#define sb_any_quota_enabled(sb) 0
185#define sb_has_quota_suspended(sb, type) 0
186#define sb_any_quota_suspended(sb) 0
187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188/*
189 * NO-OP when quota not configured.
190 */
191#define sb_dquot_ops (NULL)
192#define sb_quotactl_ops (NULL)
Andrew Morton50f8c372008-04-28 02:14:35 -0700193
Jan Karab85f4b82008-07-25 01:46:50 -0700194static inline void vfs_dq_init(struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700195{
196}
197
Jan Karab85f4b82008-07-25 01:46:50 -0700198static inline void vfs_dq_drop(struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700199{
200}
201
Jan Karab85f4b82008-07-25 01:46:50 -0700202static inline int vfs_dq_alloc_inode(struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700203{
204 return 0;
205}
206
Jan Karab85f4b82008-07-25 01:46:50 -0700207static inline void vfs_dq_free_inode(struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700208{
209}
210
Jan Karab85f4b82008-07-25 01:46:50 -0700211static inline void vfs_dq_sync(struct super_block *sb)
Andrew Morton50f8c372008-04-28 02:14:35 -0700212{
213}
214
Jan Karab85f4b82008-07-25 01:46:50 -0700215static inline int vfs_dq_off(struct super_block *sb, int remount)
Andrew Morton50f8c372008-04-28 02:14:35 -0700216{
217 return 0;
218}
219
Jan Karab85f4b82008-07-25 01:46:50 -0700220static inline int vfs_dq_quota_on_remount(struct super_block *sb)
Andrew Morton50f8c372008-04-28 02:14:35 -0700221{
222 return 0;
223}
224
Jan Karab85f4b82008-07-25 01:46:50 -0700225static inline int vfs_dq_transfer(struct inode *inode, struct iattr *iattr)
Andrew Morton50f8c372008-04-28 02:14:35 -0700226{
227 return 0;
228}
229
Jan Karab85f4b82008-07-25 01:46:50 -0700230static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
232 inode_add_bytes(inode, nr);
233 return 0;
234}
235
Jan Karab85f4b82008-07-25 01:46:50 -0700236static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237{
Jan Karab85f4b82008-07-25 01:46:50 -0700238 vfs_dq_prealloc_space_nodirty(inode, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 mark_inode_dirty(inode);
240 return 0;
241}
242
Jan Karab85f4b82008-07-25 01:46:50 -0700243static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
245 inode_add_bytes(inode, nr);
246 return 0;
247}
248
Jan Karab85f4b82008-07-25 01:46:50 -0700249static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250{
Jan Karab85f4b82008-07-25 01:46:50 -0700251 vfs_dq_alloc_space_nodirty(inode, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 mark_inode_dirty(inode);
253 return 0;
254}
255
Jan Karab85f4b82008-07-25 01:46:50 -0700256static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257{
258 inode_sub_bytes(inode, nr);
259}
260
Jan Karab85f4b82008-07-25 01:46:50 -0700261static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262{
Jan Karab85f4b82008-07-25 01:46:50 -0700263 vfs_dq_free_space_nodirty(inode, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 mark_inode_dirty(inode);
265}
266
267#endif /* CONFIG_QUOTA */
268
Jan Karab85f4b82008-07-25 01:46:50 -0700269static inline int vfs_dq_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700270{
Jan Karab85f4b82008-07-25 01:46:50 -0700271 return vfs_dq_prealloc_space_nodirty(inode,
Jan Kara03f6e922008-04-28 02:14:32 -0700272 nr << inode->i_sb->s_blocksize_bits);
273}
274
Jan Karab85f4b82008-07-25 01:46:50 -0700275static inline int vfs_dq_prealloc_block(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700276{
Jan Karab85f4b82008-07-25 01:46:50 -0700277 return vfs_dq_prealloc_space(inode,
Jan Kara03f6e922008-04-28 02:14:32 -0700278 nr << inode->i_sb->s_blocksize_bits);
279}
280
Jan Karab85f4b82008-07-25 01:46:50 -0700281static inline int vfs_dq_alloc_block_nodirty(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700282{
Jan Karab85f4b82008-07-25 01:46:50 -0700283 return vfs_dq_alloc_space_nodirty(inode,
Jan Kara03f6e922008-04-28 02:14:32 -0700284 nr << inode->i_sb->s_blocksize_bits);
285}
286
Jan Karab85f4b82008-07-25 01:46:50 -0700287static inline int vfs_dq_alloc_block(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700288{
Jan Karab85f4b82008-07-25 01:46:50 -0700289 return vfs_dq_alloc_space(inode,
Jan Kara03f6e922008-04-28 02:14:32 -0700290 nr << inode->i_sb->s_blocksize_bits);
291}
292
Jan Karab85f4b82008-07-25 01:46:50 -0700293static inline void vfs_dq_free_block_nodirty(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700294{
Jan Karab85f4b82008-07-25 01:46:50 -0700295 vfs_dq_free_space_nodirty(inode, nr << inode->i_sb->s_blocksize_bits);
Jan Kara03f6e922008-04-28 02:14:32 -0700296}
297
Jan Karab85f4b82008-07-25 01:46:50 -0700298static inline void vfs_dq_free_block(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700299{
Jan Karab85f4b82008-07-25 01:46:50 -0700300 vfs_dq_free_space(inode, nr << inode->i_sb->s_blocksize_bits);
Jan Kara03f6e922008-04-28 02:14:32 -0700301}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
Jan Karab85f4b82008-07-25 01:46:50 -0700303/*
304 * Define uppercase equivalents for compatibility with old function names
305 * Can go away when we think all users have been converted (15/04/2008)
306 */
307#define DQUOT_INIT(inode) vfs_dq_init(inode)
308#define DQUOT_DROP(inode) vfs_dq_drop(inode)
309#define DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr) \
310 vfs_dq_prealloc_space_nodirty(inode, nr)
311#define DQUOT_PREALLOC_SPACE(inode, nr) vfs_dq_prealloc_space(inode, nr)
312#define DQUOT_ALLOC_SPACE_NODIRTY(inode, nr) \
313 vfs_dq_alloc_space_nodirty(inode, nr)
314#define DQUOT_ALLOC_SPACE(inode, nr) vfs_dq_alloc_space(inode, nr)
315#define DQUOT_PREALLOC_BLOCK_NODIRTY(inode, nr) \
316 vfs_dq_prealloc_block_nodirty(inode, nr)
317#define DQUOT_PREALLOC_BLOCK(inode, nr) vfs_dq_prealloc_block(inode, nr)
318#define DQUOT_ALLOC_BLOCK_NODIRTY(inode, nr) \
319 vfs_dq_alloc_block_nodirty(inode, nr)
320#define DQUOT_ALLOC_BLOCK(inode, nr) vfs_dq_alloc_block(inode, nr)
321#define DQUOT_ALLOC_INODE(inode) vfs_dq_alloc_inode(inode)
322#define DQUOT_FREE_SPACE_NODIRTY(inode, nr) \
323 vfs_dq_free_space_nodirty(inode, nr)
324#define DQUOT_FREE_SPACE(inode, nr) vfs_dq_free_space(inode, nr)
325#define DQUOT_FREE_BLOCK_NODIRTY(inode, nr) \
326 vfs_dq_free_block_nodirty(inode, nr)
327#define DQUOT_FREE_BLOCK(inode, nr) vfs_dq_free_block(inode, nr)
328#define DQUOT_FREE_INODE(inode) vfs_dq_free_inode(inode)
329#define DQUOT_TRANSFER(inode, iattr) vfs_dq_transfer(inode, iattr)
330#define DQUOT_SYNC(sb) vfs_dq_sync(sb)
331#define DQUOT_OFF(sb, remount) vfs_dq_off(sb, remount)
332#define DQUOT_ON_REMOUNT(sb) vfs_dq_quota_on_remount(sb)
333
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334#endif /* _LINUX_QUOTAOPS_ */