--- old/usr/src/uts/common/io/fibre-channel/ulp/fcp.c	Mon Aug  5 17:28:47 2019
+++ new/usr/src/uts/common/io/fibre-channel/ulp/fcp.c	Mon Aug  5 17:28:47 2019
@@ -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>
 
@@ -3866,6 +3872,8 @@
 
 		if (cmd == DEVCTL_DEVICE_REMOVE) {
 			flag = NDI_DEVI_REMOVE;
+			if (is_mpxio)
+				flag |= NDI_USER_REQ;
 		}
 
 		if (is_mpxio) {
@@ -8151,8 +8159,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 +8198,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);
 	}
@@ -13070,15 +13037,10 @@
 
 	(void) snprintf(uaddr, MAXNAMELEN, "w%s,%x", buf, plun->lun_num);
 
-	if (plun->lun_old_guid) {
-		if (mdi_pi_find(pdip, plun->lun_old_guid, uaddr) == pip) {
-			rval = FC_SUCCESS;
-		}
-	} else {
-		if (mdi_pi_find(pdip, plun->lun_guid, uaddr) == pip) {
-			rval = FC_SUCCESS;
-		}
+	if (mdi_pi_find(pdip, NULL, uaddr) == pip) {
+		rval = FC_SUCCESS;
 	}
+
 	return (rval);
 }
 
@@ -13312,7 +13274,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,
@@ -13331,7 +13293,7 @@
 		mdi_hold_path(PIP(cip));
 		mdi_devi_exit_phci(pptr->port_dip, *circ);
 
-		rval = mdi_pi_offline(PIP(cip), flags);
+		rval = mdi_pi_offline(PIP(cip), flags & ~NDI_DEVI_REMOVE);
 
 		mdi_devi_enter_phci(pptr->port_dip, circ);
 		mdi_rele_path(PIP(cip));
@@ -13431,8 +13393,8 @@
 			mutex_exit(&plun->lun_tgt->tgt_mutex);
 			mutex_exit(&plun->lun_tgt->tgt_port->port_mutex);
 
-			mdi_devi_enter(
-			    plun->lun_tgt->tgt_port->port_dip, &circ);
+			mdi_devi_enter(plun->lun_tgt->tgt_port->port_dip,
+			    &circ);
 
 			/*
 			 * Exit phci to avoid deadlock with power management
@@ -13439,16 +13401,14 @@
 			 * code during mdi_pi_offline
 			 */
 			mdi_hold_path(PIP(cip));
-			mdi_devi_exit_phci(
-			    plun->lun_tgt->tgt_port->port_dip, circ);
-			(void) mdi_pi_offline(PIP(cip),
-			    NDI_DEVI_REMOVE);
-			mdi_devi_enter_phci(
-			    plun->lun_tgt->tgt_port->port_dip, &circ);
+			mdi_devi_exit_phci(plun->lun_tgt->tgt_port->port_dip,
+			    circ);
+			(void) mdi_pi_offline(PIP(cip), 0);
+			mdi_devi_enter_phci(plun->lun_tgt->tgt_port->port_dip,
+			    &circ);
 			mdi_rele_path(PIP(cip));
 
-			mdi_devi_exit(
-			    plun->lun_tgt->tgt_port->port_dip, circ);
+			mdi_devi_exit(plun->lun_tgt->tgt_port->port_dip, circ);
 
 			FCP_TRACE(fcp_logq,
 			    plun->lun_tgt->tgt_port->port_instbuf,
