Update crypto patches
[ext4-patch-queue.git] / fix-end-of-region-partial-cluster-handling
blobb3b8f9e3ba735816eb5fb76d1e78905efa2f0369
1 ext4: fix end of region partial cluster handling
3 From: Eric Whitney <enwlinux@gmail.com>
5 ext4_ext_remove_space() can incorrectly free a partial_cluster if
6 EAGAIN is encountered while truncating or punching.  Extent removal
7 should be retried in this case.
9 It also fails to free a partial cluster when the punched region begins
10 at the start of a file on that unaligned cluster and where the entire
11 file has not been punched.  Remove the requirement that all blocks in
12 the file must have been freed in order to free the partial cluster.
14 Signed-off-by: Eric Whitney <enwlinux@gmail.com>
15 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
16 ---
17  fs/ext4/extents.c | 16 +++++++++-------
18  1 file changed, 9 insertions(+), 7 deletions(-)
20 diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
21 index 841adf0..9eae2f4 100644
22 --- a/fs/ext4/extents.c
23 +++ b/fs/ext4/extents.c
24 @@ -3009,16 +3009,18 @@ again:
25         trace_ext4_ext_remove_space_done(inode, start, end, depth,
26                         partial_cluster, path->p_hdr->eh_entries);
28 -       /* If we still have something in the partial cluster and we have removed
29 +       /*
30 +        * If we still have something in the partial cluster and we have removed
31          * even the first extent, then we should free the blocks in the partial
32 -        * cluster as well. */
33 -       if (partial_cluster > 0 && path->p_hdr->eh_entries == 0) {
34 -               int flags = get_default_free_blocks_flags(inode);
36 +        * cluster as well.  (This code will only run when there are no leaves
37 +        * to the immediate left of the truncated/punched region.)
38 +        */
39 +       if (partial_cluster > 0 && err == 0) {
40 +               /* don't zero partial_cluster since it's not used afterwards */
41                 ext4_free_blocks(handle, inode, NULL,
42                                  EXT4_C2B(sbi, partial_cluster),
43 -                                sbi->s_cluster_ratio, flags);
44 -               partial_cluster = 0;
45 +                                sbi->s_cluster_ratio,
46 +                                get_default_free_blocks_flags(inode));
47         }
49         /* TODO: flexible tree reduction should be here */
50 -- 
51 1.9.1
54 To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
55 the body of a message to majordomo@vger.kernel.org
56 More majordomo info at  http://vger.kernel.org/majordomo-info.html