--- old/exception_lists/packaging	Mon Nov  6 02:54:31 2017
+++ new/exception_lists/packaging	Mon Nov  6 02:54:31 2017
@@ -26,6 +26,7 @@
 # Copyright 2016 Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
 # Copyright 2016 Nexenta Systems, Inc.
 # Copyright 2017 Toomas Soome <tsoome@me.com>
+# Copyright 2017 RackTop Systems.
 #
 
 #
@@ -723,19 +724,19 @@
 usr/include/smb
 usr/include/smbsrv
 #
-# Private/Internal libraries for smbsrv in user space
+# Private/Internal files for libfakekernel. Do not ship.
 #
+lib/amd64/libfakekernel.so			i386
+lib/amd64/llib-lfakekernel.ln			i386
+lib/sparcv9/libfakekernel.so			sparc
+lib/sparcv9/llib-lfakekernel.ln			sparc
+lib/libfakekernel.so
+lib/llib-lfakekernel
+lib/llib-lfakekernel.ln
 usr/include/libfakekernel
 usr/lib/libfakekernel.so
-usr/lib/libfakekernel.so.1
-usr/lib/llib-lfakekernel
-usr/lib/llib-lfakekernel.ln
-usr/lib/amd64/llib-lfakekernel.ln		i386
-usr/lib/sparcv9/llib-lfakekernel.ln		sparc
 usr/lib/amd64/libfakekernel.so			i386
-usr/lib/amd64/libfakekernel.so.1		i386
 usr/lib/sparcv9/libfakekernel.so		sparc
-usr/lib/sparcv9/libfakekernel.so.1		sparc
 #
 # Private/Internal libraries of smbsrv. Do not ship.
 #
--- old/usr/src/Targetdirs	Mon Nov  6 02:54:31 2017
+++ new/usr/src/Targetdirs	Mon Nov  6 02:54:31 2017
@@ -24,10 +24,10 @@
 # Copyright (c) 2012 by Delphix. All rights reserved.
 # Copyright (c) 2012, Igor Kozhukhov <ikozhukhov@gmail.com>
 # Copyright 2012 OmniTI Computer Consulting, Inc.  All rights reserved.
-# Copyright (c) 2013 RackTop Systems.
 # Copyright 2014 Garrett D'Amore <garrett@damore.org>
 # Copyright 2016 Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
 # Copyright 2016 Nexenta Systems, Inc.
+# Copyright 2017 RackTop Systems.
 #
 
 #
@@ -849,6 +849,8 @@
 $(ROOT)/usr/lib/libefi.so:=		REALPATH=../../lib/libefi.so.1
 $(ROOT)/usr/lib/libelf.so.1:=		REALPATH=../../lib/libelf.so.1
 $(ROOT)/usr/lib/libelf.so:=		REALPATH=../../lib/libelf.so.1
+$(ROOT)/usr/lib/libfakekernel.so.1:=	REALPATH=../../lib/libfakekernel.so.1
+$(ROOT)/usr/lib/libfakekernel.so:=	REALPATH=../../lib/libfakekernel.so.1
 $(ROOT)/usr/lib/libfdisk.so.1:=		REALPATH=../../lib/libfdisk.so.1
 $(ROOT)/usr/lib/libfdisk.so:=		REALPATH=../../lib/libfdisk.so.1
 $(ROOT)/usr/lib/libgen.so.1:=		REALPATH=../../lib/libgen.so.1
@@ -1306,6 +1308,10 @@
 	REALPATH=../../../lib/$(MACH64)/libzfs_core.so.1
 $(ROOT)/usr/lib/$(MACH64)/libzfs_core.so.1:= \
 	REALPATH=../../../lib/$(MACH64)/libzfs_core.so.1
+$(ROOT)/usr/lib/$(MACH64)/libfakekernel.so:= \
+	REALPATH=../../../lib/$(MACH64)/libfakekernel.so.1
+$(ROOT)/usr/lib/$(MACH64)/libfakekernel.so.1:= \
+	REALPATH=../../../lib/$(MACH64)/libfakekernel.so.1
 $(ROOT)/usr/lib/$(MACH64)/libfdisk.so.1:= \
 	REALPATH=../../../lib/$(MACH64)/libfdisk.so.1
 $(ROOT)/usr/lib/$(MACH64)/libfdisk.so:= \
@@ -1482,6 +1488,8 @@
 	/usr/lib/libefi.so.1 \
 	/usr/lib/libelf.so \
 	/usr/lib/libelf.so.1 \
+	/usr/lib/libfakekernel.so \
+	/usr/lib/libfakekernel.so.1 \
 	/usr/lib/libgen.so \
 	/usr/lib/libgen.so.1 \
 	/usr/lib/libinetutil.so \
@@ -1731,6 +1739,8 @@
 	/usr/lib/$(MACH64)/libefi.so.1 \
 	/usr/lib/$(MACH64)/libelf.so \
 	/usr/lib/$(MACH64)/libelf.so.1 \
+	/usr/lib/$(MACH64)/libfakekernel.so \
+	/usr/lib/$(MACH64)/libfakekernel.so.1 \
 	/usr/lib/$(MACH64)/libgen.so \
 	/usr/lib/$(MACH64)/libgen.so.1 \
 	/usr/lib/$(MACH64)/libinetutil.so \
--- old/usr/src/cmd/mdb/intel/amd64/libzpool/Makefile	Mon Nov  6 02:54:31 2017
+++ new/usr/src/cmd/mdb/intel/amd64/libzpool/Makefile	Mon Nov  6 02:54:31 2017
@@ -23,6 +23,8 @@
 # Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
+# Copyright 2017 RackTop Systems.
+#
 
 MODULE = libzpool.so
 MDBTGT = proc
@@ -38,6 +40,7 @@
 MODSRCS_DIR = ../../../common/modules/zfs
 GENUNIX_DIR = ../../../common/modules/genunix
 
+CPPFLAGS.first = -I$(SRC)/lib/libfakekernel/common -D_FAKE_KERNEL
 CPPFLAGS += -I../../../../../lib/libzpool/common \
 	-I../../../../../uts/common/fs/zfs
 
--- old/usr/src/cmd/mdb/intel/ia32/libzpool/Makefile	Mon Nov  6 02:54:32 2017
+++ new/usr/src/cmd/mdb/intel/ia32/libzpool/Makefile	Mon Nov  6 02:54:32 2017
@@ -24,6 +24,7 @@
 # Use is subject to license terms.
 #
 # Copyright (c) 2016 by Delphix. All rights reserved.
+# Copyright 2017 RackTop Systems.
 #
 
 MODULE = libzpool.so
@@ -39,6 +40,7 @@
 MODSRCS_DIR = ../../../common/modules/zfs
 GENUNIX_DIR = ../../../common/modules/genunix
 
+CPPFLAGS.first = -I$(SRC)/lib/libfakekernel/common -D_FAKE_KERNEL
 CPPFLAGS += -I../../../../../lib/libzpool/common \
 	-I../../../../../uts/common/fs/zfs \
 	-I../../../../../uts/common/fs/zfs/lua
--- old/usr/src/cmd/zdb/Makefile.com	Mon Nov  6 02:54:32 2017
+++ new/usr/src/cmd/zdb/Makefile.com	Mon Nov  6 02:54:32 2017
@@ -24,6 +24,7 @@
 # Use is subject to license terms.
 # Copyright (c) 2012 by Delphix. All rights reserved.
 # Copyright 2017 Joyent, Inc.
+# Copyright 2017 RackTop Systems.
 #
 
 PROG:sh=	cd ..; basename `pwd`
@@ -37,7 +38,7 @@
 INCS +=	-I../../../uts/common/fs/zfs
 INCS +=	-I../../../common/zfs
 
-LDLIBS += -lzpool -lumem -lnvpair -lzfs -lavl -lcmdutils
+LDLIBS += -lzpool -lumem -lnvpair -lzfs -lavl -lcmdutils -lfakekernel
 
 C99MODE=	-xc99=%all
 C99LMODE=	-Xc99=%all
@@ -44,6 +45,7 @@
 
 CFLAGS += $(CCVERBOSE)
 CFLAGS64 += $(CCVERBOSE)
+CPPFLAGS.first = -I$(SRC)/lib/libfakekernel/common -D_FAKE_KERNEL
 CPPFLAGS += -D_LARGEFILE64_SOURCE=1 -D_REENTRANT $(INCS) -DDEBUG
 
 # re-enable warnings that we can tolerate, which are disabled by default
--- old/usr/src/cmd/zdb/zdb.c	Mon Nov  6 02:54:32 2017
+++ new/usr/src/cmd/zdb/zdb.c	Mon Nov  6 02:54:32 2017
@@ -24,6 +24,7 @@
  * Copyright (c) 2011, 2016 by Delphix. All rights reserved.
  * Copyright (c) 2014 Integros [integros.com]
  * Copyright 2017 Nexenta Systems, Inc.
+ * Copyright 2017 RackTop Systems.
  */
 
 #include <stdio.h>
@@ -94,6 +95,7 @@
 
 static const char cmdname[] = "zdb";
 uint8_t dump_opt[256];
+extern int aok;
 
 typedef void object_viewer_t(objset_t *, uint64_t, void *data, size_t size);
 
--- old/usr/src/cmd/zfs/zfs_main.c	Mon Nov  6 02:54:32 2017
+++ new/usr/src/cmd/zfs/zfs_main.c	Mon Nov  6 02:54:32 2017
@@ -60,6 +60,7 @@
 #include <sys/fs/zfs.h>
 #include <sys/types.h>
 #include <time.h>
+#include <synch.h>
 
 #include <libzfs.h>
 #include <libzfs_core.h>
@@ -5749,8 +5750,13 @@
 
 #define	CHECK_SPINNER 30
 #define	SPINNER_TIME 3		/* seconds */
-#define	MOUNT_TIME 5		/* seconds */
+#define	MOUNT_TIME 1		/* seconds */
 
+typedef struct get_all_state {
+	boolean_t	ga_verbose;
+	get_all_cb_t	*ga_cbp;
+} get_all_state_t;
+
 static int
 get_one_dataset(zfs_handle_t *zhp, void *data)
 {
@@ -5758,10 +5764,10 @@
 	static int spinval = 0;
 	static int spincheck = 0;
 	static time_t last_spin_time = (time_t)0;
-	get_all_cb_t *cbp = data;
+	get_all_state_t *state = data;
 	zfs_type_t type = zfs_get_type(zhp);
 
-	if (cbp->cb_verbose) {
+	if (state->ga_verbose) {
 		if (--spincheck < 0) {
 			time_t now = time(NULL);
 			if (last_spin_time + SPINNER_TIME < now) {
@@ -5787,26 +5793,24 @@
 		zfs_close(zhp);
 		return (0);
 	}
-	libzfs_add_handle(cbp, zhp);
-	assert(cbp->cb_used <= cbp->cb_alloc);
+	libzfs_add_handle(state->ga_cbp, zhp);
+	assert(state->ga_cbp->cb_used <= state->ga_cbp->cb_alloc);
 
 	return (0);
 }
 
 static void
-get_all_datasets(zfs_handle_t ***dslist, size_t *count, boolean_t verbose)
+get_all_datasets(get_all_cb_t *cbp, boolean_t verbose)
 {
-	get_all_cb_t cb = { 0 };
-	cb.cb_verbose = verbose;
-	cb.cb_getone = get_one_dataset;
+	get_all_state_t state = {
+	    .ga_verbose = verbose,
+	    .ga_cbp = cbp
+	};
 
 	if (verbose)
 		set_progress_header(gettext("Reading ZFS config"));
-	(void) zfs_iter_root(g_zfs, get_one_dataset, &cb);
+	(void) zfs_iter_root(g_zfs, get_one_dataset, &state);
 
-	*dslist = cb.cb_handles;
-	*count = cb.cb_used;
-
 	if (verbose)
 		finish_progress(gettext("done."));
 }
@@ -5816,9 +5820,20 @@
  * similar, we have a common function with an extra parameter to determine which
  * mode we are using.
  */
-#define	OP_SHARE	0x1
-#define	OP_MOUNT	0x2
+typedef enum { OP_SHARE, OP_MOUNT } share_mount_op_t;
 
+typedef struct share_mount_state {
+	share_mount_op_t sm_op;
+	boolean_t sm_verbose;
+	int	sm_flags;
+	char	*sm_options;
+	char	*sm_proto; /* only valid for OP_SHARE */
+	mutex_t	sm_lock; /* protects the remaining fields */
+	uint_t	sm_total; /* number of filesystems to process */
+	uint_t	sm_done; /* number of filesystems processed */
+	int	sm_status; /* -1 if any of the share/mount operations failed */
+} share_mount_state_t;
+
 /*
  * Share or mount a dataset.
  */
@@ -6059,6 +6074,29 @@
 		update_progress(info);
 }
 
+/*
+ * zfs_foreach_mountpoint() callback that mounts or shares one filesystem and
+ * updates the progress meter.
+ */
+static int
+share_mount_one_cb(zfs_handle_t *zhp, void *arg)
+{
+	share_mount_state_t *sms = arg;
+	int ret;
+
+	ret = share_mount_one(zhp, sms->sm_op, sms->sm_flags, sms->sm_proto,
+	    B_FALSE, sms->sm_options);
+
+	(void) mutex_lock(&sms->sm_lock);
+	if (ret != 0)
+		sms->sm_status = ret;
+	sms->sm_done++;
+	if (sms->sm_verbose)
+		report_mount_progress(sms->sm_done, sms->sm_total);
+	(void) mutex_unlock(&sms->sm_lock);
+	return (ret);
+}
+
 static void
 append_options(char *mntopts, char *newopts)
 {
@@ -6131,8 +6169,6 @@
 
 	/* check number of arguments */
 	if (do_all) {
-		zfs_handle_t **dslist = NULL;
-		size_t i, count = 0;
 		char *protocol = NULL;
 
 		if (op == OP_SHARE && argc > 0) {
@@ -6153,33 +6189,44 @@
 		}
 
 		start_progress_timer();
-		get_all_datasets(&dslist, &count, verbose);
+		get_all_cb_t cb = { 0 };
+		get_all_datasets(&cb, verbose);
 
-		if (count == 0)
+		if (cb.cb_used == 0)
 			return (0);
 
-		qsort(dslist, count, sizeof (void *), libzfs_dataset_cmp);
-		sa_init_selective_arg_t sharearg;
-		sharearg.zhandle_arr = dslist;
-		sharearg.zhandle_len = count;
-		if ((ret = zfs_init_libshare_arg(zfs_get_handle(dslist[0]),
-		    SA_INIT_SHARE_API_SELECTIVE, &sharearg)) != SA_OK) {
-			(void) fprintf(stderr,
-			    gettext("Could not initialize libshare, %d"), ret);
-			return (ret);
+		if (op == OP_SHARE) {
+			sa_init_selective_arg_t sharearg;
+			sharearg.zhandle_arr = cb.cb_handles;
+			sharearg.zhandle_len = cb.cb_used;
+			if ((ret = zfs_init_libshare_arg(g_zfs,
+			    SA_INIT_SHARE_API_SELECTIVE, &sharearg)) != SA_OK) {
+				(void) fprintf(stderr, gettext(
+				    "Could not initialize libshare, %d"), ret);
+				return (ret);
+			}
 		}
 
-		for (i = 0; i < count; i++) {
-			if (verbose)
-				report_mount_progress(i, count);
+		share_mount_state_t share_mount_state = { 0 };
+		share_mount_state.sm_op = op;
+		share_mount_state.sm_verbose = verbose;
+		share_mount_state.sm_flags = flags;
+		share_mount_state.sm_options = options;
+		share_mount_state.sm_proto = protocol;
+		share_mount_state.sm_total = cb.cb_used;
+		(void) mutex_init(&share_mount_state.sm_lock, USYNC_THREAD,
+		    NULL);
+		/*
+		 * libshare isn't mt-safe, so only do the operation in parallel
+		 * if we're mounting.
+		 */
+		zfs_foreach_mountpoint(g_zfs, cb.cb_handles, cb.cb_used,
+		    share_mount_one_cb, &share_mount_state, op == OP_MOUNT);
+		ret = share_mount_state.sm_status;
 
-			if (share_mount_one(dslist[i], op, flags, protocol,
-			    B_FALSE, options) != 0)
-				ret = 1;
-			zfs_close(dslist[i]);
-		}
-
-		free(dslist);
+		for (int i = 0; i < cb.cb_used; i++)
+			zfs_close(cb.cb_handles[i]);
+		free(cb.cb_handles);
 	} else if (argc == 0) {
 		struct mnttab entry;
 
--- old/usr/src/cmd/zhack/Makefile.com	Mon Nov  6 02:54:33 2017
+++ new/usr/src/cmd/zhack/Makefile.com	Mon Nov  6 02:54:33 2017
@@ -26,6 +26,7 @@
 
 #
 # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
+# Copyright 2017 RackTop Systems.
 #
 
 PROG= zhack
@@ -47,6 +48,7 @@
 
 CFLAGS += $(CCVERBOSE)
 CFLAGS64 += $(CCVERBOSE)
+CPPFLAGS.first = -I$(SRC)/lib/libfakekernel/common -D_FAKE_KERNEL
 CPPFLAGS += -D_LARGEFILE64_SOURCE=1 -D_REENTRANT -DDEBUG $(INCS)
 
 LINTFLAGS += -erroff=E_STATIC_UNUSED
--- old/usr/src/cmd/zinject/Makefile.com	Mon Nov  6 02:54:33 2017
+++ new/usr/src/cmd/zinject/Makefile.com	Mon Nov  6 02:54:33 2017
@@ -23,6 +23,7 @@
 # Use is subject to license terms.
 #
 # Copyright (c) 2016 by Delphix. All rights reserved.
+# Copyright 2017 RackTop Systems.
 #
 
 PROG:sh=	cd ..; basename `pwd`
@@ -40,6 +41,7 @@
 C99MODE=	-xc99=%all
 C99LMODE=	-Xc99=%all
 
+CPPFLAGS.first = -I$(SRC)/lib/libfakekernel/common -D_FAKE_KERNEL
 CPPFLAGS += -D_LARGEFILE64_SOURCE=1 -D_REENTRANT $(INCS)
 
 CERRWARN += -_gcc=-Wno-uninitialized
--- old/usr/src/cmd/ztest/Makefile.com	Mon Nov  6 02:54:33 2017
+++ new/usr/src/cmd/ztest/Makefile.com	Mon Nov  6 02:54:33 2017
@@ -21,6 +21,7 @@
 #
 # Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
 # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
+# Copyright 2017 RackTop Systems.
 #
 
 PROG= ztest
@@ -35,12 +36,13 @@
 INCS += -I../../../uts/common/fs/zfs/lua
 INCS += -I../../../common/zfs
 
-LDLIBS += -lumem -lzpool -lcmdutils -lm -lnvpair
+LDLIBS += -lumem -lzpool -lcmdutils -lm -lnvpair -lfakekernel
 
 C99MODE= -xc99=%all
 C99LMODE= -Xc99=%all
 CFLAGS += -g $(CCVERBOSE)
 CFLAGS64 += -g $(CCVERBOSE)
+CPPFLAGS.first = -I$(SRC)/lib/libfakekernel/common -D_FAKE_KERNEL
 CPPFLAGS += -D_LARGEFILE64_SOURCE=1 -D_REENTRANT $(INCS) -DDEBUG
 
 # lint complains about unused _umem_* functions
--- old/usr/src/cmd/ztest/ztest.c	Mon Nov  6 02:54:33 2017
+++ new/usr/src/cmd/ztest/ztest.c	Mon Nov  6 02:54:33 2017
@@ -25,6 +25,7 @@
  * Copyright (c) 2013 Steven Hartland. All rights reserved.
  * Copyright (c) 2014 Integros [integros.com]
  * Copyright 2017 Joyent, Inc.
+ * Copyright 2017 RackTop Systems.
  */
 
 /*
@@ -245,8 +246,8 @@
 typedef struct rll {
 	void		*rll_writer;
 	int		rll_readers;
-	mutex_t		rll_lock;
-	cond_t		rll_cv;
+	kmutex_t	rll_lock;
+	kcondvar_t	rll_cv;
 } rll_t;
 
 typedef struct rl {
@@ -280,11 +281,11 @@
 typedef struct ztest_ds {
 	ztest_shared_ds_t *zd_shared;
 	objset_t	*zd_os;
-	rwlock_t	zd_zilog_lock;
+	krwlock_t	zd_zilog_lock;
 	zilog_t		*zd_zilog;
 	ztest_od_t	*zd_od;		/* debugging aid */
 	char		zd_name[ZFS_MAX_DATASET_NAME_LEN];
-	mutex_t		zd_dirobj_lock;
+	kmutex_t	zd_dirobj_lock;
 	rll_t		zd_object_lock[ZTEST_OBJECT_LOCKS];
 	rll_t		zd_range_lock[ZTEST_RANGE_LOCKS];
 } ztest_ds_t;
@@ -391,7 +392,7 @@
  * The callbacks are ordered by txg number.
  */
 typedef struct ztest_cb_list {
-	mutex_t	zcl_callbacks_lock;
+	kmutex_t zcl_callbacks_lock;
 	list_t	zcl_callbacks;
 } ztest_cb_list_t;
 
@@ -426,7 +427,7 @@
 static spa_t *ztest_spa = NULL;
 static ztest_ds_t *ztest_ds;
 
-static mutex_t ztest_vdev_lock;
+static kmutex_t ztest_vdev_lock;
 
 /*
  * The ztest_name_lock protects the pool and dataset namespace used by
@@ -434,7 +435,7 @@
  * this lock as writer. Grabbing the lock as reader will ensure that the
  * namespace does not change while the lock is held.
  */
-static rwlock_t ztest_name_lock;
+static krwlock_t ztest_name_lock;
 
 static boolean_t ztest_dump_core = B_TRUE;
 static boolean_t ztest_exiting;
@@ -1090,8 +1091,8 @@
 {
 	rll->rll_writer = NULL;
 	rll->rll_readers = 0;
-	VERIFY(_mutex_init(&rll->rll_lock, USYNC_THREAD, NULL) == 0);
-	VERIFY(cond_init(&rll->rll_cv, USYNC_THREAD, NULL) == 0);
+	mutex_init(&rll->rll_lock, NULL, USYNC_THREAD, NULL);
+	cv_init(&rll->rll_cv, NULL, USYNC_THREAD, NULL);
 }
 
 static void
@@ -1099,32 +1100,32 @@
 {
 	ASSERT(rll->rll_writer == NULL);
 	ASSERT(rll->rll_readers == 0);
-	VERIFY(_mutex_destroy(&rll->rll_lock) == 0);
-	VERIFY(cond_destroy(&rll->rll_cv) == 0);
+	mutex_destroy(&rll->rll_lock);
+	cv_destroy(&rll->rll_cv);
 }
 
 static void
 ztest_rll_lock(rll_t *rll, rl_type_t type)
 {
-	VERIFY(mutex_lock(&rll->rll_lock) == 0);
+	mutex_enter(&rll->rll_lock);
 
 	if (type == RL_READER) {
 		while (rll->rll_writer != NULL)
-			(void) cond_wait(&rll->rll_cv, &rll->rll_lock);
+			cv_wait(&rll->rll_cv, &rll->rll_lock);
 		rll->rll_readers++;
 	} else {
 		while (rll->rll_writer != NULL || rll->rll_readers)
-			(void) cond_wait(&rll->rll_cv, &rll->rll_lock);
+			cv_wait(&rll->rll_cv, &rll->rll_lock);
 		rll->rll_writer = curthread;
 	}
 
-	VERIFY(mutex_unlock(&rll->rll_lock) == 0);
+	mutex_exit(&rll->rll_lock);
 }
 
 static void
 ztest_rll_unlock(rll_t *rll)
 {
-	VERIFY(mutex_lock(&rll->rll_lock) == 0);
+	mutex_enter(&rll->rll_lock);
 
 	if (rll->rll_writer) {
 		ASSERT(rll->rll_readers == 0);
@@ -1136,9 +1137,9 @@
 	}
 
 	if (rll->rll_writer == NULL && rll->rll_readers == 0)
-		VERIFY(cond_broadcast(&rll->rll_cv) == 0);
+		cv_broadcast(&rll->rll_cv);
 
-	VERIFY(mutex_unlock(&rll->rll_lock) == 0);
+	mutex_exit(&rll->rll_lock);
 }
 
 static void
@@ -1197,8 +1198,8 @@
 	if (zd->zd_shared != NULL)
 		zd->zd_shared->zd_seq = 0;
 
-	VERIFY(rwlock_init(&zd->zd_zilog_lock, USYNC_THREAD, NULL) == 0);
-	VERIFY(_mutex_init(&zd->zd_dirobj_lock, USYNC_THREAD, NULL) == 0);
+	rw_init(&zd->zd_zilog_lock, NULL, USYNC_THREAD, NULL);
+	mutex_init(&zd->zd_dirobj_lock, NULL, USYNC_THREAD, NULL);
 
 	for (int l = 0; l < ZTEST_OBJECT_LOCKS; l++)
 		ztest_rll_init(&zd->zd_object_lock[l]);
@@ -1210,7 +1211,7 @@
 static void
 ztest_zd_fini(ztest_ds_t *zd)
 {
-	VERIFY(_mutex_destroy(&zd->zd_dirobj_lock) == 0);
+	mutex_destroy(&zd->zd_dirobj_lock);
 
 	for (int l = 0; l < ZTEST_OBJECT_LOCKS; l++)
 		ztest_rll_destroy(&zd->zd_object_lock[l]);
@@ -1965,7 +1966,7 @@
 	int missing = 0;
 	int error;
 
-	ASSERT(_mutex_held(&zd->zd_dirobj_lock));
+	ASSERT(MUTEX_HELD(&zd->zd_dirobj_lock));
 
 	for (int i = 0; i < count; i++, od++) {
 		od->od_object = 0;
@@ -2005,7 +2006,7 @@
 {
 	int missing = 0;
 
-	ASSERT(_mutex_held(&zd->zd_dirobj_lock));
+	ASSERT(MUTEX_HELD(&zd->zd_dirobj_lock));
 
 	for (int i = 0; i < count; i++, od++) {
 		if (missing) {
@@ -2050,7 +2051,7 @@
 	int missing = 0;
 	int error;
 
-	ASSERT(_mutex_held(&zd->zd_dirobj_lock));
+	ASSERT(MUTEX_HELD(&zd->zd_dirobj_lock));
 
 	od += count - 1;
 
@@ -2196,7 +2197,7 @@
 	if (ztest_random(2) == 0)
 		io_type = ZTEST_IO_WRITE_TAG;
 
-	(void) rw_rdlock(&zd->zd_zilog_lock);
+	rw_enter(&zd->zd_zilog_lock, RW_READER);
 
 	switch (io_type) {
 
@@ -2233,7 +2234,7 @@
 		break;
 
 	case ZTEST_IO_REWRITE:
-		(void) rw_rdlock(&ztest_name_lock);
+		rw_enter(&ztest_name_lock, RW_READER);
 		err = ztest_dsl_prop_set_uint64(zd->zd_name,
 		    ZFS_PROP_CHECKSUM, spa_dedup_checksum(ztest_spa),
 		    B_FALSE);
@@ -2243,7 +2244,7 @@
 		    ztest_random_dsl_prop(ZFS_PROP_COMPRESSION),
 		    B_FALSE);
 		VERIFY(err == 0 || err == ENOSPC);
-		(void) rw_unlock(&ztest_name_lock);
+		rw_exit(&ztest_name_lock);
 
 		VERIFY0(dmu_read(zd->zd_os, object, offset, blocksize, data,
 		    DMU_READ_NO_PREFETCH));
@@ -2252,7 +2253,7 @@
 		break;
 	}
 
-	(void) rw_unlock(&zd->zd_zilog_lock);
+	rw_exit(&zd->zd_zilog_lock);
 
 	umem_free(data, blocksize);
 }
@@ -2291,13 +2292,13 @@
 	int count = size / sizeof (*od);
 	int rv = 0;
 
-	VERIFY(mutex_lock(&zd->zd_dirobj_lock) == 0);
+	mutex_enter(&zd->zd_dirobj_lock);
 	if ((ztest_lookup(zd, od, count) != 0 || remove) &&
 	    (ztest_remove(zd, od, count) != 0 ||
 	    ztest_create(zd, od, count) != 0))
 		rv = -1;
 	zd->zd_od = od;
-	VERIFY(mutex_unlock(&zd->zd_dirobj_lock) == 0);
+	mutex_exit(&zd->zd_dirobj_lock);
 
 	return (rv);
 }
@@ -2308,7 +2309,7 @@
 {
 	zilog_t *zilog = zd->zd_zilog;
 
-	(void) rw_rdlock(&zd->zd_zilog_lock);
+	rw_enter(&zd->zd_zilog_lock, RW_READER);
 
 	zil_commit(zilog, ztest_random(ZTEST_OBJECTS));
 
@@ -2323,7 +2324,7 @@
 	zd->zd_shared->zd_seq = zilog->zl_commit_lr_seq;
 	mutex_exit(&zilog->zl_lock);
 
-	(void) rw_unlock(&zd->zd_zilog_lock);
+	rw_exit(&zd->zd_zilog_lock);
 }
 
 /*
@@ -2342,8 +2343,8 @@
 	 * updating the zil (i.e. adding in-memory log records) and the
 	 * zd_zilog_lock to block any I/O.
 	 */
-	VERIFY0(mutex_lock(&zd->zd_dirobj_lock));
-	(void) rw_wrlock(&zd->zd_zilog_lock);
+	mutex_enter(&zd->zd_dirobj_lock);
+	rw_enter(&zd->zd_zilog_lock, RW_WRITER);
 
 	/* zfsvfs_teardown() */
 	zil_close(zd->zd_zilog);
@@ -2352,8 +2353,8 @@
 	VERIFY(zil_open(os, ztest_get_data) == zd->zd_zilog);
 	zil_replay(os, zd, ztest_replay_vector);
 
-	(void) rw_unlock(&zd->zd_zilog_lock);
-	VERIFY(mutex_unlock(&zd->zd_dirobj_lock) == 0);
+	rw_exit(&zd->zd_zilog_lock);
+	mutex_exit(&zd->zd_dirobj_lock);
 }
 
 /*
@@ -2388,7 +2389,7 @@
 	 * Attempt to create an existing pool.  It shouldn't matter
 	 * what's in the nvroot; we should fail with EEXIST.
 	 */
-	(void) rw_rdlock(&ztest_name_lock);
+	rw_enter(&ztest_name_lock, RW_READER);
 	nvroot = make_vdev_root("/dev/bogus", NULL, NULL, 0, 0, 0, 0, 0, 1);
 	VERIFY3U(EEXIST, ==, spa_create(zo->zo_pool, nvroot, NULL, NULL));
 	nvlist_free(nvroot);
@@ -2396,7 +2397,7 @@
 	VERIFY3U(EBUSY, ==, spa_destroy(zo->zo_pool));
 	spa_close(spa, FTAG);
 
-	(void) rw_unlock(&ztest_name_lock);
+	rw_exit(&ztest_name_lock);
 }
 
 /* ARGSUSED */
@@ -2409,7 +2410,7 @@
 	nvlist_t *nvroot, *props;
 	char *name;
 
-	VERIFY0(mutex_lock(&ztest_vdev_lock));
+	mutex_enter(&ztest_vdev_lock);
 	name = kmem_asprintf("%s_upgrade", ztest_opts.zo_pool);
 
 	/*
@@ -2468,7 +2469,7 @@
 	spa_close(spa, FTAG);
 
 	strfree(name);
-	VERIFY0(mutex_unlock(&ztest_vdev_lock));
+	mutex_exit(&ztest_vdev_lock);
 }
 
 static vdev_t *
@@ -2521,7 +2522,7 @@
 	nvlist_t *nvroot;
 	int error;
 
-	VERIFY(mutex_lock(&ztest_vdev_lock) == 0);
+	mutex_enter(&ztest_vdev_lock);
 	leaves = MAX(zs->zs_mirrors + zs->zs_splits, 1) * ztest_opts.zo_raidz;
 
 	spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER);
@@ -2547,9 +2548,9 @@
 		 * dmu_objset_destroy() to fail with EBUSY thus
 		 * leaving the dataset in an inconsistent state.
 		 */
-		VERIFY(rw_wrlock(&ztest_name_lock) == 0);
+		rw_enter(&ztest_name_lock, RW_WRITER);
 		error = spa_vdev_remove(spa, guid, B_FALSE);
-		VERIFY(rw_unlock(&ztest_name_lock) == 0);
+		rw_exit(&ztest_name_lock);
 
 		if (error && error != EEXIST)
 			fatal(0, "spa_vdev_remove() = %d", error);
@@ -2573,7 +2574,7 @@
 			fatal(0, "spa_vdev_add() = %d", error);
 	}
 
-	VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
+	mutex_exit(&ztest_vdev_lock);
 }
 
 /*
@@ -2599,7 +2600,7 @@
 		aux = ZPOOL_CONFIG_L2CACHE;
 	}
 
-	VERIFY(mutex_lock(&ztest_vdev_lock) == 0);
+	mutex_enter(&ztest_vdev_lock);
 
 	spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER);
 
@@ -2656,7 +2657,7 @@
 			fatal(0, "spa_vdev_remove(%llu) = %d", guid, error);
 	}
 
-	VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
+	mutex_exit(&ztest_vdev_lock);
 }
 
 /*
@@ -2673,11 +2674,11 @@
 	uint_t c, children, schildren = 0, lastlogid = 0;
 	int error = 0;
 
-	VERIFY(mutex_lock(&ztest_vdev_lock) == 0);
+	mutex_enter(&ztest_vdev_lock);
 
 	/* ensure we have a useable config; mirrors of raidz aren't supported */
 	if (zs->zs_mirrors < 3 || ztest_opts.zo_raidz > 1) {
-		VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
+		mutex_exit(&ztest_vdev_lock);
 		return;
 	}
 
@@ -2736,9 +2737,9 @@
 
 	spa_config_exit(spa, SCL_VDEV, FTAG);
 
-	(void) rw_wrlock(&ztest_name_lock);
+	rw_enter(&ztest_name_lock, RW_WRITER);
 	error = spa_vdev_split_mirror(spa, "splitp", config, NULL, B_FALSE);
-	(void) rw_unlock(&ztest_name_lock);
+	rw_exit(&ztest_name_lock);
 
 	nvlist_free(config);
 
@@ -2751,7 +2752,7 @@
 		++zs->zs_splits;
 		--zs->zs_mirrors;
 	}
-	VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
+	mutex_exit(&ztest_vdev_lock);
 
 }
 
@@ -2780,7 +2781,7 @@
 	int oldvd_is_log;
 	int error, expected_error;
 
-	VERIFY(mutex_lock(&ztest_vdev_lock) == 0);
+	mutex_enter(&ztest_vdev_lock);
 	leaves = MAX(zs->zs_mirrors, 1) * ztest_opts.zo_raidz;
 
 	spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER);
@@ -2841,7 +2842,7 @@
 		if (error != 0 && error != ENODEV && error != EBUSY &&
 		    error != ENOTSUP)
 			fatal(0, "detach (%s) returned %d", oldpath, error);
-		VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
+		mutex_exit(&ztest_vdev_lock);
 		return;
 	}
 
@@ -2935,7 +2936,7 @@
 		    newsize, replacing, error, expected_error);
 	}
 
-	VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
+	mutex_exit(&ztest_vdev_lock);
 }
 
 /*
@@ -3063,7 +3064,7 @@
 	uint64_t top;
 	uint64_t old_class_space, new_class_space, old_ms_count, new_ms_count;
 
-	VERIFY(mutex_lock(&ztest_vdev_lock) == 0);
+	mutex_enter(&ztest_vdev_lock);
 	spa_config_enter(spa, SCL_STATE, spa, RW_READER);
 
 	top = ztest_random_vdev_top(spa, B_TRUE);
@@ -3091,7 +3092,7 @@
 	if (tvd->vdev_state != VDEV_STATE_HEALTHY ||
 	    psize == 0 || psize >= 4 * ztest_opts.zo_vdev_size) {
 		spa_config_exit(spa, SCL_STATE, spa);
-		VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
+		mutex_exit(&ztest_vdev_lock);
 		return;
 	}
 	ASSERT(psize > 0);
@@ -3116,7 +3117,7 @@
 			    "the vdev configuration changed.\n");
 		}
 		spa_config_exit(spa, SCL_STATE, spa);
-		VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
+		mutex_exit(&ztest_vdev_lock);
 		return;
 	}
 
@@ -3150,7 +3151,7 @@
 			    "intervening vdev offline or remove.\n");
 		}
 		spa_config_exit(spa, SCL_STATE, spa);
-		VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
+		mutex_exit(&ztest_vdev_lock);
 		return;
 	}
 
@@ -3178,7 +3179,7 @@
 	}
 
 	spa_config_exit(spa, SCL_STATE, spa);
-	VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
+	mutex_exit(&ztest_vdev_lock);
 }
 
 /*
@@ -3292,7 +3293,7 @@
 	char name[ZFS_MAX_DATASET_NAME_LEN];
 	zilog_t *zilog;
 
-	(void) rw_rdlock(&ztest_name_lock);
+	rw_enter(&ztest_name_lock, RW_READER);
 
 	(void) snprintf(name, sizeof (name), "%s/temp_%llu",
 	    ztest_opts.zo_pool, (u_longlong_t)id);
@@ -3331,7 +3332,7 @@
 	if (error) {
 		if (error == ENOSPC) {
 			ztest_record_enospc(FTAG);
-			(void) rw_unlock(&ztest_name_lock);
+			rw_exit(&ztest_name_lock);
 			return;
 		}
 		fatal(0, "dmu_objset_create(%s) = %d", name, error);
@@ -3379,7 +3380,7 @@
 	dmu_objset_disown(os, FTAG);
 	ztest_zd_fini(&zdtmp);
 
-	(void) rw_unlock(&ztest_name_lock);
+	rw_exit(&ztest_name_lock);
 }
 
 /*
@@ -3388,10 +3389,10 @@
 void
 ztest_dmu_snapshot_create_destroy(ztest_ds_t *zd, uint64_t id)
 {
-	(void) rw_rdlock(&ztest_name_lock);
+	rw_enter(&ztest_name_lock, RW_READER);
 	(void) ztest_snapshot_destroy(zd->zd_name, id);
 	(void) ztest_snapshot_create(zd->zd_name, id);
-	(void) rw_unlock(&ztest_name_lock);
+	rw_exit(&ztest_name_lock);
 }
 
 /*
@@ -3450,7 +3451,7 @@
 	char *osname = zd->zd_name;
 	int error;
 
-	(void) rw_rdlock(&ztest_name_lock);
+	rw_enter(&ztest_name_lock, RW_READER);
 
 	ztest_dsl_dataset_cleanup(osname, id);
 
@@ -3527,7 +3528,7 @@
 out:
 	ztest_dsl_dataset_cleanup(osname, id);
 
-	(void) rw_unlock(&ztest_name_lock);
+	rw_exit(&ztest_name_lock);
 }
 
 /*
@@ -4461,9 +4462,9 @@
 	ASSERT3U(data->zcd_txg, !=, 0);
 
 	/* Remove our callback from the list */
-	(void) mutex_lock(&zcl.zcl_callbacks_lock);
+	mutex_enter(&zcl.zcl_callbacks_lock);
 	list_remove(&zcl.zcl_callbacks, data);
-	(void) mutex_unlock(&zcl.zcl_callbacks_lock);
+	mutex_exit(&zcl.zcl_callbacks_lock);
 
 out:
 	umem_free(data, sizeof (ztest_cb_data_t));
@@ -4565,7 +4566,7 @@
 
 	dmu_write(os, od[0].od_object, 0, sizeof (uint64_t), &txg, tx);
 
-	(void) mutex_lock(&zcl.zcl_callbacks_lock);
+	mutex_enter(&zcl.zcl_callbacks_lock);
 
 	/*
 	 * Since commit callbacks don't have any ordering requirement and since
@@ -4612,7 +4613,7 @@
 		tmp_cb = cb_data[i];
 	}
 
-	(void) mutex_unlock(&zcl.zcl_callbacks_lock);
+	mutex_exit(&zcl.zcl_callbacks_lock);
 
 	dmu_tx_commit(tx);
 }
@@ -4628,13 +4629,13 @@
 		ZFS_PROP_DEDUP
 	};
 
-	(void) rw_rdlock(&ztest_name_lock);
+	rw_enter(&ztest_name_lock, RW_READER);
 
 	for (int p = 0; p < sizeof (proplist) / sizeof (proplist[0]); p++)
 		(void) ztest_dsl_prop_set_uint64(zd->zd_name, proplist[p],
 		    ztest_random_dsl_prop(proplist[p]), (int)ztest_random(2));
 
-	(void) rw_unlock(&ztest_name_lock);
+	rw_exit(&ztest_name_lock);
 }
 
 /* ARGSUSED */
@@ -4643,7 +4644,7 @@
 {
 	nvlist_t *props = NULL;
 
-	(void) rw_rdlock(&ztest_name_lock);
+	rw_enter(&ztest_name_lock, RW_READER);
 
 	(void) ztest_spa_prop_set_uint64(ZPOOL_PROP_DEDUPDITTO,
 	    ZIO_DEDUPDITTO_MIN + ztest_random(ZIO_DEDUPDITTO_MIN));
@@ -4655,7 +4656,7 @@
 
 	nvlist_free(props);
 
-	(void) rw_unlock(&ztest_name_lock);
+	rw_exit(&ztest_name_lock);
 }
 
 static int
@@ -4690,7 +4691,7 @@
 	char osname[ZFS_MAX_DATASET_NAME_LEN];
 	nvlist_t *holds;
 
-	(void) rw_rdlock(&ztest_name_lock);
+	rw_enter(&ztest_name_lock, RW_READER);
 
 	dmu_objset_name(os, osname);
 
@@ -4795,7 +4796,7 @@
 	VERIFY3U(dmu_objset_hold(fullname, FTAG, &origin), ==, ENOENT);
 
 out:
-	(void) rw_unlock(&ztest_name_lock);
+	rw_exit(&ztest_name_lock);
 }
 
 /*
@@ -4823,11 +4824,11 @@
 	uint64_t guid0 = 0;
 	boolean_t islog = B_FALSE;
 
-	VERIFY(mutex_lock(&ztest_vdev_lock) == 0);
+	mutex_enter(&ztest_vdev_lock);
 	maxfaults = MAXFAULTS();
 	leaves = MAX(zs->zs_mirrors, 1) * ztest_opts.zo_raidz;
 	mirror_save = zs->zs_mirrors;
-	VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
+	mutex_exit(&ztest_vdev_lock);
 
 	ASSERT(leaves >= 1);
 
@@ -4837,7 +4838,7 @@
 	 * they are in progress (i.e. spa_change_guid). Those
 	 * operations will have grabbed the name lock as writer.
 	 */
-	(void) rw_rdlock(&ztest_name_lock);
+	rw_enter(&ztest_name_lock, RW_READER);
 
 	/*
 	 * We need SCL_STATE here because we're going to look at vd0->vdev_tsd.
@@ -4906,7 +4907,7 @@
 
 		if (sav->sav_count == 0) {
 			spa_config_exit(spa, SCL_STATE, FTAG);
-			(void) rw_unlock(&ztest_name_lock);
+			rw_exit(&ztest_name_lock);
 			return;
 		}
 		vd0 = sav->sav_vdevs[ztest_random(sav->sav_count)];
@@ -4920,7 +4921,7 @@
 	}
 
 	spa_config_exit(spa, SCL_STATE, FTAG);
-	(void) rw_unlock(&ztest_name_lock);
+	rw_exit(&ztest_name_lock);
 
 	/*
 	 * If we can tolerate two or more faults, or we're dealing
@@ -4940,12 +4941,12 @@
 			 * leaving the dataset in an inconsistent state.
 			 */
 			if (islog)
-				(void) rw_wrlock(&ztest_name_lock);
+				rw_enter(&ztest_name_lock, RW_WRITER);
 
 			VERIFY(vdev_offline(spa, guid0, flags) != EBUSY);
 
 			if (islog)
-				(void) rw_unlock(&ztest_name_lock);
+				rw_exit(&ztest_name_lock);
 		} else {
 			/*
 			 * Ideally we would like to be able to randomly
@@ -4956,9 +4957,9 @@
 			 * prevent a race between injection testing and
 			 * aux_vdev removal.
 			 */
-			VERIFY(mutex_lock(&ztest_vdev_lock) == 0);
+			mutex_enter(&ztest_vdev_lock);
 			(void) vdev_online(spa, guid0, 0, NULL);
-			VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
+			mutex_exit(&ztest_vdev_lock);
 		}
 	}
 
@@ -5030,9 +5031,9 @@
 		    offset + sizeof (bad) > psize - VDEV_LABEL_END_SIZE)
 			continue;
 
-		VERIFY(mutex_lock(&ztest_vdev_lock) == 0);
+		mutex_enter(&ztest_vdev_lock);
 		if (mirror_save != zs->zs_mirrors) {
-			VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
+			mutex_exit(&ztest_vdev_lock);
 			(void) close(fd);
 			return;
 		}
@@ -5041,7 +5042,7 @@
 			fatal(1, "can't inject bad word at 0x%llx in %s",
 			    offset, pathrand);
 
-		VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
+		mutex_exit(&ztest_vdev_lock);
 
 		if (ztest_opts.zo_verbose >= 7)
 			(void) printf("injected bad word into %s,"
@@ -5081,13 +5082,13 @@
 	 * Take the name lock as writer to prevent anyone else from changing
 	 * the pool and dataset properies we need to maintain during this test.
 	 */
-	(void) rw_wrlock(&ztest_name_lock);
+	rw_enter(&ztest_name_lock, RW_WRITER);
 
 	if (ztest_dsl_prop_set_uint64(zd->zd_name, ZFS_PROP_DEDUP, checksum,
 	    B_FALSE) != 0 ||
 	    ztest_dsl_prop_set_uint64(zd->zd_name, ZFS_PROP_COPIES, 1,
 	    B_FALSE) != 0) {
-		(void) rw_unlock(&ztest_name_lock);
+		rw_exit(&ztest_name_lock);
 		return;
 	}
 
@@ -5106,7 +5107,7 @@
 	dmu_tx_hold_write(tx, object, 0, copies * blocksize);
 	txg = ztest_tx_assign(tx, TXG_WAIT, FTAG);
 	if (txg == 0) {
-		(void) rw_unlock(&ztest_name_lock);
+		rw_exit(&ztest_name_lock);
 		return;
 	}
 
@@ -5154,7 +5155,7 @@
 
 	abd_free(abd);
 
-	(void) rw_unlock(&ztest_name_lock);
+	rw_exit(&ztest_name_lock);
 }
 
 /*
@@ -5185,9 +5186,9 @@
 	orig = spa_guid(spa);
 	load = spa_load_guid(spa);
 
-	(void) rw_wrlock(&ztest_name_lock);
+	rw_enter(&ztest_name_lock, RW_WRITER);
 	error = spa_change_guid(spa);
-	(void) rw_unlock(&ztest_name_lock);
+	rw_exit(&ztest_name_lock);
 
 	if (error != 0)
 		return;
@@ -5211,7 +5212,7 @@
 	char *oldname, *newname;
 	spa_t *spa;
 
-	(void) rw_wrlock(&ztest_name_lock);
+	rw_enter(&ztest_name_lock, RW_WRITER);
 
 	oldname = ztest_opts.zo_pool;
 	newname = umem_alloc(strlen(oldname) + 5, UMEM_NOFAIL);
@@ -5251,7 +5252,7 @@
 
 	umem_free(newname, strlen(newname) + 1);
 
-	(void) rw_unlock(&ztest_name_lock);
+	rw_exit(&ztest_name_lock);
 }
 
 /*
@@ -5606,11 +5607,11 @@
 
 	ztest_dataset_name(name, ztest_opts.zo_pool, d);
 
-	(void) rw_rdlock(&ztest_name_lock);
+	rw_enter(&ztest_name_lock, RW_READER);
 
 	error = ztest_dataset_create(name);
 	if (error == ENOSPC) {
-		(void) rw_unlock(&ztest_name_lock);
+		rw_exit(&ztest_name_lock);
 		ztest_record_enospc(FTAG);
 		return (error);
 	}
@@ -5617,7 +5618,7 @@
 	ASSERT(error == 0 || error == EEXIST);
 
 	VERIFY0(dmu_objset_own(name, DMU_OST_OTHER, B_FALSE, zd, &os));
-	(void) rw_unlock(&ztest_name_lock);
+	rw_exit(&ztest_name_lock);
 
 	ztest_zd_init(zd, ZTEST_GET_SHARED_DS(d), os);
 
@@ -5668,10 +5669,10 @@
 static void
 ztest_run(ztest_shared_t *zs)
 {
-	thread_t *tid;
+	pthread_t *tid;
 	spa_t *spa;
 	objset_t *os;
-	thread_t resume_tid;
+	pthread_t resume_tid;
 	int error;
 
 	ztest_exiting = B_FALSE;
@@ -5679,8 +5680,8 @@
 	/*
 	 * Initialize parent/child shared state.
 	 */
-	VERIFY(_mutex_init(&ztest_vdev_lock, USYNC_THREAD, NULL) == 0);
-	VERIFY(rwlock_init(&ztest_name_lock, USYNC_THREAD, NULL) == 0);
+	mutex_init(&ztest_vdev_lock, NULL, USYNC_THREAD, NULL);
+	rw_init(&ztest_name_lock, NULL, USYNC_THREAD, NULL);
 
 	zs->zs_thread_start = gethrtime();
 	zs->zs_thread_stop =
@@ -5692,7 +5693,7 @@
 		    ztest_random(ztest_opts.zo_passtime * NANOSEC);
 	}
 
-	(void) _mutex_init(&zcl.zcl_callbacks_lock, USYNC_THREAD, NULL);
+	mutex_init(&zcl.zcl_callbacks_lock, NULL, USYNC_THREAD, NULL);
 
 	list_create(&zcl.zcl_callbacks, sizeof (ztest_cb_data_t),
 	    offsetof(ztest_cb_data_t, zcd_node));
@@ -5730,14 +5731,14 @@
 	/*
 	 * Create a thread to periodically resume suspended I/O.
 	 */
-	VERIFY(thr_create(0, 0, ztest_resume_thread, spa, THR_BOUND,
-	    &resume_tid) == 0);
+	VERIFY(pthread_create(&resume_tid, NULL, ztest_resume_thread,
+	    spa) == 0);
 
 	/*
 	 * Create a deadman thread to abort() if we hang.
 	 */
-	VERIFY(thr_create(0, 0, ztest_deadman_thread, zs, THR_BOUND,
-	    NULL) == 0);
+	VERIFY(pthread_create(&resume_tid, NULL, ztest_deadman_thread,
+	    zs) == 0);
 
 	/*
 	 * Verify that we can safely inquire about about any object,
@@ -5763,7 +5764,7 @@
 	}
 	zs->zs_enospc_count = 0;
 
-	tid = umem_zalloc(ztest_opts.zo_threads * sizeof (thread_t),
+	tid = umem_zalloc(ztest_opts.zo_threads * sizeof (pthread_t),
 	    UMEM_NOFAIL);
 
 	if (ztest_opts.zo_verbose >= 4)
@@ -5776,8 +5777,8 @@
 		if (t < ztest_opts.zo_datasets &&
 		    ztest_dataset_open(t) != 0)
 			return;
-		VERIFY(thr_create(0, 0, ztest_thread, (void *)(uintptr_t)t,
-		    THR_BOUND, &tid[t]) == 0);
+		VERIFY(pthread_create(&tid[t], NULL, ztest_thread,
+		    (void *)(uintptr_t)t) == 0);
 	}
 
 	/*
@@ -5785,7 +5786,7 @@
 	 * so we don't close datasets while threads are still using them.
 	 */
 	for (int t = ztest_opts.zo_threads - 1; t >= 0; t--) {
-		VERIFY(thr_join(tid[t], NULL, NULL) == 0);
+		VERIFY(pthread_join(tid[t], NULL) == 0);
 		if (t < ztest_opts.zo_datasets)
 			ztest_dataset_close(t);
 	}
@@ -5796,11 +5797,11 @@
 	zs->zs_space = metaslab_class_get_space(spa_normal_class(spa));
 	zfs_dbgmsg_print(FTAG);
 
-	umem_free(tid, ztest_opts.zo_threads * sizeof (thread_t));
+	umem_free(tid, ztest_opts.zo_threads * sizeof (pthread_t));
 
 	/* Kill the resume thread */
 	ztest_exiting = B_TRUE;
-	VERIFY(thr_join(resume_tid, NULL, NULL) == 0);
+	VERIFY(pthread_join(resume_tid, NULL) == 0);
 	ztest_resume(spa);
 
 	/*
@@ -5839,10 +5840,10 @@
 
 	list_destroy(&zcl.zcl_callbacks);
 
-	(void) _mutex_destroy(&zcl.zcl_callbacks_lock);
+	mutex_destroy(&zcl.zcl_callbacks_lock);
 
-	(void) rwlock_destroy(&ztest_name_lock);
-	(void) _mutex_destroy(&ztest_vdev_lock);
+	rw_destroy(&ztest_name_lock);
+	mutex_destroy(&ztest_vdev_lock);
 }
 
 static void
@@ -5986,8 +5987,8 @@
 	spa_t *spa;
 	nvlist_t *nvroot, *props;
 
-	VERIFY(_mutex_init(&ztest_vdev_lock, USYNC_THREAD, NULL) == 0);
-	VERIFY(rwlock_init(&ztest_name_lock, USYNC_THREAD, NULL) == 0);
+	mutex_init(&ztest_vdev_lock, NULL, USYNC_THREAD, NULL);
+	rw_init(&ztest_name_lock, NULL, USYNC_THREAD, NULL);
 
 	kernel_init(FREAD | FWRITE);
 
@@ -6025,8 +6026,8 @@
 
 	ztest_run_zdb(ztest_opts.zo_pool);
 
-	(void) rwlock_destroy(&ztest_name_lock);
-	(void) _mutex_destroy(&ztest_vdev_lock);
+	rw_destroy(&ztest_name_lock);
+	mutex_destroy(&ztest_vdev_lock);
 }
 
 static void
--- old/usr/src/lib/Makefile	Mon Nov  6 02:54:34 2017
+++ new/usr/src/lib/Makefile	Mon Nov  6 02:54:34 2017
@@ -29,6 +29,7 @@
 # Copyright 2016 Toomas Soome <tsoome@me.com>
 # Copyright 2017 Nexenta Systems, Inc.
 # Copyright (c) 2016, Chris Fraire <cfraire@me.com>.
+# Copyright 2017 RackTop Systems.
 #
 
 include ../Makefile.master
@@ -673,12 +674,12 @@
 libvscan:	libscf libsecdb
 libwanboot:	libresolv2 libdevinfo libinetutil libdhcputil
 libzfs:		libdevid libgen libuutil libadm libavl libefi libidmap \
-		libumem libtsol libzfs_core
+		libumem libtsol libzfs_core libfakekernel
 libzfs_jni:	libdiskmgt libzfs
 libzonecfg:	libuuid libsysevent libsec libbrand libpool libscf libproc \
 		libuutil libbsm libsecdb
 libzonestat:	libcmdutils libumem
-libzpool:	libavl libumem libcmdutils libsysevent
+libzpool:	libavl libumem libcmdutils libsysevent libfakekernel
 madv:		libgen
 mpapi:		libpthread libdevinfo libsysevent
 mpss:		libgen
--- old/usr/src/lib/libfakekernel/Makefile.com	Mon Nov  6 02:54:34 2017
+++ new/usr/src/lib/libfakekernel/Makefile.com	Mon Nov  6 02:54:34 2017
@@ -11,6 +11,7 @@
 
 #
 # Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
+# Copyright 2017 RackTop Systems.
 #
 
 LIBRARY =	libfakekernel.a
@@ -21,9 +22,11 @@
 	clock.o \
 	cond.o \
 	copy.o \
+	buf.o \
 	kiconv.o \
 	kmem.o \
 	kmisc.o \
+	ksid.o \
 	ksocket.o \
 	kstat.o \
 	mutex.o \
@@ -39,6 +42,9 @@
 
 include ../../Makefile.lib
 
+# libfakekernel must be installed in the root filesystem for libzfs
+include ../../Makefile.rootfs
+
 SRCDIR=		../common
 
 LIBS =		$(DYNLIB) $(LINTLIB)
--- /dev/null	Mon Nov  6 02:54:34 2017
+++ new/usr/src/lib/libfakekernel/common/buf.c	Mon Nov  6 02:54:35 2017
@@ -0,0 +1,77 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (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 (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2015 by Delphix. All rights reserved.
+ * Copyright (c) 2013, Joyent, Inc.  All rights reserved.
+ * Copyright 2017 RackTop Systems.
+ */
+
+#include <sys/debug.h>
+#include <sys/buf.h>
+#include <sys/errno.h>
+
+#include <strings.h>
+
+void
+bioinit(buf_t *bp)
+{
+	bzero(bp, sizeof (buf_t));
+}
+
+void
+biodone(buf_t *bp)
+{
+	if (bp->b_iodone != NULL) {
+		(*(bp->b_iodone))(bp);
+		return;
+	}
+	ASSERT((bp->b_flags & B_DONE) == 0);
+	bp->b_flags |= B_DONE;
+}
+
+void
+bioerror(buf_t *bp, int error)
+{
+	ASSERT(bp != NULL);
+	ASSERT(error >= 0);
+
+	if (error != 0) {
+		bp->b_flags |= B_ERROR;
+	} else {
+		bp->b_flags &= ~B_ERROR;
+	}
+	bp->b_error = error;
+}
+
+
+int
+geterror(struct buf *bp)
+{
+	int error = 0;
+
+	if (bp->b_flags & B_ERROR) {
+		error = bp->b_error;
+		if (!error)
+			error = EIO;
+	}
+	return (error);
+}
--- old/usr/src/lib/libfakekernel/common/cond.c	Mon Nov  6 02:54:35 2017
+++ new/usr/src/lib/libfakekernel/common/cond.c	Mon Nov  6 02:54:35 2017
@@ -11,6 +11,7 @@
 
 /*
  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
+ * Copyright 2017 RackTop Systems.
  */
 
 /*
@@ -118,6 +119,19 @@
 	return (cv__twait(cv, mp, delta, 1));
 }
 
+/*ARGSUSED*/
+clock_t
+cv_timedwait_hires(kcondvar_t *cv, kmutex_t *mp, hrtime_t tim, hrtime_t res,
+	int flag)
+{
+	clock_t delta;
+
+	delta = tim;
+	if (flag & CALLOUT_FLAG_ABSOLUTE)
+		delta -= gethrtime();
+	return (cv__twait(cv, mp, delta, 0));
+}
+
 clock_t
 cv_reltimedwait(kcondvar_t *cv, kmutex_t *mp, clock_t delta, time_res_t res)
 {
--- old/usr/src/lib/libfakekernel/common/cred.c	Mon Nov  6 02:54:35 2017
+++ new/usr/src/lib/libfakekernel/common/cred.c	Mon Nov  6 02:54:35 2017
@@ -11,6 +11,7 @@
 
 /*
  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
+ * Copyright 2017 RackTop Systems.
  */
 
 
@@ -52,6 +53,34 @@
 	return (0);
 }
 
+/*ARGSUSED*/
+uid_t
+crgetruid(const cred_t *cr)
+{
+	return (0);
+}
+
+/*ARGSUSED*/
+uid_t
+crgetgid(const cred_t *cr)
+{
+	return (0);
+}
+
+/*ARGSUSED*/
+int
+crgetngroups(const cred_t *cr)
+{
+	return (0);
+}
+
+/*ARGSUSED*/
+const gid_t *
+crgetgroups(const cred_t *cr)
+{
+	return (NULL);
+}
+
 cred_t *
 zone_kcred(void)
 {
--- old/usr/src/lib/libfakekernel/common/kmem.c	Mon Nov  6 02:54:35 2017
+++ new/usr/src/lib/libfakekernel/common/kmem.c	Mon Nov  6 02:54:35 2017
@@ -11,6 +11,7 @@
 
 /*
  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
+ * Copyright 2017 RackTop Systems.
  */
 
 #include <sys/kmem.h>
@@ -18,6 +19,7 @@
 #include <sys/debug.h>
 #include <sys/ksynch.h>
 #include <sys/systm.h>
+#include <sys/cmn_err.h>
 
 #include <umem.h>
 
@@ -65,7 +67,30 @@
 	return (umem_zalloc(size, kmem2umem_flags(kmflags)));
 }
 
+/*
+ * Do not change the length of the returned string; it must be freed
+ * with strfree().
+ */
+char *
+kmem_asprintf(const char *fmt, ...)
+{
+	int size;
+	va_list adx;
+	char *buf;
 
+	va_start(adx, fmt);
+	size = vsnprintf(NULL, 0, fmt, adx) + 1;
+	va_end(adx);
+
+	buf = kmem_alloc(size, KM_SLEEP);
+
+	va_start(adx, fmt);
+	size = vsnprintf(buf, size, fmt, adx);
+	va_end(adx);
+
+	return (buf);
+}
+
 void
 kmem_free(void *buf, size_t size)
 {
--- old/usr/src/lib/libfakekernel/common/kmisc.c	Mon Nov  6 02:54:35 2017
+++ new/usr/src/lib/libfakekernel/common/kmisc.c	Mon Nov  6 02:54:35 2017
@@ -11,6 +11,7 @@
 
 /*
  * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
+ * Copyright 2017 RackTop Systems.
  */
 
 #include <sys/types.h>
@@ -18,6 +19,7 @@
 #include <sys/thread.h>
 #include <sys/proc.h>
 #include <sys/zone.h>
+#include <sys/cyclic.h>
 
 #include <sys/poll.h>
 
@@ -24,6 +26,7 @@
 #include <time.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <errno.h>
 
 #include <fakekernel.h>
 
@@ -55,13 +58,58 @@
 	return ((pid_t)getpid());
 }
 
+/*
+ * Find highest one bit set.
+ *	Returns bit number + 1 of highest bit that is set, otherwise returns 0.
+ */
 int
+highbit64(uint64_t i)
+{
+	int h = 1;
+
+	if (i == 0)
+		return (0);
+	if (i & 0xffffffff00000000ULL) {
+		h += 32; i >>= 32;
+	}
+	if (i & 0xffff0000) {
+		h += 16; i >>= 16;
+	}
+	if (i & 0xff00) {
+		h += 8; i >>= 8;
+	}
+	if (i & 0xf0) {
+		h += 4; i >>= 4;
+	}
+	if (i & 0xc) {
+		h += 2; i >>= 2;
+	}
+	if (i & 0x2) {
+		h += 1;
+	}
+	return (h);
+}
+
+int
 ddi_strtoul(const char *str, char **endp, int base, unsigned long *res)
 {
 	*res = strtoul(str, endp, base);
+	if (*res == 0)
+		return (errno);
 	return (0);
 }
 
+int
+ddi_strtoull(const char *str, char **nptr, int base, u_longlong_t *res)
+{
+	char *end;
+
+	*res = strtoull(str, &end, base);
+	if (*res == 0)
+		return (errno);
+	return (0);
+}
+
 void
 delay(clock_t ticks)
 {
@@ -69,6 +117,32 @@
 	(void) poll(0, 0, msec);
 }
 
+int
+issig(int why)
+{
+	return (0);
+}
+
+/* ARGSUSED */
+cyclic_id_t
+cyclic_add(cyc_handler_t *hdlr, cyc_time_t *when)
+{
+	return (1);
+}
+
+/* ARGSUSED */
+void
+cyclic_remove(cyclic_id_t id)
+{
+}
+
+/* ARGSUSED */
+int
+cyclic_reprogram(cyclic_id_t id, hrtime_t expiration)
+{
+	return (1);
+}
+
 /*
  * This library does not really need an "init" function, but
  * providing one the main program can call is an easy way to
--- /dev/null	Mon Nov  6 02:54:35 2017
+++ new/usr/src/lib/libfakekernel/common/ksid.c	Mon Nov  6 02:54:35 2017
@@ -0,0 +1,68 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (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 (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2015 by Delphix. All rights reserved.
+ * Copyright (c) 2013, Joyent, Inc.  All rights reserved.
+ * Copyright 2017 RackTop Systems.
+ */
+
+#include <sys/sid.h>
+
+#include <umem.h>
+#include <strings.h>
+
+static char *
+ksid_strdup(const char *s)
+{
+	size_t len;
+	char *new;
+
+	len = strlen(s);
+	new = umem_alloc(len + 1, KM_SLEEP);
+	bcopy(s, new, len);
+	new[len] = '\0';
+
+	return (new);
+}
+
+static void
+ksid_strfree(char *s)
+{
+	umem_free(s, strlen(s) + 1);
+}
+
+ksiddomain_t *
+ksid_lookupdomain(const char *dom)
+{
+	ksiddomain_t *kd;
+
+	kd = umem_zalloc(sizeof (ksiddomain_t), UMEM_NOFAIL);
+	kd->kd_name = ksid_strdup(dom);
+	return (kd);
+}
+
+void
+ksiddomain_rele(ksiddomain_t *ksid)
+{
+	ksid_strfree(ksid->kd_name);
+	umem_free(ksid, sizeof (ksiddomain_t));
+}
--- old/usr/src/lib/libfakekernel/common/kstat.c	Mon Nov  6 02:54:35 2017
+++ new/usr/src/lib/libfakekernel/common/kstat.c	Mon Nov  6 02:54:35 2017
@@ -11,6 +11,7 @@
 
 /*
  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
+ * Copyright 2017 RackTop Systems.
  */
 
 #include <sys/types.h>
@@ -36,6 +37,11 @@
 
 /*ARGSUSED*/
 void
+kstat_named_init(kstat_named_t *knp, const char *name, uchar_t type)
+{}
+
+/*ARGSUSED*/
+void
 kstat_install(kstat_t *ksp)
 {}
 
@@ -42,4 +48,34 @@
 /*ARGSUSED*/
 void
 kstat_delete(kstat_t *ksp)
+{}
+
+/*ARGSUSED*/
+void
+kstat_waitq_enter(kstat_io_t *kiop)
+{}
+
+/*ARGSUSED*/
+void
+kstat_waitq_exit(kstat_io_t *kiop)
+{}
+
+/*ARGSUSED*/
+void
+kstat_runq_enter(kstat_io_t *kiop)
+{}
+
+/*ARGSUSED*/
+void
+kstat_runq_exit(kstat_io_t *kiop)
+{}
+
+/*ARGSUSED*/
+void
+kstat_waitq_to_runq(kstat_io_t *kiop)
+{}
+
+/*ARGSUSED*/
+void
+kstat_runq_back_to_waitq(kstat_io_t *kiop)
 {}
--- old/usr/src/lib/libfakekernel/common/mapfile-vers	Mon Nov  6 02:54:35 2017
+++ new/usr/src/lib/libfakekernel/common/mapfile-vers	Mon Nov  6 02:54:35 2017
@@ -11,6 +11,7 @@
 
 #
 # Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
+# Copyright 2017 RackTop Systems.
 #
 
 #
@@ -43,8 +44,21 @@
 	copyinstr;
 	copystr;
 
+	bioerror;
+	biodone;
+	bioinit;
+	geterror;
+
+	cyclic_add;
+	cyclic_remove;
+	cyclic_reprogram;
+
 	crfree;
 	crgetuid;
+	crgetruid;
+	crgetgid;
+	crgetngroups;
+	crgetgroups;
 	crhold;
 
 	cv_broadcast;
@@ -55,6 +69,7 @@
 	cv_signal;
 	cv_timedwait;
 	cv_timedwait_sig;
+	cv_timedwait_hires;
 	cv_wait;
 	cv_wait_sig;
 
@@ -62,9 +77,12 @@
 	ddi_get_lbolt;
 	ddi_get_pid;
 	ddi_strtoul;
+	ddi_strtoull;
 
 	delay;
 
+	fm_panic;
+
 	fakekernel_cprintf	{ FLAGS = NODIRECT };
 	fakekernel_init;
 	fakekernel_putlog	{ FLAGS = NODIRECT };
@@ -75,6 +93,10 @@
 
 	hz;
 
+	highbit64;
+
+	issig;
+
 	kcred;
 	kiconv;
 	kiconv_close;
@@ -81,6 +103,7 @@
 	kiconv_open;
 
 	kmem_alloc;
+	kmem_asprintf;
 	kmem_cache_alloc;
 	kmem_cache_create;
 	kmem_cache_destroy;
@@ -93,10 +116,15 @@
 
 	kmutex_destroy;
 	kmutex_init;
+	kmutex_enter;
+	kmutex_exit;
 
 	ksema_destroy;
 	ksema_init;
 
+	ksid_lookupdomain;
+	ksiddomain_rele;
+
 	ksocket_accept;
 	ksocket_bind;
 	ksocket_bind_helper	{ FLAGS = NODIRECT };
@@ -120,13 +148,18 @@
 
 	kstat_create;
 	kstat_create_zone;
+	kstat_named_init;
 	kstat_delete;
 	kstat_install;
+	kstat_waitq_enter;
+	kstat_waitq_exit;
+	kstat_runq_enter;
+	kstat_runq_exit;
+	kstat_waitq_to_runq;
+	kstat_runq_back_to_waitq;
 
 	msec_per_tick;
 
-	mutex_enter;
-	mutex_exit;
 	mutex_owned;
 	mutex_owner;
 	mutex_tryenter;
@@ -165,10 +198,12 @@
 
 	strfree;
 
+	system_taskq;
 	system_taskq_fini;	
 	system_taskq_init;
 	taskq_create;
 	taskq_create_proc;
+	taskq_create_sysdc;
 	taskq_destroy;
 	taskq_dispatch;
 	taskq_dispatch_ent;
@@ -175,8 +210,15 @@
 	taskq_member;
 	taskq_wait;
 
+	thread_create;
 	thread_join;
+	thread_exit;
 
+	tsd_get;
+	tsd_set;
+	tsd_create;
+	tsd_destroy;
+
 	tick_per_msec;
 	tsignal;
 	uiomove;
--- old/usr/src/lib/libfakekernel/common/mutex.c	Mon Nov  6 02:54:36 2017
+++ new/usr/src/lib/libfakekernel/common/mutex.c	Mon Nov  6 02:54:36 2017
@@ -11,6 +11,7 @@
 
 /*
  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
+ * Copyright 2017 RackTop Systems.
  */
 
 /*
@@ -51,7 +52,7 @@
 }
 
 void
-mutex_enter(kmutex_t *mp)
+kmutex_enter(kmutex_t *mp)
 {
 	VERIFY(0 == _lwp_mutex_lock(&mp->m_lock));
 	mp->m_owner = _curthread();
@@ -71,7 +72,7 @@
 }
 
 void
-mutex_exit(kmutex_t *mp)
+kmutex_exit(kmutex_t *mp)
 {
 	ASSERT(mp->m_owner == _curthread());
 	mp->m_owner = _KTHREAD_INVALID;
--- old/usr/src/lib/libfakekernel/common/printf.c	Mon Nov  6 02:54:36 2017
+++ new/usr/src/lib/libfakekernel/common/printf.c	Mon Nov  6 02:54:36 2017
@@ -22,6 +22,7 @@
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2012 by Delphix. All rights reserved.
  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
+ * Copyright 2017 RackTop Systems.
  */
 
 #include <sys/param.h>
@@ -123,6 +124,16 @@
 panic(const char *fmt, ...)
 {
 	va_list adx;
+
+	va_start(adx, fmt);
+	vpanic(fmt, adx);
+	va_end(adx);
+}
+
+void
+fm_panic(const char *fmt, ...)
+{
+	va_list adx;
 
 	va_start(adx, fmt);
 	vpanic(fmt, adx);
--- /dev/null	Mon Nov  6 02:54:36 2017
+++ new/usr/src/lib/libfakekernel/common/sys/cmn_err.h	Mon Nov  6 02:54:36 2017
@@ -0,0 +1,80 @@
+/*
+ * 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 (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
+/*	  All Rights Reserved	*/
+
+
+/*
+ * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
+ * Copyright 2016 Joyent, Inc.
+ * Copyright 2017 RackTop Systems.
+ */
+
+#ifndef _SYS_CMN_ERR_H
+#define	_SYS_CMN_ERR_H
+
+#include <stdio.h>
+
+#if !defined(_ASM) && (defined(_KERNEL) || defined(_FAKE_KERNEL))
+#include <sys/va_list.h>
+#endif
+
+#include <sys/dditypes.h>
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+/* Common error handling severity levels */
+
+#define	CE_CONT		0	/* continuation		*/
+#define	CE_NOTE		1	/* notice		*/
+#define	CE_WARN		2	/* warning		*/
+#define	CE_PANIC	3	/* panic		*/
+#define	CE_IGNORE	4	/* print nothing	*/
+
+#if !defined(_ASM) && (defined(_KERNEL) || defined(_FAKE_KERNEL))
+
+/*PRINTFLIKE2*/
+extern void cmn_err(int, const char *, ...)
+    __KPRINTFLIKE(2);
+
+extern void vcmn_err(int, const char *, __va_list)
+    __KVPRINTFLIKE(2);
+
+/*PRINTFLIKE1*/
+extern void panic(const char *, ...)
+    __KPRINTFLIKE(1) __NORETURN;
+
+extern void vpanic(const char *, __va_list)
+    __KVPRINTFLIKE(1) __NORETURN;
+
+#endif /* !_ASM && (_KERNEL || _FAKE_KERNEL) */
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif	/* _SYS_CMN_ERR_H */
--- old/usr/src/lib/libfakekernel/common/sys/condvar.h	Mon Nov  6 02:54:36 2017
+++ new/usr/src/lib/libfakekernel/common/sys/condvar.h	Mon Nov  6 02:54:36 2017
@@ -26,6 +26,7 @@
 /*
  * Copyright (c) 2012 by Delphix. All rights reserved.
  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
+ * Copyright 2017 RackTop Systems.
  */
 
 /*
@@ -78,6 +79,8 @@
 
 #define	TIME_RES_VALID(tr)	(tr >= TR_NANOSEC && tr < TR_COUNT)
 
+#define	CALLOUT_FLAG_ABSOLUTE	0x2
+
 /*
  * condition variable function prototypes
  */
@@ -87,6 +90,8 @@
 extern	void	cv_wait(kcondvar_t *, kmutex_t *);
 extern	void	cv_wait_stop(kcondvar_t *, kmutex_t *, int);
 extern	clock_t	cv_timedwait(kcondvar_t *, kmutex_t *, clock_t);
+extern	clock_t	cv_timedwait_hires(kcondvar_t *, kmutex_t *, hrtime_t, hrtime_t,
+    int);
 extern	clock_t	cv_reltimedwait(kcondvar_t *, kmutex_t *, clock_t, time_res_t);
 extern	int	cv_wait_sig(kcondvar_t *, kmutex_t *);
 extern	clock_t	cv_timedwait_sig(kcondvar_t *, kmutex_t *, clock_t);
--- old/usr/src/lib/libfakekernel/common/sys/cred.h	Mon Nov  6 02:54:36 2017
+++ new/usr/src/lib/libfakekernel/common/sys/cred.h	Mon Nov  6 02:54:36 2017
@@ -20,6 +20,7 @@
  */
 /*
  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
+ * Copyright 2017 RackTop Systems.
  *
  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
@@ -76,6 +77,9 @@
 extern zoneid_t crgetzoneid(const cred_t *);
 extern projid_t crgetprojid(const cred_t *);
 
+extern const gid_t *crgetgroups(const cred_t *);
+extern int crgetngroups(const cred_t *);
+
 #endif	/* _KERNEL */
 
 #ifdef	__cplusplus
--- old/usr/src/lib/libfakekernel/common/sys/mutex.h	Mon Nov  6 02:54:36 2017
+++ new/usr/src/lib/libfakekernel/common/sys/mutex.h	Mon Nov  6 02:54:36 2017
@@ -21,6 +21,7 @@
 /*
  * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
+ * Copyright 2017 RackTop Systems.
  */
 
 #ifndef _SYS_MUTEX_H
@@ -73,6 +74,8 @@
 } pad_mutex_t;
 #endif	/* _KERNEL */
 
