]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - fs/sync.c
input: misc: Changed sysfs permissions
[linux-2.6.git] / fs / sync.c
index f3f0a0e1948f0eb87389af19376dddf19c9c17b3..0e8db939d96f8fdaa072df7e6fcadb15a5781a84 100644 (file)
--- a/fs/sync.c
+++ b/fs/sync.c
@@ -6,14 +6,14 @@
 #include <linux/file.h>
 #include <linux/fs.h>
 #include <linux/slab.h>
-#include <linux/module.h>
+#include <linux/export.h>
+#include <linux/namei.h>
 #include <linux/sched.h>
 #include <linux/writeback.h>
 #include <linux/syscalls.h>
 #include <linux/linkage.h>
 #include <linux/pagemap.h>
 #include <linux/quotaops.h>
-#include <linux/buffer_head.h>
 #include <linux/backing-dev.h>
 #include "internal.h"
 
@@ -33,7 +33,7 @@ static int __sync_filesystem(struct super_block *sb, int wait)
         * This should be safe, as we require bdi backing to actually
         * write out data in the first place
         */
-       if (!sb->s_bdi || sb->s_bdi == &noop_backing_dev_info)
+       if (sb->s_bdi == &noop_backing_dev_info)
                return 0;
 
        if (sb->s_qcop && sb->s_qcop->quota_sync)
@@ -42,7 +42,7 @@ static int __sync_filesystem(struct super_block *sb, int wait)
        if (wait)
                sync_inodes_sb(sb);
        else
-               writeback_inodes_sb(sb);
+               writeback_inodes_sb(sb, WB_REASON_SYNC);
 
        if (sb->s_op->sync_fs)
                sb->s_op->sync_fs(sb, wait);
@@ -77,31 +77,18 @@ int sync_filesystem(struct super_block *sb)
 }
 EXPORT_SYMBOL_GPL(sync_filesystem);
 
+static void sync_one_sb(struct super_block *sb, void *arg)
+{
+       if (!(sb->s_flags & MS_RDONLY))
+               __sync_filesystem(sb, *(int *)arg);
+}
 /*
  * Sync all the data for all the filesystems (called by sys_sync() and
  * emergency sync)
  */
 static void sync_filesystems(int wait)
 {
-       struct super_block *sb, *n;
-
-       spin_lock(&sb_lock);
-       list_for_each_entry_safe(sb, n, &super_blocks, s_list) {
-               if (list_empty(&sb->s_instances))
-                       continue;
-               sb->s_count++;
-               spin_unlock(&sb_lock);
-
-               down_read(&sb->s_umount);
-               if (!(sb->s_flags & MS_RDONLY) && sb->s_root && sb->s_bdi)
-                       __sync_filesystem(sb, wait);
-               up_read(&sb->s_umount);
-
-               /* restart only when sb is no longer on the list */
-               spin_lock(&sb_lock);
-               __put_super(sb);
-       }
-       spin_unlock(&sb_lock);
+       iterate_supers(sync_one_sb, &wait);
 }
 
 /*
@@ -110,7 +97,7 @@ static void sync_filesystems(int wait)
  */
 SYSCALL_DEFINE0(sync)
 {
-       wakeup_flusher_threads(0);
+       wakeup_flusher_threads(0, WB_REASON_SYNC);
        sync_filesystems(0);
        sync_filesystems(1);
        if (unlikely(laptop_mode))
@@ -142,36 +129,31 @@ void emergency_sync(void)
 }
 
 /*
- * Generic function to fsync a file.
- *
- * filp may be NULL if called via the msync of a vma.
+ * sync a single super
  */
-int file_fsync(struct file *filp, struct dentry *dentry, int datasync)
+SYSCALL_DEFINE1(syncfs, int, fd)
 {
-       struct inode * inode = dentry->d_inode;
-       struct super_block * sb;
-       int ret, err;
-
-       /* sync the inode to buffers */
-       ret = write_inode_now(inode, 0);
-
-       /* sync the superblock to buffers */
-       sb = inode->i_sb;
-       if (sb->s_dirt && sb->s_op->write_super)
-               sb->s_op->write_super(sb);
-
-       /* .. finally sync the buffers to disk */
-       err = sync_blockdev(sb->s_bdev);
-       if (!ret)
-               ret = err;
+       struct file *file;
+       struct super_block *sb;
+       int ret;
+       int fput_needed;
+
+       file = fget_light(fd, &fput_needed);
+       if (!file)
+               return -EBADF;
+       sb = file->f_dentry->d_sb;
+
+       down_read(&sb->s_umount);
+       ret = sync_filesystem(sb);
+       up_read(&sb->s_umount);
+
+       fput_light(file, fput_needed);
        return ret;
 }
-EXPORT_SYMBOL(file_fsync);
 
 /**
  * vfs_fsync_range - helper to sync a range of data & metadata to disk
  * @file:              file to sync
- * @dentry:            dentry of @file
  * @start:             offset in bytes of the beginning of data range to sync
  * @end:               offset in bytes of the end of data range (inclusive)
  * @datasync:          perform only datasync
@@ -179,69 +161,26 @@ EXPORT_SYMBOL(file_fsync);
  * Write back data in range @start..@end and metadata for @file to disk.  If
  * @datasync is set only metadata needed to access modified file data is
  * written.
- *
- * In case this function is called from nfsd @file may be %NULL and
- * only @dentry is set.  This can only happen when the filesystem
- * implements the export_operations API.
  */
-int vfs_fsync_range(struct file *file, struct dentry *dentry, loff_t start,
-                   loff_t end, int datasync)
+int vfs_fsync_range(struct file *file, loff_t start, loff_t end, int datasync)
 {
-       const struct file_operations *fop;
-       struct address_space *mapping;
-       int err, ret;
-
-       /*
-        * Get mapping and operations from the file in case we have
-        * as file, or get the default values for them in case we
-        * don't have a struct file available.  Damn nfsd..
-        */
-       if (file) {
-               mapping = file->f_mapping;
-               fop = file->f_op;
-       } else {
-               mapping = dentry->d_inode->i_mapping;
-               fop = dentry->d_inode->i_fop;
-       }
-
-       if (!fop || !fop->fsync) {
-               ret = -EINVAL;
-               goto out;
-       }
-
-       ret = filemap_write_and_wait_range(mapping, start, end);
-
-       /*
-        * We need to protect against concurrent writers, which could cause
-        * livelocks in fsync_buffers_list().
-        */
-       mutex_lock(&mapping->host->i_mutex);
-       err = fop->fsync(file, dentry, datasync);
-       if (!ret)
-               ret = err;
-       mutex_unlock(&mapping->host->i_mutex);
-
-out:
-       return ret;
+       if (!file->f_op || !file->f_op->fsync)
+               return -EINVAL;
+       return file->f_op->fsync(file, start, end, datasync);
 }
 EXPORT_SYMBOL(vfs_fsync_range);
 
 /**
  * vfs_fsync - perform a fsync or fdatasync on a file
  * @file:              file to sync
- * @dentry:            dentry of @file
  * @datasync:          only perform a fdatasync operation
  *
  * Write back data and metadata for @file to disk.  If @datasync is
  * set only metadata needed to access modified file data is written.
- *
- * In case this function is called from nfsd @file may be %NULL and
- * only @dentry is set.  This can only happen when the filesystem
- * implements the export_operations API.
  */
-int vfs_fsync(struct file *file, struct dentry *dentry, int datasync)
+int vfs_fsync(struct file *file, int datasync)
 {
-       return vfs_fsync_range(file, dentry, 0, LLONG_MAX, datasync);
+       return vfs_fsync_range(file, 0, LLONG_MAX, datasync);
 }
 EXPORT_SYMBOL(vfs_fsync);
 
@@ -252,7 +191,7 @@ static int do_fsync(unsigned int fd, int datasync)
 
        file = fget(fd);
        if (file) {
-               ret = vfs_fsync(file, file->f_path.dentry, datasync);
+               ret = vfs_fsync(file, datasync);
                fput(file);
        }
        return ret;
@@ -280,8 +219,7 @@ int generic_write_sync(struct file *file, loff_t pos, loff_t count)
 {
        if (!(file->f_flags & O_DSYNC) && !IS_SYNC(file->f_mapping->host))
                return 0;
-       return vfs_fsync_range(file, file->f_path.dentry, pos,
-                              pos + count - 1,
+       return vfs_fsync_range(file, pos, pos + count - 1,
                               (file->f_flags & __O_SYNC) ? 0 : 1);
 }
 EXPORT_SYMBOL(generic_write_sync);