--- old/usr/src/lib/libshare/nfs/libshare_nfs.c	Mon Aug  5 17:16:30 2019
+++ new/usr/src/lib/libshare/nfs/libshare_nfs.c	Mon Aug  5 17:16:30 2019
@@ -21,19 +21,22 @@
 
 /*
  * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright 2016 Nexenta Systems, Inc.
+ */
+
+/*
  * Copyright (c) 2014, 2016 by Delphix. All rights reserved.
+ * Copyright 2018 Nexenta Systems, Inc.
  */
 
 /*
  * NFS specific functions
  */
+
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <zone.h>
 #include <errno.h>
 #include <locale.h>
 #include <signal.h>
@@ -123,8 +126,7 @@
 static char *service_list_default[] =
 	{ STATD, LOCKD, MOUNTD, NFSD, NFSMAPID, RQUOTAD, REPARSED, NULL };
 static char *service_list_logging[] =
-	{ STATD, LOCKD, MOUNTD, NFSD, NFSMAPID, RQUOTAD, NFSLOGD, REPARSED,
-	    NULL };
+	{ NFSLOGD, NULL };
 
 /*
  * option definitions.  Make sure to keep the #define for the option
@@ -174,8 +176,10 @@
 	{SHOPT_UIDMAP, OPT_UIDMAP, OPT_TYPE_MAPPING},
 #define	OPT_GIDMAP	19
 	{SHOPT_GIDMAP, OPT_GIDMAP, OPT_TYPE_MAPPING},
+#define	OPT_NOHIDE	20
+	{SHOPT_NOHIDE, OPT_NOHIDE, OPT_TYPE_BOOLEAN},
 #ifdef VOLATILE_FH_TEST	/* XXX added for testing volatile fh's only */
-#define	OPT_VOLFH	20
+#define	OPT_VOLFH	21
 	{SHOPT_VOLFH, OPT_VOLFH},
 #endif /* VOLATILE_FH_TEST */
 	NULL
@@ -186,7 +190,7 @@
  * Add new names here to add new property support. If we ever get a
  * way to query the kernel for character sets, this should become
  * dynamically loaded. Make sure changes here are reflected in
- * cmd/fs.d/nfs/mountd/nfscmd.c
+ * cmd/fs.d/nfs/mountd/nfs_cmd.c
  */
 
 static char *legal_conv[] = {
@@ -1027,6 +1031,14 @@
 			else
 				export->ex_flags &= ~EX_NOACLFAB;
 			break;
+		case OPT_NOHIDE:
+			if (value != NULL && (strcasecmp(value, "true") == 0 ||
+			    strcmp(value, "1") == 0))
+				export->ex_flags |= EX_NOHIDE;
+			else
+				export->ex_flags &= ~EX_NOHIDE;
+
+			break;
 		default:
 			/* have a syntactic error */
 			(void) printf(dgettext(TEXT_DOMAIN,
@@ -1781,6 +1793,8 @@
 	int iszfs;
 	sa_handle_t handle;
 
+	static int check_services = B_TRUE;
+
 	/* Don't drop core if the NFS module isn't loaded. */
 	(void) signal(SIGSYS, SIG_IGN);
 
@@ -1895,12 +1909,7 @@
 				sa_free_attr_string(sectype);
 		}
 	}
-	/*
-	 * when we get here, we can do the exportfs system call and
-	 * initiate things. We probably want to enable the
-	 * svc:/network/nfs/server service first if it isn't running.
-	 */
-	/* check svc:/network/nfs/server status and start if needed */
+
 	/* now add the share to the internal tables */
 	printarg(path, &export);
 	/*
@@ -1910,52 +1919,17 @@
 	if (iszfs) {
 		struct exportfs_args ea;
 		share_t sh;
-		char *str;
-		priv_set_t *priv_effective;
-		int privileged;
 
-		/*
-		 * If we aren't a privileged user
-		 * and NFS server service isn't running
-		 * then print out an error message
-		 * and return EPERM
-		 */
+		ea.dname = path;
+		ea.uex = &export;
 
-		priv_effective = priv_allocset();
-		(void) getppriv(PRIV_EFFECTIVE, priv_effective);
-
-		privileged = (priv_isfullset(priv_effective) == B_TRUE);
-		priv_freeset(priv_effective);
-
-		if (!privileged &&
-		    (str = smf_get_state(NFS_SERVER_SVC)) != NULL) {
-			err = 0;
-			if (strcmp(str, SCF_STATE_STRING_ONLINE) != 0) {
-				(void) printf(dgettext(TEXT_DOMAIN,
-				    "NFS: Cannot share remote "
-				    "filesystem: %s\n"), path);
-				(void) printf(dgettext(TEXT_DOMAIN,
-				    "NFS: Service needs to be enabled "
-				    "by a privileged user\n"));
-				err = SA_SYSTEM_ERR;
-				errno = EPERM;
-			}
-			free(str);
+		(void) sa_sharetab_fill_zfs(share, &sh, "nfs");
+		err = sa_share_zfs(share, NULL, path, &sh, &ea, ZFS_SHARE_NFS);
+		if (err != SA_OK) {
+			errno = err;
+			err = -1;
 		}
-
-		if (err == 0) {
-			ea.dname = path;
-			ea.uex = &export;
-
-			(void) sa_sharetab_fill_zfs(share, &sh, "nfs");
-			err = sa_share_zfs(share, NULL, path, &sh,
-			    &ea, ZFS_SHARE_NFS);
-			if (err != SA_OK) {
-				errno = err;
-				err = -1;
-			}
-			sa_emptyshare(&sh);
-		}
+		sa_emptyshare(&sh);
 	} else {
 		err = exportfs(path, &export);
 	}
@@ -1963,20 +1937,7 @@
 	if (err < 0) {
 		err = SA_SYSTEM_ERR;
 		switch (errno) {
-		case EREMOTE:
-			(void) printf(dgettext(TEXT_DOMAIN,
-			    "NFS: Cannot share filesystems "
-			    "in non-global zones: %s\n"), path);
-			err = SA_NOT_SUPPORTED;
-			break;
 		case EPERM:
-			if (getzoneid() != GLOBAL_ZONEID) {
-				(void) printf(dgettext(TEXT_DOMAIN,
-				    "NFS: Cannot share file systems "
-				    "in non-global zones: %s\n"), path);
-				err = SA_NOT_SUPPORTED;
-				break;
-			}
 			err = SA_NO_PERMISSION;
 			break;
 		case EEXIST:
@@ -1994,18 +1955,19 @@
 
 	if (err == SA_OK) {
 		/*
-		 * enable services as needed. This should probably be
-		 * done elsewhere in order to minimize the calls to
-		 * check services.
+		 * Enable services, if required.
+		 * This is only done the first time the function is called,
+		 * per instatiation of the library.
 		 */
+		if (check_services) {
+			_check_services(service_list_default);
+			check_services = B_FALSE;
+		}
+
 		/*
-		 * check to see if logging and other services need to
-		 * be triggered, but only if there wasn't an
-		 * error. This is probably where sharetab should be
-		 * updated with the NFS specific entry.
+		 * Enable logging.
 		 */
 		if (export.ex_flags & EX_LOG) {
-			/* enable logging */
 			if (nfslogtab_add(path, export.ex_log_buffer,
 			    export.ex_tag) != 0) {
 				(void) fprintf(stderr, dgettext(TEXT_DOMAIN,
@@ -2019,7 +1981,6 @@
 			 * not be thre, but that doesn't matter.
 			 */
 			(void) nfslogtab_deactivate(path);
-			_check_services(service_list_default);
 		}
 	}
 
@@ -2088,9 +2049,6 @@
 		case EPERM:
 		case EACCES:
 			ret = SA_NO_PERMISSION;
-			if (getzoneid() != GLOBAL_ZONEID) {
-				ret = SA_NOT_SUPPORTED;
-			}
 			break;
 		case EINVAL:
 		case ENOENT:
