Commit 0756b908 authored by Eric Whitney's avatar Eric Whitney Committed by Theodore Ts'o

ext4: fix end of region partial cluster handling

ext4_ext_remove_space() can incorrectly free a partial_cluster if
EAGAIN is encountered while truncating or punching.  Extent removal
should be retried in this case.

It also fails to free a partial cluster when the punched region begins
at the start of a file on that unaligned cluster and where the entire
file has not been punched.  Remove the requirement that all blocks in
the file must have been freed in order to free the partial cluster.
Signed-off-by: default avatarEric Whitney <enwlinux@gmail.com>
Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent 345ee947
...@@ -3009,16 +3009,18 @@ int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start, ...@@ -3009,16 +3009,18 @@ int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start,
trace_ext4_ext_remove_space_done(inode, start, end, depth, trace_ext4_ext_remove_space_done(inode, start, end, depth,
partial_cluster, path->p_hdr->eh_entries); partial_cluster, path->p_hdr->eh_entries);
/* If we still have something in the partial cluster and we have removed /*
* If we still have something in the partial cluster and we have removed
* even the first extent, then we should free the blocks in the partial * even the first extent, then we should free the blocks in the partial
* cluster as well. */ * cluster as well. (This code will only run when there are no leaves
if (partial_cluster > 0 && path->p_hdr->eh_entries == 0) { * to the immediate left of the truncated/punched region.)
int flags = get_default_free_blocks_flags(inode); */
if (partial_cluster > 0 && err == 0) {
/* don't zero partial_cluster since it's not used afterwards */
ext4_free_blocks(handle, inode, NULL, ext4_free_blocks(handle, inode, NULL,
EXT4_C2B(sbi, partial_cluster), EXT4_C2B(sbi, partial_cluster),
sbi->s_cluster_ratio, flags); sbi->s_cluster_ratio,
partial_cluster = 0; get_default_free_blocks_flags(inode));
} }
/* TODO: flexible tree reduction should be here */ /* TODO: flexible tree reduction should be here */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment