--- old/usr/src/uts/common/os/zone.c	2015-04-21 18:19:16.024967514 -0400
+++ new/usr/src/uts/common/os/zone.c	2015-04-21 18:19:16.032739072 -0400
@@ -576,7 +576,7 @@
 {
 	struct zsd_entry *zsd;
 
-	for (zsd = list_head(l); zsd != NULL; zsd = list_next(l, zsd)) {
+	list_for_each(l, zsd) {
 		if (zsd->zsd_key == key) {
 			return (zsd);
 		}
@@ -593,7 +593,7 @@
 {
 	struct zsd_entry *zsd;
 
-	for (zsd = list_head(l); zsd != NULL; zsd = list_next(l, zsd)) {
+	list_for_each(l, zsd) {
 		if (zsd->zsd_key == key) {
 			/*
 			 * Move to head of list to keep list in MRU order.
@@ -638,8 +638,7 @@
 	 * a create callback.
 	 */
 	mutex_enter(&zonehash_lock);	/* stop the world */
-	for (zone = list_head(&zone_active); zone != NULL;
-	    zone = list_next(&zone_active, zone)) {
+	list_for_each(&zone_active, zone) {
 		zone_status_t status;
 
 		mutex_enter(&zone->zone_lock);
@@ -715,8 +714,7 @@
 	mutex_exit(&zsd_key_lock);
 
 	mutex_enter(&zonehash_lock);
-	for (zone = list_head(&zone_active); zone != NULL;
-	    zone = list_next(&zone_active, zone)) {
+	list_for_each(&zone_active, zone) {
 		struct zsd_entry *del;
 
 		mutex_enter(&zone->zone_lock);
@@ -754,8 +752,7 @@
 
 	/* Now we can free up the zsdp structures in each zone */
 	mutex_enter(&zonehash_lock);
-	for (zone = list_head(&zone_active); zone != NULL;
-	    zone = list_next(&zone_active, zone)) {
+	list_for_each(&zone_active, zone) {
 		struct zsd_entry *del;
 
 		mutex_enter(&zone->zone_lock);
@@ -831,8 +828,7 @@
 	ASSERT(list_head(&zone->zone_zsd) == NULL);
 	mutex_enter(&zone->zone_lock);
 	mutex_enter(&zsd_key_lock);
-	for (zsdp = list_head(&zsd_registered_keys); zsdp != NULL;
-	    zsdp = list_next(&zsd_registered_keys, zsdp)) {
+	list_for_each(&zsd_registered_keys, zsdp) {
 		/*
 		 * Since this zone is ZONE_IS_UNCONFIGURED, zone_key_create
 		 * should not have added anything to it.
@@ -876,8 +872,7 @@
 	 * callbacks for a zone that is in the process of going away.
 	 */
 	mutex_enter(&zone->zone_lock);
-	for (t = list_head(&zone->zone_zsd); t != NULL;
-	    t = list_next(&zone->zone_zsd, t)) {
+	list_for_each(&zone->zone_zsd, t) {
 		zone_key_t key = t->zsd_key;
 
 		/* Skip if no callbacks registered */
@@ -919,8 +914,7 @@
 	 * Free all the zsd_entry's we had on this zone.
 	 */
 	mutex_enter(&zone->zone_lock);
-	for (t = list_head(&zone->zone_zsd); t != NULL; t = next) {
-		next = list_next(&zone->zone_zsd, t);
+	list_for_each_safe(&zone->zone_zsd, t, next) {
 		list_remove(&zone->zone_zsd, t);
 		ASSERT(!(t->zsd_flags & ZSD_ALL_INPROGRESS));
 		kmem_free(t, sizeof (*t));
@@ -1301,8 +1295,7 @@
 {
 	zone_dataset_t *t, *next;
 
-	for (t = list_head(&zone->zone_datasets); t != NULL; t = next) {
-		next = list_next(&zone->zone_datasets, t);
+	list_for_each_safe(&zone->zone_datasets, t, next) {
 		list_remove(&zone->zone_datasets, t);
 		kmem_free(t->zd_dataset, strlen(t->zd_dataset) + 1);
 		kmem_free(t, sizeof (*t));
@@ -3039,8 +3032,7 @@
 	}
 	ASSERT(*path == '/');
 	mutex_enter(&zonehash_lock);
-	for (zone = list_head(&zone_active); zone != NULL;
-	    zone = list_next(&zone_active, zone)) {
+	list_for_each(&zone_active, zone) {
 		if (ZONE_PATH_VISIBLE(path, zone))
 			zret = zone;
 	}
@@ -3258,8 +3250,7 @@
 	zone_status_t status;
 
 	mutex_enter(&zonehash_lock);
-	for (zone = list_head(&zone_active); zone != NULL;
-	    zone = list_next(&zone_active, zone)) {
+	list_for_each(&zone_active, zone) {
 		/*
 		 * Skip zones that shouldn't be externally visible.
 		 */
@@ -4050,8 +4041,7 @@
 	    (rootpath[1] == '/') && (rootpath[2] == '\0'))
 		return (B_TRUE);
 
-	for (zone = list_head(&zone_active); zone != NULL;
-	    zone = list_next(&zone_active, zone)) {
+	list_for_each(&zone_active, zone) {
 		if (zone == global_zone)
 			continue;
 		len = strlen(zone->zone_rootpath);
@@ -5732,8 +5722,7 @@
 	 */
 	if (ctp->conp_ninherited != 0) {
 		contract_t *next;
-		for (next = list_head(&ctp->conp_inherited); next;
-		    next = list_next(&ctp->conp_inherited, next)) {
+		list_for_each(&ctp->conp_inherited, next) {
 			if (contract_getzuniqid(next) != zone->zone_uniqid) {
 				mutex_exit(&pp->p_lock);
 				mutex_exit(&ct->ct_lock);
@@ -6091,9 +6080,7 @@
 				zoneids = kmem_alloc(real_nzones *
 				    sizeof (zoneid_t), KM_SLEEP);
 				mybslab = label2bslabel(myzone->zone_slabel);
-				for (zone = list_head(&zone_active);
-				    zone != NULL;
-				    zone = list_next(&zone_active, zone)) {
+				list_for_each(&zone_active, zone) {
 					if (zone->zone_id == GLOBAL_ZONEID)
 						continue;
 					if (zone != myzone &&
@@ -6120,8 +6107,7 @@
 		if (real_nzones > 0) {
 			zoneids = kmem_alloc(real_nzones * sizeof (zoneid_t),
 			    KM_SLEEP);
-			for (zone = list_head(&zone_active); zone != NULL;
-			    zone = list_next(&zone_active, zone))
+			list_for_each(&zone_active, zone)
 				zoneids[domi_nzones++] = zone->zone_id;
 			ASSERT(domi_nzones == real_nzones);
 		}
@@ -6586,8 +6572,7 @@
 	 * fail to boot the new zones when they see that the global zone is
 	 * shutting down.
 	 */
-	for (current_zonep = list_head(&zone_active); current_zonep != NULL;
-	    current_zonep = list_next(&zone_active, current_zonep)) {
+	list_for_each(&zone_active, cpurrent_zonep) {
 		if (zone_status_get(current_zonep) == ZONE_IS_RUNNING)
 			zone_status_set(current_zonep, ZONE_IS_SHUTTING_DOWN);
 	}
@@ -6617,9 +6602,7 @@
 	 * specify a dataset underneath an exported dataset.  If found, return
 	 * true and note that it is writable.
 	 */
-	for (zd = list_head(&zone->zone_datasets); zd != NULL;
-	    zd = list_next(&zone->zone_datasets, zd)) {
-
+	list_for_each(&zone->zone_datasets, zd) {
 		len = strlen(zd->zd_dataset);
 		if (strlen(dataset) >= len &&
 		    bcmp(dataset, zd->zd_dataset, len) == 0 &&
@@ -6638,9 +6621,7 @@
 	 * Note that we also have to support forms such as 'pool/dataset/', with
 	 * a trailing slash.
 	 */
-	for (zd = list_head(&zone->zone_datasets); zd != NULL;
-	    zd = list_next(&zone->zone_datasets, zd)) {
-
+	list_for_each(&zone->zone_dataset, zd) {
 		len = strlen(dataset);
 		if (dataset[len - 1] == '/')
 			len--;	/* Ignore trailing slash */
@@ -6745,8 +6726,7 @@
 	}
 
 	mutex_enter(&zonehash_lock);
-	for (zone = list_head(&zone_active); zone != NULL;
-	    zone = list_next(&zone_active, zone)) {
+	list_for_each(&zone_active, zone) {
 		char	*c;
 		size_t	pathlen;
 		char *rootpath_start;
@@ -6782,8 +6762,7 @@
 	zone_dl_t *zdl;
 
 	ASSERT(mutex_owned(&zone->zone_lock));
-	for (zdl = list_head(&zone->zone_dl_list); zdl != NULL;
-	    zdl = list_next(&zone->zone_dl_list, zdl)) {
+	list_for_each(&zone->zone_dl_list, zdl) {
 		if (zdl->zdl_id == linkid)
 			break;
 	}
@@ -6816,8 +6795,7 @@
 
 	/* Verify that the datalink ID doesn't already belong to a zone. */
 	mutex_enter(&zonehash_lock);
-	for (zone = list_head(&zone_active); zone != NULL;
-	    zone = list_next(&zone_active, zone)) {
+	list_for_each(&zone_active, zone) {
 		if (zone_dl_exists(zone, linkid)) {
 			mutex_exit(&zonehash_lock);
 			zone_rele(thiszone);
@@ -6881,8 +6859,7 @@
 	}
 
 	mutex_enter(&zonehash_lock);
-	for (zone = list_head(&zone_active); zone != NULL;
-	    zone = list_next(&zone_active, zone)) {
+	list_for_each(&zone_active, zone) {
 		if (zone_dl_exists(zone, linkid)) {
 			*zoneidp = zone->zone_id;
 			err = 0;
@@ -6917,8 +6894,7 @@
 
 	num = 0;
 	mutex_enter(&zone->zone_lock);
-	for (zdl = list_head(&zone->zone_dl_list); zdl != NULL;
-	    zdl = list_next(&zone->zone_dl_list, zdl)) {
+	list_for_each(&zone->zone_dl_list, zdl) {
 		/*
 		 * If the list is bigger than what the caller supplied, just
 		 * count, don't do copyout.
@@ -6992,8 +6968,7 @@
 	 * execute the callback with the zone_lock dropped.
 	 */
 	mutex_enter(&zone->zone_lock);
-	for (zdl = list_head(&zone->zone_dl_list); zdl != NULL;
-	    zdl = list_next(&zone->zone_dl_list, zdl)) {
+	list_for_each(&zone->zone_dl_lists, zdl) {
 		idcount++;
 	}
 
@@ -7010,9 +6985,10 @@
 		return (ENOMEM);
 	}
 
-	for (i = 0, zdl = list_head(&zone->zone_dl_list); zdl != NULL;
-	    i++, zdl = list_next(&zone->zone_dl_list, zdl)) {
+	i = 0;
+	list_for_each(&zone->zone_dl_list, zdl) {
 		idarray[i] = zdl->zdl_id;
+		i++;
 	}
 
 	mutex_exit(&zone->zone_lock);
