--- sys/nlm/nlm_prot_impl.c.orig1 2011-08-25 14:49:39.000000000 -0500 +++ sys/nlm/nlm_prot_impl.c 2011-08-25 14:56:59.000000000 -0500 @@ -1774,7 +1774,7 @@ static int nlm_get_vfs_state(struct nlm_host *host, struct svc_req *rqstp, - fhandle_t *fhp, struct vfs_state *vs) + fhandle_t *fhp, struct vfs_state *vs, accmode_t accmode) { int error, exflags; struct ucred *cred = NULL, *credanon; @@ -1815,9 +1815,14 @@ /* * Check cred. */ - error = VOP_ACCESS(vs->vs_vp, VWRITE, cred, curthread); - if (error) + error = VOP_ACCESS(vs->vs_vp, accmode, cred, curthread); + if (error) { + NLM_DEBUG(5, "nlm_get_vfs_state(): (%s) VOP_ACCESS(%s,%d) error=%d\n", + host->nh_caller_name, + accmode == F_RDLCK ? "F_RDLCK":"F_WRLCK", + cred->cr_uid, error); goto out; + } #if __FreeBSD_version < 800011 VOP_UNLOCK(vs->vs_vp, 0, curthread); @@ -1871,6 +1876,7 @@ struct nlm_host *host, *bhost; int error, sysid; struct flock fl; + accmode_t accmode; memset(result, 0, sizeof(*result)); memset(&vs, 0, sizeof(vs)); @@ -1896,7 +1902,8 @@ goto out; } - error = nlm_get_vfs_state(host, rqstp, &fh, &vs); + accmode = argp->exclusive ? VWRITE : VREAD; + error = nlm_get_vfs_state(host, rqstp, &fh, &vs, accmode); if (error) { result->stat.stat = nlm_convert_error(error); goto out; @@ -1967,6 +1974,7 @@ struct nlm_host *host; int error, sysid; struct flock fl; + accmode_t accmode; memset(result, 0, sizeof(*result)); memset(&vs, 0, sizeof(vs)); @@ -2001,7 +2009,8 @@ goto out; } - error = nlm_get_vfs_state(host, rqstp, &fh, &vs); + accmode = argp->exclusive ? VWRITE : VREAD; + error = nlm_get_vfs_state(host, rqstp, &fh, &vs, accmode); if (error) { result->stat.stat = nlm_convert_error(error); goto out; @@ -2155,6 +2164,7 @@ int error, sysid; struct flock fl; struct nlm_async_lock *af; + accmode_t accmode; memset(result, 0, sizeof(*result)); memset(&vs, 0, sizeof(vs)); @@ -2180,7 +2190,8 @@ goto out; } - error = nlm_get_vfs_state(host, rqstp, &fh, &vs); + accmode = argp->exclusive ? VWRITE : VREAD; + error = nlm_get_vfs_state(host, rqstp, &fh, &vs, accmode); if (error) { result->stat.stat = nlm_convert_error(error); goto out; @@ -2244,6 +2255,7 @@ struct nlm_host *host; int error, sysid; struct flock fl; + accmode_t accmode; memset(result, 0, sizeof(*result)); memset(&vs, 0, sizeof(vs)); @@ -2269,7 +2281,8 @@ goto out; } - error = nlm_get_vfs_state(host, rqstp, &fh, &vs); + accmode = VREAD; /* argv->exclusive not in nlm4_unlockargs */ + error = nlm_get_vfs_state(host, rqstp, &fh, &vs, accmode); if (error) { result->stat.stat = nlm_convert_error(error); goto out;