ext4: reuse path object in ext4_ext_shift_extents()
Now that the semantics of ext4_ext_find_extent() are much cleaner, it's safe and more efficient to reuse the path object across the multiple calls to ext4_ext_find_extent() in ext4_ext_shift_extents(). Signed-off-by: Theodore Ts'o <tytso@mit.edu>
This commit is contained in:
parent
10809df84a
commit
ee4bd0d963
1 changed files with 8 additions and 17 deletions
|
@ -5306,26 +5306,21 @@ ext4_ext_shift_extents(struct inode *inode, handle_t *handle,
|
||||||
|
|
||||||
depth = path->p_depth;
|
depth = path->p_depth;
|
||||||
extent = path[depth].p_ext;
|
extent = path[depth].p_ext;
|
||||||
if (!extent) {
|
if (!extent)
|
||||||
ext4_ext_drop_refs(path);
|
goto out;
|
||||||
kfree(path);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
stop_block = le32_to_cpu(extent->ee_block) +
|
stop_block = le32_to_cpu(extent->ee_block) +
|
||||||
ext4_ext_get_actual_len(extent);
|
ext4_ext_get_actual_len(extent);
|
||||||
ext4_ext_drop_refs(path);
|
|
||||||
kfree(path);
|
|
||||||
|
|
||||||
/* Nothing to shift, if hole is at the end of file */
|
/* Nothing to shift, if hole is at the end of file */
|
||||||
if (start >= stop_block)
|
if (start >= stop_block)
|
||||||
return ret;
|
goto out;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Don't start shifting extents until we make sure the hole is big
|
* Don't start shifting extents until we make sure the hole is big
|
||||||
* enough to accomodate the shift.
|
* enough to accomodate the shift.
|
||||||
*/
|
*/
|
||||||
path = ext4_ext_find_extent(inode, start - 1, NULL, 0);
|
path = ext4_ext_find_extent(inode, start - 1, &path, 0);
|
||||||
if (IS_ERR(path))
|
if (IS_ERR(path))
|
||||||
return PTR_ERR(path);
|
return PTR_ERR(path);
|
||||||
depth = path->p_depth;
|
depth = path->p_depth;
|
||||||
|
@ -5338,8 +5333,6 @@ ext4_ext_shift_extents(struct inode *inode, handle_t *handle,
|
||||||
ex_start = 0;
|
ex_start = 0;
|
||||||
ex_end = 0;
|
ex_end = 0;
|
||||||
}
|
}
|
||||||
ext4_ext_drop_refs(path);
|
|
||||||
kfree(path);
|
|
||||||
|
|
||||||
if ((start == ex_start && shift > ex_start) ||
|
if ((start == ex_start && shift > ex_start) ||
|
||||||
(shift > start - ex_end))
|
(shift > start - ex_end))
|
||||||
|
@ -5347,7 +5340,7 @@ ext4_ext_shift_extents(struct inode *inode, handle_t *handle,
|
||||||
|
|
||||||
/* Its safe to start updating extents */
|
/* Its safe to start updating extents */
|
||||||
while (start < stop_block) {
|
while (start < stop_block) {
|
||||||
path = ext4_ext_find_extent(inode, start, NULL, 0);
|
path = ext4_ext_find_extent(inode, start, &path, 0);
|
||||||
if (IS_ERR(path))
|
if (IS_ERR(path))
|
||||||
return PTR_ERR(path);
|
return PTR_ERR(path);
|
||||||
depth = path->p_depth;
|
depth = path->p_depth;
|
||||||
|
@ -5363,19 +5356,17 @@ ext4_ext_shift_extents(struct inode *inode, handle_t *handle,
|
||||||
path[depth].p_ext++;
|
path[depth].p_ext++;
|
||||||
} else {
|
} else {
|
||||||
start = ext4_ext_next_allocated_block(path);
|
start = ext4_ext_next_allocated_block(path);
|
||||||
ext4_ext_drop_refs(path);
|
|
||||||
kfree(path);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret = ext4_ext_shift_path_extents(path, shift, inode,
|
ret = ext4_ext_shift_path_extents(path, shift, inode,
|
||||||
handle, &start);
|
handle, &start);
|
||||||
ext4_ext_drop_refs(path);
|
|
||||||
kfree(path);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
out:
|
||||||
|
ext4_ext_drop_refs(path);
|
||||||
|
kfree(path);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue