All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andreas Gruenbacher <agruenba@redhat.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
	David Sterba <dsterba@suse.com>, Jeff Layton <jlayton@kernel.org>,
	"Theodore Ts'o" <tytso@mit.edu>, Chao Yu <chao@kernel.org>,
	Richard Weinberger <richard@nod.at>
Cc: linux-fsdevel@vger.kernel.org,
	Andreas Gruenbacher <agruenba@redhat.com>,
	Chao Yu <yuchao0@huawei.com>
Subject: [PATCH 5/7] f2fs: Switch to page_mkwrite_check_truncate in f2fs_vm_page_mkwrite
Date: Thu, 13 Feb 2020 21:24:21 +0100	[thread overview]
Message-ID: <20200213202423.23455-6-agruenba@redhat.com> (raw)
In-Reply-To: <20200213202423.23455-1-agruenba@redhat.com>

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(-)

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);
-- 
2.24.1


  parent reply	other threads:[~2020-02-13 20:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-13 20:24 [PATCH 0/7] Switch to page_mkwrite_check_truncate Andreas Gruenbacher
2020-02-13 20:24 ` [PATCH 1/7] fs: Un-inline page_mkwrite_check_truncate Andreas Gruenbacher
2020-02-14 15:11   ` Jan Kara
2020-02-14 20:10   ` [PATCH v2] " Andreas Gruenbacher
2020-02-17 10:33     ` Jan Kara
2020-02-13 20:24 ` [PATCH 2/7] fs: Switch to page_mkwrite_check_truncate in block_page_mkwrite Andreas Gruenbacher
2020-02-13 20:24 ` [PATCH 3/7] ubifs: Switch to page_mkwrite_check_truncate in ubifs_vm_page_mkwrite Andreas Gruenbacher
2020-02-13 20:24 ` [PATCH 4/7] ext4: Switch to page_mkwrite_check_truncate in ext4_page_mkwrite Andreas Gruenbacher
2020-02-13 20:24 ` Andreas Gruenbacher [this message]
2020-02-13 20:24 ` [PATCH 6/7] ceph: Switch to page_mkwrite_check_truncate in ceph_page_mkwrite Andreas Gruenbacher
2020-02-14  0:00   ` Jeff Layton
2020-02-13 20:24 ` [PATCH 7/7] btrfs: Switch to page_mkwrite_check_truncate in btrfs_page_mkwrite Andreas Gruenbacher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200213202423.23455-6-agruenba@redhat.com \
    --to=agruenba@redhat.com \
    --cc=chao@kernel.org \
    --cc=dsterba@suse.com \
    --cc=jlayton@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=richard@nod.at \
    --cc=tytso@mit.edu \
    --cc=viro@zeniv.linux.org.uk \
    --cc=yuchao0@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.