aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/quotaops.h
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@infradead.org>2010-03-03 09:05:00 -0500
committerJan Kara <jack@suse.cz>2010-03-04 18:20:28 -0500
commit5dd4056db84387975140ff2568eaa0406f07985e (patch)
tree03c26d7f6e3367b167bfeeb1a01654c6619573f4 /include/linux/quotaops.h
parent49792c806d0bfd53afc789dcdf50dc9bed2c5b83 (diff)
dquot: cleanup space allocation / freeing routines
Get rid of the alloc_space, free_space, reserve_space, claim_space and release_rsv dquot operations - they are always called from the filesystem and if a filesystem really needs their own (which none currently does) it can just call into it's own routine directly. Move shared logic into the common __dquot_alloc_space, dquot_claim_space_nodirty and __dquot_free_space low-level methods, and rationalize the wrappers around it to move as much as possible code into the common block for CONFIG_QUOTA vs not. Also rename all these helpers to be named dquot_* instead of vfs_dq_*. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'include/linux/quotaops.h')
-rw-r--r--include/linux/quotaops.h208
1 files changed, 58 insertions, 150 deletions
diff --git a/include/linux/quotaops.h b/include/linux/quotaops.h
index e1cae204b5d9..47e85682e118 100644
--- a/include/linux/quotaops.h
+++ b/include/linux/quotaops.h
@@ -33,14 +33,13 @@ int dquot_scan_active(struct super_block *sb,
33struct dquot *dquot_alloc(struct super_block *sb, int type); 33struct dquot *dquot_alloc(struct super_block *sb, int type);
34void dquot_destroy(struct dquot *dquot); 34void dquot_destroy(struct dquot *dquot);
35 35
36int dquot_alloc_space(struct inode *inode, qsize_t number, int prealloc); 36int __dquot_alloc_space(struct inode *inode, qsize_t number,
37int dquot_alloc_inode(const struct inode *inode, qsize_t number); 37 int warn, int reserve);
38void __dquot_free_space(struct inode *inode, qsize_t number, int reserve);
38 39
39int dquot_reserve_space(struct inode *inode, qsize_t number, int prealloc); 40int dquot_alloc_inode(const struct inode *inode, qsize_t number);
40int dquot_claim_space(struct inode *inode, qsize_t number);
41void dquot_release_reserved_space(struct inode *inode, qsize_t number);
42 41
43int dquot_free_space(struct inode *inode, qsize_t number); 42int dquot_claim_space_nodirty(struct inode *inode, qsize_t number);
44int dquot_free_inode(const struct inode *inode, qsize_t number); 43int dquot_free_inode(const struct inode *inode, qsize_t number);
45 44
46int dquot_transfer(struct inode *inode, qid_t *chid, unsigned long mask); 45int dquot_transfer(struct inode *inode, qid_t *chid, unsigned long mask);
@@ -149,60 +148,6 @@ static inline void vfs_dq_init(struct inode *inode)
149 inode->i_sb->dq_op->initialize(inode, -1); 148 inode->i_sb->dq_op->initialize(inode, -1);
150} 149}
151 150
152/* The following allocation/freeing/transfer functions *must* be called inside
153 * a transaction (deadlocks possible otherwise) */
154static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
155{
156 if (sb_any_quota_active(inode->i_sb)) {
157 /* Used space is updated in alloc_space() */
158 if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
159 return 1;
160 }
161 else
162 inode_add_bytes(inode, nr);
163 return 0;
164}
165
166static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
167{
168 int ret;
169 if (!(ret = vfs_dq_prealloc_space_nodirty(inode, nr)))
170 mark_inode_dirty(inode);
171 return ret;
172}
173
174static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
175{
176 if (sb_any_quota_active(inode->i_sb)) {
177 /* Used space is updated in alloc_space() */
178 if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
179 return 1;
180 }
181 else
182 inode_add_bytes(inode, nr);
183 return 0;
184}
185
186static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
187{
188 int ret;
189 if (!(ret = vfs_dq_alloc_space_nodirty(inode, nr)))
190 mark_inode_dirty(inode);
191 return ret;
192}
193
194static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
195{
196 if (sb_any_quota_active(inode->i_sb)) {
197 /* Used space is updated in alloc_space() */
198 if (inode->i_sb->dq_op->reserve_space(inode, nr, 0) == NO_QUOTA)
199 return 1;
200 }
201 else
202 inode_add_rsv_space(inode, nr);
203 return 0;
204}
205
206static inline int vfs_dq_alloc_inode(struct inode *inode) 151static inline int vfs_dq_alloc_inode(struct inode *inode)
207{ 152{
208 if (sb_any_quota_active(inode->i_sb)) { 153 if (sb_any_quota_active(inode->i_sb)) {
@@ -213,47 +158,6 @@ static inline int vfs_dq_alloc_inode(struct inode *inode)
213 return 0; 158 return 0;
214} 159}
215 160
216/*
217 * Convert in-memory reserved quotas to real consumed quotas
218 */
219static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
220{
221 if (sb_any_quota_active(inode->i_sb)) {
222 if (inode->i_sb->dq_op->claim_space(inode, nr) == NO_QUOTA)
223 return 1;
224 } else
225 inode_claim_rsv_space(inode, nr);
226
227 mark_inode_dirty(inode);
228 return 0;
229}
230
231/*
232 * Release reserved (in-memory) quotas
233 */
234static inline
235void vfs_dq_release_reservation_space(struct inode *inode, qsize_t nr)
236{
237 if (sb_any_quota_active(inode->i_sb))
238 inode->i_sb->dq_op->release_rsv(inode, nr);
239 else
240 inode_sub_rsv_space(inode, nr);
241}
242
243static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
244{
245 if (sb_any_quota_active(inode->i_sb))
246 inode->i_sb->dq_op->free_space(inode, nr);
247 else
248 inode_sub_bytes(inode, nr);
249}
250
251static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
252{
253 vfs_dq_free_space_nodirty(inode, nr);
254 mark_inode_dirty(inode);
255}
256
257static inline void vfs_dq_free_inode(struct inode *inode) 161static inline void vfs_dq_free_inode(struct inode *inode)
258{ 162{
259 if (sb_any_quota_active(inode->i_sb)) 163 if (sb_any_quota_active(inode->i_sb))
@@ -351,105 +255,109 @@ static inline int vfs_dq_transfer(struct inode *inode, struct iattr *iattr)
351 return 0; 255 return 0;
352} 256}
353 257
354static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr) 258static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
259 int warn, int reserve)
355{ 260{
356 inode_add_bytes(inode, nr); 261 if (!reserve)
262 inode_add_bytes(inode, number);
357 return 0; 263 return 0;
358} 264}
359 265
360static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr) 266static inline void __dquot_free_space(struct inode *inode, qsize_t number,
267 int reserve)
361{ 268{
362 vfs_dq_prealloc_space_nodirty(inode, nr); 269 if (!reserve)
363 mark_inode_dirty(inode); 270 inode_sub_bytes(inode, number);
364 return 0;
365} 271}
366 272
367static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr) 273static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
368{ 274{
369 inode_add_bytes(inode, nr); 275 inode_add_bytes(inode, number);
370 return 0; 276 return 0;
371} 277}
372 278
373static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr) 279#endif /* CONFIG_QUOTA */
280
281static inline int dquot_alloc_space_nodirty(struct inode *inode, qsize_t nr)
374{ 282{
375 vfs_dq_alloc_space_nodirty(inode, nr); 283 return __dquot_alloc_space(inode, nr, 1, 0);
376 mark_inode_dirty(inode);
377 return 0;
378} 284}
379 285
380static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr) 286static inline int dquot_alloc_space(struct inode *inode, qsize_t nr)
381{ 287{
382 return 0; 288 int ret;
289
290 ret = dquot_alloc_space_nodirty(inode, nr);
291 if (!ret)
292 mark_inode_dirty(inode);
293 return ret;
383} 294}
384 295
385static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr) 296static inline int dquot_alloc_block_nodirty(struct inode *inode, qsize_t nr)
386{ 297{
387 return vfs_dq_alloc_space(inode, nr); 298 return dquot_alloc_space_nodirty(inode, nr << inode->i_blkbits);
388} 299}
389 300
390static inline 301static inline int dquot_alloc_block(struct inode *inode, qsize_t nr)
391int vfs_dq_release_reservation_space(struct inode *inode, qsize_t nr)
392{ 302{
393 return 0; 303 return dquot_alloc_space(inode, nr << inode->i_blkbits);
394} 304}
395 305
396static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr) 306static inline int dquot_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
397{ 307{
398 inode_sub_bytes(inode, nr); 308 return __dquot_alloc_space(inode, nr << inode->i_blkbits, 0, 0);
399} 309}
400 310
401static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr) 311static inline int dquot_prealloc_block(struct inode *inode, qsize_t nr)
402{ 312{
403 vfs_dq_free_space_nodirty(inode, nr); 313 int ret;
404 mark_inode_dirty(inode);
405}
406
407#endif /* CONFIG_QUOTA */
408 314
409static inline int vfs_dq_prealloc_block_nodirty(struct inode *inode, qsize_t nr) 315 ret = dquot_prealloc_block_nodirty(inode, nr);
410{ 316 if (!ret)
411 return vfs_dq_prealloc_space_nodirty(inode, nr << inode->i_blkbits); 317 mark_inode_dirty(inode);
318 return ret;
412} 319}
413 320
414static inline int vfs_dq_prealloc_block(struct inode *inode, qsize_t nr) 321static inline int dquot_reserve_block(struct inode *inode, qsize_t nr)
415{ 322{
416 return vfs_dq_prealloc_space(inode, nr << inode->i_blkbits); 323 return __dquot_alloc_space(inode, nr << inode->i_blkbits, 1, 1);
417} 324}
418 325
419static inline int vfs_dq_alloc_block_nodirty(struct inode *inode, qsize_t nr) 326static inline int dquot_claim_block(struct inode *inode, qsize_t nr)
420{ 327{
421 return vfs_dq_alloc_space_nodirty(inode, nr << inode->i_blkbits); 328 int ret;
422}
423 329
424static inline int vfs_dq_alloc_block(struct inode *inode, qsize_t nr) 330 ret = dquot_claim_space_nodirty(inode, nr << inode->i_blkbits);
425{ 331 if (!ret)
426 return vfs_dq_alloc_space(inode, nr << inode->i_blkbits); 332 mark_inode_dirty(inode);
333 return ret;
427} 334}
428 335
429static inline int vfs_dq_reserve_block(struct inode *inode, qsize_t nr) 336static inline void dquot_free_space_nodirty(struct inode *inode, qsize_t nr)
430{ 337{
431 return vfs_dq_reserve_space(inode, nr << inode->i_blkbits); 338 __dquot_free_space(inode, nr, 0);
432} 339}
433 340
434static inline int vfs_dq_claim_block(struct inode *inode, qsize_t nr) 341static inline void dquot_free_space(struct inode *inode, qsize_t nr)
435{ 342{
436 return vfs_dq_claim_space(inode, nr << inode->i_blkbits); 343 dquot_free_space_nodirty(inode, nr);
344 mark_inode_dirty(inode);
437} 345}
438 346
439static inline 347static inline void dquot_free_block_nodirty(struct inode *inode, qsize_t nr)
440void vfs_dq_release_reservation_block(struct inode *inode, qsize_t nr)
441{ 348{
442 vfs_dq_release_reservation_space(inode, nr << inode->i_blkbits); 349 dquot_free_space_nodirty(inode, nr << inode->i_blkbits);
443} 350}
444 351
445static inline void vfs_dq_free_block_nodirty(struct inode *inode, qsize_t nr) 352static inline void dquot_free_block(struct inode *inode, qsize_t nr)
446{ 353{
447 vfs_dq_free_space_nodirty(inode, nr << inode->i_blkbits); 354 dquot_free_space(inode, nr << inode->i_blkbits);
448} 355}
449 356
450static inline void vfs_dq_free_block(struct inode *inode, qsize_t nr) 357static inline void dquot_release_reservation_block(struct inode *inode,
358 qsize_t nr)
451{ 359{
452 vfs_dq_free_space(inode, nr << inode->i_blkbits); 360 __dquot_free_space(inode, nr << inode->i_blkbits, 1);
453} 361}
454 362
455#endif /* _LINUX_QUOTAOPS_ */ 363#endif /* _LINUX_QUOTAOPS_ */