Skip to content

Commit 1de82b1

Browse files
LiBaokun96tytso
authored andcommitted
ext4: get rid of ppath in ext4_split_extent_at()
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_split_extent_at(), the following is done here: * Free the extents path when an error is encountered. * Its caller needs to update ppath if it uses ppath. * Teach ext4_ext_show_leaf() to skip error pointer. 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 f7d1331 commit 1de82b1

File tree

1 file changed

+47
-38
lines changed

1 file changed

+47
-38
lines changed

fs/ext4/extents.c

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,11 @@ static void ext4_extent_block_csum_set(struct inode *inode,
8484
et->et_checksum = ext4_extent_block_csum(inode, eh);
8585
}
8686

87-
static int ext4_split_extent_at(handle_t *handle,
88-
struct inode *inode,
89-
struct ext4_ext_path **ppath,
90-
ext4_lblk_t split,
91-
int split_flag,
92-
int flags);
87+
static struct ext4_ext_path *ext4_split_extent_at(handle_t *handle,
88+
struct inode *inode,
89+
struct ext4_ext_path *path,
90+
ext4_lblk_t split,
91+
int split_flag, int flags);
9392

9493
static int ext4_ext_trunc_restart_fn(struct inode *inode, int *dropped)
9594
{
@@ -341,9 +340,15 @@ ext4_force_split_extent_at(handle_t *handle, struct inode *inode,
341340
if (nofail)
342341
flags |= EXT4_GET_BLOCKS_METADATA_NOFAIL | EXT4_EX_NOFAIL;
343342

344-
return ext4_split_extent_at(handle, inode, ppath, lblk, unwritten ?
343+
path = ext4_split_extent_at(handle, inode, path, lblk, unwritten ?
345344
EXT4_EXT_MARK_UNWRIT1|EXT4_EXT_MARK_UNWRIT2 : 0,
346345
flags);
346+
if (IS_ERR(path)) {
347+
*ppath = NULL;
348+
return PTR_ERR(path);
349+
}
350+
*ppath = path;
351+
return 0;
347352
}
348353

349354
static int
@@ -694,7 +699,7 @@ static void ext4_ext_show_leaf(struct inode *inode, struct ext4_ext_path *path)
694699
struct ext4_extent *ex;
695700
int i;
696701

697-
if (!path)
702+
if (IS_ERR_OR_NULL(path))
698703
return;
699704

700705
eh = path[depth].p_hdr;
@@ -3175,16 +3180,14 @@ static int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex)
31753180
* a> the extent are splitted into two extent.
31763181
* b> split is not needed, and just mark the extent.
31773182
*
3178-
* return 0 on success.
3183+
* Return an extent path pointer on success, or an error pointer on failure.
31793184
*/
3180-
static int ext4_split_extent_at(handle_t *handle,
3181-
struct inode *inode,
3182-
struct ext4_ext_path **ppath,
3183-
ext4_lblk_t split,
3184-
int split_flag,
3185-
int flags)
3185+
static struct ext4_ext_path *ext4_split_extent_at(handle_t *handle,
3186+
struct inode *inode,
3187+
struct ext4_ext_path *path,
3188+
ext4_lblk_t split,
3189+
int split_flag, int flags)
31863190
{
3187-
struct ext4_ext_path *path = *ppath;
31883191
ext4_fsblk_t newblock;
31893192
ext4_lblk_t ee_block;
31903193
struct ext4_extent *ex, newex, orig_ex, zero_ex;
@@ -3255,14 +3258,12 @@ static int ext4_split_extent_at(handle_t *handle,
32553258
ext4_ext_mark_unwritten(ex2);
32563259

32573260
path = ext4_ext_insert_extent(handle, inode, path, &newex, flags);
3258-
if (!IS_ERR(path)) {
3259-
*ppath = path;
3261+
if (!IS_ERR(path))
32603262
goto out;
3261-
}
3262-
*ppath = NULL;
3263+
32633264
err = PTR_ERR(path);
32643265
if (err != -ENOSPC && err != -EDQUOT && err != -ENOMEM)
3265-
return err;
3266+
return path;
32663267

32673268
/*
32683269
* Get a new path to try to zeroout or fix the extent length.
@@ -3272,16 +3273,14 @@ static int ext4_split_extent_at(handle_t *handle,
32723273
* in ext4_da_update_reserve_space() due to an incorrect
32733274
* ee_len causing the i_reserved_data_blocks exception.
32743275
*/
3275-
path = ext4_find_extent(inode, ee_block, NULL,
3276-
flags | EXT4_EX_NOFAIL);
3276+
path = ext4_find_extent(inode, ee_block, NULL, flags | EXT4_EX_NOFAIL);
32773277
if (IS_ERR(path)) {
32783278
EXT4_ERROR_INODE(inode, "Failed split extent on %u, err %ld",
32793279
split, PTR_ERR(path));
3280-
return PTR_ERR(path);
3280+
return path;
32813281
}
32823282
depth = ext_depth(inode);
32833283
ex = path[depth].p_ext;
3284-
*ppath = path;
32853284

32863285
if (EXT4_EXT_MAY_ZEROOUT & split_flag) {
32873286
if (split_flag & (EXT4_EXT_DATA_VALID1|EXT4_EXT_DATA_VALID2)) {
@@ -3333,10 +3332,13 @@ static int ext4_split_extent_at(handle_t *handle,
33333332
* and err is a non-zero error code.
33343333
*/
33353334
ext4_ext_dirty(handle, inode, path + path->p_depth);
3336-
return err;
33373335
out:
3336+
if (err) {
3337+
ext4_free_ext_path(path);
3338+
path = ERR_PTR(err);
3339+
}
33383340
ext4_ext_show_leaf(inode, path);
3339-
return err;
3341+
return path;
33403342
}
33413343

33423344
/*
@@ -3380,18 +3382,22 @@ static int ext4_split_extent(handle_t *handle,
33803382
EXT4_EXT_MARK_UNWRIT2;
33813383
if (split_flag & EXT4_EXT_DATA_VALID2)
33823384
split_flag1 |= EXT4_EXT_DATA_VALID1;
3383-
err = ext4_split_extent_at(handle, inode, ppath,
3385+
path = ext4_split_extent_at(handle, inode, path,
33843386
map->m_lblk + map->m_len, split_flag1, flags1);
3385-
if (err)
3387+
if (IS_ERR(path)) {
3388+
err = PTR_ERR(path);
3389+
*ppath = NULL;
33863390
goto out;
3391+
}
3392+
*ppath = path;
33873393
} else {
33883394
allocated = ee_len - (map->m_lblk - ee_block);
33893395
}
33903396
/*
33913397
* Update path is required because previous ext4_split_extent_at() may
33923398
* result in split of original leaf or extent zeroout.
33933399
*/
3394-
path = ext4_find_extent(inode, map->m_lblk, *ppath, flags);
3400+
path = ext4_find_extent(inode, map->m_lblk, path, flags);
33953401
if (IS_ERR(path)) {
33963402
*ppath = NULL;
33973403
return PTR_ERR(path);
@@ -3413,13 +3419,17 @@ static int ext4_split_extent(handle_t *handle,
34133419
split_flag1 |= split_flag & (EXT4_EXT_MAY_ZEROOUT |
34143420
EXT4_EXT_MARK_UNWRIT2);
34153421
}
3416-
err = ext4_split_extent_at(handle, inode, ppath,
3422+
path = ext4_split_extent_at(handle, inode, path,
34173423
map->m_lblk, split_flag1, flags);
3418-
if (err)
3424+
if (IS_ERR(path)) {
3425+
err = PTR_ERR(path);
3426+
*ppath = NULL;
34193427
goto out;
3428+
}
3429+
*ppath = path;
34203430
}
34213431

3422-
ext4_ext_show_leaf(inode, *ppath);
3432+
ext4_ext_show_leaf(inode, path);
34233433
out:
34243434
return err ? err : allocated;
34253435
}
@@ -5580,22 +5590,21 @@ static int ext4_insert_range(struct file *file, loff_t offset, loff_t len)
55805590
if (ext4_ext_is_unwritten(extent))
55815591
split_flag = EXT4_EXT_MARK_UNWRIT1 |
55825592
EXT4_EXT_MARK_UNWRIT2;
5583-
ret = ext4_split_extent_at(handle, inode, &path,
5593+
path = ext4_split_extent_at(handle, inode, path,
55845594
offset_lblk, split_flag,
55855595
EXT4_EX_NOCACHE |
55865596
EXT4_GET_BLOCKS_PRE_IO |
55875597
EXT4_GET_BLOCKS_METADATA_NOFAIL);
55885598
}
55895599

5590-
ext4_free_ext_path(path);
5591-
if (ret < 0) {
5600+
if (IS_ERR(path)) {
55925601
up_write(&EXT4_I(inode)->i_data_sem);
5602+
ret = PTR_ERR(path);
55935603
goto out_stop;
55945604
}
5595-
} else {
5596-
ext4_free_ext_path(path);
55975605
}
55985606

5607+
ext4_free_ext_path(path);
55995608
ext4_es_remove_extent(inode, offset_lblk, EXT_MAX_BLOCKS - offset_lblk);
56005609

56015610
/*

0 commit comments

Comments
 (0)