Change NFS from rbtree to vcache.

This commit is contained in:
hannken 2014-05-30 08:47:45 +00:00
parent fb88097aee
commit ff361c30ec
5 changed files with 58 additions and 134 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: nfs_node.c,v 1.117 2014/02/27 16:51:38 hannken Exp $ */
/* $NetBSD: nfs_node.c,v 1.118 2014/05/30 08:47:45 hannken Exp $ */
/*
* Copyright (c) 1989, 1993
@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: nfs_node.c,v 1.117 2014/02/27 16:51:38 hannken Exp $");
__KERNEL_RCSID(0, "$NetBSD: nfs_node.c,v 1.118 2014/05/30 08:47:45 hannken Exp $");
#ifdef _KERNEL_OPT
#include "opt_nfs.h"
@ -106,48 +106,49 @@ nfs_node_done(void)
workqueue_destroy(nfs_sillyworkq);
}
struct fh_match {
nfsfh_t *fhm_fhp;
size_t fhm_fhsize;
size_t fhm_fhoffset;
};
static int
nfs_compare_nodes(void *ctx, const void *parent, const void *node)
/*
* Initialize this vnode / nfs node pair.
* Caller assures no other thread will try to load this node.
*/
int
nfs_loadvnode(struct mount *mp, struct vnode *vp,
const void *key, size_t key_len, const void **new_key)
{
const struct nfsnode * const pnp = parent;
const struct nfsnode * const np = node;
int fhsize = key_len;
const nfsfh_t *fhp = key;
struct nfsnode *np;
if (pnp->n_fhsize != np->n_fhsize)
return np->n_fhsize - pnp->n_fhsize;
/* Aloocate and initialize the nfsnode. */
np = pool_get(&nfs_node_pool, PR_WAITOK);
memset(np, 0, sizeof *np);
if (fhsize > NFS_SMALLFH) {
np->n_fhp = kmem_alloc(fhsize, KM_SLEEP);
} else
np->n_fhp = &np->n_fh;
vp->v_tag = VT_NFS;
vp->v_type = VNON;
vp->v_op = nfsv2_vnodeop_p;
vp->v_data = np;
memcpy(np->n_fhp, fhp, fhsize);
np->n_fhsize = fhsize;
np->n_accstamp = -1;
np->n_vattr = pool_get(&nfs_vattr_pool, PR_WAITOK);
np->n_vnode = vp;
return memcmp(np->n_fhp, pnp->n_fhp, np->n_fhsize);
}
static int
nfs_compare_node_fh(void *ctx, const void *b, const void *key)
{
const struct nfsnode * const pnp = b;
const struct fh_match * const fhm = key;
if (pnp->n_fhsize != fhm->fhm_fhsize)
return fhm->fhm_fhsize - pnp->n_fhsize;
return memcmp(fhm->fhm_fhp, pnp->n_fhp, pnp->n_fhsize);
}
static const rb_tree_ops_t nfs_node_rbtree_ops = {
.rbto_compare_nodes = nfs_compare_nodes,
.rbto_compare_key = nfs_compare_node_fh,
.rbto_node_offset = offsetof(struct nfsnode, n_rbnode),
.rbto_context = NULL
};
void
nfs_rbtinit(struct nfsmount *nmp)
{
rb_tree_init(&nmp->nm_rbtree, &nfs_node_rbtree_ops);
/* Initialize genfs node. */
genfs_node_init(vp, &nfs_genfsops);
/*
* Initalize read/write creds to useful values. VOP_OPEN will
* overwrite these.
*/
np->n_rcred = curlwp->l_cred;
kauth_cred_hold(np->n_rcred);
np->n_wcred = curlwp->l_cred;
kauth_cred_hold(np->n_wcred);
NFS_INVALIDATE_ATTRCACHE(np);
uvm_vnp_setsize(vp, 0);
*new_key = np->n_fhp;
return 0;
}
/*
@ -160,84 +161,19 @@ int
nfs_nget1(struct mount *mntp, nfsfh_t *fhp, int fhsize, struct nfsnode **npp,
int lkflags)
{
struct nfsnode *np;
struct vnode *vp;
struct nfsmount *nmp = VFSTONFS(mntp);
int error;
struct fh_match fhm;
struct vnode *vp;
fhm.fhm_fhp = fhp;
fhm.fhm_fhsize = fhsize;
loop:
rw_enter(&nmp->nm_rbtlock, RW_READER);
np = rb_tree_find_node(&nmp->nm_rbtree, &fhm);
if (np != NULL) {
vp = NFSTOV(np);
mutex_enter(vp->v_interlock);
rw_exit(&nmp->nm_rbtlock);
error = vget(vp, LK_EXCLUSIVE | lkflags);
if (error == EBUSY)
return error;
if (error)
goto loop;
*npp = np;
return(0);
}
rw_exit(&nmp->nm_rbtlock);
error = getnewvnode(VT_NFS, mntp, nfsv2_vnodeop_p, NULL, &vp);
error = vcache_get(mntp, fhp, fhsize, &vp);
if (error)
return error;
error = vn_lock(vp, LK_EXCLUSIVE | lkflags);
if (error) {
*npp = 0;
return (error);
vrele(vp);
return error;
}
np = pool_get(&nfs_node_pool, PR_WAITOK);
memset(np, 0, sizeof *np);
np->n_vnode = vp;
/*
* Insert the nfsnode in the hash queue for its new file handle
*/
if (fhsize > NFS_SMALLFH) {
np->n_fhp = kmem_alloc(fhsize, KM_SLEEP);
} else
np->n_fhp = &np->n_fh;
memcpy(np->n_fhp, fhp, fhsize);
np->n_fhsize = fhsize;
np->n_accstamp = -1;
np->n_vattr = pool_get(&nfs_vattr_pool, PR_WAITOK);
rw_enter(&nmp->nm_rbtlock, RW_WRITER);
if (NULL != rb_tree_find_node(&nmp->nm_rbtree, &fhm)) {
rw_exit(&nmp->nm_rbtlock);
if (fhsize > NFS_SMALLFH) {
kmem_free(np->n_fhp, fhsize);
}
pool_put(&nfs_vattr_pool, np->n_vattr);
pool_put(&nfs_node_pool, np);
ungetnewvnode(vp);
goto loop;
}
vp->v_data = np;
genfs_node_init(vp, &nfs_genfsops);
/*
* Initalize read/write creds to useful values. VOP_OPEN will
* overwrite these.
*/
np->n_rcred = curlwp->l_cred;
kauth_cred_hold(np->n_rcred);
np->n_wcred = curlwp->l_cred;
kauth_cred_hold(np->n_wcred);
error = VOP_LOCK(vp, LK_EXCLUSIVE);
KASSERT(error == 0);
NFS_INVALIDATE_ATTRCACHE(np);
uvm_vnp_setsize(vp, 0);
(void)rb_tree_insert_node(&nmp->nm_rbtree, np);
rw_exit(&nmp->nm_rbtlock);
*npp = np;
return (0);
*npp = VTONFS(vp);
return 0;
}
int
@ -287,14 +223,11 @@ nfs_reclaim(void *v)
} */ *ap = v;
struct vnode *vp = ap->a_vp;
struct nfsnode *np = VTONFS(vp);
struct nfsmount *nmp = VFSTONFS(vp->v_mount);
if (prtactive && vp->v_usecount > 1)
vprint("nfs_reclaim: pushing active", vp);
rw_enter(&nmp->nm_rbtlock, RW_WRITER);
rb_tree_remove_node(&nmp->nm_rbtree, np);
rw_exit(&nmp->nm_rbtlock);
vcache_remove(vp->v_mount, np->n_fhp, np->n_fhsize);
/*
* Free up any directory cookie structures and

View File

@ -1,4 +1,4 @@
/* $NetBSD: nfs_var.h,v 1.91 2013/12/14 16:19:28 christos Exp $ */
/* $NetBSD: nfs_var.h,v 1.92 2014/05/30 08:47:45 hannken Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -80,7 +80,6 @@ void nfs_kqinit(void);
void nfs_kqfini(void);
/* nfs_node.c */
void nfs_rbtinit(struct nfsmount *);
void nfs_node_init(void);
void nfs_node_done(void);

