Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Jan Kara and committed by
Theodore Ts'o
b71fc079 6a08f447

+6 -2
+6 -2
fs/ext4/inode.c
··· 4054 4054 struct ext4_inode_info *ei = EXT4_I(inode); 4055 4055 struct buffer_head *bh = iloc->bh; 4056 4056 int err = 0, rc, block; 4057 + int need_datasync = 0; 4057 4058 uid_t i_uid; 4058 4059 gid_t i_gid; 4059 4060 ··· 4105 4104 raw_inode->i_file_acl_high = 4106 4105 cpu_to_le16(ei->i_file_acl >> 32); 4107 4106 raw_inode->i_file_acl_lo = cpu_to_le32(ei->i_file_acl); 4108 - ext4_isize_set(raw_inode, ei->i_disksize); 4107 + if (ei->i_disksize != ext4_isize(raw_inode)) { 4108 + ext4_isize_set(raw_inode, ei->i_disksize); 4109 + need_datasync = 1; 4110 + } 4109 4111 if (ei->i_disksize > 0x7fffffffULL) { 4110 4112 struct super_block *sb = inode->i_sb; 4111 4113 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, ··· 4161 4157 err = rc; 4162 4158 ext4_clear_inode_state(inode, EXT4_STATE_NEW); 4163 4159 4164 - ext4_update_inode_fsync_trans(handle, inode, 0); 4160 + ext4_update_inode_fsync_trans(handle, inode, need_datasync); 4165 4161 out_brelse: 4166 4162 brelse(bh); 4167 4163 ext4_std_error(inode->i_sb, err);