Skip to content

Commit f267aeb

Browse files
biger410torvalds
authored andcommitted
ocfs2: fix zero out valid data
If append-dio feature is enabled, direct-io write and fallocate could run in parallel to extend file size, fallocate used "orig_isize" to record i_size before taking "ip_alloc_sem", when ocfs2_zeroout_partial_cluster() zeroout EOF blocks, i_size maybe already extended by ocfs2_dio_end_io_write(), that will cause valid data zeroed out. Link: https://lkml.kernel.org/r/[email protected] Fixes: 6bba447 ("ocfs2: fix data corruption by fallocate") Signed-off-by: Junxiao Bi <[email protected]> Reviewed-by: Joseph Qi <[email protected]> Cc: Changwei Ge <[email protected]> Cc: Gang He <[email protected]> Cc: Joel Becker <[email protected]> Cc: Jun Piao <[email protected]> Cc: Mark Fasheh <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent b2ff70a commit f267aeb

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fs/ocfs2/file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,15 +1935,14 @@ static int __ocfs2_change_file_space(struct file *file, struct inode *inode,
19351935
goto out_inode_unlock;
19361936
}
19371937

1938-
orig_isize = i_size_read(inode);
19391938
switch (sr->l_whence) {
19401939
case 0: /*SEEK_SET*/
19411940
break;
19421941
case 1: /*SEEK_CUR*/
19431942
sr->l_start += f_pos;
19441943
break;
19451944
case 2: /*SEEK_END*/
1946-
sr->l_start += orig_isize;
1945+
sr->l_start += i_size_read(inode);
19471946
break;
19481947
default:
19491948
ret = -EINVAL;
@@ -1998,6 +1997,7 @@ static int __ocfs2_change_file_space(struct file *file, struct inode *inode,
19981997
ret = -EINVAL;
19991998
}
20001999

2000+
orig_isize = i_size_read(inode);
20012001
/* zeroout eof blocks in the cluster. */
20022002
if (!ret && change_size && orig_isize < size) {
20032003
ret = ocfs2_zeroout_partial_cluster(inode, orig_isize,

0 commit comments

Comments
 (0)