--- old/usr/src/uts/common/fs/zfs/vdev_label.c	Mon Aug  5 17:27:07 2019
+++ new/usr/src/uts/common/fs/zfs/vdev_label.c	Mon Aug  5 17:27:07 2019
@@ -21,7 +21,8 @@
 
 /*
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2016 by Delphix. All rights reserved.
+ * Copyright (c) 2012, 2015 by Delphix. All rights reserved.
+ * Copyright 2016 Nexenta Systems, Inc.  All rights reserved.
  */
 
 /*
@@ -143,7 +144,6 @@
 #include <sys/vdev_impl.h>
 #include <sys/uberblock_impl.h>
 #include <sys/metaslab.h>
-#include <sys/metaslab_impl.h>
 #include <sys/zio.h>
 #include <sys/dsl_scan.h>
 #include <sys/abd.h>
@@ -217,7 +217,6 @@
     vdev_config_flag_t flags)
 {
 	nvlist_t *nv = NULL;
-	vdev_indirect_config_t *vic = &vd->vdev_indirect_config;
 
 	nv = fnvlist_alloc();
 
@@ -265,7 +264,7 @@
 		fnvlist_add_uint64(nv, ZPOOL_CONFIG_WHOLE_DISK,
 		    vd->vdev_wholedisk);
 
-	if (vd->vdev_not_present && !(flags & VDEV_CONFIG_MISSING))
+	if (vd->vdev_not_present)
 		fnvlist_add_uint64(nv, ZPOOL_CONFIG_NOT_PRESENT, 1);
 
 	if (vd->vdev_isspare)
@@ -281,32 +280,25 @@
 		fnvlist_add_uint64(nv, ZPOOL_CONFIG_ASIZE,
 		    vd->vdev_asize);
 		fnvlist_add_uint64(nv, ZPOOL_CONFIG_IS_LOG, vd->vdev_islog);
-		if (vd->vdev_removing) {
+		fnvlist_add_uint64(nv, ZPOOL_CONFIG_IS_SPECIAL,
+		    vd->vdev_isspecial);
+		if (vd->vdev_removing)
 			fnvlist_add_uint64(nv, ZPOOL_CONFIG_REMOVING,
 			    vd->vdev_removing);
-		}
 	}
 
+	if (flags & VDEV_CONFIG_L2CACHE)
+		/* indicate that we support L2ARC persistency */
+		VERIFY(nvlist_add_boolean_value(nv,
+		    ZPOOL_CONFIG_L2CACHE_PERSISTENT, B_TRUE) == 0);
+
+	fnvlist_add_boolean_value(nv, ZPOOL_CONFIG_IS_SSD, vd->vdev_is_ssd);
+
 	if (vd->vdev_dtl_sm != NULL) {
 		fnvlist_add_uint64(nv, ZPOOL_CONFIG_DTL,
 		    space_map_object(vd->vdev_dtl_sm));
 	}
 
-	if (vic->vic_mapping_object != 0) {
-		fnvlist_add_uint64(nv, ZPOOL_CONFIG_INDIRECT_OBJECT,
-		    vic->vic_mapping_object);
-	}
-
-	if (vic->vic_births_object != 0) {
-		fnvlist_add_uint64(nv, ZPOOL_CONFIG_INDIRECT_BIRTHS,
-		    vic->vic_births_object);
-	}
-
-	if (vic->vic_prev_indirect_vdev != UINT64_MAX) {
-		fnvlist_add_uint64(nv, ZPOOL_CONFIG_PREV_INDIRECT_VDEV,
-		    vic->vic_prev_indirect_vdev);
-	}
-
 	if (vd->vdev_crtxg)
 		fnvlist_add_uint64(nv, ZPOOL_CONFIG_CREATE_TXG, vd->vdev_crtxg);
 
@@ -326,6 +318,7 @@
 
 	if (getstats) {
 		vdev_stat_t vs;
+		pool_scan_stat_t ps;
 
 		vdev_get_stats(vd, &vs);
 		fnvlist_add_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS,
@@ -332,67 +325,11 @@
 		    (uint64_t *)&vs, sizeof (vs) / sizeof (uint64_t));
 
 		/* provide either current or previous scan information */
-		pool_scan_stat_t ps;
 		if (spa_scan_get_stats(spa, &ps) == 0) {
 			fnvlist_add_uint64_array(nv,
 			    ZPOOL_CONFIG_SCAN_STATS, (uint64_t *)&ps,
 			    sizeof (pool_scan_stat_t) / sizeof (uint64_t));
 		}
