From owner-svn-src-stable-7@FreeBSD.ORG Thu Jun 10 20:13:23 2010 Return-Path: Delivered-To: svn-src-stable-7@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8A1CE1065674; Thu, 10 Jun 2010 20:13:23 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from svn.freebsd.org (unknown [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 6E6BD8FC13; Thu, 10 Jun 2010 20:13:23 +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 o5AKDNrs053159; Thu, 10 Jun 2010 20:13:23 GMT (envelope-from jhb@svn.freebsd.org) Received: (from jhb@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o5AKDNGY053157; Thu, 10 Jun 2010 20:13:23 GMT (envelope-from jhb@svn.freebsd.org) Message-Id: <201006102013.o5AKDNGY053157@svn.freebsd.org> From: John Baldwin Date: Thu, 10 Jun 2010 20:13:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r209005 - stable/7/sys/nfsclient X-BeenThere: svn-src-stable-7@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 7-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Jun 2010 20:13:23 -0000 Author: jhb Date: Thu Jun 10 20:13:23 2010 New Revision: 209005 URL: http://svn.freebsd.org/changeset/base/209005 Log: MFC 208603: 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. Modified: stable/7/sys/nfsclient/nfs_vnops.c Directory Properties: stable/7/sys/ (props changed) stable/7/sys/cddl/contrib/opensolaris/ (props changed) stable/7/sys/contrib/dev/acpica/ (props changed) stable/7/sys/contrib/pf/ (props changed) Modified: stable/7/sys/nfsclient/nfs_vnops.c ============================================================================== --- stable/7/sys/nfsclient/nfs_vnops.c Thu Jun 10 20:13:10 2010 (r209004) +++ stable/7/sys/nfsclient/nfs_vnops.c Thu Jun 10 20:13:23 2010 (r209005) @@ -875,7 +875,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; int v3 = NFS_ISV3(dvp); struct thread *td = cnp->cn_thread; @@ -901,10 +901,26 @@ 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, td) - && 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; + mtx_unlock(&newnp->n_mtx); + } + if (VOP_GETATTR(newvp, &vattr, cnp->cn_cred, td) == 0 && + vattr.va_ctime.tv_sec == newnp->n_ctime) { nfsstats.lookupcache_hits++; if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN))