Skip to content

Commit 2ec2e10

Browse files
LiBaokun96tytso
authored andcommitted
ext4: get rid of ppath in ext4_ext_handle_unwritten_extents()
The use of path and ppath is now very confusing, so to make the code more readable, pass path between functions uniformly, and get rid of ppath. To get rid of the ppath in ext4_ext_handle_unwritten_extents(), the following is done here: * Free the extents path when an error is encountered. * The 'allocated' is changed from passing a value to passing an address. No functional changes. Signed-off-by: Baokun Li <[email protected]> Reviewed-by: Jan Kara <[email protected]> Reviewed-by: Ojaswin Mujoo <[email protected]> Tested-by: Ojaswin Mujoo <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 33c14b8 commit 2ec2e10

File tree

1 file changed

+37
-45
lines changed

1 file changed

+37
-45
lines changed

fs/ext4/extents.c

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3888,18 +3888,18 @@ convert_initialized_extent(handle_t *handle, struct inode *inode,
38883888
return 0;
38893889
}
38903890

3891-
static int
3891+
static struct ext4_ext_path *
38923892
ext4_ext_handle_unwritten_extents(handle_t *handle, struct inode *inode,
38933893
struct ext4_map_blocks *map,
3894-
struct ext4_ext_path **ppath, int flags,
3895-
unsigned int allocated, ext4_fsblk_t newblock)
3894+
struct ext4_ext_path *path, int flags,
3895+
unsigned int *allocated, ext4_fsblk_t newblock)
38963896
{
38973897
int err = 0;
38983898

38993899
ext_debug(inode, "logical block %llu, max_blocks %u, flags 0x%x, allocated %u\n",
39003900
(unsigned long long)map->m_lblk, map->m_len, flags,
3901-
allocated);
3902-
ext4_ext_show_leaf(inode, *ppath);
3901+
*allocated);
3902+
ext4_ext_show_leaf(inode, path);
39033903

39043904
/*
39053905
* When writing into unwritten space, we should not fail to
@@ -3908,40 +3908,34 @@ ext4_ext_handle_unwritten_extents(handle_t *handle, struct inode *inode,
39083908
flags |= EXT4_GET_BLOCKS_METADATA_NOFAIL;
39093909

39103910
trace_ext4_ext_handle_unwritten_extents(inode, map, flags,
3911-
allocated, newblock);
3911+
*allocated, newblock);
39123912

39133913
/* get_block() before submitting IO, split the extent */
39143914
if (flags & EXT4_GET_BLOCKS_PRE_IO) {
3915-
*ppath = ext4_split_convert_extents(handle, inode, map, *ppath,
3916-
flags | EXT4_GET_BLOCKS_CONVERT, &allocated);
3917-
if (IS_ERR(*ppath)) {
3918-
err = PTR_ERR(*ppath);
3919-
*ppath = NULL;
3920-
goto out2;
3921-
}
3915+
path = ext4_split_convert_extents(handle, inode, map, path,
3916+
flags | EXT4_GET_BLOCKS_CONVERT, allocated);
3917+
if (IS_ERR(path))
3918+
return path;
39223919
/*
39233920
* shouldn't get a 0 allocated when splitting an extent unless
39243921
* m_len is 0 (bug) or extent has been corrupted
39253922
*/
3926-
if (unlikely(allocated == 0)) {
3923+
if (unlikely(*allocated == 0)) {
39273924
EXT4_ERROR_INODE(inode,
39283925
"unexpected allocated == 0, m_len = %u",
39293926
map->m_len);
39303927
err = -EFSCORRUPTED;
3931-
goto out2;
3928+
goto errout;
39323929
}
39333930
map->m_flags |= EXT4_MAP_UNWRITTEN;
39343931
goto out;
39353932
}
39363933
/* IO end_io complete, convert the filled extent to written */
39373934
if (flags & EXT4_GET_BLOCKS_CONVERT) {
3938-
*ppath = ext4_convert_unwritten_extents_endio(handle, inode,
3939-
map, *ppath);
3940-
if (IS_ERR(*ppath)) {
3941-
err = PTR_ERR(*ppath);
3942-
*ppath = NULL;
3943-
goto out2;
3944-
}
3935+
path = ext4_convert_unwritten_extents_endio(handle, inode,
3936+
map, path);
3937+
if (IS_ERR(path))
3938+
return path;
39453939
ext4_update_inode_fsync_trans(handle, inode, 1);
39463940
goto map_out;
39473941
}
@@ -3973,23 +3967,20 @@ ext4_ext_handle_unwritten_extents(handle_t *handle, struct inode *inode,
39733967
* For buffered writes, at writepage time, etc. Convert a
39743968
* discovered unwritten extent to written.
39753969
*/
3976-
*ppath = ext4_ext_convert_to_initialized(handle, inode, map, *ppath,
3977-
flags, &allocated);
3978-
if (IS_ERR(*ppath)) {
3979-
err = PTR_ERR(*ppath);
3980-
*ppath = NULL;
3981-
goto out2;
3982-
}
3970+
path = ext4_ext_convert_to_initialized(handle, inode, map, path,
3971+
flags, allocated);
3972+
if (IS_ERR(path))
3973+
return path;
39833974
ext4_update_inode_fsync_trans(handle, inode, 1);
39843975
/*
39853976
* shouldn't get a 0 allocated when converting an unwritten extent
39863977
* unless m_len is 0 (bug) or extent has been corrupted
39873978
*/
3988-
if (unlikely(allocated == 0)) {
3979+
if (unlikely(*allocated == 0)) {
39893980
EXT4_ERROR_INODE(inode, "unexpected allocated == 0, m_len = %u",
39903981
map->m_len);
39913982
err = -EFSCORRUPTED;
3992-
goto out2;
3983+
goto errout;
39933984
}
39943985

39953986
out:
@@ -3998,12 +3989,15 @@ ext4_ext_handle_unwritten_extents(handle_t *handle, struct inode *inode,
39983989
map->m_flags |= EXT4_MAP_MAPPED;
39993990
out1:
40003991
map->m_pblk = newblock;
4001-
if (allocated > map->m_len)
4002-
allocated = map->m_len;
4003-
map->m_len = allocated;
4004-
ext4_ext_show_leaf(inode, *ppath);
4005-
out2:
4006-
return err ? err : allocated;
3992+
if (*allocated > map->m_len)
3993+
*allocated = map->m_len;
3994+
map->m_len = *allocated;
3995+
ext4_ext_show_leaf(inode, path);
3996+
return path;
3997+
3998+
errout:
3999+
ext4_free_ext_path(path);
4000+
return ERR_PTR(err);
40074001
}
40084002

40094003
/*
@@ -4201,7 +4195,7 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,
42014195
struct ext4_extent newex, *ex, ex2;
42024196
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
42034197
ext4_fsblk_t newblock = 0, pblk;
4204-
int err = 0, depth, ret;
4198+
int err = 0, depth;
42054199
unsigned int allocated = 0, offset = 0;
42064200
unsigned int allocated_clusters = 0;
42074201
struct ext4_allocation_request ar;
@@ -4275,13 +4269,11 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,
42754269
goto out;
42764270
}
42774271

4278-
ret = ext4_ext_handle_unwritten_extents(
4279-
handle, inode, map, &path, flags,
4280-
allocated, newblock);
4281-
if (ret < 0)
4282-
err = ret;
4283-
else
4284-
allocated = ret;
4272+
path = ext4_ext_handle_unwritten_extents(
4273+
handle, inode, map, path, flags,
4274+
&allocated, newblock);
4275+
if (IS_ERR(path))
4276+
err = PTR_ERR(path);
42854277
goto out;
42864278
}
42874279
}

0 commit comments

Comments
 (0)