ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / linux / quotaops.h
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
13 #include <linux/config.h>
14 #include <linux/smp_lock.h>
15
16 #include <linux/fs.h>
17
18 #if defined(CONFIG_QUOTA)
19
20 /*
21  * declaration of quota_function calls in kernel.
22  */
23 extern void sync_dquots(struct super_block *sb, int type);
24
25 extern int dquot_initialize(struct inode *inode, int type);
26 extern int dquot_drop(struct inode *inode);
27
28 extern int dquot_alloc_space(struct inode *inode, qsize_t number, int prealloc);
29 extern int dquot_alloc_inode(const struct inode *inode, unsigned long number);
30
31 extern int dquot_free_space(struct inode *inode, qsize_t number);
32 extern int dquot_free_inode(const struct inode *inode, unsigned long number);
33
34 extern int dquot_transfer(struct inode *inode, struct iattr *iattr);
35 extern int dquot_commit(struct dquot *dquot);
36 extern int dquot_acquire(struct dquot *dquot);
37 extern int dquot_release(struct dquot *dquot);
38 extern int dquot_commit_info(struct super_block *sb, int type);
39 extern int dquot_mark_dquot_dirty(struct dquot *dquot);
40
41 extern int vfs_quota_on(struct super_block *sb, int type, int format_id, char *path);
42 extern int vfs_quota_on_mount(int type, int format_id, struct dentry *dentry);
43 extern int vfs_quota_off(struct super_block *sb, int type);
44 #define vfs_quota_off_mount(sb, type) vfs_quota_off(sb, type)
45 extern int vfs_quota_sync(struct super_block *sb, int type);
46 extern int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
47 extern int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
48 extern int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
49 extern 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  */
54 extern struct dquot_operations dquot_operations;
55 extern 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. */
62 static __inline__ void DQUOT_INIT(struct inode *inode)
63 {
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 */
70 static __inline__ void DQUOT_DROP(struct inode *inode)
71 {
72         if (IS_QUOTAINIT(inode)) {
73                 BUG_ON(!inode->i_sb);
74                 inode->i_sb->dq_op->drop(inode);        /* Ops must be set when there's any quota... */
75         }
76 }
77
78 /* The following allocation/freeing/transfer functions *must* be called inside
79  * a transaction (deadlocks possible otherwise) */
80 static __inline__ int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
81 {
82         if (sb_any_quota_enabled(inode->i_sb)) {
83                 /* Used space is updated in alloc_space() */
84                 if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
85                         return 1;
86         }
87         else
88                 inode_add_bytes(inode, nr);
89         return 0;
90 }
91
92 static __inline__ int DQUOT_PREALLOC_SPACE(struct inode *inode, qsize_t nr)
93 {
94         int ret;
95         if (!(ret =  DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr)))
96                 mark_inode_dirty(inode);
97         return ret;
98 }
99
100 static __inline__ int DQUOT_ALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
101 {
102         if (sb_any_quota_enabled(inode->i_sb)) {
103                 /* Used space is updated in alloc_space() */
104                 if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
105                         return 1;
106         }
107         else
108                 inode_add_bytes(inode, nr);
109         return 0;
110 }
111
112 static __inline__ int DQUOT_ALLOC_SPACE(struct inode *inode, qsize_t nr)
113 {
114         int ret;
115         if (!(ret = DQUOT_ALLOC_SPACE_NODIRTY(inode, nr)))
116                 mark_inode_dirty(inode);
117         return ret;
118 }
119
120 static __inline__ int DQUOT_ALLOC_INODE(struct inode *inode)
121 {
122         if (sb_any_quota_enabled(inode->i_sb)) {
123                 DQUOT_INIT(inode);
124                 if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
125                         return 1;
126         }
127         return 0;
128 }
129
130 static __inline__ void DQUOT_FREE_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
131 {
132         if (sb_any_quota_enabled(inode->i_sb))
133                 inode->i_sb->dq_op->free_space(inode, nr);
134         else
135                 inode_sub_bytes(inode, nr);
136 }
137
138 static __inline__ void DQUOT_FREE_SPACE(struct inode *inode, qsize_t nr)
139 {
140         DQUOT_FREE_SPACE_NODIRTY(inode, nr);
141         mark_inode_dirty(inode);
142 }
143
144 static __inline__ void DQUOT_FREE_INODE(struct inode *inode)
145 {
146         if (sb_any_quota_enabled(inode->i_sb))
147                 inode->i_sb->dq_op->free_inode(inode, 1);
148 }
149
150 static __inline__ int DQUOT_TRANSFER(struct inode *inode, struct iattr *iattr)
151 {
152         if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode)) {
153                 DQUOT_INIT(inode);
154                 if (inode->i_sb->dq_op->transfer(inode, iattr) == NO_QUOTA)
155                         return 1;
156         }
157         return 0;
158 }
159
160 /* The following two functions cannot be called inside a transaction */
161 #define DQUOT_SYNC(sb)  sync_dquots(sb, -1)
162
163 static __inline__ int DQUOT_OFF(struct super_block *sb)
164 {
165         int ret = -ENOSYS;
166
167         if (sb->s_qcop && sb->s_qcop->quota_off)
168                 ret = sb->s_qcop->quota_off(sb, -1);
169         return ret;
170 }
171
172 #else
173
174 /*
175  * NO-OP when quota not configured.
176  */
177 #define sb_dquot_ops                            (NULL)
178 #define sb_quotactl_ops                         (NULL)
179 #define sync_dquots_dev(dev,type)               (NULL)
180 #define DQUOT_INIT(inode)                       do { } while(0)
181 #define DQUOT_DROP(inode)                       do { } while(0)
182 #define DQUOT_ALLOC_INODE(inode)                (0)
183 #define DQUOT_FREE_INODE(inode)                 do { } while(0)
184 #define DQUOT_SYNC(sb)                          do { } while(0)
185 #define DQUOT_OFF(sb)                           do { } while(0)
186 #define DQUOT_TRANSFER(inode, iattr)            (0)
187 extern __inline__ int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
188 {
189         inode_add_bytes(inode, nr);
190         return 0;
191 }
192
193 extern __inline__ int DQUOT_PREALLOC_SPACE(struct inode *inode, qsize_t nr)
194 {
195         DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr);
196         mark_inode_dirty(inode);
197         return 0;
198 }
199
200 extern __inline__ int DQUOT_ALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
201 {
202         inode_add_bytes(inode, nr);
203         return 0;
204 }
205
206 extern __inline__ int DQUOT_ALLOC_SPACE(struct inode *inode, qsize_t nr)
207 {
208         DQUOT_ALLOC_SPACE_NODIRTY(inode, nr);
209         mark_inode_dirty(inode);
210         return 0;
211 }
212
213 extern __inline__ void DQUOT_FREE_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
214 {
215         inode_sub_bytes(inode, nr);
216 }
217
218 extern __inline__ void DQUOT_FREE_SPACE(struct inode *inode, qsize_t nr)
219 {
220         DQUOT_FREE_SPACE_NODIRTY(inode, nr);
221         mark_inode_dirty(inode);
222 }       
223
224 #endif /* CONFIG_QUOTA */
225
226 #define DQUOT_PREALLOC_BLOCK_NODIRTY(inode, nr) DQUOT_PREALLOC_SPACE_NODIRTY(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
227 #define DQUOT_PREALLOC_BLOCK(inode, nr) DQUOT_PREALLOC_SPACE(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
228 #define DQUOT_ALLOC_BLOCK_NODIRTY(inode, nr) DQUOT_ALLOC_SPACE_NODIRTY(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
229 #define DQUOT_ALLOC_BLOCK(inode, nr) DQUOT_ALLOC_SPACE(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
230 #define DQUOT_FREE_BLOCK_NODIRTY(inode, nr) DQUOT_FREE_SPACE_NODIRTY(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
231 #define DQUOT_FREE_BLOCK(inode, nr) DQUOT_FREE_SPACE(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
232
233 #endif /* _LINUX_QUOTAOPS_ */