add patch move-error-report-out-of-atomic-context
[ext4-patch-queue.git] / reuse-path-object-in-ext4_ext_shift_extents
blobbd3e99c07692e28f89d0aa970501866eaefc8766
1 ext4: reuse path object in ext4_ext_shift_extents()
3 Now that the semantics of ext4_ext_find_extent() are much cleaner,
4 it's safe and more efficient to reuse the path object across the
5 multiple calls to ext4_ext_find_extent() in ext4_ext_shift_extents().
7 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
8 ---
9  fs/ext4/extents.c | 25 ++++++++-----------------
10  1 file changed, 8 insertions(+), 17 deletions(-)
12 diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
13 index ecd86e0..ad76d41 100644
14 --- a/fs/ext4/extents.c
15 +++ b/fs/ext4/extents.c
16 @@ -5305,26 +5305,21 @@ ext4_ext_shift_extents(struct inode *inode, handle_t *handle,
18         depth = path->p_depth;
19         extent = path[depth].p_ext;
20 -       if (!extent) {
21 -               ext4_ext_drop_refs(path);
22 -               kfree(path);
23 -               return ret;
24 -       }
25 +       if (!extent)
26 +               goto out;
28         stop_block = le32_to_cpu(extent->ee_block) +
29                         ext4_ext_get_actual_len(extent);
30 -       ext4_ext_drop_refs(path);
31 -       kfree(path);
33         /* Nothing to shift, if hole is at the end of file */
34         if (start >= stop_block)
35 -               return ret;
36 +               goto out;
38         /*
39          * Don't start shifting extents until we make sure the hole is big
40          * enough to accomodate the shift.
41          */
42 -       path = ext4_ext_find_extent(inode, start - 1, NULL, 0);
43 +       path = ext4_ext_find_extent(inode, start - 1, &path, 0);
44         if (IS_ERR(path))
45                 return PTR_ERR(path);
46         depth = path->p_depth;
47 @@ -5337,8 +5332,6 @@ ext4_ext_shift_extents(struct inode *inode, handle_t *handle,
48                 ex_start = 0;
49                 ex_end = 0;
50         }
51 -       ext4_ext_drop_refs(path);
52 -       kfree(path);
54         if ((start == ex_start && shift > ex_start) ||
55             (shift > start - ex_end))
56 @@ -5346,7 +5339,7 @@ ext4_ext_shift_extents(struct inode *inode, handle_t *handle,
58         /* Its safe to start updating extents */
59         while (start < stop_block) {
60 -               path = ext4_ext_find_extent(inode, start, NULL, 0);
61 +               path = ext4_ext_find_extent(inode, start, &path, 0);
62                 if (IS_ERR(path))
63                         return PTR_ERR(path);
64                 depth = path->p_depth;
65 @@ -5362,19 +5355,17 @@ ext4_ext_shift_extents(struct inode *inode, handle_t *handle,
66                                 path[depth].p_ext++;
67                         } else {
68                                 start = ext4_ext_next_allocated_block(path);
69 -                               ext4_ext_drop_refs(path);
70 -                               kfree(path);
71                                 continue;
72                         }
73                 }
74                 ret = ext4_ext_shift_path_extents(path, shift, inode,
75                                 handle, &start);
76 -               ext4_ext_drop_refs(path);
77 -               kfree(path);
78                 if (ret)
79                         break;
80         }
82 +out:
83 +       ext4_ext_drop_refs(path);
84 +       kfree(path);
85         return ret;
86  }