]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.19/fs-fat-file.c-issue-flush-after-the-writeback-of-fat.patch
b78cda648c854eab5b08d14c703125fc2b26eb82
[thirdparty/kernel/stable-queue.git] / queue-4.19 / fs-fat-file.c-issue-flush-after-the-writeback-of-fat.patch
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
5
6 [ Upstream commit bd8309de0d60838eef6fb575b0c4c7e95841cf73 ]
7
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.
12
13 Also bail out early when any stage of fsync fails.
14
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>
23 ---
24 fs/fat/file.c | 11 ++++++++---
25 1 file changed, 8 insertions(+), 3 deletions(-)
26
27 diff --git a/fs/fat/file.c b/fs/fat/file.c
28 index 4f3d72fb1e60..f86ea08bd6ce 100644
29 --- a/fs/fat/file.c
30 +++ b/fs/fat/file.c
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)
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 --
53 2.20.1
54