diff options
author | David Gwynne <dlg@cvs.openbsd.org> | 2016-09-16 03:21:17 +0000 |
---|---|---|
committer | David Gwynne <dlg@cvs.openbsd.org> | 2016-09-16 03:21:17 +0000 |
commit | 65373149f30ede9da3a8a6e3c6823d144ef3191a (patch) | |
tree | 754689d90e9880a9d6ac524e9f7393c61183caf8 | |
parent | bf41feffd36f2fc4435f198ba4b888cb2a54d9e6 (diff) |
move the namecache_rb_tree from RB macros to RBT functions.
i had to shuffle the includes a bit. all the knowledge of the RB
tree is now inside vfs_cache.c, and all accesses are via cache_*
functions.
-rw-r--r-- | sys/kern/vfs_cache.c | 27 | ||||
-rw-r--r-- | sys/kern/vfs_subr.c | 4 | ||||
-rw-r--r-- | sys/sys/namei.h | 11 | ||||
-rw-r--r-- | sys/sys/vnode.h | 5 |
4 files changed, 27 insertions, 20 deletions
diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c index aebba744f38..f18dd903eaf 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_cache.c,v 1.51 2016/09/15 02:00:16 dlg Exp $ */ +/* $OpenBSD: vfs_cache.c,v 1.52 2016/09/16 03:21:16 dlg Exp $ */ /* $NetBSD: vfs_cache.c,v 1.13 1996/02/04 02:18:09 christos Exp $ */ /* @@ -73,8 +73,8 @@ struct pool nch_pool; void cache_zap(struct namecache *); u_long nextvnodeid; -static int -namecache_compare(struct namecache *n1, struct namecache *n2) +static inline int +namecache_compare(const struct namecache *n1, const struct namecache *n2) { if (n1->nc_nlen == n2->nc_nlen) return (memcmp(n1->nc_name, n2->nc_name, n1->nc_nlen)); @@ -82,7 +82,14 @@ namecache_compare(struct namecache *n1, struct namecache *n2) return (n1->nc_nlen - n2->nc_nlen); } -RB_GENERATE(namecache_rb_cache, namecache, n_rbcache, namecache_compare); +RBT_PROTOTYPE(namecache_rb_cache, namecache, n_rbcache, namecache_compare); +RBT_GENERATE(namecache_rb_cache, namecache, n_rbcache, namecache_compare); + +void +cache_tree_init(struct namecache_rb_cache *tree) +{ + RBT_INIT(namecache_rb_cache, tree); +} /* * blow away a namecache entry @@ -100,8 +107,8 @@ cache_zap(struct namecache *ncp) numneg--; } if (ncp->nc_dvp) { - RB_REMOVE(namecache_rb_cache, &ncp->nc_dvp->v_nc_tree, ncp); - if (RB_EMPTY(&ncp->nc_dvp->v_nc_tree)) + RBT_REMOVE(namecache_rb_cache, &ncp->nc_dvp->v_nc_tree, ncp); + if (RBT_EMPTY(namecache_rb_cache, &ncp->nc_dvp->v_nc_tree)) dvp = ncp->nc_dvp; } if (ncp->nc_vp && (ncp->nc_vpid == ncp->nc_vp->v_id)) { @@ -157,7 +164,7 @@ cache_lookup(struct vnode *dvp, struct vnode **vpp, /* lookup in directory vnode's redblack tree */ n.nc_nlen = cnp->cn_namelen; memcpy(n.nc_name, cnp->cn_nameptr, n.nc_nlen); - ncp = RB_FIND(namecache_rb_cache, &dvp->v_nc_tree, &n); + ncp = RBT_FIND(namecache_rb_cache, &dvp->v_nc_tree, &n); if (ncp == NULL) { nchstats.ncs_miss++; @@ -368,10 +375,10 @@ cache_enter(struct vnode *dvp, struct vnode *vp, struct componentname *cnp) ncp->nc_dvpid = dvp->v_id; ncp->nc_nlen = cnp->cn_namelen; memcpy(ncp->nc_name, cnp->cn_nameptr, ncp->nc_nlen); - if (RB_EMPTY(&dvp->v_nc_tree)) { + if (RBT_EMPTY(namecache_rb_cache, &dvp->v_nc_tree)) { vhold(dvp); } - if ((lncp = RB_INSERT(namecache_rb_cache, &dvp->v_nc_tree, ncp)) + if ((lncp = RBT_INSERT(namecache_rb_cache, &dvp->v_nc_tree, ncp)) != NULL) { /* someone has raced us and added a different entry * for the same vnode (different ncp) - we don't need @@ -435,7 +442,7 @@ cache_purge(struct vnode *vp) while ((ncp = TAILQ_FIRST(&vp->v_cache_dst))) cache_zap(ncp); - while ((ncp = RB_ROOT(&vp->v_nc_tree))) + while ((ncp = RBT_ROOT(namecache_rb_cache, &vp->v_nc_tree))) cache_zap(ncp); /* XXX this blows goats */ diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index dc80da9ef95..6cda25874bf 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_subr.c,v 1.252 2016/09/16 02:54:51 dlg Exp $ */ +/* $OpenBSD: vfs_subr.c,v 1.253 2016/09/16 03:21:16 dlg Exp $ */ /* $NetBSD: vfs_subr.c,v 1.53 1996/04/22 01:39:13 christos Exp $ */ /* @@ -376,7 +376,7 @@ getnewvnode(enum vtagtype tag, struct mount *mp, struct vops *vops, vp->v_uvm = pool_get(&uvm_vnode_pool, PR_WAITOK | PR_ZERO); vp->v_uvm->u_vnode = vp; RBT_INIT(buf_rb_bufs, &vp->v_bufs_tree); - RB_INIT(&vp->v_nc_tree); + cache_tree_init(&vp->v_nc_tree); TAILQ_INIT(&vp->v_cache_dst); numvnodes++; } else { diff --git a/sys/sys/namei.h b/sys/sys/namei.h index e69984ecd68..08d4665d2f8 100644 --- a/sys/sys/namei.h +++ b/sys/sys/namei.h @@ -1,4 +1,4 @@ -/* $OpenBSD: namei.h,v 1.32 2016/04/29 14:40:36 beck Exp $ */ +/* $OpenBSD: namei.h,v 1.33 2016/09/16 03:21:16 dlg Exp $ */ /* $NetBSD: namei.h,v 1.11 1996/02/09 18:25:20 christos Exp $ */ /* @@ -39,10 +39,6 @@ #include <sys/tree.h> #include <sys/uio.h> -struct namecache; -struct namecache_rb_cache; -RB_PROTOTYPE(namecache_rb_cache, namecache, n_rbcache, namecache_compare); - /* * Encapsulation of namei parameters. */ @@ -176,7 +172,7 @@ void ndinitat(struct nameidata *ndp, u_long op, u_long flags, struct namecache { TAILQ_ENTRY(namecache) nc_lru; /* Regular Entry LRU chain */ TAILQ_ENTRY(namecache) nc_neg; /* Negative Entry LRU chain */ - RB_ENTRY(namecache) n_rbcache; /* Namecache rb tree from vnode */ + RBT_ENTRY(namecache) n_rbcache; /* Namecache rb tree from vnode */ TAILQ_ENTRY(namecache) nc_me; /* ncp's referring to me */ struct vnode *nc_dvp; /* vnode of parent of name */ u_long nc_dvpid; /* capability number of nc_dvp */ @@ -187,10 +183,13 @@ struct namecache { }; #ifdef _KERNEL +struct namecache_rb_cache; + int namei(struct nameidata *ndp); int vfs_lookup(struct nameidata *ndp); int vfs_relookup(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp); +void cache_tree_init(struct namecache_rb_cache *); void cache_purge(struct vnode *); int cache_lookup(struct vnode *, struct vnode **, struct componentname *); void cache_enter(struct vnode *, struct vnode *, struct componentname *); diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h index 477a70e0d42..5f5fac05965 100644 --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -1,4 +1,4 @@ -/* $OpenBSD: vnode.h,v 1.136 2016/09/16 02:54:51 dlg Exp $ */ +/* $OpenBSD: vnode.h,v 1.137 2016/09/16 03:21:16 dlg Exp $ */ /* $NetBSD: vnode.h,v 1.38 1996/02/29 20:59:05 cgd Exp $ */ /* @@ -83,7 +83,8 @@ LIST_HEAD(buflists, buf); RBT_HEAD(buf_rb_bufs, buf); RBT_PROTOTYPE(buf_rb_bufs, buf, b_rbbufs, rb_buf_compare); -RB_HEAD(namecache_rb_cache, namecache); +struct namecache; +RBT_HEAD(namecache_rb_cache, namecache); struct uvm_vnode; struct vnode { |