vfs: wrap write f_ops with file_{start,end}_write()
authorAmir Goldstein <amir73il@gmail.com>
Tue, 31 Jan 2017 08:34:57 +0000 (10:34 +0200)
committerMiklos Szeredi <mszeredi@redhat.com>
Tue, 7 Feb 2017 14:05:04 +0000 (15:05 +0100)
Before calling write f_ops, call file_start_write() instead
of sb_start_write().

Replace {sb,file}_start_write() for {copy,clone}_file_range() and
for fallocate().

Beyond correct semantics, this avoids freeze protection to sb when
operating on special inodes, such as fallocate() on a blockdev.

Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/open.c
fs/read_write.c
include/linux/fs.h

index f9118f4113e7e4573697f8371381e6ceb50f6ff7..949cef29c3bba9395efd2e461d2078d0a9a9b47c 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -314,7 +314,7 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
        if (!file->f_op->fallocate)
                return -EOPNOTSUPP;
 
-       sb_start_write(inode->i_sb);
+       file_start_write(file);
        ret = file->f_op->fallocate(file, mode, offset, len);
 
        /*
@@ -327,7 +327,7 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
        if (ret == 0)
                fsnotify_modify(file);
 
-       sb_end_write(inode->i_sb);
+       file_end_write(file);
        return ret;
 }
 EXPORT_SYMBOL_GPL(vfs_fallocate);
index 511178d7723ba9737b33049c67ff68e387840cfa..820a3f06c46a1acf1111292c47f50035bea6292b 100644 (file)
@@ -1543,7 +1543,7 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,
        if (len == 0)
                return 0;
 
-       sb_start_write(inode_out->i_sb);
+       file_start_write(file_out);
 
        /*
         * Try cloning first, this is supported by more file systems, and
@@ -1579,7 +1579,7 @@ done:
        inc_syscr(current);
        inc_syscw(current);
 
-       sb_end_write(inode_out->i_sb);
+       file_end_write(file_out);
 
        return ret;
 }
index 4a7f3cc9edab4b29f3a0656e8d9504eee0c73dde..78c81e6f5d76f72fb24bb1f583635953fd3f9d74 100644 (file)
@@ -1741,19 +1741,6 @@ extern int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff,
 extern int vfs_dedupe_file_range(struct file *file,
                                 struct file_dedupe_range *same);
 
-static inline int do_clone_file_range(struct file *file_in, loff_t pos_in,
-                                     struct file *file_out, loff_t pos_out,
-                                     u64 len)
-{
-       int ret;
-
-       sb_start_write(file_inode(file_out)->i_sb);
-       ret = vfs_clone_file_range(file_in, pos_in, file_out, pos_out, len);
-       sb_end_write(file_inode(file_out)->i_sb);
-
-       return ret;
-}
-
 struct super_operations {
        struct inode *(*alloc_inode)(struct super_block *sb);
        void (*destroy_inode)(struct inode *);
@@ -2564,6 +2551,19 @@ static inline void file_end_write(struct file *file)
        __sb_end_write(file_inode(file)->i_sb, SB_FREEZE_WRITE);
 }
 
+static inline int do_clone_file_range(struct file *file_in, loff_t pos_in,
+                                     struct file *file_out, loff_t pos_out,
+                                     u64 len)
+{
+       int ret;
+
+       file_start_write(file_out);
+       ret = vfs_clone_file_range(file_in, pos_in, file_out, pos_out, len);
+       file_end_write(file_out);
+
+       return ret;
+}
+
 /*
  * get_write_access() gets write permission for a file.
  * put_write_access() releases this write permission.