svn commit: r208603 - head/sys/nfsclient
John Baldwin
jhb at FreeBSD.org
Thu May 27 18:07:21 UTC 2010
Author: jhb
Date: Thu May 27 18:07:20 2010
New Revision: 208603
URL: http://svn.freebsd.org/changeset/base/208603
Log:
More gracefully handle stale file handles and attributes when opening a
file via NFS. Specifically, to satisfy close-to-open-consistency, the NFS
client always performs at least one RPC on a file during an open(2) to see
if the file has changed. Normally this RPC is an ACCESS or GETATTR RPC
that is forced by flushing a file's attribute cache during nfs_open() and
then requesting new attributes. However, if the file is noticed to be
stale during nfs_open(), the only recourse is to fail the open(2) call
with ESTALE. On the other hand, if the ACCESS or GETATTR RPC is sent
during nfs_lookup(), then the NFS client can fall back to a LOOKUP RPC to
obtain the new file handle in the case that a file has been replaced.
This change causes the NFS client to flush the attribute cache during
nfs_lookup() when validating a name cache hit if the attributes fetched
during nfs_lookup() can be reused in nfs_open(). This allows the client
to open a replaced file via the new file handle the first time that it
notices a replaced file rather than failing with ESTALE in some cases.
Reviewed by: rmacklem, bde
Reviewed by: mohans (older version)
MFC after: 1 week
Modified:
head/sys/nfsclient/nfs_vnops.c
Modified: head/sys/nfsclient/nfs_vnops.c
==============================================================================
--- head/sys/nfsclient/nfs_vnops.c Thu May 27 15:28:55 2010 (r208602)
+++ head/sys/nfsclient/nfs_vnops.c Thu May 27 18:07:20 2010 (r208603)
@@ -932,7 +932,7 @@ nfs_lookup(struct vop_lookup_args *ap)
struct mbuf *mreq, *mrep, *md, *mb;
long len;
nfsfh_t *fhp;
- struct nfsnode *np;
+ struct nfsnode *np, *newnp;
int error = 0, attrflag, fhsize, ltype;
int v3 = NFS_ISV3(dvp);
struct thread *td = cnp->cn_thread;
@@ -958,10 +958,27 @@ nfs_lookup(struct vop_lookup_args *ap)
* change time of the file matches our cached copy.
* Otherwise, we discard the cache entry and fallback
* to doing a lookup RPC.
+ *
+ * To better handle stale file handles and attributes,
+ * clear the attribute cache of this node if it is a
+ * leaf component, part of an open() call, and not
+ * locally modified before fetching the attributes.
+ * This should allow stale file handles to be detected
+ * here where we can fall back to a LOOKUP RPC to
+ * recover rather than having nfs_open() detect the
+ * stale file handle and failing open(2) with ESTALE.
*/
newvp = *vpp;
- if (!VOP_GETATTR(newvp, &vattr, cnp->cn_cred)
- && vattr.va_ctime.tv_sec == VTONFS(newvp)->n_ctime) {
+ newnp = VTONFS(newvp);
+ if ((cnp->cn_flags & (ISLASTCN | ISOPEN)) ==
+ (ISLASTCN | ISOPEN) && !(newnp->n_flag & NMODIFIED)) {
+ mtx_lock(&newnp->n_mtx);
+ newnp->n_attrstamp = 0;
+ KDTRACE_NFS_ATTRCACHE_FLUSH_DONE(vp);
+ mtx_unlock(&newnp->n_mtx);
+ }
+ if (VOP_GETATTR(newvp, &vattr, cnp->cn_cred) == 0 &&
+ vattr.va_ctime.tv_sec == newnp->n_ctime) {
nfsstats.lookupcache_hits++;
if (cnp->cn_nameiop != LOOKUP &&
(flags & ISLASTCN))
More information about the svn-src-all
mailing list