--- old/usr/src/uts/common/fs/sharefs/sharefs_vnops.c	Mon Feb  3 11:23:30 2020
+++ new/usr/src/uts/common/fs/sharefs/sharefs_vnops.c	Mon Feb  3 11:23:30 2020
@@ -24,6 +24,10 @@
  * Use is subject to license terms.
  */
 
+/*
+ * Copyright 2018 Nexenta Systems, Inc.
+ */
+
 #include <fs/fs_subr.h>
 
 #include <sys/errno.h>
@@ -45,7 +49,7 @@
  * the shares enumerated.
  */
 static int
-sharefs_snap_create(shnode_t *sft)
+sharefs_snap_create(sharetab_globals_t *sg, shnode_t *sft)
 {
 	sharetab_t		*sht;
 	share_t			*sh;
@@ -53,16 +57,16 @@
 	int			iCount = 0;
 	char			*buf;
 
-	rw_enter(&sharefs_lock, RW_WRITER);
-	rw_enter(&sharetab_lock, RW_READER);
+	rw_enter(&sg->sharefs_lock, RW_WRITER);
+	rw_enter(&sg->sharetab_lock, RW_READER);
 
 	if (sft->sharefs_snap) {
 		/*
 		 * Nothing has changed, so no need to grab a new copy!
 		 */
-		if (sft->sharefs_generation == sharetab_generation) {
-			rw_exit(&sharetab_lock);
-			rw_exit(&sharefs_lock);
+		if (sft->sharefs_generation == sg->sharetab_generation) {
+			rw_exit(&sg->sharetab_lock);
+			rw_exit(&sg->sharefs_lock);
 			return (0);
 		}
 
@@ -71,12 +75,12 @@
 		sft->sharefs_snap = NULL;
 	}
 
-	sft->sharefs_size = sharetab_size;
-	sft->sharefs_count = sharetab_count;
+	sft->sharefs_size = sg->sharetab_size;
+	sft->sharefs_count = sg->sharetab_count;
 
 	if (sft->sharefs_size == 0) {
-		rw_exit(&sharetab_lock);
-		rw_exit(&sharefs_lock);
+		rw_exit(&sg->sharetab_lock);
+		rw_exit(&sg->sharefs_lock);
 		return (0);
 	}
 
@@ -87,7 +91,7 @@
 	/*
 	 * Walk the Sharetab, dumping each entry.
 	 */
-	for (sht = sharefs_sharetab; sht != NULL; sht = sht->s_next) {
+	for (sht = sg->sharefs_sharetab; sht != NULL; sht = sht->s_next) {
 		int	i;
 
 		for (i = 0; i < SHARETAB_HASHES; i++) {
@@ -132,14 +136,14 @@
 	 * We want to record the generation number and
 	 * mtime inside this snapshot.
 	 */
-	gethrestime(&sharetab_snap_time);
-	sft->sharefs_snap_time = sharetab_snap_time;
-	sft->sharefs_generation = sharetab_generation;
+	gethrestime(&sg->sharetab_snap_time);
+	sft->sharefs_snap_time = sg->sharetab_snap_time;
+	sft->sharefs_generation = sg->sharetab_generation;
 
 	ASSERT(iCount == sft->sharefs_count);
 
-	rw_exit(&sharetab_lock);
-	rw_exit(&sharefs_lock);
+	rw_exit(&sg->sharetab_lock);
+	rw_exit(&sg->sharefs_lock);
 	return (0);
 
 error_fault:
@@ -148,8 +152,8 @@
 	sft->sharefs_size = 0;
 	sft->sharefs_count = 0;
 	sft->sharefs_snap = NULL;
-	rw_exit(&sharetab_lock);
-	rw_exit(&sharefs_lock);
+	rw_exit(&sg->sharetab_lock);
+	rw_exit(&sg->sharefs_lock);
 
 	return (EFAULT);
 }
@@ -161,6 +165,7 @@
 {
 	timestruc_t	now;
 	shnode_t	*sft = VTOSH(vp);
+	sharetab_globals_t *sg = sharetab_get_globals(vp->v_vfsp->vfs_zone);
 
 	vap->va_type = VREG;
 	vap->va_mode = S_IRUSR | S_IRGRP | S_IROTH;
@@ -167,7 +172,7 @@
 	vap->va_nodeid = SHAREFS_INO_FILE;
 	vap->va_nlink = 1;
 
-	rw_enter(&sharefs_lock, RW_READER);
+	rw_enter(&sg->sharefs_lock, RW_READER);
 
 	/*
 	 * If we get asked about a snapped vnode, then
@@ -177,15 +182,15 @@
 	 * sharetab.
 	 */
 	if (sft->sharefs_real_vp) {
-		rw_enter(&sharetab_lock, RW_READER);
-		vap->va_size = sharetab_size;
-		vap->va_mtime = sharetab_mtime;
-		rw_exit(&sharetab_lock);
+		rw_enter(&sg->sharetab_lock, RW_READER);
+		vap->va_size = sg->sharetab_size;
+		vap->va_mtime = sg->sharetab_mtime;
+		rw_exit(&sg->sharetab_lock);
 	} else {
 		vap->va_size = sft->sharefs_size;
 		vap->va_mtime = sft->sharefs_snap_time;
 	}
-	rw_exit(&sharefs_lock);
+	rw_exit(&sg->sharefs_lock);
 
 	gethrestime(&now);
 	vap->va_atime = vap->va_ctime = now;
@@ -259,7 +264,8 @@
 	 * are dumping an extremely huge sharetab, we make a copy
 	 * of it here and use it to dump instead.
 	 */
-	error = sharefs_snap_create(sft);
+	error = sharefs_snap_create(sharetab_get_globals(vp->v_vfsp->vfs_zone),
+	    sft);
 
 	return (error);
 }
@@ -270,11 +276,12 @@
     offset_t off, cred_t *cr, caller_context_t *ct)
 {
 	shnode_t	*sft = VTOSH(vp);
+	sharetab_globals_t *sg = sharetab_get_globals(vp->v_vfsp->vfs_zone);
 
 	if (count > 1)
 		return (0);
 
-	rw_enter(&sharefs_lock, RW_WRITER);
+	rw_enter(&sg->sharefs_lock, RW_WRITER);
 	if (vp->v_count == 1) {
 		if (sft->sharefs_snap != NULL) {
 			kmem_free(sft->sharefs_snap, sft->sharefs_size + 1);
@@ -284,7 +291,7 @@
 		}
 	}
 	atomic_dec_32(&sft->sharefs_refs);
-	rw_exit(&sharefs_lock);
+	rw_exit(&sg->sharefs_lock);
 
 	return (0);
 }
@@ -292,30 +299,31 @@
 /* ARGSUSED */
 static int
 sharefs_read(vnode_t *vp, uio_t *uio, int ioflag, cred_t *cr,
-			caller_context_t *ct)
+    caller_context_t *ct)
 {
 	shnode_t	*sft = VTOSH(vp);
 	off_t		off = uio->uio_offset;
 	size_t		len = uio->uio_resid;
 	int		error = 0;
+	sharetab_globals_t *sg = sharetab_get_globals(vp->v_vfsp->vfs_zone);
 
-	rw_enter(&sharefs_lock, RW_READER);
+	rw_enter(&sg->sharefs_lock, RW_READER);
 
 	/*
 	 * First check to see if we need to grab a new snapshot.
 	 */
 	if (off == (off_t)0) {
-		rw_exit(&sharefs_lock);
-		error = sharefs_snap_create(sft);
+		rw_exit(&sg->sharefs_lock);
+		error = sharefs_snap_create(sg, sft);
 		if (error) {
 			return (EFAULT);
 		}
-		rw_enter(&sharefs_lock, RW_READER);
+		rw_enter(&sg->sharefs_lock, RW_READER);
 	}
 
 	/* LINTED */
 	if (len <= 0 || off >= sft->sharefs_size) {
-		rw_exit(&sharefs_lock);
+		rw_exit(&sg->sharefs_lock);
 		return (error);
 	}
 
@@ -323,7 +331,7 @@
 		len = sft->sharefs_size - off;
 
 	if (off < 0 || len > sft->sharefs_size) {
-		rw_exit(&sharefs_lock);
+		rw_exit(&sg->sharefs_lock);
 		return (EFAULT);
 	}
 
@@ -332,7 +340,7 @@
 		    len, UIO_READ, uio);
 	}
 
-	rw_exit(&sharefs_lock);
+	rw_exit(&sg->sharefs_lock);
 	return (error);
 }
 
@@ -342,16 +350,17 @@
 {
 	gfs_file_t	*fp = vp->v_data;
 	shnode_t	*sft;
+	sharetab_globals_t *sg = sharetab_get_globals(vp->v_vfsp->vfs_zone);
 
 	sft = (shnode_t *)gfs_file_inactive(vp);
 	if (sft) {
-		rw_enter(&sharefs_lock, RW_WRITER);
+		rw_enter(&sg->sharefs_lock, RW_WRITER);
 		if (sft->sharefs_snap != NULL) {
 			kmem_free(sft->sharefs_snap, sft->sharefs_size + 1);
 		}
 
 		kmem_free(sft, fp->gfs_size);
-		rw_exit(&sharefs_lock);
+		rw_exit(&sg->sharefs_lock);
 	}
 }
 