+extern char *volatile panicstr;  /* panic string pointer */
+
 #define	MUTEX_HELD(x)		(mutex_owned(x))
 #define	MUTEX_NOT_HELD(x)	(!mutex_owned(x) || panicstr)
 
@@ -83,12 +86,20 @@
 #define	mutex_init	kmutex_init
 #define	mutex_destroy	kmutex_destroy
 
+/*
+ * We want to avoid binding against the versions of these
+ * functions in libc which causes bad things to happen.
+ */
+#define mutex_enter	kmutex_enter
+#define mutex_exit	kmutex_exit
+
 extern	void	kmutex_init(kmutex_t *, char *, kmutex_type_t, void *);
 extern	void	kmutex_destroy(kmutex_t *);
 
-extern	void	mutex_enter(kmutex_t *);
+extern	void	kmutex_enter(kmutex_t *);
+extern	void	kmutex_exit(kmutex_t *);
+
 extern	int	mutex_tryenter(kmutex_t *);
-extern	void	mutex_exit(kmutex_t *);
 extern	int	mutex_owned(const kmutex_t *);
 
 extern	void *mutex_owner(const kmutex_t *);
--- old/usr/src/lib/libfakekernel/common/sys/proc.h	Mon Nov  6 02:54:37 2017
+++ new/usr/src/lib/libfakekernel/common/sys/proc.h	Mon Nov  6 02:54:37 2017
@@ -22,6 +22,7 @@
 /*
  * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
+ * Copyright 2017 RackTop Systems.
  */
 
 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
@@ -110,7 +111,19 @@
 extern struct plock p0lock;	/* p0's plock */
 extern struct pid pid0;		/* p0's pid */
 
+extern int issig(int);
+#define	ISSIG(thr, why)	issig(why)
 
+/* Reasons for calling issig() */
+
+#define	FORREAL		0	/* Usual side-effects */
+#define	JUSTLOOKING	1	/* Don't stop the process */
+
+extern	void	tsd_create(uint_t *, void (*)(void *));
+extern	void	tsd_destroy(uint_t *);
+extern	void	*tsd_get(uint_t);
+extern	int	tsd_set(uint_t, void *);
+
 /*
  * This is normally in sunddi.h but
  * I didn't want to drag that in here.
--- old/usr/src/lib/libfakekernel/common/taskq.c	Mon Nov  6 02:54:37 2017
+++ new/usr/src/lib/libfakekernel/common/taskq.c	Mon Nov  6 02:54:37 2017
@@ -25,6 +25,7 @@
 /*
  * Copyright 2012 Garrett D'Amore <garrett@damore.org>.  All rights reserved.
  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
+ * Copyright 2017 RackTop Systems.
  */
 
 #include <sys/taskq_impl.h>
@@ -38,6 +39,9 @@
 #include <sys/sysmacros.h>
 #include <sys/unistd.h>
 
+/* avoid <sys/disp.h> */
+#define   maxclsyspri     99
+
 /* avoid <unistd.h> */
 extern long sysconf(int);
 
@@ -263,6 +267,15 @@
 	    minalloc, maxalloc, NULL, flags));
 }
 
+/*ARGSUSED*/
+taskq_t *
+taskq_create_sysdc(const char *name, int nthr, int minalloc,
+    int maxalloc, proc_t *proc, uint_t dc, uint_t flags)
+{
+	return (taskq_create_proc(name, nthr, maxclsyspri,
+	    minalloc, maxalloc, proc, flags));
+}
+
 /*ARGSUSED*/
 taskq_t *
 taskq_create_proc(const char *name, int nthreads, pri_t pri,
--- old/usr/src/lib/libfakekernel/common/thread.c	Mon Nov  6 02:54:37 2017
+++ new/usr/src/lib/libfakekernel/common/thread.c	Mon Nov  6 02:54:37 2017
@@ -11,11 +11,13 @@
 
 /*
  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
+ * Copyright 2017 RackTop Systems.
  */
 
 #include <sys/cmn_err.h>
 #include <sys/thread.h>
 #include <sys/zone.h>
+#include <sys/proc.h>
 
 #define	_SYNCH_H	/* keep out <synch.h> */
 #include <thread.h>
@@ -122,4 +124,29 @@
 {
 	thread_exit();
 	/* NOTREACHED */
+}
+
+void
+tsd_create(uint_t *keyp, void (*destructor)(void *))
+{
+	VERIFY0(thr_keycreate(keyp, destructor));
+}
+
+/*ARGSUSED*/
+void
+tsd_destroy(uint_t *keyp)
+{}
+
+void *
+tsd_get(uint_t key)
+{
+	void *value;
+
+	return (thr_getspecific(key, &value) ? NULL : value);
+}
+
+int
+tsd_set(uint_t key, void *value)
+{
+	return (thr_setspecific(key, value));
 }
--- old/usr/src/lib/libzfs/Makefile.com	Mon Nov  6 02:54:37 2017
+++ new/usr/src/lib/libzfs/Makefile.com	Mon Nov  6 02:54:37 2017
@@ -22,6 +22,7 @@
 # Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
 # Copyright 2016 Igor Kozhukhov <ikozhukhov@gmail.com>
 # Copyright (c) 2011, 2016 by Delphix. All rights reserved.
+# Copyright 2017 RackTop Systems.
 #
 
 LIBRARY= libzfs.a
@@ -70,8 +71,10 @@
 C99MODE=	-xc99=%all
 C99LMODE=	-Xc99=%all
 LDLIBS +=	-lc -lm -ldevid -lgen -lnvpair -luutil -lavl -lefi \
-	-ladm -lidmap -ltsol -lmd -lumem -lzfs_core -lcmdutils
-CPPFLAGS +=	$(INCS) -D_LARGEFILE64_SOURCE=1 -D_REENTRANT
+	-ladm -lidmap -ltsol -lmd -lumem -lzfs_core -lcmdutils \
+	-lfakekernel
+CPPFLAGS +=	$(INCS) -D_LARGEFILE64_SOURCE=1 -D_REENTRANT \
+	-D_TASKQUSER
 $(NOT_RELEASE_BUILD)CPPFLAGS += -DDEBUG
 
 # There's no lint library for zlib, so only include this when building
--- old/usr/src/lib/libzfs/common/libzfs.h	Mon Nov  6 02:54:37 2017
+++ new/usr/src/lib/libzfs/common/libzfs.h	Mon Nov  6 02:54:37 2017
@@ -22,7 +22,7 @@
 /*
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2011 Pawel Jakub Dawidek. All rights reserved.
- * Copyright (c) 2011, 2015 by Delphix. All rights reserved.
+ * Copyright (c) 2011, 2016 by Delphix. All rights reserved.
  * Copyright (c) 2012, Joyent, Inc. All rights reserved.
  * Copyright (c) 2013 Steven Hartland. All rights reserved.
  * Copyright (c) 2014 Integros [integros.com]
@@ -560,12 +560,11 @@
 	zfs_handle_t	**cb_handles;
 	size_t		cb_alloc;
 	size_t		cb_used;
-	boolean_t	cb_verbose;
-	int		(*cb_getone)(zfs_handle_t *, void *);
 } get_all_cb_t;
 
+void zfs_foreach_mountpoint(libzfs_handle_t *, zfs_handle_t **, size_t,
+    zfs_iter_f, void *, boolean_t);
 void libzfs_add_handle(get_all_cb_t *, zfs_handle_t *);
-int libzfs_dataset_cmp(const void *, const void *);
 
 /*
  * Functions to create and destroy datasets.
--- old/usr/src/lib/libzfs/common/libzfs_dataset.c	Mon Nov  6 02:54:37 2017
+++ new/usr/src/lib/libzfs/common/libzfs_dataset.c	Mon Nov  6 02:54:37 2017
@@ -54,6 +54,7 @@
 #include <idmap.h>
 #include <aclutils.h>
 #include <directory.h>
+#include <time.h>
 
 #include <sys/dnode.h>
 #include <sys/spa.h>
@@ -785,6 +786,7 @@
 void
 libzfs_mnttab_init(libzfs_handle_t *hdl)
 {
+	(void) mutex_init(&hdl->libzfs_mnttab_cache_lock, MUTEX_DEFAULT, NULL);
 	assert(avl_numnodes(&hdl->libzfs_mnttab_cache) == 0);
 	avl_create(&hdl->libzfs_mnttab_cache, libzfs_mnttab_cache_compare,
 	    sizeof (mnttab_node_t), offsetof(mnttab_node_t, mtn_node));
@@ -825,6 +827,7 @@
 		free(mtn);
 	}
 	avl_destroy(&hdl->libzfs_mnttab_cache);
+	(void) mutex_destroy(&hdl->libzfs_mnttab_cache_lock);
 }
 
 void
@@ -839,6 +842,7 @@
 {
 	mnttab_node_t find;
 	mnttab_node_t *mtn;
+	int ret = ENOENT;
 
 	if (!hdl->libzfs_mnttab_enable) {
 		struct mnttab srch = { 0 };
@@ -849,11 +853,11 @@
 		srch.mnt_special = (char *)fsname;
 		srch.mnt_fstype = MNTTYPE_ZFS;
 		if (getmntany(hdl->libzfs_mnttab, entry, &srch) == 0)
-			return (0);
-		else
-			return (ENOENT);
+			ret = 0;
+		return (ret);
 	}
 
+	(void) mutex_lock(&hdl->libzfs_mnttab_cache_lock);
 	if (avl_numnodes(&hdl->libzfs_mnttab_cache) == 0)
 		libzfs_mnttab_update(hdl);
 
@@ -861,9 +865,10 @@
 	mtn = avl_find(&hdl->libzfs_mnttab_cache, &find, NULL);
 	if (mtn) {
 		*entry = mtn->mtn_mt;
-		return (0);
+		ret = 0;
 	}
-	return (ENOENT);
+	(void) mutex_unlock(&hdl->libzfs_mnttab_cache_lock);
+	return (ret);
 }
 
 void
@@ -872,14 +877,16 @@
 {
 	mnttab_node_t *mtn;
 
-	if (avl_numnodes(&hdl->libzfs_mnttab_cache) == 0)
-		return;
-	mtn = zfs_alloc(hdl, sizeof (mnttab_node_t));
-	mtn->mtn_mt.mnt_special = zfs_strdup(hdl, special);
-	mtn->mtn_mt.mnt_mountp = zfs_strdup(hdl, mountp);
-	mtn->mtn_mt.mnt_fstype = zfs_strdup(hdl, MNTTYPE_ZFS);
-	mtn->mtn_mt.mnt_mntopts = zfs_strdup(hdl, mntopts);
-	avl_add(&hdl->libzfs_mnttab_cache, mtn);
+	(void) mutex_lock(&hdl->libzfs_mnttab_cache_lock);
+	if (avl_numnodes(&hdl->libzfs_mnttab_cache) != 0) {
+		mtn = zfs_alloc(hdl, sizeof (mnttab_node_t));
+		mtn->mtn_mt.mnt_special = zfs_strdup(hdl, special);
+		mtn->mtn_mt.mnt_mountp = zfs_strdup(hdl, mountp);
+		mtn->mtn_mt.mnt_fstype = zfs_strdup(hdl, MNTTYPE_ZFS);
+		mtn->mtn_mt.mnt_mntopts = zfs_strdup(hdl, mntopts);
+		avl_add(&hdl->libzfs_mnttab_cache, mtn);
+	}
+	(void) mutex_unlock(&hdl->libzfs_mnttab_cache_lock);
 }
 
 void
@@ -888,6 +895,7 @@
 	mnttab_node_t find;
 	mnttab_node_t *ret;
 
+	(void) mutex_lock(&hdl->libzfs_mnttab_cache_lock);
 	find.mtn_mt.mnt_special = (char *)fsname;
 	if ((ret = avl_find(&hdl->libzfs_mnttab_cache, (void *)&find, NULL))
 	    != NULL) {
@@ -898,6 +906,7 @@
 		free(ret->mtn_mt.mnt_mntopts);
 		free(ret);
 	}
+	(void) mutex_unlock(&hdl->libzfs_mnttab_cache_lock);
 }
 
 int
--- old/usr/src/lib/libzfs/common/libzfs_impl.h	Mon Nov  6 02:54:38 2017
+++ new/usr/src/lib/libzfs/common/libzfs_impl.h	Mon Nov  6 02:54:38 2017
@@ -22,7 +22,7 @@
 /*
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2011 Pawel Jakub Dawidek. All rights reserved.
- * Copyright (c) 2011, 2016 by Delphix. All rights reserved.
+ * Copyright (c) 2011, 2017 by Delphix. All rights reserved.
  */
 
 #ifndef	_LIBZFS_IMPL_H
@@ -33,6 +33,7 @@
 #include <sys/nvpair.h>
 #include <sys/dmu.h>
 #include <sys/zfs_ioctl.h>
+#include <synch.h>
 
 #include <libuutil.h>
 #include <libzfs.h>
@@ -73,6 +74,13 @@
 	int libzfs_storeerr; /* stuff error messages into buffer */
 	void *libzfs_sharehdl; /* libshare handle */
 	boolean_t libzfs_mnttab_enable;
+	/*
+	 * We need a lock to handle the case where parallel mount threads
+	 * are populating the mnttab cache simultaneously. The lock only
+	 * protects the integrity of of the avl tree, and does not protect
+	 * the contents of the mnttab entries themselves.
+	 */
+	mutex_t libzfs_mnttab_cache_lock;
 	avl_tree_t libzfs_mnttab_cache;
 	int libzfs_pool_iter;
 	topo_hdl_t *libzfs_topo_hdl;
--- old/usr/src/lib/libzfs/common/libzfs_mount.c	Mon Nov  6 02:54:38 2017
+++ new/usr/src/lib/libzfs/common/libzfs_mount.c	Mon Nov  6 02:54:38 2017
@@ -22,7 +22,7 @@
 /*
  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2014, 2016 by Delphix. All rights reserved.
+ * Copyright (c) 2014, 2017 by Delphix. All rights reserved.
  * Copyright 2016 Igor Kozhukhov <ikozhukhov@gmail.com>
  * Copyright 2017 Joyent, Inc.
  * Copyright 2017 RackTop Systems.
@@ -34,25 +34,25 @@
  * they are used by mount and unmount and when changing a filesystem's
  * mountpoint.
  *
- * 	zfs_is_mounted()
- * 	zfs_mount()
- * 	zfs_unmount()
- * 	zfs_unmountall()
+ *	zfs_is_mounted()
+ *	zfs_mount()
+ *	zfs_unmount()
+ *	zfs_unmountall()
  *
  * This file also contains the functions used to manage sharing filesystems via
  * NFS and iSCSI:
  *
- * 	zfs_is_shared()
- * 	zfs_share()
- * 	zfs_unshare()
+ *	zfs_is_shared()
+ *	zfs_share()
+ *	zfs_unshare()
  *
- * 	zfs_is_shared_nfs()
- * 	zfs_is_shared_smb()
- * 	zfs_share_proto()
- * 	zfs_shareall();
- * 	zfs_unshare_nfs()
- * 	zfs_unshare_smb()
- * 	zfs_unshareall_nfs()
+ *	zfs_is_shared_nfs()
+ *	zfs_is_shared_smb()
+ *	zfs_share_proto()
+ *	zfs_shareall();
+ *	zfs_unshare_nfs()
+ *	zfs_unshare_smb()
+ *	zfs_unshareall_nfs()
  *	zfs_unshareall_smb()
  *	zfs_unshareall()
  *	zfs_unshareall_bypath()
@@ -60,8 +60,8 @@
  * The following functions are available for pool consumers, and will
  * mount/unmount and share/unshare all datasets within pool:
  *
- * 	zpool_enable_datasets()
- * 	zpool_disable_datasets()
+ *	zpool_enable_datasets()
+ *	zpool_disable_datasets()
  */
 
 #include <dirent.h>
@@ -79,6 +79,7 @@
 #include <sys/mount.h>
 #include <sys/stat.h>
 #include <sys/statvfs.h>
+#include <sys/taskq.h>
 
 #include <libzfs.h>
 
@@ -88,6 +89,9 @@
 #include <sys/systeminfo.h>
 #define	MAXISALEN	257	/* based on sysinfo(2) man page */
 
+static int mount_tq_nthr = 512;	/* taskq threads for multi-threaded mounting */
+
+static void zfs_mount_task(void *);
 static int zfs_share_proto(zfs_handle_t *, zfs_share_proto_t *);
 zfs_share_type_t zfs_is_shared_proto(zfs_handle_t *, char **,
     zfs_share_proto_t);
@@ -1077,25 +1081,32 @@
 	}
 }
 
+/*
+ * Add the given zfs handle to the cb_handles array, dynamically reallocating
+ * the array if it is out of space.
+ */
 void
 libzfs_add_handle(get_all_cb_t *cbp, zfs_handle_t *zhp)
 {
 	if (cbp->cb_alloc == cbp->cb_used) {
 		size_t newsz;
-		void *ptr;
+		zfs_handle_t **newhandles;
 
-		newsz = cbp->cb_alloc ? cbp->cb_alloc * 2 : 64;
-		ptr = zfs_realloc(zhp->zfs_hdl,
-		    cbp->cb_handles, cbp->cb_alloc * sizeof (void *),
-		    newsz * sizeof (void *));
-		cbp->cb_handles = ptr;
+		newsz = cbp->cb_alloc != 0 ? cbp->cb_alloc * 2 : 64;
+		newhandles = zfs_realloc(zhp->zfs_hdl,
+		    cbp->cb_handles, cbp->cb_alloc * sizeof (zfs_handle_t *),
+		    newsz * sizeof (zfs_handle_t *));
+		cbp->cb_handles = newhandles;
 		cbp->cb_alloc = newsz;
 	}
 	cbp->cb_handles[cbp->cb_used++] = zhp;
 }
 
+/*
+ * Recursive helper function used during file system enumeration
+ */
 static int
-mount_cb(zfs_handle_t *zhp, void *data)
+zfs_iter_cb(zfs_handle_t *zhp, void *data)
 {
 	get_all_cb_t *cbp = data;
 
@@ -1121,7 +1132,7 @@
 	}
 
 	libzfs_add_handle(cbp, zhp);
-	if (zfs_iter_filesystems(zhp, mount_cb, cbp) != 0) {
+	if (zfs_iter_filesystems(zhp, zfs_iter_cb, cbp) != 0) {
 		zfs_close(zhp);
 		return (-1);
 	}
@@ -1128,24 +1139,62 @@
 	return (0);
 }
 
+/*
+ * Sort comparator that compares two mountpoint paths. We sort these paths so
+ * that subdirectories immediately follow their parents. This means that we
+ * effectively treat the '/' character as the lowest value non-nul char. An
+ * example sorted list using this comparator would look like:
+ *
+ * /foo
+ * /foo/bar
+ * /foo/bar/baz
+ * /foo/baz
+ * /foo.bar
+ *
+ * The mounting code depends on this ordering to deterministically iterate
+ * over filesystems in order to spawn parallel mount tasks.
+ */
 int
