Print this page
*** NO COMMENTS ***

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libbe/common/be_zones.c
          +++ new/usr/src/lib/libbe/common/be_zones.c
↓ open down ↓ 16 lines elided ↑ open up ↑
  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   */
  25   25  
  26   26  /*
       27 + * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
       28 + */
       29 +
       30 +/*
  27   31   * System includes
  28   32   */
  29   33  #include <assert.h>
  30   34  #include <errno.h>
  31   35  #include <libintl.h>
  32   36  #include <libnvpair.h>
  33   37  #include <libzfs.h>
  34   38  #include <stdio.h>
  35   39  #include <stdlib.h>
  36   40  #include <string.h>
↓ open down ↓ 69 lines elided ↑ open up ↑
 106  110  int
 107  111  be_find_active_zone_root(zfs_handle_t *be_zhp, char *zonepath_ds,
 108  112      char *zoneroot_ds, int zoneroot_ds_size)
 109  113  {
 110  114          active_zone_root_data_t         azr_data = { 0 };
 111  115          zfs_handle_t                    *zhp;
 112  116          char                            zone_container_ds[MAXPATHLEN];
 113  117          int                             ret = BE_SUCCESS;
 114  118  
 115  119          /* Get the uuid of the parent global BE */
 116      -        if ((ret = be_get_uuid(zfs_get_name(be_zhp), &azr_data.parent_uuid))
 117      -            != BE_SUCCESS) {
 118      -                be_print_err(gettext("be_find_active_zone_root: failed to "
 119      -                    "get uuid for BE root dataset %s\n"), zfs_get_name(be_zhp));
 120      -                return (ret);
      120 +        if (getzoneid() == GLOBAL_ZONEID) {
      121 +                if ((ret = be_get_uuid(zfs_get_name(be_zhp),
      122 +                    &azr_data.parent_uuid)) != BE_SUCCESS) {
      123 +                        be_print_err(gettext("be_find_active_zone_root: failed "
      124 +                            "to get uuid for BE root dataset %s\n"),
      125 +                            zfs_get_name(be_zhp));
      126 +                        return (ret);
      127 +                }
      128 +        } else {
      129 +                if ((ret = be_zone_get_parent_uuid(zfs_get_name(be_zhp),
      130 +                    &azr_data.parent_uuid)) != BE_SUCCESS) {
      131 +                        be_print_err(gettext("be_find_active_zone_root: failed "
      132 +                            "to get parentbe uuid for zone root dataset %s\n"),
      133 +                            zfs_get_name(be_zhp));
      134 +                        return (ret);
      135 +                }
 121  136          }
 122  137  
 123      -        /* Generate string for the root container dataset for this zone. */
      138 +        /* Generate string for the root container dataset  for this zone. */
 124  139          be_make_container_ds(zonepath_ds, zone_container_ds,
 125  140              sizeof (zone_container_ds));
 126  141  
 127  142          /* Get handle to this zone's root container dataset */
 128  143          if ((zhp = zfs_open(g_zfs, zone_container_ds, ZFS_TYPE_FILESYSTEM))
 129  144              == NULL) {
 130  145                  be_print_err(gettext("be_find_active_zone_root: failed to "
 131  146                      "open zone root container dataset (%s): %s\n"),
 132  147                      zone_container_ds, libzfs_error_description(g_zfs));
 133  148                  return (zfs_err_to_be_err(g_zfs));
↓ open down ↓ 235 lines elided ↑ open up ↑
 369  384                  be_print_err(gettext("be_zone_get_parent_uuid: failed to "
 370  385                      "parse parentuuid\n"));
 371  386                  ret = BE_ERR_PARSE_UUID;
 372  387          }
 373  388  
 374  389  done:
 375  390          ZFS_CLOSE(zhp);
 376  391          return (ret);
 377  392  }
 378  393  
      394 +/*
      395 + * Function:    be_zone_set_parent_uuid
      396 + * Description: This function sets parentbe uuid into
      397 + *              a zfs user property for a root zone dataset.
      398 + * Parameters:
      399 + *              root_ds - Root zone dataset of the BE to set a uuid on.
      400 + * Return:
      401 + *              be_errno_t - Failure
      402 + *              BE_SUCCESS - Success
      403 + * Scope:
      404 + *              Semi-private (library wide uses only)
      405 + */
      406 +int
      407 +be_zone_set_parent_uuid(char *root_ds, uuid_t uu)
      408 +{
      409 +        zfs_handle_t    *zhp = NULL;
      410 +        char            uu_string[UUID_PRINTABLE_STRING_LENGTH];
      411 +        int             ret = BE_SUCCESS;
      412 +
      413 +        uuid_unparse(uu, uu_string);
      414 +
      415 +        /* Get handle to the root zone dataset. */
      416 +        if ((zhp = zfs_open(g_zfs, root_ds, ZFS_TYPE_FILESYSTEM)) == NULL) {
      417 +                be_print_err(gettext("be_zone_set_parent_uuid: failed to "
      418 +                    "open root zone dataset (%s): %s\n"), root_ds,
      419 +                    libzfs_error_description(g_zfs));
      420 +                return (zfs_err_to_be_err(g_zfs));
      421 +        }
      422 +
      423 +        /* Set parentbe uuid property for the root zone dataset */
      424 +        if (zfs_prop_set(zhp, BE_ZONE_PARENTBE_PROPERTY, uu_string) != 0) {
      425 +                be_print_err(gettext("be_zone_set_parent_uuid: failed to "
      426 +                    "set parentbe uuid property for root zone dataset: %s\n"),
      427 +                    libzfs_error_description(g_zfs));
      428 +                ret = zfs_err_to_be_err(g_zfs);
      429 +        }
      430 +
      431 +        ZFS_CLOSE(zhp);
      432 +        return (ret);
      433 +}
      434 +
      435 +/*
      436 + * Function:    be_zone_compare_uuids
      437 + * Description: This function compare the parentbe uuid of the
      438 + *              current running root zone dataset with the parentbe
      439 + *              uuid of the given root zone dataset.
      440 + * Parameters:
      441 + *              root_ds - Root zone dataset of the BE to compare.
      442 + * Return:
      443 + *              B_TRUE - root dataset has right parentbe uuid
      444 + *              B_FALSE - root dataset has wrong parentbe uuid
      445 + * Scope:
      446 + *              Semi-private (library wide uses only)
      447 + */
      448 +boolean_t
      449 +be_zone_compare_uuids(char *root_ds)
      450 +{
      451 +        char            *active_ds;
      452 +        uuid_t          parent_uuid = {0};
      453 +        uuid_t          cur_parent_uuid = {0};
      454 +
      455 +        /* Get parentbe uuid from given zone root dataset */
      456 +        if ((be_zone_get_parent_uuid(root_ds,
      457 +            &parent_uuid)) != BE_SUCCESS) {
      458 +                be_print_err(gettext("be_zone_compare_uuids: failed to get "
      459 +                    "parentbe uuid from the given BE\n"));
      460 +                return (B_FALSE);
      461 +        }
      462 +
      463 +        /*
      464 +         * Find current running zone root dataset and get it's parentbe
      465 +         * uuid property.
      466 +         */
      467 +        if ((active_ds = be_get_ds_from_dir("/")) != NULL) {
      468 +                if ((be_zone_get_parent_uuid(active_ds,
      469 +                    &cur_parent_uuid)) != BE_SUCCESS) {
      470 +                        be_print_err(gettext("be_zone_compare_uuids: failed "
      471 +                        "to get parentbe uuid from the current running zone "
      472 +                        "root dataset\n"));
      473 +                        return (B_FALSE);
      474 +                }
      475 +        } else {
      476 +                be_print_err(gettext("be_zone_compare_uuids: zone root dataset "
      477 +                    "is not mounted\n"));
      478 +                return (B_FALSE);
      479 +        }
      480 +
      481 +        if (uuid_compare(parent_uuid, cur_parent_uuid) != 0) {
      482 +                return (B_FALSE);
      483 +        }
      484 +
      485 +        return (B_TRUE);
      486 +}
      487 +
 379  488  /* ******************************************************************** */
 380  489  /*                      Private Functions                               */
 381  490  /* ******************************************************************** */
 382  491  
 383  492  /*
 384  493   * Function:    be_find_active_zone_root_callback
 385  494   * Description: This function is used as a callback to iterate over all of
 386  495   *              a zone's root datasets, finding the one that is marked active
 387  496   *              for the parent BE specified in the data passed in.  The name
 388  497   *              of the zone's active root dataset is returned in heap storage
↓ open down ↓ 130 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX