fs: fsync on/off support
[efremov: change permissions from 0755 to 0644] Signed-off-by: djb77 <dwayne.bakewell@gmail.com> Signed-off-by: Denis Efremov <efremov@linux.com>
This commit is contained in:
parent
5eecb1807a
commit
0d3102deea
1 changed files with 31 additions and 2 deletions
33
fs/sync.c
33
fs/sync.c
|
@ -8,6 +8,7 @@
|
|||
#include <linux/fs.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/export.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/namei.h>
|
||||
#include <linux/sched/xacct.h>
|
||||
#include <linux/writeback.h>
|
||||
|
@ -18,6 +19,9 @@
|
|||
#include <linux/backing-dev.h>
|
||||
#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;
|
||||
|
|
Loading…
Reference in a new issue