1 ext4: allow ext4_truncate() to return an error
3 This allows us to properly propagate errors back up to
4 ext4_truncate()'s callers. This also means we no longer have to
5 silently ignore some errors (e.g., when trying to add the inode to the
8 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
11 fs/ext4/inode.c | 41 ++++++++++++++++++++++++++---------------
12 fs/ext4/ioctl.c | 7 +++++--
13 fs/ext4/super.c | 6 ++++--
14 4 files changed, 36 insertions(+), 20 deletions(-)
16 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
17 index 282a51b07c57..be2282dcde7d 100644
20 @@ -2491,7 +2491,7 @@ extern int ext4_change_inode_journal_flag(struct inode *, int);
21 extern int ext4_get_inode_loc(struct inode *, struct ext4_iloc *);
22 extern int ext4_inode_attach_jinode(struct inode *inode);
23 extern int ext4_can_truncate(struct inode *inode);
24 -extern void ext4_truncate(struct inode *);
25 +extern int ext4_truncate(struct inode *);
26 extern int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length);
27 extern int ext4_truncate_restart_trans(handle_t *, struct inode *, int nblocks);
28 extern void ext4_set_inode_flags(struct inode *);
29 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
30 index 9c064727ed62..40ea090d2e0e 100644
33 @@ -261,8 +261,15 @@ void ext4_evict_inode(struct inode *inode)
34 "couldn't mark inode dirty (err %d)", err);
37 - if (inode->i_blocks)
38 - ext4_truncate(inode);
39 + if (inode->i_blocks) {
40 + err = ext4_truncate(inode);
42 + ext4_error(inode->i_sb,
43 + "couldn't truncate inode %lu (err %d)",
50 * ext4_ext_truncate() doesn't reserve any slop when it
51 @@ -4091,10 +4098,11 @@ int ext4_inode_attach_jinode(struct inode *inode)
52 * that's fine - as long as they are linked from the inode, the post-crash
53 * ext4_truncate() run will find them and release them.
55 -void ext4_truncate(struct inode *inode)
56 +int ext4_truncate(struct inode *inode)
58 struct ext4_inode_info *ei = EXT4_I(inode);
62 struct address_space *mapping = inode->i_mapping;
64 @@ -4108,7 +4116,7 @@ void ext4_truncate(struct inode *inode)
65 trace_ext4_truncate_enter(inode);
67 if (!ext4_can_truncate(inode))
71 ext4_clear_inode_flag(inode, EXT4_INODE_EOFBLOCKS);
73 @@ -4120,13 +4128,13 @@ void ext4_truncate(struct inode *inode)
75 ext4_inline_data_truncate(inode, &has_inline);
81 /* If we zero-out tail of the page, we have to create jinode for jbd2 */
82 if (inode->i_size & (inode->i_sb->s_blocksize - 1)) {
83 if (ext4_inode_attach_jinode(inode) < 0)
88 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
89 @@ -4135,10 +4143,8 @@ void ext4_truncate(struct inode *inode)
90 credits = ext4_blocks_for_truncate(inode);
92 handle = ext4_journal_start(inode, EXT4_HT_TRUNCATE, credits);
93 - if (IS_ERR(handle)) {
94 - ext4_std_error(inode->i_sb, PTR_ERR(handle));
98 + return PTR_ERR(handle);
100 if (inode->i_size & (inode->i_sb->s_blocksize - 1))
101 ext4_block_truncate_page(handle, mapping, inode->i_size);
102 @@ -4152,7 +4158,8 @@ void ext4_truncate(struct inode *inode)
103 * Implication: the file must always be in a sane, consistent
104 * truncatable state while each transaction commits.
106 - if (ext4_orphan_add(handle, inode))
107 + err = ext4_orphan_add(handle, inode);
111 down_write(&EXT4_I(inode)->i_data_sem);
112 @@ -4185,6 +4192,7 @@ void ext4_truncate(struct inode *inode)
113 ext4_journal_stop(handle);
115 trace_ext4_truncate_exit(inode);
120 @@ -5199,12 +5207,15 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
121 * in data=journal mode to make pages freeable.
123 truncate_pagecache(inode, inode->i_size);
125 - ext4_truncate(inode);
127 + rc = ext4_truncate(inode);
131 up_write(&EXT4_I(inode)->i_mmap_sem);
136 setattr_copy(inode, attr);
137 mark_inode_dirty(inode);
139 @@ -5216,7 +5227,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
140 if (orphan && inode->i_nlink)
141 ext4_orphan_del(NULL, inode);
143 - if (!rc && (ia_valid & ATTR_MODE))
144 + if (!error && (ia_valid & ATTR_MODE))
145 rc = posix_acl_chmod(inode, inode->i_mode);
148 diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
149 index bf5ae8ebbc97..99862a3726fc 100644
150 --- a/fs/ext4/ioctl.c
151 +++ b/fs/ext4/ioctl.c
152 @@ -248,8 +248,11 @@ static int ext4_ioctl_setflags(struct inode *inode,
156 - } else if (oldflags & EXT4_EOFBLOCKS_FL)
157 - ext4_truncate(inode);
158 + } else if (oldflags & EXT4_EOFBLOCKS_FL) {
159 + err = ext4_truncate(inode);
164 handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
165 if (IS_ERR(handle)) {
166 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
167 index 20da99da0a34..e4f61c39328a 100644
168 --- a/fs/ext4/super.c
169 +++ b/fs/ext4/super.c
170 @@ -2330,7 +2330,7 @@ static void ext4_orphan_cleanup(struct super_block *sb,
171 struct ext4_super_block *es)
173 unsigned int s_flags = sb->s_flags;
174 - int nr_orphans = 0, nr_truncates = 0;
175 + int ret, nr_orphans = 0, nr_truncates = 0;
179 @@ -2412,7 +2412,9 @@ static void ext4_orphan_cleanup(struct super_block *sb,
180 inode->i_ino, inode->i_size);
182 truncate_inode_pages(inode->i_mapping, inode->i_size);
183 - ext4_truncate(inode);
184 + ret = ext4_truncate(inode);
186 + ext4_std_error(inode->i_sb, ret);