Print this page
*** NO COMMENTS ***


   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 
  26 /*




  27  * System includes
  28  */
  29 #include <assert.h>
  30 #include <errno.h>
  31 #include <libintl.h>
  32 #include <libnvpair.h>
  33 #include <libzfs.h>
  34 #include <stdio.h>
  35 #include <stdlib.h>
  36 #include <string.h>
  37 #include <sys/mntent.h>
  38 #include <sys/mnttab.h>
  39 #include <sys/mount.h>
  40 #include <sys/stat.h>
  41 #include <sys/types.h>
  42 #include <sys/vfstab.h>
  43 #include <unistd.h>
  44 
  45 #include <libbe.h>
  46 #include <libbe_priv.h>


  96  *              zoneroot_ds - pointer to a buffer to store the dataset name of
  97  *                      the zone's zoneroot that's currently active for this
  98  *                      given global BE..
  99  *              zoneroot-ds_size - size of zoneroot_ds.
 100  * Returns:
 101  *              BE_SUCCESS - Success
 102  *              be_errno_t - Failure
 103  * Scope:
 104  *              Semi-private (library wide use only)
 105  */
 106 int
 107 be_find_active_zone_root(zfs_handle_t *be_zhp, char *zonepath_ds,
 108     char *zoneroot_ds, int zoneroot_ds_size)
 109 {
 110         active_zone_root_data_t         azr_data = { 0 };
 111         zfs_handle_t                    *zhp;
 112         char                            zone_container_ds[MAXPATHLEN];
 113         int                             ret = BE_SUCCESS;
 114 
 115         /* 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);
 121         }









 122 
 123         /* Generate string for the root container dataset for this zone. */
 124         be_make_container_ds(zonepath_ds, zone_container_ds,
 125             sizeof (zone_container_ds));
 126 
 127         /* Get handle to this zone's root container dataset */
 128         if ((zhp = zfs_open(g_zfs, zone_container_ds, ZFS_TYPE_FILESYSTEM))
 129             == NULL) {
 130                 be_print_err(gettext("be_find_active_zone_root: failed to "
 131                     "open zone root container dataset (%s): %s\n"),
 132                     zone_container_ds, libzfs_error_description(g_zfs));
 133                 return (zfs_err_to_be_err(g_zfs));
 134         }
 135 
 136         /*
 137          * Iterate through all of this zone's BEs, looking for ones
 138          * that belong to the parent global BE, and finding the one
 139          * that is marked active.
 140          */
 141         if ((ret = zfs_iter_filesystems(zhp, be_find_active_zone_root_callback,


 359             &uu_string) != 0) {
 360                 be_print_err(gettext("be_zone_get_parent_uuid: failed to "
 361                     "get parent uuid property from zone root dataset user "
 362                     "properties.\n"));
 363                 ret = BE_ERR_ZONE_NO_PARENTBE;
 364                 goto done;
 365         }
 366 
 367         /* Parse the uuid string into internal format */
 368         if (uuid_parse(uu_string, *uu) != 0 || uuid_is_null(*uu)) {
 369                 be_print_err(gettext("be_zone_get_parent_uuid: failed to "
 370                     "parse parentuuid\n"));
 371                 ret = BE_ERR_PARSE_UUID;
 372         }
 373 
 374 done:
 375         ZFS_CLOSE(zhp);
 376         return (ret);
 377 }
 378 






























































































 379 /* ******************************************************************** */
 380 /*                      Private Functions                               */
 381 /* ******************************************************************** */
 382 
 383 /*
 384  * Function:    be_find_active_zone_root_callback
 385  * Description: This function is used as a callback to iterate over all of
 386  *              a zone's root datasets, finding the one that is marked active
 387  *              for the parent BE specified in the data passed in.  The name
 388  *              of the zone's active root dataset is returned in heap storage
 389  *              in the active_zone_root_data_t structure passed in, so the
 390  *              caller is responsible for freeing it.
 391  * Parameters:
 392  *              zhp - zfs_handle_t pointer to current dataset being processed
 393  *              data - active_zone_root_data_t pointer
 394  * Returns:
 395  *              0 - Success
 396  *              >0 - Failure
 397  * Scope:
 398  *              Private




   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 
  26 /*
  27  * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
  28  */
  29 
  30 /*
  31  * System includes
  32  */
  33 #include <assert.h>
  34 #include <errno.h>
  35 #include <libintl.h>
  36 #include <libnvpair.h>
  37 #include <libzfs.h>
  38 #include <stdio.h>
  39 #include <stdlib.h>
  40 #include <string.h>
  41 #include <sys/mntent.h>
  42 #include <sys/mnttab.h>
  43 #include <sys/mount.h>
  44 #include <sys/stat.h>
  45 #include <sys/types.h>
  46 #include <sys/vfstab.h>
  47 #include <unistd.h>
  48 
  49 #include <libbe.h>
  50 #include <libbe_priv.h>


 100  *              zoneroot_ds - pointer to a buffer to store the dataset name of
 101  *                      the zone's zoneroot that's currently active for this
 102  *                      given global BE..
 103  *              zoneroot-ds_size - size of zoneroot_ds.
 104  * Returns:
 105  *              BE_SUCCESS - Success
 106  *              be_errno_t - Failure
 107  * Scope:
 108  *              Semi-private (library wide use only)
 109  */
 110 int
 111 be_find_active_zone_root(zfs_handle_t *be_zhp, char *zonepath_ds,
 112     char *zoneroot_ds, int zoneroot_ds_size)
 113 {
 114         active_zone_root_data_t         azr_data = { 0 };
 115         zfs_handle_t                    *zhp;
 116         char                            zone_container_ds[MAXPATHLEN];
 117         int                             ret = BE_SUCCESS;
 118 
 119         /* Get the uuid of the parent global BE */
 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                 }
 136         }
 137 
 138         /* Generate string for the root container dataset  for this zone. */
 139         be_make_container_ds(zonepath_ds, zone_container_ds,
 140             sizeof (zone_container_ds));
 141 
 142         /* Get handle to this zone's root container dataset */
 143         if ((zhp = zfs_open(g_zfs, zone_container_ds, ZFS_TYPE_FILESYSTEM))
 144             == NULL) {
 145                 be_print_err(gettext("be_find_active_zone_root: failed to "
 146                     "open zone root container dataset (%s): %s\n"),
 147                     zone_container_ds, libzfs_error_description(g_zfs));
 148                 return (zfs_err_to_be_err(g_zfs));
 149         }
 150 
 151         /*
 152          * Iterate through all of this zone's BEs, looking for ones
 153          * that belong to the parent global BE, and finding the one
 154          * that is marked active.
 155          */
 156         if ((ret = zfs_iter_filesystems(zhp, be_find_active_zone_root_callback,


 374             &uu_string) != 0) {
 375                 be_print_err(gettext("be_zone_get_parent_uuid: failed to "
 376                     "get parent uuid property from zone root dataset user "
 377                     "properties.\n"));
 378                 ret = BE_ERR_ZONE_NO_PARENTBE;
 379                 goto done;
 380         }
 381 
 382         /* Parse the uuid string into internal format */
 383         if (uuid_parse(uu_string, *uu) != 0 || uuid_is_null(*uu)) {
 384                 be_print_err(gettext("be_zone_get_parent_uuid: failed to "
 385                     "parse parentuuid\n"));
 386                 ret = BE_ERR_PARSE_UUID;
 387         }
 388 
 389 done:
 390         ZFS_CLOSE(zhp);
 391         return (ret);
 392 }
 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 
 488 /* ******************************************************************** */
 489 /*                      Private Functions                               */
 490 /* ******************************************************************** */
 491 
 492 /*
 493  * Function:    be_find_active_zone_root_callback
 494  * Description: This function is used as a callback to iterate over all of
 495  *              a zone's root datasets, finding the one that is marked active
 496  *              for the parent BE specified in the data passed in.  The name
 497  *              of the zone's active root dataset is returned in heap storage
 498  *              in the active_zone_root_data_t structure passed in, so the
 499  *              caller is responsible for freeing it.
 500  * Parameters:
 501  *              zhp - zfs_handle_t pointer to current dataset being processed
 502  *              data - active_zone_root_data_t pointer
 503  * Returns:
 504  *              0 - Success
 505  *              >0 - Failure
 506  * Scope:
 507  *              Private