Print this page
patch zone-auto-create-be

@@ -21,10 +21,11 @@
 
 /*
  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
  * Copyright (c) 2014 by Delphix. All rights reserved.
+ * Copyright 2015 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  */
 
 /*
  * System includes
  */

@@ -1616,32 +1617,23 @@
         char            *zonepath = NULL;
         char            *zonename = NULL;
         char            *zonepath_ds = NULL;
         char            *mp = NULL;
         zoneList_t      zlist = NULL;
-        zoneBrandList_t *brands = NULL;
         zfs_handle_t    *zhp = NULL;
 
         /* If zones are not implemented, then get out. */
         if (!z_zones_are_implemented()) {
                 return (BE_SUCCESS);
         }
 
-        /* Get list of supported brands */
-        if ((brands = be_get_supported_brandlist()) == NULL) {
-                be_print_err(gettext("be_destroy_zones: "
-                    "no supported brands\n"));
-                return (BE_SUCCESS);
-        }
-
         /* Get handle to BE's root dataset */
         if ((zhp = zfs_open(g_zfs, be_root_ds, ZFS_TYPE_FILESYSTEM)) ==
             NULL) {
                 be_print_err(gettext("be_destroy_zones: failed to "
                     "open BE root dataset (%s): %s\n"), be_root_ds,
                     libzfs_error_description(g_zfs));
-                z_free_brand_list(brands);
                 return (zfs_err_to_be_err(g_zfs));
         }
 
         /*
          * If the global BE is not mounted, we must mount it here to

@@ -1652,24 +1644,21 @@
                     BE_MOUNT_FLAG_NO_ZONES)) != BE_SUCCESS) {
                         be_print_err(gettext("be_destroy_zones: failed to "
                             "mount the BE (%s) for zones processing.\n"),
                             be_name);
                         ZFS_CLOSE(zhp);
-                        z_free_brand_list(brands);
                         return (ret);
                 }
         }
         ZFS_CLOSE(zhp);
 
         z_set_zone_root(mp);
         free(mp);
 
-        /* Get list of supported zones. */
-        if ((zlist = z_get_nonglobal_zone_list_by_brand(brands)) == NULL) {
-                z_free_brand_list(brands);
+        /* Get list of zones. */
+        if ((zlist = z_get_nonglobal_branded_zone_list()) == NULL)
                 return (BE_SUCCESS);
-        }
 
         /* Unmount the BE before destroying the zones in it. */
         if (dd->force_unmount)
                 force_umnt = BE_UNMOUNT_FLAG_FORCE;
         if ((ret = _be_unmount(be_name, force_umnt)) != BE_SUCCESS) {

@@ -1678,10 +1667,21 @@
                 goto done;
         }
 
         /* Iterate through the zones and destroy them. */
         for (i = 0; (zonename = z_zlist_get_zonename(zlist, i)) != NULL; i++) {
+                boolean_t auto_create;
+
+                if (z_zlist_is_zone_auto_create_be(zlist, i, &auto_create) != 0) {
+                        be_print_err(gettext("be_destroy_zones: failed to get "
+                            "auto-create-be brand property\n"));
+                        ret = -1; // XXX
+                        goto done;
+                }
+
+                if (!auto_create)
+                        continue;
 
                 /* Skip zones that aren't at least installed */
                 if (z_zlist_get_current_state(zlist, i) < ZONE_STATE_INSTALLED)
                         continue;
 

@@ -1714,11 +1714,10 @@
                 }
                 free(zonepath_ds);
         }
 
 done:
-        z_free_brand_list(brands);
         z_free_zone_list(zlist);
 
         return (ret);
 }
 

@@ -1906,26 +1905,18 @@
         be_transaction_data_t bt = { 0 };
         zfs_handle_t    *obe_zhp = NULL;
         zfs_handle_t    *nbe_zhp = NULL;
         zfs_handle_t    *z_zhp = NULL;
         zoneList_t      zlist = NULL;
-        zoneBrandList_t *brands = NULL;
         boolean_t       mounted_here = B_FALSE;
         char            *snap_name = NULL;
 
         /* If zones are not implemented, then get out. */
         if (!z_zones_are_implemented()) {
                 return (BE_SUCCESS);
         }
 
-        /* Get list of supported brands */
-        if ((brands = be_get_supported_brandlist()) == NULL) {
-                be_print_err(gettext("be_copy_zones: "
-                    "no supported brands\n"));
-                return (BE_SUCCESS);
-        }
-
         /* Get handle to origin BE's root dataset */
         if ((obe_zhp = zfs_open(g_zfs, obe_root_ds, ZFS_TYPE_FILESYSTEM))
             == NULL) {
                 be_print_err(gettext("be_copy_zones: failed to open "
                     "the origin BE root dataset (%s) for zones processing: "

@@ -1969,21 +1960,31 @@
                 mounted_here = B_TRUE;
         }
 
         z_set_zone_root(temp_mntpt);
 
-        /* Get list of supported zones. */
-        if ((zlist = z_get_nonglobal_zone_list_by_brand(brands)) == NULL) {
+        /* Get list of zones. */
+        if ((zlist = z_get_nonglobal_branded_zone_list()) == NULL) {
                 ret = BE_SUCCESS;
                 goto done;
         }
 
         for (i = 0; (zonename = z_zlist_get_zonename(zlist, i)) != NULL; i++) {
 
                 be_fs_list_data_t       fld = { 0 };
                 char                    zonepath_ds[MAXPATHLEN];
                 char                    *ds = NULL;
+                boolean_t               auto_create;
+
+                if (z_zlist_is_zone_auto_create_be(zlist, i, &auto_create) != 0) {
+                        be_print_err(gettext("be_copy_zones: failed to get "
+                            "auto-create-be brand property\n"));
+                        ret = -1; // XXX
+                }
+
+                if (!auto_create)
+                        continue;
 
                 /* Get zonepath of zone */
                 zonepath = z_zlist_get_zonepath(zlist, i);
 
                 /* Skip zones that aren't at least installed */

@@ -2247,12 +2248,10 @@
                 ZFS_CLOSE(z_zhp);
         }
 
 done:
         free(snap_name);
-        if (brands != NULL)
-                z_free_brand_list(brands);
         if (zlist != NULL)
                 z_free_zone_list(zlist);
 
         if (mounted_here)
                 (void) _be_unmount(obe_name, 0);