/*
* 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
*/
/*
*/
/*
* Copyright 2013 Nexenta Systems, Inc. All rights reserved.
*/
/*
* 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 retrn zoneroot in.
* zoneroot_size - size of zoneroot
* Returns:
* None
* Scope:
* Semi-private (library wise use only)
*/
void
{
}
/*
* Function: be_find_active_zone_root
* Description: This function will find the active zone root of a zone for
* a given global 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.
* zoneroot_ds - pointer to a buffer to store the dataset name of
* the zone's zoneroot that's currently active for this
* given 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)
{
/* Get the uuid of the parent global BE */
if (getzoneid() == GLOBAL_ZONEID) {
"to get uuid for BE root dataset %s\n"),
return (ret);
}
} else {
"to get parentbe uuid for zone root dataset %s\n"),
return (ret);
}
}
/* Generate string for the root container dataset for this zone. */
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_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_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_get_parent_uuid
* 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_uuid
* Description: This function sets parentbe uuid into
* a zfs user property for a root zone dataset.
* Parameters:
* root_ds - Root zone dataset of the BE to set a uuid on.
* Return:
* be_errno_t - Failure
* BE_SUCCESS - Success
* Scope:
* Semi-private (library wide uses only)
*/
int
{
/* Get handle to the root zone dataset. */
"open root zone dataset (%s): %s\n"), root_ds,
return (zfs_err_to_be_err(g_zfs));
}
/* Set parentbe uuid property for the root zone dataset */
"set parentbe uuid property for root zone dataset: %s\n"),
}
return (ret);
}
/*
* Function: be_zone_compare_uuids
* Description: This function compare the parentbe uuid of the
* current running root zone dataset with the parentbe
* uuid of the given root zone dataset.
* Parameters:
* root_ds - Root zone dataset of the BE to compare.
* Return:
* B_TRUE - root dataset has right parentbe uuid
* B_FALSE - root dataset has wrong parentbe uuid
* Scope:
* Semi-private (library wide uses only)
*/
{
char *active_ds;
/* Get parentbe uuid from given zone root dataset */
&parent_uuid)) != BE_SUCCESS) {
"parentbe uuid from the given BE\n"));
return (B_FALSE);
}
/*
* Find current running zone root dataset and get it's parentbe
* uuid property.
*/
&cur_parent_uuid)) != BE_SUCCESS) {
"to get parentbe uuid from the current running zone "
"root dataset\n"));
return (B_FALSE);
}
} else {
"is not mounted\n"));
return (B_FALSE);
}
return (B_FALSE);
}
return (B_TRUE);
}
/* ******************************************************************** */
/* 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_get_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_get_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
*/
static boolean_t
{
/* 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) {
return (B_FALSE);
}
return (B_TRUE);
return (B_FALSE);
}