-libzfs_dataset_cmp(const void *a, const void *b)
+mountpoint_cmp(const void *arga, const void *argb)
 {
-	zfs_handle_t **za = (zfs_handle_t **)a;
-	zfs_handle_t **zb = (zfs_handle_t **)b;
+	zfs_handle_t *const *zap = arga;
+	zfs_handle_t *za = *zap;
+	zfs_handle_t *const *zbp = argb;
+	zfs_handle_t *zb = *zbp;
 	char mounta[MAXPATHLEN];
 	char mountb[MAXPATHLEN];
+	const char *a = mounta;
+	const char *b = mountb;
 	boolean_t gota, gotb;
 
-	if ((gota = (zfs_get_type(*za) == ZFS_TYPE_FILESYSTEM)) != 0)
-		verify(zfs_prop_get(*za, ZFS_PROP_MOUNTPOINT, mounta,
+	gota = (zfs_get_type(za) == ZFS_TYPE_FILESYSTEM);
+	if (gota) {
+		verify(zfs_prop_get(za, ZFS_PROP_MOUNTPOINT, mounta,
 		    sizeof (mounta), NULL, NULL, 0, B_FALSE) == 0);
-	if ((gotb = (zfs_get_type(*zb) == ZFS_TYPE_FILESYSTEM)) != 0)
-		verify(zfs_prop_get(*zb, ZFS_PROP_MOUNTPOINT, mountb,
+	}
+	gotb = (zfs_get_type(zb) == ZFS_TYPE_FILESYSTEM);
+	if (gotb) {
+		verify(zfs_prop_get(zb, ZFS_PROP_MOUNTPOINT, mountb,
 		    sizeof (mountb), NULL, NULL, 0, B_FALSE) == 0);
+	}
 
-	if (gota && gotb)
-		return (strcmp(mounta, mountb));
+	if (gota && gotb) {
+		while (*a != '\0' && (*a == *b)) {
+			a++;
+			b++;
+		}
+		if (*a == *b)
+			return (0);
+		if (*a == '\0')
+			return (-1);
+		if (*b == '\0')
+			return (1);
+		if (*a == '/')
+			return (-1);
+		if (*b == '/')
+			return (1);
+		return (*a < *b ? -1 : *a > *b);
+	}
 
 	if (gota)
 		return (-1);
@@ -1152,16 +1201,229 @@
 	if (gotb)
 		return (1);
 
-	return (strcmp(zfs_get_name(a), zfs_get_name(b)));
+	/*
+	 * If neither filesystem has a mountpoint, revert to sorting by
+	 * dataset name.
+	 */
+	return (strcmp(zfs_get_name(za), zfs_get_name(zb)));
 }
 
 /*
+ * Return true if path2 is a child of path1.
+ */
+static boolean_t
+libzfs_path_contains(const char *path1, const char *path2)
+{
+	return (strstr(path2, path1) == path2 && path2[strlen(path1)] == '/');
+}
+
+/*
+ * Given a mountpoint specified by idx in the handles array, find the first
+ * non-descendent of that mountpoint and return its index. Descendant paths
+ * start with the parent's path. This function relies on the ordering
+ * enforced by mountpoint_cmp().
+ */
+static int
+non_descendant_idx(zfs_handle_t **handles, size_t num_handles, int idx)
+{
+	char parent[ZFS_MAXPROPLEN];
+	char child[ZFS_MAXPROPLEN];
+	int i;
+
+	verify(zfs_prop_get(handles[idx], ZFS_PROP_MOUNTPOINT, parent,
+	    sizeof (parent), NULL, NULL, 0, B_FALSE) == 0);
+
+	for (i = idx + 1; i < num_handles; i++) {
+		verify(zfs_prop_get(handles[i], ZFS_PROP_MOUNTPOINT, child,
+		    sizeof (child), NULL, NULL, 0, B_FALSE) == 0);
+		if (!libzfs_path_contains(parent, child))
+			break;
+	}
+	return (i);
+}
+
+typedef struct mnt_param {
+	libzfs_handle_t	*mnt_hdl;
+	taskq_t		*mnt_tq;
+	zfs_handle_t	**mnt_zhps; /* filesystems to mount */
+	size_t		mnt_num_handles;
+	int		mnt_idx;	/* Index of selected entry to mount */
+	zfs_iter_f	mnt_func;
+	void		*mnt_data;
+} mnt_param_t;
+
+/*
+ * Allocate and populate the parameter struct for mount function, and
+ * schedule mounting of the entry selected by idx.
+ */
+static void
+zfs_dispatch_mount(libzfs_handle_t *hdl, zfs_handle_t **handles,
+    size_t num_handles, int idx, zfs_iter_f func, void *data, taskq_t *tq)
+{
+	mnt_param_t *mnt_param = zfs_alloc(hdl, sizeof (mnt_param_t));
+
+	mnt_param->mnt_hdl = hdl;
+	mnt_param->mnt_tq = tq;
+	mnt_param->mnt_zhps = handles;
+	mnt_param->mnt_num_handles = num_handles;
+	mnt_param->mnt_idx = idx;
+	mnt_param->mnt_func = func;
+	mnt_param->mnt_data = data;
+
+	(void) taskq_dispatch(tq, zfs_mount_task, (void*)mnt_param, TQ_SLEEP);
+}
+
+/*
+ * This is the structure used to keep state of mounting or sharing operations
+ * during a call to zpool_enable_datasets().
+ */
+typedef struct mount_state {
+	/*
+	 * ms_mntstatus is set to -1 if any mount fails. While multiple threads
+	 * could update this variable concurrently, no synchronization is
+	 * needed as it's only ever set to -1.
+	 */
+	int		ms_mntstatus;
+	int		ms_mntflags;
+	const char	*ms_mntopts;
+} mount_state_t;
+
+static int
+zfs_mount_one(zfs_handle_t *zhp, void *arg)
+{
+	mount_state_t *ms = arg;
+	int ret = 0;
+
+	if (zfs_mount(zhp, ms->ms_mntopts, ms->ms_mntflags) != 0)
+		ret = ms->ms_mntstatus = -1;
+	return (ret);
+}
+
+static int
+zfs_share_one(zfs_handle_t *zhp, void *arg)
+{
+	mount_state_t *ms = arg;
+	int ret = 0;
+
+	if (zfs_share(zhp) != 0)
+		ret = ms->ms_mntstatus = -1;
+	return (ret);
+}
+
+/*
+ * Task queue function to mount one file system. On completion, it finds and
+ * schedules its children to be mounted. This depends on the sorting done in
+ * zfs_foreach_mountpoint(). Note that the degenerate case (chain of entries
+ * each descending from the previous) will have no parallelism since we always
+ * have to wait for the parent to finish mounting before we can schedule
+ * its children.
+ */
+static void
+zfs_mount_task(void *arg)
+{
+	mnt_param_t *mp = arg;
+	int idx = mp->mnt_idx;
+	zfs_handle_t **handles = mp->mnt_zhps;
+	size_t num_handles = mp->mnt_num_handles;
+	char mountpoint[ZFS_MAXPROPLEN];
+
+	verify(zfs_prop_get(handles[idx], ZFS_PROP_MOUNTPOINT, mountpoint,
+	    sizeof (mountpoint), NULL, NULL, 0, B_FALSE) == 0);
+
+	if (mp->mnt_func(handles[idx], mp->mnt_data) != 0)
+		return;
+
+	/*
+	 * We dispatch tasks to mount filesystems with mountpoints underneath
+	 * this one. We do this by dispatching the next filesystem with a
+	 * descendant mountpoint of the one we just mounted, then skip all of
+	 * its descendants, dispatch the next descendant mountpoint, and so on.
+	 * The non_descendant_idx() function skips over filesystems that are
+	 * descendants of the filesystem we just dispatched.
+	 */
+	for (int i = idx + 1; i < num_handles;
+	    i = non_descendant_idx(handles, num_handles, i)) {
+		char child[ZFS_MAXPROPLEN];
+		verify(zfs_prop_get(handles[i], ZFS_PROP_MOUNTPOINT,
+		    child, sizeof (child), NULL, NULL, 0, B_FALSE) == 0);
+
+		if (!libzfs_path_contains(mountpoint, child))
+			break; /* not a descendant, return */
+		zfs_dispatch_mount(mp->mnt_hdl, handles, num_handles, i,
+		    mp->mnt_func, mp->mnt_data, mp->mnt_tq);
+	}
+	free(mp);
+}
+
+/*
+ * Issue the func callback for each ZFS handle contained in the handles
+ * array. This function is used to mount all datasets, and so this function
+ * guarantees that filesystems for parent mountpoints are called before their
+ * children. As such, before issuing any callbacks, we first sort the array
+ * of handles by mountpoint.
+ *
+ * Callbacks are issued in one of two ways:
+ *
+ * 1. Sequentially: If the parallel argument is B_FALSE or the ZFS_SERIAL_MOUNT
+ *    environment variable is set, then we issue callbacks sequentially.
+ *
+ * 2. In parallel: If the parallel argument is B_TRUE and the ZFS_SERIAL_MOUNT
+ *    environment variable is not set, then we use a taskq to dispatch threads
+ *    to mount filesystems is parallel. This function dispatches tasks to mount
+ *    the filesystems at the top-level mountpoints, and these tasks in turn
+ *    are responsible for recursively mounting filesystems in their children
+ *    mountpoints.
+ */
+void
+zfs_foreach_mountpoint(libzfs_handle_t *hdl, zfs_handle_t **handles,
+    size_t num_handles, zfs_iter_f func, void *data, boolean_t parallel)
+{
+	/*
+	 * The ZFS_SERIAL_MOUNT environment variable is an undocumented
+	 * variable that can be used as a convenience to do a/b comparison
+	 * of serial vs. parallel mounting.
+	 */
+	boolean_t serial_mount = !parallel ||
+	    (getenv("ZFS_SERIAL_MOUNT") != NULL);
+
+	/*
+	 * Sort the datasets by mountpoint. See mountpoint_cmp for details
+	 * of how these are sorted.
+	 */
+	qsort(handles, num_handles, sizeof (zfs_handle_t *), mountpoint_cmp);
+
+	if (serial_mount) {
+		for (int i = 0; i < num_handles; i++) {
+			func(handles[i], data);
+		}
+		return;
+	}
+
+	/*
+	 * Issue the callback function for each dataset using a parallel
+	 * algorithm that uses a taskq to manage threads.
+	 */
+	taskq_t *tq = taskq_create("mount_taskq", mount_tq_nthr, 0,
+	    mount_tq_nthr, mount_tq_nthr, TASKQ_DYNAMIC | TASKQ_PREPOPULATE);
+
+	/*
+	 * There may be multiple "top level" mountpoints outside of the pool's
+	 * root mountpoint, e.g.: /foo /bar. Dispatch a mount task for each of
+	 * these.
+	 */
+	for (int i = 0; i < num_handles;
+	    i = non_descendant_idx(handles, num_handles, i)) {
+		zfs_dispatch_mount(hdl, handles, num_handles, i, func, data,
+		    tq);
+	}
+
+	taskq_wait(tq); /* wait for all scheduled mounts to complete */
+	taskq_destroy(tq);
+}
+
+/*
  * Mount and share all datasets within the given pool.  This assumes that no
- * datasets within the pool are currently mounted.  Because users can create
- * complicated nested hierarchies of mountpoints, we first gather all the
- * datasets and mountpoints within the pool, and sort them by mountpoint.  Once
- * we have the list of all filesystems, we iterate over them in order and mount
- * and/or share each one.
+ * datasets within the pool are currently mounted.
  */
 #pragma weak zpool_mount_datasets = zpool_enable_datasets
 int
@@ -1168,57 +1430,51 @@
 zpool_enable_datasets(zpool_handle_t *zhp, const char *mntopts, int flags)
 {
 	get_all_cb_t cb = { 0 };
-	libzfs_handle_t *hdl = zhp->zpool_hdl;
+	mount_state_t ms = { 0 };
 	zfs_handle_t *zfsp;
-	int i, ret = -1;
-	int *good;
+	sa_init_selective_arg_t sharearg;
+	int ret = 0;
 
-	/*
-	 * Gather all non-snap datasets within the pool.
-	 */
-	if ((zfsp = zfs_open(hdl, zhp->zpool_name, ZFS_TYPE_DATASET)) == NULL)
+	if ((zfsp = zfs_open(zhp->zpool_hdl, zhp->zpool_name,
+	    ZFS_TYPE_DATASET)) == NULL)
 		goto out;
 
-	libzfs_add_handle(&cb, zfsp);
-	if (zfs_iter_filesystems(zfsp, mount_cb, &cb) != 0)
-		goto out;
-	/*
-	 * Sort the datasets by mountpoint.
-	 */
-	qsort(cb.cb_handles, cb.cb_used, sizeof (void *),
-	    libzfs_dataset_cmp);
 
 	/*
-	 * And mount all the datasets, keeping track of which ones
-	 * succeeded or failed.
+	 * Gather all non-snapshot datasets within the pool. Start by adding
+	 * the root filesystem for this pool to the list, and then iterate
+	 * over all child filesystems.
 	 */
-	if ((good = zfs_alloc(zhp->zpool_hdl,
-	    cb.cb_used * sizeof (int))) == NULL)
+	libzfs_add_handle(&cb, zfsp);
+	if (zfs_iter_filesystems(zfsp, zfs_iter_cb, &cb) != 0)
 		goto out;
 
-	ret = 0;
-	for (i = 0; i < cb.cb_used; i++) {
-		if (zfs_mount(cb.cb_handles[i], mntopts, flags) != 0)
-			ret = -1;
-		else
-			good[i] = 1;
-	}
+	ms.ms_mntopts = mntopts;
+	ms.ms_mntflags = flags;
+	zfs_foreach_mountpoint(zhp->zpool_hdl, cb.cb_handles, cb.cb_used,
+	    zfs_mount_one, &ms, B_TRUE);
+	if (ms.ms_mntstatus != 0)
+		ret = ms.ms_mntstatus;
 
 	/*
-	 * Then share all the ones that need to be shared. This needs
-	 * to be a separate pass in order to avoid excessive reloading
-	 * of the configuration. Good should never be NULL since
-	 * zfs_alloc is supposed to exit if memory isn't available.
+	 * Share all filesystems that need to be shared. This needs to be
+	 * a separate pass because libshare is not mt-safe, and so we need
+	 * to share serially.
 	 */
-	for (i = 0; i < cb.cb_used; i++) {
-		if (good[i] && zfs_share(cb.cb_handles[i]) != 0)
-			ret = -1;
-	}
+	sharearg.zhandle_arr = cb.cb_handles;
+	sharearg.zhandle_len = cb.cb_used;
+	if ((ret = zfs_init_libshare_arg(zhp->zpool_hdl,
+	    SA_INIT_SHARE_API_SELECTIVE, &sharearg)) != 0)
+		goto out;
 
-	free(good);
+	ms.ms_mntstatus = 0;
+	zfs_foreach_mountpoint(zhp->zpool_hdl, cb.cb_handles, cb.cb_used,
+	    zfs_share_one, &ms, B_FALSE);
+	if (ms.ms_mntstatus != 0)
+		ret = ms.ms_mntstatus;
 
 out:
-	for (i = 0; i < cb.cb_used; i++)
+	for (int i = 0; i < cb.cb_used; i++)
 		zfs_close(cb.cb_handles[i]);
 	free(cb.cb_handles);
 
--- old/usr/src/lib/libzfs/common/mapfile-vers	Mon Nov  6 02:54:38 2017
+++ new/usr/src/lib/libzfs/common/mapfile-vers	Mon Nov  6 02:54:38 2017
@@ -21,7 +21,7 @@
 
 #
 # Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
-# Copyright (c) 2011, 2014 by Delphix. All rights reserved.
+# Copyright (c) 2011, 2017 by Delphix. All rights reserved.
 # Copyright 2016 Nexenta Systems, Inc.
 #
 
@@ -50,7 +50,6 @@
 	fletcher_4_incremental_native;
 	fletcher_4_incremental_byteswap;
 	libzfs_add_handle;
-	libzfs_dataset_cmp;
 	libzfs_errno;
 	libzfs_error_action;
 	libzfs_error_description;
@@ -77,6 +76,7 @@
 	zfs_destroy_snaps;
 	zfs_destroy_snaps_nvl;
 	zfs_expand_proplist;
+	zfs_foreach_mountpoint;
 	zfs_get_handle;
 	zfs_get_holds;
 	zfs_get_hole_count;
--- old/usr/src/lib/libzpool/Makefile.com	Mon Nov  6 02:54:38 2017
+++ new/usr/src/lib/libzpool/Makefile.com	Mon Nov  6 02:54:38 2017
@@ -29,7 +29,7 @@
 
 # include the list of ZFS sources
 include ../../../uts/common/Makefile.files
-KERNEL_OBJS = kernel.o taskq.o util.o
+KERNEL_OBJS = kernel.o util.o
 DTRACE_OBJS = zfs.o
 
 OBJECTS=$(LUA_OBJS) $(ZFS_COMMON_OBJS) $(ZFS_SHARED_OBJS) $(KERNEL_OBJS)
@@ -67,9 +67,14 @@
 
 CFLAGS +=	-g $(CCVERBOSE) $(CNOGLOBAL)
 CFLAGS64 +=	-g $(CCVERBOSE)	$(CNOGLOBAL)
-LDLIBS +=	-lcmdutils -lumem -lavl -lnvpair -lz -lc -lsysevent -lmd
-CPPFLAGS +=	$(INCS)	-DDEBUG
+LDLIBS +=	-lcmdutils -lumem -lavl -lnvpair -lz -lc -lsysevent -lmd \
+		-lfakekernel
+CPPFLAGS.first =	-I$(SRC)/lib/libfakekernel/common
+CPPFLAGS +=	$(INCS)	-DDEBUG -D_FAKE_KERNEL
 
+LINTFLAGS +=	-erroff=E_STATIC_UNUSED $(INCS)
+LINTFLAGS64 +=	-erroff=E_STATIC_UNUSED $(INCS)
+
 CERRWARN +=	-_gcc=-Wno-parentheses
 CERRWARN +=	-_gcc=-Wno-switch
 CERRWARN +=	-_gcc=-Wno-type-limits
--- old/usr/src/lib/libzpool/common/kernel.c	Mon Nov  6 02:54:38 2017
+++ new/usr/src/lib/libzpool/common/kernel.c	Mon Nov  6 02:54:38 2017
@@ -22,6 +22,7 @@
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2012, 2015 by Delphix. All rights reserved.
  * Copyright (c) 2013, Joyent, Inc.  All rights reserved.
+ * Copyright 2017 RackTop Systems.
  */
 
 #include <assert.h>
@@ -41,12 +42,14 @@
 #include <sys/utsname.h>
 #include <sys/systeminfo.h>
 
+extern void system_taskq_init(void);
+extern void system_taskq_fini(void);
+
 /*
  * Emulation of kernel services in userland.
  */
 
-int aok;
-uint64_t physmem;
+pgcnt_t physmem;
 vnode_t *rootdir = (vnode_t *)0xabcd1234;
 char hw_serial[HW_HOSTID_LEN];
 kmutex_t cpu_lock;
@@ -59,339 +62,8 @@
 	"userland", "libzpool", "1", "1", "na"
 };
 
-/* this only exists to have its address taken */
-struct proc p0;
-
 /*
  * =========================================================================
- * threads
- * =========================================================================
- */
-/*ARGSUSED*/
-kthread_t *
-zk_thread_create(void (*func)(), void *arg, uint64_t len)
-{
-	thread_t tid;
-
-	ASSERT0(len);
-	VERIFY(thr_create(0, 0, (void *(*)(void *))func, arg, THR_DETACHED,
-	    &tid) == 0);
-
-	return ((void *)(uintptr_t)tid);
-}
-
-/*
- * =========================================================================
- * kstats
- * =========================================================================
- */
-/*ARGSUSED*/
-kstat_t *
-kstat_create(const char *module, int instance, const char *name,
-    const char *class, uchar_t type, ulong_t ndata, uchar_t ks_flag)
-{
-	return (NULL);
-}
-
-/*ARGSUSED*/
-void
-kstat_named_init(kstat_named_t *knp, const char *name, uchar_t type)
-{}
-
-/*ARGSUSED*/
-void
-kstat_install(kstat_t *ksp)
-{}
-
-/*ARGSUSED*/
-void
-kstat_delete(kstat_t *ksp)
-{}
-
-/*ARGSUSED*/
-void
-kstat_waitq_enter(kstat_io_t *kiop)
-{}
-
-/*ARGSUSED*/
-void
-kstat_waitq_exit(kstat_io_t *kiop)
-{}
-
-/*ARGSUSED*/
-void
-kstat_runq_enter(kstat_io_t *kiop)
-{}
-
-/*ARGSUSED*/
-void
-kstat_runq_exit(kstat_io_t *kiop)
-{}
-
-/*ARGSUSED*/
-void
-kstat_waitq_to_runq(kstat_io_t *kiop)
-{}
-
-/*ARGSUSED*/
-void
-kstat_runq_back_to_waitq(kstat_io_t *kiop)
-{}
-
-/*
- * =========================================================================
- * mutexes
- * =========================================================================
- */
-void
-zmutex_init(kmutex_t *mp)
-{
-	mp->m_owner = NULL;
-	mp->initialized = B_TRUE;
-	(void) _mutex_init(&mp->m_lock, USYNC_THREAD, NULL);
-}
-
-void
-zmutex_destroy(kmutex_t *mp)
-{
-	ASSERT(mp->initialized == B_TRUE);
-	ASSERT(mp->m_owner == NULL);
-	(void) _mutex_destroy(&(mp)->m_lock);
-	mp->m_owner = (void *)-1UL;
-	mp->initialized = B_FALSE;
-}
-
-void
-zmutex_enter(kmutex_t *mp)
-{
-	ASSERT(mp->initialized == B_TRUE);
-	ASSERT(mp->m_owner != (void *)-1UL);
-	ASSERT(mp->m_owner != curthread);
-	VERIFY(mutex_lock(&mp->m_lock) == 0);
-	ASSERT(mp->m_owner == NULL);
-	mp->m_owner = curthread;
-}
-
-int
-mutex_tryenter(kmutex_t *mp)
-{
-	ASSERT(mp->initialized == B_TRUE);
-	ASSERT(mp->m_owner != (void *)-1UL);
-	if (0 == mutex_trylock(&mp->m_lock)) {
-		ASSERT(mp->m_owner == NULL);
-		mp->m_owner = curthread;
-		return (1);
-	} else {
-		return (0);
-	}
-}
-
-void
-zmutex_exit(kmutex_t *mp)
-{
-	ASSERT(mp->initialized == B_TRUE);
-	ASSERT(mutex_owner(mp) == curthread);
-	mp->m_owner = NULL;
-	VERIFY(mutex_unlock(&mp->m_lock) == 0);
-}
-
-void *
-mutex_owner(kmutex_t *mp)
-{
-	ASSERT(mp->initialized == B_TRUE);
-	return (mp->m_owner);
-}
-
-/*
- * =========================================================================
- * rwlocks
- * =========================================================================
- */
-/*ARGSUSED*/
-void
-rw_init(krwlock_t *rwlp, char *name, int type, void *arg)
-{
-	rwlock_init(&rwlp->rw_lock, USYNC_THREAD, NULL);
-	rwlp->rw_owner = NULL;
-	rwlp->initialized = B_TRUE;
-}
-
-void
-rw_destroy(krwlock_t *rwlp)
-{
-	rwlock_destroy(&rwlp->rw_lock);
-	rwlp->rw_owner = (void *)-1UL;
-	rwlp->initialized = B_FALSE;
-}
-
-void
-rw_enter(krwlock_t *rwlp, krw_t rw)
-{
-	ASSERT(!RW_LOCK_HELD(rwlp));
-	ASSERT(rwlp->initialized == B_TRUE);
-	ASSERT(rwlp->rw_owner != (void *)-1UL);
-	ASSERT(rwlp->rw_owner != curthread);
-
-	if (rw == RW_WRITER)
-		VERIFY(rw_wrlock(&rwlp->rw_lock) == 0);
-	else
-		VERIFY(rw_rdlock(&rwlp->rw_lock) == 0);
-
-	rwlp->rw_owner = curthread;
-}
-
-void
-rw_exit(krwlock_t *rwlp)
-{
-	ASSERT(rwlp->initialized == B_TRUE);
-	ASSERT(rwlp->rw_owner != (void *)-1UL);
-
-	rwlp->rw_owner = NULL;
-	VERIFY(rw_unlock(&rwlp->rw_lock) == 0);
-}
-
-int
-rw_tryenter(krwlock_t *rwlp, krw_t rw)
-{
-	int rv;
-
-	ASSERT(rwlp->initialized == B_TRUE);
-	ASSERT(rwlp->rw_owner != (void *)-1UL);
-
-	if (rw == RW_WRITER)
-		rv = rw_trywrlock(&rwlp->rw_lock);
-	else
-		rv = rw_tryrdlock(&rwlp->rw_lock);
-
-	if (rv == 0) {
-		rwlp->rw_owner = curthread;
-		return (1);
-	}
-
-	return (0);
-}
-
-/*ARGSUSED*/
-int
-rw_tryupgrade(krwlock_t *rwlp)
-{
-	ASSERT(rwlp->initialized == B_TRUE);
-	ASSERT(rwlp->rw_owner != (void *)-1UL);
-
-	return (0);
-}
-
-/*
- * =========================================================================
- * condition variables
- * =========================================================================
- */
-/*ARGSUSED*/
-void
-cv_init(kcondvar_t *cv, char *name, int type, void *arg)
-{
-	VERIFY(cond_init(cv, type, NULL) == 0);
-}
-
-void
-cv_destroy(kcondvar_t *cv)
-{
-	VERIFY(cond_destroy(cv) == 0);
-}
-
-void
-cv_wait(kcondvar_t *cv, kmutex_t *mp)
-{
-	ASSERT(mutex_owner(mp) == curthread);
-	mp->m_owner = NULL;
-	int ret = cond_wait(cv, &mp->m_lock);
-	VERIFY(ret == 0 || ret == EINTR);
-	mp->m_owner = curthread;
-}
-
-clock_t
-cv_timedwait(kcondvar_t *cv, kmutex_t *mp, clock_t abstime)
-{
-	int error;
-	timestruc_t ts;
-	clock_t delta;
-
-top:
-	delta = abstime - ddi_get_lbolt();
-	if (delta <= 0)
-		return (-1);
-
-	ts.tv_sec = delta / hz;
-	ts.tv_nsec = (delta % hz) * (NANOSEC / hz);
-
-	ASSERT(mutex_owner(mp) == curthread);
-	mp->m_owner = NULL;
-	error = cond_reltimedwait(cv, &mp->m_lock, &ts);
-	mp->m_owner = curthread;
-
-	if (error == ETIME)
-		return (-1);
-
-	if (error == EINTR)
-		goto top;
-
-	ASSERT(error == 0);
-
-	return (1);
-}
-
-/*ARGSUSED*/
-clock_t
-cv_timedwait_hires(kcondvar_t *cv, kmutex_t *mp, hrtime_t tim, hrtime_t res,
-    int flag)
-{
-	int error;
-	timestruc_t ts;
-	hrtime_t delta;
-
-	ASSERT(flag == 0 || flag == CALLOUT_FLAG_ABSOLUTE);
-
-top:
-	delta = tim;
-	if (flag & CALLOUT_FLAG_ABSOLUTE)
-		delta -= gethrtime();
-
-	if (delta <= 0)
-		return (-1);
-
-	ts.tv_sec = delta / NANOSEC;
-	ts.tv_nsec = delta % NANOSEC;
-
-	ASSERT(mutex_owner(mp) == curthread);
-	mp->m_owner = NULL;
-	error = cond_reltimedwait(cv, &mp->m_lock, &ts);
-	mp->m_owner = curthread;
-
-	if (error == ETIME)
-		return (-1);
-
-	if (error == EINTR)
-		goto top;
-
-	ASSERT(error == 0);
-
-	return (1);
-}
-
-void
-cv_signal(kcondvar_t *cv)
-{
-	VERIFY(cond_signal(cv) == 0);
-}
-
-void
-cv_broadcast(kcondvar_t *cv)
-{
-	VERIFY(cond_broadcast(cv) == 0);
-}
-
-/*
- * =========================================================================
  * vnode operations
  * =========================================================================
  */
@@ -691,56 +363,6 @@
 
 /*
  * =========================================================================
- * cmn_err() and panic()
- * =========================================================================
- */
-static char ce_prefix[CE_IGNORE][10] = { "", "NOTICE: ", "WARNING: ", "" };
-static char ce_suffix[CE_IGNORE][2] = { "", "\n", "\n", "" };
-
-void
-vpanic(const char *fmt, va_list adx)
-{
-	char buf[512];
-	(void) vsnprintf(buf, 512, fmt, adx);
-	assfail(buf, NULL, 0);
-	abort(); /* necessary to make vpanic meet noreturn requirements */
-}
-
-void
-panic(const char *fmt, ...)
-{
-	va_list adx;
-
-	va_start(adx, fmt);
-	vpanic(fmt, adx);
-	va_end(adx);
-}
-
-void
-vcmn_err(int ce, const char *fmt, va_list adx)
-{
-	if (ce == CE_PANIC)
-		vpanic(fmt, adx);
-	if (ce != CE_NOTE) {	/* suppress noise in userland stress testing */
-		(void) fprintf(stderr, "%s", ce_prefix[ce]);
-		(void) vfprintf(stderr, fmt, adx);
-		(void) fprintf(stderr, "%s", ce_suffix[ce]);
-	}
-}
-
-/*PRINTFLIKE2*/
-void
-cmn_err(int ce, const char *fmt, ...)
-{
-	va_list adx;
-
-	va_start(adx, fmt);
-	vcmn_err(ce, fmt, adx);
-	va_end(adx);
-}
-
-/*
- * =========================================================================
  * kobj interfaces
  * =========================================================================
  */
@@ -794,124 +416,6 @@
 
 /*
  * =========================================================================
- * misc routines
- * =========================================================================
- */
-
-void
-delay(clock_t ticks)
-{
-	poll(0, 0, ticks * (1000 / hz));
-}
-
-/*
- * Find highest one bit set.
- *	Returns bit number + 1 of highest bit that is set, otherwise returns 0.
- */
-int
-highbit64(uint64_t i)
-{
-	int h = 1;
-
-	if (i == 0)
-		return (0);
-	if (i & 0xffffffff00000000ULL) {
-		h += 32; i >>= 32;
-	}
-	if (i & 0xffff0000) {
-		h += 16; i >>= 16;
-	}
-	if (i & 0xff00) {
-		h += 8; i >>= 8;
-	}
-	if (i & 0xf0) {
-		h += 4; i >>= 4;
-	}
-	if (i & 0xc) {
-		h += 2; i >>= 2;
-	}
-	if (i & 0x2) {
-		h += 1;
-	}
-	return (h);
-}
-
-static int random_fd = -1, urandom_fd = -1;
-
-static int
-random_get_bytes_common(uint8_t *ptr, size_t len, int fd)
-{
-	size_t resid = len;
-	ssize_t bytes;
-
-	ASSERT(fd != -1);
-
-	while (resid != 0) {
-		bytes = read(fd, ptr, resid);
-		ASSERT3S(bytes, >=, 0);
-		ptr += bytes;
-		resid -= bytes;
-	}
-
-	return (0);
-}
-
-int
-random_get_bytes(uint8_t *ptr, size_t len)
-{
-	return (random_get_bytes_common(ptr, len, random_fd));
-}
-
-int
-random_get_pseudo_bytes(uint8_t *ptr, size_t len)
-{
-	return (random_get_bytes_common(ptr, len, urandom_fd));
-}
-
-int
-ddi_strtoul(const char *hw_serial, char **nptr, int base, unsigned long *result)
-{
-	char *end;
-
-	*result = strtoul(hw_serial, &end, base);
-	if (*result == 0)
-		return (errno);
-	return (0);
-}
-
-int
-ddi_strtoull(const char *str, char **nptr, int base, u_longlong_t *result)
-{
-	char *end;
-
-	*result = strtoull(str, &end, base);
-	if (*result == 0)
-		return (errno);
-	return (0);
-}
-
-/* ARGSUSED */
-cyclic_id_t
-cyclic_add(cyc_handler_t *hdlr, cyc_time_t *when)
-{
-	return (1);
-}
-
-/* ARGSUSED */
-void
-cyclic_remove(cyclic_id_t id)
-{
-}
-
-/* ARGSUSED */
-int
-cyclic_reprogram(cyclic_id_t id, hrtime_t expiration)
-{
-	return (1);
-}
-
-/*
- * =========================================================================
  * kernel emulation setup & teardown
  * =========================================================================
  */
@@ -940,9 +444,6 @@
 	(void) snprintf(hw_serial, sizeof (hw_serial), "%ld",
 	    (mode & FWRITE) ? gethostid() : 0);
 
-	VERIFY((random_fd = open("/dev/random", O_RDONLY)) != -1);
-	VERIFY((urandom_fd = open("/dev/urandom", O_RDONLY)) != -1);
-
 	system_taskq_init();
 
 	mutex_init(&cpu_lock, NULL, MUTEX_DEFAULT, NULL);
@@ -958,12 +459,6 @@
 	spa_fini();
 
 	system_taskq_fini();
-
-	close(random_fd);
-	close(urandom_fd);
-
-	random_fd = -1;
-	urandom_fd = -1;
 }
 
 int
@@ -991,37 +486,7 @@
 	return (ret);
 }
 
-uid_t
-crgetuid(cred_t *cr)
-{
-	return (0);
-}
-
-uid_t
-crgetruid(cred_t *cr)
-{
-	return (0);
-}
-
-gid_t
-crgetgid(cred_t *cr)
-{
-	return (0);
-}
-
 int
-crgetngroups(cred_t *cr)
-{
-	return (0);
-}
-
-gid_t *
-crgetgroups(cred_t *cr)
-{
-	return (NULL);
-}
-
-int
 zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr)
 {
 	return (0);
@@ -1039,47 +504,6 @@
 	return (0);
 }
 
-ksiddomain_t *
-ksid_lookupdomain(const char *dom)
-{
-	ksiddomain_t *kd;
-
-	kd = umem_zalloc(sizeof (ksiddomain_t), UMEM_NOFAIL);
-	kd->kd_name = spa_strdup(dom);
-	return (kd);
-}
-
-void
-ksiddomain_rele(ksiddomain_t *ksid)
-{
-	spa_strfree(ksid->kd_name);
-	umem_free(ksid, sizeof (ksiddomain_t));
-}
-
-/*
- * Do not change the length of the returned string; it must be freed
- * with strfree().
- */
-char *
-kmem_asprintf(const char *fmt, ...)
-{
-	int size;
-	va_list adx;
-	char *buf;
-
-	va_start(adx, fmt);
-	size = vsnprintf(NULL, 0, fmt, adx) + 1;
-	va_end(adx);
-
-	buf = kmem_alloc(size, KM_SLEEP);
-
-	va_start(adx, fmt);
-	size = vsnprintf(buf, size, fmt, adx);
-	va_end(adx);
-
-	return (buf);
-}
-
 /* ARGSUSED */
 int
 zfs_onexit_fd_hold(int fd, minor_t *minorp)
@@ -1114,49 +538,4 @@
 zfs_onexit_cb_data(minor_t minor, uint64_t action_handle, void **data)
 {
 	return (0);
-}
-
-void
-bioinit(buf_t *bp)
-{
-	bzero(bp, sizeof (buf_t));
-}
-
-void
-biodone(buf_t *bp)
-{
-	if (bp->b_iodone != NULL) {
-		(*(bp->b_iodone))(bp);
-		return;
-	}
-	ASSERT((bp->b_flags & B_DONE) == 0);
-	bp->b_flags |= B_DONE;
-}
-
-void
-bioerror(buf_t *bp, int error)
-{
-	ASSERT(bp != NULL);
-	ASSERT(error >= 0);
-
-	if (error != 0) {
-		bp->b_flags |= B_ERROR;
-	} else {
-		bp->b_flags &= ~B_ERROR;
-	}
-	bp->b_error = error;
-}
-
-
-int
-geterror(struct buf *bp)
-{
-	int error = 0;
-
-	if (bp->b_flags & B_ERROR) {
-		error = bp->b_error;
-		if (!error)
-			error = EIO;
-	}
-	return (error);
 }
--- old/usr/src/lib/libzpool/common/sys/zfs_context.h	Mon Nov  6 02:54:39 2017
+++ new/usr/src/lib/libzpool/common/sys/zfs_context.h	Mon Nov  6 02:54:39 2017
@@ -23,6 +23,7 @@
  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  * Copyright (c) 2012, 2016 by Delphix. All rights reserved.
  * Copyright (c) 2012, Joyent, Inc. All rights reserved.
+ * Copyright 2017 RackTop Systems.
  */
 
 #ifndef _SYS_ZFS_CONTEXT_H
@@ -32,14 +33,10 @@
 extern "C" {
 #endif
 
-#define	_SYS_MUTEX_H
-#define	_SYS_RWLOCK_H
-#define	_SYS_CONDVAR_H
-#define	_SYS_SYSTM_H
-#define	_SYS_T_LOCK_H
+#define	_SYNCH_H
+
 #define	_SYS_VNODE_H
 #define	_SYS_VFS_H
-#define	_SYS_SUNDDI_H
 #define	_SYS_CALLB_H
 
 #include <stdio.h>
@@ -51,7 +48,6 @@
 #include <errno.h>
 #include <string.h>
 #include <strings.h>
-#include <synch.h>
 #include <thread.h>
 #include <assert.h>
 #include <alloca.h>
@@ -80,25 +76,28 @@
 #include <sys/u8_textprep.h>
 #include <sys/sysevent/eventdefs.h>
 #include <sys/sysevent/dev.h>
-#include <sys/sunddi.h>
 #include <sys/debug.h>
+#include <sys/taskq.h>
+#include <sys/taskq_impl.h>
+#include <sys/mutex.h>
+#include <sys/proc.h>
+#include <sys/condvar.h>
+#include <sys/cmn_err.h>
+#include <sys/kmem.h>
+#include <sys/systm.h>
+#include <sys/random.h>
+#include <sys/buf.h>
+#include <sys/sid.h>
+#include <sys/acl.h>
+#include <sys/bitmap.h>
+#include <sys/systeminfo.h>
+#include <sys/cpuvar.h>
+#include <sys/pset.h>
+#include <sys/kobj.h>
+#include <sys/fm/util.h>
 #include "zfs.h"
 
 /*
- * Debugging
- */
-
-/*
- * Note that we are not using the debugging levels.
- */
-
-#define	CE_CONT		0	/* continuation		*/
-#define	CE_NOTE		1	/* notice		*/
-#define	CE_WARN		2	/* warning		*/
-#define	CE_PANIC	3	/* panic		*/
-#define	CE_IGNORE	4	/* print nothing	*/
-
-/*
  * ZFS debugging
  */
 
@@ -106,15 +105,6 @@
 extern void dprintf_setup(int *argc, char **argv);
 #endif /* ZFS_DEBUG */
 
-extern void cmn_err(int, const char *, ...);
-extern void vcmn_err(int, const char *, __va_list);
-extern void panic(const char *, ...)  __NORETURN;
-extern void vpanic(const char *, __va_list)  __NORETURN;
-
-#define	fm_panic	panic
-
-extern int aok;
-
 /*
  * DTrace SDT probes have different signatures in userland than they do in
  * the kernel.  If they're being used in kernel code, re-define them out of
@@ -174,234 +164,15 @@
 /*
  * Threads
  */
-#define	curthread	((void *)(uintptr_t)thr_self())
-
 #define	kpreempt(x)	yield()
-
-typedef struct kthread kthread_t;
-
-#define	thread_create(stk, stksize, func, arg, len, pp, state, pri)	\
-	zk_thread_create(func, arg, len)
-#define	thread_exit() thr_exit(NULL)
-#define	thread_join(t)	panic("libzpool cannot join threads")
-
 #define	newproc(f, a, cid, pri, ctp, pid)	(ENOSYS)
 
-/* in libzpool, p0 exists only to have its address taken */
-struct proc {
-	uintptr_t	this_is_never_used_dont_dereference_it;
-};
-
-extern struct proc p0;
-#define	curproc		(&p0)
-
-#define	PS_NONE		-1
-
-extern kthread_t *zk_thread_create(void (*func)(void*), void *arg,
-    uint64_t len);
-
-#define	issig(why)	(FALSE)
-#define	ISSIG(thr, why)	(FALSE)
-
 /*
- * Mutexes
+ * vnodes
  */
-typedef struct kmutex {
-	void		*m_owner;
-	boolean_t	initialized;
-	mutex_t		m_lock;
-} kmutex_t;
-
-#define	MUTEX_DEFAULT	USYNC_THREAD
-#undef	MUTEX_HELD
-#undef	MUTEX_NOT_HELD
-#define	MUTEX_HELD(m) _mutex_held(&(m)->m_lock)
-#define	MUTEX_NOT_HELD(m) (!MUTEX_HELD(m))
-
-/*
- * Argh -- we have to get cheesy here because the kernel and userland
- * have different signatures for the same routine.
- */
-extern int _mutex_init(mutex_t *mp, int type, void *arg);
-extern int _mutex_destroy(mutex_t *mp);
-
-#define	mutex_init(mp, b, c, d)		zmutex_init((kmutex_t *)(mp))
-#define	mutex_destroy(mp)		zmutex_destroy((kmutex_t *)(mp))
-#define	mutex_enter(mp)			zmutex_enter(mp)
-#define	mutex_exit(mp)			zmutex_exit(mp)
-
-extern void zmutex_init(kmutex_t *mp);
-extern void zmutex_destroy(kmutex_t *mp);
-extern void zmutex_enter(kmutex_t *mp);
-extern void zmutex_exit(kmutex_t *mp);
-extern int mutex_tryenter(kmutex_t *mp);
-extern void *mutex_owner(kmutex_t *mp);
-
-/*
- * RW locks
- */
-typedef struct krwlock {
-	void		*rw_owner;
-	boolean_t	initialized;
-	rwlock_t	rw_lock;
-} krwlock_t;
-
-typedef int krw_t;
-
-#define	RW_READER	0
-#define	RW_WRITER	1
-#define	RW_DEFAULT	USYNC_THREAD
-
-#undef RW_READ_HELD
-#define	RW_READ_HELD(x)		_rw_read_held(&(x)->rw_lock)
-
-#undef RW_WRITE_HELD
-#define	RW_WRITE_HELD(x)	_rw_write_held(&(x)->rw_lock)
-
-#undef RW_LOCK_HELD
-#define	RW_LOCK_HELD(x)		(RW_READ_HELD(x) || RW_WRITE_HELD(x))
-
-extern void rw_init(krwlock_t *rwlp, char *name, int type, void *arg);
-extern void rw_destroy(krwlock_t *rwlp);
-extern void rw_enter(krwlock_t *rwlp, krw_t rw);
-extern int rw_tryenter(krwlock_t *rwlp, krw_t rw);
-extern int rw_tryupgrade(krwlock_t *rwlp);
-extern void rw_exit(krwlock_t *rwlp);
-#define	rw_downgrade(rwlp) do { } while (0)
-
-extern uid_t crgetuid(cred_t *cr);
-extern uid_t crgetruid(cred_t *cr);
-extern gid_t crgetgid(cred_t *cr);
-extern int crgetngroups(cred_t *cr);
-extern gid_t *crgetgroups(cred_t *cr);
-
-/*
- * Condition variables
- */
-typedef cond_t kcondvar_t;
-
-#define	CV_DEFAULT	USYNC_THREAD
-#define	CALLOUT_FLAG_ABSOLUTE	0x2
-
-extern void cv_init(kcondvar_t *cv, char *name, int type, void *arg);
-extern void cv_destroy(kcondvar_t *cv);
-extern void cv_wait(kcondvar_t *cv, kmutex_t *mp);
-extern clock_t cv_timedwait(kcondvar_t *cv, kmutex_t *mp, clock_t abstime);
-extern clock_t cv_timedwait_hires(kcondvar_t *cvp, kmutex_t *mp, hrtime_t tim,
-    hrtime_t res, int flag);
-extern void cv_signal(kcondvar_t *cv);
-extern void cv_broadcast(kcondvar_t *cv);
-
-/*
- * Thread-specific data
- */
-#define	tsd_get(k) pthread_getspecific(k)
-#define	tsd_set(k, v) pthread_setspecific(k, v)
-#define	tsd_create(kp, d) pthread_key_create(kp, d)
-#define	tsd_destroy(kp) /* nothing */
-
-/*
- * kstat creation, installation and deletion
- */
-extern kstat_t *kstat_create(const char *, int,
-    const char *, const char *, uchar_t, ulong_t, uchar_t);
-extern void kstat_named_init(kstat_named_t *, const char *, uchar_t);
-extern void kstat_install(kstat_t *);
-extern void kstat_delete(kstat_t *);
-extern void kstat_waitq_enter(kstat_io_t *);
-extern void kstat_waitq_exit(kstat_io_t *);
-extern void kstat_runq_enter(kstat_io_t *);
-extern void kstat_runq_exit(kstat_io_t *);
-extern void kstat_waitq_to_runq(kstat_io_t *);
-extern void kstat_runq_back_to_waitq(kstat_io_t *);
-
-/*
- * Kernel memory
- */
-#define	KM_SLEEP		UMEM_NOFAIL
-#define	KM_PUSHPAGE		KM_SLEEP
-#define	KM_NOSLEEP		UMEM_DEFAULT
-#define	KM_NORMALPRI		0	/* not needed with UMEM_DEFAULT */
-#define	KMC_NODEBUG		UMC_NODEBUG
-#define	KMC_NOTOUCH		0	/* not needed for userland caches */
-#define	kmem_alloc(_s, _f)	umem_alloc(_s, _f)
-#define	kmem_zalloc(_s, _f)	umem_zalloc(_s, _f)
-#define	kmem_free(_b, _s)	umem_free(_b, _s)
-#define	kmem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i) \
-	umem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i)
-#define	kmem_cache_destroy(_c)	umem_cache_destroy(_c)
-#define	kmem_cache_alloc(_c, _f) umem_cache_alloc(_c, _f)
-#define	kmem_cache_free(_c, _b)	umem_cache_free(_c, _b)
-#define	kmem_debugging()	0
-#define	kmem_cache_reap_now(_c)		/* nothing */
-#define	kmem_cache_set_move(_c, _cb)	/* nothing */
-#define	vmem_qcache_reap(_v)		/* nothing */
-#define	POINTER_INVALIDATE(_pp)		/* nothing */
-#define	POINTER_IS_VALID(_p)	0
-
-extern vmem_t *zio_arena;
-
-typedef umem_cache_t kmem_cache_t;
-
-typedef enum kmem_cbrc {
-	KMEM_CBRC_YES,
-	KMEM_CBRC_NO,
-	KMEM_CBRC_LATER,
-	KMEM_CBRC_DONT_NEED,
-	KMEM_CBRC_DONT_KNOW
-} kmem_cbrc_t;
-
-/*
- * Task queues
- */
-typedef struct taskq taskq_t;
-typedef uintptr_t taskqid_t;
-typedef void (task_func_t)(void *);
-
-typedef struct taskq_ent {
-	struct taskq_ent	*tqent_next;
-	struct taskq_ent	*tqent_prev;
-	task_func_t		*tqent_func;
-	void			*tqent_arg;
-	uintptr_t		tqent_flags;
-} taskq_ent_t;
-
-#define	TQENT_FLAG_PREALLOC	0x1	/* taskq_dispatch_ent used */
-
-#define	TASKQ_PREPOPULATE	0x0001
-#define	TASKQ_CPR_SAFE		0x0002	/* Use CPR safe protocol */
-#define	TASKQ_DYNAMIC		0x0004	/* Use dynamic thread scheduling */
-#define	TASKQ_THREADS_CPU_PCT	0x0008	/* Scale # threads by # cpus */
-#define	TASKQ_DC_BATCH		0x0010	/* Mark threads as batch */
-
-#define	TQ_SLEEP	KM_SLEEP	/* Can block for memory */
-#define	TQ_NOSLEEP	KM_NOSLEEP	/* cannot block for memory; may fail */
-#define	TQ_NOQUEUE	0x02		/* Do not enqueue if can't dispatch */
-#define	TQ_FRONT	0x08		/* Queue in front */
-
-
-extern taskq_t *system_taskq;
-
-extern taskq_t	*taskq_create(const char *, int, pri_t, int, int, uint_t);
-#define	taskq_create_proc(a, b, c, d, e, p, f) \
-	    (taskq_create(a, b, c, d, e, f))
-#define	taskq_create_sysdc(a, b, d, e, p, dc, f) \
-	    (taskq_create(a, b, maxclsyspri, d, e, f))
-extern taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t);
-extern void	taskq_dispatch_ent(taskq_t *, task_func_t, void *, uint_t,
-    taskq_ent_t *);
-extern void	taskq_destroy(taskq_t *);
-extern void	taskq_wait(taskq_t *);
-extern int	taskq_member(taskq_t *, void *);
-extern void	system_taskq_init(void);
-extern void	system_taskq_fini(void);
-
 #define	XVA_MAPSIZE	3
 #define	XVA_MAGIC	0x78766174
 
-/*
- * vnodes
- */
 typedef struct vnode {
 	uint64_t	v_size;
 	int		v_fd;
@@ -501,26 +272,13 @@
 extern vnode_t *rootdir;
 
 #include <sys/file.h>		/* for FREAD, FWRITE, etc */
+#include <sys/sunddi.h>		/* for ddi_strtoul, ddi_strtoull, etc */
+#include <sys/cyclic.h>		/* for cyclic_add, cyclic remove, etc */
+#include <vm/seg_kmem.h>	/* for zio_arena */
 
 /*
  * Random stuff
  */
-#define	ddi_get_lbolt()		(gethrtime() >> 23)
-#define	ddi_get_lbolt64()	(gethrtime() >> 23)
-#define	hz	119	/* frequency when using gethrtime() >> 23 for lbolt */
-
-extern void delay(clock_t ticks);
-
-#define	SEC_TO_TICK(sec)	((sec) * hz)
-#define	NSEC_TO_TICK(usec)	((usec) / (NANOSEC / hz))
-
-#define	gethrestime_sec() time(NULL)
-#define	gethrestime(t) \
-	do {\
-		(t)->tv_sec = gethrestime_sec();\
-		(t)->tv_nsec = 0;\
-	} while (0);
-
 #define	max_ncpus	64
 #define	boot_ncpus	(sysconf(_SC_NPROCESSORS_ONLN))
 
@@ -529,22 +287,10 @@
 
 #define	CPU_SEQID	(thr_self() & (max_ncpus - 1))
 
-#define	kcred		NULL
-#define	CRED()		NULL
-
-#define	ptob(x)		((x) * PAGESIZE)
-
-extern uint64_t physmem;
-
-extern int highbit64(uint64_t i);
-extern int random_get_bytes(uint8_t *ptr, size_t len);
-extern int random_get_pseudo_bytes(uint8_t *ptr, size_t len);
-
 extern void kernel_init(int);
 extern void kernel_fini(void);
 
 struct spa;
-extern void nicenum(uint64_t num, char *buf, size_t);
 extern void show_pool_stats(struct spa *);
 extern int set_global_var(char *arg);
 
@@ -572,127 +318,14 @@
 #define	zone_dataset_visible(x, y)	(1)
 #define	INGLOBALZONE(z)			(1)
 
-extern char *kmem_asprintf(const char *fmt, ...);
-#define	strfree(str) kmem_free((str), strlen(str) + 1)
-
-/*
- * Hostname information
- */
-extern char hw_serial[];	/* for userland-emulated hostid access */
-extern int ddi_strtoul(const char *str, char **nptr, int base,
-    unsigned long *result);
-
-extern int ddi_strtoull(const char *str, char **nptr, int base,
-    u_longlong_t *result);
-
-/* ZFS Boot Related stuff. */
-
-struct _buf {
-	intptr_t	_fd;
-};
-
-struct bootstat {
-	uint64_t st_size;
-};
-
-typedef struct ace_object {
-	uid_t		a_who;
-	uint32_t	a_access_mask;
-	uint16_t	a_flags;
-	uint16_t	a_type;
-	uint8_t		a_obj_type[16];
-	uint8_t		a_inherit_obj_type[16];
-} ace_object_t;
-
-
-#define	ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE	0x05
-#define	ACE_ACCESS_DENIED_OBJECT_ACE_TYPE	0x06
-#define	ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE	0x07
-#define	ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE	0x08
-
-extern struct _buf *kobj_open_file(char *name);
-extern int kobj_read_file(struct _buf *file, char *buf, unsigned size,
-    unsigned off);
-extern void kobj_close_file(struct _buf *file);
-extern int kobj_get_filesize(struct _buf *file, uint64_t *size);
 extern int zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr);
 extern int zfs_secpolicy_rename_perms(const char *from, const char *to,
     cred_t *cr);
 extern int zfs_secpolicy_destroy_perms(const char *name, cred_t *cr);
-extern zoneid_t getzoneid(void);
 
-/* SID stuff */
-typedef struct ksiddomain {
-	uint_t	kd_ref;
-	uint_t	kd_len;
-	char	*kd_name;
-} ksiddomain_t;
-
-ksiddomain_t *ksid_lookupdomain(const char *);
-void ksiddomain_rele(ksiddomain_t *);
-
-#define	DDI_SLEEP	KM_SLEEP
 #define	ddi_log_sysevent(_a, _b, _c, _d, _e, _f, _g) \
 	sysevent_post_event(_c, _d, _b, "libzpool", _e, _f)
 
-/*
- * Cyclic information
- */
-extern kmutex_t cpu_lock;
-
-typedef uintptr_t cyclic_id_t;
-typedef uint16_t cyc_level_t;
-typedef void (*cyc_func_t)(void *);
-
-#define	CY_LOW_LEVEL	0
-#define	CY_INFINITY	INT64_MAX
-#define	CYCLIC_NONE	((cyclic_id_t)0)
-
-typedef struct cyc_time {
-	hrtime_t cyt_when;
-	hrtime_t cyt_interval;
-} cyc_time_t;
-
-typedef struct cyc_handler {
-	cyc_func_t cyh_func;
-	void *cyh_arg;
-	cyc_level_t cyh_level;
-} cyc_handler_t;
-
-extern cyclic_id_t cyclic_add(cyc_handler_t *, cyc_time_t *);
-extern void cyclic_remove(cyclic_id_t);
-extern int cyclic_reprogram(cyclic_id_t, hrtime_t);
-
-/*
- * Buf structure
- */
-#define	B_BUSY		0x0001
-#define	B_DONE		0x0002
-#define	B_ERROR		0x0004
-#define	B_READ		0x0040	/* read when I/O occurs */
-#define	B_WRITE		0x0100	/* non-read pseudo-flag */
-
-typedef struct buf {
-	int	b_flags;
-	size_t b_bcount;
-	union {
-		caddr_t b_addr;
-	} b_un;
-
-	lldaddr_t	_b_blkno;
-#define	b_lblkno	_b_blkno._f
-	size_t	b_resid;
-	size_t	b_bufsize;
-	int	(*b_iodone)(struct buf *);
-	int	b_error;
-	void	*b_private;
-} buf_t;
-
-extern void bioinit(buf_t *);
-extern void biodone(buf_t *);
-extern void bioerror(buf_t *, int);
-extern int geterror(buf_t *);
-
 #ifdef	__cplusplus
 }
 #endif
