Skip to content

Commit 5dd4056

Browse files
Christoph Hellwigjankara
authored andcommitted
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>
1 parent 49792c8 commit 5dd4056

29 files changed

Lines changed: 258 additions & 383 deletions

File tree

‎Documentation/filesystems/Locking‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,7 @@ in sys_read() and friends.
462462
prototypes:
463463
int (*initialize) (struct inode *, int);
464464
int (*drop) (struct inode *);
465-
int (*alloc_space) (struct inode *, qsize_t, int);
466465
int (*alloc_inode) (const struct inode *, unsigned long);
467-
int (*free_space) (struct inode *, qsize_t);
468466
int (*free_inode) (const struct inode *, unsigned long);
469467
int (*transfer) (struct inode *, struct iattr *);
470468
int (*write_dquot) (struct dquot *);
@@ -481,9 +479,7 @@ What filesystem should expect from the generic quota functions:
481479
FS recursion Held locks when called
482480
initialize: yes maybe dqonoff_sem
483481
drop: yes -
484-
alloc_space: ->mark_dirty() -
485482
alloc_inode: ->mark_dirty() -
486-
free_space: ->mark_dirty() -
487483
free_inode: ->mark_dirty() -
488484
transfer: yes -
489485
write_dquot: yes dqonoff_sem or dqptr_sem
@@ -495,7 +491,7 @@ write_info: yes dqonoff_sem
495491
FS recursion means calling ->quota_read() and ->quota_write() from superblock
496492
operations.
497493

498-
->alloc_space(), ->alloc_inode(), ->free_space(), ->free_inode() are called
494+
->alloc_inode(), ->free_inode() are called
499495
only directly by the filesystem and do not call any fs functions only
500496
the ->mark_dirty() operation.
501497

‎fs/ext2/balloc.c‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ void ext2_free_blocks (struct inode * inode, unsigned long block,
570570
error_return:
571571
brelse(bitmap_bh);
572572
release_blocks(sb, freed);
573-
vfs_dq_free_block(inode, freed);
573+
dquot_free_block(inode, freed);
574574
}
575575

576576
/**
@@ -1236,6 +1236,7 @@ ext2_fsblk_t ext2_new_blocks(struct inode *inode, ext2_fsblk_t goal,
12361236
unsigned short windowsz = 0;
12371237
unsigned long ngroups;
12381238
unsigned long num = *count;
1239+
int ret;
12391240

12401241
*errp = -ENOSPC;
12411242
sb = inode->i_sb;
@@ -1247,8 +1248,9 @@ ext2_fsblk_t ext2_new_blocks(struct inode *inode, ext2_fsblk_t goal,
12471248
/*
12481249
* Check quota for allocation of this block.
12491250
*/
1250-
if (vfs_dq_alloc_block(inode, num)) {
1251-
*errp = -EDQUOT;
1251+
ret = dquot_alloc_block(inode, num);
1252+
if (ret) {
1253+
*errp = ret;
12521254
return 0;
12531255
}
12541256

@@ -1409,7 +1411,7 @@ ext2_fsblk_t ext2_new_blocks(struct inode *inode, ext2_fsblk_t goal,
14091411

14101412
*errp = 0;
14111413
brelse(bitmap_bh);
1412-
vfs_dq_free_block(inode, *count-num);
1414+
dquot_free_block(inode, *count-num);
14131415
*count = num;
14141416
return ret_block;
14151417

@@ -1420,7 +1422,7 @@ ext2_fsblk_t ext2_new_blocks(struct inode *inode, ext2_fsblk_t goal,
14201422
* Undo the block allocation
14211423
*/
14221424
if (!performed_allocation)
1423-
vfs_dq_free_block(inode, *count);
1425+
dquot_free_block(inode, *count);
14241426
brelse(bitmap_bh);
14251427
return 0;
14261428
}

‎fs/ext2/xattr.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,8 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
644644
the inode. */
645645
ea_bdebug(new_bh, "reusing block");
646646

647-
error = -EDQUOT;
648-
if (vfs_dq_alloc_block(inode, 1)) {
647+
error = dquot_alloc_block(inode, 1);
648+
if (error) {
649649
unlock_buffer(new_bh);
650650
goto cleanup;
651651
}
@@ -702,7 +702,7 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
702702
* as if nothing happened and cleanup the unused block */
703703
if (error && error != -ENOSPC) {
704704
if (new_bh && new_bh != old_bh)
705-
vfs_dq_free_block(inode, 1);
705+
dquot_free_block(inode, 1);
706706
goto cleanup;
707707
}
708708
} else
@@ -734,7 +734,7 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
734734
le32_add_cpu(&HDR(old_bh)->h_refcount, -1);
735735
if (ce)
736736
mb_cache_entry_release(ce);
737-
vfs_dq_free_block(inode, 1);
737+
dquot_free_block(inode, 1);
738738
mark_buffer_dirty(old_bh);
739739
ea_bdebug(old_bh, "refcount now=%d",
740740
le32_to_cpu(HDR(old_bh)->h_refcount));
@@ -797,7 +797,7 @@ ext2_xattr_delete_inode(struct inode *inode)
797797
mark_buffer_dirty(bh);
798798
if (IS_SYNC(inode))
799799
sync_dirty_buffer(bh);
800-
vfs_dq_free_block(inode, 1);
800+
dquot_free_block(inode, 1);
801801
}
802802
EXT2_I(inode)->i_file_acl = 0;
803803

‎fs/ext3/balloc.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ void ext3_free_blocks(handle_t *handle, struct inode *inode,
676676
}
677677
ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
678678
if (dquot_freed_blocks)
679-
vfs_dq_free_block(inode, dquot_freed_blocks);
679+
dquot_free_block(inode, dquot_freed_blocks);
680680
return;
681681
}
682682

