f2fs: fix f2fs_ioc_abort_volatile_write
authorJaegeuk Kim <jaegeuk@kernel.org>
Tue, 29 Dec 2015 23:46:33 +0000 (15:46 -0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 30 Dec 2015 18:53:25 +0000 (10:53 -0800)
There are two rules to handle aborting volatile or atomic writes.

1. drop atomic writes
 - we don't need to keep any stale db data.

2. write journal data
 - we should keep the journal data with fsync for db recovery.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/file.c

index 91f576a7903cfe9fdee0786c43279e37d69aea19..b04ab40ddc737c25f072600f578789ad772b52c0 100644 (file)
@@ -1433,9 +1433,14 @@ static int f2fs_ioc_abort_volatile_write(struct file *filp)
        if (ret)
                return ret;
 
-       clear_inode_flag(F2FS_I(inode), FI_ATOMIC_FILE);
-       clear_inode_flag(F2FS_I(inode), FI_VOLATILE_FILE);
-       commit_inmem_pages(inode, true);
+       if (f2fs_is_atomic_file(inode)) {
+               clear_inode_flag(F2FS_I(inode), FI_ATOMIC_FILE);
+               commit_inmem_pages(inode, true);
+       }
+       if (f2fs_is_volatile_file(inode)) {
+               clear_inode_flag(F2FS_I(inode), FI_VOLATILE_FILE);
+               ret = f2fs_sync_file(filp, 0, LLONG_MAX, 0);
+       }
 
        mnt_drop_write_file(filp);
        return ret;