Blame SOURCES/0043-exfat-flush-dirty-metadata-in-fsync.patch

Kmods SIG 50e2b3
From 5267456e953fd8c5abd8e278b1cc6a9f9027ac0a Mon Sep 17 00:00:00 2001
Kmods SIG 50e2b3
From: Sungjong Seo <sj1557.seo@samsung.com>
Kmods SIG 50e2b3
Date: Thu, 18 Jun 2020 20:43:26 +0900
Kmods SIG 50e2b3
Subject: [Backport 5267456e953f] exfat: flush dirty metadata in fsync
Kmods SIG 50e2b3
Kmods SIG 50e2b3
generic_file_fsync() exfat used could not guarantee the consistency of
Kmods SIG 50e2b3
a file because it has flushed not dirty metadata but only dirty data pages
Kmods SIG 50e2b3
for a file.
Kmods SIG 50e2b3
Kmods SIG 50e2b3
Instead of that, use exfat_file_fsync() for files and directories so that
Kmods SIG 50e2b3
it guarantees to commit both the metadata and data pages for a file.
Kmods SIG 50e2b3
Kmods SIG 50e2b3
Signed-off-by: Sungjong Seo <sj1557.seo@samsung.com>
Kmods SIG 50e2b3
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Kmods SIG 50e2b3
---
Kmods SIG 50e2b3
 src/dir.c      |  2 +-
Kmods SIG 50e2b3
 src/exfat_fs.h |  1 +
Kmods SIG 50e2b3
 src/file.c     | 19 ++++++++++++++++++-
Kmods SIG 50e2b3
 3 files changed, 20 insertions(+), 2 deletions(-)
Kmods SIG 50e2b3
Kmods SIG 50e2b3
diff --git a/src/dir.c b/src/dir.c
Kmods SIG 50e2b3
index 8e775bd5d523046530b9c82a58264a358bf857e3..91ece649285d2824ff99ee5b996adeb8ff973a93 100644
Kmods SIG 50e2b3
--- a/src/dir.c
Kmods SIG 50e2b3
+++ b/src/dir.c
Kmods SIG 50e2b3
@@ -309,7 +309,7 @@ const struct file_operations exfat_dir_operations = {
Kmods SIG 50e2b3
 	.llseek		= generic_file_llseek,
Kmods SIG 50e2b3
 	.read		= generic_read_dir,
Kmods SIG 50e2b3
 	.iterate	= exfat_iterate,
Kmods SIG 50e2b3
-	.fsync		= generic_file_fsync,
Kmods SIG 50e2b3
+	.fsync		= exfat_file_fsync,
Kmods SIG 50e2b3
 };
Kmods SIG 50e2b3
 
Kmods SIG 50e2b3
 int exfat_alloc_new_dir(struct inode *inode, struct exfat_chain *clu)
Kmods SIG 50e2b3
diff --git a/src/exfat_fs.h b/src/exfat_fs.h
Kmods SIG 50e2b3
index 595f3117f4924893a07eba48b55ef3d7d6edbee6..7579cd3bbadba87a8bfd56c0699c8186902a6763 100644
Kmods SIG 50e2b3
--- a/src/exfat_fs.h
Kmods SIG 50e2b3
+++ b/src/exfat_fs.h
Kmods SIG 50e2b3
@@ -420,6 +420,7 @@ void exfat_truncate(struct inode *inode, loff_t size);
Kmods SIG 50e2b3
 int exfat_setattr(struct dentry *dentry, struct iattr *attr);
Kmods SIG 50e2b3
 int exfat_getattr(const struct path *path, struct kstat *stat,
Kmods SIG 50e2b3
 		unsigned int request_mask, unsigned int query_flags);
Kmods SIG 50e2b3
+int exfat_file_fsync(struct file *file, loff_t start, loff_t end, int datasync);
Kmods SIG 50e2b3
 
Kmods SIG 50e2b3
 /* namei.c */
Kmods SIG 50e2b3
 extern const struct dentry_operations exfat_dentry_ops;
Kmods SIG 50e2b3
diff --git a/src/file.c b/src/file.c
Kmods SIG 50e2b3
index fce03f31878735e1fa389231abc1052f24447146..3b7fea465fd41e2859a94afac61dd9768a9f3119 100644
Kmods SIG 50e2b3
--- a/src/file.c
Kmods SIG 50e2b3
+++ b/src/file.c
Kmods SIG 50e2b3
@@ -6,6 +6,7 @@
Kmods SIG 50e2b3
 #include <linux/slab.h>
Kmods SIG 50e2b3
 #include <linux/cred.h>
Kmods SIG 50e2b3
 #include <linux/buffer_head.h>
Kmods SIG 50e2b3
+#include <linux/blkdev.h>
Kmods SIG 50e2b3
 
Kmods SIG 50e2b3
 #include "exfat_raw.h"
Kmods SIG 50e2b3
 #include "exfat_fs.h"
Kmods SIG 50e2b3
@@ -346,12 +347,28 @@ int exfat_setattr(struct dentry *dentry, struct iattr *attr)
Kmods SIG 50e2b3
 	return error;
Kmods SIG 50e2b3
 }
Kmods SIG 50e2b3
 
Kmods SIG 50e2b3
+int exfat_file_fsync(struct file *filp, loff_t start, loff_t end, int datasync)
Kmods SIG 50e2b3
+{
Kmods SIG 50e2b3
+	struct inode *inode = filp->f_mapping->host;
Kmods SIG 50e2b3
+	int err;
Kmods SIG 50e2b3
+
Kmods SIG 50e2b3
+	err = __generic_file_fsync(filp, start, end, datasync);
Kmods SIG 50e2b3
+	if (err)
Kmods SIG 50e2b3
+		return err;
Kmods SIG 50e2b3
+
Kmods SIG 50e2b3
+	err = sync_blockdev(inode->i_sb->s_bdev);
Kmods SIG 50e2b3
+	if (err)
Kmods SIG 50e2b3
+		return err;
Kmods SIG 50e2b3
+
Kmods SIG 50e2b3
+	return blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL);
Kmods SIG 50e2b3
+}
Kmods SIG 50e2b3
+
Kmods SIG 50e2b3
 const struct file_operations exfat_file_operations = {
Kmods SIG 50e2b3
 	.llseek		= generic_file_llseek,
Kmods SIG 50e2b3
 	.read_iter	= generic_file_read_iter,
Kmods SIG 50e2b3
 	.write_iter	= generic_file_write_iter,
Kmods SIG 50e2b3
 	.mmap		= generic_file_mmap,
Kmods SIG 50e2b3
-	.fsync		= generic_file_fsync,
Kmods SIG 50e2b3
+	.fsync		= exfat_file_fsync,
Kmods SIG 50e2b3
 	.splice_read	= generic_file_splice_read,
Kmods SIG 50e2b3
 	.splice_write	= iter_file_splice_write,
Kmods SIG 50e2b3
 };
Kmods SIG 50e2b3
-- 
Kmods SIG 50e2b3
2.31.1
Kmods SIG 50e2b3