]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - queue-4.14/fs-fat-file.c-issue-flush-after-the-writeback-of-fat.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / queue-4.14 / fs-fat-file.c-issue-flush-after-the-writeback-of-fat.patch
CommitLineData
6e4ffbcf
SL
1From 2722bc6cac840183a1211bb2d8037110daa3882d Mon Sep 17 00:00:00 2001
2From: Hou Tao <houtao1@huawei.com>
3Date: Tue, 14 May 2019 15:44:32 -0700
4Subject: fs/fat/file.c: issue flush after the writeback of FAT
5
6[ Upstream commit bd8309de0d60838eef6fb575b0c4c7e95841cf73 ]
7
8fsync() needs to make sure the data & meta-data of file are persistent
9after the return of fsync(), even when a power-failure occurs later. In
10the case of fat-fs, the FAT belongs to the meta-data of file, so we need
11to issue a flush after the writeback of FAT instead before.
12
13Also bail out early when any stage of fsync fails.
14
15Link: http://lkml.kernel.org/r/20190409030158.136316-1-houtao1@huawei.com
16Signed-off-by: Hou Tao <houtao1@huawei.com>
17Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
18Cc: Al Viro <viro@zeniv.linux.org.uk>
19Cc: Jan Kara <jack@suse.cz>
20Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
21Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
22Signed-off-by: Sasha Levin <sashal@kernel.org>
23---
24 fs/fat/file.c | 11 ++++++++---
25 1 file changed, 8 insertions(+), 3 deletions(-)
26
27diff --git a/fs/fat/file.c b/fs/fat/file.c
28index 4724cc9ad650..62581de09bf1 100644
29--- a/fs/fat/file.c
30+++ b/fs/fat/file.c
31@@ -160,12 +160,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)
33 {
34 struct inode *inode = filp->f_mapping->host;
35- int res, err;
36+ int err;
37+
38+ err = __generic_file_fsync(filp, start, end, datasync);
39+ if (err)
40+ return err;
41
42- res = generic_file_fsync(filp, start, end, datasync);
43 err = sync_mapping_buffers(MSDOS_SB(inode->i_sb)->fat_inode->i_mapping);
44+ if (err)
45+ return err;
46
47- return res ? res : err;
48+ return blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);
49 }
50
51
52--
532.20.1
54