summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGordon Ross <gwr@nexenta.com>2018-06-16 11:04:35 -0400
committerGordon Ross <gwr@nexenta.com>2019-05-28 13:34:10 -0400
commite0687fa3d7ea3b0bb17ed079bd9679fc2dffbf4b (patch)
treebcbd22579b236c3ebf9026ce795bdafd35fda169
parentdb46347b25b03d61611dcb9b588ee786da62c918 (diff)
downloadillumos-joyent-e0687fa3d7ea3b0bb17ed079bd9679fc2dffbf4b.tar.gz
10983 add mdb walker for smbd share cache
Reviewed by: Matt Barden <matt.barden@nexenta.com> Reviewed by: Joyce McIntosh <joyce.mcintosh@nexenta.com> Approved by: Garrett D'Amore <garrett@damore.org>
-rw-r--r--exception_lists/packaging2
-rw-r--r--usr/src/cmd/mdb/Makefile.common3
-rw-r--r--usr/src/cmd/mdb/common/modules/libmlsvc/mlsvc.c197
-rw-r--r--usr/src/cmd/mdb/common/modules/libmlsvc/smb_ht.c106
-rw-r--r--usr/src/cmd/mdb/intel/amd64/libmlsvc/Makefile46
-rw-r--r--usr/src/cmd/mdb/intel/ia32/libmlsvc/Makefile45
-rw-r--r--usr/src/pkg/manifests/service-file-system-smb.mf4
-rwxr-xr-xusr/src/tools/quick/make-smbsrv15
8 files changed, 408 insertions, 10 deletions
diff --git a/exception_lists/packaging b/exception_lists/packaging
index 4cedbefc5f..7d99df560a 100644
--- a/exception_lists/packaging
+++ b/exception_lists/packaging
@@ -594,6 +594,8 @@ usr/lib/sparcv9/libfakekernel.so sparc
usr/lib/mdb/proc/libfksmbsrv.so
usr/lib/mdb/proc/amd64/libfksmbsrv.so i386
usr/lib/mdb/proc/sparcv9/libfksmbsrv.so sparc
+usr/lib/mdb/proc/amd64/libmlsvc.so i386
+usr/lib/mdb/proc/sparcv9/libmlsvc.so sparc
usr/lib/smbsrv/bind-helper
usr/lib/smbsrv/fksmbd
usr/lib/smbsrv/libfksmbsrv.so
diff --git a/usr/src/cmd/mdb/Makefile.common b/usr/src/cmd/mdb/Makefile.common
index 0107f36dff..ff81215380 100644
--- a/usr/src/cmd/mdb/Makefile.common
+++ b/usr/src/cmd/mdb/Makefile.common
@@ -22,7 +22,7 @@
#
# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright 2016 Joyent, Inc.
-# Copyright 2017 Nexenta Systems, Inc.
+# Copyright 2018 Nexenta Systems, Inc.
#
#
@@ -38,6 +38,7 @@ COMMON_MODULES_PROC = \
libfknsmb \
libfksmbfs \
libfksmbsrv \
+ libmlsvc \
libnvpair \
libproc \
libpython \
diff --git a/usr/src/cmd/mdb/common/modules/libmlsvc/mlsvc.c b/usr/src/cmd/mdb/common/modules/libmlsvc/mlsvc.c
new file mode 100644
index 0000000000..fdd7fc86e4
--- /dev/null
+++ b/usr/src/cmd/mdb/common/modules/libmlsvc/mlsvc.c
@@ -0,0 +1,197 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2018 Nexenta Systems, Inc. All rights reserved.
+ */
+
+/*
+ * mdb module for libmlsvc, which contains interesting data structures
+ * including: the share cache
+ */
+
+#include <mdb/mdb_modapi.h>
+#include <mdb/mdb_ks.h>
+#include <mdb/mdb_ctf.h>
+
+#include <synch.h>
+#include <smbsrv/hash_table.h>
+#include <smbsrv/libsmb.h>
+#include <smbsrv/smb_share.h>
+
+#define MLSVC_OBJNAME "libmlsvc.so.1"
+#define MLSVC_SCOPE MLSVC_OBJNAME "`"
+
+#define AFLAG 1
+#define VFLAG 2
+
+typedef struct dump_shr_args {
+ uint_t dsa_opts;
+ uintptr_t dsa_hdl;
+ smb_share_t dsa_shr;
+} dump_shr_args_t;
+
+/*ARGSUSED*/
+static int
+dump_shr_cb(uintptr_t addr, const void *data, void *varg)
+{
+ dump_shr_args_t *args = varg;
+ const HT_ITEM *hi = data;
+ smb_share_t *shr = &args->dsa_shr;
+
+ if (hi->hi_data == NULL)
+ return (WALK_NEXT);
+
+ if ((hi->hi_flags & HT_DELETE) != 0 &&
+ (args->dsa_opts & AFLAG) == 0)
+ return (WALK_NEXT);
+
+ if (args->dsa_opts & VFLAG) {
+ mdb_arg_t argv;
+ int flags = DCMD_ADDRSPEC;
+
+ argv.a_type = MDB_TYPE_STRING;
+ argv.a_un.a_str = MLSVC_SCOPE "smb_share_t";
+ /* Don't fail the walk if this fails. */
+ mdb_printf("%-?p ", hi->hi_data);
+ mdb_call_dcmd("print", (uintptr_t)hi->hi_data,
+ flags, 1, &argv);
+ } else {
+ if (mdb_vread(shr, sizeof (*shr),
+ (uintptr_t)hi->hi_data) == -1) {
+ mdb_warn("failed to read %s at %p",
+ "smb_share_t", hi->hi_data);
+ return (WALK_NEXT);
+ }
+
+ mdb_printf("%-?p ", hi->hi_data);
+ mdb_printf("name=%s path=%s desc=\"%s\"\n",
+ shr->shr_name, shr->shr_path, shr->shr_cmnt);
+ }
+
+ return (WALK_NEXT);
+}
+
+
+/*
+ * *************************** Top level dcmds ****************************
+ */
+
+typedef struct mdb_smb_shr_cache {
+ HT_HANDLE *sc_cache;
+ rwlock_t sc_cache_lck;
+ mutex_t sc_mtx;
+ cond_t sc_cv;
+ uint32_t sc_state;
+ uint32_t sc_nops;
+} mdb_smb_shr_cache_t;
+
+
+static void
+smb_shr_cache_help(void)
+{
+ mdb_printf(
+ "Displays the list of shares in the smbd smb_shr_cache.\n"
+ "With -a, also show deleted entries.\n"
+ "With -v, print full smb_share_t objects.\n\n");
+}
+
+/*
+ * ::smb_shr_cache
+ */
+/*ARGSUSED*/
+static int
+smb_shr_cache_dcmd(uintptr_t addr, uint_t flags, int argc,
+ const mdb_arg_t *argv)
+{
+ dump_shr_args_t *args;
+ mdb_smb_shr_cache_t *ssc;
+
+ args = mdb_zalloc(sizeof (*args), UM_SLEEP | UM_GC);
+
+ if (mdb_getopts(argc, argv,
+ 'a', MDB_OPT_SETBITS, AFLAG, &args->dsa_opts,
+ 'v', MDB_OPT_SETBITS, VFLAG, &args->dsa_opts,
+ NULL) != argc)
+ return (DCMD_USAGE);
+
+ if (!(flags & DCMD_ADDRSPEC)) {
+ GElf_Sym sym;
+
+ /* Locate the shr hash head. */
+ if (mdb_lookup_by_obj(MLSVC_OBJNAME, "smb_shr_cache", &sym)) {
+ mdb_warn("failed to lookup `smb_shr_cache'\n");
+ return (DCMD_ERR);
+ }
+ addr = sym.st_value;
+ }
+
+ ssc = mdb_zalloc(sizeof (*ssc), UM_SLEEP | UM_GC);
+ if (mdb_ctf_vread(ssc, MLSVC_SCOPE "smb_shr_cache_t",
+ "mdb_smb_shr_cache_t", addr, 0) < 0) {
+ mdb_warn("failed to read smb_shr_cache at %p", addr);
+ return (DCMD_ERR);
+ }
+
+ /* Now walk HT_HANDLE *sc_cache */
+ args->dsa_hdl = (uintptr_t)ssc->sc_cache;
+
+ if (mdb_pwalk(MLSVC_SCOPE "smb_ht_walker",
+ dump_shr_cb, args, args->dsa_hdl) == -1) {
+ mdb_warn("cannot walk smb_shr_cache list");
+ return (DCMD_ERR);
+ }
+ return (DCMD_OK);
+}
+
+
+
+/*
+ * MDB module linkage information:
+ *
+ * We declare a list of structures describing our dcmds, a list of structures
+ * describing our walkers and a function named _mdb_init to return a pointer
+ * to our module information.
+ */
+static const mdb_dcmd_t dcmds[] = {
+
+ /* Avoiding name conflict with smbsrv`smb_shr_cache */
+ { "smbd_shr_cache",
+ "[-av]",
+ "print SMB share cache",
+ smb_shr_cache_dcmd,
+ smb_shr_cache_help },
+
+ { NULL }
+};
+
+int smb_ht_walk_init(mdb_walk_state_t *wsp);
+int smb_ht_walk_step(mdb_walk_state_t *wsp);
+
+static const mdb_walker_t walkers[] = {
+ { "smb_ht_walker",
+ "walk an smb_hash_t structure",
+ smb_ht_walk_init,
+ smb_ht_walk_step,
+ NULL,
+ NULL },
+ { NULL }
+};
+
+static const mdb_modinfo_t modinfo = {
+ MDB_API_VERSION, dcmds, walkers
+};
+
+const mdb_modinfo_t *
+_mdb_init(void)
+{
+ return (&modinfo);
+}
diff --git a/usr/src/cmd/mdb/common/modules/libmlsvc/smb_ht.c b/usr/src/cmd/mdb/common/modules/libmlsvc/smb_ht.c
new file mode 100644
index 0000000000..a060d9f0e4
--- /dev/null
+++ b/usr/src/cmd/mdb/common/modules/libmlsvc/smb_ht.c
@@ -0,0 +1,106 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2018 Nexenta Systems, Inc. All rights reserved.
+ */
+
+/*
+ * walker for libsmb : smb_ht.c (hash tables)
+ */
+
+#include <mdb/mdb_modapi.h>
+#include <mdb/mdb_ks.h>
+#include <mdb/mdb_ctf.h>
+
+#include <smbsrv/hash_table.h>
+
+/* smb_ht_walk info */
+struct hw_info {
+ HT_HANDLE hw_handle; /* struct ht_handle being walked */
+ HT_TABLE_ENTRY hw_tblent;
+ HT_ITEM hw_item;
+ int hw_idx;
+};
+
+/*
+ * Walker for libsmb/smb_ht.c code. Calls the call-back function with
+ * each HT_ITEM object. Top-level is HT_HANDLE, passed to _walk_init.
+ */
+int
+smb_ht_walk_init(mdb_walk_state_t *wsp)
+{
+ struct hw_info *hw;
+ uintptr_t addr = wsp->walk_addr;
+ HT_HANDLE *ht;
+
+ if (addr == NULL) {
+ mdb_printf("require address of an HT_HANDLE\n");
+ return (WALK_ERR);
+ }
+
+ /*
+ * allocate the AVL walk data
+ */
+ wsp->walk_data = hw = mdb_zalloc(sizeof (*hw), UM_GC|UM_SLEEP);
+
+ /*
+ * get an mdb copy of the HT_HANDLE being walked
+ */
+ ht = &hw->hw_handle;
+ if (mdb_vread(ht, sizeof (*ht), wsp->walk_addr) == -1) {
+ mdb_warn("failed to read %s at %#lx",
+ "HT_HANDLE", wsp->walk_addr);
+ return (WALK_ERR);
+ }
+
+ hw->hw_idx = -1;
+ wsp->walk_addr = NULL;
+ wsp->walk_data = hw;
+
+ return (WALK_NEXT);
+}
+
+int
+smb_ht_walk_step(mdb_walk_state_t *wsp)
+{
+ struct hw_info *hw = wsp->walk_data;
+ HT_TABLE_ENTRY *he = &hw->hw_tblent;
+ HT_ITEM *hi = &hw->hw_item;
+ uintptr_t he_addr;
+ int rv;
+
+ while (wsp->walk_addr == NULL) {
+ if (++hw->hw_idx >= hw->hw_handle.ht_table_size)
+ return (WALK_DONE);
+ he_addr = (uintptr_t)hw->hw_handle.ht_table +
+ (hw->hw_idx * sizeof (HT_TABLE_ENTRY));
+ if (mdb_vread(he, sizeof (*he), he_addr) == -1) {
+ mdb_warn("failed to read %s at %p",
+ "HT_TABLE_ENTRY", wsp->walk_addr);
+ return (WALK_ERR);
+ }
+ wsp->walk_addr = (uintptr_t)he->he_head;
+ }
+
+ if (mdb_vread(hi, sizeof (*hi), wsp->walk_addr) == -1) {
+ mdb_warn("failed to read %s at %p",
+ "HT_ITEM", wsp->walk_addr);
+ return (WALK_ERR);
+ }
+
+ rv = wsp->walk_callback(wsp->walk_addr, hi,
+ wsp->walk_cbdata);
+
+ wsp->walk_addr = (uintptr_t)hi->hi_next;
+
+ return (rv);
+}
diff --git a/usr/src/cmd/mdb/intel/amd64/libmlsvc/Makefile b/usr/src/cmd/mdb/intel/amd64/libmlsvc/Makefile
new file mode 100644
index 0000000000..33157930f7
--- /dev/null
+++ b/usr/src/cmd/mdb/intel/amd64/libmlsvc/Makefile
@@ -0,0 +1,46 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# Copyright 2018 Nexenta Systems, Inc. All rights reserved.
+#
+
+MODULE = libmlsvc.so
+MDBTGT = proc
+
+MODSRCS = mlsvc.c smb_ht.c
+
+include ../../../../Makefile.cmd
+include ../../../../Makefile.cmd.64
+include ../../Makefile.amd64
+include ../../../Makefile.module
+
+MODSRCS_DIR = ../../../common/modules/libmlsvc
+
+# CPPFLAGS += -I$(SRC)/lib/smbsrv/libmlsvc
+CPPFLAGS += -I$(SRC)/uts/common
+
+CSTD= $(CSTD_GNU99)
+C99MODE= -xc99=%all
+C99LMODE= -Xc99=%all
diff --git a/usr/src/cmd/mdb/intel/ia32/libmlsvc/Makefile b/usr/src/cmd/mdb/intel/ia32/libmlsvc/Makefile
new file mode 100644
index 0000000000..0d889ab4ab
--- /dev/null
+++ b/usr/src/cmd/mdb/intel/ia32/libmlsvc/Makefile
@@ -0,0 +1,45 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# Copyright 2018 Nexenta Systems, Inc. All rights reserved.
+#
+
+MODULE = libmlsvc.so
+MDBTGT = proc
+
+MODSRCS = mlsvc.c smb_ht.c
+
+include ../../../../Makefile.cmd
+include ../../Makefile.ia32
+include ../../../Makefile.module
+
+MODSRCS_DIR = ../../../common/modules/libmlsvc
+
+# CPPFLAGS += -I$(SRC)/lib/smbsrv/libmlsvc
+CPPFLAGS += -I$(SRC)/uts/common
+
+CSTD= $(CSTD_GNU99)
+C99MODE= -xc99=%all
+C99LMODE= -Xc99=%all
diff --git a/usr/src/pkg/manifests/service-file-system-smb.mf b/usr/src/pkg/manifests/service-file-system-smb.mf
index bb8f384499..6a9242b816 100644
--- a/usr/src/pkg/manifests/service-file-system-smb.mf
+++ b/usr/src/pkg/manifests/service-file-system-smb.mf
@@ -21,7 +21,7 @@
#
# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
-# Copyright 2014 Nexenta Systems, Inc. All rights reserved.
+# Copyright 2018 Nexenta Systems, Inc. All rights reserved.
#
set name=pkg.fmri value=pkg:/service/file-system/smb@$(PKGVERS)
@@ -49,6 +49,7 @@ dir path=usr/lib/fs/smb/$(ARCH64) group=sys
dir path=usr/lib/mdb group=sys
dir path=usr/lib/mdb/kvm group=sys
dir path=usr/lib/mdb/kvm/$(ARCH64) group=sys
+dir path=usr/lib/mdb/proc group=sys
dir path=usr/lib/reparse
dir path=usr/lib/security
dir path=usr/lib/smbsrv
@@ -74,6 +75,7 @@ file path=usr/kernel/kmdb/$(ARCH64)/smbsrv group=sys mode=0555
file path=usr/lib/fs/smb/$(ARCH64)/libshare_smb.so.1
file path=usr/lib/fs/smb/libshare_smb.so.1
file path=usr/lib/mdb/kvm/$(ARCH64)/smbsrv.so group=sys mode=0555
+file path=usr/lib/mdb/proc/libmlsvc.so group=sys mode=0555
file path=usr/lib/reparse/libreparse_smb.so.1
file path=usr/lib/security/pam_smb_passwd.so.1
file path=usr/lib/smbsrv/dtrace/smbd-all.d mode=0555
diff --git a/usr/src/tools/quick/make-smbsrv b/usr/src/tools/quick/make-smbsrv
index d5809420d2..45a6f2d178 100755
--- a/usr/src/tools/quick/make-smbsrv
+++ b/usr/src/tools/quick/make-smbsrv
@@ -216,16 +216,14 @@ done
# mdb_arch is both 32-bit & 64-bit
for a in $mdb_arch
do
- (cd $SRC/cmd/mdb/$x/$a/libfksmbsrv &&
- $make $1 )
+ # We build these libraries (to the proto area), so we need to
+ # build the mdb modules for all dependent libraries too.
-# We build these libraries (to the proto area), so we need to
-# build the mdb modules too so mdb will load them.
- (cd $SRC/cmd/mdb/$x/$a/libcmdutils &&
- $make $1 )
- (cd $SRC/cmd/mdb/$x/$a/libavl &&
- $make $1 )
+ for lib in libfksmbsrv libmlsvc libcmdutils libavl
+ do
+ (cd $SRC/cmd/mdb/$x/$a/$lib && $make $1 )
+ done
done
}
@@ -272,6 +270,7 @@ usr/lib/fs/smb/$arch64/libshare_smb.so.1
usr/lib/fs/smb/libshare_smb.so.1
usr/lib/libsmbfs.so.1
usr/lib/mdb/kvm/$arch64/smbsrv.so
+usr/lib/mdb/proc/libmlsvc.so
usr/lib/reparse/libreparse_smb.so.1
usr/lib/security/pam_smb_passwd.so.1
usr/lib/smbsrv/dtrace