Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/nfs Change NFS from rbtree to vcache.



details:   https://anonhg.NetBSD.org/src/rev/f11c6839d947
branches:  trunk
changeset: 796362:f11c6839d947
user:      hannken <hannken%NetBSD.org@localhost>
date:      Fri May 30 08:47:45 2014 +0000

description:
Change NFS from rbtree to vcache.

diffstat:

 sys/nfs/nfs_node.c   |  173 +++++++++++++++-----------------------------------
 sys/nfs/nfs_var.h    |    3 +-
 sys/nfs/nfs_vfsops.c |    9 +-
 sys/nfs/nfsmount.h   |    5 +-
 sys/nfs/nfsnode.h    |    4 +-
 5 files changed, 59 insertions(+), 135 deletions(-)

diffs (truncated from 348 to 300 lines):

diff -r 4192bdf39844 -r f11c6839d947 sys/nfs/nfs_node.c
--- a/sys/nfs/nfs_node.c        Fri May 30 08:46:00 2014 +0000
+++ b/sys/nfs/nfs_node.c        Fri May 30 08:47:45 2014 +0000
@@ -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 @@
        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)
-{
-       const struct nfsnode * const pnp = parent;
-       const struct nfsnode * const np = node;
-
-       if (pnp->n_fhsize != np->n_fhsize)
-               return np->n_fhsize - pnp->n_fhsize;
-
-       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)
+/*
+ * 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 = 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);
-}
+       int fhsize = key_len;
+       const nfsfh_t *fhp = key;
+       struct nfsnode *np;
 
-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
-};
+       /* 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;
 
-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 @@
 nfs_nget1(struct mount *mntp, nfsfh_t *fhp, int fhsize, struct nfsnode **npp,
     int lkflags)
 {
-       struct nfsnode *np;
+       int error;
        struct vnode *vp;
-       struct nfsmount *nmp = VFSTONFS(mntp);
-       int error;
-       struct fh_match fhm;
-
-       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);
-       if (error) {
-               *npp = 0;
-               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;
+       error = vcache_get(mntp, fhp, fhsize, &vp);
+       if (error)
+               return error;
+       error = vn_lock(vp, LK_EXCLUSIVE | lkflags);
+       if (error) {
+               vrele(vp);
+               return error;
        }
-       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 @@
        } */ *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
diff -r 4192bdf39844 -r f11c6839d947 sys/nfs/nfs_var.h
--- a/sys/nfs/nfs_var.h Fri May 30 08:46:00 2014 +0000
+++ b/sys/nfs/nfs_var.h Fri May 30 08:47:45 2014 +0000
@@ -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_kqfini(void);
 
 /* nfs_node.c */
-void nfs_rbtinit(struct nfsmount *);
 void nfs_node_init(void);
 void nfs_node_done(void);
 
diff -r 4192bdf39844 -r f11c6839d947 sys/nfs/nfs_vfsops.c
--- a/sys/nfs/nfs_vfsops.c      Fri May 30 08:46:00 2014 +0000
+++ b/sys/nfs/nfs_vfsops.c      Fri May 30 08:47:45 2014 +0000
@@ -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 @@
        .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 @@
                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 @@
 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 @@
        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);
diff -r 4192bdf39844 -r f11c6839d947 sys/nfs/nfsmount.h
--- a/sys/nfs/nfsmount.h        Fri May 30 08:46:00 2014 +0000
+++ b/sys/nfs/nfsmount.h        Fri May 30 08:47:45 2014 +0000
@@ -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 @@



Home | Main Index | Thread Index | Old Index