aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/quotaops.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/quotaops.h')
-rw-r--r--include/linux/quotaops.h283
1 files changed, 166 insertions, 117 deletions
diff --git a/include/linux/quotaops.h b/include/linux/quotaops.h
index f86702053853..ca6b9b5c8d52 100644
--- a/include/linux/quotaops.h
+++ b/include/linux/quotaops.h
@@ -11,42 +11,87 @@
11#define _LINUX_QUOTAOPS_ 11#define _LINUX_QUOTAOPS_
12 12
13#include <linux/smp_lock.h> 13#include <linux/smp_lock.h>
14
15#include <linux/fs.h> 14#include <linux/fs.h>
16 15
16static inline struct quota_info *sb_dqopt(struct super_block *sb)
17{
18 return &sb->s_dquot;
19}
20
17#if defined(CONFIG_QUOTA) 21#if defined(CONFIG_QUOTA)
18 22
19/* 23/*
20 * declaration of quota_function calls in kernel. 24 * declaration of quota_function calls in kernel.
21 */ 25 */
22extern void sync_dquots(struct super_block *sb, int type); 26void sync_dquots(struct super_block *sb, int type);
23 27
24extern int dquot_initialize(struct inode *inode, int type); 28int dquot_initialize(struct inode *inode, int type);
25extern int dquot_drop(struct inode *inode); 29int dquot_drop(struct inode *inode);
26 30
27extern int dquot_alloc_space(struct inode *inode, qsize_t number, int prealloc); 31int dquot_alloc_space(struct inode *inode, qsize_t number, int prealloc);
28extern int dquot_alloc_inode(const struct inode *inode, unsigned long number); 32int dquot_alloc_inode(const struct inode *inode, unsigned long number);
29 33
30extern int dquot_free_space(struct inode *inode, qsize_t number); 34int dquot_free_space(struct inode *inode, qsize_t number);
31extern int dquot_free_inode(const struct inode *inode, unsigned long number); 35int dquot_free_inode(const struct inode *inode, unsigned long number);
32 36
33extern int dquot_transfer(struct inode *inode, struct iattr *iattr); 37int dquot_transfer(struct inode *inode, struct iattr *iattr);
34extern int dquot_commit(struct dquot *dquot); 38int dquot_commit(struct dquot *dquot);
35extern int dquot_acquire(struct dquot *dquot); 39int dquot_acquire(struct dquot *dquot);
36extern int dquot_release(struct dquot *dquot); 40int dquot_release(struct dquot *dquot);
37extern int dquot_commit_info(struct super_block *sb, int type); 41int dquot_commit_info(struct super_block *sb, int type);
38extern int dquot_mark_dquot_dirty(struct dquot *dquot); 42int dquot_mark_dquot_dirty(struct dquot *dquot);
39 43
40extern int vfs_quota_on(struct super_block *sb, int type, int format_id, 44int vfs_quota_on(struct super_block *sb, int type, int format_id,
41 char *path, int remount); 45 char *path, int remount);
42extern int vfs_quota_on_mount(struct super_block *sb, char *qf_name, 46int vfs_quota_on_path(struct super_block *sb, int type, int format_id,
43 int format_id, int type); 47 struct path *path);
44extern int vfs_quota_off(struct super_block *sb, int type, int remount); 48int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
45extern int vfs_quota_sync(struct super_block *sb, int type); 49 int format_id, int type);
46extern int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii); 50int vfs_quota_off(struct super_block *sb, int type, int remount);
47extern int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii); 51int vfs_quota_sync(struct super_block *sb, int type);
48extern int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di); 52int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
49extern int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di); 53int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
54int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
55int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
56
57void vfs_dq_drop(struct inode *inode);
58int vfs_dq_transfer(struct inode *inode, struct iattr *iattr);
59int vfs_dq_quota_on_remount(struct super_block *sb);
60
61static inline struct mem_dqinfo *sb_dqinfo(struct super_block *sb, int type)
62{
63 return sb_dqopt(sb)->info + type;
64}
65
66/*
67 * Functions for checking status of quota
68 */
69
70static inline int sb_has_quota_enabled(struct super_block *sb, int type)
71{
72 if (type == USRQUOTA)
73 return sb_dqopt(sb)->flags & DQUOT_USR_ENABLED;
74 return sb_dqopt(sb)->flags & DQUOT_GRP_ENABLED;
75}
76
77static inline int sb_any_quota_enabled(struct super_block *sb)
78{
79 return sb_has_quota_enabled(sb, USRQUOTA) ||
80 sb_has_quota_enabled(sb, GRPQUOTA);
81}
82
83static inline int sb_has_quota_suspended(struct super_block *sb, int type)
84{
85 if (type == USRQUOTA)
86 return sb_dqopt(sb)->flags & DQUOT_USR_SUSPENDED;
87 return sb_dqopt(sb)->flags & DQUOT_GRP_SUSPENDED;
88}
89
90static inline int sb_any_quota_suspended(struct super_block *sb)
91{
92 return sb_has_quota_suspended(sb, USRQUOTA) ||
93 sb_has_quota_suspended(sb, GRPQUOTA);
94}
50 95
51/* 96/*
52 * Operations supported for diskquotas. 97 * Operations supported for diskquotas.
@@ -59,38 +104,16 @@ extern struct quotactl_ops vfs_quotactl_ops;
59 104
60/* It is better to call this function outside of any transaction as it might 105/* 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. */ 106 * need a lot of space in journal for dquot structure allocation. */
62static inline void DQUOT_INIT(struct inode *inode) 107static inline void vfs_dq_init(struct inode *inode)
63{ 108{
64 BUG_ON(!inode->i_sb); 109 BUG_ON(!inode->i_sb);
65 if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode)) 110 if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode))
66 inode->i_sb->dq_op->initialize(inode, -1); 111 inode->i_sb->dq_op->initialize(inode, -1);
67} 112}
68 113
69/* The same as with DQUOT_INIT */
70static inline void DQUOT_DROP(struct inode *inode)
71{
72 /* Here we can get arbitrary inode from clear_inode() so we have
73 * to be careful. OTOH we don't need locking as quota operations
74 * are allowed to change only at mount time */
75 if (!IS_NOQUOTA(inode) && inode->i_sb && inode->i_sb->dq_op
76 && inode->i_sb->dq_op->drop) {
77 int cnt;
78 /* Test before calling to rule out calls from proc and such
79 * where we are not allowed to block. Note that this is
80 * actually reliable test even without the lock - the caller
81 * must assure that nobody can come after the DQUOT_DROP and
82 * add quota pointers back anyway */
83 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
84 if (inode->i_dquot[cnt] != NODQUOT)
85 break;
86 if (cnt < MAXQUOTAS)
87 inode->i_sb->dq_op->drop(inode);
88 }
89}
90
91/* The following allocation/freeing/transfer functions *must* be called inside 114/* The following allocation/freeing/transfer functions *must* be called inside
92 * a transaction (deadlocks possible otherwise) */ 115 * a transaction (deadlocks possible otherwise) */
93static inline int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr) 116static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
94{ 117{
95 if (sb_any_quota_enabled(inode->i_sb)) { 118 if (sb_any_quota_enabled(inode->i_sb)) {
96 /* Used space is updated in alloc_space() */ 119 /* Used space is updated in alloc_space() */
@@ -102,15 +125,15 @@ static inline int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
102 return 0; 125 return 0;
103} 126}
104 127
105static inline int DQUOT_PREALLOC_SPACE(struct inode *inode, qsize_t nr) 128static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
106{ 129{
107 int ret; 130 int ret;
108 if (!(ret = DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr))) 131 if (!(ret = vfs_dq_prealloc_space_nodirty(inode, nr)))
109 mark_inode_dirty(inode); 132 mark_inode_dirty(inode);
110 return ret; 133 return ret;
111} 134}
112 135
113static inline int DQUOT_ALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr) 136static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
114{ 137{
115 if (sb_any_quota_enabled(inode->i_sb)) { 138 if (sb_any_quota_enabled(inode->i_sb)) {
116 /* Used space is updated in alloc_space() */ 139 /* Used space is updated in alloc_space() */
@@ -122,25 +145,25 @@ static inline int DQUOT_ALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
122 return 0; 145 return 0;
123} 146}
124 147
125static inline int DQUOT_ALLOC_SPACE(struct inode *inode, qsize_t nr) 148static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
126{ 149{
127 int ret; 150 int ret;
128 if (!(ret = DQUOT_ALLOC_SPACE_NODIRTY(inode, nr))) 151 if (!(ret = vfs_dq_alloc_space_nodirty(inode, nr)))
129 mark_inode_dirty(inode); 152 mark_inode_dirty(inode);
130 return ret; 153 return ret;
131} 154}
132 155
133static inline int DQUOT_ALLOC_INODE(struct inode *inode) 156static inline int vfs_dq_alloc_inode(struct inode *inode)
134{ 157{
135 if (sb_any_quota_enabled(inode->i_sb)) { 158 if (sb_any_quota_enabled(inode->i_sb)) {
136 DQUOT_INIT(inode); 159 vfs_dq_init(inode);
137 if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA) 160 if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
138 return 1; 161 return 1;
139 } 162 }
140 return 0; 163 return 0;
141} 164}
142 165
143static inline void DQUOT_FREE_SPACE_NODIRTY(struct inode *inode, qsize_t nr) 166static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
144{ 167{
145 if (sb_any_quota_enabled(inode->i_sb)) 168 if (sb_any_quota_enabled(inode->i_sb))
146 inode->i_sb->dq_op->free_space(inode, nr); 169 inode->i_sb->dq_op->free_space(inode, nr);
@@ -148,35 +171,25 @@ static inline void DQUOT_FREE_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
148 inode_sub_bytes(inode, nr); 171 inode_sub_bytes(inode, nr);
149} 172}
150 173
151static inline void DQUOT_FREE_SPACE(struct inode *inode, qsize_t nr) 174static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
152{ 175{
153 DQUOT_FREE_SPACE_NODIRTY(inode, nr); 176 vfs_dq_free_space_nodirty(inode, nr);
154 mark_inode_dirty(inode); 177 mark_inode_dirty(inode);
155} 178}
156 179
157static inline void DQUOT_FREE_INODE(struct inode *inode) 180static inline void vfs_dq_free_inode(struct inode *inode)
158{ 181{
159 if (sb_any_quota_enabled(inode->i_sb)) 182 if (sb_any_quota_enabled(inode->i_sb))
160 inode->i_sb->dq_op->free_inode(inode, 1); 183 inode->i_sb->dq_op->free_inode(inode, 1);
161} 184}
162 185
163static inline int DQUOT_TRANSFER(struct inode *inode, struct iattr *iattr)
164{
165 if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode)) {
166 DQUOT_INIT(inode);
167 if (inode->i_sb->dq_op->transfer(inode, iattr) == NO_QUOTA)
168 return 1;
169 }
170 return 0;
171}
172
173/* The following two functions cannot be called inside a transaction */ 186/* The following two functions cannot be called inside a transaction */
174static inline void DQUOT_SYNC(struct super_block *sb) 187static inline void vfs_dq_sync(struct super_block *sb)
175{ 188{
176 sync_dquots(sb, -1); 189 sync_dquots(sb, -1);
177} 190}
178 191
179static inline int DQUOT_OFF(struct super_block *sb, int remount) 192static inline int vfs_dq_off(struct super_block *sb, int remount)
180{ 193{
181 int ret = -ENOSYS; 194 int ret = -ENOSYS;
182 195
@@ -185,22 +198,27 @@ static inline int DQUOT_OFF(struct super_block *sb, int remount)
185 return ret; 198 return ret;
186} 199}
187 200
188static inline int DQUOT_ON_REMOUNT(struct super_block *sb) 201#else
202
203static inline int sb_has_quota_enabled(struct super_block *sb, int type)
189{ 204{
190 int cnt; 205 return 0;
191 int ret = 0, err; 206}
192 207
193 if (!sb->s_qcop || !sb->s_qcop->quota_on) 208static inline int sb_any_quota_enabled(struct super_block *sb)
194 return -ENOSYS; 209{
195 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 210 return 0;
196 err = sb->s_qcop->quota_on(sb, cnt, 0, NULL, 1);
197 if (err < 0 && !ret)
198 ret = err;
199 }
200 return ret;
201} 211}
202 212
203#else 213static inline int sb_has_quota_suspended(struct super_block *sb, int type)
214{
215 return 0;
216}
217
218static inline int sb_any_quota_suspended(struct super_block *sb)
219{
220 return 0;
221}
204 222
205/* 223/*
206 * NO-OP when quota not configured. 224 * NO-OP when quota not configured.
@@ -208,113 +226,144 @@ static inline int DQUOT_ON_REMOUNT(struct super_block *sb)
208#define sb_dquot_ops (NULL) 226#define sb_dquot_ops (NULL)
209#define sb_quotactl_ops (NULL) 227#define sb_quotactl_ops (NULL)
210 228
211static inline void DQUOT_INIT(struct inode *inode) 229static inline void vfs_dq_init(struct inode *inode)
212{ 230{
213} 231}
214 232
215static inline void DQUOT_DROP(struct inode *inode) 233static inline void vfs_dq_drop(struct inode *inode)
216{ 234{
217} 235}
218 236
219static inline int DQUOT_ALLOC_INODE(struct inode *inode) 237static inline int vfs_dq_alloc_inode(struct inode *inode)
220{ 238{
221 return 0; 239 return 0;
222} 240}
223 241
224static inline void DQUOT_FREE_INODE(struct inode *inode) 242static inline void vfs_dq_free_inode(struct inode *inode)
225{ 243{
226} 244}
227 245
228static inline void DQUOT_SYNC(struct super_block *sb) 246static inline void vfs_dq_sync(struct super_block *sb)
229{ 247{
230} 248}
231 249
232static inline int DQUOT_OFF(struct super_block *sb, int remount) 250static inline int vfs_dq_off(struct super_block *sb, int remount)
233{ 251{
234 return 0; 252 return 0;
235} 253}
236 254
237static inline int DQUOT_ON_REMOUNT(struct super_block *sb) 255static inline int vfs_dq_quota_on_remount(struct super_block *sb)
238{ 256{
239 return 0; 257 return 0;
240} 258}
241 259
242static inline int DQUOT_TRANSFER(struct inode *inode, struct iattr *iattr) 260static inline int vfs_dq_transfer(struct inode *inode, struct iattr *iattr)
243{ 261{
244 return 0; 262 return 0;
245} 263}
246 264
247static inline int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr) 265static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
248{ 266{
249 inode_add_bytes(inode, nr); 267 inode_add_bytes(inode, nr);
250 return 0; 268 return 0;
251} 269}
252 270
253static inline int DQUOT_PREALLOC_SPACE(struct inode *inode, qsize_t nr) 271static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
254{ 272{
255 DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr); 273 vfs_dq_prealloc_space_nodirty(inode, nr);
256 mark_inode_dirty(inode); 274 mark_inode_dirty(inode);
257 return 0; 275 return 0;
258} 276}
259 277
260static inline int DQUOT_ALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr) 278static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
261{ 279{
262 inode_add_bytes(inode, nr); 280 inode_add_bytes(inode, nr);
263 return 0; 281 return 0;
264} 282}
265 283
266static inline int DQUOT_ALLOC_SPACE(struct inode *inode, qsize_t nr) 284static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
267{ 285{
268 DQUOT_ALLOC_SPACE_NODIRTY(inode, nr); 286 vfs_dq_alloc_space_nodirty(inode, nr);
269 mark_inode_dirty(inode); 287 mark_inode_dirty(inode);
270 return 0; 288 return 0;
271} 289}
272 290
273static inline void DQUOT_FREE_SPACE_NODIRTY(struct inode *inode, qsize_t nr) 291static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
274{ 292{
275 inode_sub_bytes(inode, nr); 293 inode_sub_bytes(inode, nr);
276} 294}
277 295
278static inline void DQUOT_FREE_SPACE(struct inode *inode, qsize_t nr) 296static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
279{ 297{
280 DQUOT_FREE_SPACE_NODIRTY(inode, nr); 298 vfs_dq_free_space_nodirty(inode, nr);
281 mark_inode_dirty(inode); 299 mark_inode_dirty(inode);
282} 300}
283 301
284#endif /* CONFIG_QUOTA */ 302#endif /* CONFIG_QUOTA */
285 303
286static inline int DQUOT_PREALLOC_BLOCK_NODIRTY(struct inode *inode, qsize_t nr) 304static inline int vfs_dq_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
287{ 305{
288 return DQUOT_PREALLOC_SPACE_NODIRTY(inode, 306 return vfs_dq_prealloc_space_nodirty(inode,
289 nr << inode->i_sb->s_blocksize_bits); 307 nr << inode->i_sb->s_blocksize_bits);
290} 308}
291 309
292static inline int DQUOT_PREALLOC_BLOCK(struct inode *inode, qsize_t nr) 310static inline int vfs_dq_prealloc_block(struct inode *inode, qsize_t nr)
293{ 311{
294 return DQUOT_PREALLOC_SPACE(inode, 312 return vfs_dq_prealloc_space(inode,
295 nr << inode->i_sb->s_blocksize_bits); 313 nr << inode->i_sb->s_blocksize_bits);
296} 314}
297 315
298static inline int DQUOT_ALLOC_BLOCK_NODIRTY(struct inode *inode, qsize_t nr) 316static inline int vfs_dq_alloc_block_nodirty(struct inode *inode, qsize_t nr)
299{ 317{
300 return DQUOT_ALLOC_SPACE_NODIRTY(inode, 318 return vfs_dq_alloc_space_nodirty(inode,
301 nr << inode->i_sb->s_blocksize_bits); 319 nr << inode->i_sb->s_blocksize_bits);
302} 320}
303 321
304static inline int DQUOT_ALLOC_BLOCK(struct inode *inode, qsize_t nr) 322static inline int vfs_dq_alloc_block(struct inode *inode, qsize_t nr)
305{ 323{
306 return DQUOT_ALLOC_SPACE(inode, 324 return vfs_dq_alloc_space(inode,
307 nr << inode->i_sb->s_blocksize_bits); 325 nr << inode->i_sb->s_blocksize_bits);
308} 326}
309 327
310static inline void DQUOT_FREE_BLOCK_NODIRTY(struct inode *inode, qsize_t nr) 328static inline void vfs_dq_free_block_nodirty(struct inode *inode, qsize_t nr)
311{ 329{
312 DQUOT_FREE_SPACE_NODIRTY(inode, nr << inode->i_sb->s_blocksize_bits); 330 vfs_dq_free_space_nodirty(inode, nr << inode->i_sb->s_blocksize_bits);
313} 331}
314 332
315static inline void DQUOT_FREE_BLOCK(struct inode *inode, qsize_t nr) 333static inline void vfs_dq_free_block(struct inode *inode, qsize_t nr)
316{ 334{
317 DQUOT_FREE_SPACE(inode, nr << inode->i_sb->s_blocksize_bits); 335 vfs_dq_free_space(inode, nr << inode->i_sb->s_blocksize_bits);
318} 336}
319 337
338/*
339 * Define uppercase equivalents for compatibility with old function names
340 * Can go away when we think all users have been converted (15/04/2008)
341 */
342#define DQUOT_INIT(inode) vfs_dq_init(inode)
343#define DQUOT_DROP(inode) vfs_dq_drop(inode)
344#define DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr) \
345 vfs_dq_prealloc_space_nodirty(inode, nr)
346#define DQUOT_PREALLOC_SPACE(inode, nr) vfs_dq_prealloc_space(inode, nr)
347#define DQUOT_ALLOC_SPACE_NODIRTY(inode, nr) \
348 vfs_dq_alloc_space_nodirty(inode, nr)
349#define DQUOT_ALLOC_SPACE(inode, nr) vfs_dq_alloc_space(inode, nr)
350#define DQUOT_PREALLOC_BLOCK_NODIRTY(inode, nr) \
351 vfs_dq_prealloc_block_nodirty(inode, nr)
352#define DQUOT_PREALLOC_BLOCK(inode, nr) vfs_dq_prealloc_block(inode, nr)
353#define DQUOT_ALLOC_BLOCK_NODIRTY(inode, nr) \
354 vfs_dq_alloc_block_nodirty(inode, nr)
355#define DQUOT_ALLOC_BLOCK(inode, nr) vfs_dq_alloc_block(inode, nr)
356#define DQUOT_ALLOC_INODE(inode) vfs_dq_alloc_inode(inode)
357#define DQUOT_FREE_SPACE_NODIRTY(inode, nr) \
358 vfs_dq_free_space_nodirty(inode, nr)
359#define DQUOT_FREE_SPACE(inode, nr) vfs_dq_free_space(inode, nr)
360#define DQUOT_FREE_BLOCK_NODIRTY(inode, nr) \
361 vfs_dq_free_block_nodirty(inode, nr)
362#define DQUOT_FREE_BLOCK(inode, nr) vfs_dq_free_block(inode, nr)
363#define DQUOT_FREE_INODE(inode) vfs_dq_free_inode(inode)
364#define DQUOT_TRANSFER(inode, iattr) vfs_dq_transfer(inode, iattr)
365#define DQUOT_SYNC(sb) vfs_dq_sync(sb)
366#define DQUOT_OFF(sb, remount) vfs_dq_off(sb, remount)
367#define DQUOT_ON_REMOUNT(sb) vfs_dq_quota_on_remount(sb)
368
320#endif /* _LINUX_QUOTAOPS_ */ 369#endif /* _LINUX_QUOTAOPS_ */