--- old/usr/src/uts/common/io/fibre-channel/ulp/fcp.c	Fri Aug  3 23:09:54 2018
+++ new/usr/src/uts/common/io/fibre-channel/ulp/fcp.c	Fri Aug  3 23:09:54 2018
@@ -18,9 +18,16 @@
  *
  * CDDL HEADER END
  */
+
 /*
  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
- *
+ */
+
+/*
+ * Copyright 2018 Nexenta Systems, Inc.
+ */
+
+/*
  * Fibre Channel SCSI ULP Mapping driver
  */
 
@@ -40,7 +47,6 @@
 #include <sys/scsi/impl/scsi_reset_notify.h>
 #include <sys/ndi_impldefs.h>
 #include <sys/byteorder.h>
-#include <sys/fs/dv_node.h>
 #include <sys/ctype.h>
 #include <sys/sunmdi.h>
 
@@ -8151,8 +8157,6 @@
 	child_info_t		*ccip;
 	struct fcp_port		*pptr = plun->lun_tgt->tgt_port;
 	int			is_mpxio = pptr->port_mpxio;
-	dev_info_t		*cdip, *pdip;
-	char			*devname;
 
 	if ((old_mpxio != 0) && (plun->lun_mpxio != old_mpxio)) {
 		/*
@@ -8192,45 +8196,6 @@
 		return (rval);
 	}
 
-	/*
-	 * Explicit devfs_clean() due to ndi_devi_offline() not
-	 * executing devfs_clean() if parent lock is held.
-	 */
-	ASSERT(!servicing_interrupt());
-	if (online == FCP_OFFLINE) {
-		if (plun->lun_mpxio == 0) {
-			if (plun->lun_cip == cip) {
-				cdip = DIP(plun->lun_cip);
-			} else {
-				cdip = DIP(cip);
-			}
-		} else if ((plun->lun_cip == cip) && plun->lun_cip) {
-			cdip = mdi_pi_get_client(PIP(plun->lun_cip));
-		} else if ((plun->lun_cip != cip) && cip) {
-			/*
-			 * This means a DTYPE/GUID change, we shall get the
-			 * dip of the old cip instead of the current lun_cip.
-			 */
-			cdip = mdi_pi_get_client(PIP(cip));
-		}
-		if (cdip) {
-			if (i_ddi_devi_attached(cdip)) {
-				pdip = ddi_get_parent(cdip);
-				devname = kmem_alloc(MAXNAMELEN + 1, KM_SLEEP);
-				ndi_devi_enter(pdip, &circ);
-				(void) ddi_deviname(cdip, devname);
-				/*
-				 * Release parent lock before calling
-				 * devfs_clean().
-				 */
-				ndi_devi_exit(pdip, circ);
-				(void) devfs_clean(pdip, devname + 1,
-				    DV_CLEAN_FORCE);
-				kmem_free(devname, MAXNAMELEN + 1);
-			}
-		}
-	}
-
 	if (fc_ulp_busy_port(pptr->port_fp_handle) != 0) {
 		return (NDI_FAILURE);
 	}
@@ -13312,7 +13277,7 @@
 		cdip = DIP(cip);
 		mutex_exit(&plun->lun_mutex);
 		mutex_exit(&pptr->port_mutex);
-		rval = ndi_devi_offline(DIP(cip), flags);
+		rval = ndi_devi_offline(DIP(cip), NDI_DEVFS_CLEAN | flags);
 		if (rval != NDI_SUCCESS) {
 			FCP_TRACE(fcp_logq, pptr->port_instbuf,
 			    fcp_trace, FCP_BUF_LEVEL_3, 0,
--- old/usr/src/uts/common/io/mr_sas/mr_sas.c	Fri Aug  3 23:09:56 2018
+++ new/usr/src/uts/common/io/mr_sas/mr_sas.c	Fri Aug  3 23:09:56 2018
@@ -44,7 +44,7 @@
 /*
  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2011 Bayard G. Bell. All rights reserved.
- * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
+ * Copyright 2018 Nexenta Systems, Inc.
  * Copyright 2015, 2017 Citrus IT Limited. All rights reserved.
  * Copyright 2015 Garrett D'Amore <garrett@damore.org>
  */
@@ -70,7 +70,6 @@
 #include <sys/signal.h>
 #include <sys/byteorder.h>
 #include <sys/sdt.h>
-#include <sys/fs/dv_node.h>	/* devfs_clean */
 
 #include "mr_sas.h"
 
@@ -7742,9 +7741,8 @@
 mrsas_issue_evt_taskq(struct mrsas_eventinfo *mrevt)
 {
 	struct mrsas_instance *instance = mrevt->instance;
-	dev_info_t *dip, *pdip;
+	dev_info_t *dip;
 	int circ1 = 0;
-	char *devname;
 
 	con_log(CL_ANN1, (CE_NOTE, "mrsas_issue_evt_taskq: called for"
 	    " tgt %d lun %d event %d",
@@ -7765,7 +7763,6 @@
 	switch (mrevt->event) {
 	case MRSAS_EVT_CONFIG_TGT:
 		if (dip == NULL) {
-
 			if (mrevt->lun == 0) {
 				(void) mrsas_config_ld(instance, mrevt->tgt,
 				    0, NULL);
@@ -7778,7 +7775,6 @@
 			    "mr_sas: EVT_CONFIG_TGT called:"
 			    " for tgt %d lun %d event %d",
 			    mrevt->tgt, mrevt->lun, mrevt->event));
-
 		} else {
 			con_log(CL_ANN1, (CE_NOTE,
 			    "mr_sas: EVT_CONFIG_TGT dip != NULL:"
@@ -7788,18 +7784,8 @@
 		break;
 	case MRSAS_EVT_UNCONFIG_TGT:
 		if (dip) {
-			if (i_ddi_devi_attached(dip)) {
-
-				pdip = ddi_get_parent(dip);
-
-				devname = kmem_zalloc(MAXNAMELEN + 1, KM_SLEEP);
-				(void) ddi_deviname(dip, devname);
-
-				(void) devfs_clean(pdip, devname + 1,
-				    DV_CLEAN_FORCE);
-				kmem_free(devname, MAXNAMELEN + 1);
-			}
-			(void) ndi_devi_offline(dip, NDI_DEVI_REMOVE);
+			(void) ndi_devi_offline(dip,
+			    NDI_DEVFS_CLEAN | NDI_DEVI_REMOVE);
 			con_log(CL_ANN1, (CE_NOTE,
 			    "mr_sas: EVT_UNCONFIG_TGT called:"
 			    " for tgt %d lun %d event %d",
--- old/usr/src/uts/common/io/scsi/adapters/iscsi/iscsi_lun.c	Fri Aug  3 23:09:58 2018
+++ new/usr/src/uts/common/io/scsi/adapters/iscsi/iscsi_lun.c	Fri Aug  3 23:09:58 2018
@@ -18,15 +18,22 @@
  *
  * CDDL HEADER END
  */
+
 /*
  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  *
+ */
+
+/*
+ * Copyright 2018 Nexenta Systems, Inc.
+ */
+
+/*
  * iSCSI logical unit interfaces
  */
 
 #include "iscsi.h"
-#include <sys/fs/dv_node.h>	/* devfs_clean */
 #include <sys/bootprops.h>
 #include <sys/sysevent/eventdefs.h>
 #include <sys/sysevent/dev.h>
@@ -641,10 +648,8 @@
 {
 	iscsi_status_t		status		= ISCSI_STATUS_SUCCESS;
 	int			circ		= 0;
-	dev_info_t		*cdip, *pdip;
-	char			*devname	= NULL;
+	dev_info_t		*cdip;
 	char			*pathname	= NULL;
-	int			rval;
 	boolean_t		offline		= B_FALSE;
 	nvlist_t		*attr_list	= NULL;
 
@@ -651,47 +656,11 @@
 	ASSERT(ilp != NULL);
 	ASSERT((ilp->lun_pip != NULL) || (ilp->lun_dip != NULL));
 
-	/*
-	 * Since we carry the logical units parent
-	 * lock across the offline call it will not
-	 * issue devfs_clean() and may fail with a
-	 * devi_ref count > 0.
-	 */
-	if (ilp->lun_pip == NULL) {
+	if (ilp->lun_pip == NULL)
 		cdip = ilp->lun_dip;
-	} else {
+	else
 		cdip = mdi_pi_get_client(ilp->lun_pip);
-	}
 
-	if ((cdip != NULL) &&
-	    (lun_free == B_TRUE) &&
-	    (ilp->lun_state & ISCSI_LUN_STATE_ONLINE)) {
-		/*
-		 * Make sure node is attached otherwise
-		 * it won't have related cache nodes to
-		 * clean up.  i_ddi_devi_attached is
-		 * similiar to i_ddi_node_state(cdip) >=
-		 * DS_ATTACHED. We should clean up only
-		 * when lun_free is set.
-		 */
-		if (i_ddi_devi_attached(cdip)) {
-
-			/* Get parent dip */
-			pdip = ddi_get_parent(cdip);
-
-			/* Get full devname */
-			devname = kmem_alloc(MAXNAMELEN + 1, KM_SLEEP);
-			ndi_devi_enter(pdip, &circ);
-			(void) ddi_deviname(cdip, devname);
-			/* Release lock before devfs_clean() */
-			ndi_devi_exit(pdip, circ);
-
-			/* Clean cache */
-			(void) devfs_clean(pdip, devname + 1, DV_CLEAN_FORCE);
-			kmem_free(devname, MAXNAMELEN + 1);
-		}
-	}
-
 	if (cdip != NULL && ilp->lun_type == DTYPE_DIRECT) {
 		pathname = kmem_zalloc(MAXNAMELEN + 1, KM_SLEEP);
 		(void) ddi_pathname(cdip, pathname);
@@ -699,18 +668,9 @@
 
 	/* Attempt to offline the logical units */
 	if (ilp->lun_pip != NULL) {
-
 		/* virt/mdi */
 		ndi_devi_enter(scsi_vhci_dip, &circ);
-		if ((lun_free == B_TRUE) &&
-		    (ilp->lun_state & ISCSI_LUN_STATE_ONLINE)) {
-			rval = mdi_pi_offline(ilp->lun_pip,
-			    NDI_DEVI_REMOVE);
-		} else {
-			rval = mdi_pi_offline(ilp->lun_pip, 0);
-		}
-
-		if (rval == MDI_SUCCESS) {
+		if (mdi_pi_offline(ilp->lun_pip, 0) == MDI_SUCCESS) {
 			ilp->lun_state &= ISCSI_LUN_STATE_CLEAR;
 			ilp->lun_state |= ISCSI_LUN_STATE_OFFLINE;
 			if (lun_free == B_TRUE) {
@@ -728,18 +688,14 @@
 		ndi_devi_exit(scsi_vhci_dip, circ);
 
 	} else  {
-
 		/* phys/ndi */
+		int flags = NDI_DEVFS_CLEAN;
+
 		ndi_devi_enter(ihp->hba_dip, &circ);
-		if ((lun_free == B_TRUE) &&
-		    (ilp->lun_state & ISCSI_LUN_STATE_ONLINE)) {
-			rval = ndi_devi_offline(
-			    ilp->lun_dip, NDI_DEVI_REMOVE);
-		} else {
-			rval = ndi_devi_offline(
-			    ilp->lun_dip, 0);
-		}
-		if (rval != NDI_SUCCESS) {
+		if (lun_free == B_TRUE &&
+		    (ilp->lun_state & ISCSI_LUN_STATE_ONLINE))
+			flags |= NDI_DEVI_REMOVE;
+		if (ndi_devi_offline(ilp->lun_dip, flags) != NDI_SUCCESS) {
 			status = ISCSI_STATUS_BUSY;
 			if (lun_free == B_FALSE) {
 				ilp->lun_state |= ISCSI_LUN_STATE_INVALID;
--- old/usr/src/uts/common/io/scsi/adapters/mpt_sas/mptsas.c	Fri Aug  3 23:09:58 2018
+++ new/usr/src/uts/common/io/scsi/adapters/mpt_sas/mptsas.c	Fri Aug  3 23:09:58 2018
@@ -102,8 +102,6 @@
 #include <sys/scsi/adapters/mpt_sas/mptsas_hash.h>
 #include <sys/raidioctl.h>
 
-#include <sys/fs/dv_node.h>	/* devfs_clean */
-
 /*
  * FMA header files
  */
@@ -397,13 +395,11 @@
 
 static void mptsas_offline_missed_luns(dev_info_t *pdip,
     uint16_t *repluns, int lun_cnt, mptsas_target_t *ptgt);
-static int mptsas_offline_lun(dev_info_t *pdip, dev_info_t *rdip,
-    mdi_pathinfo_t *rpip, uint_t flags);
+static int mptsas_offline_lun(dev_info_t *rdip, mdi_pathinfo_t *rpip);
 
 static int mptsas_config_smp(dev_info_t *pdip, uint64_t sas_wwn,
     dev_info_t **smp_dip);
-static int mptsas_offline_smp(dev_info_t *pdip, mptsas_smp_t *smp_node,
-    uint_t flags);
+static int mptsas_offline_smp(dev_info_t *pdip, mptsas_smp_t *smp_node);
 
 static int mptsas_event_query(mptsas_t *mpt, mptsas_event_query_t *data,
     int mode, int *rval);
@@ -6891,7 +6887,7 @@
 		mutex_exit(&mpt->m_mutex);
 
 		ndi_devi_enter(parent, &circ1);
-		rval = mptsas_offline_smp(parent, psmp, NDI_DEVI_REMOVE);
+		rval = mptsas_offline_smp(parent, psmp);
 		ndi_devi_exit(parent, circ1);
 
 		dev_info = psmp->m_deviceinfo;
@@ -14693,8 +14689,7 @@
 			/*
 			 * The lun has not been there already
 			 */
-			(void) mptsas_offline_lun(pdip, savechild, NULL,
-			    NDI_DEVI_REMOVE);
+			(void) mptsas_offline_lun(savechild, NULL);
 		}
 	}
 
@@ -14730,8 +14725,7 @@
 			/*
 			 * The lun has not been there already
 			 */
-			(void) mptsas_offline_lun(pdip, NULL, savepip,
-			    NDI_DEVI_REMOVE);
+			(void) mptsas_offline_lun(NULL, savepip);
 		}
 	}
 }
@@ -15025,8 +15019,7 @@
 			continue;
 		}
 
-		tmp_rval = mptsas_offline_lun(pdip, prechild, NULL,
-		    NDI_DEVI_REMOVE);
+		tmp_rval = mptsas_offline_lun(prechild, NULL);
 		if (tmp_rval != DDI_SUCCESS) {
 			rval = DDI_FAILURE;
 			if (ndi_prop_create_boolean(DDI_DEV_T_NONE,
@@ -15058,8 +15051,7 @@
 			continue;
 		}
 
-		(void) mptsas_offline_lun(pdip, NULL, savepip,
-		    NDI_DEVI_REMOVE);
+		(void) mptsas_offline_lun(NULL, savepip);
 		/*
 		 * driver will not invoke mdi_pi_free, so path will not
 		 * be freed forever, return DDI_FAILURE.
@@ -15070,48 +15062,19 @@
 }
 
 static int
-mptsas_offline_lun(dev_info_t *pdip, dev_info_t *rdip,
-    mdi_pathinfo_t *rpip, uint_t flags)
+mptsas_offline_lun(dev_info_t *rdip, mdi_pathinfo_t *rpip)
 {
 	int		rval = DDI_FAILURE;
-	char		*devname;
-	dev_info_t	*cdip, *parent;
 
 	if (rpip != NULL) {
-		parent = scsi_vhci_dip;
-		cdip = mdi_pi_get_client(rpip);
-	} else if (rdip != NULL) {
-		parent = pdip;
-		cdip = rdip;
-	} else {
-		return (DDI_FAILURE);
-	}
-
-	/*
-	 * Make sure node is attached otherwise
-	 * it won't have related cache nodes to
-	 * clean up.  i_ddi_devi_attached is
-	 * similiar to i_ddi_node_state(cdip) >=
-	 * DS_ATTACHED.
-	 */
-	if (i_ddi_devi_attached(cdip)) {
-
-		/* Get full devname */
-		devname = kmem_alloc(MAXNAMELEN + 1, KM_SLEEP);
-		(void) ddi_deviname(cdip, devname);
-		/* Clean cache */
-		(void) devfs_clean(parent, devname + 1,
-		    DV_CLEAN_FORCE);
-		kmem_free(devname, MAXNAMELEN + 1);
-	}
-	if (rpip != NULL) {
 		if (MDI_PI_IS_OFFLINE(rpip)) {
 			rval = DDI_SUCCESS;
 		} else {
 			rval = mdi_pi_offline(rpip, 0);
 		}
-	} else {
-		rval = ndi_devi_offline(cdip, flags);
+	} else if (rdip != NULL) {
+		rval = ndi_devi_offline(rdip,
+		    NDI_DEVFS_CLEAN | NDI_DEVI_REMOVE);
 	}
 
 	return (rval);
@@ -15143,10 +15106,9 @@
 }
 
 static int
-mptsas_offline_smp(dev_info_t *pdip, mptsas_smp_t *smp_node, uint_t flags)
+mptsas_offline_smp(dev_info_t *pdip, mptsas_smp_t *smp_node)
 {
 	int		rval = DDI_FAILURE;
-	char		*devname;
 	char		wwn_str[MPTSAS_WWN_STRLEN];
 	dev_info_t	*cdip;
 
@@ -15153,30 +15115,11 @@
 	(void) sprintf(wwn_str, "%"PRIx64, smp_node->m_addr.mta_wwn);
 
 	cdip = mptsas_find_smp_child(pdip, wwn_str);
-
 	if (cdip == NULL)
 		return (DDI_SUCCESS);
 
-	/*
-	 * Make sure node is attached otherwise
-	 * it won't have related cache nodes to
-	 * clean up.  i_ddi_devi_attached is
-	 * similiar to i_ddi_node_state(cdip) >=
-	 * DS_ATTACHED.
-	 */
-	if (i_ddi_devi_attached(cdip)) {
+	rval = ndi_devi_offline(cdip, NDI_DEVFS_CLEAN | NDI_DEVI_REMOVE);
 
-		/* Get full devname */
-		devname = kmem_alloc(MAXNAMELEN + 1, KM_SLEEP);
-		(void) ddi_deviname(cdip, devname);
-		/* Clean cache */
-		(void) devfs_clean(pdip, devname + 1,
-		    DV_CLEAN_FORCE);
-		kmem_free(devname, MAXNAMELEN + 1);
-	}
-
-	rval = ndi_devi_offline(cdip, flags);
-
 	return (rval);
 }
 
--- old/usr/src/uts/common/os/sunmdi.c	Fri Aug  3 23:10:00 2018
+++ new/usr/src/uts/common/os/sunmdi.c	Fri Aug  3 23:10:00 2018
@@ -18,6 +18,7 @@
  *
  * CDDL HEADER END
  */
+
 /*
  * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2014 Nexenta Systems Inc. All rights reserved.
@@ -26,16 +27,6 @@
 /*
  * Multipath driver interface (MDI) implementation; see mdi_impldefs.h for a
  * more detailed discussion of the overall mpxio architecture.
- *
- * Default locking order:
- *
- * _NOTE(LOCK_ORDER(mdi_mutex, mdi_vhci:vh_phci_mutex);
- * _NOTE(LOCK_ORDER(mdi_mutex, mdi_vhci:vh_client_mutex);
- * _NOTE(LOCK_ORDER(mdi_vhci:vh_phci_mutex, mdi_phci::ph_mutex);
- * _NOTE(LOCK_ORDER(mdi_vhci:vh_client_mutex, mdi_client::ct_mutex);
- * _NOTE(LOCK_ORDER(mdi_phci::ph_mutex mdi_pathinfo::pi_mutex))
- * _NOTE(LOCK_ORDER(mdi_phci::ph_mutex mdi_client::ct_mutex))
- * _NOTE(LOCK_ORDER(mdi_client::ct_mutex mdi_pathinfo::pi_mutex))
  */
 
 #include <sys/note.h>
@@ -3670,26 +3661,24 @@
 				 * This is the last path case for
 				 * non-user initiated events.
 				 */
-				if (((flag & NDI_USER_REQ) == 0) &&
-				    cdip && (i_ddi_node_state(cdip) >=
-				    DS_INITIALIZED)) {
-					MDI_CLIENT_UNLOCK(ct);
-					rv = ndi_devi_offline(cdip,
-					    NDI_DEVFS_CLEAN);
-					MDI_CLIENT_LOCK(ct);
+				if ((flag & NDI_USER_REQ) ||
+				    cdip == NULL || i_ddi_node_state(cdip) <
+				    DS_INITIALIZED)
+					break;
 
-					if (rv != NDI_SUCCESS) {
-						/*
-						 * ndi_devi_offline failed.
-						 * Reset client flags to
-						 * online as the path could not
-						 * be offlined.
-						 */
-						MDI_DEBUG(1, (MDI_WARN, cdip,
-						    "!ndi_devi_offline failed: "
-						    "error %x", rv));
-						MDI_CLIENT_SET_ONLINE(ct);
-					}
+				MDI_CLIENT_UNLOCK(ct);
+				rv = ndi_devi_offline(cdip, NDI_DEVFS_CLEAN);
+				MDI_CLIENT_LOCK(ct);
+
+				if (rv != NDI_SUCCESS) {
+					/*
+					 * Reset client flags to online as the
+					 * path could not be offlined.
+					 */
+					MDI_DEBUG(1, (MDI_WARN, cdip,
+					    "!ndi_devi_offline failed: %d",
+					    rv));
+					MDI_CLIENT_SET_ONLINE(ct);
 				}
 				break;
 			}
--- old/usr/src/uts/intel/io/scsi/adapters/pvscsi/pvscsi.c	Fri Aug  3 23:10:01 2018
+++ new/usr/src/uts/intel/io/scsi/adapters/pvscsi/pvscsi.c	Fri Aug  3 23:10:01 2018
@@ -10,7 +10,7 @@
  */
 
 /*
- * Copyright 2016 Nexenta Systems, Inc.
+ * Copyright 2018 Nexenta Systems, Inc.
  */
 
 #include <sys/atomic.h>
@@ -19,7 +19,6 @@
 #include <sys/cpuvar.h>
 #include <sys/ddi.h>
 #include <sys/errno.h>
-#include <sys/fs/dv_node.h>
 #include <sys/kmem.h>
 #include <sys/kmem_impl.h>
 #include <sys/list.h>
@@ -360,20 +359,8 @@
 
 	if (devnode != NULL) {
 		if (inqrc != 0) {
-			/* Target disappeared, drop devnode */
-			if (i_ddi_devi_attached(devnode->pdip)) {
-				char    *devname;
-				/* Get full devname */
-				devname = kmem_alloc(MAXPATHLEN, KM_SLEEP);
-				(void) ddi_deviname(devnode->pdip, devname);
-				/* Clean cache and name */
-				(void) devfs_clean(devnode->parent, devname + 1,
-				    DV_CLEAN_FORCE);
-				kmem_free(devname, MAXPATHLEN);
-			}
-
-			(void) ndi_devi_offline(devnode->pdip, NDI_DEVI_REMOVE);
-
+			(void) ndi_devi_offline(devnode->pdip,
+			    NDI_DEVFS_CLEAN | NDI_DEVI_REMOVE);
 			list_remove(&pvs->devnodes, devnode);
 			kmem_free(devnode, sizeof (*devnode));
 		} else if (childp != NULL) {
--- old/usr/src/uts/intel/mpt_sas/Makefile	Fri Aug  3 23:10:01 2018
+++ new/usr/src/uts/intel/mpt_sas/Makefile	Fri Aug  3 23:10:01 2018
@@ -18,18 +18,16 @@
 #
 # CDDL HEADER END
 #
+
+#
 # Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
-#	This makefile drives the production of the mpt_sas driver kernel module.
-#
-#	intel architecture dependent
-#
 
 #
 #	Paths to the base of the uts directory trees
 #
-UTSBASE   = ../../../../src/uts
+UTSBASE=	$(SRC)/uts
 
 #
 #	Define the module and object file sets.
