Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Change layerfs from hashlist to vcache.
details: https://anonhg.NetBSD.org/src/rev/b2fd8cb28e0e
branches: trunk
changeset: 329460:b2fd8cb28e0e
user: hannken <hannken%NetBSD.org@localhost>
date: Sun May 25 13:51:25 2014 +0000
description:
Change layerfs from hashlist to vcache.
Make VI_LOCKSHARE public again.
Ride 6.99.43
diffstat:
sys/miscfs/genfs/layer.h | 14 +---
sys/miscfs/genfs/layer_extern.h | 11 +-
sys/miscfs/genfs/layer_subr.c | 151 +----------------------------------
sys/miscfs/genfs/layer_vfsops.c | 42 +++++++++-
sys/miscfs/genfs/layer_vnops.c | 8 +-
sys/miscfs/nullfs/null_vfsops.c | 13 +--
sys/miscfs/overlay/overlay_vfsops.c | 12 +--
sys/miscfs/umapfs/umap_vfsops.c | 14 +--
sys/sys/vnode.h | 4 +-
9 files changed, 64 insertions(+), 205 deletions(-)
diffs (truncated from 551 to 300 lines):
diff -r 52923d6f4019 -r b2fd8cb28e0e sys/miscfs/genfs/layer.h
--- a/sys/miscfs/genfs/layer.h Sun May 25 13:49:13 2014 +0000
+++ b/sys/miscfs/genfs/layer.h Sun May 25 13:51:25 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: layer.h,v 1.14 2010/06/06 08:01:31 hannken Exp $ */
+/* $NetBSD: layer.h,v 1.15 2014/05/25 13:51:25 hannken Exp $ */
/*
* Copyright (c) 1999 National Aeronautics & Space Administration
@@ -78,10 +78,6 @@
#ifdef _KERNEL
-struct layer_node;
-
-LIST_HEAD(layer_node_hashhead, layer_node);
-
struct layer_mount {
struct mount *layerm_vfs;
struct vnode *layerm_rootvp; /* Ref to root layer_node */
@@ -90,15 +86,8 @@
enum vtype layerm_tag; /* vtag of our vnodes */
int /* bypass routine for this mount */
(*layerm_bypass)(void *);
- int (*layerm_alloc) /* alloc a new layer node */
- (struct mount *, struct vnode *,
- struct vnode **);
int (**layerm_vnodeop_p) /* ops for our nodes */
(void *);
- struct layer_node_hashhead /* head of hash list for layer_nodes */
- *layerm_node_hashtbl;
- u_long layerm_node_hash; /* hash mask for hash chain */
- kmutex_t layerm_hashlock; /* interlock for hash chain. */
};
#define LAYERFS_MFLAGS 0x00000fff /* reserved layer mount flags */
@@ -108,7 +97,6 @@
* A cache of vnode references
*/
struct layer_node {
- LIST_ENTRY(layer_node) layer_hash; /* Hash list */
struct vnode *layer_lowervp; /* VREFed once */
struct vnode *layer_vnode; /* Back pointer */
unsigned int layer_flags; /* locking, etc. */
diff -r 52923d6f4019 -r b2fd8cb28e0e sys/miscfs/genfs/layer_extern.h
--- a/sys/miscfs/genfs/layer_extern.h Sun May 25 13:49:13 2014 +0000
+++ b/sys/miscfs/genfs/layer_extern.h Sun May 25 13:51:25 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: layer_extern.h,v 1.35 2014/02/27 16:51:38 hannken Exp $ */
+/* $NetBSD: layer_extern.h,v 1.36 2014/05/25 13:51:25 hannken Exp $ */
/*
* Copyright (c) 1999 National Aeronautics & Space Administration
@@ -76,14 +76,7 @@
/* Routines to manage nodes. */
void layerfs_init(void);
void layerfs_done(void);
-int layer_node_alloc(struct mount *, struct vnode *, struct vnode **);
int layer_node_create(struct mount *, struct vnode *, struct vnode **);
-struct vnode *layer_node_find(struct mount *, struct vnode *);
-
-#define LOG2_SIZEVNODE 7 /* log2(sizeof struct vnode) */
-#define LAYER_NHASH(lmp, vp) \
- (&((lmp)->layerm_node_hashtbl[(((u_long)vp)>>LOG2_SIZEVNODE) & \
- (lmp)->layerm_node_hash]))
/* VFS routines */
int layerfs_start(struct mount *, int);
@@ -91,6 +84,8 @@
int layerfs_quotactl(struct mount *, struct quotactl_args *);
int layerfs_statvfs(struct mount *, struct statvfs *);
int layerfs_sync(struct mount *, int, struct kauth_cred *);
+int layerfs_loadvnode(struct mount *, struct vnode *,
+ const void *, size_t, const void **);
int layerfs_vget(struct mount *, ino_t, struct vnode **);
int layerfs_fhtovp(struct mount *, struct fid *, struct vnode **);
int layerfs_vptofh(struct vnode *, struct fid *, size_t *);
diff -r 52923d6f4019 -r b2fd8cb28e0e sys/miscfs/genfs/layer_subr.c
--- a/sys/miscfs/genfs/layer_subr.c Sun May 25 13:49:13 2014 +0000
+++ b/sys/miscfs/genfs/layer_subr.c Sun May 25 13:51:25 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: layer_subr.c,v 1.35 2014/02/10 11:23:14 hannken Exp $ */
+/* $NetBSD: layer_subr.c,v 1.36 2014/05/25 13:51:25 hannken Exp $ */
/*
* Copyright (c) 1999 National Aeronautics & Space Administration
@@ -69,7 +69,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: layer_subr.c,v 1.35 2014/02/10 11:23:14 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: layer_subr.c,v 1.36 2014/05/25 13:51:25 hannken Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -81,7 +81,6 @@
#include <sys/kmem.h>
#include <sys/malloc.h>
-#include <miscfs/specfs/specdev.h>
#include <miscfs/genfs/layer.h>
#include <miscfs/genfs/layer_extern.h>
@@ -110,156 +109,18 @@
}
/*
- * layer_node_find: find and return alias for lower vnode or NULL.
- *
- * => Return alias vnode referenced. if already exists.
- * => The layermp's hashlock must be held on entry, we will unlock on success.
- */
-struct vnode *
-layer_node_find(struct mount *mp, struct vnode *lowervp)
-{
- struct layer_mount *lmp = MOUNTTOLAYERMOUNT(mp);
- struct layer_node_hashhead *hd;
- struct layer_node *a;
- struct vnode *vp;
- int error;
-
- /*
- * Find hash bucket and search the (two-way) linked list looking
- * for a layerfs node structure which is referencing the lower vnode.
- * If found, the increment the layer_node reference count, but NOT
- * the lower vnode's reference counter.
- */
- KASSERT(mutex_owned(&lmp->layerm_hashlock));
- hd = LAYER_NHASH(lmp, lowervp);
-loop:
- LIST_FOREACH(a, hd, layer_hash) {
- if (a->layer_lowervp != lowervp) {
- continue;
- }
- vp = LAYERTOV(a);
- if (vp->v_mount != mp) {
- continue;
- }
- mutex_enter(vp->v_interlock);
- mutex_exit(&lmp->layerm_hashlock);
- error = vget(vp, 0);
- if (error) {
- mutex_enter(&lmp->layerm_hashlock);
- goto loop;
- }
- return vp;
- }
- return NULL;
-}
-
-/*
- * layer_node_alloc: make a new layerfs vnode.
- *
- * => vp is the alias vnode, lowervp is the lower vnode.
- * => We will hold a reference to lowervp.
- */
-int
-layer_node_alloc(struct mount *mp, struct vnode *lowervp, struct vnode **vpp)
-{
- struct layer_mount *lmp = MOUNTTOLAYERMOUNT(mp);
- struct layer_node_hashhead *hd;
- struct layer_node *xp;
- struct vnode *vp, *nvp;
- int error;
-
- /* Get a new vnode and share its interlock with underlying vnode. */
- error = getnewvnode(lmp->layerm_tag, mp, lmp->layerm_vnodeop_p,
- lowervp->v_interlock, &vp);
- if (error) {
- return error;
- }
- vp->v_type = lowervp->v_type;
- mutex_enter(vp->v_interlock);
- vp->v_iflag |= VI_LAYER;
- mutex_exit(vp->v_interlock);
-
- xp = kmem_alloc(lmp->layerm_size, KM_SLEEP);
- if (xp == NULL) {
- ungetnewvnode(vp);
- return ENOMEM;
- }
- if (vp->v_type == VBLK || vp->v_type == VCHR) {
- spec_node_init(vp, lowervp->v_rdev);
- }
-
- /*
- * Before inserting the node into the hash, check if other thread
- * did not race with us. If so - return that node, destroy ours.
- */
- mutex_enter(&lmp->layerm_hashlock);
- if ((nvp = layer_node_find(mp, lowervp)) != NULL) {
- ungetnewvnode(vp);
- kmem_free(xp, lmp->layerm_size);
- *vpp = nvp;
- return 0;
- }
-
- vp->v_data = xp;
- vp->v_vflag = (vp->v_vflag & ~VV_MPSAFE) |
- (lowervp->v_vflag & VV_MPSAFE);
- xp->layer_vnode = vp;
- xp->layer_lowervp = lowervp;
- xp->layer_flags = 0;
-
- /*
- * Insert the new node into the hash.
- * Add a reference to the lower node.
- */
- vref(lowervp);
- hd = LAYER_NHASH(lmp, lowervp);
- LIST_INSERT_HEAD(hd, xp, layer_hash);
- uvm_vnp_setsize(vp, 0);
- mutex_exit(&lmp->layerm_hashlock);
-
- *vpp = vp;
- return 0;
-}
-
-/*
* layer_node_create: try to find an existing layerfs vnode refering to it,
* otherwise make a new vnode which contains a reference to the lower vnode.
- *
- * => Caller should lock the lower node.
*/
int
layer_node_create(struct mount *mp, struct vnode *lowervp, struct vnode **nvpp)
{
+ int error;
struct vnode *aliasvp;
- struct layer_mount *lmp = MOUNTTOLAYERMOUNT(mp);
- mutex_enter(&lmp->layerm_hashlock);
- aliasvp = layer_node_find(mp, lowervp);
- if (aliasvp != NULL) {
- /*
- * Note: layer_node_find() has taken another reference to
- * the alias vnode and moved the lock holding to aliasvp.
- */
-#ifdef LAYERFS_DIAGNOSTIC
- if (layerfs_debug)
- vprint("layer_node_create: exists", aliasvp);
-#endif
- } else {
- int error;
-
- mutex_exit(&lmp->layerm_hashlock);
- /*
- * Get a new vnode. Make it to reference the layer_node.
- * Note: aliasvp will be return with the reference held.
- */
- error = (lmp->layerm_alloc)(mp, lowervp, &aliasvp);
- if (error)
- return error;
-#ifdef LAYERFS_DIAGNOSTIC
- if (layerfs_debug)
- printf("layer_node_create: create new alias vnode\n");
-#endif
- }
+ error = vcache_get(mp, &lowervp, sizeof(lowervp), &aliasvp);
+ if (error)
+ return error;
/*
* Now that we acquired a reference on the upper vnode, release one
diff -r 52923d6f4019 -r b2fd8cb28e0e sys/miscfs/genfs/layer_vfsops.c
--- a/sys/miscfs/genfs/layer_vfsops.c Sun May 25 13:49:13 2014 +0000
+++ b/sys/miscfs/genfs/layer_vfsops.c Sun May 25 13:51:25 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: layer_vfsops.c,v 1.43 2014/02/25 18:30:11 pooka Exp $ */
+/* $NetBSD: layer_vfsops.c,v 1.44 2014/05/25 13:51:25 hannken Exp $ */
/*
* Copyright (c) 1999 National Aeronautics & Space Administration
@@ -74,7 +74,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: layer_vfsops.c,v 1.43 2014/02/25 18:30:11 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: layer_vfsops.c,v 1.44 2014/05/25 13:51:25 hannken Exp $");
#include <sys/param.h>
#include <sys/sysctl.h>
@@ -86,6 +86,7 @@
#include <sys/kauth.h>
#include <sys/module.h>
+#include <miscfs/specfs/specdev.h>
#include <miscfs/genfs/layer.h>
#include <miscfs/genfs/layer_extern.h>
@@ -204,6 +205,43 @@
}
int
+layerfs_loadvnode(struct mount *mp, struct vnode *vp,
+ const void *key, size_t key_len, const void **new_key)
+{
+ struct layer_mount *lmp = MOUNTTOLAYERMOUNT(mp);
+ struct vnode *lowervp;
+ struct layer_node *xp;
Home |
Main Index |
Thread Index |
Old Index