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/fs.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/export.h>
|
#include <linux/export.h>
|
||||||
|
#include <linux/module.h>
|
||||||
#include <linux/namei.h>
|
#include <linux/namei.h>
|
||||||
#include <linux/sched/xacct.h>
|
#include <linux/sched/xacct.h>
|
||||||
#include <linux/writeback.h>
|
#include <linux/writeback.h>
|
||||||
|
@ -18,6 +19,9 @@
|
||||||
#include <linux/backing-dev.h>
|
#include <linux/backing-dev.h>
|
||||||
#include "internal.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| \
|
#define VALID_FLAGS (SYNC_FILE_RANGE_WAIT_BEFORE|SYNC_FILE_RANGE_WRITE| \
|
||||||
SYNC_FILE_RANGE_WAIT_AFTER)
|
SYNC_FILE_RANGE_WAIT_AFTER)
|
||||||
|
|
||||||
|
@ -162,10 +166,15 @@ void emergency_sync(void)
|
||||||
*/
|
*/
|
||||||
SYSCALL_DEFINE1(syncfs, int, fd)
|
SYSCALL_DEFINE1(syncfs, int, fd)
|
||||||
{
|
{
|
||||||
struct fd f = fdget(fd);
|
struct fd f;
|
||||||
struct super_block *sb;
|
struct super_block *sb;
|
||||||
int ret, ret2;
|
int ret, ret2;
|
||||||
|
|
||||||
|
if (!fsync_enabled)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
f = fdget(fd);
|
||||||
|
|
||||||
if (!f.file)
|
if (!f.file)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
sb = f.file->f_path.dentry->d_sb;
|
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;
|
struct inode *inode = file->f_mapping->host;
|
||||||
|
|
||||||
|
if (!fsync_enabled)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (!file->f_op->fsync)
|
if (!file->f_op->fsync)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (!datasync && (inode->i_state & I_DIRTY_TIME))
|
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)
|
int vfs_fsync(struct file *file, int datasync)
|
||||||
{
|
{
|
||||||
|
if (!fsync_enabled)
|
||||||
|
return 0;
|
||||||
|
|
||||||
return vfs_fsync_range(file, 0, LLONG_MAX, datasync);
|
return vfs_fsync_range(file, 0, LLONG_MAX, datasync);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(vfs_fsync);
|
EXPORT_SYMBOL(vfs_fsync);
|
||||||
|
|
||||||
static int do_fsync(unsigned int fd, int datasync)
|
static int do_fsync(unsigned int fd, int datasync)
|
||||||
{
|
{
|
||||||
struct fd f = fdget(fd);
|
struct fd f;
|
||||||
int ret = -EBADF;
|
int ret = -EBADF;
|
||||||
|
|
||||||
|
if (!fsync_enabled)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
f = fdget(fd);
|
||||||
|
|
||||||
if (f.file) {
|
if (f.file) {
|
||||||
ret = vfs_fsync(f.file, datasync);
|
ret = vfs_fsync(f.file, datasync);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
|
@ -232,11 +252,17 @@ static int do_fsync(unsigned int fd, int datasync)
|
||||||
|
|
||||||
SYSCALL_DEFINE1(fsync, unsigned int, fd)
|
SYSCALL_DEFINE1(fsync, unsigned int, fd)
|
||||||
{
|
{
|
||||||
|
if (!fsync_enabled)
|
||||||
|
return 0;
|
||||||
|
|
||||||
return do_fsync(fd, 0);
|
return do_fsync(fd, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SYSCALL_DEFINE1(fdatasync, unsigned int, fd)
|
SYSCALL_DEFINE1(fdatasync, unsigned int, fd)
|
||||||
{
|
{
|
||||||
|
if (!fsync_enabled)
|
||||||
|
return 0;
|
||||||
|
|
||||||
return do_fsync(fd, 1);
|
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 */
|
loff_t endbyte; /* inclusive */
|
||||||
umode_t i_mode;
|
umode_t i_mode;
|
||||||
|
|
||||||
|
if (!fsync_enabled)
|
||||||
|
return 0;
|
||||||
|
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
if (flags & ~VALID_FLAGS)
|
if (flags & ~VALID_FLAGS)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
Loading…
Reference in a new issue