diff options
author | Theodore Ts'o <tytso@mit.edu> | 2014-09-01 14:35:09 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2014-09-01 14:35:09 -0400 |
commit | e8b83d9303317fb068ad83d87991b610fe990ed5 (patch) | |
tree | 5872e8a3ebb1126be98f722d55744d51f48b6a86 /fs/ext4 | |
parent | 705912ca95f4bbdbb3be753e46bf30d6be15a5e8 (diff) |
ext4: collapse ext4_convert_initialized_extents()
The function ext4_convert_initialized_extents() is only called by a
single function --- ext4_ext_convert_initalized_extents(). Inline the
code and get rid of the unnecessary bits in order to simplify the code.
Rename ext4_ext_convert_initalized_extents() to
convert_initalized_extents() since it's a static function that is
actually only used in a single caller, ext4_ext_map_blocks().
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'fs/ext4')
-rw-r--r-- | fs/ext4/extents.c | 136 |
1 files changed, 59 insertions, 77 deletions
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 0ced78c974e2..5fc5e2b6e3a7 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c | |||
@@ -3677,67 +3677,6 @@ static int ext4_split_convert_extents(handle_t *handle, | |||
3677 | return ext4_split_extent(handle, inode, path, map, split_flag, flags); | 3677 | return ext4_split_extent(handle, inode, path, map, split_flag, flags); |
3678 | } | 3678 | } |
3679 | 3679 | ||
3680 | static int ext4_convert_initialized_extents(handle_t *handle, | ||
3681 | struct inode *inode, | ||
3682 | struct ext4_map_blocks *map, | ||
3683 | struct ext4_ext_path *path) | ||
3684 | { | ||
3685 | struct ext4_extent *ex; | ||
3686 | ext4_lblk_t ee_block; | ||
3687 | unsigned int ee_len; | ||
3688 | int depth; | ||
3689 | int err = 0; | ||
3690 | |||
3691 | depth = ext_depth(inode); | ||
3692 | ex = path[depth].p_ext; | ||
3693 | ee_block = le32_to_cpu(ex->ee_block); | ||
3694 | ee_len = ext4_ext_get_actual_len(ex); | ||
3695 | |||
3696 | ext_debug("%s: inode %lu, logical" | ||
3697 | "block %llu, max_blocks %u\n", __func__, inode->i_ino, | ||
3698 | (unsigned long long)ee_block, ee_len); | ||
3699 | |||
3700 | if (ee_block != map->m_lblk || ee_len > map->m_len) { | ||
3701 | err = ext4_split_convert_extents(handle, inode, map, path, | ||
3702 | EXT4_GET_BLOCKS_CONVERT_UNWRITTEN); | ||
3703 | if (err < 0) | ||
3704 | goto out; | ||
3705 | ext4_ext_drop_refs(path); | ||
3706 | path = ext4_ext_find_extent(inode, map->m_lblk, &path, | ||
3707 | EXT4_EX_NOFREE_ON_ERR); | ||
3708 | if (IS_ERR(path)) { | ||
3709 | err = PTR_ERR(path); | ||
3710 | goto out; | ||
3711 | } | ||
3712 | depth = ext_depth(inode); | ||
3713 | ex = path[depth].p_ext; | ||
3714 | if (!ex) { | ||
3715 | EXT4_ERROR_INODE(inode, "unexpected hole at %lu", | ||
3716 | (unsigned long) map->m_lblk); | ||
3717 | err = -EIO; | ||
3718 | goto out; | ||
3719 | } | ||
3720 | } | ||
3721 | |||
3722 | err = ext4_ext_get_access(handle, inode, path + depth); | ||
3723 | if (err) | ||
3724 | goto out; | ||
3725 | /* first mark the extent as unwritten */ | ||
3726 | ext4_ext_mark_unwritten(ex); | ||
3727 | |||
3728 | /* note: ext4_ext_correct_indexes() isn't needed here because | ||
3729 | * borders are not changed | ||
3730 | */ | ||
3731 | ext4_ext_try_to_merge(handle, inode, path, ex); | ||
3732 | |||
3733 | /* Mark modified extent as dirty */ | ||
3734 | err = ext4_ext_dirty(handle, inode, path + path->p_depth); | ||
3735 | out: | ||
3736 | ext4_ext_show_leaf(inode, path); | ||
3737 | return err; | ||
3738 | } | ||
3739 | |||
3740 | |||
3741 | static int ext4_convert_unwritten_extents_endio(handle_t *handle, | 3680 | static int ext4_convert_unwritten_extents_endio(handle_t *handle, |
3742 | struct inode *inode, | 3681 | struct inode *inode, |
3743 | struct ext4_map_blocks *map, | 3682 | struct ext4_map_blocks *map, |
@@ -3974,12 +3913,15 @@ get_reserved_cluster_alloc(struct inode *inode, ext4_lblk_t lblk_start, | |||
3974 | } | 3913 | } |
3975 | 3914 | ||
3976 | static int | 3915 | static int |
3977 | ext4_ext_convert_initialized_extent(handle_t *handle, struct inode *inode, | 3916 | convert_initialized_extent(handle_t *handle, struct inode *inode, |
3978 | struct ext4_map_blocks *map, | 3917 | struct ext4_map_blocks *map, |
3979 | struct ext4_ext_path *path, int flags, | 3918 | struct ext4_ext_path *path, int flags, |
3980 | unsigned int allocated, ext4_fsblk_t newblock) | 3919 | unsigned int allocated, ext4_fsblk_t newblock) |
3981 | { | 3920 | { |
3982 | int ret = 0; | 3921 | struct ext4_extent *ex; |
3922 | ext4_lblk_t ee_block; | ||
3923 | unsigned int ee_len; | ||
3924 | int depth; | ||
3983 | int err = 0; | 3925 | int err = 0; |
3984 | 3926 | ||
3985 | /* | 3927 | /* |
@@ -3989,20 +3931,60 @@ ext4_ext_convert_initialized_extent(handle_t *handle, struct inode *inode, | |||
3989 | if (map->m_len > EXT_UNWRITTEN_MAX_LEN) | 3931 | if (map->m_len > EXT_UNWRITTEN_MAX_LEN) |
3990 | map->m_len = EXT_UNWRITTEN_MAX_LEN / 2; | 3932 | map->m_len = EXT_UNWRITTEN_MAX_LEN / 2; |
3991 | 3933 | ||
3992 | ret = ext4_convert_initialized_extents(handle, inode, map, | 3934 | depth = ext_depth(inode); |
3993 | path); | 3935 | ex = path[depth].p_ext; |
3994 | if (ret >= 0) { | 3936 | ee_block = le32_to_cpu(ex->ee_block); |
3995 | ext4_update_inode_fsync_trans(handle, inode, 1); | 3937 | ee_len = ext4_ext_get_actual_len(ex); |
3996 | err = check_eofblocks_fl(handle, inode, map->m_lblk, | 3938 | |
3997 | path, map->m_len); | 3939 | ext_debug("%s: inode %lu, logical" |
3998 | } else | 3940 | "block %llu, max_blocks %u\n", __func__, inode->i_ino, |
3999 | err = ret; | 3941 | (unsigned long long)ee_block, ee_len); |
3942 | |||
3943 | if (ee_block != map->m_lblk || ee_len > map->m_len) { | ||
3944 | err = ext4_split_convert_extents(handle, inode, map, path, | ||
3945 | EXT4_GET_BLOCKS_CONVERT_UNWRITTEN); | ||
3946 | if (err < 0) | ||
3947 | return err; | ||
3948 | ext4_ext_drop_refs(path); | ||
3949 | path = ext4_ext_find_extent(inode, map->m_lblk, &path, | ||
3950 | EXT4_EX_NOFREE_ON_ERR); | ||
3951 | if (IS_ERR(path)) | ||
3952 | return PTR_ERR(path); | ||
3953 | depth = ext_depth(inode); | ||
3954 | ex = path[depth].p_ext; | ||
3955 | if (!ex) { | ||
3956 | EXT4_ERROR_INODE(inode, "unexpected hole at %lu", | ||
3957 | (unsigned long) map->m_lblk); | ||
3958 | return -EIO; | ||
3959 | } | ||
3960 | } | ||
3961 | |||
3962 | err = ext4_ext_get_access(handle, inode, path + depth); | ||
3963 | if (err) | ||
3964 | return err; | ||
3965 | /* first mark the extent as unwritten */ | ||
3966 | ext4_ext_mark_unwritten(ex); | ||
3967 | |||
3968 | /* note: ext4_ext_correct_indexes() isn't needed here because | ||
3969 | * borders are not changed | ||
3970 | */ | ||
3971 | ext4_ext_try_to_merge(handle, inode, path, ex); | ||
3972 | |||
3973 | /* Mark modified extent as dirty */ | ||
3974 | err = ext4_ext_dirty(handle, inode, path + path->p_depth); | ||
3975 | if (err) | ||
3976 | return err; | ||
3977 | ext4_ext_show_leaf(inode, path); | ||
3978 | |||
3979 | ext4_update_inode_fsync_trans(handle, inode, 1); | ||
3980 | err = check_eofblocks_fl(handle, inode, map->m_lblk, path, map->m_len); | ||
3981 | if (err) | ||
3982 | return err; | ||
4000 | map->m_flags |= EXT4_MAP_UNWRITTEN; | 3983 | map->m_flags |= EXT4_MAP_UNWRITTEN; |
4001 | if (allocated > map->m_len) | 3984 | if (allocated > map->m_len) |
4002 | allocated = map->m_len; | 3985 | allocated = map->m_len; |
4003 | map->m_len = allocated; | 3986 | map->m_len = allocated; |
4004 | 3987 | return allocated; | |
4005 | return err ? err : allocated; | ||
4006 | } | 3988 | } |
4007 | 3989 | ||
4008 | static int | 3990 | static int |
@@ -4342,7 +4324,7 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, | |||
4342 | */ | 4324 | */ |
4343 | if ((!ext4_ext_is_unwritten(ex)) && | 4325 | if ((!ext4_ext_is_unwritten(ex)) && |
4344 | (flags & EXT4_GET_BLOCKS_CONVERT_UNWRITTEN)) { | 4326 | (flags & EXT4_GET_BLOCKS_CONVERT_UNWRITTEN)) { |
4345 | allocated = ext4_ext_convert_initialized_extent( | 4327 | allocated = convert_initialized_extent( |
4346 | handle, inode, map, path, flags, | 4328 | handle, inode, map, path, flags, |
4347 | allocated, newblock); | 4329 | allocated, newblock); |
4348 | goto out2; | 4330 | goto out2; |