From owner-svn-src-all@FreeBSD.ORG Thu Aug 5 19:11:14 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 12CB71065672; Thu, 5 Aug 2010 19:11:14 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 0068F8FC0A; Thu, 5 Aug 2010 19:11:14 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o75JBDkP079545; Thu, 5 Aug 2010 19:11:13 GMT (envelope-from jhb@svn.freebsd.org) Received: (from jhb@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o75JBDMa079543; Thu, 5 Aug 2010 19:11:13 GMT (envelope-from jhb@svn.freebsd.org) Message-Id: <201008051911.o75JBDMa079543@svn.freebsd.org> From: John Baldwin Date: Thu, 5 Aug 2010 19:11:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r210884 - stable/8/sys/fs/nfsclient X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Aug 2010 19:11:14 -0000 Author: jhb Date: Thu Aug 5 19:11:13 2010 New Revision: 210884 URL: http://svn.freebsd.org/changeset/base/210884 Log: MFC 210135: Move attribute cache flushes from VOP_OPEN() to VOP_LOOKUP() to provide more graceful recovery for stale filehandles and eliminate the need for conditionally clearing the attribute cache in the !NMODIFIED case in VOP_OPEN(). Modified: stable/8/sys/fs/nfsclient/nfs_clvnops.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cam/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/fs/nfsclient/nfs_clvnops.c ============================================================================== --- stable/8/sys/fs/nfsclient/nfs_clvnops.c Thu Aug 5 19:08:54 2010 (r210883) +++ stable/8/sys/fs/nfsclient/nfs_clvnops.c Thu Aug 5 19:11:13 2010 (r210884) @@ -516,9 +516,11 @@ nfs_open(struct vop_open_args *ap) (void) nfsrpc_close(vp, 0, ap->a_td); return (error); } + mtx_lock(&np->n_mtx); np->n_attrstamp = 0; if (vp->v_type == VDIR) np->n_direofoffset = 0; + mtx_unlock(&np->n_mtx); error = VOP_GETATTR(vp, &vattr, ap->a_cred); if (error) { if (NFS_ISV4(vp)) @@ -531,14 +533,6 @@ nfs_open(struct vop_open_args *ap) np->n_change = vattr.va_filerev; mtx_unlock(&np->n_mtx); } else { - struct thread *td = curthread; - - if (np->n_ac_ts_syscalls != td->td_syscalls || - np->n_ac_ts_tid != td->td_tid || - td->td_proc == NULL || - np->n_ac_ts_pid != td->td_proc->p_pid) { - np->n_attrstamp = 0; - } mtx_unlock(&np->n_mtx); error = VOP_GETATTR(vp, &vattr, ap->a_cred); if (error) { @@ -998,7 +992,7 @@ nfs_lookup(struct vop_lookup_args *ap) int flags = cnp->cn_flags; struct vnode *newvp; struct nfsmount *nmp; - struct nfsnode *np; + struct nfsnode *np, *newnp; int error = 0, attrflag, dattrflag, ltype; struct thread *td = cnp->cn_thread; struct nfsfh *nfhp; @@ -1034,11 +1028,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; + newnp = VTONFS(newvp); + if ((flags & (ISLASTCN | ISOPEN)) == (ISLASTCN | ISOPEN) && + !(newnp->n_flag & NMODIFIED)) { + mtx_lock(&newnp->n_mtx); + newnp->n_attrstamp = 0; + mtx_unlock(&newnp->n_mtx); + } if (nfscl_nodeleg(newvp, 0) == 0 || - (!VOP_GETATTR(newvp, &vattr, cnp->cn_cred) - && vattr.va_ctime.tv_sec == VTONFS(newvp)->n_ctime)) { + (VOP_GETATTR(newvp, &vattr, cnp->cn_cred) == 0 && + vattr.va_ctime.tv_sec == newnp->n_ctime)) { NFSINCRGLOBAL(newnfsstats.lookupcache_hits); if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN)) @@ -1224,6 +1234,18 @@ nfs_lookup(struct vop_lookup_args *ap) if (attrflag) (void) nfscl_loadattrcache(&newvp, &nfsva, NULL, NULL, 0, 1); + else if ((flags & (ISLASTCN | ISOPEN)) == (ISLASTCN | ISOPEN) && + !(np->n_flag & NMODIFIED)) { + /* + * Flush the attribute cache when opening a + * leaf node to ensure that fresh attributes + * are fetched in nfs_open() since we did not + * fetch attributes from the LOOKUP reply. + */ + mtx_lock(&np->n_mtx); + np->n_attrstamp = 0; + mtx_unlock(&np->n_mtx); + } } if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN)) cnp->cn_flags |= SAVENAME;