nilfs2: fix lock order reversal in chcp operation
[safe/jmp/linux-2.6] / fs / sync.c
index 4e15da0..d104591 100644 (file)
--- a/fs/sync.c
+++ b/fs/sync.c
  */
 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)
+               return 0;
+
        /* Avoid doing twice syncing and cache pruning for quota sync */
        if (!wait) {
                writeout_quota_sb(sb, -1);
@@ -101,7 +108,7 @@ restart:
                spin_unlock(&sb_lock);
 
                down_read(&sb->s_umount);
-               if (!(sb->s_flags & MS_RDONLY) && sb->s_root)
+               if (!(sb->s_flags & MS_RDONLY) && sb->s_root && sb->s_bdi)
                        __sync_filesystem(sb, wait);
                up_read(&sb->s_umount);
 
@@ -176,6 +183,7 @@ int file_fsync(struct file *filp, struct dentry *dentry, int datasync)
                ret = err;
        return ret;
 }
+EXPORT_SYMBOL(file_fsync);
 
 /**
  * vfs_fsync_range - helper to sync a range of data & metadata to disk
@@ -218,7 +226,7 @@ int vfs_fsync_range(struct file *file, struct dentry *dentry, loff_t start,
                goto out;
        }
 
-       ret = filemap_fdatawrite_range(mapping, start, end);
+       ret = filemap_write_and_wait_range(mapping, start, end);
 
        /*
         * We need to protect against concurrent writers, which could cause
@@ -230,9 +238,6 @@ int vfs_fsync_range(struct file *file, struct dentry *dentry, loff_t start,
                ret = err;
        mutex_unlock(&mapping->host->i_mutex);
 
-       err = filemap_fdatawait_range(mapping, start, end);
-       if (!ret)
-               ret = err;
 out:
        return ret;
 }