diff --git a/fs/sync.c b/fs/sync.c index ad7a2715a..a64efeac0 100755 --- a/fs/sync.c +++ b/fs/sync.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -18,6 +19,9 @@ #include #include "internal.h" +bool fsync_enabled = true; +module_param(fsync_enabled, bool, 0644); + #define VALID_FLAGS (SYNC_FILE_RANGE_WAIT_BEFORE|SYNC_FILE_RANGE_WRITE| \ SYNC_FILE_RANGE_WAIT_AFTER) @@ -162,10 +166,15 @@ void emergency_sync(void) */ SYSCALL_DEFINE1(syncfs, int, fd) { - struct fd f = fdget(fd); + struct fd f; struct super_block *sb; int ret, ret2; + if (!fsync_enabled) + return 0; + + f = fdget(fd); + if (!f.file) return -EBADF; sb = f.file->f_path.dentry->d_sb; @@ -195,6 +204,9 @@ int vfs_fsync_range(struct file *file, loff_t start, loff_t end, int datasync) { struct inode *inode = file->f_mapping->host; + if (!fsync_enabled) + return 0; + if (!file->f_op->fsync) return -EINVAL; if (!datasync && (inode->i_state & I_DIRTY_TIME)) @@ -213,15 +225,23 @@ 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); static int do_fsync(unsigned int fd, int datasync) { - struct fd f = fdget(fd); + struct fd f; int ret = -EBADF; + if (!fsync_enabled) + return 0; + + f = fdget(fd); + if (f.file) { ret = vfs_fsync(f.file, datasync); fdput(f); @@ -232,11 +252,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); } @@ -248,6 +274,9 @@ int sync_file_range(struct file *file, loff_t offset, loff_t nbytes, loff_t endbyte; /* inclusive */ umode_t i_mode; + if (!fsync_enabled) + return 0; + ret = -EINVAL; if (flags & ~VALID_FLAGS) goto out;