uadmin.c revision 753a6d457b330b1b29b2d3eefcd0831116ce950d
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * CDDL HEADER START
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner * The contents of this file are subject to the terms of the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Common Development and Distribution License (the "License").
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * You may not use this file except in compliance with the License.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * See the License for the specific language governing permissions
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * and limitations under the License.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * When distributing Covered Code, include this CDDL HEADER in each
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * If applicable, add the following below this CDDL HEADER, with the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * fields enclosed by brackets "[]" replaced with your own identifying
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * information: Portions Copyright [yyyy] [name of copyright owner]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * CDDL HEADER END
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Use is subject to license terms.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Administrivia system call. We provide this in two flavors: one for calling
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * from the system call path (uadmin), and the other for calling from elsewhere
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * within the kernel (kadmin). Callers must beware that certain uadmin cmd
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * values (specifically A_SWAPCTL) are only supported by uadmin and not kadmin.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinvolatile int fastreboot_dryrun = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Kill all user processes in said zone. A special argument of ALL_ZONES is
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * passed in when the system as a whole is shutting down. The lack of per-zone
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * process lists is likely to make the following a performance bottleneck on a
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * system with many zones.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Kill all processes except kernel daemons and ourself.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Make a first pass to stop all processes so they won't
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * be trying to restart children as we kill them.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((zoneid == ALL_ZONES || p->p_zone->zone_id == zoneid) &&
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while (p != NULL) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((zoneid == ALL_ZONES || p->p_zone->zone_id == zoneid) &&
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * We might be called directly by the kernel's fault-handling code, so
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * we can't assert that the caller is in the global zone.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Make sure that cmd is one of the valid <sys/uadmin.h> command codes
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * and that we have appropriate privileges for this action.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin switch (cmd) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Serialize these operations on ualock. If it is held, the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * system should shutdown, reboot, or remount shortly, unless there is
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * an error. We need a cv rather than just a mutex because proper
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * functioning of A_REBOOT relies on being able to interrupt blocked
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * userland callers.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * We only clear ua_shutdown_thread after A_REMOUNT or A_CONFIG.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Other commands should never return.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (cmd == A_SHUTDOWN || cmd == A_REBOOT || cmd == A_REMOUNT ||
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * If we were interrupted, leave, and handle
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * the signal (or exit, depending on what
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * happened)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin switch (cmd) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Release (almost) all of our own resources if we are called
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * from a user context, however if we are calling kadmin() from
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * a kernel context then we do not release these resources.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (p != &p0) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Another thread in this process also called
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * exitlwps().
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Reset t_cred if not set because much of the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * filesystem code depends on CRED() being valid.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* indicate shutdown in progress */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Communcate that init shouldn't be restarted.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * If we are calling kadmin() from a kernel context then we
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * do not release these resources.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Allow the reboot/halt/poweroff code a chance to do
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * anything it needs to whilst we still have filesystems
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * mounted, like loading any modules necessary for later
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * performing the actual poweroff.
vfs_syncall();
case A_REBOOT:
case A_CONFIG:
switch (fcn) {
case AD_UPDATE_BOOT_CONFIG:
#ifndef __sparc
extern int fastreboot_capable;
extern void fastboot_update_config(const char *);
if (fastreboot_capable)
case A_REMOUNT:
case A_FREEZE:
extern int cpr(int, void *);
return (ENOTSUP);
case A_FTRACE:
switch (fcn) {
case AD_FTRACE_START:
(void) FTRACE_START();
case AD_FTRACE_STOP:
(void) FTRACE_STOP();
case A_DUMP:
#ifndef __sparc
extern int fastreboot_onpanic;
extern void fastboot_update_config(const char *);
fastreboot_onpanic = 0;
if (fastreboot_onpanic) {
extern void fastboot_load_kernel(char *);
case A_SDTTEST:
return (error);
int reset_status = 0;
&reset_status);
if (reset_status != 0)
return (EIO);
#if defined(_SYSCALL32_IMPL)