Commit 8c3bf8a0 authored by Eric Sandeen's avatar Eric Sandeen Committed by Theodore Ts'o

merge ext4_claim_free_blocks & ext4_has_free_blocks

Mingming pointed out that ext4_claim_free_blocks & ext4_has_free_blocks
are largely cut & pasted; they can be collapsed/merged as follows.
Signed-off-by: default avatarEric Sandeen <sandeen@redhat.com>
Reviewed-by: default avatarMingming Cao <cmm@us.ibm.com>
Signed-off-by: default avatar"Theodore Ts'o" <tytso@mit.edu>
parent 6c20ec85
...@@ -589,8 +589,15 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode, ...@@ -589,8 +589,15 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode,
return; return;
} }
int ext4_claim_free_blocks(struct ext4_sb_info *sbi, /**
s64 nblocks) * ext4_has_free_blocks()
* @sbi: in-core super block structure.
* @nblocks: number of needed blocks
*
* Check if filesystem has nblocks free & available for allocation.
* On success return 1, return 0 on failure.
*/
int ext4_has_free_blocks(struct ext4_sb_info *sbi, s64 nblocks)
{ {
s64 free_blocks, dirty_blocks; s64 free_blocks, dirty_blocks;
s64 root_blocks = 0; s64 root_blocks = 0;
...@@ -620,53 +627,21 @@ int ext4_claim_free_blocks(struct ext4_sb_info *sbi, ...@@ -620,53 +627,21 @@ int ext4_claim_free_blocks(struct ext4_sb_info *sbi,
*/ */
if (free_blocks < ((root_blocks + nblocks) + dirty_blocks)) if (free_blocks < ((root_blocks + nblocks) + dirty_blocks))
/* we don't have free space */ /* we don't have free space */
return -ENOSPC;
/* Add the blocks to nblocks */
percpu_counter_add(dbc, nblocks);
return 0; return 0;
return 1;
} }
/** int ext4_claim_free_blocks(struct ext4_sb_info *sbi,
* ext4_has_free_blocks()
* @sbi: in-core super block structure.
* @nblocks: number of neeed blocks
*
* Check if filesystem has free blocks available for allocation.
* Return the number of blocks avaible for allocation for this request
* On success, return nblocks
*/
ext4_fsblk_t ext4_has_free_blocks(struct ext4_sb_info *sbi,
s64 nblocks) s64 nblocks)
{ {
s64 free_blocks, dirty_blocks; if (ext4_has_free_blocks(sbi, nblocks)) {
s64 root_blocks = 0; percpu_counter_add(&sbi->s_dirtyblocks_counter, nblocks);
struct percpu_counter *fbc = &sbi->s_freeblocks_counter;
struct percpu_counter *dbc = &sbi->s_dirtyblocks_counter;
free_blocks = percpu_counter_read_positive(fbc);
dirty_blocks = percpu_counter_read_positive(dbc);
if (!capable(CAP_SYS_RESOURCE) &&
sbi->s_resuid != current->fsuid &&
(sbi->s_resgid == 0 || !in_group_p(sbi->s_resgid)))
root_blocks = ext4_r_blocks_count(sbi->s_es);
if (free_blocks - (nblocks + root_blocks + dirty_blocks) <
EXT4_FREEBLOCKS_WATERMARK) {
free_blocks = percpu_counter_sum(fbc);
dirty_blocks = percpu_counter_sum(dbc);
}
if (free_blocks <= (root_blocks + dirty_blocks))
/* we don't have free space */
return 0; return 0;
} else
if (free_blocks - (root_blocks + dirty_blocks) < nblocks) return -ENOSPC;
return free_blocks - (root_blocks + dirty_blocks);
return nblocks;
} }
/** /**
* ext4_should_retry_alloc() * ext4_should_retry_alloc()
* @sb: super block * @sb: super block
......
...@@ -1003,8 +1003,7 @@ extern ext4_fsblk_t ext4_new_blocks(handle_t *handle, struct inode *inode, ...@@ -1003,8 +1003,7 @@ extern ext4_fsblk_t ext4_new_blocks(handle_t *handle, struct inode *inode,
ext4_lblk_t iblock, ext4_fsblk_t goal, ext4_lblk_t iblock, ext4_fsblk_t goal,
unsigned long *count, int *errp); unsigned long *count, int *errp);
extern int ext4_claim_free_blocks(struct ext4_sb_info *sbi, s64 nblocks); extern int ext4_claim_free_blocks(struct ext4_sb_info *sbi, s64 nblocks);
extern ext4_fsblk_t ext4_has_free_blocks(struct ext4_sb_info *sbi, extern int ext4_has_free_blocks(struct ext4_sb_info *sbi, s64 nblocks);
s64 nblocks);
extern void ext4_free_blocks(handle_t *handle, struct inode *inode, extern void ext4_free_blocks(handle_t *handle, struct inode *inode,
ext4_fsblk_t block, unsigned long count, int metadata); ext4_fsblk_t block, unsigned long count, int metadata);
extern void ext4_free_blocks_sb(handle_t *handle, struct super_block *sb, extern void ext4_free_blocks_sb(handle_t *handle, struct super_block *sb,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment