summaryrefslogtreecommitdiffstats
path: root/sys/nfsclient
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2010-05-27 18:07:20 +0000
committerjhb <jhb@FreeBSD.org>2010-05-27 18:07:20 +0000
commit7df451c1cdfd59559eb63234874f255b651c5035 (patch)
tree137d460c6cb6c42aa09e95a90b33d2325e39fae3 /sys/nfsclient
parentb7cd561c87e1dc5ef6c6f30253b92e4700deba0b (diff)
downloadFreeBSD-src-7df451c1cdfd59559eb63234874f255b651c5035.zip
FreeBSD-src-7df451c1cdfd59559eb63234874f255b651c5035.tar.gz
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
Diffstat (limited to 'sys/nfsclient')
-rw-r--r--sys/nfsclient/nfs_vnops.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/sys/nfsclient/nfs_vnops.c b/sys/nfsclient/nfs_vnops.c
index 64953fe..5897111 100644
--- a/sys/nfsclient/nfs_vnops.c
+++ b/sys/nfsclient/nfs_vnops.c
@@ -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))
OpenPOWER on IntegriCloud