Commit 716f02ac00a77c14cdf18de2e75e49e68e46e1e8

Authored by Scott Mayhew
Committed by Greg Kroah-Hartman
1 parent ff177fb44d

nfs: Fix cache_validity check in nfs_write_pageuptodate()

commit 18dd78c427513fb0f89365138be66e6ee8700d1b upstream.

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: Scott Mayhew <smayhew@redhat.com>
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 1 changed file with 3 additions and 1 deletions Side-by-side Diff

... ... @@ -913,12 +913,14 @@
913 913  
914 914 if (nfs_have_delegated_attributes(inode))
915 915 goto out;
916   - if (nfsi->cache_validity & (NFS_INO_INVALID_DATA|NFS_INO_REVAL_PAGECACHE))
  916 + if (nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE)
917 917 return false;
918 918 smp_rmb();
919 919 if (test_bit(NFS_INO_INVALIDATING, &nfsi->flags))
920 920 return false;
921 921 out:
  922 + if (nfsi->cache_validity & NFS_INO_INVALID_DATA)
  923 + return false;
922 924 return PageUptodate(page) != 0;
923 925 }
924 926