xref: /illumos-gate/usr/src/uts/common/syscall/uadmin.c (revision 7e12ceb3)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
53f2f09c1Sdp  * Common Development and Distribution License (the "License").
63f2f09c1Sdp  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
2197eda132Sraf 
227c478bd9Sstevel@tonic-gate /*
23753a6d45SSherry Moore  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25a288e5a9SJoshua M. Clulow  * Copyright 2013 Joyent, Inc.  All rights reserved.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <sys/param.h>
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
317c478bd9Sstevel@tonic-gate #include <sys/systm.h>
327c478bd9Sstevel@tonic-gate #include <sys/errno.h>
337c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
347c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
357c478bd9Sstevel@tonic-gate #include <sys/swap.h>
367c478bd9Sstevel@tonic-gate #include <sys/file.h>
377c478bd9Sstevel@tonic-gate #include <sys/proc.h>
387c478bd9Sstevel@tonic-gate #include <sys/var.h>
397c478bd9Sstevel@tonic-gate #include <sys/uadmin.h>
407c478bd9Sstevel@tonic-gate #include <sys/signal.h>
417c478bd9Sstevel@tonic-gate #include <sys/time.h>
427c478bd9Sstevel@tonic-gate #include <vm/seg_kmem.h>
437c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
447c478bd9Sstevel@tonic-gate #include <sys/callb.h>
457c478bd9Sstevel@tonic-gate #include <sys/dumphdr.h>
467c478bd9Sstevel@tonic-gate #include <sys/debug.h>
477c478bd9Sstevel@tonic-gate #include <sys/ftrace.h>
487c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
497c478bd9Sstevel@tonic-gate #include <sys/panic.h>
507c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
51a288e5a9SJoshua M. Clulow #include <sys/ddi_periodic.h>
527c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
537c478bd9Sstevel@tonic-gate #include <sys/policy.h>
547c478bd9Sstevel@tonic-gate #include <sys/zone.h>
55ed0ee1acScg #include <sys/condvar.h>
56ed0ee1acScg #include <sys/thread.h>
5710e6dadfSbrendan #include <sys/sdt.h>
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate /*
607c478bd9Sstevel@tonic-gate  * Administrivia system call.  We provide this in two flavors: one for calling
617c478bd9Sstevel@tonic-gate  * from the system call path (uadmin), and the other for calling from elsewhere
627c478bd9Sstevel@tonic-gate  * within the kernel (kadmin).  Callers must beware that certain uadmin cmd
637c478bd9Sstevel@tonic-gate  * values (specifically A_SWAPCTL) are only supported by uadmin and not kadmin.
647c478bd9Sstevel@tonic-gate  */
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate extern ksema_t fsflush_sema;
677c478bd9Sstevel@tonic-gate kmutex_t ualock;
68ed0ee1acScg kcondvar_t uacond;
69ed0ee1acScg kthread_t *ua_shutdown_thread = NULL;
707c478bd9Sstevel@tonic-gate 
71facf4a8dSllai int sys_shutdown = 0;
7219397407SSherry Moore volatile int fastreboot_dryrun = 0;
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate /*
757c478bd9Sstevel@tonic-gate  * Kill all user processes in said zone.  A special argument of ALL_ZONES is
767c478bd9Sstevel@tonic-gate  * passed in when the system as a whole is shutting down.  The lack of per-zone
777c478bd9Sstevel@tonic-gate  * process lists is likely to make the following a performance bottleneck on a
787c478bd9Sstevel@tonic-gate  * system with many zones.
797c478bd9Sstevel@tonic-gate  */
807c478bd9Sstevel@tonic-gate void
killall(zoneid_t zoneid)817c478bd9Sstevel@tonic-gate killall(zoneid_t zoneid)
827c478bd9Sstevel@tonic-gate {
837c478bd9Sstevel@tonic-gate 	proc_t *p;
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate 	ASSERT(zoneid != GLOBAL_ZONEID);
867c478bd9Sstevel@tonic-gate 	/*
877c478bd9Sstevel@tonic-gate 	 * Kill all processes except kernel daemons and ourself.
887c478bd9Sstevel@tonic-gate 	 * Make a first pass to stop all processes so they won't
897c478bd9Sstevel@tonic-gate 	 * be trying to restart children as we kill them.
907c478bd9Sstevel@tonic-gate 	 */
917c478bd9Sstevel@tonic-gate 	mutex_enter(&pidlock);
927c478bd9Sstevel@tonic-gate 	for (p = practive; p != NULL; p = p->p_next) {
937c478bd9Sstevel@tonic-gate 		if ((zoneid == ALL_ZONES || p->p_zone->zone_id == zoneid) &&
947c478bd9Sstevel@tonic-gate 		    p->p_exec != NULLVP &&	/* kernel daemons */
957c478bd9Sstevel@tonic-gate 		    p->p_as != &kas &&
967c478bd9Sstevel@tonic-gate 		    p->p_stat != SZOMB) {
977c478bd9Sstevel@tonic-gate 			mutex_enter(&p->p_lock);
987c478bd9Sstevel@tonic-gate 			p->p_flag |= SNOWAIT;
997c478bd9Sstevel@tonic-gate 			sigtoproc(p, NULL, SIGSTOP);
1007c478bd9Sstevel@tonic-gate 			mutex_exit(&p->p_lock);
1017c478bd9Sstevel@tonic-gate 		}
1027c478bd9Sstevel@tonic-gate 	}
1037c478bd9Sstevel@tonic-gate 	p = practive;
1047c478bd9Sstevel@tonic-gate 	while (p != NULL) {
1057c478bd9Sstevel@tonic-gate 		if ((zoneid == ALL_ZONES || p->p_zone->zone_id == zoneid) &&
1067c478bd9Sstevel@tonic-gate 		    p->p_exec != NULLVP &&	/* kernel daemons */
1077c478bd9Sstevel@tonic-gate 		    p->p_as != &kas &&
1087c478bd9Sstevel@tonic-gate 		    p->p_stat != SIDL &&
1097c478bd9Sstevel@tonic-gate 		    p->p_stat != SZOMB) {
1107c478bd9Sstevel@tonic-gate 			mutex_enter(&p->p_lock);
1117c478bd9Sstevel@tonic-gate 			if (sigismember(&p->p_sig, SIGKILL)) {
1127c478bd9Sstevel@tonic-gate 				mutex_exit(&p->p_lock);
1137c478bd9Sstevel@tonic-gate 				p = p->p_next;
1147c478bd9Sstevel@tonic-gate 			} else {
1157c478bd9Sstevel@tonic-gate 				sigtoproc(p, NULL, SIGKILL);
1167c478bd9Sstevel@tonic-gate 				mutex_exit(&p->p_lock);
117d3d50737SRafael Vanoni 				(void) cv_reltimedwait(&p->p_srwchan_cv,
118d3d50737SRafael Vanoni 				    &pidlock, hz, TR_CLOCK_TICK);
1197c478bd9Sstevel@tonic-gate 				p = practive;
1207c478bd9Sstevel@tonic-gate 			}
1217c478bd9Sstevel@tonic-gate 		} else {
1227c478bd9Sstevel@tonic-gate 			p = p->p_next;
1237c478bd9Sstevel@tonic-gate 		}
1247c478bd9Sstevel@tonic-gate 	}
1257c478bd9Sstevel@tonic-gate 	mutex_exit(&pidlock);
1267c478bd9Sstevel@tonic-gate }
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate int
kadmin(int cmd,int fcn,void * mdep,cred_t * credp)1297c478bd9Sstevel@tonic-gate kadmin(int cmd, int fcn, void *mdep, cred_t *credp)
1307c478bd9Sstevel@tonic-gate {
1317c478bd9Sstevel@tonic-gate 	int error = 0;
1327c478bd9Sstevel@tonic-gate 	char *buf;
1337c478bd9Sstevel@tonic-gate 	size_t buflen = 0;
134edc40228Sachartre 	boolean_t invoke_cb = B_FALSE;
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate 	/*
1377c478bd9Sstevel@tonic-gate 	 * We might be called directly by the kernel's fault-handling code, so
1387c478bd9Sstevel@tonic-gate 	 * we can't assert that the caller is in the global zone.
1397c478bd9Sstevel@tonic-gate 	 */
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate 	/*
1427c478bd9Sstevel@tonic-gate 	 * Make sure that cmd is one of the valid <sys/uadmin.h> command codes
1437c478bd9Sstevel@tonic-gate 	 * and that we have appropriate privileges for this action.
1447c478bd9Sstevel@tonic-gate 	 */
1457c478bd9Sstevel@tonic-gate 	switch (cmd) {
1467c478bd9Sstevel@tonic-gate 	case A_FTRACE:
1477c478bd9Sstevel@tonic-gate 	case A_SHUTDOWN:
1487c478bd9Sstevel@tonic-gate 	case A_REBOOT:
1497c478bd9Sstevel@tonic-gate 	case A_REMOUNT:
1507c478bd9Sstevel@tonic-gate 	case A_FREEZE:
1517c478bd9Sstevel@tonic-gate 	case A_DUMP:
15210e6dadfSbrendan 	case A_SDTTEST:
153753a6d45SSherry Moore 	case A_CONFIG:
1547c478bd9Sstevel@tonic-gate 		if (secpolicy_sys_config(credp, B_FALSE) != 0)
1557c478bd9Sstevel@tonic-gate 			return (EPERM);
1567c478bd9Sstevel@tonic-gate 		break;
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate 	default:
1597c478bd9Sstevel@tonic-gate 		return (EINVAL);
1607c478bd9Sstevel@tonic-gate 	}
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate 	/*
163ed0ee1acScg 	 * Serialize these operations on ualock.  If it is held, the
164ed0ee1acScg 	 * system should shutdown, reboot, or remount shortly, unless there is
165ed0ee1acScg 	 * an error.  We need a cv rather than just a mutex because proper
166ed0ee1acScg 	 * functioning of A_REBOOT relies on being able to interrupt blocked
167ed0ee1acScg 	 * userland callers.
168ed0ee1acScg 	 *
169753a6d45SSherry Moore 	 * We only clear ua_shutdown_thread after A_REMOUNT or A_CONFIG.
170753a6d45SSherry Moore 	 * Other commands should never return.
1717c478bd9Sstevel@tonic-gate 	 */
172753a6d45SSherry Moore 	if (cmd == A_SHUTDOWN || cmd == A_REBOOT || cmd == A_REMOUNT ||
173753a6d45SSherry Moore 	    cmd == A_CONFIG) {
174ed0ee1acScg 		mutex_enter(&ualock);
175ed0ee1acScg 		while (ua_shutdown_thread != NULL) {
176ed0ee1acScg 			if (cv_wait_sig(&uacond, &ualock) == 0) {
177ed0ee1acScg 				/*
178ed0ee1acScg 				 * If we were interrupted, leave, and handle
179ed0ee1acScg 				 * the signal (or exit, depending on what
180ed0ee1acScg 				 * happened)
181ed0ee1acScg 				 */
182ed0ee1acScg 				mutex_exit(&ualock);
183ed0ee1acScg 				return (EINTR);
184ed0ee1acScg 			}
185ed0ee1acScg 		}
186ed0ee1acScg 		ua_shutdown_thread = curthread;
187ed0ee1acScg 		mutex_exit(&ualock);
1887c478bd9Sstevel@tonic-gate 	}
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 	switch (cmd) {
1917c478bd9Sstevel@tonic-gate 	case A_SHUTDOWN:
1927c478bd9Sstevel@tonic-gate 	{
1937c478bd9Sstevel@tonic-gate 		proc_t *p = ttoproc(curthread);
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate 		/*
1967c478bd9Sstevel@tonic-gate 		 * Release (almost) all of our own resources if we are called
1977c478bd9Sstevel@tonic-gate 		 * from a user context, however if we are calling kadmin() from
1987c478bd9Sstevel@tonic-gate 		 * a kernel context then we do not release these resources.
1997c478bd9Sstevel@tonic-gate 		 */
20097eda132Sraf 		if (p != &p0) {
20197eda132Sraf 			proc_is_exiting(p);
2028c9fe657Scg 			if ((error = exitlwps(0)) != 0) {
203ed0ee1acScg 				/*
204ed0ee1acScg 				 * Another thread in this process also called
205ed0ee1acScg 				 * exitlwps().
206ed0ee1acScg 				 */
207ed0ee1acScg 				mutex_enter(&ualock);
208ed0ee1acScg 				ua_shutdown_thread = NULL;
209ed0ee1acScg 				cv_signal(&uacond);
2108c9fe657Scg 				mutex_exit(&ualock);
2117c478bd9Sstevel@tonic-gate 				return (error);
2128c9fe657Scg 			}
2137c478bd9Sstevel@tonic-gate 			mutex_enter(&p->p_lock);
2147c478bd9Sstevel@tonic-gate 			p->p_flag |= SNOWAIT;
2157c478bd9Sstevel@tonic-gate 			sigfillset(&p->p_ignore);
2167c478bd9Sstevel@tonic-gate 			curthread->t_lwp->lwp_cursig = 0;
2177c478bd9Sstevel@tonic-gate 			curthread->t_lwp->lwp_extsig = 0;
2187c478bd9Sstevel@tonic-gate 			if (p->p_exec) {
2197c478bd9Sstevel@tonic-gate 				vnode_t *exec_vp = p->p_exec;
2207c478bd9Sstevel@tonic-gate 				p->p_exec = NULLVP;
2217c478bd9Sstevel@tonic-gate 				mutex_exit(&p->p_lock);
2227c478bd9Sstevel@tonic-gate 				VN_RELE(exec_vp);
2237c478bd9Sstevel@tonic-gate 			} else {
2247c478bd9Sstevel@tonic-gate 				mutex_exit(&p->p_lock);
2257c478bd9Sstevel@tonic-gate 			}
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 			pollcleanup();
2287c478bd9Sstevel@tonic-gate 			closeall(P_FINFO(curproc));
2297c478bd9Sstevel@tonic-gate 			relvm();
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate 		} else {
2327c478bd9Sstevel@tonic-gate 			/*
2337c478bd9Sstevel@tonic-gate 			 * Reset t_cred if not set because much of the
2347c478bd9Sstevel@tonic-gate 			 * filesystem code depends on CRED() being valid.
2357c478bd9Sstevel@tonic-gate 			 */
2367c478bd9Sstevel@tonic-gate 			if (curthread->t_cred == NULL)
2377c478bd9Sstevel@tonic-gate 				curthread->t_cred = kcred;
2387c478bd9Sstevel@tonic-gate 		}
2397c478bd9Sstevel@tonic-gate 
240facf4a8dSllai 		/* indicate shutdown in progress */
241facf4a8dSllai 		sys_shutdown = 1;
242facf4a8dSllai 
2437c478bd9Sstevel@tonic-gate 		/*
2447c478bd9Sstevel@tonic-gate 		 * Communcate that init shouldn't be restarted.
2457c478bd9Sstevel@tonic-gate 		 */
2467c478bd9Sstevel@tonic-gate 		zone_shutdown_global();
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 		killall(ALL_ZONES);
2497c478bd9Sstevel@tonic-gate 		/*
2507c478bd9Sstevel@tonic-gate 		 * If we are calling kadmin() from a kernel context then we
2517c478bd9Sstevel@tonic-gate 		 * do not release these resources.
2527c478bd9Sstevel@tonic-gate 		 */
2537c478bd9Sstevel@tonic-gate 		if (ttoproc(curthread) != &p0) {
254ae115bc7Smrj 			VN_RELE(PTOU(curproc)->u_cdir);
255ae115bc7Smrj 			if (PTOU(curproc)->u_rdir)
256ae115bc7Smrj 				VN_RELE(PTOU(curproc)->u_rdir);
257ae115bc7Smrj 			if (PTOU(curproc)->u_cwd)
258ae115bc7Smrj 				refstr_rele(PTOU(curproc)->u_cwd);
259ae115bc7Smrj 
260ae115bc7Smrj 			PTOU(curproc)->u_cdir = rootdir;
261ae115bc7Smrj 			PTOU(curproc)->u_rdir = NULL;
262ae115bc7Smrj 			PTOU(curproc)->u_cwd = NULL;
2637c478bd9Sstevel@tonic-gate 		}
2647c478bd9Sstevel@tonic-gate 
2657c478bd9Sstevel@tonic-gate 		/*
2667c478bd9Sstevel@tonic-gate 		 * Allow the reboot/halt/poweroff code a chance to do
2677c478bd9Sstevel@tonic-gate 		 * anything it needs to whilst we still have filesystems
2687c478bd9Sstevel@tonic-gate 		 * mounted, like loading any modules necessary for later
2697c478bd9Sstevel@tonic-gate 		 * performing the actual poweroff.
2707c478bd9Sstevel@tonic-gate 		 */
2717c478bd9Sstevel@tonic-gate 		if ((mdep != NULL) && (*(char *)mdep == '/')) {
2727c478bd9Sstevel@tonic-gate 			buf = i_convert_boot_device_name(mdep, NULL, &buflen);
2737c478bd9Sstevel@tonic-gate 			mdpreboot(cmd, fcn, buf);
2747c478bd9Sstevel@tonic-gate 		} else
2757c478bd9Sstevel@tonic-gate 			mdpreboot(cmd, fcn, mdep);
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate 		/*
2787c478bd9Sstevel@tonic-gate 		 * Allow fsflush to finish running and then prevent it
2797c478bd9Sstevel@tonic-gate 		 * from ever running again so that vfs_unmountall() and
2807c478bd9Sstevel@tonic-gate 		 * vfs_syncall() can acquire the vfs locks they need.
2817c478bd9Sstevel@tonic-gate 		 */
2827c478bd9Sstevel@tonic-gate 		sema_p(&fsflush_sema);
283*7e12ceb3SToomas Soome 		(void) callb_execute_class(CB_CL_UADMIN_PRE_VFS, 0);
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate 		vfs_unmountall();
2867c478bd9Sstevel@tonic-gate 		(void) VFS_MOUNTROOT(rootvfs, ROOT_UNMOUNT);
2877c478bd9Sstevel@tonic-gate 		vfs_syncall();
2887c478bd9Sstevel@tonic-gate 
289a288e5a9SJoshua M. Clulow 		/*
290a288e5a9SJoshua M. Clulow 		 * Check for (and unregister) any DDI periodic handlers that
291a288e5a9SJoshua M. Clulow 		 * still exist, as they most likely constitute resource leaks:
292a288e5a9SJoshua M. Clulow 		 */
293a288e5a9SJoshua M. Clulow 		ddi_periodic_fini();
294a288e5a9SJoshua M. Clulow 
2957c478bd9Sstevel@tonic-gate 		dump_ereports();
2967c478bd9Sstevel@tonic-gate 		dump_messages();
2977c478bd9Sstevel@tonic-gate 
298edc40228Sachartre 		invoke_cb = B_TRUE;
2997c478bd9Sstevel@tonic-gate 	}
300a9f62b1aSToomas Soome 	/* FALLTHROUGH */
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate 	case A_REBOOT:
3037c478bd9Sstevel@tonic-gate 		if ((mdep != NULL) && (*(char *)mdep == '/')) {
3047c478bd9Sstevel@tonic-gate 			buf = i_convert_boot_device_name(mdep, NULL, &buflen);
305edc40228Sachartre 			mdboot(cmd, fcn, buf, invoke_cb);
3067c478bd9Sstevel@tonic-gate 		} else
307edc40228Sachartre 			mdboot(cmd, fcn, mdep, invoke_cb);
3087c478bd9Sstevel@tonic-gate 		/* no return expected */
3097c478bd9Sstevel@tonic-gate 		break;
3107c478bd9Sstevel@tonic-gate 
311753a6d45SSherry Moore 	case A_CONFIG:
312753a6d45SSherry Moore 		switch (fcn) {
313753a6d45SSherry Moore 		case AD_UPDATE_BOOT_CONFIG:
314753a6d45SSherry Moore #ifndef	__sparc
315753a6d45SSherry Moore 		{
316753a6d45SSherry Moore 			extern void fastboot_update_config(const char *);
317753a6d45SSherry Moore 
318c90a5fbeSSherry Moore 			fastboot_update_config(mdep);
319753a6d45SSherry Moore 		}
320753a6d45SSherry Moore #endif
321753a6d45SSherry Moore 
322753a6d45SSherry Moore 			break;
323753a6d45SSherry Moore 		}
324753a6d45SSherry Moore 		/* Let other threads enter the shutdown path now */
325753a6d45SSherry Moore 		mutex_enter(&ualock);
326753a6d45SSherry Moore 		ua_shutdown_thread = NULL;
327753a6d45SSherry Moore 		cv_signal(&uacond);
328753a6d45SSherry Moore 		mutex_exit(&ualock);
329753a6d45SSherry Moore 		break;
330753a6d45SSherry Moore 
3317c478bd9Sstevel@tonic-gate 	case A_REMOUNT:
3327c478bd9Sstevel@tonic-gate 		(void) VFS_MOUNTROOT(rootvfs, ROOT_REMOUNT);
333ed0ee1acScg 		/* Let other threads enter the shutdown path now */
334ed0ee1acScg 		mutex_enter(&ualock);
335ed0ee1acScg 		ua_shutdown_thread = NULL;
336ed0ee1acScg 		cv_signal(&uacond);
337ed0ee1acScg 		mutex_exit(&ualock);
3387c478bd9Sstevel@tonic-gate 		break;
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate 	case A_FREEZE:
3417c478bd9Sstevel@tonic-gate 	{
3422df1fe9cSrandyf 		/*
3432df1fe9cSrandyf 		 * This is the entrypoint for all suspend/resume actions.
3442df1fe9cSrandyf 		 */
3452df1fe9cSrandyf 		extern int cpr(int, void *);
3467c478bd9Sstevel@tonic-gate 
3477c478bd9Sstevel@tonic-gate 		if (modload("misc", "cpr") == -1)
3487c478bd9Sstevel@tonic-gate 			return (ENOTSUP);
3492df1fe9cSrandyf 		/* Let the CPR module decide what to do with mdep */
3502df1fe9cSrandyf 		error = cpr(fcn, mdep);
3517c478bd9Sstevel@tonic-gate 		break;
3527c478bd9Sstevel@tonic-gate 	}
3537c478bd9Sstevel@tonic-gate 
3547c478bd9Sstevel@tonic-gate 	case A_FTRACE:
3557c478bd9Sstevel@tonic-gate 	{
3567c478bd9Sstevel@tonic-gate 		switch (fcn) {
3577c478bd9Sstevel@tonic-gate 		case AD_FTRACE_START:
3587c478bd9Sstevel@tonic-gate 			(void) FTRACE_START();
3597c478bd9Sstevel@tonic-gate 			break;
3607c478bd9Sstevel@tonic-gate 		case AD_FTRACE_STOP:
3617c478bd9Sstevel@tonic-gate 			(void) FTRACE_STOP();
3627c478bd9Sstevel@tonic-gate 			break;
3637c478bd9Sstevel@tonic-gate 		default:
3647c478bd9Sstevel@tonic-gate 			error = EINVAL;
3657c478bd9Sstevel@tonic-gate 		}
3667c478bd9Sstevel@tonic-gate 		break;
3677c478bd9Sstevel@tonic-gate 	}
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate 	case A_DUMP:
3707c478bd9Sstevel@tonic-gate 	{
3717c478bd9Sstevel@tonic-gate 		if (fcn == AD_NOSYNC) {
3727c478bd9Sstevel@tonic-gate 			in_sync = 1;
3737c478bd9Sstevel@tonic-gate 			break;
3747c478bd9Sstevel@tonic-gate 		}
3757c478bd9Sstevel@tonic-gate 
3767c478bd9Sstevel@tonic-gate 		panic_bootfcn = fcn;
3777c478bd9Sstevel@tonic-gate 		panic_forced = 1;
3787c478bd9Sstevel@tonic-gate 
3797c478bd9Sstevel@tonic-gate 		if ((mdep != NULL) && (*(char *)mdep == '/')) {
3807c478bd9Sstevel@tonic-gate 			panic_bootstr = i_convert_boot_device_name(mdep,
3813f2f09c1Sdp 			    NULL, &buflen);
3827c478bd9Sstevel@tonic-gate 		} else
3837c478bd9Sstevel@tonic-gate 			panic_bootstr = mdep;
3847c478bd9Sstevel@tonic-gate 
385753a6d45SSherry Moore #ifndef	__sparc
386c90a5fbeSSherry Moore 		extern void fastboot_update_and_load(int, char *);
387753a6d45SSherry Moore 
388c90a5fbeSSherry Moore 		fastboot_update_and_load(fcn, mdep);
389753a6d45SSherry Moore #endif
390753a6d45SSherry Moore 
3917c478bd9Sstevel@tonic-gate 		panic("forced crash dump initiated at user request");
3927c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
3937c478bd9Sstevel@tonic-gate 	}
3947c478bd9Sstevel@tonic-gate 
39510e6dadfSbrendan 	case A_SDTTEST:
39610e6dadfSbrendan 	{
39710e6dadfSbrendan 		DTRACE_PROBE7(test, int, 1, int, 2, int, 3, int, 4, int, 5,
39810e6dadfSbrendan 		    int, 6, int, 7);
39910e6dadfSbrendan 		break;
40010e6dadfSbrendan 	}
40110e6dadfSbrendan 
4027c478bd9Sstevel@tonic-gate 	default:
4037c478bd9Sstevel@tonic-gate 		error = EINVAL;
4047c478bd9Sstevel@tonic-gate 	}
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate 	return (error);
4077c478bd9Sstevel@tonic-gate }
4087c478bd9Sstevel@tonic-gate 
4097c478bd9Sstevel@tonic-gate int
uadmin(int cmd,int fcn,uintptr_t mdep)4107c478bd9Sstevel@tonic-gate uadmin(int cmd, int fcn, uintptr_t mdep)
4117c478bd9Sstevel@tonic-gate {
4127c478bd9Sstevel@tonic-gate 	int error = 0, rv = 0;
4137c478bd9Sstevel@tonic-gate 	size_t nbytes = 0;
4147c478bd9Sstevel@tonic-gate 	cred_t *credp = CRED();
4153f2f09c1Sdp 	char *bootargs = NULL;
41619397407SSherry Moore 	int reset_status = 0;
41719397407SSherry Moore 
41819397407SSherry Moore 	if (cmd == A_SHUTDOWN && fcn == AD_FASTREBOOT_DRYRUN) {
41919397407SSherry Moore 		ddi_walk_devs(ddi_root_node(), check_driver_quiesce,
42019397407SSherry Moore 		    &reset_status);
42119397407SSherry Moore 		if (reset_status != 0)
42219397407SSherry Moore 			return (EIO);
42319397407SSherry Moore 		else
42419397407SSherry Moore 			return (0);
42519397407SSherry Moore 	}
4267c478bd9Sstevel@tonic-gate 
4277c478bd9Sstevel@tonic-gate 	/*
4287c478bd9Sstevel@tonic-gate 	 * The swapctl system call doesn't have its own entry point: it uses
4297c478bd9Sstevel@tonic-gate 	 * uadmin as a wrapper so we just call it directly from here.
4307c478bd9Sstevel@tonic-gate 	 */
4317c478bd9Sstevel@tonic-gate 	if (cmd == A_SWAPCTL) {
4327c478bd9Sstevel@tonic-gate 		if (get_udatamodel() == DATAMODEL_NATIVE)
4337c478bd9Sstevel@tonic-gate 			error = swapctl(fcn, (void *)mdep, &rv);
4347c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32_IMPL)
4357c478bd9Sstevel@tonic-gate 		else
4367c478bd9Sstevel@tonic-gate 			error = swapctl32(fcn, (void *)mdep, &rv);
4377c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32_IMPL */
4387c478bd9Sstevel@tonic-gate 		return (error ? set_errno(error) : rv);
4397c478bd9Sstevel@tonic-gate 	}
4407c478bd9Sstevel@tonic-gate 
4417c478bd9Sstevel@tonic-gate 	/*
4423f2f09c1Sdp 	 * Certain subcommands intepret a non-NULL mdep value as a pointer to
4433f2f09c1Sdp 	 * a boot string.  We pull that in as bootargs, if applicable.
4447c478bd9Sstevel@tonic-gate 	 */
445*7e12ceb3SToomas Soome 	if (mdep != (uintptr_t)NULL &&
4462df1fe9cSrandyf 	    (cmd == A_SHUTDOWN || cmd == A_REBOOT || cmd == A_DUMP ||
447753a6d45SSherry Moore 	    cmd == A_FREEZE || cmd == A_CONFIG)) {
4483f2f09c1Sdp 		bootargs = kmem_zalloc(BOOTARGS_MAX, KM_SLEEP);
4493f2f09c1Sdp 		if ((error = copyinstr((const char *)mdep, bootargs,
4503f2f09c1Sdp 		    BOOTARGS_MAX, &nbytes)) != 0) {
4513f2f09c1Sdp 			kmem_free(bootargs, BOOTARGS_MAX);
4523f2f09c1Sdp 			return (set_errno(error));
4533f2f09c1Sdp 		}
4547c478bd9Sstevel@tonic-gate 	}
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate 	/*
4573f2f09c1Sdp 	 * Invoke the appropriate kadmin() routine.
4587c478bd9Sstevel@tonic-gate 	 */
4593f2f09c1Sdp 	if (getzoneid() != GLOBAL_ZONEID)
4603f2f09c1Sdp 		error = zone_kadmin(cmd, fcn, bootargs, credp);
4613f2f09c1Sdp 	else
4623f2f09c1Sdp 		error = kadmin(cmd, fcn, bootargs, credp);
4633f2f09c1Sdp 
4643f2f09c1Sdp 	if (bootargs != NULL)
4653f2f09c1Sdp 		kmem_free(bootargs, BOOTARGS_MAX);
4663f2f09c1Sdp 	return (error ? set_errno(error) : 0);
4677c478bd9Sstevel@tonic-gate }
468