diff options
author | Amir Goldstein <amir73il@gmail.com> | 2017-01-31 03:34:57 -0500 |
---|---|---|
committer | Miklos Szeredi <mszeredi@redhat.com> | 2017-02-07 09:05:04 -0500 |
commit | bfe219d373cadab761373aeea4c70406bc27ea2c (patch) | |
tree | 781b1664565d45394b4272cc783932b857de67cf | |
parent | 11cbfb10775aa2a01cee966d118049ede9d0bdf2 (diff) |
vfs: wrap write f_ops with file_{start,end}_write()
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>
-rw-r--r-- | fs/open.c | 4 | ||||
-rw-r--r-- | fs/read_write.c | 4 | ||||
-rw-r--r-- | include/linux/fs.h | 26 |
3 files changed, 17 insertions, 17 deletions
@@ -314,7 +314,7 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len) | |||
314 | if (!file->f_op->fallocate) | 314 | if (!file->f_op->fallocate) |
315 | return -EOPNOTSUPP; | 315 | return -EOPNOTSUPP; |
316 | 316 | ||
317 | sb_start_write(inode->i_sb); | 317 | file_start_write(file); |
318 | ret = file->f_op->fallocate(file, mode, offset, len); | 318 | ret = file->f_op->fallocate(file, mode, offset, len); |
319 | 319 | ||
320 | /* | 320 | /* |
@@ -327,7 +327,7 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len) | |||
327 | if (ret == 0) | 327 | if (ret == 0) |
328 | fsnotify_modify(file); | 328 | fsnotify_modify(file); |
329 | 329 | ||
330 | sb_end_write(inode->i_sb); | 330 | file_end_write(file); |
331 | return ret; | 331 | return ret; |
332 | } | 332 | } |
333 | EXPORT_SYMBOL_GPL(vfs_fallocate); | 333 | EXPORT_SYMBOL_GPL(vfs_fallocate); |
diff --git a/fs/read_write.c b/fs/read_write.c index 511178d7723b..820a3f06c46a 100644 --- a/fs/read_write.c +++ b/fs/read_write.c | |||
@@ -1543,7 +1543,7 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, | |||
1543 | if (len == 0) | 1543 | if (len == 0) |
1544 | return 0; | 1544 | return 0; |
1545 | 1545 | ||
1546 | sb_start_write(inode_out->i_sb); | 1546 | file_start_write(file_out); |
1547 | 1547 | ||
1548 | /* | 1548 | /* |
1549 | * Try cloning first, this is supported by more file systems, and | 1549 | * Try cloning first, this is supported by more file systems, and |
@@ -1579,7 +1579,7 @@ done: | |||
1579 | inc_syscr(current); | 1579 | inc_syscr(current); |
1580 | inc_syscw(current); | 1580 | inc_syscw(current); |
1581 | 1581 | ||
1582 | sb_end_write(inode_out->i_sb); | 1582 | file_end_write(file_out); |
1583 | 1583 | ||
1584 | return ret; | 1584 | return ret; |
1585 | } | 1585 | } |
diff --git a/include/linux/fs.h b/include/linux/fs.h index 4a7f3cc9edab..78c81e6f5d76 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h | |||
@@ -1741,19 +1741,6 @@ extern int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff, | |||
1741 | extern int vfs_dedupe_file_range(struct file *file, | 1741 | extern int vfs_dedupe_file_range(struct file *file, |
1742 | struct file_dedupe_range *same); | 1742 | struct file_dedupe_range *same); |
1743 | 1743 | ||
1744 | static inline int do_clone_file_range(struct file *file_in, loff_t pos_in, | ||
1745 | struct file *file_out, loff_t pos_out, | ||
1746 | u64 len) | ||
1747 | { | ||
1748 | int ret; | ||
1749 | |||
1750 | sb_start_write(file_inode(file_out)->i_sb); | ||
1751 | ret = vfs_clone_file_range(file_in, pos_in, file_out, pos_out, len); | ||
1752 | sb_end_write(file_inode(file_out)->i_sb); | ||
1753 | |||
1754 | return ret; | ||
1755 | } | ||
1756 | |||
1757 | struct super_operations { | 1744 | struct super_operations { |
1758 | struct inode *(*alloc_inode)(struct super_block *sb); | 1745 | struct inode *(*alloc_inode)(struct super_block *sb); |
1759 | void (*destroy_inode)(struct inode *); | 1746 | void (*destroy_inode)(struct inode *); |
@@ -2564,6 +2551,19 @@ static inline void file_end_write(struct file *file) | |||
2564 | __sb_end_write(file_inode(file)->i_sb, SB_FREEZE_WRITE); | 2551 | __sb_end_write(file_inode(file)->i_sb, SB_FREEZE_WRITE); |
2565 | } | 2552 | } |
2566 | 2553 | ||
2554 | static inline int do_clone_file_range(struct file *file_in, loff_t pos_in, | ||
2555 | struct file *file_out, loff_t pos_out, | ||
2556 | u64 len) | ||
2557 | { | ||
2558 | int ret; | ||
2559 | |||
2560 | file_start_write(file_out); | ||
2561 | ret = vfs_clone_file_range(file_in, pos_in, file_out, pos_out, len); | ||
2562 | file_end_write(file_out); | ||
2563 | |||
2564 | return ret; | ||
2565 | } | ||
2566 | |||
2567 | /* | 2567 | /* |
2568 | * get_write_access() gets write permission for a file. | 2568 | * get_write_access() gets write permission for a file. |
2569 | * put_write_access() releases this write permission. | 2569 | * put_write_access() releases this write permission. |