Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/miscfs/fdesc Change fdesc from hashlist to vcache.
details: https://anonhg.NetBSD.org/src/rev/2034dfcc9fc9
branches: trunk
changeset: 330530:2034dfcc9fc9
user: hannken <hannken%NetBSD.org@localhost>
date: Sun Jul 13 11:23:01 2014 +0000
description:
Change fdesc from hashlist to vcache.
diffstat:
sys/miscfs/fdesc/fdesc.h | 5 +-
sys/miscfs/fdesc/fdesc_vfsops.c | 75 ++++++++++++++++-
sys/miscfs/fdesc/fdesc_vnops.c | 166 +++++++--------------------------------
3 files changed, 99 insertions(+), 147 deletions(-)
diffs (truncated from 431 to 300 lines):
diff -r 7f14e0accae0 -r 2034dfcc9fc9 sys/miscfs/fdesc/fdesc.h
--- a/sys/miscfs/fdesc/fdesc.h Sun Jul 13 11:08:46 2014 +0000
+++ b/sys/miscfs/fdesc/fdesc.h Sun Jul 13 11:23:01 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdesc.h,v 1.21 2011/09/27 01:22:12 christos Exp $ */
+/* $NetBSD: fdesc.h,v 1.22 2014/07/13 11:23:01 hannken Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -56,11 +56,10 @@
} fdntype;
struct fdescnode {
- LIST_ENTRY(fdescnode) fd_hash; /* Hash list */
struct vnode *fd_vnode; /* Back ptr to vnode */
fdntype fd_type; /* Type of this node */
unsigned fd_fd; /* Fd to be dup'ed */
- char *fd_link; /* Link to fd/n */
+ const char *fd_link; /* Link to fd/n */
int fd_ix; /* filesystem index */
};
diff -r 7f14e0accae0 -r 2034dfcc9fc9 sys/miscfs/fdesc/fdesc_vfsops.c
--- a/sys/miscfs/fdesc/fdesc_vfsops.c Sun Jul 13 11:08:46 2014 +0000
+++ b/sys/miscfs/fdesc/fdesc_vfsops.c Sun Jul 13 11:23:01 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdesc_vfsops.c,v 1.88 2014/03/23 15:21:16 hannken Exp $ */
+/* $NetBSD: fdesc_vfsops.c,v 1.89 2014/07/13 11:23:01 hannken Exp $ */
/*
* Copyright (c) 1992, 1993, 1995
@@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdesc_vfsops.c,v 1.88 2014/03/23 15:21:16 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdesc_vfsops.c,v 1.89 2014/07/13 11:23:01 hannken Exp $");
#if defined(_KERNEL_OPT)
#include "opt_compat_netbsd.h"
@@ -78,7 +78,7 @@
fdesc_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
{
struct lwp *l = curlwp;
- int error = 0;
+ int error = 0, ix;
struct vnode *rvp;
if (mp->mnt_flag & MNT_GETARGS) {
@@ -91,12 +91,11 @@
if (mp->mnt_flag & MNT_UPDATE)
return (EOPNOTSUPP);
- error = fdesc_allocvp(Froot, FD_ROOT, mp, &rvp);
+ ix = FD_ROOT;
+ error = vcache_get(mp, &ix, sizeof(ix), &rvp);
if (error)
- return (error);
+ return error;
- rvp->v_type = VDIR;
- rvp->v_vflag |= VV_ROOT;
mp->mnt_stat.f_namemax = FDESC_MAXNAMLEN;
mp->mnt_flag |= MNT_LOCAL;
mp->mnt_data = rvp;
@@ -104,7 +103,6 @@
error = set_statvfs_info(path, UIO_USERSPACE, "fdesc", UIO_SYSSPACE,
mp->mnt_op->vfs_name, mp, l);
- VOP_UNLOCK(rvp);
return error;
}
@@ -174,6 +172,66 @@
return (EOPNOTSUPP);
}
+int
+fdesc_loadvnode(struct mount *mp, struct vnode *vp,
+ const void *key, size_t key_len, const void **new_key)
+{
+ int ix;
+ struct fdescnode *fd;
+
+ KASSERT(key_len == sizeof(ix));
+ memcpy(&ix, key, key_len);
+
+ fd = kmem_alloc(sizeof(struct fdescnode), KM_SLEEP);
+ fd->fd_fd = -1;
+ fd->fd_link = NULL;
+ fd->fd_ix = ix;
+ fd->fd_vnode = vp;
+ vp->v_tag = VT_FDESC;
+ vp->v_op = fdesc_vnodeop_p;
+ vp->v_data = fd;
+ switch (ix) {
+ case FD_ROOT:
+ fd->fd_type = Froot;
+ vp->v_type = VDIR;
+ vp->v_vflag |= VV_ROOT;
+ break;
+ case FD_DEVFD:
+ fd->fd_type = Fdevfd;
+ vp->v_type = VDIR;
+ break;
+ case FD_CTTY:
+ fd->fd_type = Fctty;
+ vp->v_type = VNON;
+ break;
+ case FD_STDIN:
+ fd->fd_type = Flink;
+ fd->fd_link = "fd/0";
+ vp->v_type = VLNK;
+ break;
+ case FD_STDOUT:
+ fd->fd_type = Flink;
+ fd->fd_link = "fd/1";
+ vp->v_type = VLNK;
+ break;
+ case FD_STDERR:
+ fd->fd_type = Flink;
+ fd->fd_link = "fd/2";
+ vp->v_type = VLNK;
+ break;
+ default:
+ KASSERT(ix >= FD_DESC);
+ fd->fd_type = Fdesc;
+ fd->fd_fd = ix - FD_DESC;
+ vp->v_type = VNON;
+ break;
+ }
+ uvm_vnp_setsize(vp, 0);
+ *new_key = &fd->fd_ix;
+
+ return 0;
+}
+
extern const struct vnodeopv_desc fdesc_vnodeop_opv_desc;
const struct vnodeopv_desc * const fdesc_vnodeopv_descs[] = {
@@ -192,6 +250,7 @@
.vfs_statvfs = genfs_statvfs,
.vfs_sync = fdesc_sync,
.vfs_vget = fdesc_vget,
+ .vfs_loadvnode = fdesc_loadvnode,
.vfs_fhtovp = (void *)eopnotsupp,
.vfs_vptofh = (void *)eopnotsupp,
.vfs_init = fdesc_init,
diff -r 7f14e0accae0 -r 2034dfcc9fc9 sys/miscfs/fdesc/fdesc_vnops.c
--- a/sys/miscfs/fdesc/fdesc_vnops.c Sun Jul 13 11:08:46 2014 +0000
+++ b/sys/miscfs/fdesc/fdesc_vnops.c Sun Jul 13 11:23:01 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdesc_vnops.c,v 1.119 2014/03/20 18:04:05 christos Exp $ */
+/* $NetBSD: fdesc_vnops.c,v 1.120 2014/07/13 11:23:01 hannken Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdesc_vnops.c,v 1.119 2014/03/20 18:04:05 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdesc_vnops.c,v 1.120 2014/07/13 11:23:01 hannken Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -69,21 +69,12 @@
#define cttyvp(p) ((p)->p_lflag & PL_CONTROLT ? (p)->p_session->s_ttyvp : NULL)
-static kmutex_t fdcache_lock;
-
dev_t devctty;
#if (FD_STDIN != FD_STDOUT-1) || (FD_STDOUT != FD_STDERR-1)
FD_STDIN, FD_STDOUT, FD_STDERR must be a sequence n, n+1, n+2
#endif
-#define NFDCACHE 4
-
-#define FD_NHASH(ix) \
- (&fdhashtbl[(ix) & fdhash])
-LIST_HEAD(fdhashhead, fdescnode) *fdhashtbl;
-u_long fdhash;
-
int fdesc_lookup(void *);
#define fdesc_create genfs_eopnotsupp
#define fdesc_mknod genfs_eopnotsupp
@@ -185,76 +176,11 @@
/* locate the major number */
cttymajor = devsw_name2chr("ctty", NULL, 0);
devctty = makedev(cttymajor, 0);
- mutex_init(&fdcache_lock, MUTEX_DEFAULT, IPL_NONE);
- fdhashtbl = hashinit(NFDCACHE, HASH_LIST, true, &fdhash);
}
-/*
- * Free hash table.
- */
void
fdesc_done(void)
{
- hashdone(fdhashtbl, HASH_LIST, fdhash);
- mutex_destroy(&fdcache_lock);
-}
-
-/*
- * Return a locked vnode of the correct type.
- */
-int
-fdesc_allocvp(fdntype ftype, int ix, struct mount *mp, struct vnode **vpp)
-{
- struct fdhashhead *fc;
- struct fdescnode *fd;
- int error = 0;
-
- fc = FD_NHASH(ix);
-loop:
- mutex_enter(&fdcache_lock);
- LIST_FOREACH(fd, fc, fd_hash) {
- if (fd->fd_ix == ix && fd->fd_vnode->v_mount == mp) {
- mutex_enter(fd->fd_vnode->v_interlock);
- mutex_exit(&fdcache_lock);
- if (vget(fd->fd_vnode, LK_EXCLUSIVE))
- goto loop;
- *vpp = fd->fd_vnode;
- return 0;
- }
- }
- mutex_exit(&fdcache_lock);
-
- error = getnewvnode(VT_FDESC, mp, fdesc_vnodeop_p, NULL, vpp);
- if (error)
- return error;
-
- mutex_enter(&fdcache_lock);
- LIST_FOREACH(fd, fc, fd_hash) {
- if (fd->fd_ix == ix && fd->fd_vnode->v_mount == mp) {
- /*
- * Another thread beat us, push back freshly
- * allocated vnode and retry.
- */
- mutex_exit(&fdcache_lock);
- ungetnewvnode(*vpp);
- goto loop;
- }
- }
-
- fd = malloc(sizeof(struct fdescnode), M_TEMP, M_WAITOK);
- (*vpp)->v_data = fd;
- fd->fd_vnode = *vpp;
- fd->fd_type = ftype;
- fd->fd_fd = -1;
- fd->fd_link = 0;
- fd->fd_ix = ix;
- uvm_vnp_setsize(*vpp, 0);
- error = VOP_LOCK(*vpp, LK_EXCLUSIVE);
- KASSERT(error == 0);
- LIST_INSERT_HEAD(fc, fd, fd_hash);
- mutex_exit(&fdcache_lock);
-
- return 0;
}
/*
@@ -276,9 +202,7 @@
const char *pname = cnp->cn_nameptr;
struct proc *p = l->l_proc;
unsigned fd = 0;
- int error;
- struct vnode *fvp;
- const char *ln;
+ int error, ix = -1;
fdtab_t *dt;
dt = curlwp->l_fd->fd_dt;
@@ -299,11 +223,7 @@
case Froot:
if (cnp->cn_namelen == 2 && memcmp(pname, "fd", 2) == 0) {
- error = fdesc_allocvp(Fdevfd, FD_DEVFD, dvp->v_mount, &fvp);
- if (error)
- goto bad;
- *vpp = fvp;
- fvp->v_type = VDIR;
+ ix = FD_DEVFD;
goto good;
}
@@ -313,58 +233,35 @@
error = ENXIO;
goto bad;
}
- error = fdesc_allocvp(Fctty, FD_CTTY, dvp->v_mount, &fvp);
- if (error)
- goto bad;
- *vpp = fvp;
- fvp->v_type = VCHR;
+ ix = FD_CTTY;
goto good;
Home |
Main Index |
Thread Index |
Old Index