Store puffs_node's on lists hashed with the cookie value instead

of just one flat list.
This commit is contained in:
pooka 2007-01-15 23:29:08 +00:00
parent f13e324ee5
commit 84906bc20f
5 changed files with 65 additions and 25 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: puffs_msgif.c,v 1.13 2006/12/29 01:37:11 pooka Exp $ */
/* $NetBSD: puffs_msgif.c,v 1.14 2007/01/15 23:29:08 pooka Exp $ */
/*
* Copyright (c) 2005, 2006 Antti Kantee. All Rights Reserved.
@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: puffs_msgif.c,v 1.13 2006/12/29 01:37:11 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: puffs_msgif.c,v 1.14 2007/01/15 23:29:08 pooka Exp $");
#include <sys/param.h>
#include <sys/malloc.h>
@ -55,7 +55,7 @@ static int touser(struct puffs_mount *, struct puffs_park *, uint64_t,
uint64_t
puffs_getreqid(struct puffs_mount *pmp)
{
unsigned int rv;
uint64_t rv;
simple_lock(&pmp->pmp_lock);
rv = pmp->pmp_nextreq++;

View File

@ -1,4 +1,4 @@
/* $NetBSD: puffs_subr.c,v 1.15 2007/01/15 20:40:29 pooka Exp $ */
/* $NetBSD: puffs_subr.c,v 1.16 2007/01/15 23:29:08 pooka Exp $ */
/*
* Copyright (c) 2005, 2006 Antti Kantee. All Rights Reserved.
@ -33,10 +33,11 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: puffs_subr.c,v 1.15 2007/01/15 20:40:29 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: puffs_subr.c,v 1.16 2007/01/15 23:29:08 pooka Exp $");
#include <sys/param.h>
#include <sys/conf.h>
#include <sys/hash.h>
#include <sys/malloc.h>
#include <sys/mount.h>
#include <sys/socketvar.h>
@ -57,6 +58,9 @@ POOL_INIT(puffs_pnpool, sizeof(struct puffs_node), 0, 0, 0, "puffspnpl",
int puffsdebug;
#endif
static __inline struct puffs_node_hashlist
*puffs_cookie2hashlist(struct puffs_mount *, void *);
static struct puffs_node *puffs_cookie2pnode(struct puffs_mount *, void *);
static void puffs_gop_size(struct vnode *, off_t, off_t *, int);
static void puffs_gop_markupdate(struct vnode *, int);
@ -80,6 +84,7 @@ puffs_getvnode(struct mount *mp, void *cookie, enum vtype type,
struct puffs_mount *pmp;
struct vnode *vp, *nvp;
struct puffs_node *pnode;
struct puffs_node_hashlist *plist;
int error;
pmp = MPTOPUFFSMP(mp);
@ -121,10 +126,7 @@ puffs_getvnode(struct mount *mp, void *cookie, enum vtype type,
/* So it's not dead yet.. good.. inform new vnode of its master */
simple_lock(&mntvnode_slock);
if (TAILQ_EMPTY(&mp->mnt_vnodelist))
TAILQ_INSERT_HEAD(&mp->mnt_vnodelist, vp, v_mntvnodes);
else
TAILQ_INSERT_TAIL(&mp->mnt_vnodelist, vp, v_mntvnodes);
TAILQ_INSERT_TAIL(&mp->mnt_vnodelist, vp, v_mntvnodes);
simple_unlock(&mntvnode_slock);
vp->v_mount = mp;
@ -183,7 +185,8 @@ puffs_getvnode(struct mount *mp, void *cookie, enum vtype type,
pnode = pool_get(&puffs_pnpool, PR_WAITOK);
pnode->pn_cookie = cookie;
pnode->pn_stat = 0;
LIST_INSERT_HEAD(&pmp->pmp_pnodelist, pnode, pn_entries);
plist = puffs_cookie2hashlist(pmp, cookie);
LIST_INSERT_HEAD(plist, pnode, pn_hashent);
vp->v_data = pnode;
vp->v_type = type;
pnode->pn_vp = vp;
@ -254,23 +257,34 @@ puffs_putvnode(struct vnode *vp)
panic("puffs_putvnode: %p not a puffs vnode", vp);
#endif
LIST_REMOVE(pnode, pn_entries);
LIST_REMOVE(pnode, pn_hashent);
pool_put(&puffs_pnpool, vp->v_data);
vp->v_data = NULL;
return;
}
static __inline struct puffs_node_hashlist *
puffs_cookie2hashlist(struct puffs_mount *pmp, void *cookie)
{
uint32_t hash;
hash = hash32_buf(&cookie, sizeof(void *), HASH32_BUF_INIT);
return &pmp->pmp_pnodehash[hash % pmp->pmp_npnodehash];
}
/*
* Translate cookie to puffs_node. Caller must hold mountpoint
* lock and it will be held upon return.
*/
struct puffs_node *
static struct puffs_node *
puffs_cookie2pnode(struct puffs_mount *pmp, void *cookie)
{
struct puffs_node_hashlist *plist;
struct puffs_node *pnode;
LIST_FOREACH(pnode, &pmp->pmp_pnodelist, pn_entries) {
plist = puffs_cookie2hashlist(pmp, cookie);
LIST_FOREACH(pnode, plist, pn_hashent) {
if (pnode->pn_cookie == cookie)
break;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: puffs_sys.h,v 1.19 2007/01/15 20:40:29 pooka Exp $ */
/* $NetBSD: puffs_sys.h,v 1.20 2007/01/15 23:29:08 pooka Exp $ */
/*
* Copyright (c) 2005, 2006 Antti Kantee. All Rights Reserved.
@ -119,6 +119,7 @@ extern int puffsdebug; /* puffs_subr.c */
#define PUFFS_DOCACHE(pmp) (((pmp)->pmp_flags & PUFFS_KFLAG_NOCACHE) == 0)
TAILQ_HEAD(puffs_wq, puffs_park);
LIST_HEAD(puffs_node_hashlist, puffs_node);
struct puffs_mount {
struct simplelock pmp_lock;
@ -133,14 +134,15 @@ struct puffs_mount {
struct puffs_wq pmp_req_replywait;
TAILQ_HEAD(, puffs_sizepark) pmp_req_sizepark;
LIST_HEAD(, puffs_node) pmp_pnodelist;
struct puffs_node_hashlist *pmp_pnodehash;
size_t pmp_npnodehash;
struct mount *pmp_mp;
struct vnode *pmp_root;
void *pmp_rootcookie;
struct selinfo *pmp_sel; /* in puffs_instance */
unsigned int pmp_nextreq;
uint64_t pmp_nextreq;
uint8_t pmp_status;
uint8_t pmp_unmounting;
};
@ -159,7 +161,7 @@ struct puffs_node {
struct vnode *pn_vp; /* backpointer to vnode */
uint32_t pn_stat; /* node status */
LIST_ENTRY(puffs_node) pn_entries;
LIST_ENTRY(puffs_node) pn_hashent;
};
int puffs_start2(struct puffs_mount *, struct puffs_startreq *);
@ -178,7 +180,6 @@ int puffs_getvnode(struct mount *, void *, enum vtype, voff_t, dev_t,
int puffs_newnode(struct mount *, struct vnode *, struct vnode **,
void *, struct componentname *, enum vtype, dev_t);
void puffs_putvnode(struct vnode *);
struct puffs_node *puffs_cookie2pnode(struct puffs_mount *, void *);
struct vnode *puffs_pnode2vnode(struct puffs_mount *, void *, int);
void puffs_makecn(struct puffs_kcn *, const struct componentname *);
void puffs_credcvt(struct puffs_cred *, kauth_cred_t);

View File

@ -1,4 +1,4 @@
/* $NetBSD: puffs_vfsops.c,v 1.21 2007/01/09 23:10:23 pooka Exp $ */
/* $NetBSD: puffs_vfsops.c,v 1.22 2007/01/15 23:29:08 pooka Exp $ */
/*
* Copyright (c) 2005, 2006 Antti Kantee. All Rights Reserved.
@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: puffs_vfsops.c,v 1.21 2007/01/09 23:10:23 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: puffs_vfsops.c,v 1.22 2007/01/15 23:29:08 pooka Exp $");
#include <sys/param.h>
#include <sys/mount.h>
@ -53,14 +53,22 @@ VFS_PROTOS(puffs);
MALLOC_DEFINE(M_PUFFS, "puffs", "pass-to-userspace file system structures");
#ifndef PUFFS_PNODEBUCKETS
#define PUFFS_PNODEBUCKETS 256
#endif
#ifndef PUFFS_MAXPNODEBUCKETS
#define PUFFS_MAXPNODEBUCKETS 65536
#endif
int puffs_pnodebuckets = PUFFS_PNODEBUCKETS;
int
puffs_mount(struct mount *mp, const char *path, void *data,
struct nameidata *ndp, struct lwp *l)
{
struct puffs_mount *pmp;
struct puffs_mount *pmp = NULL;
struct puffs_args *args;
char namebuf[PUFFSNAMESIZE+sizeof(PUFFS_NAMEPREFIX)+1]; /* spooky */
int error = 0;
int error = 0, i;
if (mp->mnt_flag & MNT_GETARGS) {
pmp = MPTOPUFFSMP(mp);
@ -129,13 +137,24 @@ puffs_mount(struct mount *mp, const char *path, void *data,
pmp->pmp_req_maxsize = args->pa_maxreqlen;
pmp->pmp_args = *args;
/* puffs_node hash buckets */
pmp->pmp_npnodehash = puffs_pnodebuckets;
if (pmp->pmp_npnodehash < 1)
pmp->pmp_npnodehash = 1;
if (pmp->pmp_npnodehash > PUFFS_MAXPNODEBUCKETS)
pmp->pmp_npnodehash = PUFFS_MAXPNODEBUCKETS;
pmp->pmp_pnodehash = malloc
(sizeof(struct puffs_pnode_hashlist *) * pmp->pmp_npnodehash,
M_PUFFS, M_WAITOK);
for (i = 0; i < pmp->pmp_npnodehash; i++)
LIST_INIT(&pmp->pmp_pnodehash[i]);
/*
* Inform the fileops processing code that we have a mountpoint.
* If it doesn't know about anyone with our pid/fd having the
* device open, punt
*/
if (puffs_setpmp(l->l_proc->p_pid, args->pa_fd, pmp)) {
FREE(pmp, M_PUFFS);
error = ENOENT;
goto out;
}
@ -151,6 +170,10 @@ puffs_mount(struct mount *mp, const char *path, void *data,
vfs_getnewfsid(mp);
out:
if (error && pmp && pmp->pmp_pnodehash)
free(pmp->pmp_pnodehash, M_PUFFS);
if (error && pmp)
FREE(pmp, M_PUFFS);
FREE(args, M_PUFFS);
return error;
}
@ -264,6 +287,7 @@ puffs_unmount(struct mount *mp, int mntflags, struct lwp *l)
pmp->pmp_status = PUFFSTAT_DYING;
puffs_nukebypmp(pmp);
simple_unlock(&pmp->pmp_lock);
free(pmp->pmp_pnodehash, M_PUFFS);
FREE(pmp, M_PUFFS);
error = 0;
} else {

View File

@ -1,4 +1,4 @@
/* $NetBSD: puffs_vnops.c,v 1.32 2007/01/15 20:40:29 pooka Exp $ */
/* $NetBSD: puffs_vnops.c,v 1.33 2007/01/15 23:29:08 pooka Exp $ */
/*
* Copyright (c) 2005, 2006 Antti Kantee. All Rights Reserved.
@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: puffs_vnops.c,v 1.32 2007/01/15 20:40:29 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: puffs_vnops.c,v 1.33 2007/01/15 23:29:08 pooka Exp $");
#include <sys/param.h>
#include <sys/vnode.h>
@ -499,6 +499,7 @@ puffs_lookup(void *v)
}
/* XXX: race here */
/* XXX2: this check for node existence twice */
vp = puffs_pnode2vnode(pmp, lookup_arg.pvnr_newnode, 1);
if (!vp) {
error = puffs_getvnode(dvp->v_mount,