Skip to content

Commit 33c14b8

Browse files
LiBaokun96tytso
authored andcommitted
ext4: get rid of ppath in ext4_ext_convert_to_initialized()
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_convert_to_initialized(), the following is done here: * Free the extents path when an error is encountered. * Its caller needs to update ppath if it uses ppath. * 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 8d5ad7b commit 33c14b8

File tree

1 file changed

+35
-38
lines changed

1 file changed

+35
-38
lines changed

fs/ext4/extents.c

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3438,13 +3438,11 @@ static struct ext4_ext_path *ext4_split_extent(handle_t *handle,
34383438
* that are allocated and initialized.
34393439
* It is guaranteed to be >= map->m_len.
34403440
*/
3441-
static int ext4_ext_convert_to_initialized(handle_t *handle,
3442-
struct inode *inode,
3443-
struct ext4_map_blocks *map,
3444-
struct ext4_ext_path **ppath,
3445-
int flags)
3441+
static struct ext4_ext_path *
3442+
ext4_ext_convert_to_initialized(handle_t *handle, struct inode *inode,
3443+
struct ext4_map_blocks *map, struct ext4_ext_path *path,
3444+
int flags, unsigned int *allocated)
34463445
{
3447-
struct ext4_ext_path *path = *ppath;
34483446
struct ext4_sb_info *sbi;
34493447
struct ext4_extent_header *eh;
34503448
struct ext4_map_blocks split_map;
@@ -3454,7 +3452,6 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,
34543452
unsigned int ee_len, depth, map_len = map->m_len;
34553453
int err = 0;
34563454
int split_flag = EXT4_EXT_DATA_VALID2;
3457-
int allocated = 0;
34583455
unsigned int max_zeroout = 0;
34593456

34603457
ext_debug(inode, "logical block %llu, max_blocks %u\n",
@@ -3495,6 +3492,7 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,
34953492
* - L2: we only attempt to merge with an extent stored in the
34963493
* same extent tree node.
34973494
*/
3495+
*allocated = 0;
34983496
if ((map->m_lblk == ee_block) &&
34993497
/* See if we can merge left */
35003498
(map_len < ee_len) && /*L1*/
@@ -3524,7 +3522,7 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,
35243522
(prev_len < (EXT_INIT_MAX_LEN - map_len))) { /*C4*/
35253523
err = ext4_ext_get_access(handle, inode, path + depth);
35263524
if (err)
3527-
goto out;
3525+
goto errout;
35283526

35293527
trace_ext4_ext_convert_to_initialized_fastpath(inode,
35303528
map, ex, abut_ex);
@@ -3539,7 +3537,7 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,
35393537
abut_ex->ee_len = cpu_to_le16(prev_len + map_len);
35403538

35413539
/* Result: number of initialized blocks past m_lblk */
3542-
allocated = map_len;
3540+
*allocated = map_len;
35433541
}
35443542
} else if (((map->m_lblk + map_len) == (ee_block + ee_len)) &&
35453543
(map_len < ee_len) && /*L1*/
@@ -3570,7 +3568,7 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,
35703568
(next_len < (EXT_INIT_MAX_LEN - map_len))) { /*C4*/
35713569
err = ext4_ext_get_access(handle, inode, path + depth);
35723570
if (err)
3573-
goto out;
3571+
goto errout;
35743572

35753573
trace_ext4_ext_convert_to_initialized_fastpath(inode,
35763574
map, ex, abut_ex);
@@ -3585,18 +3583,20 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,
35853583
abut_ex->ee_len = cpu_to_le16(next_len + map_len);
35863584

35873585
/* Result: number of initialized blocks past m_lblk */
3588-
allocated = map_len;
3586+
*allocated = map_len;
35893587
}
35903588
}
3591-
if (allocated) {
3589+
if (*allocated) {
35923590
/* Mark the block containing both extents as dirty */
35933591
err = ext4_ext_dirty(handle, inode, path + depth);
35943592

35953593
/* Update path to point to the right extent */
35963594
path[depth].p_ext = abut_ex;
3595+
if (err)
3596+
goto errout;
35973597
goto out;
35983598
} else
3599-
allocated = ee_len - (map->m_lblk - ee_block);
3599+
*allocated = ee_len - (map->m_lblk - ee_block);
36003600

36013601
WARN_ON(map->m_lblk < ee_block);
36023602
/*
@@ -3623,21 +3623,21 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,
36233623
split_map.m_lblk = map->m_lblk;
36243624
split_map.m_len = map->m_len;
36253625

3626-
if (max_zeroout && (allocated > split_map.m_len)) {
3627-
if (allocated <= max_zeroout) {
3626+
if (max_zeroout && (*allocated > split_map.m_len)) {
3627+
if (*allocated <= max_zeroout) {
36283628
/* case 3 or 5 */
36293629
zero_ex1.ee_block =
36303630
cpu_to_le32(split_map.m_lblk +
36313631
split_map.m_len);
36323632
zero_ex1.ee_len =
3633-
cpu_to_le16(allocated - split_map.m_len);
3633+
cpu_to_le16(*allocated - split_map.m_len);
36343634
ext4_ext_store_pblock(&zero_ex1,
36353635
ext4_ext_pblock(ex) + split_map.m_lblk +
36363636
split_map.m_len - ee_block);
36373637
err = ext4_ext_zeroout(inode, &zero_ex1);
36383638
if (err)
36393639
goto fallback;
3640-
split_map.m_len = allocated;
3640+
split_map.m_len = *allocated;
36413641
}
36423642
if (split_map.m_lblk - ee_block + split_map.m_len <
36433643
max_zeroout) {
@@ -3655,27 +3655,24 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,
36553655

36563656
split_map.m_len += split_map.m_lblk - ee_block;
36573657
split_map.m_lblk = ee_block;
3658-
allocated = map->m_len;
3658+
*allocated = map->m_len;
36593659
}
36603660
}
36613661

