Fix follow-on patches so they apply correctly
[ext4-patch-queue.git] / propagate-error-values-from-ext4_inline_data_truncate
blobc4682bd39d49db2438bb30daf45a066662c07cce
1 ext4: propagate error values from ext4_inline_data_truncate()
3 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 ---
5  fs/ext4/ext4.h   |  2 +-
6  fs/ext4/inline.c | 40 +++++++++++++++++++++++-----------------
7  fs/ext4/inode.c  |  4 +++-
8  3 files changed, 27 insertions(+), 19 deletions(-)
10 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
11 index 6bcb9622fdf9..1cd077e02517 100644
12 --- a/fs/ext4/ext4.h
13 +++ b/fs/ext4/ext4.h
14 @@ -3023,7 +3023,7 @@ extern int ext4_inline_data_fiemap(struct inode *inode,
15  extern int ext4_try_to_evict_inline_data(handle_t *handle,
16                                          struct inode *inode,
17                                          int needed);
18 -extern void ext4_inline_data_truncate(struct inode *inode, int *has_inline);
19 +extern int ext4_inline_data_truncate(struct inode *inode, int *has_inline);
21  extern int ext4_convert_inline_data(struct inode *inode);
23 diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
24 index 31f98dd04e51..338cfd862adb 100644
25 --- a/fs/ext4/inline.c
26 +++ b/fs/ext4/inline.c
27 @@ -1896,10 +1896,10 @@ int ext4_try_to_evict_inline_data(handle_t *handle,
28         return error;
29  }
31 -void ext4_inline_data_truncate(struct inode *inode, int *has_inline)
32 +int ext4_inline_data_truncate(struct inode *inode, int *has_inline)
33  {
34         handle_t *handle;
35 -       int inline_size, value_len, needed_blocks, no_expand;
36 +       int inline_size, value_len, needed_blocks, no_expand, err = 0;
37         size_t i_size;
38         void *value = NULL;
39         struct ext4_xattr_ibody_find is = {
40 @@ -1914,19 +1914,19 @@ void ext4_inline_data_truncate(struct inode *inode, int *has_inline)
41         needed_blocks = ext4_writepage_trans_blocks(inode);
42         handle = ext4_journal_start(inode, EXT4_HT_INODE, needed_blocks);
43         if (IS_ERR(handle))
44 -               return;
45 +               return PTR_ERR(handle);
47         ext4_write_lock_xattr(inode, &no_expand);
48         if (!ext4_has_inline_data(inode)) {
49                 *has_inline = 0;
50                 ext4_journal_stop(handle);
51 -               return;
52 +               return 0;
53         }
55 -       if (ext4_orphan_add(handle, inode))
56 +       if ((err = ext4_orphan_add(handle, inode)) != 0)
57                 goto out;
59 -       if (ext4_get_inode_loc(inode, &is.iloc))
60 +       if ((err = ext4_get_inode_loc(inode, &is.iloc)) != 0)
61                 goto out;
63         down_write(&EXT4_I(inode)->i_data_sem);
64 @@ -1937,24 +1937,29 @@ void ext4_inline_data_truncate(struct inode *inode, int *has_inline)
65         if (i_size < inline_size) {
66                 /* Clear the content in the xattr space. */
67                 if (inline_size > EXT4_MIN_INLINE_DATA_SIZE) {
68 -                       if (ext4_xattr_ibody_find(inode, &i, &is))
69 +                       if ((err = ext4_xattr_ibody_find(inode, &i, &is)) != 0)
70                                 goto out_error;
72                         BUG_ON(is.s.not_found);
74                         value_len = le32_to_cpu(is.s.here->e_value_size);
75                         value = kmalloc(value_len, GFP_NOFS);
76 -                       if (!value)
77 +                       if (!value) {
78 +                               err = -ENOMEM;
79                                 goto out_error;
80 +                       }
82 -                       if (ext4_xattr_ibody_get(inode, i.name_index, i.name,
83 -                                               value, value_len))
84 +                       err = ext4_xattr_ibody_get(inode, i.name_index,
85 +                                                  i.name, value, value_len);
86 +                       if (err <= 0)
87                                 goto out_error;
89                         i.value = value;
90                         i.value_len = i_size > EXT4_MIN_INLINE_DATA_SIZE ?
91                                         i_size - EXT4_MIN_INLINE_DATA_SIZE : 0;
92 -                       if (ext4_xattr_ibody_inline_set(handle, inode, &i, &is))
93 +                       err = ext4_xattr_ibody_inline_set(handle, inode,
94 +                                                         &i, &is);
95 +                       if (err)
96                                 goto out_error;
97                 }
99 @@ -1979,13 +1984,14 @@ void ext4_inline_data_truncate(struct inode *inode, int *has_inline)
100         if (inode->i_nlink)
101                 ext4_orphan_del(handle, inode);
103 -       inode->i_mtime = inode->i_ctime = current_time(inode);
104 -       ext4_mark_inode_dirty(handle, inode);
105 -       if (IS_SYNC(inode))
106 -               ext4_handle_sync(handle);
108 +       if (err == 0) {
109 +               inode->i_mtime = inode->i_ctime = current_time(inode);
110 +               err = ext4_mark_inode_dirty(handle, inode);
111 +               if (IS_SYNC(inode))
112 +                       ext4_handle_sync(handle);
113 +       }
114         ext4_journal_stop(handle);
115 -       return;
116 +       return err;
119  int ext4_convert_inline_data(struct inode *inode)
120 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
121 index 86dde0667ccc..1e2c881f102d 100644
122 --- a/fs/ext4/inode.c
123 +++ b/fs/ext4/inode.c
124 @@ -4222,7 +4222,9 @@ int ext4_truncate(struct inode *inode)
125         if (ext4_has_inline_data(inode)) {
126                 int has_inline = 1;
128 -               ext4_inline_data_truncate(inode, &has_inline);
129 +               err = ext4_inline_data_truncate(inode, &has_inline);
130 +               if (err)
131 +                       return err;
132                 if (has_inline)
133                         return 0;
134         }