Commit 18dd78c4 authored by Scott Mayhew's avatar Scott Mayhew Committed by Trond Myklebust

nfs: Fix cache_validity check in nfs_write_pageuptodate()

NFS_INO_INVALID_DATA cannot be ignored, even if we have a delegation.

We're still having some problems with data corruption when multiple
clients are appending to a file and those clients are being granted
write delegations on open.

To reproduce:

Client A:
vi /mnt/`hostname -s`
while :; do echo "XXXXXXXXXXXXXXX" >>/mnt/file; sleep $(( $RANDOM % 5 )); done

Client B:
vi /mnt/`hostname -s`
while :; do echo "YYYYYYYYYYYYYYY" >>/mnt/file; sleep $(( $RANDOM % 5 )); done

What's happening is that in nfs_update_inode() we're recognizing that
the file size has changed and we're setting NFS_INO_INVALID_DATA
accordingly, but then we ignore the cache_validity flags in
nfs_write_pageuptodate() because we have a delegation.  As a result,
in nfs_updatepage() we're extending the write to cover the full page
even though we've not read in the data to begin with.
Signed-off-by: default avatarScott Mayhew <smayhew@redhat.com>
Cc: <stable@vger.kernel.org> # v3.11+
Signed-off-by: default avatarTrond Myklebust <trond.myklebust@primarydata.com>
parent a497c3ba
...@@ -934,12 +934,14 @@ static bool nfs_write_pageuptodate(struct page *page, struct inode *inode) ...@@ -934,12 +934,14 @@ static bool nfs_write_pageuptodate(struct page *page, struct inode *inode)
if (nfs_have_delegated_attributes(inode)) if (nfs_have_delegated_attributes(inode))
goto out; goto out;
if (nfsi->cache_validity & (NFS_INO_INVALID_DATA|NFS_INO_REVAL_PAGECACHE)) if (nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE)
return false; return false;
smp_rmb(); smp_rmb();
if (test_bit(NFS_INO_INVALIDATING, &nfsi->flags)) if (test_bit(NFS_INO_INVALIDATING, &nfsi->flags))
return false; return false;
out: out:
if (nfsi->cache_validity & NFS_INO_INVALID_DATA)
return false;
return PageUptodate(page) != 0; return PageUptodate(page) != 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment