Print this page
*** NO COMMENTS ***

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 ↓ 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   */
  25   25  
       26 +/*
       27 + * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
       28 + */
       29 +
  26   30  #include <assert.h>
  27   31  #include <libintl.h>
  28   32  #include <libnvpair.h>
  29   33  #include <libzfs.h>
  30   34  #include <stdio.h>
  31   35  #include <stdlib.h>
  32   36  #include <string.h>
  33   37  #include <errno.h>
  34   38  #include <sys/mnttab.h>
  35   39  #include <sys/types.h>
↓ open down ↓ 88 lines elided ↑ open up ↑
 124  128   *              be_errnot_t - Failure
 125  129   * Scope:
 126  130   *              Public
 127  131   */
 128  132  int
 129  133  _be_activate(char *be_name)
 130  134  {
 131  135          be_transaction_data_t cb = { 0 };
 132  136          zfs_handle_t    *zhp = NULL;
 133  137          char            root_ds[MAXPATHLEN];
      138 +        char            active_ds[MAXPATHLEN];
 134  139          char            *cur_vers = NULL, *new_vers = NULL;
 135  140          be_node_list_t  *be_nodes = NULL;
 136  141          uuid_t          uu = {0};
 137  142          int             entry, ret = BE_SUCCESS;
 138  143          int             zret = 0;
 139  144  
 140  145          /*
 141  146           * TODO: The BE needs to be validated to make sure that it is actually
 142  147           * a bootable BE.
 143  148           */
↓ open down ↓ 73 lines elided ↑ open up ↑
 217  222          if ((ret = _be_list(cb.obe_name, &be_nodes)) != BE_SUCCESS) {
 218  223                  return (ret);
 219  224          }
 220  225  
 221  226          if ((ret = set_canmount(be_nodes, "noauto")) != BE_SUCCESS) {
 222  227                  be_print_err(gettext("be_activate: failed to set "
 223  228                      "canmount dataset property\n"));
 224  229                  goto done;
 225  230          }
 226  231  
 227      -        if ((ret = set_bootfs(be_nodes->be_rpool, root_ds)) != BE_SUCCESS) {
 228      -                be_print_err(gettext("be_activate: failed to set "
 229      -                    "bootfs pool property for %s\n"), root_ds);
 230      -                goto done;
      232 +        if (getzoneid() == GLOBAL_ZONEID) {
      233 +                if ((ret = set_bootfs(be_nodes->be_rpool,
      234 +                    root_ds)) != BE_SUCCESS) {
      235 +                        be_print_err(gettext("be_activate: failed to set "
      236 +                            "bootfs pool property for %s\n"), root_ds);
      237 +                        goto done;
      238 +                }
 231  239          }
 232  240  
 233  241          if ((zhp = zfs_open(g_zfs, root_ds, ZFS_TYPE_FILESYSTEM)) != NULL) {
 234  242                  /*
 235  243                   * We don't need to close the zfs handle at this
 236  244                   * point because The callback funtion
 237  245                   * be_promote_ds_callback() will close it for us.
 238  246                   */
 239  247                  if (be_promote_ds_callback(zhp, NULL) != 0) {
 240  248                          be_print_err(gettext("be_activate: "
 241  249                              "failed to activate the "
 242  250                              "datasets for %s: %s\n"),
 243  251                              root_ds,
 244  252                              libzfs_error_description(g_zfs));
 245  253                          ret = BE_ERR_PROMOTE;
 246  254                          goto done;
 247  255                  }
 248  256          } else {
 249      -                be_print_err(gettext("be_activate:: failed to open "
      257 +                be_print_err(gettext("be_activate: failed to open "
 250  258                      "dataset (%s): %s\n"), root_ds,
 251  259                      libzfs_error_description(g_zfs));
 252  260                  ret = zfs_err_to_be_err(g_zfs);
 253  261                  goto done;
 254  262          }
 255  263  
 256  264          if (getzoneid() == GLOBAL_ZONEID &&
 257  265              be_get_uuid(cb.obe_root_ds, &uu) == BE_SUCCESS &&
 258  266              (ret = be_promote_zone_ds(cb.obe_name, cb.obe_root_ds))
 259  267              != BE_SUCCESS) {
 260  268                  be_print_err(gettext("be_activate: failed to promote "
 261  269                      "the active zonepath datasets for zones in BE %s\n"),
 262  270                      cb.obe_name);
 263  271          }
 264  272  
      273 +        if (getzoneid() != GLOBAL_ZONEID) {
      274 +                if (!be_zone_compare_uuids(root_ds)) {
      275 +                        be_print_err(gettext("be_activate: activating zone "
      276 +                            "root dataset from non-active global BE is not "
      277 +                            "supported\n"));
      278 +                        ret = BE_ERR_NOTSUP;
      279 +                        goto done;
      280 +                }
      281 +                if ((zhp = zfs_open(g_zfs, root_ds,
      282 +                    ZFS_TYPE_FILESYSTEM)) == NULL) {
      283 +                        be_print_err(gettext("be_activate: failed to open "
      284 +                            "dataset (%s): %s\n"), root_ds,
      285 +                            libzfs_error_description(g_zfs));
      286 +                        ret = zfs_err_to_be_err(g_zfs);
      287 +                        goto done;
      288 +                }
      289 +                /* Find current active zone root dataset */
      290 +                if ((ret = be_find_active_zone_root(zhp, cb.obe_zpool,
      291 +                    active_ds, sizeof (active_ds))) != BE_SUCCESS) {
      292 +                        be_print_err(gettext("be_activate: failed to find "
      293 +                            "active zone root dataset\n"));
      294 +                        ZFS_CLOSE(zhp);
      295 +                        goto done;
      296 +                }
      297 +                /* Do nothing if requested BE is already active */
      298 +                if (strcmp(root_ds, active_ds) == 0) {
      299 +                        ret = BE_SUCCESS;
      300 +                        ZFS_CLOSE(zhp);
      301 +                        goto done;
      302 +                }
      303 +
      304 +                /* Set active property for BE */
      305 +                if (zfs_prop_set(zhp, BE_ZONE_ACTIVE_PROPERTY, "on") != 0) {
      306 +                        be_print_err(gettext("be_activate: failed to set "
      307 +                            "active property (%s): %s\n"), root_ds,
      308 +                            libzfs_error_description(g_zfs));
      309 +                        ret = zfs_err_to_be_err(g_zfs);
      310 +                        ZFS_CLOSE(zhp);
      311 +                        goto done;
      312 +                }
      313 +                ZFS_CLOSE(zhp);
      314 +
      315 +                /* Unset active property for old active root dataset */
      316 +                if ((zhp = zfs_open(g_zfs, active_ds,
      317 +                    ZFS_TYPE_FILESYSTEM)) == NULL) {
      318 +                        be_print_err(gettext("be_activate: failed to open "
      319 +                            "dataset (%s): %s\n"), active_ds,
      320 +                            libzfs_error_description(g_zfs));
      321 +                        ret = zfs_err_to_be_err(g_zfs);
      322 +                        goto done;
      323 +                }
      324 +                if (zfs_prop_set(zhp, BE_ZONE_ACTIVE_PROPERTY, "off") != 0) {
      325 +                        be_print_err(gettext("be_activate: failed to unset "
      326 +                            "active property (%s): %s\n"), active_ds,
      327 +                            libzfs_error_description(g_zfs));
      328 +                        ret = zfs_err_to_be_err(g_zfs);
      329 +                        ZFS_CLOSE(zhp);
      330 +                        goto done;
      331 +                }
      332 +                ZFS_CLOSE(zhp);
      333 +        }
 265  334  done:
 266  335          be_free_list(be_nodes);
 267  336          return (ret);
 268  337  }
 269  338  
 270  339  /*
 271  340   * Function:    be_activate_current_be
 272  341   * Description: Set the currently "active" BE to be "active on boot"
 273  342   * Paramters:
 274  343   *              none
↓ open down ↓ 917 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX