Add a hashmap to access all procfs nodes by pid.
This commit is contained in:
parent
29964953ba
commit
da4222d367
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: procfs.h,v 1.82 2022/01/19 10:23:00 martin Exp $ */
|
||||
/* $NetBSD: procfs.h,v 1.83 2024/01/17 10:19:21 hannken Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993
|
||||
|
@ -129,7 +129,9 @@ struct pfskey {
|
|||
int pk_fd; /* associated fd if not -1 */
|
||||
};
|
||||
struct pfsnode {
|
||||
LIST_ENTRY(pfsnode) pfs_hash; /* per pid hash list */
|
||||
struct vnode *pfs_vnode; /* vnode associated with this pfsnode */
|
||||
struct mount *pfs_mount; /* mount associated with this pfsnode */
|
||||
struct pfskey pfs_key;
|
||||
#define pfs_type pfs_key.pk_type
|
||||
#define pfs_pid pfs_key.pk_pid
|
||||
|
@ -269,6 +271,7 @@ int procfs_doauxv(struct lwp *, struct proc *, struct pfsnode *,
|
|||
int procfs_dolimit(struct lwp *, struct proc *, struct pfsnode *,
|
||||
struct uio *);
|
||||
|
||||
void procfs_hashrem(struct pfsnode *);
|
||||
void procfs_revoke_vnodes(struct proc *, void *);
|
||||
int procfs_getfp(struct pfsnode *, struct proc *, struct file **);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: procfs_vfsops.c,v 1.111 2022/01/17 11:20:00 bouyer Exp $ */
|
||||
/* $NetBSD: procfs_vfsops.c,v 1.112 2024/01/17 10:19:21 hannken Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993
|
||||
|
@ -76,7 +76,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: procfs_vfsops.c,v 1.111 2022/01/17 11:20:00 bouyer Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: procfs_vfsops.c,v 1.112 2024/01/17 10:19:21 hannken Exp $");
|
||||
|
||||
#if defined(_KERNEL_OPT)
|
||||
#include "opt_compat_netbsd.h"
|
||||
|
@ -110,7 +110,29 @@ MODULE(MODULE_CLASS_VFS, procfs, "ptrace_common");
|
|||
|
||||
VFS_PROTOS(procfs);
|
||||
|
||||
#define PROCFS_HASHSIZE 256
|
||||
|
||||
static kauth_listener_t procfs_listener;
|
||||
LIST_HEAD(hashhead, pfsnode);
|
||||
static u_long procfs_hashmask;
|
||||
static struct hashhead *procfs_hashtab;
|
||||
static kmutex_t procfs_hashlock;
|
||||
|
||||
static struct hashhead *
|
||||
procfs_hashhead(pid_t pid)
|
||||
{
|
||||
|
||||
return &procfs_hashtab[pid & procfs_hashmask];
|
||||
}
|
||||
|
||||
void
|
||||
procfs_hashrem(struct pfsnode *pfs)
|
||||
{
|
||||
|
||||
mutex_enter(&procfs_hashlock);
|
||||
LIST_REMOVE(pfs, pfs_hash);
|
||||
mutex_exit(&procfs_hashlock);
|
||||
}
|
||||
|
||||
/*
|
||||
* VFS Operations.
|
||||
|
@ -279,6 +301,7 @@ procfs_loadvnode(struct mount *mp, struct vnode *vp,
|
|||
pfs->pfs_type = pfskey.pk_type;
|
||||
pfs->pfs_fd = pfskey.pk_fd;
|
||||
pfs->pfs_vnode = vp;
|
||||
pfs->pfs_mount = mp;
|
||||
pfs->pfs_flags = 0;
|
||||
pfs->pfs_fileno =
|
||||
PROCFS_FILENO(pfs->pfs_pid, pfs->pfs_type, pfs->pfs_fd);
|
||||
|
@ -421,6 +444,10 @@ procfs_loadvnode(struct mount *mp, struct vnode *vp,
|
|||
panic("procfs_allocvp");
|
||||
}
|
||||
|
||||
mutex_enter(&procfs_hashlock);
|
||||
LIST_INSERT_HEAD(procfs_hashhead(pfs->pfs_pid), pfs, pfs_hash);
|
||||
mutex_exit(&procfs_hashlock);
|
||||
|
||||
uvm_vnp_setsize(vp, 0);
|
||||
*new_key = &pfs->pfs_key;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: procfs_vnops.c,v 1.229 2022/06/17 14:30:37 shm Exp $ */
|
||||
/* $NetBSD: procfs_vnops.c,v 1.230 2024/01/17 10:19:21 hannken Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
|
||||
|
@ -105,7 +105,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: procfs_vnops.c,v 1.229 2022/06/17 14:30:37 shm Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: procfs_vnops.c,v 1.230 2024/01/17 10:19:21 hannken Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/atomic.h>
|
||||
|
@ -437,6 +437,7 @@ procfs_reclaim(void *v)
|
|||
mutex_enter(vp->v_interlock);
|
||||
vp->v_data = NULL;
|
||||
mutex_exit(vp->v_interlock);
|
||||
procfs_hashrem(pfs);
|
||||
kmem_free(pfs, sizeof(*pfs));
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue