diff options
author | Jan Kara <jack@suse.cz> | 2012-09-26 21:52:20 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2012-09-26 21:52:20 -0400 |
commit | b71fc079b5d8f42b2a52743c8d2f1d35d655b1c5 (patch) | |
tree | f33b95f6bda4c99ac236dce9b81e4f076336fa5b /fs/ext4 | |
parent | 6a08f447facb4f9e29fcc30fb68060bb5a0d21c2 (diff) |
ext4: fix fdatasync() for files with only i_size changes
Code tracking when transaction needs to be committed on fdatasync(2) forgets
to handle a situation when only inode's i_size is changed. Thus in such
situations fdatasync(2) doesn't force transaction with new i_size to disk
and that can result in wrong i_size after a crash.
Fix the issue by updating inode's i_datasync_tid whenever its size is
updated.
CC: <stable@vger.kernel.org> # >= 2.6.32
Reported-by: Kristian Nielsen <knielsen@knielsen-hq.org>
Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'fs/ext4')
-rw-r--r-- | fs/ext4/inode.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 0a31197590d..4df5e95801b 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -4054,6 +4054,7 @@ static int ext4_do_update_inode(handle_t *handle, | |||
4054 | struct ext4_inode_info *ei = EXT4_I(inode); | 4054 | struct ext4_inode_info *ei = EXT4_I(inode); |
4055 | struct buffer_head *bh = iloc->bh; | 4055 | struct buffer_head *bh = iloc->bh; |
4056 | int err = 0, rc, block; | 4056 | int err = 0, rc, block; |
4057 | int need_datasync = 0; | ||
4057 | uid_t i_uid; | 4058 | uid_t i_uid; |
4058 | gid_t i_gid; | 4059 | gid_t i_gid; |
4059 | 4060 | ||
@@ -4104,7 +4105,10 @@ static int ext4_do_update_inode(handle_t *handle, | |||
4104 | raw_inode->i_file_acl_high = | 4105 | raw_inode->i_file_acl_high = |
4105 | cpu_to_le16(ei->i_file_acl >> 32); | 4106 | cpu_to_le16(ei->i_file_acl >> 32); |
4106 | raw_inode->i_file_acl_lo = cpu_to_le32(ei->i_file_acl); | 4107 | raw_inode->i_file_acl_lo = cpu_to_le32(ei->i_file_acl); |
4107 | ext4_isize_set(raw_inode, ei->i_disksize); | 4108 | if (ei->i_disksize != ext4_isize(raw_inode)) { |
4109 | ext4_isize_set(raw_inode, ei->i_disksize); | ||
4110 | need_datasync = 1; | ||
4111 | } | ||
4108 | if (ei->i_disksize > 0x7fffffffULL) { | 4112 | if (ei->i_disksize > 0x7fffffffULL) { |
4109 | struct super_block *sb = inode->i_sb; | 4113 | struct super_block *sb = inode->i_sb; |
4110 | if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, | 4114 | if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, |
@@ -4157,7 +4161,7 @@ static int ext4_do_update_inode(handle_t *handle, | |||
4157 | err = rc; | 4161 | err = rc; |
4158 | ext4_clear_inode_state(inode, EXT4_STATE_NEW); | 4162 | ext4_clear_inode_state(inode, EXT4_STATE_NEW); |
4159 | 4163 | ||
4160 | ext4_update_inode_fsync_trans(handle, inode, 0); | 4164 | ext4_update_inode_fsync_trans(handle, inode, need_datasync); |
4161 | out_brelse: | 4165 | out_brelse: |
4162 | brelse(bh); | 4166 | brelse(bh); |
4163 | ext4_std_error(inode->i_sb, err); | 4167 | ext4_std_error(inode->i_sb, err); |