Print this page
patch zone-auto-create-be

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libbe/common/be_create.c
          +++ new/usr/src/lib/libbe/common/be_create.c
↓ open down ↓ 15 lines elided ↑ open up ↑
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  24   24   * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
  25   25   * Copyright (c) 2014 by Delphix. All rights reserved.
       26 + * Copyright 2015 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  26   27   */
  27   28  
  28   29  /*
  29   30   * System includes
  30   31   */
  31   32  
  32   33  #include <assert.h>
  33   34  #include <ctype.h>
  34   35  #include <errno.h>
  35   36  #include <libgen.h>
↓ open down ↓ 1575 lines elided ↑ open up ↑
1611 1612  be_destroy_zones(char *be_name, char *be_root_ds, be_destroy_data_t *dd)
1612 1613  {
1613 1614          int             i;
1614 1615          int             ret = BE_SUCCESS;
1615 1616          int             force_umnt = BE_UNMOUNT_FLAG_NULL;
1616 1617          char            *zonepath = NULL;
1617 1618          char            *zonename = NULL;
1618 1619          char            *zonepath_ds = NULL;
1619 1620          char            *mp = NULL;
1620 1621          zoneList_t      zlist = NULL;
1621      -        zoneBrandList_t *brands = NULL;
1622 1622          zfs_handle_t    *zhp = NULL;
1623 1623  
1624 1624          /* If zones are not implemented, then get out. */
1625 1625          if (!z_zones_are_implemented()) {
1626 1626                  return (BE_SUCCESS);
1627 1627          }
1628 1628  
1629      -        /* Get list of supported brands */
1630      -        if ((brands = be_get_supported_brandlist()) == NULL) {
1631      -                be_print_err(gettext("be_destroy_zones: "
1632      -                    "no supported brands\n"));
1633      -                return (BE_SUCCESS);
1634      -        }
1635      -
1636 1629          /* Get handle to BE's root dataset */
1637 1630          if ((zhp = zfs_open(g_zfs, be_root_ds, ZFS_TYPE_FILESYSTEM)) ==
1638 1631              NULL) {
1639 1632                  be_print_err(gettext("be_destroy_zones: failed to "
1640 1633                      "open BE root dataset (%s): %s\n"), be_root_ds,
1641 1634                      libzfs_error_description(g_zfs));
1642      -                z_free_brand_list(brands);
1643 1635                  return (zfs_err_to_be_err(g_zfs));
1644 1636          }
1645 1637  
1646 1638          /*
1647 1639           * If the global BE is not mounted, we must mount it here to
1648 1640           * gather data about the non-global zones in it.
1649 1641           */
1650 1642          if (!zfs_is_mounted(zhp, &mp)) {
1651 1643                  if ((ret = _be_mount(be_name, &mp,
1652 1644                      BE_MOUNT_FLAG_NO_ZONES)) != BE_SUCCESS) {
1653 1645                          be_print_err(gettext("be_destroy_zones: failed to "
1654 1646                              "mount the BE (%s) for zones processing.\n"),
1655 1647                              be_name);
1656 1648                          ZFS_CLOSE(zhp);
1657      -                        z_free_brand_list(brands);
1658 1649                          return (ret);
1659 1650                  }
1660 1651          }
1661 1652          ZFS_CLOSE(zhp);
1662 1653  
1663 1654          z_set_zone_root(mp);
1664 1655          free(mp);
1665 1656  
1666      -        /* Get list of supported zones. */
1667      -        if ((zlist = z_get_nonglobal_zone_list_by_brand(brands)) == NULL) {
1668      -                z_free_brand_list(brands);
     1657 +        /* Get list of zones. */
     1658 +        if ((zlist = z_get_nonglobal_branded_zone_list()) == NULL)
1669 1659                  return (BE_SUCCESS);
1670      -        }
1671 1660  
1672 1661          /* Unmount the BE before destroying the zones in it. */
1673 1662          if (dd->force_unmount)
1674 1663                  force_umnt = BE_UNMOUNT_FLAG_FORCE;
1675 1664          if ((ret = _be_unmount(be_name, force_umnt)) != BE_SUCCESS) {
1676 1665                  be_print_err(gettext("be_destroy_zones: failed to "
1677 1666                      "unmount the BE (%s)\n"), be_name);
1678 1667                  goto done;
1679 1668          }
1680 1669  
1681 1670          /* Iterate through the zones and destroy them. */
1682 1671          for (i = 0; (zonename = z_zlist_get_zonename(zlist, i)) != NULL; i++) {
     1672 +                boolean_t auto_create;
     1673 +
     1674 +                if (z_zlist_is_zone_auto_create_be(zlist, i, &auto_create) != 0) {
     1675 +                        be_print_err(gettext("be_destroy_zones: failed to get "
     1676 +                            "auto-create-be brand property\n"));
     1677 +                        ret = -1; // XXX
     1678 +                        goto done;
     1679 +                }
     1680 +
     1681 +                if (!auto_create)
     1682 +                        continue;
1683 1683  
1684 1684                  /* Skip zones that aren't at least installed */
1685 1685                  if (z_zlist_get_current_state(zlist, i) < ZONE_STATE_INSTALLED)
1686 1686                          continue;
1687 1687  
1688 1688                  zonepath = z_zlist_get_zonepath(zlist, i);
1689 1689  
1690 1690                  /*
1691 1691                   * Get the dataset of this zonepath.  If its not
1692 1692                   * a dataset, skip it.
↓ open down ↓ 16 lines elided ↑ open up ↑
1709 1709                          be_print_err(gettext("be_destroy_zones: failed to "
1710 1710                              "find and destroy zone roots for zone %s\n"),
1711 1711                              zonename);
1712 1712                          free(zonepath_ds);
1713 1713                          goto done;
1714 1714                  }
1715 1715                  free(zonepath_ds);
1716 1716          }
1717 1717  
1718 1718  done:
1719      -        z_free_brand_list(brands);
1720 1719          z_free_zone_list(zlist);
1721 1720  
1722 1721          return (ret);
1723 1722  }
1724 1723  
1725 1724  /*
1726 1725   * Function:    be_destroy_zone_roots
1727 1726   * Description: This function will open the zone's root container dataset
1728 1727   *              and iterate the datasets within, looking for roots that
1729 1728   *              belong to the given global BE and destroying them.
↓ open down ↓ 171 lines elided ↑ open up ↑
1901 1900          char            zone_container_ds[MAXPATHLEN];
1902 1901          char            new_zoneroot_ds[MAXPATHLEN];
1903 1902          char            ss[MAXPATHLEN];
1904 1903          uuid_t          uu = { 0 };
1905 1904          char            uu_string[UUID_PRINTABLE_STRING_LENGTH] = { 0 };
1906 1905          be_transaction_data_t bt = { 0 };
1907 1906          zfs_handle_t    *obe_zhp = NULL;
1908 1907          zfs_handle_t    *nbe_zhp = NULL;
1909 1908          zfs_handle_t    *z_zhp = NULL;
1910 1909          zoneList_t      zlist = NULL;
1911      -        zoneBrandList_t *brands = NULL;
1912 1910          boolean_t       mounted_here = B_FALSE;
1913 1911          char            *snap_name = NULL;
1914 1912  
1915 1913          /* If zones are not implemented, then get out. */
1916 1914          if (!z_zones_are_implemented()) {
1917 1915                  return (BE_SUCCESS);
1918 1916          }
1919 1917  
1920      -        /* Get list of supported brands */
1921      -        if ((brands = be_get_supported_brandlist()) == NULL) {
1922      -                be_print_err(gettext("be_copy_zones: "
1923      -                    "no supported brands\n"));
1924      -                return (BE_SUCCESS);
1925      -        }
1926      -
1927 1918          /* Get handle to origin BE's root dataset */
1928 1919          if ((obe_zhp = zfs_open(g_zfs, obe_root_ds, ZFS_TYPE_FILESYSTEM))
1929 1920              == NULL) {
1930 1921                  be_print_err(gettext("be_copy_zones: failed to open "
1931 1922                      "the origin BE root dataset (%s) for zones processing: "
1932 1923                      "%s\n"), obe_root_ds, libzfs_error_description(g_zfs));
1933 1924                  return (zfs_err_to_be_err(g_zfs));
1934 1925          }
1935 1926  
1936 1927          /* Get handle to newly cloned BE's root dataset */
↓ open down ↓ 27 lines elided ↑ open up ↑
1964 1955                          be_print_err(gettext("be_copy_zones: failed to "
1965 1956                              "mount the BE (%s) for zones procesing.\n"),
1966 1957                              obe_name);
1967 1958                          goto done;
1968 1959                  }
1969 1960                  mounted_here = B_TRUE;
1970 1961          }
1971 1962  
1972 1963          z_set_zone_root(temp_mntpt);
1973 1964  
1974      -        /* Get list of supported zones. */
1975      -        if ((zlist = z_get_nonglobal_zone_list_by_brand(brands)) == NULL) {
     1965 +        /* Get list of zones. */
     1966 +        if ((zlist = z_get_nonglobal_branded_zone_list()) == NULL) {
1976 1967                  ret = BE_SUCCESS;
1977 1968                  goto done;
1978 1969          }
1979 1970  
1980 1971          for (i = 0; (zonename = z_zlist_get_zonename(zlist, i)) != NULL; i++) {
1981 1972  
1982 1973                  be_fs_list_data_t       fld = { 0 };
1983 1974                  char                    zonepath_ds[MAXPATHLEN];
1984 1975                  char                    *ds = NULL;
     1976 +                boolean_t               auto_create;
     1977 +
     1978 +                if (z_zlist_is_zone_auto_create_be(zlist, i, &auto_create) != 0) {
     1979 +                        be_print_err(gettext("be_copy_zones: failed to get "
     1980 +                            "auto-create-be brand property\n"));
     1981 +                        ret = -1; // XXX
     1982 +                }
     1983 +
     1984 +                if (!auto_create)
     1985 +                        continue;
1985 1986  
1986 1987                  /* Get zonepath of zone */
1987 1988                  zonepath = z_zlist_get_zonepath(zlist, i);
1988 1989  
1989 1990                  /* Skip zones that aren't at least installed */
1990 1991                  if (z_zlist_get_current_state(zlist, i) < ZONE_STATE_INSTALLED)
1991 1992                          continue;
1992 1993  
1993 1994                  /*
1994 1995                   * Get the dataset of this zonepath.  If its not
↓ open down ↓ 247 lines elided ↑ open up ↑
2242 2243                          be_free_fs_list(&fld);
2243 2244                          goto done;
2244 2245                  }
2245 2246  
2246 2247                  be_free_fs_list(&fld);
2247 2248                  ZFS_CLOSE(z_zhp);
2248 2249          }
2249 2250  
2250 2251  done:
2251 2252          free(snap_name);
2252      -        if (brands != NULL)
2253      -                z_free_brand_list(brands);
2254 2253          if (zlist != NULL)
2255 2254                  z_free_zone_list(zlist);
2256 2255  
2257 2256          if (mounted_here)
2258 2257                  (void) _be_unmount(obe_name, 0);
2259 2258  
2260 2259          ZFS_CLOSE(obe_zhp);
2261 2260          return (ret);
2262 2261  }
2263 2262  
↓ open down ↓ 835 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX