/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/*
* System includes
*/
#include <assert.h>
#include <errno.h>
#include <libintl.h>
#include <libnvpair.h>
#include <libzfs.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <libbe.h>
#include <libbe_priv.h>
typedef struct active_zone_root_data {
char *zoneroot_ds;
typedef struct mounted_zone_root_data {
char *zone_altroot;
char *zoneroot_ds;
/* Private function prototypes */
static int be_find_active_zone_root_callback(zfs_handle_t *, void *);
static int be_find_mounted_zone_root_callback(zfs_handle_t *, void *);
/* ******************************************************************** */
/* Semi-Private Functions */
/* ******************************************************************** */
/*
* Function: be_make_zoneroot
* Description: Generate a string for a zone's zoneroot given the
* zone's zonepath.
* Parameters:
* zonepath - pointer to zonepath
* zoneroot - pointer to buffer to return zoneroot in.
* zoneroot_size - size of zoneroot
* Returns:
* None
* Scope:
* Semi-private (library wise use only)
*/
void
{
}
/*
* Function: be_zone_get_zpool_analog
* Description: This function gets the zpool 'analog' for the currently
* booted Solaris Container. The zpool 'analog' is the
* solaris container equivalent to the zpool portion of a global
* zone BE's root dataset. For a non-global zone BE dataset
* Parameters:
* p_analog - pointer to a char * to return the zpool analog
* Returns:
* BE_SUCCESS - Success
* be_errno_t - Failure
* Scope:
* Private
*/
int
{
"supported in a scratch mounted zone.\n"));
return (BE_ERR_ZONE_NOTSUP);
}
return (BE_SUCCESS);
}
/*
* Function: be_zone_toggle_active
* Description: This function sets or unsets the active property of
* a zone root dataset.
* Parameters:
* root_ds - Root dataset of the nested BE to set active
* Returns:
* be_errno_t - Failure
* BE_SUCCESS - Success
* Scope:
* Private
*/
int
{
/* Get handle to the BE's root dataset */
"root dataset (%s): %s\n"), root_ds,
return (zfs_err_to_be_err(g_zfs));
}
if (be_zone_is_active(zhp)) {
"unset active property for BE: %s\n"),
zfs_get_name(zhp));
goto done;
}
} else {
"set active property for BE: %s\n"),
zfs_get_name(zhp));
}
}
done:
return (ret);
}
/*
* Function: be_find_active_zone_root
* Description: This function will find the active zone root of a zone for
* a given global BE when called in a global zone context.
* In a local zone context it will find the active zone BE.
* It will iterate all of the zone roots under a zonepath, find the
* zone roots that belong to the specified global BE, and return
* the one that is active.
* Parameters:
* be_zhp - zfs handle to global BE root dataset.
* zonepath_ds - pointer to zone's zonepath dataset. In a local
* zone context, this is equivalent to the zone's 'zpool analog'.
* zoneroot_ds - pointer to a buffer to store the dataset name of
* the zone's zoneroot that's currently active for this
* given global zone BE.
* zoneroot-ds_size - size of zoneroot_ds.
* Returns:
* BE_SUCCESS - Success
* be_errno_t - Failure
* Scope:
* Semi-private (library wide use only)
*/
int
char *zoneroot_ds, int zoneroot_ds_size)
{
if (getzoneid() == GLOBAL_ZONEID) {
/* Get the uuid of the parent global BE */
"to get uuid for BE root dataset %s\n"),
return (ret);
}
/*
* Generate string for the root container dataset for this
* zone.
*/
sizeof (zone_rpool_ds));
sizeof (zone_container_ds));
} else {
"failed to get parentbe uuid for BE root "
return (ret);
}
sizeof (zone_container_ds));
}
/* Get handle to this zone's root container dataset */
== NULL) {
"open zone root container dataset (%s): %s\n"),
return (zfs_err_to_be_err(g_zfs));
}
/*
* Iterate through all of this zone's BEs, looking for ones
* that belong to the parent global BE, and finding the one
* that is marked active.
*/
&azr_data)) != 0) {
"find active zone root in zonepath dataset %s: %s\n"),
goto done;
}
} else {
"find active zone root in zonepath dataset %s\n"),
}
done:
return (ret);
}
/*
* Function: be_find_mounted_zone_root
* Description: This function will find the dataset mounted as the zoneroot
* of a zone for a given mounted global BE.
* Parameters:
* zone_altroot - path of zoneroot wrt the mounted global BE.
* zonepath_ds - dataset of the zone's zonepath.
* zoneroot_ds - pointer to a buffer to store the dataset of
* the zoneroot that currently mounted for this zone
* in the mounted global BE.
* zoneroot_ds_size - size of zoneroot_ds
* Returns:
* BE_SUCCESS - Success
* be_errno_t - Failure
* Scope:
* Semi-private (library wide use only)
*/
int
char *zoneroot_ds, int zoneroot_ds_size)
{
int zret = 0;
/* Generate string for the root container dataset for this zone. */
sizeof (zone_rpool_ds));
sizeof (zone_container_ds));
/* Get handle to this zone's root container dataset. */
== NULL) {
"open zone root container dataset (%s): %s\n"),
return (zfs_err_to_be_err(g_zfs));
}
/*
* Iterate through all of the zone's BEs, looking for the one
* that is currently mounted at the zone altroot in the mounted
* global BE.
*/
be_find_mounted_zone_root_callback, &mzr_data)) == 0) {
"find mounted zone under altroot zonepath %s\n"),
goto done;
} else if (zret < 0) {
"zfs_iter_filesystems failed: %s\n"),
goto done;
}
}
done:
return (ret);
}
/*
* Function: be_zone_supported
* Description: This function will determine if a zone is supported
* based on its zonepath dataset. The zonepath dataset
* must:
* - not be under any global BE root dataset.
* - have a root container dataset underneath it.
*
* Parameters:
* zonepath_ds - name of dataset of the zonepath of the
* zone to check.
* Returns:
* B_TRUE - zone is supported
* B_FALSE - zone is not supported
* Scope:
* Semi-private (library wide use only)
*/
{
int ret = 0;
/*
* Make sure the dataset for the zonepath is not hierarchically
* under any reserved BE root container dataset of any pool.
*/
zonepath_ds)) > 0) {
"zonepath dataset %s not supported\n"), zonepath_ds);
return (B_FALSE);
} else if (ret < 0) {
"zpool_iter failed: %s\n"),
return (B_FALSE);
}
/*
* Make sure the zonepath has a zone root container dataset
* underneath it.
*/
sizeof (zone_rpool_ds));
sizeof (zone_container_ds));
"zonepath dataset (%s) does not have a zone root container "
"dataset, zone is not supported, skipping ...\n"),
return (B_FALSE);
}
return (B_TRUE);
}
/*
* Function: be_get_supported_brandlist
* Desciption: This functions retuns a list of supported brands in
* a zoneBrandList_t object.
* Parameters:
* None
* Returns:
* Failure - NULL if no supported brands found.
* Success - pointer to zoneBrandList structure.
* Scope:
* Semi-private (library wide use only)
*/
{
}
/*
* Function: be_zone_is_bootable
* Description: This function checks to see if a BE root dataset
* is bootable (ie is associated with the current
* active global zone).
* Parameters:
* root_ds - dataset name of a zone root dataset
* Returns:
* B_TRUE - Success, BE is bootable
* B_FALSE - Failure, BE is not bootable
* Scope:
* Private
*/
&cbe_parentbe_id) != BE_SUCCESS) {
"current be parent id\n"));
return (B_FALSE);
}
"new be parent id\n"));
return (B_FALSE);
}
return (B_FALSE);
}
return (B_TRUE);
}
/*
* Function: be_zone_get_parent_id
* Description: This function gets the parentbe property of a zone root
* dataset, parsed it into internal uuid format, and returns
* it in the uuid_t reference pointer passed in.
* Parameters:
* root_ds - dataset name of a zone root dataset
* uu - pointer to a uuid_t to return the parentbe uuid in
* Returns:
* BE_SUCCESS - Success
* be_errno_t - Failure
* Scope:
* Private
*/
int
{
/* Get handle to zone root dataset */
"open zone root dataset (%s): %s\n"), root_ds,
return (zfs_err_to_be_err(g_zfs));
}
/* Get user properties for zone root dataset */
"failed to get user properties for zone root "
"dataset (%s): %s\n"), root_ds,
goto done;
}
/* Get UUID string from zone's root dataset user properties */
&uu_string) != 0) {
"get parent uuid property from zone root dataset user "
"properties.\n"));
goto done;
}
/* Parse the uuid string into internal format */
"parse parentuuid\n"));
}
done:
return (ret);
}
/*
* Function: be_zone_set_parent_id
* Description: This function sets the parent uuid property of a zone root
* dataset.
* Parameters:
* root_ds - Root dataset of the BE to set active
* parent_uuid - Value for parent uuid property
* Returns:
* be_errno_t - Failure
* BE_SUCCESS - Success
* Scope:
* Private
*/
int
{
/* Get handle to the BE's root dataset */
"BE root dataset (%s): %s\n"), root_ds,
return (zfs_err_to_be_err(g_zfs));
}
"parent id property for BE: %s\n"),
}
return (ret);
}
/* ******************************************************************** */
/* Private Functions */
/* ******************************************************************** */
/*
* Function: be_find_active_zone_root_callback
* Description: This function is used as a callback to iterate over all of
* a zone's root datasets, finding the one that is marked active
* for the parent BE specified in the data passed in. The name
* of the zone's active root dataset is returned in heap storage
* in the active_zone_root_data_t structure passed in, so the
* caller is responsible for freeing it.
* Parameters:
* zhp - zfs_handle_t pointer to current dataset being processed
* data - active_zone_root_data_t pointer
* Returns:
* 0 - Success
* >0 - Failure
* Scope:
* Private
*/
static int
{
int iret = 0;
int ret = 0;
!= BE_SUCCESS) {
"skipping zone root dataset (%s): %s\n"),
goto done;
}
/*
* Found a zone root dataset belonging to the right parent,
* check if its active.
*/
if (be_zone_is_active(zhp)) {
/*
* Found active zone root dataset, if its already
* set in the callback data, that means this
* is the second one we've found. Return error.
*/
goto done;
}
ret = BE_ERR_NOMEM;
}
}
}
done:
return (ret);
}
/*
* Function: be_find_mounted_zone_root_callback
* Description: This function is used as a callback to iterate over all of
* a zone's root datasets, find the one that is currently
* mounted for the parent BE specified in the data passed in.
* The name of the zone's mounted root dataset is returned in
* heap storage the mounted_zone_data_t structure passed in,
* so the caller is responsible for freeing it.
* Parameters:
* zhp - zfs_handle_t pointer to the current dataset being
* processed
* data - mounted_zone_data_t pointer
* Returns:
* 0 - not mounted as zone's root
* 1 - this dataset is mounted as zone's root
* Scope:
* Private
*/
static int
{
return (1);
}
return (0);
}
/*
* Function: be_zone_is_active
* Description: This function gets the active property of a zone root
* dataset, and returns true if active property is on.
* Parameters:
* zfs - zfs_handle_t pointer to zone root dataset to check
* Returns:
* B_TRUE - zone root dataset is active
* B_FALSE - zone root dataset is not active
* Scope:
* Private
*/
{
/* Get user properties for the zone root dataset */
"failed to get user properties for zone root "
return (B_FALSE);
}
/* Get active property from the zone root dataset user properties */
!= 0) {
/* BE_ZONE_ACTIVE_PROPERTY was not found */
return (B_FALSE);
}
return (B_TRUE);
/* BE_ZONE_ACTIVE_PROPERTY was found but not set to 'on' */
return (B_FALSE);
}