public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: linux-kernel@vger.kernel.org
Cc: akpm@linux-foundation.org, mm-commits@vger.kernel.org,
	nickpiggin@yahoo.com.au, trond.myklebust@fys.uio.no
Subject: Re: + git-nfs-vs-nfs-convert-to-new-aops.patch added to -mm tree
Date: Thu, 20 Sep 2007 13:20:47 +0200	[thread overview]
Message-ID: <20070920132047.7c2ee42a@twins> (raw)
In-Reply-To: <200708202301.l7KN1GAH028291@imap1.linux-foundation.org>

On Mon, 20 Aug 2007 15:56:10 -0700 akpm@linux-foundation.org wrote:


> ------------------------------------------------------
> Subject: git-nfs vs nfs-convert-to-new-aops
> From: Andrew Morton <akpm@linux-foundation.org>
> 
> nfi if this is correct.  How am I supposed to know how to work out what to put
> in `copied' in write_end?

I can has broken NFS :-)

nfs_write_begin wants to lock the page itself, but we pass it a locked
page.

> Cc: Nick Piggin <nickpiggin@yahoo.com.au>
> Cc: Trond Myklebust <trond.myklebust@fys.uio.no>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> ---
> 
>  fs/nfs/file.c |    9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff -puN fs/nfs/file.c~git-nfs-vs-nfs-convert-to-new-aops fs/nfs/file.c
> --- a/fs/nfs/file.c~git-nfs-vs-nfs-convert-to-new-aops
> +++ a/fs/nfs/file.c
> @@ -392,6 +392,7 @@ static int nfs_vm_page_mkwrite(struct vm
>  	struct file *filp = vma->vm_file;
>  	unsigned pagelen;
>  	int ret = -EINVAL;
> +	void *fsdata;
>  
>  	lock_page(page);
>  	if (page->mapping != vma->vm_file->f_path.dentry->d_inode->i_mapping)
> @@ -399,9 +400,13 @@ static int nfs_vm_page_mkwrite(struct vm
>  	pagelen = nfs_page_length(page);
>  	if (pagelen == 0)
>  		goto out_unlock;
> -	ret = nfs_prepare_write(filp, page, 0, pagelen);
> +	ret = nfs_write_begin(filp, page->mapping,
> +				(loff_t)page->index << PAGE_CACHE_SHIFT,
> +				pagelen, 0, &page, &fsdata);
>  	if (!ret)
> -		ret = nfs_commit_write(filp, page, 0, pagelen);
> +		ret = nfs_write_end(filp, page->mapping,
> +				(loff_t)page->index << PAGE_CACHE_SHIFT,
> +				pagelen, pagelen, page, fsdata);
>  out_unlock:
>  	unlock_page(page);
>  	return ret;
> _

But even with this patch I deadlock on page lock, just not here
anymore :-/

/me continues the mmap write on nfs adventure...

---
 fs/nfs/file.c |   36 ++++++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 12 deletions(-)

Index: linux-2.6/fs/nfs/file.c
===================================================================
--- linux-2.6.orig/fs/nfs/file.c
+++ linux-2.6/fs/nfs/file.c
@@ -393,22 +393,34 @@ static int nfs_vm_page_mkwrite(struct vm
 	unsigned pagelen;
 	int ret = -EINVAL;
 	void *fsdata;
+	struct address_space *mapping;
+	loff_t offset;
 
 	lock_page(page);
-	if (page->mapping != vma->vm_file->f_path.dentry->d_inode->i_mapping)
-		goto out_unlock;
+	mapping = page->mapping;
+	if (mapping != vma->vm_file->f_path.dentry->d_inode->i_mapping) {
+		unlock_page(page);
+		return -EINVAL;
+	}
 	pagelen = nfs_page_length(page);
-	if (pagelen == 0)
-		goto out_unlock;
-	ret = nfs_write_begin(filp, page->mapping,
-				(loff_t)page->index << PAGE_CACHE_SHIFT,
-				pagelen, 0, &page, &fsdata);
-	if (!ret)
-		ret = nfs_write_end(filp, page->mapping,
-				(loff_t)page->index << PAGE_CACHE_SHIFT,
-				pagelen, pagelen, page, fsdata);
-out_unlock:
+	offset = (loff_t)page->index << PAGE_CACHE_SHIFT;
 	unlock_page(page);
+
+	/*
+	 * we can use mapping after releasing the page lock, because:
+	 * we hold mmap_sem on the fault path, which should pin the vma
+	 * which should pin the file, which pins the dentry which should
+	 * hold a reference on inode.
+	 */
+
+	if (pagelen) {
+		struct page *page2 = NULL;
+		ret = nfs_write_begin(filp, mapping, offset, pagelen,
+			       	0, &page2, &fsdata);
+		if (!ret)
+			ret = nfs_write_end(filp, mapping, offset, pagelen,
+				       	pagelen, page2, fsdata);
+	}
 	return ret;
 }
 

       reply	other threads:[~2007-09-20 11:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200708202301.l7KN1GAH028291@imap1.linux-foundation.org>
2007-09-20 11:20 ` Peter Zijlstra [this message]
2007-09-20 12:37   ` + git-nfs-vs-nfs-convert-to-new-aops.patch added to -mm tree Trond Myklebust
2007-09-24 13:53   ` Peter Zijlstra

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=20070920132047.7c2ee42a@twins \
    --to=peterz@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mm-commits@vger.kernel.org \
    --cc=nickpiggin@yahoo.com.au \
    --cc=trond.myklebust@fys.uio.no \
    /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