All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Patrick J. LoPresti" <lopresti@gmail.com>
To: linux-nfs@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] nfs: lookupcache coherence bugs in WCC update path
Date: Wed, 11 Aug 2010 16:02:53 -0700	[thread overview]
Message-ID: <87lj8ckb1e.fsf@patl.com> (raw)

This patch fixes some coherence bugs in the NFS "dentry lookup cache".

The NFS dentry lookup cache provides the nfs_force_lookup_revalidate()
call to invalidate all cached dentries associated with an inode.  In
general, the NFS client uses the ctime and mtime in the inode to detect
when changes are made on the server.

Therefore, to maintain cache coherence, nfs_force_lookup_revalidate()
must be called whenever the ctime or mtime of a directory inode is
updated with fresh data from the server.  There are a few spots in
nfs_wcc_update_inode() where this rule is violated, making it possible
for the lookup cache to return arbitrarily stale data.

This actually bit me in practice.  I have an application where a
negative dentry results in -ENOENT for a file that was created 30+
minutes earlier (despite the "noac" mount option).  Unfortunately I
cannot share my test case, but I believe the following simple patch is
"obviously correct", and I can confirm that it fixes my issue.

CC: stable <stable@kernel.org>
Signed-off-by: Patrick LoPresti <lopresti@gmail.com>

---

--- linux-2.6.35/fs/nfs/inode.c.orig	2010-08-01 15:11:14.000000000 -0700
+++ linux-2.6.35/fs/nfs/inode.c	2010-08-11 14:19:56.000000000 -0700
@@ -819,21 +819,28 @@ static void nfs_wcc_update_inode(struct
 			&& (fattr->valid & NFS_ATTR_FATTR_CHANGE)
 			&& nfsi->change_attr == fattr->pre_change_attr) {
 		nfsi->change_attr = fattr->change_attr;
-		if (S_ISDIR(inode->i_mode))
+		if (S_ISDIR(inode->i_mode)) {
 			nfsi->cache_validity |= NFS_INO_INVALID_DATA;
+			nfs_force_lookup_revalidate(inode);
+		}
 	}
 	/* If we have atomic WCC data, we may update some attributes */
 	if ((fattr->valid & NFS_ATTR_FATTR_PRECTIME)
 			&& (fattr->valid & NFS_ATTR_FATTR_CTIME)
-			&& timespec_equal(&inode->i_ctime, &fattr->pre_ctime))
-			memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime));
+			&& timespec_equal(&inode->i_ctime,
+					  &fattr->pre_ctime)) {
+		if (S_ISDIR(inode->i_mode))
+			nfs_force_lookup_revalidate(inode);
+		memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime));
+	}
 
 	if ((fattr->valid & NFS_ATTR_FATTR_PREMTIME)
 			&& (fattr->valid & NFS_ATTR_FATTR_MTIME)
 			&& timespec_equal(&inode->i_mtime, &fattr->pre_mtime)) {
 			memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime));
-			if (S_ISDIR(inode->i_mode))
+			if (S_ISDIR(inode->i_mode)) {
 				nfsi->cache_validity |= NFS_INO_INVALID_DATA;
+				nfs_force_lookup_revalidate(inode);
 	}
 	if ((fattr->valid & NFS_ATTR_FATTR_PRESIZE)
 			&& (fattr->valid & NFS_ATTR_FATTR_SIZE)

             reply	other threads:[~2010-08-11 23:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-11 23:02 Patrick J. LoPresti [this message]
2010-08-12  5:26 ` [PATCH] nfs: lookupcache coherence bugs in WCC update path (revised) Patrick J. LoPresti
2010-08-12 15:49   ` Trond Myklebust
2010-08-12 17:13     ` Patrick J. LoPresti
2010-08-12 17:26       ` Trond Myklebust
2010-08-12 17:48         ` Patrick J. LoPresti
2010-08-12 18:50         ` Patrick J. LoPresti
2010-08-13  5:16           ` Patrick J. LoPresti
2010-08-13 12:36             ` J. Bruce Fields
2010-08-13 12:36               ` J. Bruce Fields
2010-08-13 18:30               ` Patrick J. LoPresti
2010-08-13 18:30                 ` Patrick J. LoPresti

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=87lj8ckb1e.fsf@patl.com \
    --to=lopresti@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.