/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Module: zones_states.c
* Group: libinstzones
* Description: Provide "zones" state interfaces for install consolidation code
*
* Public Methods:
*
* z_make_zone_running - change state of non-global zone to "running"
* _z_make_zone_ready - change state of non-global zone to "ready"
* _z_make_zone_down - change state of non-global zone to "down"
*/
/*
* System includes
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <ctype.h>
#include <string.h>
#include <strings.h>
#include <stdarg.h>
#include <limits.h>
#include <errno.h>
#include <stropts.h>
#include <libintl.h>
#include <locale.h>
#include <assert.h>
/*
* local includes
*/
#include "instzones_lib.h"
#include "zones_strings.h"
/*
* Private structures
*/
/*
* Library Function Prototypes
*/
/*
* Local Function Prototypes
*/
/*
* global internal (private) declarations
*/
/*
* *****************************************************************************
* global external (public) functions
* *****************************************************************************
*/
/*
* Name: _z_make_zone_running
* Description: Given a zone element entry for the non-global zone to affect,
* change the state of that non-global zone to "running"
* Arguments: a_zlem - [RO, *RW] - (zoneListElement_t)
* Zone list element describing the non-global zone to
* make running
* Returns: boolean_t
* B_TRUE - non-global zone state changed successfully
* B_FALSE - failed to make the non-global zone run
*/
{
int ret;
int status = 0;
/* entry assertions */
/* act based on the zone's current kernel state */
switch (a_zlem->_zlCurrKernelStatus) {
case ZONE_STATE_RUNNING:
case ZONE_STATE_MOUNTED:
/* already running */
return (B_TRUE);
case ZONE_STATE_READY:
/* This should never happen */
if (zonecfg_in_alt_root())
return (B_FALSE);
/*
* We're going to upset the zone anyway, so might as well just
* halt it now and fall through to normal mounting.
*/
/* free generated argument list */
if (ret != 0) {
return (B_FALSE);
}
if (status != 0) {
if (status == -1) {
} else {
}
return (B_FALSE);
}
/* FALLTHROUGH */
case ZONE_STATE_INSTALLED:
case ZONE_STATE_DOWN:
/* return false if the zone cannot be booted */
return (B_FALSE);
}
/* these states can be booted - do so */
if (zonecfg_in_alt_root()) {
(char *)zonecfg_get_root());
}
/* free generated argument list */
if (ret != 0) {
return (B_FALSE);
}
if (status != 0) {
if (status == -1) {
} else {
}
/* remember this zone cannot be booted */
return (B_FALSE);
}
if (zonecfg_in_alt_root()) {
sizeof (zonename)) == -1) {
return (B_FALSE);
}
}
return (B_TRUE);
case ZONE_STATE_CONFIGURED:
case ZONE_STATE_INCOMPLETE:
case ZONE_STATE_SHUTTING_DOWN:
default:
/* cannot transition (boot) these states */
return (B_FALSE);
}
}
/*
* Name: _z_make_zone_ready
* Description: Given a zone element entry for the non-global zone to affect,
* restore the ready state of the zone when the zone is currently
* in the running state.
* Arguments: a_zlem - [RO, *RW] - (zoneListElement_t)
* Zone list element describing the non-global zone to
* make ready
* Returns: boolean_t
* B_TRUE - non-global zone state changed successfully
* B_FALSE - failed to make the non-global zone ready
*/
{
int status = 0;
int i;
int ret;
/* entry assertions */
/* act based on the zone's current kernel state */
switch (a_zlem->_zlCurrKernelStatus) {
case ZONE_STATE_DOWN:
case ZONE_STATE_READY:
/* already down */
return (B_TRUE);
case ZONE_STATE_MOUNTED:
if (ret != 0) {
return (B_FALSE);
}
if (status != 0) {
if (status == -1) {
} else {
}
}
return (B_FALSE);
}
}
if (ret != 0) {
return (B_FALSE);
}
if (status != 0) {
}
return (B_FALSE);
}
}
/* success - zone is now in the ready state */
return (B_TRUE);
case ZONE_STATE_RUNNING:
/* free generated argument list */
if (ret != 0) {
return (B_FALSE);
}
if (status != 0) {
}
return (B_FALSE);
}
}
for (i = 0; i < MAX_RETRIES; i++) {
break;
}
if ((st == ZONE_STATE_DOWN) ||
(st == ZONE_STATE_INSTALLED)||
(st == ZONE_STATE_READY)) {
break;
}
(void) sleep(RETRY_DELAY_SECS);
}
/* failure if maximum retries reached */
if (i >= MAX_RETRIES) {
return (B_FALSE);
}
/* success - zone is now in the ready state */
return (B_TRUE);
case ZONE_STATE_INSTALLED:
case ZONE_STATE_CONFIGURED:
case ZONE_STATE_INCOMPLETE:
case ZONE_STATE_SHUTTING_DOWN:
default:
return (B_FALSE);
}
}
/*
* Name: _z_make_zone_down
* Description: Given a zone element entry for the non-global zone to affect,
* change the state of that non-global zone to "down"
* Arguments: a_zlem - [RO, *RW] - (zoneListElement_t)
* Zone list element describing the non-global zone to
* make down
* Returns: boolean_t
* B_TRUE - non-global zone state changed successfully
* B_FALSE - failed to make the non-global zone down
*/
{
int status = 0;
int ret;
/* entry assertions */
/* act based on the zone's current kernel state */
switch (a_zlem->_zlCurrKernelStatus) {
case ZONE_STATE_DOWN:
case ZONE_STATE_READY:
case ZONE_STATE_RUNNING:
/* shouldn't be touched */
return (B_TRUE);
case ZONE_STATE_MOUNTED:
/* these states can be halted - do so */
if (zonecfg_in_alt_root()) {
(char *)zonecfg_get_root());
}
/* free generated argument list */
if (ret != 0) {
return (B_FALSE);
}
if (status != 0) {
if (status == -1) {
} else {
}
return (B_FALSE);
}
/*
* Leave the scratch name in place because the upper level
* software may have used it to construct file names and the
* like.
*/
return (B_TRUE);
case ZONE_STATE_INSTALLED:
case ZONE_STATE_CONFIGURED:
case ZONE_STATE_INCOMPLETE:
case ZONE_STATE_SHUTTING_DOWN:
default:
return (B_FALSE);
}
}
/*
* Function: UmountAllZones
* Description: Unmount all mounted zones under a specified directory.
*
* Scope: public
* Parameters: mntpnt [RO, *RO]
* Non-NULL pointer to name of directory to be unmounted.
* Return: 0 - successfull
* -1 - unmount failed; see errno for reason
*/
int
int k;
int ret = 0;
if (z_zones_are_implemented()) {
return (0);
}
k++) {
if (z_zlist_get_current_state(zlst, k) >
if (!z_zlist_change_zone_state(zlst, k,
ret = -1;
break;
}
}
}
/* Free zlst */
}
return (ret);
}