--- old/usr/src/lib/libzpool/common/taskq.c	Mon Nov  6 02:54:39 2017
+++ /dev/null	Mon Nov  6 02:54:36 2017
@@ -1,342 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (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 2010 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-/*
- * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
- * Copyright 2012 Garrett D'Amore <garrett@damore.org>.  All rights reserved.
- * Copyright (c) 2014 by Delphix. All rights reserved.
- */
-
-#include <sys/zfs_context.h>
-
-int taskq_now;
-taskq_t *system_taskq;
-
-#define	TASKQ_ACTIVE	0x00010000
-#define	TASKQ_NAMELEN	31
-
-struct taskq {
-	char		tq_name[TASKQ_NAMELEN + 1];
-	kmutex_t	tq_lock;
-	krwlock_t	tq_threadlock;
-	kcondvar_t	tq_dispatch_cv;
-	kcondvar_t	tq_wait_cv;
-	thread_t	*tq_threadlist;
-	int		tq_flags;
-	int		tq_active;
-	int		tq_nthreads;
-	int		tq_nalloc;
-	int		tq_minalloc;
-	int		tq_maxalloc;
-	kcondvar_t	tq_maxalloc_cv;
-	int		tq_maxalloc_wait;
-	taskq_ent_t	*tq_freelist;
-	taskq_ent_t	tq_task;
-};
-
-static taskq_ent_t *
-task_alloc(taskq_t *tq, int tqflags)
-{
-	taskq_ent_t *t;
-	int rv;
-
-again:	if ((t = tq->tq_freelist) != NULL && tq->tq_nalloc >= tq->tq_minalloc) {
-		tq->tq_freelist = t->tqent_next;
-	} else {
-		if (tq->tq_nalloc >= tq->tq_maxalloc) {
-			if (!(tqflags & KM_SLEEP))
-				return (NULL);
-
-			/*
-			 * We don't want to exceed tq_maxalloc, but we can't
-			 * wait for other tasks to complete (and thus free up
-			 * task structures) without risking deadlock with
-			 * the caller.  So, we just delay for one second
-			 * to throttle the allocation rate. If we have tasks
-			 * complete before one second timeout expires then
-			 * taskq_ent_free will signal us and we will
-			 * immediately retry the allocation.
-			 */
-			tq->tq_maxalloc_wait++;
-			rv = cv_timedwait(&tq->tq_maxalloc_cv,
-			    &tq->tq_lock, ddi_get_lbolt() + hz);
-			tq->tq_maxalloc_wait--;
-			if (rv > 0)
-				goto again;		/* signaled */
-		}
-		mutex_exit(&tq->tq_lock);
-
-		t = kmem_alloc(sizeof (taskq_ent_t), tqflags);
-
-		mutex_enter(&tq->tq_lock);
-		if (t != NULL)
-			tq->tq_nalloc++;
-	}
-	return (t);
-}
-
-static void
-task_free(taskq_t *tq, taskq_ent_t *t)
-{
-	if (tq->tq_nalloc <= tq->tq_minalloc) {
-		t->tqent_next = tq->tq_freelist;
-		tq->tq_freelist = t;
-	} else {
-		tq->tq_nalloc--;
-		mutex_exit(&tq->tq_lock);
-		kmem_free(t, sizeof (taskq_ent_t));
-		mutex_enter(&tq->tq_lock);
-	}
-
-	if (tq->tq_maxalloc_wait)
-		cv_signal(&tq->tq_maxalloc_cv);
-}
-
-taskqid_t
-taskq_dispatch(taskq_t *tq, task_func_t func, void *arg, uint_t tqflags)
-{
-	taskq_ent_t *t;
-
-	if (taskq_now) {
-		func(arg);
-		return (1);
-	}
-
-	mutex_enter(&tq->tq_lock);
-	ASSERT(tq->tq_flags & TASKQ_ACTIVE);
-	if ((t = task_alloc(tq, tqflags)) == NULL) {
-		mutex_exit(&tq->tq_lock);
-		return (0);
-	}
-	if (tqflags & TQ_FRONT) {
-		t->tqent_next = tq->tq_task.tqent_next;
-		t->tqent_prev = &tq->tq_task;
-	} else {
-		t->tqent_next = &tq->tq_task;
-		t->tqent_prev = tq->tq_task.tqent_prev;
-	}
-	t->tqent_next->tqent_prev = t;
-	t->tqent_prev->tqent_next = t;
-	t->tqent_func = func;
-	t->tqent_arg = arg;
-	t->tqent_flags = 0;
-	cv_signal(&tq->tq_dispatch_cv);
-	mutex_exit(&tq->tq_lock);
-	return (1);
-}
-
-void
-taskq_dispatch_ent(taskq_t *tq, task_func_t func, void *arg, uint_t flags,
-    taskq_ent_t *t)
-{
-	ASSERT(func != NULL);
-	ASSERT(!(tq->tq_flags & TASKQ_DYNAMIC));
-
-	/*
-	 * Mark it as a prealloc'd task.  This is important
-	 * to ensure that we don't free it later.
-	 */
-	t->tqent_flags |= TQENT_FLAG_PREALLOC;
-	/*
-	 * Enqueue the task to the underlying queue.
-	 */
-	mutex_enter(&tq->tq_lock);
-
-	if (flags & TQ_FRONT) {
-		t->tqent_next = tq->tq_task.tqent_next;
-		t->tqent_prev = &tq->tq_task;
-	} else {
-		t->tqent_next = &tq->tq_task;
-		t->tqent_prev = tq->tq_task.tqent_prev;
-	}
-	t->tqent_next->tqent_prev = t;
-	t->tqent_prev->tqent_next = t;
-	t->tqent_func = func;
-	t->tqent_arg = arg;
-	cv_signal(&tq->tq_dispatch_cv);
-	mutex_exit(&tq->tq_lock);
-}
-
-void
-taskq_wait(taskq_t *tq)
-{
-	mutex_enter(&tq->tq_lock);
-	while (tq->tq_task.tqent_next != &tq->tq_task || tq->tq_active != 0)
-		cv_wait(&tq->tq_wait_cv, &tq->tq_lock);
-	mutex_exit(&tq->tq_lock);
-}
-
-static void *
-taskq_thread(void *arg)
-{
-	taskq_t *tq = arg;
-	taskq_ent_t *t;
-	boolean_t prealloc;
-
-	mutex_enter(&tq->tq_lock);
-	while (tq->tq_flags & TASKQ_ACTIVE) {
-		if ((t = tq->tq_task.tqent_next) == &tq->tq_task) {
-			if (--tq->tq_active == 0)
-				cv_broadcast(&tq->tq_wait_cv);
-			cv_wait(&tq->tq_dispatch_cv, &tq->tq_lock);
-			tq->tq_active++;
-			continue;
-		}
-		t->tqent_prev->tqent_next = t->tqent_next;
-		t->tqent_next->tqent_prev = t->tqent_prev;
-		t->tqent_next = NULL;
-		t->tqent_prev = NULL;
-		prealloc = t->tqent_flags & TQENT_FLAG_PREALLOC;
-		mutex_exit(&tq->tq_lock);
-
-		rw_enter(&tq->tq_threadlock, RW_READER);
-		t->tqent_func(t->tqent_arg);
-		rw_exit(&tq->tq_threadlock);
-
-		mutex_enter(&tq->tq_lock);
-		if (!prealloc)
-			task_free(tq, t);
-	}
-	tq->tq_nthreads--;
-	cv_broadcast(&tq->tq_wait_cv);
-	mutex_exit(&tq->tq_lock);
-	return (NULL);
-}
-
-/*ARGSUSED*/
-taskq_t *
-taskq_create(const char *name, int nthreads, pri_t pri,
-	int minalloc, int maxalloc, uint_t flags)
-{
-	taskq_t *tq = kmem_zalloc(sizeof (taskq_t), KM_SLEEP);
-	int t;
-
-	if (flags & TASKQ_THREADS_CPU_PCT) {
-		int pct;
-		ASSERT3S(nthreads, >=, 0);
-		ASSERT3S(nthreads, <=, 100);
-		pct = MIN(nthreads, 100);
-		pct = MAX(pct, 0);
-
-		nthreads = (sysconf(_SC_NPROCESSORS_ONLN) * pct) / 100;
-		nthreads = MAX(nthreads, 1);	/* need at least 1 thread */
-	} else {
-		ASSERT3S(nthreads, >=, 1);
-	}
-
-	rw_init(&tq->tq_threadlock, NULL, RW_DEFAULT, NULL);
-	mutex_init(&tq->tq_lock, NULL, MUTEX_DEFAULT, NULL);
-	cv_init(&tq->tq_dispatch_cv, NULL, CV_DEFAULT, NULL);
-	cv_init(&tq->tq_wait_cv, NULL, CV_DEFAULT, NULL);
-	cv_init(&tq->tq_maxalloc_cv, NULL, CV_DEFAULT, NULL);
-	(void) strncpy(tq->tq_name, name, TASKQ_NAMELEN + 1);
-	tq->tq_flags = flags | TASKQ_ACTIVE;
-	tq->tq_active = nthreads;
-	tq->tq_nthreads = nthreads;
-	tq->tq_minalloc = minalloc;
-	tq->tq_maxalloc = maxalloc;
-	tq->tq_task.tqent_next = &tq->tq_task;
-	tq->tq_task.tqent_prev = &tq->tq_task;
-	tq->tq_threadlist = kmem_alloc(nthreads * sizeof (thread_t), KM_SLEEP);
-
-	if (flags & TASKQ_PREPOPULATE) {
-		mutex_enter(&tq->tq_lock);
-		while (minalloc-- > 0)
-			task_free(tq, task_alloc(tq, KM_SLEEP));
-		mutex_exit(&tq->tq_lock);
-	}
-
-	for (t = 0; t < nthreads; t++)
-		(void) thr_create(0, 0, taskq_thread,
-		    tq, THR_BOUND, &tq->tq_threadlist[t]);
-
-	return (tq);
-}
-
-void
-taskq_destroy(taskq_t *tq)
-{
-	int t;
-	int nthreads = tq->tq_nthreads;
-
-	taskq_wait(tq);
-
-	mutex_enter(&tq->tq_lock);
-
-	tq->tq_flags &= ~TASKQ_ACTIVE;
-	cv_broadcast(&tq->tq_dispatch_cv);
-
-	while (tq->tq_nthreads != 0)
-		cv_wait(&tq->tq_wait_cv, &tq->tq_lock);
-
-	tq->tq_minalloc = 0;
-	while (tq->tq_nalloc != 0) {
-		ASSERT(tq->tq_freelist != NULL);
-		task_free(tq, task_alloc(tq, KM_SLEEP));
-	}
-
-	mutex_exit(&tq->tq_lock);
-
-	for (t = 0; t < nthreads; t++)
-		(void) thr_join(tq->tq_threadlist[t], NULL, NULL);
-
-	kmem_free(tq->tq_threadlist, nthreads * sizeof (thread_t));
-
-	rw_destroy(&tq->tq_threadlock);
-	mutex_destroy(&tq->tq_lock);
-	cv_destroy(&tq->tq_dispatch_cv);
-	cv_destroy(&tq->tq_wait_cv);
-	cv_destroy(&tq->tq_maxalloc_cv);
-
-	kmem_free(tq, sizeof (taskq_t));
-}
-
-int
-taskq_member(taskq_t *tq, void *t)
-{
-	int i;
-
-	if (taskq_now)
-		return (1);
-
-	for (i = 0; i < tq->tq_nthreads; i++)
-		if (tq->tq_threadlist[i] == (thread_t)(uintptr_t)t)
-			return (1);
-
-	return (0);
-}
-
-void
-system_taskq_init(void)
-{
-	system_taskq = taskq_create("system_taskq", 64, minclsyspri, 4, 512,
-	    TASKQ_DYNAMIC | TASKQ_PREPOPULATE);
-}
-
-void
-system_taskq_fini(void)
-{
-	taskq_destroy(system_taskq);
-	system_taskq = NULL; /* defensive */
-}
--- old/usr/src/lib/libzpool/common/util.c	Mon Nov  6 02:54:39 2017
+++ new/usr/src/lib/libzpool/common/util.c	Mon Nov  6 02:54:39 2017
@@ -21,6 +21,7 @@
 /*
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2016 by Delphix. All rights reserved.
+ * Copyright 2017 RackTop Systems.
  */
 
 #include <assert.h>
@@ -34,6 +35,8 @@
 #include <sys/refcount.h>
 #include <dlfcn.h>
 
+extern void nicenum(uint64_t num, char *buf, size_t);
+
 /*
  * Routines needed by more than one client of libzpool.
  */
--- old/usr/src/pkg/manifests/system-library.mf	Mon Nov  6 02:54:39 2017
+++ new/usr/src/pkg/manifests/system-library.mf	Mon Nov  6 02:54:39 2017
@@ -24,6 +24,7 @@
 # Copyright 2012 OmniTI Computer Consulting, Inc.  All rights reserved.
 # Copyright (c) 2013 Gary Mills
 # Copyright 2017 Nexenta Systems, Inc.
+# Copyright 2017 RackTop Systems.
 #
 
 <include system-library.man3.inc>
@@ -202,6 +203,7 @@
 file path=lib/$(ARCH64)/libdoor.so.1
 file path=lib/$(ARCH64)/libefi.so.1
 file path=lib/$(ARCH64)/libelf.so.1
+file path=lib/$(ARCH64)/libfakekernel.so.1
 $(i386_ONLY)file path=lib/$(ARCH64)/libfdisk.so.1
 file path=lib/$(ARCH64)/libgen.so.1
 file path=lib/$(ARCH64)/libinetutil.so.1
@@ -280,6 +282,7 @@
 file path=lib/libefi.so.1
 file path=lib/libelf.so.1
 file path=lib/libelfsign.so.1
+file path=lib/libfakekernel.so.1
 $(i386_ONLY)file path=lib/libfdisk.so.1
 file path=lib/libgen.so.1
 file path=lib/libinetutil.so.1
@@ -853,6 +856,8 @@
 link path=usr/lib/$(ARCH64)/libelf.so.1 \
     target=../../../lib/$(ARCH64)/libelf.so.1
 link path=usr/lib/$(ARCH64)/libexacct.so target=libexacct.so.1
+link path=usr/lib/$(ARCH64)/libfakekernel.so.1 \
+    target=../../../lib/$(ARCH64)/libfakekernel.so.1
 $(i386_ONLY)link path=usr/lib/$(ARCH64)/libfdisk.so \
     target=../../../lib/$(ARCH64)/libfdisk.so.1
 $(i386_ONLY)link path=usr/lib/$(ARCH64)/libfdisk.so.1 \
@@ -1106,6 +1111,7 @@
 link path=usr/lib/libelf.so target=../../lib/libelf.so.1
 link path=usr/lib/libelf.so.1 target=../../lib/libelf.so.1
 link path=usr/lib/libexacct.so target=./libexacct.so.1
+link path=usr/lib/libfakekernel.so.1 target=../../lib/libfakekernel.so.1
 $(i386_ONLY)link path=usr/lib/libfdisk.so target=../../lib/libfdisk.so.1
 $(i386_ONLY)link path=usr/lib/libfdisk.so.1 target=../../lib/libfdisk.so.1
 link path=usr/lib/libform.so target=./libform.so.1
--- old/usr/src/pkg/manifests/system-test-zfstest.mf	Mon Nov  6 02:54:39 2017
+++ new/usr/src/pkg/manifests/system-test-zfstest.mf	Mon Nov  6 02:54:39 2017
@@ -863,6 +863,11 @@
 file \
     path=opt/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_all_001_pos \
     mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_all_fail \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_all_mountpoints \
+    mode=0555
 file path=opt/zfs-tests/tests/functional/cli_root/zfs_promote/cleanup \
     mode=0555
 file path=opt/zfs-tests/tests/functional/cli_root/zfs_promote/setup mode=0555
--- old/usr/src/test/zfs-tests/runfiles/delphix.run	Mon Nov  6 02:54:40 2017
+++ new/usr/src/test/zfs-tests/runfiles/delphix.run	Mon Nov  6 02:54:40 2017
@@ -144,7 +144,7 @@
     'zfs_mount_004_pos', 'zfs_mount_005_pos', 'zfs_mount_006_pos',
     'zfs_mount_007_pos', 'zfs_mount_008_pos', 'zfs_mount_009_neg',
     'zfs_mount_010_neg', 'zfs_mount_011_neg', 'zfs_mount_012_neg',
-    'zfs_mount_all_001_pos']
+    'zfs_mount_all_001_pos', 'zfs_mount_all_fail', 'zfs_mount_all_mountpoints']
 
 [/opt/zfs-tests/tests/functional/cli_root/zfs_promote]
 tests = ['zfs_promote_001_pos', 'zfs_promote_002_pos', 'zfs_promote_003_pos',
--- old/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib	Mon Nov  6 02:54:40 2017
+++ new/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib	Mon Nov  6 02:54:40 2017
@@ -25,7 +25,7 @@
 #
 
 #
-# Copyright (c) 2016 by Delphix. All rights reserved.
+# Copyright (c) 2017 by Delphix. All rights reserved.
 #
 
 . $STF_SUITE/include/libtest.shlib
@@ -84,13 +84,11 @@
 	fi
 
 	case "$type" in
-		'ctr')	log_must zfs create $pool/$fs
-			log_must zfs set mountpoint=$mntpoint $pool/$fs
+		'ctr')	log_must zfs create -o mountpoint=$mntpoint $pool/$fs
 			;;
 		'vol')	log_must zfs create -V $VOLSIZE $pool/$fs
 			;;
-		*)	log_must zfs create $pool/$fs
-			log_must zfs set mountpoint=$mntpoint $pool/$fs
+		*)	log_must zfs create -o mountpoint=$mntpoint $pool/$fs
 			;;
 	esac
 
--- /dev/null	Mon Nov  6 02:54:40 2017
+++ new/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_all_fail.ksh	Mon Nov  6 02:54:40 2017
@@ -0,0 +1,96 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# 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.
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright (c) 2017 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
+
+# DESCRIPTION:
+#       Verify that if 'zfs mount -a' fails to mount one filesystem,
+#       the command fails with a non-zero error code, but all other
+#       filesystems are mounted.
+#
+# STRATEGY:
+#       1. Create zfs filesystems
+#       2. Unmount a leaf filesystem
+#       3. Create a file in the above filesystem's mountpoint
+#       4. Verify that 'zfs mount -a' fails to mount the above
+#       5. Verify that all other filesystems were mounted
+#
+
+verify_runnable "both"
+
+typeset -a filesystems
+typeset path=${TEST_BASE_DIR%%/}/testroot$$/$TESTPOOL
+typeset fscount=10
+
+function setup_all
+{
+	# Create $fscount filesystems at the top level of $path
+	for ((i=0; i<$fscount; i++)); do
+		setup_filesystem "$DISKS" "$TESTPOOL" $i "$path/$i" ctr
+	done
+
+	zfs list -r $TESTPOOL
+
+	return 0
+}
+
+function cleanup_all
+{
+	export __ZFS_POOL_RESTRICT="$TESTPOOL"
+	log_must zfs $unmountall
+	unset __ZFS_POOL_RESTRICT
+
+	[[ -d ${TEST_BASE_DIR%%/}/testroot$$ ]] && \
+		rm -rf ${TEST_BASE_DIR%%/}/testroot$$
+}
+
+log_onexit cleanup_all
+
+log_must setup_all
+
+#
+# Unmount all of the above so that we can create the stray file
+# in one of the mountpoint directories.
+#
+export __ZFS_POOL_RESTRICT="$TESTPOOL"
+log_must zfs $unmountall
+unset __ZFS_POOL_RESTRICT
+
+# All of our filesystems should be unmounted at this point
+for ((i=0; i<$fscount; i++)); do
+	log_mustnot mounted "$TESTPOOL/$i"
+done
+
+# Create a stray file in one filesystem's mountpoint
+touch $path/0/strayfile
+
+# Verify that zfs mount -a fails
+export __ZFS_POOL_RESTRICT="$TESTPOOL"
+log_mustnot zfs $mountall
+unset __ZFS_POOL_RESTRICT
+
+# All filesystems except for "0" should be mounted
+log_mustnot mounted "$TESTPOOL/0"
+for ((i=1; i<$fscount; i++)); do
+	log_must mounted "$TESTPOOL/$i"
+done
+
+log_pass "'zfs $mountall' failed as expected."
--- /dev/null	Mon Nov  6 02:54:40 2017
+++ new/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_all_mountpoints.ksh	Mon Nov  6 02:54:40 2017
@@ -0,0 +1,162 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# 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.
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright (c) 2017 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
+
+# DESCRIPTION:
+#       Verify that 'zfs mount -a' succeeds given a set of filesystems
+#       whose mountpoints have a parent/child relationship which is
+#       counter to the filesystem parent/child relationship.
+#
+# STRATEGY:
+#       1. Create zfs filesystems within the given pool.
+#       2. Unmount all the filesystems.
+#       3. Verify that 'zfs mount -a' command succeed,
+#	   and all available ZFS filesystems are mounted.
+#	4. Verify that 'zfs mount' is identical with 'df -F zfs'
+#
+
+verify_runnable "both"
+
+typeset -a filesystems
+
+function setup_all
+{
+	typeset path=${TEST_BASE_DIR%%/}/testroot$$/$TESTPOOL
+	typeset fscount=10
+
+	#
+	# Generate an array of filesystem names that represent a deep
+	# hierarchy as such:
+	#
+	# 0
+	# 0/1
+	# 0/1/2
+	# 0/1/2/3
+	# 0/1/2/3/4
+	# ...
+	#
+	fs=0
+	for ((i=0; i<$fscount; i++)); do
+		if [[ $i -gt 0 ]]; then
+			fs=$fs/$i
+		fi
+		filesystems+=($fs)
+	done
+
+	# Create all of the above filesystems
+	for ((i=0; i<$fscount; i++)); do
+		fs=${filesystems[$i]}
+		setup_filesystem "$DISKS" "$TESTPOOL" "$fs" "$path/$i" ctr
+	done
+
+	zfs list -r $TESTPOOL
+
+	#
+	# Unmount all of the above so that we can setup our convoluted
+	# mount paths.
+	#
+	export __ZFS_POOL_RESTRICT="$TESTPOOL"
+	log_must zfs $unmountall
+	unset __ZFS_POOL_RESTRICT
+
+	#
+	# Configure the mount paths so that each mountpoint is contained
+	# in a child filesystem. We should end up with something like the
+	# following structure (modulo the number of filesystems):
+	#
+	# NAME                       MOUNTPOINT
+	# testpool                   /testpool
+	# testpool/0                 /testroot25416/testpool/0/1/2/3/4/5/6
+	# testpool/0/1               /testroot25416/testpool/0/1/2/3/4/5
+	# testpool/0/1/2             /testroot25416/testpool/0/1/2/3/4
+	# testpool/0/1/2/3           /testroot25416/testpool/0/1/2/3
+	# testpool/0/1/2/3/4         /testroot25416/testpool/0/1/2
+	# testpool/0/1/2/3/4/5       /testroot25416/testpool/0/1
+	# testpool/0/1/2/3/4/5/6     /testroot25416/testpool/0
+	#
+	for ((i=0; i<$fscount; i++)); do
+		fs=$TESTPOOL/${filesystems[$(($fscount - $i - 1))]}
+		mnt=$path/${filesystems[$i]}
+		zfs set mountpoint=$mnt $fs
+	done
+
+	zfs list -r $TESTPOOL
+
+	return 0
+}
+
+function cleanup_all
+{
+	export __ZFS_POOL_RESTRICT="$TESTPOOL"
+	log_must zfs $unmountall
+	unset __ZFS_POOL_RESTRICT
+
+	for fs in ${filesystems[@]}; do
+		cleanup_filesystem "$TESTPOOL" "$fs"
+	done
+	[[ -d ${TEST_BASE_DIR%%/}/testroot$$ ]] && \
+		rm -rf ${TEST_BASE_DIR%%/}/testroot$$
+}
+
+#
+# This function takes a single true/false argument. If true it will verify that
+# all file systems are mounted. If false it will verify that they are not
+# mounted.
+#
+function verify_all
+{
+	if $1; then
+		logfunc=log_must
+	else
+		logfunc=log_mustnot
+	fi
+
+	for fs in ${filesystems[@]}; do
+		$logfunc mounted "$TESTPOOL/$fs"
+	done
+
+	return 0
+}
+
+log_onexit cleanup_all
+
+log_must setup_all
+
+export __ZFS_POOL_RESTRICT="$TESTPOOL"
+log_must zfs $unmountall
+unset __ZFS_POOL_RESTRICT
+
+verify_all false
+
+export __ZFS_POOL_RESTRICT="$TESTPOOL"
+log_must zfs $mountall
+unset __ZFS_POOL_RESTRICT
+
+verify_all true
+
+log_note "Verify that 'zfs $mountcmd' will display " \
+	"all ZFS filesystems currently mounted."
+
+verify_mount_display
+
+log_pass "'zfs $mountall' succeeds as root, " \
+	"and all available ZFS filesystems are mounted."
--- old/usr/src/uts/common/fs/hsfs/hsfs_vfsops.c	Mon Nov  6 02:54:40 2017
+++ new/usr/src/uts/common/fs/hsfs/hsfs_vfsops.c	Mon Nov  6 02:54:40 2017
@@ -22,6 +22,7 @@
  * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2011 Bayard G. Bell. All rights reserved.
  * Copyright 2013 Joyent, Inc. All rights reserved.
+ * Copyright (c) 2017 by Delphix. All rights reserved.
  */
 
 /*
@@ -150,7 +151,7 @@
 	"hsfs",
 	hsfsinit,
 	/* We don't suppport remounting */
-	VSW_HASPROTO|VSW_STATS|VSW_CANLOFI,
+	VSW_HASPROTO|VSW_STATS|VSW_CANLOFI|VSW_MOUNTDEV,
 	&hsfs_proto_opttbl
 };
 
--- old/usr/src/uts/common/fs/pcfs/pc_vfsops.c	Mon Nov  6 02:54:40 2017
+++ new/usr/src/uts/common/fs/pcfs/pc_vfsops.c	Mon Nov  6 02:54:40 2017
@@ -23,6 +23,9 @@
  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
