f2fs: issue cache flush on direct IO
authorJaegeuk Kim <jaegeuk@kernel.org>
Mon, 18 Apr 2016 21:07:44 +0000 (17:07 -0400)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 26 Apr 2016 21:25:05 +0000 (14:25 -0700)
Under direct IO path with O_(D)SYNC, it needs to set proper APPEND or UPDATE
flags, so taht f2fs_sync_file can make its data safe.

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

index e54489b970ae0297e98a3cc43d5a4da9af9a4774..38ce5d6f8583b44f17e677c6931bafe74a14f27f 100644 (file)
@@ -673,6 +673,9 @@ next_block:
                                        err = reserve_new_block(&dn);
                        } else {
                                err = __allocate_data_block(&dn);
+                               if (!err)
+                                       set_inode_flag(F2FS_I(inode),
+                                                       FI_APPEND_WRITE);
                        }
                        if (err)
                                goto sync_out;
@@ -1685,8 +1688,12 @@ static ssize_t f2fs_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
        trace_f2fs_direct_IO_enter(inode, offset, count, iov_iter_rw(iter));
 
        err = blockdev_direct_IO(iocb, inode, iter, offset, get_data_block_dio);
-       if (err < 0 && iov_iter_rw(iter) == WRITE)
-               f2fs_write_failed(mapping, offset + count);
+       if (iov_iter_rw(iter) == WRITE) {
+               if (err > 0)
+                       set_inode_flag(F2FS_I(inode), FI_UPDATE_WRITE);
+               else if (err < 0)
+                       f2fs_write_failed(mapping, offset + count);
+       }
 
        trace_f2fs_direct_IO_exit(inode, offset, count, iov_iter_rw(iter), err);