patch series sync
[ext4-patch-queue.git] / allow-ext4_ext_truncate-to-return-an-error
blob72416404e816fd8b9108f7175a020d322962acaa
1 ext4: allow ext4_ext_truncate() to return an error
3 Return errors to the caller instead of declaring the file system
4 corrupted.
6 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
7 ---
8  fs/ext4/ext4.h    |  2 +-
9  fs/ext4/extents.c | 15 +++++++--------
10  fs/ext4/inode.c   |  4 +++-
11  3 files changed, 11 insertions(+), 10 deletions(-)
13 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
14 index be2282dcde7d..54211c7876f8 100644
15 --- a/fs/ext4/ext4.h
16 +++ b/fs/ext4/ext4.h
17 @@ -3128,7 +3128,7 @@ extern int ext4_ext_writepage_trans_blocks(struct inode *, int);
18  extern int ext4_ext_index_trans_blocks(struct inode *inode, int extents);
19  extern int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,
20                                struct ext4_map_blocks *map, int flags);
21 -extern void ext4_ext_truncate(handle_t *, struct inode *);
22 +extern int ext4_ext_truncate(handle_t *, struct inode *);
23  extern int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start,
24                                  ext4_lblk_t end);
25  extern void ext4_ext_init(struct super_block *);
26 diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
27 index c930a0110fb4..d3b119499c53 100644
28 --- a/fs/ext4/extents.c
29 +++ b/fs/ext4/extents.c
30 @@ -4631,7 +4631,7 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,
31         return err ? err : allocated;
32  }
34 -void ext4_ext_truncate(handle_t *handle, struct inode *inode)
35 +int ext4_ext_truncate(handle_t *handle, struct inode *inode)
36  {
37         struct super_block *sb = inode->i_sb;
38         ext4_lblk_t last_block;
39 @@ -4645,7 +4645,9 @@ void ext4_ext_truncate(handle_t *handle, struct inode *inode)
41         /* we have to know where to truncate from in crash case */
42         EXT4_I(inode)->i_disksize = inode->i_size;
43 -       ext4_mark_inode_dirty(handle, inode);
44 +       err = ext4_mark_inode_dirty(handle, inode);
45 +       if (err)
46 +               return err;
48         last_block = (inode->i_size + sb->s_blocksize - 1)
49                         >> EXT4_BLOCK_SIZE_BITS(sb);
50 @@ -4657,12 +4659,9 @@ void ext4_ext_truncate(handle_t *handle, struct inode *inode)
51                 congestion_wait(BLK_RW_ASYNC, HZ/50);
52                 goto retry;
53         }
54 -       if (err) {
55 -               ext4_std_error(inode->i_sb, err);
56 -               return;
57 -       }
58 -       err = ext4_ext_remove_space(inode, last_block, EXT_MAX_BLOCKS - 1);
59 -       ext4_std_error(inode->i_sb, err);
60 +       if (err)
61 +               return err;
62 +       return ext4_ext_remove_space(inode, last_block, EXT_MAX_BLOCKS - 1);
63  }
65  static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset,
66 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
67 index 40ea090d2e0e..7f32899c9701 100644
68 --- a/fs/ext4/inode.c
69 +++ b/fs/ext4/inode.c
70 @@ -4167,11 +4167,13 @@ int ext4_truncate(struct inode *inode)
71         ext4_discard_preallocations(inode);
73         if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
74 -               ext4_ext_truncate(handle, inode);
75 +               err = ext4_ext_truncate(handle, inode);
76         else
77                 ext4_ind_truncate(handle, inode);
79         up_write(&ei->i_data_sem);
80 +       if (err)
81 +               goto out_stop;
83         if (IS_SYNC(inode))
84                 ext4_handle_sync(handle);