summaryrefslogtreecommitdiffstats
path: root/fs/buffer.c
diff options
context:
space:
mode:
authorAndrew Morton <akpm@osdl.org>2006-03-24 03:18:14 -0800
committerLinus Torvalds <torvalds@g5.osdl.org>2006-03-24 07:33:27 -0800
commit18e79b40ed9c5223b88771f805c69f5993fc131b (patch)
treecc628524d4bfe3166bbe9d8d7217a1cb009ea209 /fs/buffer.c
parent676758bdb7bfca8413a85203921746f446e237be (diff)
downloadlinux-18e79b40ed9c5223b88771f805c69f5993fc131b.tar.bz2
[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: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'fs/buffer.c')
-rw-r--r--fs/buffer.c43
1 files changed, 23 insertions, 20 deletions
diff --git a/fs/buffer.c b/fs/buffer.c
index 24262ea8cc50..6d77ce9f54e5 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -327,31 +327,24 @@ int file_fsync(struct file *filp, struct dentry *dentry, int datasync)
return ret;
}
-static long do_fsync(unsigned int fd, int datasync)
+long do_fsync(struct file *file, int datasync)
{
- struct file * file;
- struct address_space *mapping;
- int ret, err;
-
- ret = -EBADF;
- file = fget(fd);
- if (!file)
- goto out;
+ int ret;
+ int err;
+ struct address_space *mapping = file->f_mapping;
- ret = -EINVAL;
if (!file->f_op || !file->f_op->fsync) {
/* Why? We can still call filemap_fdatawrite */
- goto out_putf;
+ ret = -EINVAL;
+ goto out;
}
- mapping = file->f_mapping;
-
current->flags |= PF_SYNCWRITE;
ret = filemap_fdatawrite(mapping);
/*
- * We need to protect against concurrent writers,
- * which could cause livelocks in fsync_buffers_list
+ * We need to protect against concurrent writers, which could cause
+ * livelocks in fsync_buffers_list().
*/
mutex_lock(&mapping->host->i_mutex);
err = file->f_op->fsync(file, file->f_dentry, datasync);
@@ -362,21 +355,31 @@ static long do_fsync(unsigned int fd, int datasync)
if (!ret)
ret = err;
current->flags &= ~PF_SYNCWRITE;
-
-out_putf:
- fput(file);
out:
return ret;
}
+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);
+ }
+ return ret;
+}
+
asmlinkage long sys_fsync(unsigned int fd)
{
- return do_fsync(fd, 0);
+ return __do_fsync(fd, 0);
}
asmlinkage long sys_fdatasync(unsigned int fd)
{
- return do_fsync(fd, 1);
+ return __do_fsync(fd, 1);
}
/*