1 From 78bbcc38db4efba1f64fbf8351bec5583c1132e1 Mon Sep 17 00:00:00 2001
2 From: Hou Tao <houtao1@huawei.com>
3 Date: Tue, 14 May 2019 15:44:32 -0700
4 Subject: fs/fat/file.c: issue flush after the writeback of FAT
6 [ Upstream commit bd8309de0d60838eef6fb575b0c4c7e95841cf73 ]
8 fsync() needs to make sure the data & meta-data of file are persistent
9 after the return of fsync(), even when a power-failure occurs later. In
10 the case of fat-fs, the FAT belongs to the meta-data of file, so we need
11 to issue a flush after the writeback of FAT instead before.
13 Also bail out early when any stage of fsync fails.
15 Link: http://lkml.kernel.org/r/20190409030158.136316-1-houtao1@huawei.com
16 Signed-off-by: Hou Tao <houtao1@huawei.com>
17 Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
18 Cc: Al Viro <viro@zeniv.linux.org.uk>
19 Cc: Jan Kara <jack@suse.cz>
20 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
21 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
22 Signed-off-by: Sasha Levin <sashal@kernel.org>
24 fs/fat/file.c | 11 ++++++++---
25 1 file changed, 8 insertions(+), 3 deletions(-)
27 diff --git a/fs/fat/file.c b/fs/fat/file.c
28 index 4f3d72fb1e60..f86ea08bd6ce 100644
31 @@ -193,12 +193,17 @@ static int fat_file_release(struct inode *inode, struct file *filp)
32 int fat_file_fsync(struct file *filp, loff_t start, loff_t end, int datasync)
34 struct inode *inode = filp->f_mapping->host;
38 + err = __generic_file_fsync(filp, start, end, datasync);
42 - res = generic_file_fsync(filp, start, end, datasync);
43 err = sync_mapping_buffers(MSDOS_SB(inode->i_sb)->fat_inode->i_mapping);
47 - return res ? res : err;
48 + return blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);