Print this page
patch zone

@@ -574,11 +574,11 @@
 static struct zsd_entry *
 zsd_find(list_t *l, zone_key_t key)
 {
         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);
                 }
         }
         return (NULL);

@@ -591,11 +591,11 @@
 static struct zsd_entry *
 zsd_find_mru(list_t *l, zone_key_t key)
 {
         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.
                          */
                         if (zsd != list_head(l)) {

@@ -636,12 +636,11 @@
         /*
          * Insert for all existing zones and mark them as needing
          * 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);
 
                 /* Skip zones that are on the way down or not yet up */

@@ -713,12 +712,11 @@
         }
         list_remove(&zsd_registered_keys, zsdp);
         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);
                 del = zsd_find_mru(&zone->zone_zsd, key);
                 if (del == NULL) {

@@ -752,12 +750,11 @@
         zsd_apply_all_zones(zsd_apply_shutdown, key);
         zsd_apply_all_zones(zsd_apply_destroy, key);
 
         /* 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);
                 del = zsd_find(&zone->zone_zsd, key);
                 if (del != NULL) {

@@ -829,12 +826,11 @@
 
         ASSERT(MUTEX_HELD(&zonehash_lock));
         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.
                  */
                 ASSERT(zsd_find(&zone->zone_zsd, zsdp->zsd_key) == NULL);

@@ -874,12 +870,11 @@
          * in zone_zsd. The global list can change independently of this
          * as keys are registered and unregistered and we don't register new
          * 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 */
 
                 if (ct == ZSD_SHUTDOWN) {

@@ -917,12 +912,11 @@
 
         /*
          * 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));
         }
         list_destroy(&zone->zone_zsd);

@@ -1299,12 +1293,11 @@
 static void
 zone_free_datasets(zone_t *zone)
 {
         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));
         }
         list_destroy(&zone->zone_datasets);

@@ -3037,12 +3030,11 @@
                 zone_hold(global_zone);
                 return (global_zone);
         }
         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;
         }
         ASSERT(zret != NULL);
         status = zone_status_get(zret);

@@ -3256,12 +3248,11 @@
         zone_t *zone;
         int ret = 0;
         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.
                  */
                 status = zone_status_get(zone);
                 if (status < ZONE_IS_READY || status > ZONE_IS_DOWN)

@@ -4048,12 +4039,11 @@
          */
         if ((rootpathlen <= 3) && (rootpath[0] == '/') &&
             (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);
                 if (strncmp(rootpath, zone->zone_rootpath,
                     MIN(rootpathlen, len)) == 0)

@@ -5730,12 +5720,11 @@
          * restarted init (or other zone-penetrating process) its
          * predecessor's contracts.
          */
         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);
                                 mutex_exit(&zonehash_lock);
                                 err = EINVAL;

@@ -6089,13 +6078,11 @@
                         domi_nzones = 0;
                         if (real_nzones > 0) {
                                 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 &&
                                             (zone->zone_flags & ZF_IS_SCRATCH))
                                                 continue;

@@ -6118,12 +6105,11 @@
                 real_nzones = zonecount;
                 domi_nzones = 0;
                 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);
                 }
                 mutex_exit(&zonehash_lock);
         }

@@ -6584,12 +6570,11 @@
          * state during initialization, readying, or booting) or produce races.
          * We'll let threads continue to initialize and ready new zones: they'll
          * 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);
         }
         mutex_exit(&zone_status_lock);
         mutex_exit(&zonehash_lock);

@@ -6615,13 +6600,11 @@
         /*
          * Walk the list once, looking for datasets which match exactly, or
          * 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 &&
                     (dataset[len] == '\0' || dataset[len] == '/' ||
                     dataset[len] == '@')) {

@@ -6636,13 +6619,11 @@
          * of exported datasets.  These should be visible, but read-only.
          *
          * 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 */
                 if (len < strlen(zd->zd_dataset) &&
                     bcmp(dataset, zd->zd_dataset, len) == 0 &&

@@ -6743,12 +6724,11 @@
                 ASSERT(treat_abs);
                 path_offset = 1;
         }
 
         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;
 
                 if (zone == global_zone)        /* skip global zone */

@@ -6780,12 +6760,11 @@
 zone_find_dl(zone_t *zone, datalink_id_t linkid)
 {
         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;
         }
         return (zdl);
 }

@@ -6814,12 +6793,11 @@
         if ((thiszone = zone_find_by_id(zoneid)) == NULL)
                 return (set_errno(ENXIO));
 
         /* 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);
                         return (set_errno((zone == thiszone) ? EEXIST : EPERM));
                 }

@@ -6879,12 +6857,11 @@
                 }
                 return (err);
         }
 
         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;
                         break;
                 }

@@ -6915,12 +6892,11 @@
         if ((zone = zone_find_by_id(zoneid)) == NULL)
                 return (set_errno(ENXIO));
 
         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.
                  */
                 if (++num > dlcount)

@@ -6990,12 +6966,11 @@
         /*
          * We first build an array of linkid's so that we can walk these and
          * 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++;
         }
 
         if (idcount == 0) {
                 mutex_exit(&zone->zone_lock);

@@ -7008,13 +6983,14 @@
                 mutex_exit(&zone->zone_lock);
                 zone_rele(zone);
                 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);
 
         for (i = 0; i < idcount && ret == 0; i++) {