-
-		pool_removal_stat_t prs;
-		if (spa_removal_get_stats(spa, &prs) == 0) {
-			fnvlist_add_uint64_array(nv,
-			    ZPOOL_CONFIG_REMOVAL_STATS, (uint64_t *)&prs,
-			    sizeof (prs) / sizeof (uint64_t));
-		}
-
-		/*
-		 * Note: this can be called from open context
-		 * (spa_get_stats()), so we need the rwlock to prevent
-		 * the mapping from being changed by condensing.
-		 */
-		rw_enter(&vd->vdev_indirect_rwlock, RW_READER);
-		if (vd->vdev_indirect_mapping != NULL) {
-			ASSERT(vd->vdev_indirect_births != NULL);
-			vdev_indirect_mapping_t *vim =
-			    vd->vdev_indirect_mapping;
-			fnvlist_add_uint64(nv, ZPOOL_CONFIG_INDIRECT_SIZE,
-			    vdev_indirect_mapping_size(vim));
-		}
-		rw_exit(&vd->vdev_indirect_rwlock);
-		if (vd->vdev_mg != NULL &&
-		    vd->vdev_mg->mg_fragmentation != ZFS_FRAG_INVALID) {
-			/*
-			 * Compute approximately how much memory would be used
-			 * for the indirect mapping if this device were to
-			 * be removed.
-			 *
-			 * Note: If the frag metric is invalid, then not
-			 * enough metaslabs have been converted to have
-			 * histograms.
-			 */
-			uint64_t seg_count = 0;
-
-			/*
-			 * There are the same number of allocated segments
-			 * as free segments, so we will have at least one
-			 * entry per free segment.
-			 */
-			for (int i = 0; i < RANGE_TREE_HISTOGRAM_SIZE; i++) {
-				seg_count += vd->vdev_mg->mg_histogram[i];
-			}
-
-			/*
-			 * The maximum length of a mapping is SPA_MAXBLOCKSIZE,
-			 * so we need at least one entry per SPA_MAXBLOCKSIZE
-			 * of allocated data.
-			 */
-			seg_count += vd->vdev_stat.vs_alloc / SPA_MAXBLOCKSIZE;
-
-			fnvlist_add_uint64(nv, ZPOOL_CONFIG_INDIRECT_SIZE,
-			    seg_count *
-			    sizeof (vdev_indirect_mapping_entry_phys_t));
-		}
 	}
 
 	if (!vd->vdev_ops->vdev_op_leaf) {
@@ -466,6 +403,12 @@
 			fnvlist_add_uint64(nv, ZPOOL_CONFIG_ORIG_GUID,
 			    vd->vdev_orig_guid);
 		}
+
+		/* grab per-leaf-vdev trim stats */
+		if (getstats) {
+			fnvlist_add_uint64(nv, ZPOOL_CONFIG_TRIM_PROG,
+			    vd->vdev_trim_prog);
+		}
 	}
 
 	return (nv);
@@ -489,9 +432,8 @@
 	for (c = 0, idx = 0; c < rvd->vdev_children; c++) {
 		vdev_t *tvd = rvd->vdev_child[c];
 
-		if (tvd->vdev_ishole) {
+		if (tvd->vdev_ishole)
 			array[idx++] = c;
-		}
 	}
 
 	if (idx) {
@@ -1057,20 +999,8 @@
 	 * Search all labels on this vdev to find the configuration that
 	 * matches the txg for our uberblock.
 	 */
-	if (cb.ubl_vd != NULL) {
-		vdev_dbgmsg(cb.ubl_vd, "best uberblock found for spa %s. "
-		    "txg %llu", spa->spa_name, (u_longlong_t)ub->ub_txg);
-
+	if (cb.ubl_vd != NULL)
 		*config = vdev_label_read_config(cb.ubl_vd, ub->ub_txg);
-		if (*config == NULL && spa->spa_extreme_rewind) {
-			vdev_dbgmsg(cb.ubl_vd, "failed to read label config. "
-			    "Trying again without txg restrictions.");
-			*config = vdev_label_read_config(cb.ubl_vd, UINT64_MAX);
-		}
-		if (*config == NULL) {
-			vdev_dbgmsg(cb.ubl_vd, "failed to read label config");
-		}
-	}
 	spa_config_exit(spa, SCL_ALL, FTAG);
 }
 
@@ -1093,7 +1023,7 @@
 static void
 vdev_uberblock_sync(zio_t *zio, uberblock_t *ub, vdev_t *vd, int flags)
 {
-	for (uint64_t c = 0; c < vd->vdev_children; c++)
+	for (int c = 0; c < vd->vdev_children; c++)
 		vdev_uberblock_sync(zio, ub, vd->vdev_child[c], flags);
 
 	if (!vd->vdev_ops->vdev_op_leaf)
@@ -1140,11 +1070,8 @@
 	 */
 	zio = zio_root(spa, NULL, NULL, flags);
 
-	for (int v = 0; v < svdcount; v++) {
-		if (vdev_writeable(svd[v])) {
-			zio_flush(zio, svd[v]);
-		}
-	}
+	for (int v = 0; v < svdcount; v++)
+		zio_flush(zio, svd[v]);
 
 	(void) zio_wait(zio);
 