View File

@ -1,4 +1,4 @@
/* $NetBSD: nfs_vfsops.c,v 1.228 2014/05/24 16:34:04 christos Exp $ */
/* $NetBSD: nfs_vfsops.c,v 1.229 2014/05/30 08:47:45 hannken Exp $ */
/*
* Copyright (c) 1989, 1993, 1995
@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: nfs_vfsops.c,v 1.228 2014/05/24 16:34:04 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: nfs_vfsops.c,v 1.229 2014/05/30 08:47:45 hannken Exp $");
#if defined(_KERNEL_OPT)
#include "opt_nfs.h"
@ -113,6 +113,7 @@ struct vfsops nfs_vfsops = {
.vfs_quotactl = (void *)eopnotsupp,
.vfs_statvfs = nfs_statvfs,
.vfs_sync = nfs_sync,
.vfs_loadvnode = nfs_loadvnode,
.vfs_vget = nfs_vget,
.vfs_fhtovp = nfs_fhtovp,
.vfs_vptofh = nfs_vptofh,
@ -721,12 +722,10 @@ mountnfs(struct nfs_args *argp, struct mount *mp, struct mbuf *nam, const char *
TAILQ_INIT(&nmp->nm_bufq);
rw_init(&nmp->nm_writeverflock);
mutex_init(&nmp->nm_lock, MUTEX_DEFAULT, IPL_NONE);
rw_init(&nmp->nm_rbtlock);
cv_init(&nmp->nm_rcvcv, "nfsrcv");
cv_init(&nmp->nm_sndcv, "nfssnd");
cv_init(&nmp->nm_aiocv, "nfsaio");
cv_init(&nmp->nm_disconcv, "nfsdis");
nfs_rbtinit(nmp);
}
vfs_getnewfsid(mp);
nmp->nm_mountp = mp;
@ -826,7 +825,6 @@ mountnfs(struct nfs_args *argp, struct mount *mp, struct mbuf *nam, const char *
bad:
nfs_disconnect(nmp);
rw_destroy(&nmp->nm_writeverflock);
rw_destroy(&nmp->nm_rbtlock);
mutex_destroy(&nmp->nm_lock);
cv_destroy(&nmp->nm_rcvcv);
cv_destroy(&nmp->nm_sndcv);
@ -903,7 +901,6 @@ nfs_unmount(struct mount *mp, int mntflags)
m_freem(nmp->nm_nam);
rw_destroy(&nmp->nm_writeverflock);
rw_destroy(&nmp->nm_rbtlock);
mutex_destroy(&nmp->nm_lock);
cv_destroy(&nmp->nm_rcvcv);
cv_destroy(&nmp->nm_sndcv);

View File

@ -1,4 +1,4 @@
/* $NetBSD: nfsmount.h,v 1.51 2011/01/22 22:26:10 matt Exp $ */
/* $NetBSD: nfsmount.h,v 1.52 2014/05/30 08:47:45 hannken Exp $ */
/*
* Copyright (c) 1989, 1993
@ -43,7 +43,6 @@
#include <sys/rwlock.h>
#include <sys/mutex.h>
#include <sys/disk.h>
#include <sys/rbtree.h>
#endif
/*
@ -130,7 +129,6 @@ struct nfs_args {
*/
struct nfsmount {
kmutex_t nm_lock; /* Lock for this structure */
krwlock_t nm_rbtlock; /* Lock for the rbtree */
kcondvar_t nm_rcvcv;
kcondvar_t nm_sndcv;
int nm_flag; /* Flags for soft/hard... */
@ -138,7 +136,6 @@ struct nfsmount {
int nm_numgrps; /* Max. size of groupslist */
struct vnode *nm_vnode;
struct socket *nm_so; /* Rpc socket */
struct rb_tree nm_rbtree; /* red/black tree by fh for nfsnode */
int nm_sotype; /* Type of socket */
int nm_soproto; /* and protocol */
int nm_soflags; /* pr_flags for socket protocol */

View File

@ -1,4 +1,4 @@
/* $NetBSD: nfsnode.h,v 1.72 2010/09/25 01:42:39 matt Exp $ */
/* $NetBSD: nfsnode.h,v 1.73 2014/05/30 08:47:45 hannken Exp $ */
/*
* Copyright (c) 1989, 1993
@ -40,7 +40,6 @@
#include <sys/condvar.h>
#include <sys/mutex.h>
#include <sys/rbtree.h>
#ifndef _NFS_NFS_H_
#include <nfs/nfs.h>
@ -153,7 +152,6 @@ struct nfsnode {
#define n_sillyrename n_un2.nf_silly
#define n_dirgens n_un2.ndir_dirgens
struct rb_node n_rbnode; /* red/black node */
nfsfh_t *n_fhp; /* NFS File Handle */
struct vattr *n_vattr; /* Vnode attribute cache */
struct vnode *n_vnode; /* associated vnode */