Print this page
patch zone-auto-create-be

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libbe/common/be_activate.c
          +++ new/usr/src/lib/libbe/common/be_activate.c
↓ open down ↓ 17 lines elided ↑ open up ↑
  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   */
  25   25  
  26   26  /*
  27   27   * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
       28 + * Copyright 2015 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  28   29   */
  29   30  
  30   31  #include <assert.h>
  31   32  #include <libintl.h>
  32   33  #include <libnvpair.h>
  33   34  #include <libzfs.h>
  34   35  #include <stdio.h>
  35   36  #include <stdlib.h>
  36   37  #include <string.h>
  37   38  #include <strings.h>
↓ open down ↓ 1345 lines elided ↑ open up ↑
1383 1384  static int
1384 1385  be_promote_zone_ds(char *be_name, char *be_root_ds)
1385 1386  {
1386 1387          char            *zone_ds = NULL;
1387 1388          char            *temp_mntpt = NULL;
1388 1389          char            origin[MAXPATHLEN];
1389 1390          char            zoneroot_ds[MAXPATHLEN];
1390 1391          zfs_handle_t    *zhp = NULL;
1391 1392          zfs_handle_t    *z_zhp = NULL;
1392 1393          zoneList_t      zone_list = NULL;
1393      -        zoneBrandList_t *brands = NULL;
1394 1394          boolean_t       be_mounted = B_FALSE;
1395 1395          int             zone_index = 0;
1396 1396          int             err = BE_SUCCESS;
1397 1397  
1398      -        /*
1399      -         * Get the supported zone brands so we can pass that
1400      -         * to z_get_nonglobal_zone_list_by_brand. Currently
1401      -         * only the ipkg and labeled brand zones are supported
1402      -         *
1403      -         */
1404      -        if ((brands = be_get_supported_brandlist()) == NULL) {
1405      -                be_print_err(gettext("be_promote_zone_ds: no supported "
1406      -                    "brands\n"));
1407      -                return (BE_SUCCESS);
1408      -        }
1409      -
1410 1398          if ((zhp = zfs_open(g_zfs, be_root_ds,
1411 1399              ZFS_TYPE_FILESYSTEM)) == NULL) {
1412 1400                  be_print_err(gettext("be_promote_zone_ds: Failed to open "
1413 1401                      "dataset (%s): %s\n"), be_root_ds,
1414 1402                      libzfs_error_description(g_zfs));
1415 1403                  err = zfs_err_to_be_err(g_zfs);
1416      -                z_free_brand_list(brands);
1417 1404                  return (err);
1418 1405          }
1419 1406  
1420 1407          if (!zfs_is_mounted(zhp, &temp_mntpt)) {
1421 1408                  if ((err = _be_mount(be_name, &temp_mntpt,
1422 1409                      BE_MOUNT_FLAG_NO_ZONES)) != BE_SUCCESS) {
1423 1410                          be_print_err(gettext("be_promote_zone_ds: failed to "
1424 1411                              "mount the BE for zones procesing.\n"));
1425 1412                          ZFS_CLOSE(zhp);
1426      -                        z_free_brand_list(brands);
1427 1413                          return (err);
1428 1414                  }
1429 1415                  be_mounted = B_TRUE;
1430 1416          }
1431 1417  
1432 1418          /*
1433 1419           * Set the zone root to the temp mount point for the BE we just mounted.
1434 1420           */
1435 1421          z_set_zone_root(temp_mntpt);
1436 1422  
1437 1423          /*
1438      -         * Get all the zones based on the brands we're looking for. If no zones
1439      -         * are found that we're interested in unmount the BE and move on.
     1424 +         * If no zones are found, unmount the BE and move on.
1440 1425           */
1441      -        if ((zone_list = z_get_nonglobal_zone_list_by_brand(brands)) == NULL) {
     1426 +        if ((zone_list = z_get_nonglobal_branded_zone_list()) == NULL) {
1442 1427                  if (be_mounted)
1443 1428                          (void) _be_unmount(be_name, 0);
1444 1429                  ZFS_CLOSE(zhp);
1445      -                z_free_brand_list(brands);
1446 1430                  free(temp_mntpt);
1447 1431                  return (BE_SUCCESS);
1448 1432          }
1449 1433          for (zone_index = 0; z_zlist_get_zonename(zone_list, zone_index)
1450 1434              != NULL; zone_index++) {
1451 1435                  char *zone_path = NULL;
     1436 +                boolean_t auto_create;
     1437 +
     1438 +                if (z_zlist_is_zone_auto_create_be(zone_list, zone_index,
     1439 +                    &auto_create) != 0) {
     1440 +                        be_print_err(gettext("be_promote_zone_ds: "
     1441 +                            "Failed to get auto-create-be brand property\n"));
     1442 +                        err = -1; // XXX
     1443 +                        goto done;
     1444 +                }
     1445 +
     1446 +                if (!auto_create)
     1447 +                        continue;
1452 1448  
1453 1449                  /* Skip zones that aren't at least installed */
1454 1450                  if (z_zlist_get_current_state(zone_list, zone_index) <
1455 1451                      ZONE_STATE_INSTALLED)
1456 1452                          continue;
1457 1453  
1458 1454                  if (((zone_path =
1459 1455                      z_zlist_get_zonepath(zone_list, zone_index)) == NULL) ||
1460 1456                      ((zone_ds = be_get_ds_from_dir(zone_path)) == NULL) ||
1461 1457                      !be_zone_supported(zone_ds))
↓ open down ↓ 36 lines elided ↑ open up ↑
1498 1494                              libzfs_error_description(g_zfs));
1499 1495                          err = BE_ERR_PROMOTE;
1500 1496                          goto done;
1501 1497                  }
1502 1498          }
1503 1499  done:
1504 1500          if (be_mounted)
1505 1501                  (void) _be_unmount(be_name, 0);
1506 1502          ZFS_CLOSE(zhp);
1507 1503          free(temp_mntpt);
1508      -        z_free_brand_list(brands);
1509 1504          z_free_zone_list(zone_list);
1510 1505          return (err);
1511 1506  }
1512 1507  
1513 1508  /*
1514 1509   * Function:    be_promote_ds_callback
1515 1510   * Description: This function is used to promote the datasets for the BE
1516 1511   *              being activated as well as the datasets for the zones BE
1517 1512   *              being activated.
1518 1513   *
↓ open down ↓ 88 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX