use mutex and rwlock rather than lockmgr.
This commit is contained in:
parent
10a11a26b3
commit
6d6b5c51d6
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: nfs_bio.c,v 1.146 2006/12/27 12:10:09 yamt Exp $ */
|
||||
/* $NetBSD: nfs_bio.c,v 1.147 2007/02/15 16:01:51 yamt Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
@ -35,7 +35,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: nfs_bio.c,v 1.146 2006/12/27 12:10:09 yamt Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: nfs_bio.c,v 1.147 2007/02/15 16:01:51 yamt Exp $");
|
||||
|
||||
#include "opt_nfs.h"
|
||||
#include "opt_ddb.h"
|
||||
@ -966,7 +966,7 @@ nfs_doio_write(bp, uiop)
|
||||
#ifndef NFS_V2_ONLY
|
||||
again:
|
||||
#endif
|
||||
lockmgr(&nmp->nm_writeverflock, LK_SHARED, NULL);
|
||||
rw_enter(&nmp->nm_writeverflock, RW_READER);
|
||||
|
||||
for (i = 0; i < npages; i++) {
|
||||
pgs[i] = uvm_pageratop((vaddr_t)bp->b_data + (i << PAGE_SHIFT));
|
||||
@ -1029,7 +1029,7 @@ again:
|
||||
|
||||
off = uiop->uio_offset;
|
||||
cnt = bp->b_bcount;
|
||||
lockmgr(&np->n_commitlock, LK_EXCLUSIVE, NULL);
|
||||
mutex_enter(&np->n_commitlock);
|
||||
if (!nfs_in_committed_range(vp, off, bp->b_bcount)) {
|
||||
boolean_t pushedrange;
|
||||
if (nfs_in_tobecommitted_range(vp, off, bp->b_bcount)) {
|
||||
@ -1050,8 +1050,8 @@ again:
|
||||
} else {
|
||||
error = 0;
|
||||
}
|
||||
lockmgr(&np->n_commitlock, LK_RELEASE, NULL);
|
||||
lockmgr(&nmp->nm_writeverflock, LK_RELEASE, NULL);
|
||||
mutex_exit(&np->n_commitlock);
|
||||
rw_exit(&nmp->nm_writeverflock);
|
||||
if (!error) {
|
||||
/*
|
||||
* pages are now on stable storage.
|
||||
@ -1085,7 +1085,7 @@ again:
|
||||
/*
|
||||
* we need to commit pages later.
|
||||
*/
|
||||
lockmgr(&np->n_commitlock, LK_EXCLUSIVE, NULL);
|
||||
mutex_enter(&np->n_commitlock);
|
||||
nfs_add_tobecommitted_range(vp, off, cnt);
|
||||
/*
|
||||
* if there can be too many uncommitted pages, commit them now.
|
||||
@ -1113,16 +1113,16 @@ again:
|
||||
}
|
||||
simple_unlock(&uobj->vmobjlock);
|
||||
}
|
||||
lockmgr(&np->n_commitlock, LK_RELEASE, NULL);
|
||||
mutex_exit(&np->n_commitlock);
|
||||
} else
|
||||
#endif
|
||||
if (!error) {
|
||||
/*
|
||||
* pages are now on stable storage.
|
||||
*/
|
||||
lockmgr(&np->n_commitlock, LK_EXCLUSIVE, NULL);
|
||||
mutex_enter(&np->n_commitlock);
|
||||
nfs_del_committed_range(vp, off, cnt);
|
||||
lockmgr(&np->n_commitlock, LK_RELEASE, NULL);
|
||||
mutex_exit(&np->n_commitlock);
|
||||
simple_lock(&uobj->vmobjlock);
|
||||
for (i = 0; i < npages; i++) {
|
||||
pgs[i]->flags &= ~(PG_NEEDCOMMIT | PG_RDONLY);
|
||||
@ -1137,7 +1137,7 @@ again:
|
||||
np->n_flag |= NWRITEERR;
|
||||
}
|
||||
|
||||
lockmgr(&nmp->nm_writeverflock, LK_RELEASE, NULL);
|
||||
rw_exit(&nmp->nm_writeverflock);
|
||||
|
||||
if (stalewriteverf) {
|
||||
nfs_clearcommit(vp->v_mount);
|
||||
@ -1168,9 +1168,9 @@ nfs_doio_phys(bp, uiop)
|
||||
|
||||
uiop->uio_rw = UIO_WRITE;
|
||||
nfsstats.write_physios++;
|
||||
lockmgr(&nmp->nm_writeverflock, LK_SHARED, NULL);
|
||||
rw_enter(&nmp->nm_writeverflock, RW_READER);
|
||||
error = nfs_writerpc(vp, uiop, &iomode, FALSE, &stalewriteverf);
|
||||
lockmgr(&nmp->nm_writeverflock, LK_RELEASE, NULL);
|
||||
rw_exit(&nmp->nm_writeverflock);
|
||||
if (stalewriteverf) {
|
||||
nfs_clearcommit(bp->b_vp->v_mount);
|
||||
}
|
||||
@ -1310,25 +1310,27 @@ nfs_getpages(v)
|
||||
len = npages << PAGE_SHIFT;
|
||||
|
||||
if (v3) {
|
||||
error = lockmgr(&np->n_commitlock,
|
||||
LK_EXCLUSIVE | (locked ? LK_NOWAIT : 0), NULL);
|
||||
if (error) {
|
||||
KASSERT(locked != 0);
|
||||
if (!locked) {
|
||||
mutex_enter(&np->n_commitlock);
|
||||
} else {
|
||||
error = mutex_tryenter(&np->n_commitlock);
|
||||
if (error) {
|
||||
|
||||
/*
|
||||
* Since PGO_LOCKED is set, we need to unbusy
|
||||
* all pages fetched by genfs_getpages() above,
|
||||
* tell the caller that there are no pages
|
||||
* available and put back original pgs array.
|
||||
*/
|
||||
/*
|
||||
* Since PGO_LOCKED is set, we need to unbusy
|
||||
* all pages fetched by genfs_getpages() above,
|
||||
* tell the caller that there are no pages
|
||||
* available and put back original pgs array.
|
||||
*/
|
||||
|
||||
uvm_lock_pageq();
|
||||
uvm_page_unbusy(pgs, npages);
|
||||
uvm_unlock_pageq();
|
||||
*ap->a_count = 0;
|
||||
memcpy(pgs, opgs,
|
||||
npages * sizeof(struct vm_pages *));
|
||||
return (error);
|
||||
uvm_lock_pageq();
|
||||
uvm_page_unbusy(pgs, npages);
|
||||
uvm_unlock_pageq();
|
||||
*ap->a_count = 0;
|
||||
memcpy(pgs, opgs,
|
||||
npages * sizeof(struct vm_pages *));
|
||||
return (error);
|
||||
}
|
||||
}
|
||||
nfs_del_committed_range(vp, origoffset, len);
|
||||
nfs_del_tobecommitted_range(vp, origoffset, len);
|
||||
@ -1348,7 +1350,7 @@ nfs_getpages(v)
|
||||
simple_unlock(&uobj->vmobjlock);
|
||||
}
|
||||
if (v3) {
|
||||
lockmgr(&np->n_commitlock, LK_RELEASE, NULL);
|
||||
mutex_exit(&np->n_commitlock);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: nfs_node.c,v 1.89 2006/12/28 00:39:03 yamt Exp $ */
|
||||
/* $NetBSD: nfs_node.c,v 1.90 2007/02/15 16:01:51 yamt Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
@ -35,7 +35,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: nfs_node.c,v 1.89 2006/12/28 00:39:03 yamt Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: nfs_node.c,v 1.90 2007/02/15 16:01:51 yamt Exp $");
|
||||
|
||||
#include "opt_nfs.h"
|
||||
|
||||
@ -317,7 +317,10 @@ nfs_reclaim(v)
|
||||
kauth_cred_free(np->n_wcred);
|
||||
|
||||
cache_purge(vp);
|
||||
pool_put(&nfs_node_pool, vp->v_data);
|
||||
if (vp->v_type == VREG) {
|
||||
mutex_destroy(&np->n_commitlock);
|
||||
}
|
||||
pool_put(&nfs_node_pool, np);
|
||||
vp->v_data = NULL;
|
||||
return (0);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: nfs_subs.c,v 1.179 2006/12/27 12:10:09 yamt Exp $ */
|
||||
/* $NetBSD: nfs_subs.c,v 1.180 2007/02/15 16:01:51 yamt Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
@ -70,7 +70,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: nfs_subs.c,v 1.179 2006/12/27 12:10:09 yamt Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: nfs_subs.c,v 1.180 2007/02/15 16:01:51 yamt Exp $");
|
||||
|
||||
#include "fs_nfs.h"
|
||||
#include "opt_nfs.h"
|
||||
@ -1667,7 +1667,7 @@ nfs_loadattrcache(vpp, fp, vaper, flags)
|
||||
extern int (**fifo_nfsv2nodeop_p) __P((void *));
|
||||
vp->v_op = fifo_nfsv2nodeop_p;
|
||||
} else if (vp->v_type == VREG) {
|
||||
lockinit(&np->n_commitlock, PINOD, "nfsclock", 0, 0);
|
||||
mutex_init(&np->n_commitlock, MUTEX_DEFAULT, IPL_NONE);
|
||||
} else if (vp->v_type == VCHR || vp->v_type == VBLK) {
|
||||
vp->v_op = spec_nfsv2nodeop_p;
|
||||
nvp = checkalias(vp, (dev_t)rdev, vp->v_mount);
|
||||
@ -2639,7 +2639,7 @@ nfs_clearcommit(mp)
|
||||
struct vm_page *pg;
|
||||
struct nfsmount *nmp = VFSTONFS(mp);
|
||||
|
||||
lockmgr(&nmp->nm_writeverflock, LK_EXCLUSIVE, NULL);
|
||||
rw_enter(&nmp->nm_writeverflock, RW_WRITER);
|
||||
|
||||
TAILQ_FOREACH(vp, &mp->mnt_vnodelist, v_mntvnodes) {
|
||||
KASSERT(vp->v_mount == mp);
|
||||
@ -2659,7 +2659,7 @@ nfs_clearcommit(mp)
|
||||
simple_lock(&nmp->nm_slock);
|
||||
nmp->nm_iflag &= ~NFSMNT_STALEWRITEVERF;
|
||||
simple_unlock(&nmp->nm_slock);
|
||||
lockmgr(&nmp->nm_writeverflock, LK_RELEASE, NULL);
|
||||
rw_exit(&nmp->nm_writeverflock);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: nfs_vfsops.c,v 1.171 2007/01/19 14:49:11 hannken Exp $ */
|
||||
/* $NetBSD: nfs_vfsops.c,v 1.172 2007/02/15 16:01:51 yamt Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993, 1995
|
||||
@ -35,7 +35,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: nfs_vfsops.c,v 1.171 2007/01/19 14:49:11 hannken Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: nfs_vfsops.c,v 1.172 2007/02/15 16:01:51 yamt Exp $");
|
||||
|
||||
#if defined(_KERNEL_OPT)
|
||||
#include "opt_compat_netbsd.h"
|
||||
@ -723,7 +723,7 @@ mountnfs(argp, mp, nam, pth, hst, vpp, l)
|
||||
mp->mnt_data = nmp;
|
||||
TAILQ_INIT(&nmp->nm_uidlruhead);
|
||||
TAILQ_INIT(&nmp->nm_bufq);
|
||||
lockinit(&nmp->nm_writeverflock, PRIBIO, "nfswverf", 0, 0);
|
||||
rw_init(&nmp->nm_writeverflock);
|
||||
simple_lock_init(&nmp->nm_slock);
|
||||
}
|
||||
vfs_getnewfsid(mp);
|
||||
@ -817,6 +817,7 @@ mountnfs(argp, mp, nam, pth, hst, vpp, l)
|
||||
return (0);
|
||||
bad:
|
||||
nfs_disconnect(nmp);
|
||||
rw_destroy(&nmp->nm_writeverflock);
|
||||
free((caddr_t)nmp, M_NFSMNT);
|
||||
m_freem(nam);
|
||||
return (error);
|
||||
@ -889,6 +890,7 @@ nfs_unmount(struct mount *mp, int mntflags, struct lwp *l)
|
||||
nfs_disconnect(nmp);
|
||||
m_freem(nmp->nm_nam);
|
||||
|
||||
rw_destroy(&nmp->nm_writeverflock);
|
||||
free(nmp, M_NFSMNT);
|
||||
return (0);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: nfsmount.h,v 1.41 2006/12/27 12:10:09 yamt Exp $ */
|
||||
/* $NetBSD: nfsmount.h,v 1.42 2007/02/15 16:01:51 yamt Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
@ -38,6 +38,7 @@
|
||||
#ifndef _NFS_NFSMOUNT_H_
|
||||
#define _NFS_NFSMOUNT_H_
|
||||
#ifdef _KERNEL
|
||||
#include <sys/rwlock.h>
|
||||
#include <sys/disk.h>
|
||||
#endif
|
||||
|
||||
@ -152,7 +153,7 @@ struct nfsmount {
|
||||
char *nm_authstr; /* Authenticator string */
|
||||
char *nm_verfstr; /* and the verifier */
|
||||
int nm_verflen;
|
||||
struct lock nm_writeverflock; /* lock for below */
|
||||
krwlock_t nm_writeverflock; /* lock for below */
|
||||
u_char nm_writeverf[NFSX_V3WRITEVERF]; /* V3 write verifier */
|
||||
NFSKERBKEY_T nm_key; /* and the session key */
|
||||
int nm_numuids; /* Number of nfsuid mappings */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: nfsnode.h,v 1.60 2006/12/28 00:39:03 yamt Exp $ */
|
||||
/* $NetBSD: nfsnode.h,v 1.61 2007/02/15 16:01:51 yamt Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
@ -38,6 +38,8 @@
|
||||
#ifndef _NFS_NFSNODE_H_
|
||||
#define _NFS_NFSNODE_H_
|
||||
|
||||
#include <sys/mutex.h>
|
||||
|
||||
#ifndef _NFS_NFS_H_
|
||||
#include <nfs/nfs.h>
|
||||
#endif
|
||||
@ -110,7 +112,7 @@ struct nfsnode_reg {
|
||||
off_t nreg_pushedhi; /* Last block in range */
|
||||
off_t nreg_pushlo; /* 1st block in commit range */
|
||||
off_t nreg_pushhi; /* Last block in range */
|
||||
struct lock nreg_commitlock; /* Serialize commits XXX */
|
||||
kmutex_t nreg_commitlock; /* Serialize commits XXX */
|
||||
int nreg_commitflags;
|
||||
int nreg_error; /* Save write error value */
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user