mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Trond Myklebust <trond.myklebust@fys.uio.no>
To: Kenny Simpson <theonetruekenny@yahoo.com>,
	Charles Lever <cel@citi.umich.edu>
Cc: linux-kernel@vger.kernel.org
Subject: Re: another nfs puzzle
Date: Tue, 06 Dec 2005 22:24:40 -0500	[thread overview]
Message-ID: <1133925880.8197.86.camel@lade.trondhjem.org> (raw)
In-Reply-To: <20051206220448.82860.qmail@web34109.mail.mud.yahoo.com>

[-- Attachment #1: Type: text/plain, Size: 375 bytes --]

On Tue, 2005-12-06 at 14:04 -0800, Kenny Simpson wrote:
> Hi again,
>   I am seeing some odd behavior with O_DIRECT.  If a file opened with O_DIRECT has a page mmap'd,
> and the file is extended via pwrite, then the mmap'd region seems to get lost - i.e. it neither
> takes up system memory, nor does it get written out.
> 

Does the attached patch fix it?

Cheers,
  Trond


[-- Attachment #2: linux-2.6.15-27-unmap_before_odirect.dif --]
[-- Type: text/plain, Size: 2119 bytes --]

NFS: Fix another O_DIRECT race

 Ensure we call unmap_mapping_range() and sync dirty pages to disk before
 doing an NFS direct write.

 Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
---

 fs/nfs/direct.c |   43 ++++++++++++++++++++++++-------------------
 1 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c
index a2d2814..ce83000 100644
--- a/fs/nfs/direct.c
+++ b/fs/nfs/direct.c
@@ -111,6 +111,21 @@ nfs_get_user_pages(int rw, unsigned long
 	return result;
 }
 
+static int nfs_sync_mapping(struct address_space *mapping, loff_t offset, size_t len)
+{
+	int ret;
+	if (mapping->nrpages)
+		return 0;
+
+	unmap_mapping_range(mapping, offset, len, 0);
+	ret = filemap_fdatawrite(mapping);
+	if (ret == 0)
+		ret = filemap_fdatawait(mapping);
+	if (ret == 0)
+		ret = nfs_wb_all(mapping->host);
+	return ret;
+}
+
 /**
  * nfs_free_user_pages - tear down page struct array
  * @pages: array of page struct pointers underlying target buffer
@@ -676,15 +691,9 @@ nfs_file_direct_read(struct kiocb *iocb,
 	if (!count)
 		goto out;
 
-	if (mapping->nrpages) {
-		retval = filemap_fdatawrite(mapping);
-		if (retval == 0)
-			retval = nfs_wb_all(inode);
-		if (retval == 0)
-			retval = filemap_fdatawait(mapping);
-		if (retval)
-			goto out;
-	}
+	retval = nfs_sync_mapping(mapping, pos, count);
+	if (retval)
+		goto out;
 
 	retval = nfs_direct_read(inode, ctx, &iov, pos, 1);
 	if (retval > 0)
@@ -762,19 +771,15 @@ nfs_file_direct_write(struct kiocb *iocb
 	if (!count)
 		goto out;
 
-	if (mapping->nrpages) {
-		retval = filemap_fdatawrite(mapping);
-		if (retval == 0)
-			retval = nfs_wb_all(inode);
-		if (retval == 0)
-			retval = filemap_fdatawait(mapping);
-		if (retval)
-			goto out;
-	}
+	retval = nfs_sync_mapping(mapping, pos, count);
+	if (retval)
+		goto out;
 
 	retval = nfs_direct_write(inode, ctx, &iov, pos, 1);
 	if (mapping->nrpages)
-		invalidate_inode_pages2(mapping);
+		invalidate_inode_pages2_range(mapping,
+				pos >> PAGE_CACHE_SHIFT,
+				(pos + count - 1) >> PAGE_CACHE_SHIFT);
 	if (retval > 0)
 		*ppos = pos + retval;
 

  reply	other threads:[~2005-12-07  3:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-06 22:04 Kenny Simpson
2005-12-07  3:24 ` Trond Myklebust [this message]
2005-12-07 14:50   ` Kenny Simpson
2005-12-07 14:01 ` Peter Staubach
2005-12-07 14:11   ` Trond Myklebust
2005-12-07 14:18     ` Peter Staubach
2005-12-07 14:34       ` Trond Myklebust
2005-12-07 15:34         ` Peter Staubach
2005-12-07 15:41           ` Trond Myklebust
2005-12-07 15:56             ` Peter Staubach
2005-12-07 16:09               ` Trond Myklebust
2005-12-07 16:39                 ` Peter Staubach

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=1133925880.8197.86.camel@lade.trondhjem.org \
    --to=trond.myklebust@fys.uio.no \
    --cc=cel@citi.umich.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=theonetruekenny@yahoo.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®