mirror of https://gitee.com/openkylin/linux.git
ext4: remove do_blk_alloc()
The convenience function do_blk_alloc() is a static function with only one caller, so fold it into ext4_new_meta_blocks() to simplify the code and to make it easier to understand. To save more stack space, if count is a null pointer in ext4_new_meta_blocks() assume that caller wanted a single block (and if there is an error, no blocks were allocated). Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
This commit is contained in:
parent
cfe82c8567
commit
97df5d155d
|
@ -666,59 +666,40 @@ int ext4_should_retry_alloc(struct super_block *sb, int *retries)
|
||||||
return jbd2_journal_force_commit_nested(EXT4_SB(sb)->s_journal);
|
return jbd2_journal_force_commit_nested(EXT4_SB(sb)->s_journal);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define EXT4_META_BLOCK 0x1
|
|
||||||
|
|
||||||
static ext4_fsblk_t do_blk_alloc(handle_t *handle, struct inode *inode,
|
|
||||||
ext4_lblk_t iblock, ext4_fsblk_t goal,
|
|
||||||
unsigned long *count, int *errp, int flags)
|
|
||||||
{
|
|
||||||
struct ext4_allocation_request ar;
|
|
||||||
ext4_fsblk_t ret;
|
|
||||||
|
|
||||||
memset(&ar, 0, sizeof(ar));
|
|
||||||
/* Fill with neighbour allocated blocks */
|
|
||||||
|
|
||||||
ar.inode = inode;
|
|
||||||
ar.goal = goal;
|
|
||||||
ar.len = *count;
|
|
||||||
ar.logical = iblock;
|
|
||||||
|
|
||||||
if (S_ISREG(inode->i_mode) && !(flags & EXT4_META_BLOCK))
|
|
||||||
/* enable in-core preallocation for data block allocation */
|
|
||||||
ar.flags = EXT4_MB_HINT_DATA;
|
|
||||||
else
|
|
||||||
/* disable in-core preallocation for non-regular files */
|
|
||||||
ar.flags = 0;
|
|
||||||
|
|
||||||
ret = ext4_mb_new_blocks(handle, &ar, errp);
|
|
||||||
*count = ar.len;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ext4_new_meta_blocks() -- allocate block for meta data (indexing) blocks
|
* ext4_new_meta_blocks() -- allocate block for meta data (indexing) blocks
|
||||||
*
|
*
|
||||||
* @handle: handle to this transaction
|
* @handle: handle to this transaction
|
||||||
* @inode: file inode
|
* @inode: file inode
|
||||||
* @goal: given target block(filesystem wide)
|
* @goal: given target block(filesystem wide)
|
||||||
* @count: total number of blocks need
|
* @count: pointer to total number of blocks needed
|
||||||
* @errp: error code
|
* @errp: error code
|
||||||
*
|
*
|
||||||
* Return 1st allocated block numberon success, *count stores total account
|
* Return 1st allocated block number on success, *count stores total account
|
||||||
* error stores in errp pointer
|
* error stores in errp pointer
|
||||||
*/
|
*/
|
||||||
ext4_fsblk_t ext4_new_meta_blocks(handle_t *handle, struct inode *inode,
|
ext4_fsblk_t ext4_new_meta_blocks(handle_t *handle, struct inode *inode,
|
||||||
ext4_fsblk_t goal, unsigned long *count, int *errp)
|
ext4_fsblk_t goal, unsigned long *count, int *errp)
|
||||||
{
|
{
|
||||||
|
struct ext4_allocation_request ar;
|
||||||
ext4_fsblk_t ret;
|
ext4_fsblk_t ret;
|
||||||
ret = do_blk_alloc(handle, inode, 0, goal,
|
|
||||||
count, errp, EXT4_META_BLOCK);
|
memset(&ar, 0, sizeof(ar));
|
||||||
|
/* Fill with neighbour allocated blocks */
|
||||||
|
ar.inode = inode;
|
||||||
|
ar.goal = goal;
|
||||||
|
ar.len = count ? *count : 1;
|
||||||
|
|
||||||
|
ret = ext4_mb_new_blocks(handle, &ar, errp);
|
||||||
|
if (count)
|
||||||
|
*count = ar.len;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Account for the allocated meta blocks
|
* Account for the allocated meta blocks
|
||||||
*/
|
*/
|
||||||
if (!(*errp) && EXT4_I(inode)->i_delalloc_reserved_flag) {
|
if (!(*errp) && EXT4_I(inode)->i_delalloc_reserved_flag) {
|
||||||
spin_lock(&EXT4_I(inode)->i_block_reservation_lock);
|
spin_lock(&EXT4_I(inode)->i_block_reservation_lock);
|
||||||
EXT4_I(inode)->i_allocated_meta_blocks += *count;
|
EXT4_I(inode)->i_allocated_meta_blocks += ar.len;
|
||||||
spin_unlock(&EXT4_I(inode)->i_block_reservation_lock);
|
spin_unlock(&EXT4_I(inode)->i_block_reservation_lock);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -189,10 +189,9 @@ ext4_ext_new_meta_block(handle_t *handle, struct inode *inode,
|
||||||
struct ext4_extent *ex, int *err)
|
struct ext4_extent *ex, int *err)
|
||||||
{
|
{
|
||||||
ext4_fsblk_t goal, newblock;
|
ext4_fsblk_t goal, newblock;
|
||||||
unsigned long count = 1;
|
|
||||||
|
|
||||||
goal = ext4_ext_find_goal(inode, path, le32_to_cpu(ex->ee_block));
|
goal = ext4_ext_find_goal(inode, path, le32_to_cpu(ex->ee_block));
|
||||||
newblock = ext4_new_meta_blocks(handle, inode, goal, &count, err);
|
newblock = ext4_new_meta_blocks(handle, inode, goal, NULL, err);
|
||||||
return newblock;
|
return newblock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -689,7 +689,6 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
|
||||||
struct ext4_xattr_info *i,
|
struct ext4_xattr_info *i,
|
||||||
struct ext4_xattr_block_find *bs)
|
struct ext4_xattr_block_find *bs)
|
||||||
{
|
{
|
||||||
unsigned long count = 1;
|
|
||||||
struct super_block *sb = inode->i_sb;
|
struct super_block *sb = inode->i_sb;
|
||||||
struct buffer_head *new_bh = NULL;
|
struct buffer_head *new_bh = NULL;
|
||||||
struct ext4_xattr_search *s = &bs->s;
|
struct ext4_xattr_search *s = &bs->s;
|
||||||
|
@ -812,7 +811,7 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
|
||||||
ext4_fsblk_t goal = ext4_group_first_block_no(sb,
|
ext4_fsblk_t goal = ext4_group_first_block_no(sb,
|
||||||
EXT4_I(inode)->i_block_group);
|
EXT4_I(inode)->i_block_group);
|
||||||
ext4_fsblk_t block = ext4_new_meta_blocks(handle, inode,
|
ext4_fsblk_t block = ext4_new_meta_blocks(handle, inode,
|
||||||
goal, &count, &error);
|
goal, NULL, &error);
|
||||||
if (error)
|
if (error)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
ea_idebug(inode, "creating block %d", block);
|
ea_idebug(inode, "creating block %d", block);
|
||||||
|
|
Loading…
Reference in New Issue