@@ -1502,8 +1502,9 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode,
15021502
/*
15031503
* Check quota for allocation of this block.
15041504
*/
1505-
if (vfs_dq_alloc_block(inode, num)) {
1506-
*errp = -EDQUOT;
1505+
err = dquot_alloc_block(inode, num);
1506+
if (err) {
1507+
*errp = err;
15071508
return 0;
15081509
}
15091510

@@ -1713,7 +1714,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode,
17131714

17141715
*errp = 0;
17151716
brelse(bitmap_bh);
1716-
vfs_dq_free_block(inode, *count-num);
1717+
dquot_free_block(inode, *count-num);
17171718
*count = num;
17181719
return ret_block;
17191720

@@ -1728,7 +1729,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode,
17281729
* Undo the block allocation
17291730
*/
17301731
if (!performed_allocation)
1731-
vfs_dq_free_block(inode, *count);
1732+
dquot_free_block(inode, *count);
17321733
brelse(bitmap_bh);
17331734
return 0;
17341735
}

‎fs/ext3/inode.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3336,7 +3336,7 @@ int ext3_mark_inode_dirty(handle_t *handle, struct inode *inode)
33363336
* i_size has been changed by generic_commit_write() and we thus need
33373337
* to include the updated inode in the current transaction.
33383338
*
3339-
* Also, vfs_dq_alloc_space() will always dirty the inode when blocks
3339+
* Also, dquot_alloc_space() will always dirty the inode when blocks
33403340
* are allocated to the file.
33413341
*
33423342
* If the inode is marked synchronous, we don't honour that here - doing

‎fs/ext3/super.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,9 +752,7 @@ static ssize_t ext3_quota_write(struct super_block *sb, int type,
752752
static const struct dquot_operations ext3_quota_operations = {
753753
.initialize = dquot_initialize,
754754
.drop = dquot_drop,
755-
.alloc_space = dquot_alloc_space,
756755
.alloc_inode = dquot_alloc_inode,
757-
.free_space = dquot_free_space,
758756
.free_inode = dquot_free_inode,
759757
.transfer = dquot_transfer,
760758
.write_dquot = ext3_write_dquot,

‎fs/ext3/xattr.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ ext3_xattr_release_block(handle_t *handle, struct inode *inode,
500500
error = ext3_journal_dirty_metadata(handle, bh);
501501
if (IS_SYNC(inode))
502502
handle->h_sync = 1;
503-
vfs_dq_free_block(inode, 1);
503+
dquot_free_block(inode, 1);
504504
ea_bdebug(bh, "refcount now=%d; releasing",
505505
le32_to_cpu(BHDR(bh)->h_refcount));
506506
if (ce)
@@ -775,8 +775,8 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode,
775775
else {
776776
/* The old block is released after updating
777777
the inode. */
778-
error = -EDQUOT;
779-
if (vfs_dq_alloc_block(inode, 1))
778+
error = dquot_alloc_block(inode, 1);
779+
if (error)
780780
goto cleanup;
781781
error = ext3_journal_get_write_access(handle,
782782
new_bh);
@@ -850,7 +850,7 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode,
850850
return error;
851851

852852
cleanup_dquot:
853-
vfs_dq_free_block(inode, 1);
853+
dquot_free_block(inode, 1);
854854
goto cleanup;
855855

856856
bad_block:

‎fs/ext4/inode.c‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,9 +1093,9 @@ void ext4_da_update_reserve_space(struct inode *inode,
10931093

10941094
/* Update quota subsystem */
10951095
if (quota_claim) {
1096-
vfs_dq_claim_block(inode, used);
1096+
dquot_claim_block(inode, used);
10971097
if (mdb_free)
1098-
vfs_dq_release_reservation_block(inode, mdb_free);
1098+
dquot_release_reservation_block(inode, mdb_free);
10991099
} else {
11001100
/*
11011101
* We did fallocate with an offset that is already delayed
@@ -1106,8 +1106,8 @@ void ext4_da_update_reserve_space(struct inode *inode,
11061106
* that
11071107
*/
11081108
if (allocated_meta_blocks)
1109-
vfs_dq_claim_block(inode, allocated_meta_blocks);
1110-
vfs_dq_release_reservation_block(inode, mdb_free + used);
1109+
dquot_claim_block(inode, allocated_meta_blocks);
1110+
dquot_release_reservation_block(inode, mdb_free + used);
11111111
}
11121112

11131113
/*
@@ -1836,6 +1836,7 @@ static int ext4_da_reserve_space(struct inode *inode, sector_t lblock)
18361836
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
18371837
struct ext4_inode_info *ei = EXT4_I(inode);
18381838
unsigned long md_needed, md_reserved;
1839+
int ret;
18391840

18401841
/*
18411842
* recalculate the amount of metadata blocks to reserve
@@ -1853,11 +1854,12 @@ static int ext4_da_reserve_space(struct inode *inode, sector_t lblock)
18531854
* later. Real quota accounting is done at pages writeout
18541855
* time.
18551856
*/
1856-
if (vfs_dq_reserve_block(inode, md_needed + 1))
1857-
return -EDQUOT;
1857+
ret = dquot_reserve_block(inode, md_needed + 1);
1858+
if (ret)
1859+
return ret;
18581860

18591861
if (ext4_claim_free_blocks(sbi, md_needed + 1)) {
1860-
vfs_dq_release_reservation_block(inode, md_needed + 1);
1862+
dquot_release_reservation_block(inode, md_needed + 1);
18611863
if (ext4_should_retry_alloc(inode->i_sb, &retries)) {
18621864
yield();
18631865
goto repeat;
@@ -1914,7 +1916,7 @@ static void ext4_da_release_space(struct inode *inode, int to_free)
19141916

19151917
spin_unlock(&EXT4_I(inode)->i_block_reservation_lock);
19161918

1917-
vfs_dq_release_reservation_block(inode, to_free);
1919+
dquot_release_reservation_block(inode, to_free);
19181920
}
19191921

19201922
static void ext4_da_page_release_reservation(struct page *page,
@@ -5641,7 +5643,7 @@ int ext4_mark_inode_dirty(handle_t *handle, struct inode *inode)
56415643
* i_size has been changed by generic_commit_write() and we thus need
56425644
* to include the updated inode in the current transaction.
56435645
*
5644-
* Also, vfs_dq_alloc_block() will always dirty the inode when blocks
5646+
* Also, dquot_alloc_block() will always dirty the inode when blocks
56455647
* are allocated to the file.
56465648
*
56475649
* If the inode is marked synchronous, we don't honour that here - doing

‎fs/ext4/mballoc.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4254,7 +4254,7 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle,
42544254
return 0;
42554255
}
42564256
reserv_blks = ar->len;
4257-
while (ar->len && vfs_dq_alloc_block(ar->inode, ar->len)) {
4257+
while (ar->len && dquot_alloc_block(ar->inode, ar->len)) {
42584258
ar->flags |= EXT4_MB_HINT_NOPREALLOC;
42594259
ar->len--;
42604260
}
@@ -4331,7 +4331,7 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle,
43314331
kmem_cache_free(ext4_ac_cachep, ac);
43324332
out1:
43334333
if (inquota && ar->len < inquota)
4334-
vfs_dq_free_block(ar->inode, inquota - ar->len);
4334+
dquot_free_block(ar->inode, inquota - ar->len);
43354335
out3:
43364336
if (!ar->len) {
43374337
if (!EXT4_I(ar->inode)->i_delalloc_reserved_flag)
@@ -4646,7 +4646,7 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode,
46464646
sb->s_dirt = 1;
46474647
error_return:
46484648
if (freed)
4649-
vfs_dq_free_block(inode, freed);
4649+
dquot_free_block(inode, freed);
46504650
brelse(bitmap_bh);
46514651
ext4_std_error(sb, err);
46524652
if (ac)

‎fs/ext4/super.c‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,15 +1014,10 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type,
10141014
static const struct dquot_operations ext4_quota_operations = {
10151015
.initialize = dquot_initialize,
10161016
.drop = dquot_drop,
1017-
.alloc_space = dquot_alloc_space,
1018-
.reserve_space = dquot_reserve_space,
1019-
.claim_space = dquot_claim_space,
1020-
.release_rsv = dquot_release_reserved_space,
10211017
#ifdef CONFIG_QUOTA
10221018
.get_reserved_space = ext4_get_reserved_space,
10231019
#endif
10241020
.alloc_inode = dquot_alloc_inode,
1025-
.free_space = dquot_free_space,
10261021
.free_inode = dquot_free_inode,
10271022
.transfer = dquot_transfer,
10281023
.write_dquot = ext4_write_dquot,

0 commit comments

Comments
 (0)