@@ -3346,21 +3346,18 @@ static struct ext4_ext_path *ext4_split_extent_at(handle_t *handle,
33463346 * c> Splits in three extents: Somone is splitting in middle of the extent
33473347 *
33483348 */
3349- static int ext4_split_extent (handle_t * handle ,
3350- struct inode * inode ,
3351- struct ext4_ext_path * * ppath ,
3352- struct ext4_map_blocks * map ,
3353- int split_flag ,
3354- int flags )
3349+ static struct ext4_ext_path * ext4_split_extent (handle_t * handle ,
3350+ struct inode * inode ,
3351+ struct ext4_ext_path * path ,
3352+ struct ext4_map_blocks * map ,
3353+ int split_flag , int flags ,
3354+ unsigned int * allocated )
33553355{
3356- struct ext4_ext_path * path = * ppath ;
33573356 ext4_lblk_t ee_block ;
33583357 struct ext4_extent * ex ;
33593358 unsigned int ee_len , depth ;
3360- int err = 0 ;
33613359 int unwritten ;
33623360 int split_flag1 , flags1 ;
3363- int allocated = map -> m_len ;
33643361
33653362 depth = ext_depth (inode );
33663363 ex = path [depth ].p_ext ;
@@ -3378,33 +3375,25 @@ static int ext4_split_extent(handle_t *handle,
33783375 split_flag1 |= EXT4_EXT_DATA_VALID1 ;
33793376 path = ext4_split_extent_at (handle , inode , path ,
33803377 map -> m_lblk + map -> m_len , split_flag1 , flags1 );
3381- if (IS_ERR (path )) {
3382- err = PTR_ERR (path );
3383- * ppath = NULL ;
3384- goto out ;
3378+ if (IS_ERR (path ))
3379+ return path ;
3380+ /*
3381+ * Update path is required because previous ext4_split_extent_at
3382+ * may result in split of original leaf or extent zeroout.
3383+ */
3384+ path = ext4_find_extent (inode , map -> m_lblk , path , flags );
3385+ if (IS_ERR (path ))
3386+ return path ;
3387+ depth = ext_depth (inode );
3388+ ex = path [depth ].p_ext ;
3389+ if (!ex ) {
3390+ EXT4_ERROR_INODE (inode , "unexpected hole at %lu" ,
3391+ (unsigned long ) map -> m_lblk );
3392+ ext4_free_ext_path (path );
3393+ return ERR_PTR (- EFSCORRUPTED );
33853394 }
3386- * ppath = path ;
3387- } else {
3388- allocated = ee_len - (map -> m_lblk - ee_block );
3389- }
3390- /*
3391- * Update path is required because previous ext4_split_extent_at() may
3392- * result in split of original leaf or extent zeroout.
3393- */
3394- path = ext4_find_extent (inode , map -> m_lblk , path , flags );
3395- if (IS_ERR (path )) {
3396- * ppath = NULL ;
3397- return PTR_ERR (path );
3398- }
3399- * ppath = path ;
3400- depth = ext_depth (inode );
3401- ex = path [depth ].p_ext ;
3402- if (!ex ) {
3403- EXT4_ERROR_INODE (inode , "unexpected hole at %lu" ,
3404- (unsigned long ) map -> m_lblk );
3405- return - EFSCORRUPTED ;
3395+ unwritten = ext4_ext_is_unwritten (ex );
34063396 }
3407- unwritten = ext4_ext_is_unwritten (ex );
34083397
34093398 if (map -> m_lblk >= ee_block ) {
34103399 split_flag1 = split_flag & EXT4_EXT_DATA_VALID2 ;
@@ -3415,17 +3404,18 @@ static int ext4_split_extent(handle_t *handle,
34153404 }
34163405 path = ext4_split_extent_at (handle , inode , path ,
34173406 map -> m_lblk , split_flag1 , flags );
3418- if (IS_ERR (path )) {
3419- err = PTR_ERR (path );
3420- * ppath = NULL ;
3421- goto out ;
3422- }
3423- * ppath = path ;
3407+ if (IS_ERR (path ))
3408+ return path ;
34243409 }
34253410
3411+ if (allocated ) {
3412+ if (map -> m_lblk + map -> m_len > ee_block + ee_len )
3413+ * allocated = ee_len - (map -> m_lblk - ee_block );
3414+ else
3415+ * allocated = map -> m_len ;
3416+ }
34263417 ext4_ext_show_leaf (inode , path );
3427- out :
3428- return err ? err : allocated ;
3418+ return path ;
34293419}
34303420
34313421/*
@@ -3670,10 +3660,15 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,
36703660 }
36713661
36723662fallback :
3673- err = ext4_split_extent (handle , inode , ppath , & split_map , split_flag ,
3674- flags );
3675- if (err > 0 )
3676- err = 0 ;
3663+ path = ext4_split_extent (handle , inode , path , & split_map , split_flag ,
3664+ flags , NULL );
3665+ if (IS_ERR (path )) {
3666+ err = PTR_ERR (path );
3667+ * ppath = NULL ;
3668+ goto out ;
3669+ }
3670+ err = 0 ;
3671+ * ppath = path ;
36773672out :
36783673 /* If we have gotten a failure, don't zero out status tree */
36793674 if (!err ) {
@@ -3719,6 +3714,7 @@ static int ext4_split_convert_extents(handle_t *handle,
37193714 struct ext4_extent * ex ;
37203715 unsigned int ee_len ;
37213716 int split_flag = 0 , depth ;
3717+ unsigned int allocated = 0 ;
37223718
37233719 ext_debug (inode , "logical block %llu, max_blocks %u\n" ,
37243720 (unsigned long long )map -> m_lblk , map -> m_len );
@@ -3746,7 +3742,14 @@ static int ext4_split_convert_extents(handle_t *handle,
37463742 split_flag |= (EXT4_EXT_MARK_UNWRIT2 | EXT4_EXT_DATA_VALID2 );
37473743 }
37483744 flags |= EXT4_GET_BLOCKS_PRE_IO ;
3749- return ext4_split_extent (handle , inode , ppath , map , split_flag , flags );
3745+ path = ext4_split_extent (handle , inode , path , map , split_flag , flags ,
3746+ & allocated );
3747+ if (IS_ERR (path )) {
3748+ * ppath = NULL ;
3749+ return PTR_ERR (path );
3750+ }
3751+ * ppath = path ;
3752+ return allocated ;
37503753}
37513754
37523755static int ext4_convert_unwritten_extents_endio (handle_t * handle ,
0 commit comments