Commit 18e79b40 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] fsync: extract internal code

Pull the guts out of do_fsync() - we can use it elsewhere.

Cc: Hugh Dickins <hugh@veritas.com>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 676758bd
...@@ -327,31 +327,24 @@ int file_fsync(struct file *filp, struct dentry *dentry, int datasync) ...@@ -327,31 +327,24 @@ int file_fsync(struct file *filp, struct dentry *dentry, int datasync)
return ret; return ret;
} }
static long do_fsync(unsigned int fd, int datasync) long do_fsync(struct file *file, int datasync)
{ {
struct file * file; int ret;
struct address_space *mapping; int err;
int ret, err; struct address_space *mapping = file->f_mapping;
ret = -EBADF;
file = fget(fd);
if (!file)
goto out;
ret = -EINVAL;
if (!file->f_op || !file->f_op->fsync) { if (!file->f_op || !file->f_op->fsync) {
/* Why? We can still call filemap_fdatawrite */ /* Why? We can still call filemap_fdatawrite */
goto out_putf; ret = -EINVAL;
goto out;
} }
mapping = file->f_mapping;
current->flags |= PF_SYNCWRITE; current->flags |= PF_SYNCWRITE;
ret = filemap_fdatawrite(mapping); ret = filemap_fdatawrite(mapping);
/* /*
* We need to protect against concurrent writers, * We need to protect against concurrent writers, which could cause
* which could cause livelocks in fsync_buffers_list * livelocks in fsync_buffers_list().
*/ */
mutex_lock(&mapping->host->i_mutex); mutex_lock(&mapping->host->i_mutex);
err = file->f_op->fsync(file, file->f_dentry, datasync); err = file->f_op->fsync(file, file->f_dentry, datasync);
...@@ -362,21 +355,31 @@ static long do_fsync(unsigned int fd, int datasync) ...@@ -362,21 +355,31 @@ static long do_fsync(unsigned int fd, int datasync)
if (!ret) if (!ret)
ret = err; ret = err;
current->flags &= ~PF_SYNCWRITE; current->flags &= ~PF_SYNCWRITE;
out:
return ret;
}
out_putf: static long __do_fsync(unsigned int fd, int datasync)
{
struct file *file;
int ret = -EBADF;
file = fget(fd);
if (file) {
ret = do_fsync(file, datasync);
fput(file); fput(file);
out: }
return ret; return ret;
} }
asmlinkage long sys_fsync(unsigned int fd) asmlinkage long sys_fsync(unsigned int fd)
{ {
return do_fsync(fd, 0); return __do_fsync(fd, 0);
} }
asmlinkage long sys_fdatasync(unsigned int fd) asmlinkage long sys_fdatasync(unsigned int fd)
{ {
return do_fsync(fd, 1); return __do_fsync(fd, 1);
} }
/* /*
......
...@@ -1478,6 +1478,7 @@ extern int wait_on_page_writeback_range(struct address_space *mapping, ...@@ -1478,6 +1478,7 @@ extern int wait_on_page_writeback_range(struct address_space *mapping,
extern int __filemap_fdatawrite_range(struct address_space *mapping, extern int __filemap_fdatawrite_range(struct address_space *mapping,
loff_t start, loff_t end, int sync_mode); loff_t start, loff_t end, int sync_mode);
extern long do_fsync(struct file *file, int datasync);
extern void sync_supers(void); extern void sync_supers(void);
extern void sync_filesystems(int wait); extern void sync_filesystems(int wait);
extern void emergency_sync(void); extern void emergency_sync(void);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment