CEPH filesystem development
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: ceph-devel@vger.kernel.org
Subject: [PATCH v2 2/5] ceph: don't call ceph_update_writeable_page from page_mkwrite
Date: Wed, 23 Sep 2020 07:51:58 -0400	[thread overview]
Message-ID: <20200923115201.15664-3-jlayton@kernel.org> (raw)
In-Reply-To: <20200923115201.15664-1-jlayton@kernel.org>

page_mkwrite should only be called with Uptodate pages, so we should
only need to flush incompatible snap contexts.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
 fs/ceph/addr.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index f8b478237ea8..c2c23b468d13 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -1300,7 +1300,6 @@ static int context_is_writeable_or_written(struct inode *inode,
 
 /**
  * ceph_find_incompatible - find an incompatible context and return it
- * @inode: inode associated with page
  * @page: page being dirtied
  *
  * We are only allowed to write into/dirty a page if the page is
@@ -1311,8 +1310,9 @@ static int context_is_writeable_or_written(struct inode *inode,
  * Must be called with page lock held.
  */
 static struct ceph_snap_context *
-ceph_find_incompatible(struct inode *inode, struct page *page)
+ceph_find_incompatible(struct page *page)
 {
+	struct inode *inode = page->mapping->host;
 	struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
 	struct ceph_inode_info *ci = ceph_inode(inode);
 
@@ -1376,7 +1376,7 @@ static int ceph_update_writeable_page(struct file *file,
 	int r;
 
 retry_locked:
-	snapc = ceph_find_incompatible(inode, page);
+	snapc = ceph_find_incompatible(page);
 	if (snapc) {
 		if (IS_ERR(snapc)) {
 			r = PTR_ERR(snapc);
@@ -1689,6 +1689,8 @@ static vm_fault_t ceph_page_mkwrite(struct vm_fault *vmf)
 	inode_inc_iversion_raw(inode);
 
 	do {
+		struct ceph_snap_context *snapc;
+
 		lock_page(page);
 
 		if (page_mkwrite_check_truncate(page, inode) < 0) {
@@ -1697,13 +1699,26 @@ static vm_fault_t ceph_page_mkwrite(struct vm_fault *vmf)
 			break;
 		}
 
-		err = ceph_update_writeable_page(vma->vm_file, off, len, page);
-		if (err >= 0) {
+		snapc = ceph_find_incompatible(page);
+		if (!snapc) {
 			/* success.  we'll keep the page locked. */
 			set_page_dirty(page);
 			ret = VM_FAULT_LOCKED;
+			break;
+		}
+
+		unlock_page(page);
+
+		if (IS_ERR(snapc)) {
+			ret = VM_FAULT_SIGBUS;
+			break;
 		}
-	} while (err == -EAGAIN);
+
+		ceph_queue_writeback(inode);
+		err = wait_event_killable(ci->i_cap_wq,
+				context_is_writeable_or_written(inode, snapc));
+		ceph_put_snap_context(snapc);
+	} while (err == 0);
 
 	if (ret == VM_FAULT_LOCKED ||
 	    ci->i_inline_version != CEPH_INLINE_NONE) {
-- 
2.26.2


  parent reply	other threads:[~2020-09-23 11:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-23 11:51 [PATCH v2 0/5] ceph: addr.c cleanups Jeff Layton
2020-09-23 11:51 ` [PATCH v2 1/5] ceph: break out writeback of incompatible snap context to separate function Jeff Layton
2020-09-23 11:51 ` Jeff Layton [this message]
2020-09-23 11:51 ` [PATCH v2 3/5] ceph: fold ceph_sync_readpages into ceph_readpage Jeff Layton
2020-09-23 11:52 ` [PATCH v2 4/5] ceph: fold ceph_sync_writepages into writepage_nounlock Jeff Layton
2020-09-23 11:52 ` [PATCH v2 5/5] ceph: fold ceph_update_writeable_page into ceph_write_begin Jeff Layton

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=20200923115201.15664-3-jlayton@kernel.org \
    --to=jlayton@kernel.org \
    --cc=ceph-devel@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox