|
@@ -855,11 +855,13 @@ int ext4_ext_tree_init(handle_t *handle, struct inode *inode)
|
|
|
|
|
|
struct ext4_ext_path *
|
|
struct ext4_ext_path *
|
|
ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block,
|
|
ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block,
|
|
- struct ext4_ext_path *path, int flags)
|
|
|
|
|
|
+ struct ext4_ext_path **orig_path, int flags)
|
|
{
|
|
{
|
|
struct ext4_extent_header *eh;
|
|
struct ext4_extent_header *eh;
|
|
struct buffer_head *bh;
|
|
struct buffer_head *bh;
|
|
- short int depth, i, ppos = 0, alloc = 0;
|
|
|
|
|
|
+ struct ext4_ext_path *path = orig_path ? *orig_path : NULL;
|
|
|
|
+ short int depth, i, ppos = 0;
|
|
|
|
+ short free_on_err = (flags & EXT4_EX_NOFREE_ON_ERR) == 0;
|
|
int ret;
|
|
int ret;
|
|
|
|
|
|
eh = ext_inode_hdr(inode);
|
|
eh = ext_inode_hdr(inode);
|
|
@@ -871,7 +873,7 @@ ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block,
|
|
GFP_NOFS);
|
|
GFP_NOFS);
|
|
if (unlikely(!path))
|
|
if (unlikely(!path))
|
|
return ERR_PTR(-ENOMEM);
|
|
return ERR_PTR(-ENOMEM);
|
|
- alloc = 1;
|
|
|
|
|
|
+ free_on_err = 1;
|
|
}
|
|
}
|
|
path[0].p_hdr = eh;
|
|
path[0].p_hdr = eh;
|
|
path[0].p_bh = NULL;
|
|
path[0].p_bh = NULL;
|
|
@@ -923,8 +925,11 @@ ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block,
|
|
|
|
|
|
err:
|
|
err:
|
|
ext4_ext_drop_refs(path);
|
|
ext4_ext_drop_refs(path);
|
|
- if (alloc)
|
|
|
|
|
|
+ if (free_on_err) {
|
|
kfree(path);
|
|
kfree(path);
|
|
|
|
+ if (orig_path)
|
|
|
|
+ *orig_path = NULL;
|
|
|
|
+ }
|
|
return ERR_PTR(ret);
|
|
return ERR_PTR(ret);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1356,7 +1361,7 @@ repeat:
|
|
ext4_ext_drop_refs(path);
|
|
ext4_ext_drop_refs(path);
|
|
path = ext4_ext_find_extent(inode,
|
|
path = ext4_ext_find_extent(inode,
|
|
(ext4_lblk_t)le32_to_cpu(newext->ee_block),
|
|
(ext4_lblk_t)le32_to_cpu(newext->ee_block),
|
|
- path, gb_flags);
|
|
|
|
|
|
+ &path, gb_flags | EXT4_EX_NOFREE_ON_ERR);
|
|
if (IS_ERR(path))
|
|
if (IS_ERR(path))
|
|
err = PTR_ERR(path);
|
|
err = PTR_ERR(path);
|
|
} else {
|
|
} else {
|
|
@@ -1369,7 +1374,7 @@ repeat:
|
|
ext4_ext_drop_refs(path);
|
|
ext4_ext_drop_refs(path);
|
|
path = ext4_ext_find_extent(inode,
|
|
path = ext4_ext_find_extent(inode,
|
|
(ext4_lblk_t)le32_to_cpu(newext->ee_block),
|
|
(ext4_lblk_t)le32_to_cpu(newext->ee_block),
|
|
- path, gb_flags);
|
|
|
|
|
|
+ &path, gb_flags | EXT4_EX_NOFREE_ON_ERR);
|
|
if (IS_ERR(path)) {
|
|
if (IS_ERR(path)) {
|
|
err = PTR_ERR(path);
|
|
err = PTR_ERR(path);
|
|
goto out;
|
|
goto out;
|
|
@@ -2152,7 +2157,7 @@ static int ext4_fill_fiemap_extents(struct inode *inode,
|
|
path = NULL;
|
|
path = NULL;
|
|
}
|
|
}
|
|
|
|
|
|
- path = ext4_ext_find_extent(inode, block, path, 0);
|
|
|
|
|
|
+ path = ext4_ext_find_extent(inode, block, &path, 0);
|
|
if (IS_ERR(path)) {
|
|
if (IS_ERR(path)) {
|
|
up_read(&EXT4_I(inode)->i_data_sem);
|
|
up_read(&EXT4_I(inode)->i_data_sem);
|
|
err = PTR_ERR(path);
|
|
err = PTR_ERR(path);
|
|
@@ -3313,7 +3318,8 @@ static int ext4_split_extent(handle_t *handle,
|
|
* result in split of original leaf or extent zeroout.
|
|
* result in split of original leaf or extent zeroout.
|
|
*/
|
|
*/
|
|
ext4_ext_drop_refs(path);
|
|
ext4_ext_drop_refs(path);
|
|
- path = ext4_ext_find_extent(inode, map->m_lblk, path, 0);
|
|
|
|
|
|
+ path = ext4_ext_find_extent(inode, map->m_lblk, &path,
|
|
|
|
+ EXT4_EX_NOFREE_ON_ERR);
|
|
if (IS_ERR(path))
|
|
if (IS_ERR(path))
|
|
return PTR_ERR(path);
|
|
return PTR_ERR(path);
|
|
depth = ext_depth(inode);
|
|
depth = ext_depth(inode);
|
|
@@ -3697,7 +3703,8 @@ static int ext4_convert_initialized_extents(handle_t *handle,
|
|
if (err < 0)
|
|
if (err < 0)
|
|
goto out;
|
|
goto out;
|
|
ext4_ext_drop_refs(path);
|
|
ext4_ext_drop_refs(path);
|
|
- path = ext4_ext_find_extent(inode, map->m_lblk, path, 0);
|
|
|
|
|
|
+ path = ext4_ext_find_extent(inode, map->m_lblk, &path,
|
|
|
|
+ EXT4_EX_NOFREE_ON_ERR);
|
|
if (IS_ERR(path)) {
|
|
if (IS_ERR(path)) {
|
|
err = PTR_ERR(path);
|
|
err = PTR_ERR(path);
|
|
goto out;
|
|
goto out;
|
|
@@ -3769,7 +3776,8 @@ static int ext4_convert_unwritten_extents_endio(handle_t *handle,
|
|
if (err < 0)
|
|
if (err < 0)
|
|
goto out;
|
|
goto out;
|
|
ext4_ext_drop_refs(path);
|
|
ext4_ext_drop_refs(path);
|
|
- path = ext4_ext_find_extent(inode, map->m_lblk, path, 0);
|
|
|
|
|
|
+ path = ext4_ext_find_extent(inode, map->m_lblk, &path,
|
|
|
|
+ EXT4_EX_NOFREE_ON_ERR);
|
|
if (IS_ERR(path)) {
|
|
if (IS_ERR(path)) {
|
|
err = PTR_ERR(path);
|
|
err = PTR_ERR(path);
|
|
goto out;
|
|
goto out;
|