f2fs: fix fdatasync
authorChao Yu <yuchao0@huawei.com>
Thu, 17 Nov 2016 12:53:31 +0000 (20:53 +0800)
committerJaegeuk Kim <jaegeuk@google.com>
Mon, 25 Sep 2017 22:36:56 +0000 (15:36 -0700)
commit8f5fcb8034c939bb9e6c03fe748a08df85a8503a
treec688c6867f50f0dbd4d13fd49c33d1e2ea40fbef
parent031017c6f9922c9c7b7819e876531de3f7ecb065
f2fs: fix fdatasync

commit 281518c694a5228d6c46fac83529fb3e2c331281 upstream.

For below two cases, we can't guarantee data consistence:

a)
1. xfs_io "pwrite 0 4195328" "fsync"
2. xfs_io "pwrite 4195328 1024" "fdatasync"
3. godown
4. umount & mount
--> isize we updated before fdatasync won't be recovered

b)
1. xfs_io "pwrite -S 0xcc 0 4202496" "fsync"
2. xfs_io "fpunch 4194304 4096" "fdatasync"
3. godown
4. umount & mount
--> dnode we punched before fdatasync won't be recovered

The reason is that normally fdatasync won't be aware of modification
of metadata in file, e.g. isize changing, dnode updating, so in ->fsync
we will skip flushing node pages for above cases, result in making
fdatasynced file being lost during recovery.

Currently we have introduced DIRTY_META global list in sbi for tracking
dirty inode selectively, so in fdatasync we can choose to flush nodes
depend on dirty state of current inode in the list.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/f2fs.h
fs/f2fs/file.c