blob: 90c23f690c0deab4fedeb6f5126dfbb4838cb54d [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
Adrian Bunk0da14802006-12-06 20:40:03 -080040int remove_inode_dquot_ref(struct inode *inode, int type,
41 struct list_head *tofree_head);
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043extern int vfs_quota_on(struct super_block *sb, int type, int format_id, char *path);
Christoph Hellwig84de8562005-06-23 00:09:16 -070044extern int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
45 int format_id, int type);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046extern int vfs_quota_off(struct super_block *sb, int type);
47#define vfs_quota_off_mount(sb, type) vfs_quota_off(sb, type)
48extern int vfs_quota_sync(struct super_block *sb, int type);
49extern int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
50extern int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
51extern int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
52extern int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
53
54/*
55 * Operations supported for diskquotas.
56 */
57extern struct dquot_operations dquot_operations;
58extern struct quotactl_ops vfs_quotactl_ops;
59
60#define sb_dquot_ops (&dquot_operations)
61#define sb_quotactl_ops (&vfs_quotactl_ops)
62
63/* It is better to call this function outside of any transaction as it might
64 * need a lot of space in journal for dquot structure allocation. */
65static __inline__ void DQUOT_INIT(struct inode *inode)
66{
67 BUG_ON(!inode->i_sb);
68 if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode))
69 inode->i_sb->dq_op->initialize(inode, -1);
70}
71
72/* The same as with DQUOT_INIT */
73static __inline__ void DQUOT_DROP(struct inode *inode)
74{
75 /* Here we can get arbitrary inode from clear_inode() so we have
76 * to be careful. OTOH we don't need locking as quota operations
77 * are allowed to change only at mount time */
78 if (!IS_NOQUOTA(inode) && inode->i_sb && inode->i_sb->dq_op
79 && inode->i_sb->dq_op->drop) {
80 int cnt;
81 /* Test before calling to rule out calls from proc and such
82 * where we are not allowed to block. Note that this is
83 * actually reliable test even without the lock - the caller
84 * must assure that nobody can come after the DQUOT_DROP and
85 * add quota pointers back anyway */
86 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
87 if (inode->i_dquot[cnt] != NODQUOT)
88 break;
89 if (cnt < MAXQUOTAS)
90 inode->i_sb->dq_op->drop(inode);
91 }
92}
93
94/* The following allocation/freeing/transfer functions *must* be called inside
95 * a transaction (deadlocks possible otherwise) */
96static __inline__ int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
97{
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
108static __inline__ int DQUOT_PREALLOC_SPACE(struct inode *inode, qsize_t nr)
109{
110 int ret;
111 if (!(ret = DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr)))
112 mark_inode_dirty(inode);
113 return ret;
114}
115
116static __inline__ int DQUOT_ALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
117{
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
128static __inline__ int DQUOT_ALLOC_SPACE(struct inode *inode, qsize_t nr)
129{
130 int ret;
131 if (!(ret = DQUOT_ALLOC_SPACE_NODIRTY(inode, nr)))
132 mark_inode_dirty(inode);
133 return ret;
134}
135
136static __inline__ int DQUOT_ALLOC_INODE(struct inode *inode)
137{
138 if (sb_any_quota_enabled(inode->i_sb)) {
139 DQUOT_INIT(inode);
140 if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
141 return 1;
142 }
143 return 0;
144}
145
146static __inline__ void DQUOT_FREE_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
147{
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
154static __inline__ void DQUOT_FREE_SPACE(struct inode *inode, qsize_t nr)
155{
156 DQUOT_FREE_SPACE_NODIRTY(inode, nr);
157 mark_inode_dirty(inode);
158}
159
160static __inline__ void DQUOT_FREE_INODE(struct inode *inode)
161{
162 if (sb_any_quota_enabled(inode->i_sb))
163 inode->i_sb->dq_op->free_inode(inode, 1);
164}
165
166static __inline__ int DQUOT_TRANSFER(struct inode *inode, struct iattr *iattr)
167{
168 if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode)) {
169 DQUOT_INIT(inode);
170 if (inode->i_sb->dq_op->transfer(inode, iattr) == NO_QUOTA)
171 return 1;
172 }
173 return 0;
174}
175
176/* The following two functions cannot be called inside a transaction */
177#define DQUOT_SYNC(sb) sync_dquots(sb, -1)
178
179static __inline__ int DQUOT_OFF(struct super_block *sb)
180{
181 int ret = -ENOSYS;
182
183 if (sb_any_quota_enabled(sb) && sb->s_qcop && sb->s_qcop->quota_off)
184 ret = sb->s_qcop->quota_off(sb, -1);
185 return ret;
186}
187
188#else
189
190/*
191 * NO-OP when quota not configured.
192 */
193#define sb_dquot_ops (NULL)
194#define sb_quotactl_ops (NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195#define DQUOT_INIT(inode) do { } while(0)
196#define DQUOT_DROP(inode) do { } while(0)
197#define DQUOT_ALLOC_INODE(inode) (0)
198#define DQUOT_FREE_INODE(inode) do { } while(0)
199#define DQUOT_SYNC(sb) do { } while(0)
200#define DQUOT_OFF(sb) do { } while(0)
201#define DQUOT_TRANSFER(inode, iattr) (0)
Adrian Bunkbe586ba2005-11-07 00:59:35 -0800202static inline int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203{
204 inode_add_bytes(inode, nr);
205 return 0;
206}
207
Adrian Bunkbe586ba2005-11-07 00:59:35 -0800208static inline int DQUOT_PREALLOC_SPACE(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
210 DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr);
211 mark_inode_dirty(inode);
212 return 0;
213}
214
Adrian Bunkbe586ba2005-11-07 00:59:35 -0800215static inline int DQUOT_ALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216{
217 inode_add_bytes(inode, nr);
218 return 0;
219}
220
Adrian Bunkbe586ba2005-11-07 00:59:35 -0800221static inline int DQUOT_ALLOC_SPACE(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222{
223 DQUOT_ALLOC_SPACE_NODIRTY(inode, nr);
224 mark_inode_dirty(inode);
225 return 0;
226}
227
Adrian Bunkbe586ba2005-11-07 00:59:35 -0800228static inline void DQUOT_FREE_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229{
230 inode_sub_bytes(inode, nr);
231}
232
Adrian Bunkbe586ba2005-11-07 00:59:35 -0800233static inline void DQUOT_FREE_SPACE(struct inode *inode, qsize_t nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234{
235 DQUOT_FREE_SPACE_NODIRTY(inode, nr);
236 mark_inode_dirty(inode);
237}
238
239#endif /* CONFIG_QUOTA */
240
241#define DQUOT_PREALLOC_BLOCK_NODIRTY(inode, nr) DQUOT_PREALLOC_SPACE_NODIRTY(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
242#define DQUOT_PREALLOC_BLOCK(inode, nr) DQUOT_PREALLOC_SPACE(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
243#define DQUOT_ALLOC_BLOCK_NODIRTY(inode, nr) DQUOT_ALLOC_SPACE_NODIRTY(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
244#define DQUOT_ALLOC_BLOCK(inode, nr) DQUOT_ALLOC_SPACE(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
245#define DQUOT_FREE_BLOCK_NODIRTY(inode, nr) DQUOT_FREE_SPACE_NODIRTY(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
246#define DQUOT_FREE_BLOCK(inode, nr) DQUOT_FREE_SPACE(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
247
248#endif /* _LINUX_QUOTAOPS_ */