1996-08-19 02:19:23 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1986, 1988, 1991, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
* (c) UNIX System Laboratories, Inc.
|
|
|
|
* All or some portions of this file are derived from material licensed
|
|
|
|
* to the University of California by American Telephone and Telegraph
|
|
|
|
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
|
|
|
|
* the permission of UNIX System Laboratories, Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* @(#)kern_shutdown.c 8.3 (Berkeley) 1/21/94
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1996-08-19 02:19:23 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "opt_ddb.h"
|
1998-02-16 23:57:49 +00:00
|
|
|
#include "opt_hw_wdog.h"
|
1997-08-31 23:08:38 +00:00
|
|
|
#include "opt_panic.h"
|
|
|
|
#include "opt_show_busybufs.h"
|
1996-08-19 02:19:23 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2000-05-05 09:59:14 +00:00
|
|
|
#include <sys/bio.h>
|
1997-11-18 15:16:43 +00:00
|
|
|
#include <sys/buf.h>
|
2001-06-25 18:30:42 +00:00
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/cons.h>
|
2001-08-15 11:35:45 +00:00
|
|
|
#include <sys/disklabel.h>
|
2001-06-25 18:30:42 +00:00
|
|
|
#include <sys/eventhandler.h>
|
1996-08-19 02:19:23 +00:00
|
|
|
#include <sys/kernel.h>
|
2000-01-07 08:36:44 +00:00
|
|
|
#include <sys/kthread.h>
|
2002-01-21 01:16:11 +00:00
|
|
|
#include <sys/malloc.h>
|
1997-01-16 15:58:32 +00:00
|
|
|
#include <sys/mount.h>
|
2001-06-25 18:30:42 +00:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/reboot.h>
|
|
|
|
#include <sys/resourcevar.h>
|
|
|
|
#include <sys/smp.h> /* smp_active */
|
1996-08-19 02:19:23 +00:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/sysproto.h>
|
2001-06-25 18:30:42 +00:00
|
|
|
#include <sys/vnode.h>
|
1996-08-19 02:19:23 +00:00
|
|
|
|
|
|
|
#include <machine/pcb.h>
|
|
|
|
#include <machine/md_var.h>
|
|
|
|
|
|
|
|
#include <sys/signalvar.h>
|
2001-08-21 23:29:40 +00:00
|
|
|
#ifdef DDB
|
|
|
|
#include <ddb/ddb.h>
|
|
|
|
#endif
|
1996-08-19 02:19:23 +00:00
|
|
|
|
|
|
|
#ifndef PANIC_REBOOT_WAIT_TIME
|
|
|
|
#define PANIC_REBOOT_WAIT_TIME 15 /* default to 15 seconds */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note that stdarg.h and the ANSI style va_start macro is used for both
|
|
|
|
* ANSI and traditional C compilers.
|
|
|
|
*/
|
|
|
|
#include <machine/stdarg.h>
|
|
|
|
|
1997-08-26 00:24:25 +00:00
|
|
|
#ifdef DDB
|
1996-08-19 02:19:23 +00:00
|
|
|
#ifdef DDB_UNATTENDED
|
Improved DDB_UNATTENDED behaviour. From the submitter:
There's something that's been bugging me for a while, so I decided to fix it.
FreeBSD now will DTRT WRT DDB and DDB_UNATTENDED (!debugger_on_panic), at least
in my opinion. The behavior change is such that:
1. Nothing changes when debugger_on_panic != 0.
2. When DDB_UNATTENDED (!debugger_on_panic), if a panic occurs, the
machine will reboot. Also, if a trap occurs, the machine will
panic and reboot, unlike how it broke to DDB before. HOWEVER,
a trap inside DDB will not cause a panic, allowing full use
of DDB without having to worry about the machine being stuck
at a DDB prompt if something goes wrong during the day.
Patches for this behavior follow my signature, and it would
be a boon to anyone (like me) who uses DDB_UNATTENDED, but
actually wants the machine to panic on a trap (otherwise,
what's the use, if the machine causes a fatal trap rather than
a true panic, of debugger_on_panic?). The changes cause no
adverse behavior, but do involve two symbols becoming global
Submitted by: Brian Feldman <green@unixhelp.org>
1998-12-28 23:03:00 +00:00
|
|
|
int debugger_on_panic = 0;
|
1996-08-19 02:19:23 +00:00
|
|
|
#else
|
Improved DDB_UNATTENDED behaviour. From the submitter:
There's something that's been bugging me for a while, so I decided to fix it.
FreeBSD now will DTRT WRT DDB and DDB_UNATTENDED (!debugger_on_panic), at least
in my opinion. The behavior change is such that:
1. Nothing changes when debugger_on_panic != 0.
2. When DDB_UNATTENDED (!debugger_on_panic), if a panic occurs, the
machine will reboot. Also, if a trap occurs, the machine will
panic and reboot, unlike how it broke to DDB before. HOWEVER,
a trap inside DDB will not cause a panic, allowing full use
of DDB without having to worry about the machine being stuck
at a DDB prompt if something goes wrong during the day.
Patches for this behavior follow my signature, and it would
be a boon to anyone (like me) who uses DDB_UNATTENDED, but
actually wants the machine to panic on a trap (otherwise,
what's the use, if the machine causes a fatal trap rather than
a true panic, of debugger_on_panic?). The changes cause no
adverse behavior, but do involve two symbols becoming global
Submitted by: Brian Feldman <green@unixhelp.org>
1998-12-28 23:03:00 +00:00
|
|
|
int debugger_on_panic = 1;
|
1996-08-19 02:19:23 +00:00
|
|
|
#endif
|
|
|
|
SYSCTL_INT(_debug, OID_AUTO, debugger_on_panic, CTLFLAG_RW,
|
1999-05-03 23:57:32 +00:00
|
|
|
&debugger_on_panic, 0, "Run debugger on kernel panic");
|
1996-08-19 02:19:23 +00:00
|
|
|
#endif
|
|
|
|
|
2001-10-19 23:32:03 +00:00
|
|
|
int sync_on_panic = 1;
|
|
|
|
SYSCTL_INT(_kern, OID_AUTO, sync_on_panic, CTLFLAG_RW,
|
|
|
|
&sync_on_panic, 0, "Do a sync before rebooting from a panic");
|
|
|
|
|
1999-01-30 19:28:30 +00:00
|
|
|
SYSCTL_NODE(_kern, OID_AUTO, shutdown, CTLFLAG_RW, 0, "Shutdown environment");
|
|
|
|
|
1997-08-09 01:44:25 +00:00
|
|
|
#ifdef HW_WDOG
|
1997-08-09 01:25:54 +00:00
|
|
|
/*
|
|
|
|
* If there is a hardware watchdog, point this at the function needed to
|
|
|
|
* hold it off.
|
|
|
|
* It's needed when the kernel needs to do some lengthy operations.
|
|
|
|
* e.g. in wd.c when dumping core.. It's most annoying to have
|
|
|
|
* your precious core-dump only half written because the wdog kicked in.
|
|
|
|
*/
|
|
|
|
watchdog_tickle_fn wdog_tickler = NULL;
|
1997-08-09 01:44:25 +00:00
|
|
|
#endif /* HW_WDOG */
|
1997-08-09 01:25:54 +00:00
|
|
|
|
1996-08-19 02:19:23 +00:00
|
|
|
/*
|
|
|
|
* Variable panicstr contains argument to first call to panic; used as flag
|
|
|
|
* to indicate that the kernel has already called panic.
|
|
|
|
*/
|
|
|
|
const char *panicstr;
|
|
|
|
|
2000-10-13 21:49:19 +00:00
|
|
|
int dumping; /* system is dumping */
|
|
|
|
|
2000-09-03 06:44:53 +00:00
|
|
|
static void boot(int) __dead2;
|
|
|
|
static void dumpsys(void);
|
|
|
|
static void poweroff_wait(void *, int);
|
|
|
|
static void shutdown_halt(void *junk, int howto);
|
|
|
|
static void shutdown_panic(void *junk, int howto);
|
|
|
|
static void shutdown_reset(void *junk, int howto);
|
1999-08-21 06:24:40 +00:00
|
|
|
|
|
|
|
/* register various local shutdown events */
|
|
|
|
static void
|
|
|
|
shutdown_conf(void *unused)
|
|
|
|
{
|
|
|
|
EVENTHANDLER_REGISTER(shutdown_final, poweroff_wait, NULL, SHUTDOWN_PRI_FIRST);
|
|
|
|
EVENTHANDLER_REGISTER(shutdown_final, shutdown_halt, NULL, SHUTDOWN_PRI_LAST + 100);
|
|
|
|
EVENTHANDLER_REGISTER(shutdown_final, shutdown_panic, NULL, SHUTDOWN_PRI_LAST + 100);
|
|
|
|
EVENTHANDLER_REGISTER(shutdown_final, shutdown_reset, NULL, SHUTDOWN_PRI_LAST + 200);
|
|
|
|
}
|
1999-07-17 20:47:52 +00:00
|
|
|
|
1999-08-21 06:24:40 +00:00
|
|
|
SYSINIT(shutdown_conf, SI_SUB_INTRINSIC, SI_ORDER_ANY, shutdown_conf, NULL)
|
1996-08-19 02:19:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The system call that results in a reboot
|
2001-09-01 19:04:37 +00:00
|
|
|
*
|
|
|
|
* MPSAFE
|
1996-08-19 02:19:23 +00:00
|
|
|
*/
|
2001-09-01 19:04:37 +00:00
|
|
|
/* ARGSUSED */
|
1996-08-19 02:19:23 +00:00
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
reboot(struct thread *td, struct reboot_args *uap)
|
1996-08-19 02:19:23 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2001-09-01 19:04:37 +00:00
|
|
|
mtx_lock(&Giant);
|
2001-09-12 08:38:13 +00:00
|
|
|
if ((error = suser_td(td)) == 0)
|
2001-09-01 19:04:37 +00:00
|
|
|
boot(uap->opt);
|
|
|
|
mtx_unlock(&Giant);
|
|
|
|
return (error);
|
1996-08-19 02:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called by events that want to shut down.. e.g <CTL><ALT><DEL> on a PC
|
|
|
|
*/
|
2000-08-31 00:08:50 +00:00
|
|
|
static int shutdown_howto = 0;
|
|
|
|
|
1996-08-19 02:19:23 +00:00
|
|
|
void
|
2000-08-31 00:08:50 +00:00
|
|
|
shutdown_nice(int howto)
|
1996-08-19 02:19:23 +00:00
|
|
|
{
|
2000-08-31 00:08:50 +00:00
|
|
|
shutdown_howto = howto;
|
|
|
|
|
1996-08-19 02:19:23 +00:00
|
|
|
/* Send a signal to init(8) and have it shutdown the world */
|
|
|
|
if (initproc != NULL) {
|
2001-03-07 02:50:09 +00:00
|
|
|
PROC_LOCK(initproc);
|
1996-08-19 02:19:23 +00:00
|
|
|
psignal(initproc, SIGINT);
|
2001-03-07 02:50:09 +00:00
|
|
|
PROC_UNLOCK(initproc);
|
1996-08-19 02:19:23 +00:00
|
|
|
} else {
|
|
|
|
/* No init(8) running, so simply reboot */
|
|
|
|
boot(RB_NOSYNC);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
static int waittime = -1;
|
|
|
|
static struct pcb dumppcb;
|
|
|
|
|
1999-12-06 22:35:51 +00:00
|
|
|
static void
|
2000-09-03 06:44:53 +00:00
|
|
|
print_uptime(void)
|
1999-12-06 22:35:51 +00:00
|
|
|
{
|
|
|
|
int f;
|
|
|
|
struct timespec ts;
|
|
|
|
|
|
|
|
getnanouptime(&ts);
|
|
|
|
printf("Uptime: ");
|
|
|
|
f = 0;
|
|
|
|
if (ts.tv_sec >= 86400) {
|
2000-09-11 23:55:10 +00:00
|
|
|
printf("%ldd", (long)ts.tv_sec / 86400);
|
1999-12-06 22:35:51 +00:00
|
|
|
ts.tv_sec %= 86400;
|
|
|
|
f = 1;
|
|
|
|
}
|
|
|
|
if (f || ts.tv_sec >= 3600) {
|
2000-09-11 23:55:10 +00:00
|
|
|
printf("%ldh", (long)ts.tv_sec / 3600);
|
1999-12-06 22:35:51 +00:00
|
|
|
ts.tv_sec %= 3600;
|
|
|
|
f = 1;
|
|
|
|
}
|
|
|
|
if (f || ts.tv_sec >= 60) {
|
2000-09-11 23:55:10 +00:00
|
|
|
printf("%ldm", (long)ts.tv_sec / 60);
|
1999-12-06 22:35:51 +00:00
|
|
|
ts.tv_sec %= 60;
|
|
|
|
f = 1;
|
|
|
|
}
|
2000-09-11 23:55:10 +00:00
|
|
|
printf("%lds\n", (long)ts.tv_sec);
|
1999-12-06 22:35:51 +00:00
|
|
|
}
|
|
|
|
|
1996-08-19 02:19:23 +00:00
|
|
|
/*
|
|
|
|
* Go through the rigmarole of shutting down..
|
|
|
|
* this used to be in machdep.c but I'll be dammned if I could see
|
|
|
|
* anything machine dependant in it.
|
|
|
|
*/
|
1997-11-18 15:16:43 +00:00
|
|
|
static void
|
2000-09-03 06:44:53 +00:00
|
|
|
boot(int howto)
|
1996-08-19 02:19:23 +00:00
|
|
|
{
|
|
|
|
|
2000-08-31 00:08:50 +00:00
|
|
|
/* collect extra flags that shutdown_nice might have set */
|
|
|
|
howto |= shutdown_howto;
|
|
|
|
|
2001-08-21 23:29:40 +00:00
|
|
|
#ifdef DDB
|
|
|
|
/* We are out of the debugger now. */
|
|
|
|
db_active = 0;
|
|
|
|
#endif
|
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
#ifdef SMP
|
2000-09-03 06:44:53 +00:00
|
|
|
if (smp_active)
|
2001-01-10 04:43:51 +00:00
|
|
|
printf("boot() called on cpu#%d\n", PCPU_GET(cpuid));
|
1997-04-26 11:46:25 +00:00
|
|
|
#endif
|
1997-08-09 01:25:54 +00:00
|
|
|
/*
|
|
|
|
* Do any callouts that should be done BEFORE syncing the filesystems.
|
|
|
|
*/
|
1999-08-21 06:24:40 +00:00
|
|
|
EVENTHANDLER_INVOKE(shutdown_pre_sync, howto);
|
1997-08-09 01:25:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now sync filesystems
|
|
|
|
*/
|
1996-08-19 02:19:23 +00:00
|
|
|
if (!cold && (howto & RB_NOSYNC) == 0 && waittime < 0) {
|
|
|
|
register struct buf *bp;
|
2000-09-10 23:06:50 +00:00
|
|
|
int iter, nbusy, pbusy;
|
|
|
|
int subiter;
|
1996-08-19 02:19:23 +00:00
|
|
|
|
|
|
|
waittime = 0;
|
|
|
|
printf("\nsyncing disks... ");
|
|
|
|
|
2002-02-07 20:58:47 +00:00
|
|
|
sync(&thread0, NULL);
|
1996-08-19 02:19:23 +00:00
|
|
|
|
1998-03-08 09:59:44 +00:00
|
|
|
/*
|
|
|
|
* With soft updates, some buffers that are
|
|
|
|
* written will be remarked as dirty until other
|
|
|
|
* buffers are written.
|
|
|
|
*/
|
2000-09-10 23:06:50 +00:00
|
|
|
for (iter = pbusy = 0; iter < 20; iter++) {
|
1996-08-19 02:19:23 +00:00
|
|
|
nbusy = 0;
|
|
|
|
for (bp = &buf[nbuf]; --bp >= buf; ) {
|
1999-06-26 02:47:16 +00:00
|
|
|
if ((bp->b_flags & B_INVAL) == 0 &&
|
|
|
|
BUF_REFCNT(bp) > 0) {
|
1996-08-19 02:19:23 +00:00
|
|
|
nbusy++;
|
1998-03-08 09:59:44 +00:00
|
|
|
} else if ((bp->b_flags & (B_DELWRI | B_INVAL))
|
|
|
|
== B_DELWRI) {
|
|
|
|
/* bawrite(bp);*/
|
|
|
|
nbusy++;
|
1996-08-19 02:19:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (nbusy == 0)
|
|
|
|
break;
|
|
|
|
printf("%d ", nbusy);
|
2000-09-10 23:06:50 +00:00
|
|
|
if (nbusy < pbusy)
|
|
|
|
iter = 0;
|
|
|
|
pbusy = nbusy;
|
2002-02-07 20:58:47 +00:00
|
|
|
sync(&thread0, NULL);
|
2001-09-12 08:38:13 +00:00
|
|
|
if (curthread != NULL) {
|
Change the preemption code for software interrupt thread schedules and
mutex releases to not require flags for the cases when preemption is
not allowed:
The purpose of the MTX_NOSWITCH and SWI_NOSWITCH flags is to prevent
switching to a higher priority thread on mutex releease and swi schedule,
respectively when that switch is not safe. Now that the critical section
API maintains a per-thread nesting count, the kernel can easily check
whether or not it should switch without relying on flags from the
programmer. This fixes a few bugs in that all current callers of
swi_sched() used SWI_NOSWITCH, when in fact, only the ones called from
fast interrupt handlers and the swi_sched of softclock needed this flag.
Note that to ensure that swi_sched()'s in clock and fast interrupt
handlers do not switch, these handlers have to be explicitly wrapped
in critical_enter/exit pairs. Presently, just wrapping the handlers is
sufficient, but in the future with the fully preemptive kernel, the
interrupt must be EOI'd before critical_exit() is called. (critical_exit()
can switch due to a deferred preemption in a fully preemptive kernel.)
I've tested the changes to the interrupt code on i386 and alpha. I have
not tested ia64, but the interrupt code is almost identical to the alpha
code, so I expect it will work fine. PowerPC and ARM do not yet have
interrupt code in the tree so they shouldn't be broken. Sparc64 is
broken, but that's been ok'd by jake and tmm who will be fixing the
interrupt code for sparc64 shortly.
Reviewed by: peter
Tested on: i386, alpha
2002-01-05 08:47:13 +00:00
|
|
|
DROP_GIANT();
|
2000-09-10 23:06:50 +00:00
|
|
|
for (subiter = 0; subiter < 50 * iter; subiter++) {
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_lock_spin(&sched_lock);
|
2002-02-09 01:38:16 +00:00
|
|
|
setrunqueue(curthread);
|
2001-09-12 08:38:13 +00:00
|
|
|
curthread->td_proc->p_stats->p_ru.ru_nvcsw++;
|
2000-09-10 23:06:50 +00:00
|
|
|
mi_switch(); /* Allow interrupt threads to run */
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_unlock_spin(&sched_lock);
|
2000-09-10 23:06:50 +00:00
|
|
|
DELAY(1000);
|
|
|
|
}
|
2000-11-16 02:16:44 +00:00
|
|
|
PICKUP_GIANT();
|
2000-09-10 23:06:50 +00:00
|
|
|
} else
|
1998-03-08 09:59:44 +00:00
|
|
|
DELAY(50000 * iter);
|
1998-11-13 22:40:37 +00:00
|
|
|
}
|
1999-11-08 19:36:45 +00:00
|
|
|
printf("\n");
|
1998-11-13 22:40:37 +00:00
|
|
|
/*
|
|
|
|
* Count only busy local buffers to prevent forcing
|
|
|
|
* a fsck if we're just a client of a wedged NFS server
|
|
|
|
*/
|
|
|
|
nbusy = 0;
|
|
|
|
for (bp = &buf[nbuf]; --bp >= buf; ) {
|
1999-06-26 02:47:16 +00:00
|
|
|
if (((bp->b_flags&B_INVAL) == 0 && BUF_REFCNT(bp)) ||
|
|
|
|
((bp->b_flags & (B_DELWRI|B_INVAL)) == B_DELWRI)) {
|
1999-11-08 19:36:45 +00:00
|
|
|
if (bp->b_dev == NODEV) {
|
1999-11-20 10:00:46 +00:00
|
|
|
TAILQ_REMOVE(&mountlist,
|
1999-06-26 02:47:16 +00:00
|
|
|
bp->b_vp->v_mount, mnt_list);
|
1999-11-08 19:36:45 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
nbusy++;
|
|
|
|
#if defined(SHOW_BUSYBUFS) || defined(DIAGNOSTIC)
|
|
|
|
printf(
|
|
|
|
"%d: dev:%s, flags:%08lx, blkno:%ld, lblkno:%ld\n",
|
|
|
|
nbusy, devtoname(bp->b_dev),
|
|
|
|
bp->b_flags, (long)bp->b_blkno,
|
|
|
|
(long)bp->b_lblkno);
|
|
|
|
#endif
|
1999-05-06 18:13:11 +00:00
|
|
|
}
|
1996-08-19 02:19:23 +00:00
|
|
|
}
|
|
|
|
if (nbusy) {
|
|
|
|
/*
|
|
|
|
* Failed to sync all blocks. Indicate this and don't
|
|
|
|
* unmount filesystems (thus forcing an fsck on reboot).
|
|
|
|
*/
|
1999-11-08 19:36:45 +00:00
|
|
|
printf("giving up on %d buffers\n", nbusy);
|
1996-08-19 02:19:23 +00:00
|
|
|
DELAY(5000000); /* 5 seconds */
|
|
|
|
} else {
|
|
|
|
printf("done\n");
|
|
|
|
/*
|
|
|
|
* Unmount filesystems
|
|
|
|
*/
|
|
|
|
if (panicstr == 0)
|
|
|
|
vfs_unmountall();
|
|
|
|
}
|
1998-09-15 08:49:52 +00:00
|
|
|
DELAY(100000); /* wait for console output to finish */
|
1996-08-19 02:19:23 +00:00
|
|
|
}
|
1997-08-09 01:25:54 +00:00
|
|
|
|
1999-12-06 22:35:51 +00:00
|
|
|
print_uptime();
|
|
|
|
|
1997-08-09 01:25:54 +00:00
|
|
|
/*
|
|
|
|
* Ok, now do things that assume all filesystem activity has
|
|
|
|
* been completed.
|
|
|
|
*/
|
1999-08-21 06:24:40 +00:00
|
|
|
EVENTHANDLER_INVOKE(shutdown_post_sync, howto);
|
1996-08-19 02:19:23 +00:00
|
|
|
splhigh();
|
2000-09-03 06:35:04 +00:00
|
|
|
if ((howto & (RB_HALT|RB_DUMP)) == RB_DUMP && !cold)
|
1998-09-15 08:49:52 +00:00
|
|
|
dumpsys();
|
|
|
|
|
|
|
|
/* Now that we're going to really halt the system... */
|
1999-08-21 06:24:40 +00:00
|
|
|
EVENTHANDLER_INVOKE(shutdown_final, howto);
|
|
|
|
|
|
|
|
for(;;) ; /* safety against shutdown_reset not working */
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
1998-09-15 08:49:52 +00:00
|
|
|
|
1999-08-21 06:24:40 +00:00
|
|
|
/*
|
|
|
|
* If the shutdown was a clean halt, behave accordingly.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
shutdown_halt(void *junk, int howto)
|
|
|
|
{
|
1996-08-19 02:19:23 +00:00
|
|
|
if (howto & RB_HALT) {
|
|
|
|
printf("\n");
|
|
|
|
printf("The operating system has halted.\n");
|
|
|
|
printf("Please press any key to reboot.\n\n");
|
1996-10-31 00:57:28 +00:00
|
|
|
switch (cngetc()) {
|
|
|
|
case -1: /* No console, just die */
|
|
|
|
cpu_halt();
|
|
|
|
/* NOTREACHED */
|
|
|
|
default:
|
1998-09-15 08:49:52 +00:00
|
|
|
howto &= ~RB_HALT;
|
1996-10-31 00:57:28 +00:00
|
|
|
break;
|
|
|
|
}
|
1999-08-21 06:24:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check to see if the system paniced, pause and then reboot
|
|
|
|
* according to the specified delay.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
shutdown_panic(void *junk, int howto)
|
|
|
|
{
|
|
|
|
int loop;
|
1998-09-15 08:49:52 +00:00
|
|
|
|
1999-08-21 06:24:40 +00:00
|
|
|
if (howto & RB_DUMP) {
|
1998-09-15 08:49:52 +00:00
|
|
|
if (PANIC_REBOOT_WAIT_TIME != 0) {
|
|
|
|
if (PANIC_REBOOT_WAIT_TIME != -1) {
|
|
|
|
printf("Automatic reboot in %d seconds - "
|
|
|
|
"press a key on the console to abort\n",
|
|
|
|
PANIC_REBOOT_WAIT_TIME);
|
|
|
|
for (loop = PANIC_REBOOT_WAIT_TIME * 10;
|
|
|
|
loop > 0; --loop) {
|
|
|
|
DELAY(1000 * 100); /* 1/10th second */
|
|
|
|
/* Did user type a key? */
|
|
|
|
if (cncheckc() != -1)
|
|
|
|
break;
|
1996-08-19 02:19:23 +00:00
|
|
|
}
|
1998-09-15 08:49:52 +00:00
|
|
|
if (!loop)
|
1999-08-21 06:24:40 +00:00
|
|
|
return;
|
1996-08-19 02:19:23 +00:00
|
|
|
}
|
1998-09-15 08:49:52 +00:00
|
|
|
} else { /* zero time specified - reboot NOW */
|
1999-08-21 06:24:40 +00:00
|
|
|
return;
|
1996-08-19 02:19:23 +00:00
|
|
|
}
|
2002-01-18 22:45:29 +00:00
|
|
|
printf("--> Press a key on the console to reboot,\n");
|
|
|
|
printf("--> or switch off the system now.\n");
|
1998-09-15 08:49:52 +00:00
|
|
|
cngetc();
|
1996-08-19 02:19:23 +00:00
|
|
|
}
|
1999-08-21 06:24:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Everything done, now reset
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
shutdown_reset(void *junk, int howto)
|
|
|
|
{
|
1996-08-19 02:19:23 +00:00
|
|
|
printf("Rebooting...\n");
|
|
|
|
DELAY(1000000); /* wait 1 sec for printf's to complete and be read */
|
1996-08-19 20:07:07 +00:00
|
|
|
/* cpu_boot(howto); */ /* doesn't do anything at the moment */
|
1996-08-19 02:19:23 +00:00
|
|
|
cpu_reset();
|
1999-08-21 06:24:40 +00:00
|
|
|
/* NOTREACHED */ /* assuming reset worked */
|
1996-08-19 02:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Magic number for savecore
|
|
|
|
*
|
|
|
|
* exported (symorder) and used at least by savecore(8)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static u_long const dumpmag = 0x8fca0101UL;
|
|
|
|
|
|
|
|
static int dumpsize = 0; /* also for savecore */
|
|
|
|
|
|
|
|
static int dodump = 1;
|
1999-07-17 20:47:52 +00:00
|
|
|
|
|
|
|
SYSCTL_INT(_machdep, OID_AUTO, do_dump, CTLFLAG_RW, &dodump, 0,
|
|
|
|
"Try to perform coredump on kernel panic");
|
|
|
|
|
|
|
|
static int
|
2000-09-03 06:44:53 +00:00
|
|
|
setdumpdev(dev_t dev)
|
1999-07-17 20:47:52 +00:00
|
|
|
{
|
1999-08-29 14:54:11 +00:00
|
|
|
int psize;
|
1999-07-17 20:47:52 +00:00
|
|
|
long newdumplo;
|
|
|
|
|
|
|
|
if (dev == NODEV) {
|
|
|
|
dumpdev = dev;
|
|
|
|
return (0);
|
|
|
|
}
|
1999-08-13 10:29:38 +00:00
|
|
|
if (devsw(dev) == NULL)
|
1999-07-17 20:47:52 +00:00
|
|
|
return (ENXIO); /* XXX is this right? */
|
1999-08-13 10:29:38 +00:00
|
|
|
if (devsw(dev)->d_psize == NULL)
|
1999-07-17 20:47:52 +00:00
|
|
|
return (ENXIO); /* XXX should be ENODEV ? */
|
1999-08-13 10:29:38 +00:00
|
|
|
psize = devsw(dev)->d_psize(dev);
|
1999-07-17 20:47:52 +00:00
|
|
|
if (psize == -1)
|
|
|
|
return (ENXIO); /* XXX should be ENODEV ? */
|
|
|
|
/*
|
1999-08-29 14:54:11 +00:00
|
|
|
* XXX should clean up checking in dumpsys() to be more like this.
|
1999-07-17 20:47:52 +00:00
|
|
|
*/
|
2001-08-15 11:35:45 +00:00
|
|
|
newdumplo = psize - Maxmem * (PAGE_SIZE / DEV_BSIZE);
|
|
|
|
if (newdumplo <= LABELSECTOR)
|
1999-07-17 20:47:52 +00:00
|
|
|
return (ENOSPC);
|
|
|
|
dumpdev = dev;
|
|
|
|
dumplo = newdumplo;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1996-08-19 02:19:23 +00:00
|
|
|
|
1997-11-25 07:07:48 +00:00
|
|
|
/* ARGSUSED */
|
|
|
|
static void
|
2000-09-03 06:44:53 +00:00
|
|
|
dump_conf(void *dummy)
|
1997-11-25 07:07:48 +00:00
|
|
|
{
|
2002-01-21 01:16:11 +00:00
|
|
|
char *path;
|
|
|
|
dev_t dev;
|
|
|
|
|
|
|
|
path = malloc(MNAMELEN, M_TEMP, M_WAITOK);
|
|
|
|
if (TUNABLE_STR_FETCH("dumpdev", path, MNAMELEN) != 0) {
|
|
|
|
dev = getdiskbyname(path);
|
|
|
|
if (dev != NODEV)
|
|
|
|
dumpdev = dev;
|
|
|
|
}
|
|
|
|
free(path, M_TEMP);
|
1999-07-17 20:47:52 +00:00
|
|
|
if (setdumpdev(dumpdev) != 0)
|
|
|
|
dumpdev = NODEV;
|
1997-11-25 07:07:48 +00:00
|
|
|
}
|
1999-07-17 20:47:52 +00:00
|
|
|
|
1997-11-25 07:07:48 +00:00
|
|
|
SYSINIT(dump_conf, SI_SUB_DUMP_CONF, SI_ORDER_FIRST, dump_conf, NULL)
|
|
|
|
|
1999-07-17 20:47:52 +00:00
|
|
|
static int
|
2000-07-04 11:25:35 +00:00
|
|
|
sysctl_kern_dumpdev(SYSCTL_HANDLER_ARGS)
|
1999-07-17 20:47:52 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
udev_t ndumpdev;
|
|
|
|
|
1999-11-28 16:25:17 +00:00
|
|
|
ndumpdev = dev2udev(dumpdev);
|
1999-07-17 20:47:52 +00:00
|
|
|
error = sysctl_handle_opaque(oidp, &ndumpdev, sizeof ndumpdev, req);
|
|
|
|
if (error == 0 && req->newptr != NULL)
|
1999-11-28 16:25:17 +00:00
|
|
|
error = setdumpdev(udev2dev(ndumpdev, 0));
|
1999-07-17 20:47:52 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSCTL_PROC(_kern, KERN_DUMPDEV, dumpdev, CTLTYPE_OPAQUE|CTLFLAG_RW,
|
|
|
|
0, sizeof dumpdev, sysctl_kern_dumpdev, "T,dev_t", "");
|
|
|
|
|
1996-08-19 02:19:23 +00:00
|
|
|
/*
|
|
|
|
* Doadump comes here after turning off memory management and
|
|
|
|
* getting on the dump stack, either when called above, or by
|
|
|
|
* the auto-restart code.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
dumpsys(void)
|
|
|
|
{
|
1999-08-11 14:02:20 +00:00
|
|
|
int error;
|
1996-08-19 02:19:23 +00:00
|
|
|
|
2000-09-03 06:35:04 +00:00
|
|
|
savectx(&dumppcb);
|
1996-08-19 02:19:23 +00:00
|
|
|
if (!dodump)
|
|
|
|
return;
|
|
|
|
if (dumpdev == NODEV)
|
|
|
|
return;
|
1999-08-13 10:29:38 +00:00
|
|
|
if (!(devsw(dumpdev)))
|
1996-08-19 02:19:23 +00:00
|
|
|
return;
|
1999-08-13 10:29:38 +00:00
|
|
|
if (!(devsw(dumpdev)->d_dump))
|
1996-08-19 02:19:23 +00:00
|
|
|
return;
|
2001-09-20 06:08:53 +00:00
|
|
|
if (dumping++) {
|
|
|
|
dumping--;
|
|
|
|
printf("Dump already in progress, bailing...\n");
|
|
|
|
return;
|
|
|
|
}
|
1996-08-19 02:19:23 +00:00
|
|
|
dumpsize = Maxmem;
|
1999-08-29 14:54:11 +00:00
|
|
|
printf("\ndumping to dev %s, offset %ld\n", devtoname(dumpdev), dumplo);
|
1996-08-19 02:19:23 +00:00
|
|
|
printf("dump ");
|
1999-08-13 10:29:38 +00:00
|
|
|
error = (*devsw(dumpdev)->d_dump)(dumpdev);
|
2001-09-20 06:08:53 +00:00
|
|
|
dumping--;
|
1999-08-11 14:02:20 +00:00
|
|
|
if (error == 0) {
|
|
|
|
printf("succeeded\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("failed, reason: ");
|
|
|
|
switch (error) {
|
|
|
|
case ENODEV:
|
|
|
|
printf("device doesn't support a dump routine\n");
|
|
|
|
break;
|
1996-08-19 02:19:23 +00:00
|
|
|
|
|
|
|
case ENXIO:
|
|
|
|
printf("device bad\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EFAULT:
|
|
|
|
printf("device not ready\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EINVAL:
|
|
|
|
printf("area improper\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EIO:
|
|
|
|
printf("i/o error\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EINTR:
|
|
|
|
printf("aborted from console\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1999-08-11 14:02:20 +00:00
|
|
|
printf("unknown, error = %d\n", error);
|
1996-08-19 02:19:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-28 01:37:29 +00:00
|
|
|
int
|
2001-11-13 01:08:54 +00:00
|
|
|
dumpstatus(vm_offset_t addr, off_t count)
|
2001-03-28 01:37:29 +00:00
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
|
|
|
if (addr % (1024 * 1024) == 0) {
|
|
|
|
#ifdef HW_WDOG
|
|
|
|
if (wdog_tickler)
|
|
|
|
(*wdog_tickler)();
|
|
|
|
#endif
|
2001-11-13 01:08:54 +00:00
|
|
|
printf("%ld ", (long)(count / (1024 * 1024)));
|
2001-03-28 01:37:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((c = cncheckc()) == 0x03)
|
|
|
|
return -1;
|
|
|
|
else if (c != -1)
|
|
|
|
printf("[CTRL-C to abort] ");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-04-17 04:18:08 +00:00
|
|
|
#ifdef SMP
|
|
|
|
static u_int panic_cpu = NOCPU;
|
|
|
|
#endif
|
|
|
|
|
1996-08-19 02:19:23 +00:00
|
|
|
/*
|
|
|
|
* Panic is called on unresolvable fatal errors. It prints "panic: mesg",
|
|
|
|
* and then reboots. If we are called twice, then we avoid trying to sync
|
|
|
|
* the disks as this often leads to recursive panics.
|
2001-09-01 19:04:37 +00:00
|
|
|
*
|
|
|
|
* MPSAFE
|
1996-08-19 02:19:23 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
panic(const char *fmt, ...)
|
|
|
|
{
|
2001-09-10 21:04:49 +00:00
|
|
|
int bootopt;
|
1996-08-19 02:19:23 +00:00
|
|
|
va_list ap;
|
1998-09-06 06:25:18 +00:00
|
|
|
static char buf[256];
|
1996-08-19 02:19:23 +00:00
|
|
|
|
2000-09-07 01:33:02 +00:00
|
|
|
#ifdef SMP
|
2001-08-21 22:55:20 +00:00
|
|
|
/*
|
|
|
|
* We don't want multiple CPU's to panic at the same time, so we
|
|
|
|
* use panic_cpu as a simple spinlock. We have to keep checking
|
|
|
|
* panic_cpu if we are spinning in case the panic on the first
|
|
|
|
* CPU is canceled.
|
|
|
|
*/
|
2001-09-10 21:04:49 +00:00
|
|
|
if (panic_cpu != PCPU_GET(cpuid))
|
2001-08-21 22:55:20 +00:00
|
|
|
while (atomic_cmpset_int(&panic_cpu, NOCPU,
|
2001-09-10 21:04:49 +00:00
|
|
|
PCPU_GET(cpuid)) == 0)
|
2001-08-21 22:55:20 +00:00
|
|
|
while (panic_cpu != NOCPU)
|
|
|
|
; /* nothing */
|
2000-09-07 01:33:02 +00:00
|
|
|
#endif
|
|
|
|
|
1996-08-19 02:19:23 +00:00
|
|
|
bootopt = RB_AUTOBOOT | RB_DUMP;
|
|
|
|
if (panicstr)
|
|
|
|
bootopt |= RB_NOSYNC;
|
|
|
|
else
|
|
|
|
panicstr = fmt;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
1998-12-04 22:54:57 +00:00
|
|
|
(void)vsnprintf(buf, sizeof(buf), fmt, ap);
|
1998-09-06 06:25:18 +00:00
|
|
|
if (panicstr == fmt)
|
|
|
|
panicstr = buf;
|
1996-08-19 02:19:23 +00:00
|
|
|
va_end(ap);
|
1998-09-06 06:25:18 +00:00
|
|
|
printf("panic: %s\n", buf);
|
1997-05-24 18:35:44 +00:00
|
|
|
#ifdef SMP
|
2001-02-06 11:21:58 +00:00
|
|
|
/* two separate prints in case of an unmapped page and trap */
|
2001-01-10 04:43:51 +00:00
|
|
|
printf("cpuid = %d; ", PCPU_GET(cpuid));
|
2000-11-29 01:33:15 +00:00
|
|
|
#ifdef APIC_IO
|
1997-09-05 08:54:55 +00:00
|
|
|
printf("lapic.id = %08x\n", lapic.id);
|
1997-05-24 18:35:44 +00:00
|
|
|
#endif
|
2000-11-29 01:33:15 +00:00
|
|
|
#endif
|
1996-08-19 02:19:23 +00:00
|
|
|
|
|
|
|
#if defined(DDB)
|
|
|
|
if (debugger_on_panic)
|
|
|
|
Debugger ("panic");
|
2001-08-23 20:32:21 +00:00
|
|
|
#ifdef RESTARTABLE_PANICS
|
2001-08-21 22:55:20 +00:00
|
|
|
/* See if the user aborted the panic, in which case we continue. */
|
|
|
|
if (panicstr == NULL) {
|
|
|
|
#ifdef SMP
|
|
|
|
atomic_store_rel_int(&panic_cpu, NOCPU);
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
2001-08-23 20:32:21 +00:00
|
|
|
#endif
|
1996-08-19 02:19:23 +00:00
|
|
|
#endif
|
2001-10-19 23:32:03 +00:00
|
|
|
if (!sync_on_panic)
|
|
|
|
bootopt |= RB_NOSYNC;
|
1996-08-19 02:19:23 +00:00
|
|
|
boot(bootopt);
|
|
|
|
}
|
|
|
|
|
1999-01-30 19:28:30 +00:00
|
|
|
/*
|
|
|
|
* Support for poweroff delay.
|
|
|
|
*/
|
1999-12-07 04:35:37 +00:00
|
|
|
#ifndef POWEROFF_DELAY
|
|
|
|
# define POWEROFF_DELAY 5000
|
|
|
|
#endif
|
|
|
|
static int poweroff_delay = POWEROFF_DELAY;
|
|
|
|
|
1999-01-30 19:28:30 +00:00
|
|
|
SYSCTL_INT(_kern_shutdown, OID_AUTO, poweroff_delay, CTLFLAG_RW,
|
|
|
|
&poweroff_delay, 0, "");
|
|
|
|
|
1999-08-21 06:24:40 +00:00
|
|
|
static void
|
|
|
|
poweroff_wait(void *junk, int howto)
|
1999-01-30 19:28:30 +00:00
|
|
|
{
|
|
|
|
if(!(howto & RB_POWEROFF) || poweroff_delay <= 0)
|
|
|
|
return;
|
|
|
|
DELAY(poweroff_delay * 1000);
|
|
|
|
}
|
2000-01-07 08:36:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Some system processes (e.g. syncer) need to be stopped at appropriate
|
|
|
|
* points in their main loops prior to a system shutdown, so that they
|
|
|
|
* won't interfere with the shutdown process (e.g. by holding a disk buf
|
|
|
|
* to cause sync to fail). For each of these system processes, register
|
|
|
|
* shutdown_kproc() as a handler for one of shutdown events.
|
|
|
|
*/
|
|
|
|
static int kproc_shutdown_wait = 60;
|
|
|
|
SYSCTL_INT(_kern_shutdown, OID_AUTO, kproc_shutdown_wait, CTLFLAG_RW,
|
|
|
|
&kproc_shutdown_wait, 0, "");
|
|
|
|
|
|
|
|
void
|
2000-12-15 20:08:20 +00:00
|
|
|
kproc_shutdown(void *arg, int howto)
|
2000-01-07 08:36:44 +00:00
|
|
|
{
|
|
|
|
struct proc *p;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (panicstr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
p = (struct proc *)arg;
|
|
|
|
printf("Waiting (max %d seconds) for system process `%s' to stop...",
|
2000-01-12 17:26:42 +00:00
|
|
|
kproc_shutdown_wait, p->p_comm);
|
2000-12-15 20:08:20 +00:00
|
|
|
error = kthread_suspend(p, kproc_shutdown_wait * hz);
|
2000-01-07 08:36:44 +00:00
|
|
|
|
|
|
|
if (error == EWOULDBLOCK)
|
|
|
|
printf("timed out\n");
|
|
|
|
else
|
|
|
|
printf("stopped\n");
|
|
|
|
}
|