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 #if defined(CONFIG_QUOTA)
17
18 #include <linux/fs.h>
19
20 /*
21 * declaration of quota_function calls in kernel.
22 */
23 extern void sync_dquots_dev(kdev_t dev, int type);
24 extern void sync_dquots_sb(struct super_block *sb, int type);
25
26 extern void dquot_initialize(struct inode *inode, int type);
27 extern void dquot_drop(struct inode *inode);
28
29 extern int dquot_alloc_space(struct inode *inode, qsize_t number, int prealloc);
30 extern int dquot_alloc_inode(const struct inode *inode, unsigned long number);
31
32 extern void dquot_free_space(struct inode *inode, qsize_t number);
33 extern void dquot_free_inode(const struct inode *inode, unsigned long number);
34
35 extern int dquot_transfer(struct inode *inode, struct iattr *iattr);
36
37 /*
38 * Operations supported for diskquotas.
39 */
40 extern struct dquot_operations dquot_operations;
41 extern struct quotactl_ops vfs_quotactl_ops;
42
43 #define sb_dquot_ops (&dquot_operations)
44 #define sb_quotactl_ops (&vfs_quotactl_ops)
45
DQUOT_INIT(struct inode * inode)46 static __inline__ void DQUOT_INIT(struct inode *inode)
47 {
48 if (!inode->i_sb)
49 out_of_line_bug();
50 lock_kernel();
51 if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode))
52 inode->i_sb->dq_op->initialize(inode, -1);
53 unlock_kernel();
54 }
55
DQUOT_DROP(struct inode * inode)56 static __inline__ void DQUOT_DROP(struct inode *inode)
57 {
58 lock_kernel();
59 if (IS_QUOTAINIT(inode)) {
60 if (!inode->i_sb)
61 out_of_line_bug();
62 inode->i_sb->dq_op->drop(inode); /* Ops must be set when there's any quota... */
63 }
64 unlock_kernel();
65 }
66
DQUOT_PREALLOC_SPACE_NODIRTY(struct inode * inode,qsize_t nr)67 static __inline__ int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
68 {
69 lock_kernel();
70 if (sb_any_quota_enabled(inode->i_sb)) {
71 /* Used space is updated in alloc_space() */
72 if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA) {
73 unlock_kernel();
74 return 1;
75 }
76 }
77 else
78 inode_add_bytes(inode, nr);
79 unlock_kernel();
80 return 0;
81 }
82
DQUOT_PREALLOC_SPACE(struct inode * inode,qsize_t nr)83 static __inline__ int DQUOT_PREALLOC_SPACE(struct inode *inode, qsize_t nr)
84 {
85 int ret;
86 if (!(ret = DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr)))
87 mark_inode_dirty(inode);
88 return ret;
89 }
90
DQUOT_ALLOC_SPACE_NODIRTY(struct inode * inode,qsize_t nr)91 static __inline__ int DQUOT_ALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
92 {
93 lock_kernel();
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, 0) == NO_QUOTA) {
97 unlock_kernel();
98 return 1;
99 }
100 }
101 else
102 inode_add_bytes(inode, nr);
103 unlock_kernel();
104 return 0;
105 }
106
DQUOT_ALLOC_SPACE(struct inode * inode,qsize_t nr)107 static __inline__ int DQUOT_ALLOC_SPACE(struct inode *inode, qsize_t nr)
108 {
109 int ret;
110 if (!(ret = DQUOT_ALLOC_SPACE_NODIRTY(inode, nr)))
111 mark_inode_dirty(inode);
112 return ret;
113 }
114
DQUOT_ALLOC_INODE(struct inode * inode)115 static __inline__ int DQUOT_ALLOC_INODE(struct inode *inode)
116 {
117 lock_kernel();
118 if (sb_any_quota_enabled(inode->i_sb)) {
119 DQUOT_INIT(inode);
120 if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA) {
121 unlock_kernel();
122 return 1;
123 }
124 }
125 unlock_kernel();
126 return 0;
127 }
128
DQUOT_FREE_SPACE_NODIRTY(struct inode * inode,qsize_t nr)129 static __inline__ void DQUOT_FREE_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
130 {
131 lock_kernel();
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 unlock_kernel();
137 }
138
DQUOT_FREE_SPACE(struct inode * inode,qsize_t nr)139 static __inline__ void DQUOT_FREE_SPACE(struct inode *inode, qsize_t nr)
140 {
141 DQUOT_FREE_SPACE_NODIRTY(inode, nr);
142 mark_inode_dirty(inode);
143 }
144
DQUOT_FREE_INODE(struct inode * inode)145 static __inline__ void DQUOT_FREE_INODE(struct inode *inode)
146 {
147 lock_kernel();
148 if (sb_any_quota_enabled(inode->i_sb))
149 inode->i_sb->dq_op->free_inode(inode, 1);
150 unlock_kernel();
151 }
152
DQUOT_TRANSFER(struct inode * inode,struct iattr * iattr)153 static __inline__ int DQUOT_TRANSFER(struct inode *inode, struct iattr *iattr)
154 {
155 lock_kernel();
156 if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode)) {
157 DQUOT_INIT(inode);
158 if (inode->i_sb->dq_op->transfer(inode, iattr) == NO_QUOTA) {
159 unlock_kernel();
160 return 1;
161 }
162 }
163 unlock_kernel();
164 return 0;
165 }
166
167 #define DQUOT_SYNC_DEV(dev) sync_dquots_dev(dev, -1)
168 #define DQUOT_SYNC_SB(sb) sync_dquots_sb(sb, -1)
169
DQUOT_OFF(struct super_block * sb)170 static __inline__ int DQUOT_OFF(struct super_block *sb)
171 {
172 int ret = -ENOSYS;
173
174 lock_kernel();
175 if (sb->s_qcop && sb->s_qcop->quota_off)
176 ret = sb->s_qcop->quota_off(sb, -1);
177 unlock_kernel();
178 return ret;
179 }
180
181 #else
182
183 /*
184 * NO-OP when quota not configured.
185 */
186 #define sb_dquot_ops (NULL)
187 #define sb_quotactl_ops (NULL)
188 #define sync_dquots_dev(dev, type) do { } while(0)
189 #define DQUOT_INIT(inode) do { } while(0)
190 #define DQUOT_DROP(inode) do { } while(0)
191 #define DQUOT_ALLOC_INODE(inode) (0)
192 #define DQUOT_FREE_INODE(inode) do { } while(0)
193 #define DQUOT_SYNC_DEV(dev) do { } while(0)
194 #define DQUOT_SYNC_SB(sb) do { } while(0)
195 #define DQUOT_OFF(sb) do { } while(0)
196 #define DQUOT_TRANSFER(inode, iattr) (0)
DQUOT_PREALLOC_SPACE_NODIRTY(struct inode * inode,qsize_t nr)197 extern __inline__ int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
198 {
199 lock_kernel();
200 inode_add_bytes(inode, nr);
201 unlock_kernel();
202 return 0;
203 }
204
DQUOT_PREALLOC_SPACE(struct inode * inode,qsize_t nr)205 extern __inline__ int DQUOT_PREALLOC_SPACE(struct inode *inode, qsize_t nr)
206 {
207 DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr);
208 mark_inode_dirty(inode);
209 return 0;
210 }
211
DQUOT_ALLOC_SPACE_NODIRTY(struct inode * inode,qsize_t nr)212 extern __inline__ int DQUOT_ALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
213 {
214 lock_kernel();
215 inode_add_bytes(inode, nr);
216 unlock_kernel();
217 return 0;
218 }
219
DQUOT_ALLOC_SPACE(struct inode * inode,qsize_t nr)220 extern __inline__ int DQUOT_ALLOC_SPACE(struct inode *inode, qsize_t nr)
221 {
222 DQUOT_ALLOC_SPACE_NODIRTY(inode, nr);
223 mark_inode_dirty(inode);
224 return 0;
225 }
226
DQUOT_FREE_SPACE_NODIRTY(struct inode * inode,qsize_t nr)227 extern __inline__ void DQUOT_FREE_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
228 {
229 lock_kernel();
230 inode_sub_bytes(inode, nr);
231 unlock_kernel();
232 }
233
DQUOT_FREE_SPACE(struct inode * inode,qsize_t nr)234 extern __inline__ void DQUOT_FREE_SPACE(struct inode *inode, qsize_t nr)
235 {
236 DQUOT_FREE_SPACE_NODIRTY(inode, nr);
237 mark_inode_dirty(inode);
238 }
239
240 #endif /* CONFIG_QUOTA */
241
242 #define DQUOT_PREALLOC_BLOCK_NODIRTY(inode, nr) DQUOT_PREALLOC_SPACE_NODIRTY(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
243 #define DQUOT_PREALLOC_BLOCK(inode, nr) DQUOT_PREALLOC_SPACE(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
244 #define DQUOT_ALLOC_BLOCK_NODIRTY(inode, nr) DQUOT_ALLOC_SPACE_NODIRTY(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
245 #define DQUOT_ALLOC_BLOCK(inode, nr) DQUOT_ALLOC_SPACE(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
246 #define DQUOT_FREE_BLOCK_NODIRTY(inode, nr) DQUOT_FREE_SPACE_NODIRTY(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
247 #define DQUOT_FREE_BLOCK(inode, nr) DQUOT_FREE_SPACE(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
248
249 #endif /* _LINUX_QUOTAOPS_ */
250