From owner-svn-src-head@FreeBSD.ORG Thu Jul 15 19:21:48 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BFA041065680; Thu, 15 Jul 2010 19:21:48 +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 AE65E8FC0A; Thu, 15 Jul 2010 19:21:48 +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 o6FJLmBO078076; Thu, 15 Jul 2010 19:21:48 GMT (envelope-from jhb@svn.freebsd.org) Received: (from jhb@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o6FJLmRR078074; Thu, 15 Jul 2010 19:21:48 GMT (envelope-from jhb@svn.freebsd.org) Message-Id: <201007151921.o6FJLmRR078074@svn.freebsd.org> From: John Baldwin Date: Thu, 15 Jul 2010 19:21:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r210135 - head/sys/fs/nfsclient X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Jul 2010 19:21:48 -0000 Author: jhb Date: Thu Jul 15 19:21:48 2010 New Revision: 210135 URL: http://svn.freebsd.org/changeset/base/210135 Log: Merge 208603, 209946, and 209948 to the new NFS client: 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(). Reviewed by: rmacklem MFC after: 2 weeks Modified: head/sys/fs/nfsclient/nfs_clvnops.c Modified: head/sys/fs/nfsclient/nfs_clvnops.c ============================================================================== --- head/sys/fs/nfsclient/nfs_clvnops.c Thu Jul 15 19:21:33 2010 (r210134) +++ head/sys/fs/nfsclient/nfs_clvnops.c Thu Jul 15 19:21:48 2010 (r210135) @@ -505,9 +505,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)) @@ -520,14 +522,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) { @@ -987,7 +981,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; @@ -1023,11 +1017,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)) @@ -1213,6 +1223,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;