Print this page
*** NO COMMENTS ***

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 ↓ 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 2011 Nexenta Systems, Inc. All rights reserved.
       27 + * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
  28   28   */
  29   29  
  30   30  /*
  31   31   * System includes
  32   32   */
  33   33  
  34   34  #include <assert.h>
  35   35  #include <ctype.h>
  36   36  #include <errno.h>
  37   37  #include <libgen.h>
↓ open down ↓ 405 lines elided ↑ open up ↑
 443  443                  be_print_err(gettext("be_destroy: zpool_iter failed: %s\n"),
 444  444                      libzfs_error_description(g_zfs));
 445  445                  return (zfs_err_to_be_err(g_zfs));
 446  446          }
 447  447  
 448  448          /* Generate string for obe_name's root dataset */
 449  449          be_make_root_ds(bt.obe_zpool, bt.obe_name, obe_root_ds,
 450  450              sizeof (obe_root_ds));
 451  451          bt.obe_root_ds = obe_root_ds;
 452  452  
      453 +        if (getzoneid() != GLOBAL_ZONEID) {
      454 +                if (!be_zone_compare_uuids(bt.obe_root_ds)) {
      455 +                        if (be_is_active_on_boot(bt.obe_name)) {
      456 +                                be_print_err(gettext("be_destroy: destroying "
      457 +                                    "active zone root dataset from non-active "
      458 +                                    "global BE is not supported\n"));
      459 +                                return (BE_ERR_NOTSUP);
      460 +                        }
      461 +                }
      462 +        }
      463 +
 453  464          /*
 454  465           * Detect if the BE to destroy has the 'active on boot' property set.
 455  466           * If so, set the 'active on boot' property on the the 'active' BE.
 456  467           */
 457  468          if (be_is_active_on_boot(bt.obe_name)) {
 458  469                  if ((ret = be_activate_current_be()) != BE_SUCCESS) {
 459  470                          be_print_err(gettext("be_destroy: failed to "
 460  471                              "make the current BE 'active on boot'\n"));
 461  472                          return (ret);
 462  473                  }
↓ open down ↓ 12 lines elided ↑ open up ↑
 475  486           * Check if BE has snapshots and BE_DESTROY_FLAG_SNAPSHOTS
 476  487           * is not set.
 477  488           */
 478  489          (void) zfs_iter_snapshots(zhp, be_has_snapshot_callback, &bs_found);
 479  490          if (!dd.destroy_snaps && bs_found) {
 480  491                  ZFS_CLOSE(zhp);
 481  492                  return (BE_ERR_SS_EXISTS);
 482  493          }
 483  494  
 484  495          /* Get the UUID of the global BE */
 485      -        if (be_get_uuid(zfs_get_name(zhp), &dd.gz_be_uuid) != BE_SUCCESS) {
 486      -                be_print_err(gettext("be_destroy: BE has no UUID (%s)\n"),
 487      -                    zfs_get_name(zhp));
      496 +        if (getzoneid() == GLOBAL_ZONEID) {
      497 +                if (be_get_uuid(zfs_get_name(zhp),
      498 +                    &dd.gz_be_uuid) != BE_SUCCESS) {
      499 +                        be_print_err(gettext("be_destroy: BE has no "
      500 +                        "UUID (%s)\n"), zfs_get_name(zhp));
      501 +                }
 488  502          }
 489  503  
 490  504          /*
 491  505           * If the global BE is mounted, make sure we've been given the
 492  506           * flag to forcibly unmount it.
 493  507           */
 494  508          if (zfs_is_mounted(zhp, &mp)) {
 495  509                  if (!(dd.force_unmount)) {
 496  510                          be_print_err(gettext("be_destroy: "
 497  511                              "%s is currently mounted at %s, cannot destroy\n"),
↓ open down ↓ 90 lines elided ↑ open up ↑
 588  602   */
 589  603  int
 590  604  be_copy(nvlist_t *be_attrs)
 591  605  {
 592  606          be_transaction_data_t   bt = { 0 };
 593  607          be_fs_list_data_t       fld = { 0 };
 594  608          zfs_handle_t    *zhp = NULL;
 595  609          zpool_handle_t  *zphp = NULL;
 596  610          nvlist_t        *zfs_props = NULL;
 597  611          uuid_t          uu = { 0 };
      612 +        uuid_t          parent_uu = { 0 };
 598  613          char            obe_root_ds[MAXPATHLEN];
 599  614          char            nbe_root_ds[MAXPATHLEN];
 600  615          char            ss[MAXPATHLEN];
 601  616          char            *new_mp = NULL;
 602  617          char            *obe_name = NULL;
 603  618          boolean_t       autoname = B_FALSE;
 604  619          boolean_t       be_created = B_FALSE;
 605  620          int             i;
 606  621          int             zret;
 607  622          int             ret = BE_SUCCESS;
↓ open down ↓ 138 lines elided ↑ open up ↑
 746  761          if (bt.nbe_name) {
 747  762                  /* Validate original BE name */
 748  763                  if (!be_valid_be_name(bt.nbe_name)) {
 749  764                          be_print_err(gettext("be_copy: "
 750  765                              "invalid BE name %s\n"), bt.nbe_name);
 751  766                          ret = BE_ERR_INVAL;
 752  767                          goto done;
 753  768                  }
 754  769  
 755  770                  /* Verify it doesn't already exist */
 756      -                if ((zret = zpool_iter(g_zfs, be_exists_callback, bt.nbe_name))
 757      -                    > 0) {
 758      -                        be_print_err(gettext("be_copy: BE (%s) already "
 759      -                            "exists\n"), bt.nbe_name);
 760      -                        ret = BE_ERR_BE_EXISTS;
 761      -                        goto done;
 762      -                } else if (zret < 0) {
 763      -                        be_print_err(gettext("be_copy: zpool_iter failed: "
 764      -                            "%s\n"), libzfs_error_description(g_zfs));
 765      -                        ret = zfs_err_to_be_err(g_zfs);
 766      -                        goto done;
      771 +                if (getzoneid() == GLOBAL_ZONEID) {
      772 +                        if ((zret = zpool_iter(g_zfs, be_exists_callback,
      773 +                            bt.nbe_name)) > 0) {
      774 +                                be_print_err(gettext("be_copy: BE (%s) already "
      775 +                                    "exists\n"), bt.nbe_name);
      776 +                                ret = BE_ERR_BE_EXISTS;
      777 +                                goto done;
      778 +                        } else if (zret < 0) {
      779 +                                be_print_err(gettext("be_copy: zpool_iter "
      780 +                                    "failed: %s\n"),
      781 +                                    libzfs_error_description(g_zfs));
      782 +                                ret = zfs_err_to_be_err(g_zfs);
      783 +                                goto done;
      784 +                        }
      785 +                } else {
      786 +                        be_make_root_ds(bt.nbe_zpool, bt.nbe_name, nbe_root_ds,
      787 +                            sizeof (nbe_root_ds));
      788 +                        if (zfs_dataset_exists(g_zfs, nbe_root_ds,
      789 +                            ZFS_TYPE_FILESYSTEM)) {
      790 +                                be_print_err(gettext("be_copy: BE (%s) already "
      791 +                                    "exists\n"), bt.nbe_name);
      792 +                                ret = BE_ERR_BE_EXISTS;
      793 +                                goto done;
      794 +                        }
 767  795                  }
 768  796          } else {
 769  797                  /*
 770  798                   * If an auto named BE is desired, it must be in the same
 771  799                   * pool is the original BE.
 772  800                   */
 773  801                  if (bt.nbe_zpool != NULL) {
 774  802                          be_print_err(gettext("be_copy: cannot specify pool "
 775  803                              "name when creating an auto named BE\n"));
 776  804                          ret = BE_ERR_INVAL;
↓ open down ↓ 232 lines elided ↑ open up ↑
1009 1037           */
1010 1038          if ((ret = _be_mount(bt.nbe_name, &new_mp, BE_MOUNT_FLAG_NO_ZONES))
1011 1039              != BE_SUCCESS) {
1012 1040                  be_print_err(gettext("be_copy: failed to "
1013 1041                      "mount newly created BE\n"));
1014 1042                  (void) _be_unmount(bt.nbe_name, 0);
1015 1043                  goto done;
1016 1044          }
1017 1045  
1018 1046          /* Set UUID for new BE */
1019      -        if (be_set_uuid(bt.nbe_root_ds) != BE_SUCCESS) {
1020      -                be_print_err(gettext("be_copy: failed to "
1021      -                    "set uuid for new BE\n"));
     1047 +        if (getzoneid() == GLOBAL_ZONEID) {
     1048 +                if (be_set_uuid(bt.nbe_root_ds) != BE_SUCCESS) {
     1049 +                        be_print_err(gettext("be_copy: failed to "
     1050 +                            "set uuid for new BE\n"));
     1051 +                }
     1052 +        } else {
     1053 +                if ((ret = be_zone_get_parent_uuid(bt.obe_root_ds,
     1054 +                    &parent_uu)) != BE_SUCCESS) {
     1055 +                        be_print_err(gettext("be_copy: failed to get "
     1056 +                            "parentbe uuid from orig BE\n"));
     1057 +                        ret = BE_ERR_ZONE_NO_PARENTBE;
     1058 +                        goto done;
     1059 +                } else if ((ret = be_zone_set_parent_uuid(bt.nbe_root_ds,
     1060 +                    parent_uu)) != BE_SUCCESS) {
     1061 +                        be_print_err(gettext("be_copy: failed to set "
     1062 +                            "parentbe uuid for newly created BE\n"));
     1063 +                        goto done;
     1064 +                }
1022 1065          }
1023 1066  
1024 1067          /*
1025 1068           * Process zones outside of the private BE namespace.
1026 1069           * This has to be done here because we need the uuid set in the
1027 1070           * root dataset of the new BE. The uuid is use to set the parentbe
1028 1071           * property for the new zones datasets.
1029 1072           */
1030 1073          if (getzoneid() == GLOBAL_ZONEID &&
1031 1074              be_get_uuid(bt.obe_root_ds, &uu) == BE_SUCCESS) {
↓ open down ↓ 2026 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX