pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc/sysutils/lsof lsof: support kmem grovelling of current...
details: https://anonhg.NetBSD.org/pkgsrc/rev/f0b24953b842
branches: trunk
changeset: 379912:f0b24953b842
user: tnn <tnn%pkgsrc.org@localhost>
date: Wed May 25 09:33:37 2022 +0000
description:
lsof: support kmem grovelling of current-era NetBSD rbtree kernel namecache
diffstat:
sysutils/lsof/Makefile | 5 +-
sysutils/lsof/distinfo | 7 +-
sysutils/lsof/files/rnmt.c | 229 ++++++++++++++++++++++++++
sysutils/lsof/patches/patch-aa | 17 +-
sysutils/lsof/patches/patch-ac | 19 +-
sysutils/lsof/patches/patch-lib_Makefile.skel | 24 ++
6 files changed, 289 insertions(+), 12 deletions(-)
diffs (truncated from 361 to 300 lines):
diff -r ee0cb21e9d3c -r f0b24953b842 sysutils/lsof/Makefile
--- a/sysutils/lsof/Makefile Wed May 25 09:29:14 2022 +0000
+++ b/sysutils/lsof/Makefile Wed May 25 09:33:37 2022 +0000
@@ -1,8 +1,8 @@
-# $NetBSD: Makefile,v 1.140 2021/11/11 00:49:34 gutteridge Exp $
+# $NetBSD: Makefile,v 1.141 2022/05/25 09:33:37 tnn Exp $
DISTNAME= lsof_4.91
PKGNAME= ${DISTNAME:S/_/-/}
-PKGREVISION= 5
+PKGREVISION= 6
CATEGORIES= sysutils
MASTER_SITES= ftp://ftp.mirrorservice.org/sites/lsof.itap.purdue.edu/pub/tools/unix/lsof/
MASTER_SITES+= ftp://ftp.mirrorservice.org/sites/lsof.itap.purdue.edu/pub/tools/unix/lsof/OLD/
@@ -74,6 +74,7 @@
fi ; \
${TOOLS_PATH.bsdtar} -xf ${SRCBALL_NAME}.tar
cd ${WRKSRC} ; ${ECHO} "y" | ./Inventory || exit 1
+ ${CP} ${FILESDIR}/rnmt.c ${WRKSRC}/lib/rnmt.c
SPECIAL_PERMS+= ${PREFIX}/sbin/lsof ${REAL_ROOT_USER} ${REAL_GROUP} 2755
diff -r ee0cb21e9d3c -r f0b24953b842 sysutils/lsof/distinfo
--- a/sysutils/lsof/distinfo Wed May 25 09:29:14 2022 +0000
+++ b/sysutils/lsof/distinfo Wed May 25 09:33:37 2022 +0000
@@ -1,14 +1,15 @@
-$NetBSD: distinfo,v 1.101 2022/02/27 02:13:44 gutteridge Exp $
+$NetBSD: distinfo,v 1.102 2022/05/25 09:33:37 tnn Exp $
BLAKE2s (lsof_4.91.tar.bz2) = 77109e036c36f7d1483e69f2aae2314830dc4d2bdc3bf88a4031832f17e6afef
SHA512 (lsof_4.91.tar.bz2) = 49f811941dd6303f7cb0655fddb8b1177af5d1b18f2bd1edfab09d2c128aea73daecf09c7a5375979c66ba764c88a6e70c9086b55c3634e3be01ab1aa12e9f92
Size (lsof_4.91.tar.bz2) = 791734 bytes
-SHA1 (patch-aa) = 4469a5fed540e3c5635b6082efedc477ea96a382
+SHA1 (patch-aa) = 76523a6d3bdff93a835dc442114f2bd4a018f95e
SHA1 (patch-ab) = 1501d8b0e6fd2c61949ba0d447c7b726655725c4
-SHA1 (patch-ac) = dac0fcdfee97d42c8f23684a4321519b9f8698d9
+SHA1 (patch-ac) = ab1dc4540452f413493c58b729c7c6de83abfb6a
SHA1 (patch-ad) = 7f639e8832c2da8e498c33a38ecbc7b3d3a7430a
SHA1 (patch-ae) = 3f4a7ce54c0646941fd86400f91a2d17e9d2354a
SHA1 (patch-af) = 88b3d2b42c05e20c189fa00fd65f1f412fe54038
SHA1 (patch-ag) = 99ab1c616604e9775522dbc70bfd6a7294964d0a
SHA1 (patch-ah) = 2de22b9a3733f958298af5e33b66c0653c320f59
SHA1 (patch-dialects_n+obsd_dnode1.c) = dc8c766760aca4eb2e7d7af3944260dd49795c09
+SHA1 (patch-lib_Makefile.skel) = abfb9d50eef60c5d43cbf4978bf179de0ebe371e
diff -r ee0cb21e9d3c -r f0b24953b842 sysutils/lsof/files/rnmt.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sysutils/lsof/files/rnmt.c Wed May 25 09:33:37 2022 +0000
@@ -0,0 +1,229 @@
+/*
+ * Copyright (C) 2022 Tobias Nygren <tnn%NetBSD.org@localhost>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+#include "../machine.h"
+
+#if defined(HASNCACHE) && defined(USE_LIB_RNMT)
+#include <sys/rbtree.h>
+#include <sys/vnode_impl.h>
+#include <err.h>
+
+#include "../lsof.h"
+
+/*
+ * rnmt.c - read NetBSD=>10-style red-black tree kernel name cache
+ */
+
+static int lnc_compare_nodes(void *, const void *, const void *);
+static int lnc_compare_key(void *, const void *, const void *);
+
+static rb_tree_t lnc_rbtree;
+
+/* local name cache entry */
+struct lnc {
+ struct rb_node lnc_tree; /* red-black tree */
+ KA_T lnc_vp; /* vnode address */
+ KA_T lnc_pvp; /* parent vnode address */
+ const struct lnc *lnc_plnc; /* parent lnc address */
+ int lnc_nlen; /* name length */
+ char lnc_name[NCHNAMLEN + 1]; /* name */
+};
+
+static const rb_tree_ops_t lnc_rbtree_ops = {
+ .rbto_compare_nodes = lnc_compare_nodes,
+ .rbto_compare_key = lnc_compare_key,
+ .rbto_node_offset = offsetof(struct lnc, lnc_tree),
+ .rbto_context = NULL
+};
+
+static int
+lnc_compare_nodes(void *context, const void *node1, const void *node2)
+{
+ const struct lnc *lnc1 = node1;
+ const struct lnc *lnc2 = node2;
+
+ if (lnc1->lnc_vp < lnc2->lnc_vp) {
+ return -1;
+ }
+ if (lnc1->lnc_vp > lnc2->lnc_vp) {
+ return 1;
+ }
+
+ return 0;
+}
+
+static int
+lnc_compare_key(void *context, const void *node, const void *key)
+{
+ const struct lnc *lnc = node;
+ const KA_T vp = (KA_T)key;
+
+ if (lnc->lnc_vp < vp) {
+ return -1;
+ }
+ if (lnc->lnc_vp > vp) {
+ return 1;
+ }
+
+ return 0;
+}
+
+static struct lnc *
+ncache_enter_local(KA_T vp, KA_T pvp, const struct lnc *plnc, const struct namecache *nc)
+{
+ struct lnc *lnc;
+
+ lnc = malloc(sizeof(*lnc));
+ if (!lnc) {
+ errx(1, "can't allocate local name cache entry\n");
+ }
+ lnc->lnc_vp = vp;
+ lnc->lnc_pvp = pvp;
+ lnc->lnc_plnc = plnc;
+ lnc->lnc_nlen = nc->nc_nlen;
+ memcpy(lnc->lnc_name, nc->nc_name, lnc->lnc_nlen);
+ lnc->lnc_name[lnc->lnc_nlen] = 0;
+
+ rb_tree_insert_node(&lnc_rbtree, lnc);
+
+ return lnc;
+}
+
+static int
+sanity_check_vnode_impl(const struct vnode_impl *vi)
+{
+ if (vi->vi_vnode.v_type >= VBAD)
+ return -1;
+
+ return 0;
+}
+
+static int
+sanity_check_namecache(const struct namecache *nc)
+{
+ if (nc->nc_vp == NULL)
+ return -1;
+
+ if (nc->nc_nlen > NCHNAMLEN)
+ return -1;
+
+ if (nc->nc_nlen == 1 && nc->nc_name[0] == '.')
+ return -1;
+
+ if (nc->nc_nlen == 2 && nc->nc_name[0] == '.' && nc->nc_name[1] == '.')
+ return -1;
+
+ return 0;
+}
+
+static void
+ncache_walk(KA_T ncp, KA_T pvp, const struct lnc *plnc)
+{
+ struct l_nch *lc;
+ static struct vnode_impl vi;
+ static struct namecache nc;
+ struct lnc *lnc;
+ KA_T vp;
+ KA_T left, right;
+
+ if (kread(ncp, (char *)&nc, sizeof(nc))) {
+ return;
+ }
+ vp = (KA_T)nc.nc_vp;
+ if (kread(vp, (char *)&vi, sizeof(vi))) {
+ vi.vi_vnode.v_type = VBAD;
+ }
+ left = (KA_T)nc.nc_tree.rb_nodes[0];
+ right = (KA_T)nc.nc_tree.rb_nodes[1];
+ if (sanity_check_vnode_impl(&vi) == 0 && sanity_check_namecache(&nc) == 0) {
+ lnc = ncache_enter_local(vp, pvp, plnc, &nc);
+ if (vi.vi_vnode.v_type = VDIR && vi.vi_nc_tree.rbt_root != NULL) {
+ ncache_walk((KA_T)vi.vi_nc_tree.rbt_root, ncp, lnc);
+ }
+ }
+ if (left)
+ ncache_walk(left, pvp, plnc);
+ if (right)
+ ncache_walk(right, pvp, plnc);
+}
+
+void
+ncache_load()
+{
+ KA_T rootvnode_addr;
+ struct vnode_impl vi;
+
+ rootvnode_addr = (KA_T)0;
+ if (get_Nl_value("rootvnode", (struct drive_Nl *)NULL, &rootvnode_addr) < 0
+ || !rootvnode_addr
+ || kread((KA_T)rootvnode_addr, (char *)&rootvnode_addr, sizeof(rootvnode_addr))
+ || kread((KA_T)rootvnode_addr, (char *)&vi, sizeof(vi))) {
+ errx(1, "can't read rootvnode\n");
+ }
+
+ rb_tree_init(&lnc_rbtree, &lnc_rbtree_ops);
+ ncache_walk((KA_T)vi.vi_nc_tree.rbt_root, 0, 0);
+}
+
+static void
+build_path(char **buf, size_t *remaining, const struct lnc *lnc)
+{
+ size_t len;
+
+ if (lnc == NULL)
+ return;
+
+ build_path(buf, remaining, lnc->lnc_plnc);
+ if (remaining == 0) {
+ return;
+ }
+ if (lnc->lnc_plnc != NULL) {
+ **buf = '/';
+ (*buf)++;
+ }
+ remaining--;
+ len = lnc->lnc_nlen;
+ if (*remaining < len)
+ len = *remaining;
+ memcpy(*buf, lnc->lnc_name, len);
+ *remaining -= len;
+ *buf += len;
+}
+
+char *
+ncache_lookup(char *buf, int blen, int *fp)
+{
+ const struct lnc *lnc;
+ char *p;
+ size_t remaining;
+
+ *fp = 0;
+ lnc = rb_tree_find_node(&lnc_rbtree, (void*)Lf->na);
+ if (lnc != NULL) {
+ p = buf;
+ remaining = blen;
+ build_path(&p, &remaining, lnc);
+ if (remaining == 0) {
+ buf[blen - 1] = 0;
+ } else {
+ *p = 0;
+ }
+ *fp = 1;
+ return buf;
+ }
+
+ return NULL;
+}
+#endif
diff -r ee0cb21e9d3c -r f0b24953b842 sysutils/lsof/patches/patch-aa
--- a/sysutils/lsof/patches/patch-aa Wed May 25 09:29:14 2022 +0000
+++ b/sysutils/lsof/patches/patch-aa Wed May 25 09:33:37 2022 +0000
@@ -1,7 +1,7 @@
-$NetBSD: patch-aa,v 1.28 2010/04/30 06:53:07 sbd Exp $
+$NetBSD: patch-aa,v 1.29 2022/05/25 09:33:37 tnn Exp $
---- dialects/n+obsd/machine.h.orig 2006-03-28 16:54:17.000000000 -0500
-+++ dialects/n+obsd/machine.h 2008-05-17 18:53:29.000000000 -0400
+--- dialects/n+obsd/machine.h.orig 2010-07-29 16:02:55.000000000 +0000
++++ dialects/n+obsd/machine.h
@@ -41,6 +41,10 @@
#include <sys/types.h>
@@ -13,3 +13,14 @@
/*
+@@ -577,7 +581,9 @@
+ /* #define USE_LIB_READMNT 1 rmnt.c */
+ /* #define USE_LIB_REGEX 1 regex.c */
+
+-# if (defined(OPENBSDV) && OPENBSDV>=2010) || (defined(NETBSDV) && NETBSDV>=1002000)
Home |
Main Index |
Thread Index |
Old Index