summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBaokun Li <libaokun1@huawei.com>2024-08-22 10:35:33 +0800
committerTheodore Ts'o <tytso@mit.edu>2024-09-03 22:12:17 -0400
commita000bc8678cc2bb10a5b80b4e991e77c7b4612fd (patch)
treede3e6a7ebb6269bd529d8713e127d9048f094f38
parent6b854d552711aa33f59eda334e6d94a00d8825bb (diff)
downloadlinux-a000bc8678cc2bb10a5b80b4e991e77c7b4612fd.tar.gz
linux-a000bc8678cc2bb10a5b80b4e991e77c7b4612fd.tar.bz2
linux-a000bc8678cc2bb10a5b80b4e991e77c7b4612fd.zip
ext4: get rid of ppath in ext4_ext_create_new_leaf()
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_create_new_leaf(), the following is done here: * Free the extents path when an error is encountered. * Its caller needs to update ppath if it uses ppath. No functional changes. Signed-off-by: Baokun Li <libaokun1@huawei.com> Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com> Tested-by: Ojaswin Mujoo <ojaswin@linux.ibm.com> Link: https://patch.msgid.link/20240822023545.1994557-14-libaokun@huaweicloud.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r--fs/ext4/extents.c43
1 files changed, 22 insertions, 21 deletions
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 575e674219a8..8610a22f4f5a 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -1397,13 +1397,12 @@ out:
* finds empty index and adds new leaf.
* if no free index is found, then it requests in-depth growing.
*/
-static int ext4_ext_create_new_leaf(handle_t *handle, struct inode *inode,
- unsigned int mb_flags,
- unsigned int gb_flags,
- struct ext4_ext_path **ppath,
- struct ext4_extent *newext)
+static struct ext4_ext_path *
+ext4_ext_create_new_leaf(handle_t *handle, struct inode *inode,
+ unsigned int mb_flags, unsigned int gb_flags,
+ struct ext4_ext_path *path,
+ struct ext4_extent *newext)
{
- struct ext4_ext_path *path = *ppath;
struct ext4_ext_path *curp;
int depth, i, err = 0;
@@ -1424,28 +1423,25 @@ repeat:
* entry: create all needed subtree and add new leaf */
err = ext4_ext_split(handle, inode, mb_flags, path, newext, i);
if (err)
- goto out;
+ goto errout;
/* refill path */
path = ext4_find_extent(inode,
(ext4_lblk_t)le32_to_cpu(newext->ee_block),
path, gb_flags);
- if (IS_ERR(path))
- err = PTR_ERR(path);
+ return path;
} else {
/* tree is full, time to grow in depth */
err = ext4_ext_grow_indepth(handle, inode, mb_flags);
if (err)
- goto out;
+ goto errout;
/* refill path */
path = ext4_find_extent(inode,
(ext4_lblk_t)le32_to_cpu(newext->ee_block),
path, gb_flags);
- if (IS_ERR(path)) {
- err = PTR_ERR(path);
- goto out;
- }
+ if (IS_ERR(path))
+ return path;
/*
* only first (depth 0 -> 1) produces free space;
@@ -1457,9 +1453,11 @@ repeat:
goto repeat;
}
}
-out:
- *ppath = IS_ERR(path) ? NULL : path;
- return err;
+ return path;
+
+errout:
+ ext4_free_ext_path(path);
+ return ERR_PTR(err);
}
/*
@@ -2112,11 +2110,14 @@ prepend:
*/
if (gb_flags & EXT4_GET_BLOCKS_METADATA_NOFAIL)
mb_flags |= EXT4_MB_USE_RESERVED;
- err = ext4_ext_create_new_leaf(handle, inode, mb_flags, gb_flags,
- ppath, newext);
- if (err)
+ path = ext4_ext_create_new_leaf(handle, inode, mb_flags, gb_flags,
+ path, newext);
+ if (IS_ERR(path)) {
+ *ppath = NULL;
+ err = PTR_ERR(path);
goto cleanup;
- path = *ppath;
+ }
+ *ppath = path;
depth = ext_depth(inode);
eh = path[depth].p_hdr;