36623662
fallback:
36633663
path = ext4_split_extent(handle, inode, path, &split_map, split_flag,
36643664
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;
3665+
if (IS_ERR(path))
3666+
return path;
36723667
out:
36733668
/* If we have gotten a failure, don't zero out status tree */
3674-
if (!err) {
3675-
ext4_zeroout_es(inode, &zero_ex1);
3676-
ext4_zeroout_es(inode, &zero_ex2);
3677-
}
3678-
return err ? err : allocated;
3669+
ext4_zeroout_es(inode, &zero_ex1);
3670+
ext4_zeroout_es(inode, &zero_ex2);
3671+
return path;
3672+
3673+
errout:
3674+
ext4_free_ext_path(path);
3675+
return ERR_PTR(err);
36793676
}
36803677

36813678
/*
@@ -3897,7 +3894,6 @@ ext4_ext_handle_unwritten_extents(handle_t *handle, struct inode *inode,
38973894
struct ext4_ext_path **ppath, int flags,
38983895
unsigned int allocated, ext4_fsblk_t newblock)
38993896
{
3900-
int ret = 0;
39013897
int err = 0;
39023898

39033899
ext_debug(inode, "logical block %llu, max_blocks %u, flags 0x%x, allocated %u\n",
@@ -3977,23 +3973,24 @@ ext4_ext_handle_unwritten_extents(handle_t *handle, struct inode *inode,
39773973
* For buffered writes, at writepage time, etc. Convert a
39783974
* discovered unwritten extent to written.
39793975
*/
3980-
ret = ext4_ext_convert_to_initialized(handle, inode, map, ppath, flags);
3981-
if (ret < 0) {
3982-
err = ret;
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;
39833981
goto out2;
39843982
}
39853983
ext4_update_inode_fsync_trans(handle, inode, 1);
39863984
/*
3987-
* shouldn't get a 0 return when converting an unwritten extent
3985+
* shouldn't get a 0 allocated when converting an unwritten extent
39883986
* unless m_len is 0 (bug) or extent has been corrupted
39893987
*/
3990-
if (unlikely(ret == 0)) {
3991-
EXT4_ERROR_INODE(inode, "unexpected ret == 0, m_len = %u",
3988+
if (unlikely(allocated == 0)) {
3989+
EXT4_ERROR_INODE(inode, "unexpected allocated == 0, m_len = %u",
39923990
map->m_len);
39933991
err = -EFSCORRUPTED;
39943992
goto out2;
39953993
}
3996-
allocated = ret;
39973994

39983995
out:
39993996
map->m_flags |= EXT4_MAP_NEW;

0 commit comments

Comments
 (0)