[5/7] f2fs: Switch to page_mkwrite_check_truncate in f2fs_vm_page_mkwrite
diff mbox series

Message ID 20200213202423.23455-6-agruenba@redhat.com
State New
Headers show
Series
  • Switch to page_mkwrite_check_truncate
Related show

Commit Message

Andreas Gruenbacher Feb. 13, 2020, 8:24 p.m. UTC
Use the "page has been truncated" logic in page_mkwrite_check_truncate
instead of reimplementing it here.  Other than with the existing code,
fail with -EFAULT / VM_FAULT_NOPAGE when page_offset(page) == size here
as well, as should be expected.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Acked-by: Chao Yu <yuchao0@huawei.com>
---
 fs/f2fs/file.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

Patch
diff mbox series

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 0d4da644df3b..0d5ac7a92230 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -52,7 +52,7 @@  static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	struct dnode_of_data dn;
 	bool need_alloc = true;
-	int err = 0;
+	int offset, err = 0;
 
 	if (unlikely(f2fs_cp_error(sbi))) {
 		err = -EIO;
@@ -91,11 +91,12 @@  static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
 	file_update_time(vmf->vma->vm_file);
 	down_read(&F2FS_I(inode)->i_mmap_sem);
 	lock_page(page);
-	if (unlikely(page->mapping != inode->i_mapping ||
-			page_offset(page) > i_size_read(inode) ||
-			!PageUptodate(page))) {
+	offset = -EFAULT;
+	if (likely(PageUptodate(page)))
+		offset = page_mkwrite_check_truncate(page, inode);
+	if (unlikely(offset < 0)) {
 		unlock_page(page);
-		err = -EFAULT;
+		err = offset;
 		goto out_sem;
 	}
 
@@ -124,14 +125,8 @@  static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
 	if (PageMappedToDisk(page))
 		goto out_sem;
 
-	/* page is wholly or partially inside EOF */
-	if (((loff_t)(page->index + 1) << PAGE_SHIFT) >
-						i_size_read(inode)) {
-		loff_t offset;
-
-		offset = i_size_read(inode) & ~PAGE_MASK;
+	if (offset != PAGE_SIZE)
 		zero_user_segment(page, offset, PAGE_SIZE);
-	}
 	set_page_dirty(page);
 	if (!PageUptodate(page))
 		SetPageUptodate(page);