+/*
+ * Copyright (c) 2017 by Delphix. All rights reserved.
+ */
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -156,7 +159,7 @@
 	VFSDEF_VERSION,
 	"pcfs",
 	pcfsinit,
-	VSW_HASPROTO|VSW_CANREMOUNT|VSW_STATS|VSW_CANLOFI,
+	VSW_HASPROTO|VSW_CANREMOUNT|VSW_STATS|VSW_CANLOFI|VSW_MOUNTDEV,
 	&pcfs_mntopts
 };
 
--- old/usr/src/uts/common/fs/udfs/udf_vfsops.c	Mon Nov  6 02:54:41 2017
+++ new/usr/src/uts/common/fs/udfs/udf_vfsops.c	Mon Nov  6 02:54:41 2017
@@ -22,6 +22,7 @@
  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  * Copyright (c) 2011 Bayard G. Bell. All rights reserved.
+ * Copyright (c) 2017 by Delphix. All rights reserved.
  */
 
 #include <sys/types.h>
@@ -121,7 +122,7 @@
 	VFSDEF_VERSION,
 	"udfs",
 	udfinit,
-	VSW_HASPROTO|VSW_CANREMOUNT|VSW_STATS|VSW_CANLOFI,
+	VSW_HASPROTO|VSW_CANREMOUNT|VSW_STATS|VSW_CANLOFI|VSW_MOUNTDEV,
 	&udfs_mntopts
 };
 
@@ -177,7 +178,7 @@
 #endif
 static int32_t
 udf_mount(struct vfs *vfsp, struct vnode *mvp,
-	struct mounta *uap, struct cred *cr)
+    struct mounta *uap, struct cred *cr)
 {
 	dev_t dev;
 	struct vnode *lvp = NULL;
@@ -489,8 +490,7 @@
 
 /* ARGSUSED */
 static int32_t
-udf_vget(struct vfs *vfsp,
-	struct vnode **vpp, struct fid *fidp)
+udf_vget(struct vfs *vfsp, struct vnode **vpp, struct fid *fidp)
 {
 	int32_t error = 0;
 	struct udf_fid *udfid;
@@ -612,9 +612,8 @@
 
 
 static int32_t
-ud_mountfs(struct vfs *vfsp,
-	enum whymountroot why, dev_t dev, char *name,
-	struct cred *cr, int32_t isroot)
+ud_mountfs(struct vfs *vfsp, enum whymountroot why, dev_t dev, char *name,
+    struct cred *cr, int32_t isroot)
 {
 	struct vnode *devvp = NULL;
 	int32_t error = 0;
@@ -1554,7 +1553,7 @@
 
 void
 ud_convert_to_superblock(struct udf_vfs *udf_vfsp,
-	struct log_vol_int_desc *lvid)
+    struct log_vol_int_desc *lvid)
 {
 	int32_t i, c;
 	uint32_t *temp;
@@ -1652,7 +1651,7 @@
  */
 static int32_t
 ud_val_get_vat(struct udf_vfs *udf_vfsp, dev_t dev,
-	daddr_t blkno, struct ud_map *udm)
+    daddr_t blkno, struct ud_map *udm)
 {
 	struct buf *secbp;
 	struct file_entry *fe;
@@ -1776,7 +1775,7 @@
 
 int32_t
 ud_read_sparing_tbls(struct udf_vfs *udf_vfsp,
-	dev_t dev, struct ud_map *map, struct pmap_typ2 *typ2)
+    dev_t dev, struct ud_map *map, struct pmap_typ2 *typ2)
 {
 	int32_t index, valid = 0;
 	uint32_t sz;
--- old/usr/src/uts/common/fs/ufs/ufs_vfsops.c	Mon Nov  6 02:54:41 2017
+++ new/usr/src/uts/common/fs/ufs/ufs_vfsops.c	Mon Nov  6 02:54:41 2017
@@ -23,6 +23,7 @@
  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  * Copyright 2016 Nexenta Systems, Inc.
+ * Copyright (c) 2017 by Delphix. All rights reserved.
  */
 
 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
@@ -196,7 +197,7 @@
 	VFSDEF_VERSION,
 	"ufs",
 	ufsinit,
-	VSW_HASPROTO|VSW_CANREMOUNT|VSW_STATS|VSW_CANLOFI,
+	VSW_HASPROTO|VSW_CANREMOUNT|VSW_STATS|VSW_CANLOFI|VSW_MOUNTDEV,
 	&ufs_mntopts
 };
 
@@ -258,8 +259,7 @@
 
 static int
 ufs_mount(struct vfs *vfsp, struct vnode *mvp, struct mounta *uap,
-	struct cred *cr)
-
+    struct cred *cr)
 {
 	char *data = uap->dataptr;
 	int datalen = uap->datalen;
@@ -796,7 +796,7 @@
 
 static int
 mountfs(struct vfs *vfsp, enum whymountroot why, struct vnode *devvp,
-	char *path, cred_t *cr, int isroot, void *raw_argsp, int args_len)
+    char *path, cred_t *cr, int isroot, void *raw_argsp, int args_len)
 {
 	dev_t dev = devvp->v_rdev;
 	struct fs *fsp;
--- old/usr/src/uts/common/fs/vfs.c	Mon Nov  6 02:54:41 2017
+++ new/usr/src/uts/common/fs/vfs.c	Mon Nov  6 02:54:41 2017
@@ -23,7 +23,7 @@
  * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright 2016 Joyent, Inc.
  * Copyright 2016 Toomas Soome <tsoome@me.com>
- * Copyright (c) 2016 by Delphix. All rights reserved.
+ * Copyright (c) 2016, 2017 by Delphix. All rights reserved.
  * Copyright 2016 Nexenta Systems, Inc.
  * Copyright 2017 RackTop Systems.
  */
@@ -1291,7 +1291,8 @@
 		 * successful for later cleanup and addition to
 		 * the mount in progress table.
 		 */
-		if ((uap->flags & MS_GLOBAL) == 0 &&
+		if ((vswp->vsw_flag & VSW_MOUNTDEV) &&
+		    (uap->flags & MS_GLOBAL) == 0 &&
 		    lookupname(uap->spec, fromspace,
 		    FOLLOW, NULL, &bvp) == 0) {
 			addmip = 1;
@@ -1507,7 +1508,8 @@
 	 * wlock above. This case is for a non-spliced, non-global filesystem.
 	 */
 	if (!addmip) {
-		if ((uap->flags & MS_GLOBAL) == 0 &&
+		if ((vswp->vsw_flag & VSW_MOUNTDEV) &&
+		    (uap->flags & MS_GLOBAL) == 0 &&
 		    lookupname(uap->spec, fromspace, FOLLOW, NULL, &bvp) == 0) {
 			addmip = 1;
 		}
--- old/usr/src/uts/common/fs/zfs/dnode.c	Mon Nov  6 02:54:42 2017
+++ new/usr/src/uts/common/fs/zfs/dnode.c	Mon Nov  6 02:54:42 2017
@@ -23,6 +23,7 @@
  * Copyright (c) 2012, 2017 by Delphix. All rights reserved.
  * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
  * Copyright (c) 2014 Integros [integros.com]
+ * Copyright 2017 RackTop Systems.
  */
 
 #include <sys/zfs_context.h>
@@ -59,7 +60,9 @@
 int zfs_default_bs = SPA_MINBLOCKSHIFT;
 int zfs_default_ibs = DN_MAX_INDBLKSHIFT;
 
+#ifdef	_KERNEL
 static kmem_cbrc_t dnode_move(void *, void *, size_t, void *);
+#endif	/* _KERNEL */
 
 static int
 dbuf_compare(const void *x1, const void *x2)
@@ -213,7 +216,9 @@
 	dnode_cache = kmem_cache_create("dnode_t",
 	    sizeof (dnode_t),
 	    0, dnode_cons, dnode_dest, NULL, NULL, NULL, 0);
+#ifdef	_KERNEL
 	kmem_cache_set_move(dnode_cache, dnode_move);
+#endif	/* _KERNEL */
 }
 
 void
@@ -697,6 +702,7 @@
 } dnode_move_stats;
 #endif	/* DNODE_STATS */
 
+#ifdef	_KERNEL
 static void
 dnode_move_impl(dnode_t *odn, dnode_t *ndn)
 {
@@ -833,7 +839,6 @@
 	odn->dn_moved = (uint8_t)-1;
 }
 
-#ifdef	_KERNEL
 /*ARGSUSED*/
 static kmem_cbrc_t
 dnode_move(void *buf, void *newbuf, size_t size, void *arg)
--- old/usr/src/uts/common/sys/acl.h	Mon Nov  6 02:54:42 2017
+++ new/usr/src/uts/common/sys/acl.h	Mon Nov  6 02:54:42 2017
@@ -25,6 +25,7 @@
  * Use is subject to license terms.
  *
  * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
+ * Copyright 2017 RackTop Systems.
  */
 
 #ifndef _SYS_ACL_H
@@ -158,7 +159,7 @@
 
 #define	ACE_ALL_TYPES	0x001F
 
-#ifdef _KERNEL
+#if defined(_KERNEL) || defined(_FAKE_KERNEL)
 
 typedef struct ace_object {
 	uid_t		a_who;		/* uid or gid */
--- old/usr/src/uts/common/sys/bitmap.h	Mon Nov  6 02:54:42 2017
+++ new/usr/src/uts/common/sys/bitmap.h	Mon Nov  6 02:54:42 2017
@@ -26,6 +26,7 @@
 
 /*
  * Copyright (c) 2014 by Delphix. All rights reserved.
+ * Copyright 2017 RackTop Systems.
  */
 
 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
@@ -134,7 +135,7 @@
 #define	BIT_ONLYONESET(u) \
 	((((u) == 0) ? 0 : ((u) & ((u) - 1)) == 0))
 
-#if defined(_KERNEL) && !defined(_ASM)
+#if (defined(_KERNEL) || defined(_FAKE_KERNEL)) && !defined(_ASM)
 #include <sys/atomic.h>
 
 /*
@@ -188,7 +189,7 @@
  */
 #define	BITX(u, h, l)	(((u) >> (l)) & ((1LU << ((h) - (l) + 1LU)) - 1LU))
 
-#endif	/* _KERNEL && !_ASM */
+#endif	/* (_KERNEL || _FAKE_KERNEL) && !_ASM */
 
 #ifdef	__cplusplus
 }
--- old/usr/src/uts/common/sys/bitset.h	Mon Nov  6 02:54:42 2017
+++ new/usr/src/uts/common/sys/bitset.h	Mon Nov  6 02:54:42 2017
@@ -20,6 +20,7 @@
  */
 /*
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2017 RackTop Systems.
  */
 
 #ifndef	_BITSET_H
@@ -29,7 +30,7 @@
 extern "C" {
 #endif
 
-#if (defined(_KERNEL) || defined(_KMEMUSER))
+#if defined(_KERNEL) || defined(_FAKE_KERNEL) || defined(_KMEMUSER)
 #include <sys/bitmap.h>
 #include <sys/types.h>
 
@@ -87,7 +88,7 @@
 void		bitset_copy(bitset_t *, bitset_t *);
 int		bitset_match(bitset_t *, bitset_t *);
 
-#endif	/* !_KERNEL && !_KMEMUSER */
+#endif	/* _KERNEL || _FAKE_KERNEL || _KMEMUSER */
 
 #ifdef	__cplusplus
 }
--- old/usr/src/uts/common/sys/buf.h	Mon Nov  6 02:54:42 2017
+++ new/usr/src/uts/common/sys/buf.h	Mon Nov  6 02:54:42 2017
@@ -21,6 +21,8 @@
 /*
  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright 2017 RackTop Systems.
  */
 
 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
@@ -292,7 +294,7 @@
 	(bp)->av_forw = (bp)->av_back = NULL; \
 }
 
-#if defined(_KERNEL)
+#if defined(_KERNEL) || defined(_FAKE_KERNEL)
 /*
  * Macros to avoid the extra function call needed for binary compat.
  *
@@ -397,7 +399,7 @@
 struct buf *bioclone(struct buf *, off_t, size_t, dev_t, daddr_t,
 	int (*)(struct buf *), struct buf *, int);
 size_t	biosize(void);
-#endif	/* defined(_KERNEL) */
+#endif	/* defined(_KERNEL) || defined(_FAKE_KERNEL) */
 
 #ifdef	__cplusplus
 }
--- old/usr/src/uts/common/sys/cpupart.h	Mon Nov  6 02:54:43 2017
+++ new/usr/src/uts/common/sys/cpupart.h	Mon Nov  6 02:54:43 2017
@@ -20,6 +20,7 @@
  */
 /*
  * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2017 RackTop Systems.
  */
 
 #ifndef	_SYS_CPUPART_H
@@ -40,7 +41,7 @@
 extern "C" {
 #endif
 
-#ifdef _KERNEL
+#if defined(_KERNEL) || defined(_FAKE_KERNEL)
 
 typedef int	cpupartid_t;
 
@@ -148,7 +149,7 @@
 extern int	cpupart_setattr(psetid_t, uint_t);
 extern int	cpupart_getattr(psetid_t, uint_t *);
 
-#endif	/* _KERNEL */
+#endif	/* _KERNEL || _FAKE_KERNEL */
 
 #ifdef	__cplusplus
 }
--- old/usr/src/uts/common/sys/cpuvar.h	Mon Nov  6 02:54:43 2017
+++ new/usr/src/uts/common/sys/cpuvar.h	Mon Nov  6 02:54:43 2017
@@ -23,6 +23,7 @@
  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2012 by Delphix. All rights reserved.
  * Copyright 2014 Igor Kozhukhov <ikozhukhov@gmail.com>.
+ * Copyright 2017 RackTop Systems.
  */
 
 #ifndef _SYS_CPUVAR_H
@@ -32,6 +33,7 @@
 #include <sys/sysinfo.h>	/* has cpu_stat_t definition */
 #include <sys/disp.h>
 #include <sys/processor.h>
+#include <sys/kcpc.h>		/* has kcpc_ctx_t definition */
 
 #include <sys/loadavg.h>
 #if (defined(_KERNEL) || defined(_KMEMUSER)) && defined(_MACHDEP)
@@ -614,9 +616,9 @@
 #endif /* _KERNEL || _KMEMUSER */
 
 /*
- * CPU support routines.
+ * CPU support routines (not for genassym.c)
  */
-#if	defined(_KERNEL) && defined(__STDC__)	/* not for genassym.c */
+#if	defined(_KERNEL) || defined(_FAKE_KERNEL) && defined(__STDC__)
 
 struct zone;
 
@@ -823,7 +825,7 @@
 extern void cpu_vm_data_init(struct cpu *);
 extern void cpu_vm_data_destroy(struct cpu *);
 
-#endif	/* _KERNEL */
+#endif	/* _KERNEL || _FAKE_KERNEL */
 
 #ifdef	__cplusplus
 }
--- old/usr/src/uts/common/sys/cyclic.h	Mon Nov  6 02:54:43 2017
+++ new/usr/src/uts/common/sys/cyclic.h	Mon Nov  6 02:54:43 2017
@@ -21,6 +21,8 @@
 /*
  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright 2017 RackTop Systems.
  */
 
 #ifndef _SYS_CYCLIC_H
@@ -72,7 +74,7 @@
 
 #define	CY_INFINITY	INT64_MAX
 
-#ifdef _KERNEL
+#if defined(_KERNEL) || defined(_FAKE_KERNEL)
 
 extern cyclic_id_t cyclic_add(cyc_handler_t *, cyc_time_t *);
 extern cyclic_id_t cyclic_add_omni(cyc_omni_handler_t *);
@@ -92,7 +94,7 @@
 extern void cyclic_fire(cpu_t *cpu);
 extern void cyclic_softint(cpu_t *cpu, cyc_level_t level);
 
-#endif /* _KERNEL */
+#endif /* _KERNEL || _FAKE_KERNEL */
 
 #endif /* !_ASM */
 
--- old/usr/src/uts/common/sys/fm/util.h	Mon Nov  6 02:54:43 2017
+++ new/usr/src/uts/common/sys/fm/util.h	Mon Nov  6 02:54:43 2017
@@ -21,6 +21,7 @@
 
 /*
  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2017 RackTop Systems.
  */
 
 #ifndef	_SYS_FM_UTIL_H
@@ -70,7 +71,7 @@
 	} ed_tod_base;
 } erpt_dump_t;
 
-#ifdef _KERNEL
+#if defined(_KERNEL) || defined(_FAKE_KERNEL)
 #include <sys/systm.h>
 
 #define	FM_STK_DEPTH	20	/* maximum stack depth */
@@ -94,7 +95,7 @@
 extern void fm_payload_stack_add(nvlist_t *, const pc_t *, int);
 
 extern int is_fm_panic();
-#endif  /* _KERNEL */
+#endif  /* _KERNEL || _FAKE_KERNEL */
 
 #ifdef	__cplusplus
 }
--- old/usr/src/uts/common/sys/kobj.h	Mon Nov  6 02:54:43 2017
+++ new/usr/src/uts/common/sys/kobj.h	Mon Nov  6 02:54:43 2017
@@ -21,13 +21,13 @@
 /*
  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright 2017 RackTop Systems.
  */
 
 #ifndef _SYS_KOBJ_H
 #define	_SYS_KOBJ_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/modctl.h>
 #include <sys/elf.h>
 #include <sys/machelf.h>
@@ -158,7 +158,7 @@
 
 #define	F_BLKS(file, size)	((size / (file)->_bsize) * (file)->_bsize)
 
-#if defined(_KERNEL)
+#if defined(_KERNEL) || defined(_FAKE_KERNEL)
 
 extern int kobj_load_module(struct modctl *, int);
 extern void kobj_unload_module(struct modctl *);
@@ -202,7 +202,7 @@
 extern void kobj_textwin_alloc(struct module *);
 extern void kobj_textwin_free(struct module *);
 
-#endif	/* defined(_KERNEL) */
+#endif	/* defined(_KERNEL) || defined(_FAKE_KERNEL) */
 
 #ifdef	__cplusplus
 }
--- old/usr/src/uts/common/sys/lgrp.h	Mon Nov  6 02:54:43 2017
+++ new/usr/src/uts/common/sys/lgrp.h	Mon Nov  6 02:54:43 2017
@@ -22,6 +22,8 @@
 /*
  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright 2017 RackTop Systems.
  */
 
 #ifndef	_LGRP_H
@@ -39,11 +41,11 @@
 
 #define	LGRP_NONE	(-1)		/* non-existent lgroup ID */
 
-#if (!defined(_KERNEL) && !defined(_KMEMUSER))
+#if !defined(_KERNEL) && !defined(_FAKE_KERNEL) && !defined(_KMEMUSER)
 typedef struct lgrp_mem_policy_info { int opaque[2]; }	lgrp_mem_policy_info_t;
-#endif	/* !_KERNEL && !_KMEMUSER */
+#endif	/* !_KERNEL && !_FAKE_KERNEL && !_KMEMUSER */
 
-#if (defined(_KERNEL) || defined(_KMEMUSER))
+#if defined(_KERNEL) || defined(_FAKE_KERNEL) || defined(_KMEMUSER)
 #include <sys/cpuvar.h>
 #include <sys/bitmap.h>
 #include <sys/vnode.h>
@@ -631,7 +633,7 @@
 extern uint32_t		lgrp_load_thresh;
 extern lgrp_mem_policy_t lgrp_mem_policy_root;
 
-#endif	/* _KERNEL && _KMEMUSER */
+#endif	/* _KERNEL || _FAKE_KERNEL || _KMEMUSER */
 
 #ifdef	__cplusplus
 }
--- old/usr/src/uts/common/sys/lgrp_user.h	Mon Nov  6 02:54:44 2017
+++ new/usr/src/uts/common/sys/lgrp_user.h	Mon Nov  6 02:54:44 2017
@@ -21,6 +21,7 @@
  */
 /*
  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
+ * Copyright 2017 RackTop Systems.
  *
  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
@@ -242,7 +243,7 @@
 #endif	/* _SYSCALL32 */
 
 
-#if (!defined(_KERNEL) && !defined(_KMEMUSER))
+#if !defined(_KERNEL) && !defined(_FAKE_KERNEL) && !defined(_KMEMUSER)
 
 lgrp_affinity_t	lgrp_affinity_get(idtype_t idtype, id_t id, lgrp_id_t lgrp);
 
@@ -285,7 +286,7 @@
 
 lgrp_view_t	lgrp_view(lgrp_cookie_t cookie);
 
-#endif	/* !_KERNEL && !_KMEMUSER */
+#endif	/* !_KERNEL && !_FAKE_KERNEL && !_KMEMUSER */
 
 #ifdef	__cplusplus
 }
--- old/usr/src/uts/common/sys/systeminfo.h	Mon Nov  6 02:54:44 2017
+++ new/usr/src/uts/common/sys/systeminfo.h	Mon Nov  6 02:54:44 2017
@@ -20,6 +20,7 @@
  */
 /*
  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
+ * Copyright 2017 RackTop Systems.
  *
  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
@@ -36,7 +37,7 @@
 extern "C" {
 #endif
 
-#ifdef	_KERNEL
+#if defined(_KERNEL) || defined(_FAKE_KERNEL)
 extern char architecture[];
 extern char architecture_32[];
 extern char hw_serial[];	/* machine's 32-bit hostid; a decimal string */
@@ -43,7 +44,7 @@
 extern char hw_provider[];
 extern char srpc_domain[];
 extern char platform[];
-#endif	/* _KERNEL */
+#endif	/* _KERNEL || _FAKE_KERNEL */
 
 /*
  * Commands to sysinfo(2)
--- old/usr/src/uts/common/sys/taskq.h	Mon Nov  6 02:54:44 2017
+++ new/usr/src/uts/common/sys/taskq.h	Mon Nov  6 02:54:44 2017
@@ -23,6 +23,7 @@
  * Use is subject to license terms.
  *
  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
+ * Copyright 2017 RackTop Systems.
  */
 
 #ifndef	_SYS_TASKQ_H
@@ -62,7 +63,7 @@
 #define	TQ_NOALLOC	0x04	/* cannot allocate memory; may fail */
 #define	TQ_FRONT	0x08	/* Put task at the front of the queue */
 
-#if defined(_KERNEL) || defined(_FAKE_KERNEL)
+#if defined(_KERNEL) || defined(_FAKE_KERNEL) || defined(_TASKQUSER)
 
 extern taskq_t *system_taskq;
 
@@ -85,7 +86,7 @@
 extern void	taskq_resume(taskq_t *);
 extern int	taskq_member(taskq_t *, kthread_t *);
 
-#endif	/* _KERNEL */
+#endif	/* _KERNEL || _FAKE_KERNEL || _TASKQUSER */
 
 #ifdef	__cplusplus
 }
--- old/usr/src/uts/common/sys/taskq_impl.h	Mon Nov  6 02:54:44 2017
+++ new/usr/src/uts/common/sys/taskq_impl.h	Mon Nov  6 02:54:44 2017
@@ -25,6 +25,7 @@
 /*
  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  * Copyright (c) 2017 by Delphix. All rights reserved.
+ * Copyright 2017 RackTop Systems.
  */
 
 #ifndef	_SYS_TASKQ_IMPL_H
@@ -35,6 +36,7 @@
 #include <sys/vmem.h>
 #include <sys/list.h>
 #include <sys/kstat.h>
+#include <sys/rwlock.h>
 
 #ifdef	__cplusplus
 extern "C" {
--- old/usr/src/uts/common/sys/vfs.h	Mon Nov  6 02:54:44 2017
+++ new/usr/src/uts/common/sys/vfs.h	Mon Nov  6 02:54:44 2017
@@ -22,7 +22,7 @@
 /*
  * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright 2016 Toomas Soome <tsoome@me.com>
- * Copyright (c) 2016 by Delphix. All rights reserved.
+ * Copyright (c) 2016, 2017 by Delphix. All rights reserved.
  * Copyright 2016 Nexenta Systems, Inc.
  */
 
@@ -416,6 +416,7 @@
 #define	VSW_XID		0x40	/* file system supports extended ids */
 #define	VSW_CANLOFI	0x80	/* file system supports lofi mounts */
 #define	VSW_ZMOUNT	0x100	/* file system always allowed in a zone */
+#define	VSW_MOUNTDEV	0x200	/* file system is mounted via device path */
 
 #define	VSW_INSTALLED	0x8000	/* this vsw is associated with a file system */
 
--- old/usr/src/uts/common/vm/seg_kmem.h	Mon Nov  6 02:54:44 2017
+++ new/usr/src/uts/common/vm/seg_kmem.h	Mon Nov  6 02:54:45 2017
@@ -22,6 +22,7 @@
  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  * Copyright 2016 Joyent, Inc.
+ * Copyright 2017 RackTop Systems.
  */
 
 #ifndef _VM_SEG_KMEM_H
@@ -43,7 +44,7 @@
  * VM - Kernel Segment Driver
  */
 
-#if defined(_KERNEL)
+#if defined(_KERNEL) || defined(_FAKE_KERNEL)
 
 extern char *kernelheap;	/* start of primary kernel heap */
 extern char *ekernelheap;	/* end of primary kernel heap */
@@ -139,7 +140,7 @@
 
 extern struct seg_ops segkmem_ops;
 
-#endif	/* _KERNEL */
+#endif	/* _KERNEL || _FAKE_KERNEL */
 
 #ifdef	__cplusplus
 }
