diff options
Diffstat (limited to 'fs/btrfs/file.c')
-rw-r--r-- | fs/btrfs/file.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 9260d3478aad..843e920388ed 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c | |||
@@ -635,8 +635,9 @@ static ssize_t btrfs_file_write(struct file *file, const char __user *buf, | |||
635 | size_t count, loff_t *ppos) | 635 | size_t count, loff_t *ppos) |
636 | { | 636 | { |
637 | loff_t pos; | 637 | loff_t pos; |
638 | size_t num_written = 0; | 638 | loff_t start_pos; |
639 | int err = 0; | 639 | ssize_t num_written = 0; |
640 | ssize_t err = 0; | ||
640 | int ret = 0; | 641 | int ret = 0; |
641 | struct inode *inode = file->f_path.dentry->d_inode; | 642 | struct inode *inode = file->f_path.dentry->d_inode; |
642 | struct btrfs_root *root = BTRFS_I(inode)->root; | 643 | struct btrfs_root *root = BTRFS_I(inode)->root; |
@@ -652,7 +653,10 @@ static ssize_t btrfs_file_write(struct file *file, const char __user *buf, | |||
652 | pinned[1] = NULL; | 653 | pinned[1] = NULL; |
653 | if (file->f_flags & O_DIRECT) | 654 | if (file->f_flags & O_DIRECT) |
654 | return -EINVAL; | 655 | return -EINVAL; |
656 | |||
655 | pos = *ppos; | 657 | pos = *ppos; |
658 | start_pos = pos; | ||
659 | |||
656 | vfs_check_frozen(inode->i_sb, SB_FREEZE_WRITE); | 660 | vfs_check_frozen(inode->i_sb, SB_FREEZE_WRITE); |
657 | current->backing_dev_info = inode->i_mapping->backing_dev_info; | 661 | current->backing_dev_info = inode->i_mapping->backing_dev_info; |
658 | err = generic_write_checks(file, &pos, &count, S_ISBLK(inode->i_mode)); | 662 | err = generic_write_checks(file, &pos, &count, S_ISBLK(inode->i_mode)); |
@@ -743,6 +747,13 @@ out: | |||
743 | if (pinned[1]) | 747 | if (pinned[1]) |
744 | page_cache_release(pinned[1]); | 748 | page_cache_release(pinned[1]); |
745 | *ppos = pos; | 749 | *ppos = pos; |
750 | |||
751 | if (num_written > 0 && ((file->f_flags & O_SYNC) || IS_SYNC(inode))) { | ||
752 | err = sync_page_range(inode, inode->i_mapping, | ||
753 | start_pos, num_written); | ||
754 | if (err < 0) | ||
755 | num_written = err; | ||
756 | } | ||
746 | current->backing_dev_info = NULL; | 757 | current->backing_dev_info = NULL; |
747 | return num_written ? num_written : err; | 758 | return num_written ? num_written : err; |
748 | } | 759 | } |