summaryrefslogtreecommitdiffstats
path: root/sys/nfsclient
diff options
context:
space:
mode:
authorrmacklem <rmacklem@FreeBSD.org>2012-05-12 12:02:51 +0000
committerrmacklem <rmacklem@FreeBSD.org>2012-05-12 12:02:51 +0000
commit6a6a18bf5cd7caebec476234cbf2b10a703e7716 (patch)
treecec7c23a3a6eb769268eaeb44dacf6f9ac149b47 /sys/nfsclient
parent79b0e4a50a30baea8c74aaa515a5b91047812153 (diff)
downloadFreeBSD-src-6a6a18bf5cd7caebec476234cbf2b10a703e7716.zip
FreeBSD-src-6a6a18bf5cd7caebec476234cbf2b10a703e7716.tar.gz
PR# 165923 reported intermittent write failures for dirty
memory mapped pages being written back on an NFS mount. Since any thread can call VOP_PUTPAGES() to write back a dirty page, the credentials of that thread may not have write access to the file on an NFS server. (Often the uid is 0, which may be mapped to "nobody" in the NFS server.) Although there is no completely correct fix for this (NFS servers check access on every write RPC instead of at open/mmap time), this patch avoids the common cases by holding onto a credential that recently opened the file for writing and uses that credential for the write RPCs being done by VOP_PUTPAGES() for both NFS clients. Tested by: Joel Ray Holveck (joelh at juniper.net) PR: kern/165923 Reviewed by: kib MFC after: 2 weeks
Diffstat (limited to 'sys/nfsclient')
-rw-r--r--sys/nfsclient/nfs_bio.c7
-rw-r--r--sys/nfsclient/nfs_node.c2
-rw-r--r--sys/nfsclient/nfs_vnops.c16
-rw-r--r--sys/nfsclient/nfsnode.h1
4 files changed, 25 insertions, 1 deletions
diff --git a/sys/nfsclient/nfs_bio.c b/sys/nfsclient/nfs_bio.c
index 90fe96e..2ffd822 100644
--- a/sys/nfsclient/nfs_bio.c
+++ b/sys/nfsclient/nfs_bio.c
@@ -275,7 +275,11 @@ nfs_putpages(struct vop_putpages_args *ap)
vp = ap->a_vp;
np = VTONFS(vp);
td = curthread; /* XXX */
- cred = curthread->td_ucred; /* XXX */
+ /* Set the cred to n_writecred for the write rpcs. */
+ if (np->n_writecred != NULL)
+ cred = crhold(np->n_writecred);
+ else
+ cred = crhold(curthread->td_ucred); /* XXX */
nmp = VFSTONFS(vp->v_mount);
pages = ap->a_m;
count = ap->a_count;
@@ -339,6 +343,7 @@ nfs_putpages(struct vop_putpages_args *ap)
iomode = NFSV3WRITE_FILESYNC;
error = (nmp->nm_rpcops->nr_writerpc)(vp, &uio, cred, &iomode, &must_commit);
+ crfree(cred);
pmap_qremove(kva, npages);
relpbuf(bp, &nfs_pbuf_freecnt);
diff --git a/sys/nfsclient/nfs_node.c b/sys/nfsclient/nfs_node.c
index afe3341..3805f6c 100644
--- a/sys/nfsclient/nfs_node.c
+++ b/sys/nfsclient/nfs_node.c
@@ -270,6 +270,8 @@ nfs_reclaim(struct vop_reclaim_args *ap)
free((caddr_t)dp2, M_NFSDIROFF);
}
}
+ if (np->n_writecred != NULL)
+ crfree(np->n_writecred);
if (np->n_fhsize > NFS_SMALLFH) {
free((caddr_t)np->n_fhp, M_NFSBIGFH);
}
diff --git a/sys/nfsclient/nfs_vnops.c b/sys/nfsclient/nfs_vnops.c
index 872317b..ca9edad 100644
--- a/sys/nfsclient/nfs_vnops.c
+++ b/sys/nfsclient/nfs_vnops.c
@@ -507,6 +507,7 @@ nfs_open(struct vop_open_args *ap)
struct vattr vattr;
int error;
int fmode = ap->a_mode;
+ struct ucred *cred;
if (vp->v_type != VREG && vp->v_type != VDIR && vp->v_type != VLNK)
return (EOPNOTSUPP);
@@ -563,7 +564,22 @@ nfs_open(struct vop_open_args *ap)
}
np->n_directio_opens++;
}
+
+ /*
+ * If this is an open for writing, capture a reference to the
+ * credentials, so they can be used by nfs_putpages(). Using
+ * these write credentials is preferable to the credentials of
+ * whatever thread happens to be doing the VOP_PUTPAGES() since
+ * the write RPCs are less likely to fail with EACCES.
+ */
+ if ((fmode & FWRITE) != 0) {
+ cred = np->n_writecred;
+ np->n_writecred = crhold(ap->a_cred);
+ } else
+ cred = NULL;
mtx_unlock(&np->n_mtx);
+ if (cred != NULL)
+ crfree(cred);
vnode_create_vobject(vp, vattr.va_size, ap->a_td);
return (0);
}
diff --git a/sys/nfsclient/nfsnode.h b/sys/nfsclient/nfsnode.h
index 60e5613..c6fa73e 100644
--- a/sys/nfsclient/nfsnode.h
+++ b/sys/nfsclient/nfsnode.h
@@ -128,6 +128,7 @@ struct nfsnode {
uint32_t n_namelen;
int n_directio_opens;
int n_directio_asyncwr;
+ struct ucred *n_writecred; /* Cred. for putpages */
};
#define n_atim n_un1.nf_atim
OpenPOWER on IntegriCloud