From c6e722bb219c8ccb79440e875a116f54ca45b0cf Mon Sep 17 00:00:00 2001
From: Loller79 <loller790@gmail.com>
Date: Sat, 18 Oct 2014 18:52:13 +0200
Subject: [PATCH] Added FSync : Thanks to franciscofranco

---
 fs/sync.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/fs/sync.c b/fs/sync.c
index 0e8db93..5162fbe 100644
--- a/fs/sync.c
+++ b/fs/sync.c
@@ -7,6 +7,7 @@
 #include <linux/fs.h>
 #include <linux/slab.h>
 #include <linux/export.h>
+#include <linux/module.h>
 #include <linux/namei.h>
 #include <linux/sched.h>
 #include <linux/writeback.h>
@@ -17,6 +18,9 @@
 #include <linux/backing-dev.h>
 #include "internal.h"

+bool fsync_enabled = true;
+module_param(fsync_enabled, bool, 0755);
+
 #define VALID_FLAGS (SYNC_FILE_RANGE_WAIT_BEFORE|SYNC_FILE_RANGE_WRITE| \
 SYNC_FILE_RANGE_WAIT_AFTER)

@@ -137,6 +141,9 @@ SYSCALL_DEFINE1(syncfs, int, fd)
 struct super_block *sb;
 int ret;
 int fput_needed;
+
+if (!fsync_enabled)
+return 0;

 file = fget_light(fd, &fput_needed);
 if (!file)
@@ -164,6 +171,9 @@ SYSCALL_DEFINE1(syncfs, int, fd)
  */
 int vfs_fsync_range(struct file *file, loff_t start, loff_t end, int datasync)
 {
+if (!fsync_enabled)
+return 0;
+
 if (!file->f_op || !file->f_op->fsync)
 return -EINVAL;
 return file->f_op->fsync(file, start, end, datasync);
@@ -180,6 +190,9 @@ EXPORT_SYMBOL(vfs_fsync_range);
  */
 int vfs_fsync(struct file *file, int datasync)
 {
+if (!fsync_enabled)
+return 0;
+
 return vfs_fsync_range(file, 0, LLONG_MAX, datasync);
 }
 EXPORT_SYMBOL(vfs_fsync);
@@ -188,6 +201,9 @@ static int do_fsync(unsigned int fd, int datasync)
 {
 struct file *file;
 int ret = -EBADF;
+
+if (!fsync_enabled)
+return 0;

 file = fget(fd);
 if (file) {
@@ -199,11 +215,17 @@ static int do_fsync(unsigned int fd, int datasync)

 SYSCALL_DEFINE1(fsync, unsigned int, fd)
 {
+if (!fsync_enabled)
+return 0;
+
 return do_fsync(fd, 0);
 }

 SYSCALL_DEFINE1(fdatasync, unsigned int, fd)
 {
+if (!fsync_enabled)
+return 0;
+
 return do_fsync(fd, 1);
 }

@@ -217,6 +239,9 @@ SYSCALL_DEFINE1(fdatasync, unsigned int, fd)
  */
 int generic_write_sync(struct file *file, loff_t pos, loff_t count)
 {
+if (!fsync_enabled)
+return 0;
+
 if (!(file->f_flags & O_DSYNC) && !IS_SYNC(file->f_mapping->host))
 return 0;
 return vfs_fsync_range(file, pos, pos + count - 1,
@@ -281,6 +306,9 @@ SYSCALL_DEFINE(sync_file_range)(int fd, loff_t offset, loff_t nbytes,
 int fput_needed;
 umode_t i_mode;

+if (!fsync_enabled)
+return 0;
+
 ret = -EINVAL;
 if (flags & ~VALID_FLAGS)
 goto out;