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.
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2003-06-11 00:56:59 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
Add textdump(4) facility, which provides an alternative form of kernel
dump using mechanically generated/extracted debugging output rather than
a simple memory dump. Current sources of debugging output are:
- DDB output capture buffer, if there is captured output to save
- Kernel message buffer
- Kernel configuration, if included in kernel
- Kernel version string
- Panic message
Textdumps are stored in swap/dump partitions as with regular dumps, but
are laid out as ustar files in order to allow multiple parts to be stored
as a stream of sequentially written blocks. Blocks are written out in
reverse order, as the size of a textdump isn't known a priori. As with
regular dumps, they will be extracted using savecore(8).
One new DDB(4) command is added, "textdump", which accepts "set",
"unset", and "status" arguments. By default, normal kernel dumps are
generated unless "textdump set" is run in order to schedule a textdump.
It can be canceled using "textdump unset" to restore generation of a
normal kernel dump.
Several sysctls exist to configure aspects of textdumps;
debug.ddb.textdump.pending can be set to check whether a textdump is
pending, or set/unset in order to control whether the next kernel dump
will be a textdump from userspace.
While textdumps don't have to be generated as a result of a DDB script
run automatically as part of a kernel panic, this is a particular useful
way to use them, as instead of generating a complete memory dump, a
simple transcript of an automated DDB session can be captured using the
DDB output capture and textdump facilities. This can be used to
generate quite brief kernel bug reports rich in debugging information
but not dependent on kernel symbol tables or precisely synchronized
source code. Most textdumps I generate are less than 100k including
the full message buffer. Using textdumps with an interactive debugging
session is also useful, with capture being enabled/disabled in order to
record some but not all of the DDB session.
MFC after: 3 months
2007-12-26 11:32:33 +00:00
|
|
|
#include "opt_ddb.h"
|
2004-07-10 21:36:01 +00:00
|
|
|
#include "opt_kdb.h"
|
1997-08-31 23:08:38 +00:00
|
|
|
#include "opt_panic.h"
|
2004-09-02 18:59:15 +00:00
|
|
|
#include "opt_sched.h"
|
2011-04-28 16:02:05 +00:00
|
|
|
#include "opt_watchdog.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>
|
|
|
|
#include <sys/eventhandler.h>
|
2009-05-29 21:27:12 +00:00
|
|
|
#include <sys/jail.h>
|
2004-07-10 21:36:01 +00:00
|
|
|
#include <sys/kdb.h>
|
1996-08-19 02:19:23 +00:00
|
|
|
#include <sys/kernel.h>
|
2008-10-01 22:08:53 +00:00
|
|
|
#include <sys/kerneldump.h>
|
2000-01-07 08:36:44 +00:00
|
|
|
#include <sys/kthread.h>
|
2012-12-07 08:25:08 +00:00
|
|
|
#include <sys/ktr.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>
|
2006-11-06 13:42:10 +00:00
|
|
|
#include <sys/priv.h>
|
2001-06-25 18:30:42 +00:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/reboot.h>
|
|
|
|
#include <sys/resourcevar.h>
|
2004-11-05 18:29:10 +00:00
|
|
|
#include <sys/sched.h>
|
2010-04-19 23:27:54 +00:00
|
|
|
#include <sys/smp.h>
|
1996-08-19 02:19:23 +00:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/sysproto.h>
|
2011-09-08 12:56:26 +00:00
|
|
|
#include <sys/vnode.h>
|
2011-04-28 16:02:05 +00:00
|
|
|
#include <sys/watchdog.h>
|
1996-08-19 02:19:23 +00:00
|
|
|
|
Add textdump(4) facility, which provides an alternative form of kernel
dump using mechanically generated/extracted debugging output rather than
a simple memory dump. Current sources of debugging output are:
- DDB output capture buffer, if there is captured output to save
- Kernel message buffer
- Kernel configuration, if included in kernel
- Kernel version string
- Panic message
Textdumps are stored in swap/dump partitions as with regular dumps, but
are laid out as ustar files in order to allow multiple parts to be stored
as a stream of sequentially written blocks. Blocks are written out in
reverse order, as the size of a textdump isn't known a priori. As with
regular dumps, they will be extracted using savecore(8).
One new DDB(4) command is added, "textdump", which accepts "set",
"unset", and "status" arguments. By default, normal kernel dumps are
generated unless "textdump set" is run in order to schedule a textdump.
It can be canceled using "textdump unset" to restore generation of a
normal kernel dump.
Several sysctls exist to configure aspects of textdumps;
debug.ddb.textdump.pending can be set to check whether a textdump is
pending, or set/unset in order to control whether the next kernel dump
will be a textdump from userspace.
While textdumps don't have to be generated as a result of a DDB script
run automatically as part of a kernel panic, this is a particular useful
way to use them, as instead of generating a complete memory dump, a
simple transcript of an automated DDB session can be captured using the
DDB output capture and textdump facilities. This can be used to
generate quite brief kernel bug reports rich in debugging information
but not dependent on kernel symbol tables or precisely synchronized
source code. Most textdumps I generate are less than 100k including
the full message buffer. Using textdumps with an interactive debugging
session is also useful, with capture being enabled/disabled in order to
record some but not all of the DDB session.
MFC after: 3 months
2007-12-26 11:32:33 +00:00
|
|
|
#include <ddb/ddb.h>
|
|
|
|
|
2003-08-16 16:57:57 +00:00
|
|
|
#include <machine/cpu.h>
|
2002-04-08 06:59:13 +00:00
|
|
|
#include <machine/pcb.h>
|
2002-03-07 04:43:51 +00:00
|
|
|
#include <machine/smp.h>
|
1996-08-19 02:19:23 +00:00
|
|
|
|
2006-10-22 11:52:19 +00:00
|
|
|
#include <security/mac/mac_framework.h>
|
|
|
|
|
2006-04-10 10:03:41 +00:00
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_object.h>
|
|
|
|
#include <vm/vm_page.h>
|
|
|
|
#include <vm/vm_pager.h>
|
|
|
|
#include <vm/swap_pager.h>
|
|
|
|
|
1996-08-19 02:19:23 +00:00
|
|
|
#include <sys/signalvar.h>
|
|
|
|
|
|
|
|
#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>
|
|
|
|
|
2004-07-10 21:36:01 +00:00
|
|
|
#ifdef KDB
|
|
|
|
#ifdef KDB_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
|
2011-12-13 17:59:16 +00:00
|
|
|
SYSCTL_INT(_debug, OID_AUTO, debugger_on_panic,
|
2011-12-14 02:31:32 +00:00
|
|
|
CTLFLAG_RW | CTLFLAG_SECURE | CTLFLAG_TUN,
|
|
|
|
&debugger_on_panic, 0, "Run debugger on kernel panic");
|
2010-10-01 09:34:41 +00:00
|
|
|
TUNABLE_INT("debug.debugger_on_panic", &debugger_on_panic);
|
2002-09-19 18:49:46 +00:00
|
|
|
|
2004-07-10 21:36:01 +00:00
|
|
|
#ifdef KDB_TRACE
|
2010-10-01 09:34:41 +00:00
|
|
|
static int trace_on_panic = 1;
|
2002-09-19 18:49:46 +00:00
|
|
|
#else
|
2010-10-01 09:34:41 +00:00
|
|
|
static int trace_on_panic = 0;
|
2002-09-19 18:49:46 +00:00
|
|
|
#endif
|
2011-12-13 17:59:16 +00:00
|
|
|
SYSCTL_INT(_debug, OID_AUTO, trace_on_panic,
|
2011-12-14 02:31:32 +00:00
|
|
|
CTLFLAG_RW | CTLFLAG_SECURE | CTLFLAG_TUN,
|
|
|
|
&trace_on_panic, 0, "Print stack trace on kernel panic");
|
2010-10-01 09:34:41 +00:00
|
|
|
TUNABLE_INT("debug.trace_on_panic", &trace_on_panic);
|
2004-07-10 21:36:01 +00:00
|
|
|
#endif /* KDB */
|
1996-08-19 02:19:23 +00:00
|
|
|
|
2010-10-01 09:34:41 +00:00
|
|
|
static int sync_on_panic = 0;
|
|
|
|
SYSCTL_INT(_kern, OID_AUTO, sync_on_panic, CTLFLAG_RW | CTLFLAG_TUN,
|
2001-10-19 23:32:03 +00:00
|
|
|
&sync_on_panic, 0, "Do a sync before rebooting from a panic");
|
2010-10-01 09:34:41 +00:00
|
|
|
TUNABLE_INT("kern.sync_on_panic", &sync_on_panic);
|
2001-10-19 23:32:03 +00:00
|
|
|
|
2011-11-07 15:43:11 +00:00
|
|
|
static SYSCTL_NODE(_kern, OID_AUTO, shutdown, CTLFLAG_RW, 0,
|
|
|
|
"Shutdown environment");
|
1999-01-30 19:28:30 +00:00
|
|
|
|
2011-09-08 12:56:26 +00:00
|
|
|
#ifndef DIAGNOSTIC
|
|
|
|
static int show_busybufs;
|
|
|
|
#else
|
|
|
|
static int show_busybufs = 1;
|
|
|
|
#endif
|
|
|
|
SYSCTL_INT(_kern_shutdown, OID_AUTO, show_busybufs, CTLFLAG_RW,
|
|
|
|
&show_busybufs, 0, "");
|
|
|
|
|
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;
|
|
|
|
|
Here follows the new kernel dumping infrastructure.
Caveats:
The new savecore program is not complete in the sense that it emulates
enough of the old savecores features to do the job, but implements none
of the options yet.
I would appreciate if a userland hacker could help me out getting savecore
to do what we want it to do from a users point of view, compression,
email-notification, space reservation etc etc. (send me email if
you are interested).
Currently, savecore will scan all devices marked as "swap" or "dump" in
/etc/fstab _or_ any devices specified on the command-line.
All architectures but i386 lack an implementation of dumpsys(), but
looking at the i386 version it should be trivial for anybody familiar
with the platform(s) to provide this function.
Documentation is quite sparse at this time, more to come.
Details:
ATA and SCSI drivers should work as the dump formatting code has been
removed. The IDA, TWE and AAC have not yet been converted.
Dumpon now opens the device and uses ioctl(DIOCGKERNELDUMP) to set
the device as dumpdev. To implement the "off" argument, /dev/null
is used as the device.
Savecore will fail if handed any options since they are not (yet)
implemented. All devices marked "dump" or "swap" in /etc/fstab
will be scanned and dumps found will be saved to diskfiles
named from the MD5 hash of the header record. The header record
is dumped in readable format in the .info file. The kernel
is not saved. Only complete dumps will be saved.
All maintainer rights for this code are disclaimed: feel free to
improve and extend.
Sponsored by: DARPA, NAI Labs
2002-03-31 22:37:00 +00:00
|
|
|
int dumping; /* system is dumping */
|
2006-02-06 10:12:00 +00:00
|
|
|
int rebooting; /* system is rebooting */
|
Here follows the new kernel dumping infrastructure.
Caveats:
The new savecore program is not complete in the sense that it emulates
enough of the old savecores features to do the job, but implements none
of the options yet.
I would appreciate if a userland hacker could help me out getting savecore
to do what we want it to do from a users point of view, compression,
email-notification, space reservation etc etc. (send me email if
you are interested).
Currently, savecore will scan all devices marked as "swap" or "dump" in
/etc/fstab _or_ any devices specified on the command-line.
All architectures but i386 lack an implementation of dumpsys(), but
looking at the i386 version it should be trivial for anybody familiar
with the platform(s) to provide this function.
Documentation is quite sparse at this time, more to come.
Details:
ATA and SCSI drivers should work as the dump formatting code has been
removed. The IDA, TWE and AAC have not yet been converted.
Dumpon now opens the device and uses ioctl(DIOCGKERNELDUMP) to set
the device as dumpdev. To implement the "off" argument, /dev/null
is used as the device.
Savecore will fail if handed any options since they are not (yet)
implemented. All devices marked "dump" or "swap" in /etc/fstab
will be scanned and dumps found will be saved to diskfiles
named from the MD5 hash of the header record. The header record
is dumped in readable format in the .info file. The kernel
is not saved. Only complete dumps will be saved.
All maintainer rights for this code are disclaimed: feel free to
improve and extend.
Sponsored by: DARPA, NAI Labs
2002-03-31 22:37:00 +00:00
|
|
|
static struct dumperinfo dumper; /* our selected dumper */
|
2004-07-10 21:36:01 +00:00
|
|
|
|
|
|
|
/* Context information for dump-debuggers. */
|
|
|
|
static struct pcb dumppcb; /* Registers. */
|
2012-05-22 07:23:41 +00:00
|
|
|
lwpid_t dumptid; /* Thread ID. */
|
2000-10-13 21:49:19 +00:00
|
|
|
|
2000-09-03 06:44:53 +00:00
|
|
|
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);
|
2012-12-07 08:25:08 +00:00
|
|
|
static void vpanic(const char *fmt, va_list ap) __dead2;
|
1999-08-21 06:24:40 +00:00
|
|
|
|
|
|
|
/* register various local shutdown events */
|
2003-02-14 12:44:48 +00:00
|
|
|
static void
|
1999-08-21 06:24:40 +00:00
|
|
|
shutdown_conf(void *unused)
|
|
|
|
{
|
2003-02-14 12:44:48 +00:00
|
|
|
|
|
|
|
EVENTHANDLER_REGISTER(shutdown_final, poweroff_wait, NULL,
|
2010-10-24 16:31:57 +00:00
|
|
|
SHUTDOWN_PRI_FIRST);
|
2003-02-14 12:44:48 +00:00
|
|
|
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-08-21 06:24:40 +00:00
|
|
|
}
|
1999-07-17 20:47:52 +00:00
|
|
|
|
2008-03-16 10:58:09 +00:00
|
|
|
SYSINIT(shutdown_conf, SI_SUB_INTRINSIC, SI_ORDER_ANY, shutdown_conf, NULL);
|
1996-08-19 02:19:23 +00:00
|
|
|
|
|
|
|
/*
|
2007-03-04 22:36:48 +00:00
|
|
|
* The system call that results in a reboot.
|
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
|
2011-09-16 13:58:51 +00:00
|
|
|
sys_reboot(struct thread *td, struct reboot_args *uap)
|
1996-08-19 02:19:23 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2002-10-27 07:03:29 +00:00
|
|
|
error = 0;
|
|
|
|
#ifdef MAC
|
2007-10-24 19:04:04 +00:00
|
|
|
error = mac_system_check_reboot(td->td_ucred, uap->opt);
|
2002-10-27 07:03:29 +00:00
|
|
|
#endif
|
|
|
|
if (error == 0)
|
2006-11-06 13:42:10 +00:00
|
|
|
error = priv_check(td, PRIV_REBOOT);
|
2002-10-27 07:03:29 +00:00
|
|
|
if (error == 0) {
|
|
|
|
mtx_lock(&Giant);
|
2010-10-18 04:30:27 +00:00
|
|
|
kern_reboot(uap->opt);
|
2002-10-27 07:03:29 +00:00
|
|
|
mtx_unlock(&Giant);
|
|
|
|
}
|
2001-09-01 19:04:37 +00:00
|
|
|
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
|
|
|
{
|
2003-02-14 12:44:48 +00:00
|
|
|
|
2000-08-31 00:08:50 +00:00
|
|
|
shutdown_howto = howto;
|
2003-02-14 12:44:48 +00:00
|
|
|
|
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);
|
2011-09-16 13:58:51 +00:00
|
|
|
kern_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 */
|
2010-10-18 04:30:27 +00:00
|
|
|
kern_reboot(RB_NOSYNC);
|
1996-08-19 02:19:23 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
static int waittime = -1;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-06-07 01:28:12 +00:00
|
|
|
int
|
|
|
|
doadump(boolean_t textdump)
|
2002-04-08 06:59:13 +00:00
|
|
|
{
|
2011-06-07 01:28:12 +00:00
|
|
|
boolean_t coredump;
|
2003-02-14 12:44:48 +00:00
|
|
|
|
2011-06-07 01:28:12 +00:00
|
|
|
if (dumping)
|
|
|
|
return (EBUSY);
|
|
|
|
if (dumper.dumper == NULL)
|
|
|
|
return (ENXIO);
|
2004-07-19 18:03:02 +00:00
|
|
|
|
2002-04-08 06:59:13 +00:00
|
|
|
savectx(&dumppcb);
|
2004-07-10 21:36:01 +00:00
|
|
|
dumptid = curthread->td_tid;
|
2002-04-08 06:59:13 +00:00
|
|
|
dumping++;
|
2011-06-07 01:28:12 +00:00
|
|
|
|
|
|
|
coredump = TRUE;
|
Add textdump(4) facility, which provides an alternative form of kernel
dump using mechanically generated/extracted debugging output rather than
a simple memory dump. Current sources of debugging output are:
- DDB output capture buffer, if there is captured output to save
- Kernel message buffer
- Kernel configuration, if included in kernel
- Kernel version string
- Panic message
Textdumps are stored in swap/dump partitions as with regular dumps, but
are laid out as ustar files in order to allow multiple parts to be stored
as a stream of sequentially written blocks. Blocks are written out in
reverse order, as the size of a textdump isn't known a priori. As with
regular dumps, they will be extracted using savecore(8).
One new DDB(4) command is added, "textdump", which accepts "set",
"unset", and "status" arguments. By default, normal kernel dumps are
generated unless "textdump set" is run in order to schedule a textdump.
It can be canceled using "textdump unset" to restore generation of a
normal kernel dump.
Several sysctls exist to configure aspects of textdumps;
debug.ddb.textdump.pending can be set to check whether a textdump is
pending, or set/unset in order to control whether the next kernel dump
will be a textdump from userspace.
While textdumps don't have to be generated as a result of a DDB script
run automatically as part of a kernel panic, this is a particular useful
way to use them, as instead of generating a complete memory dump, a
simple transcript of an automated DDB session can be captured using the
DDB output capture and textdump facilities. This can be used to
generate quite brief kernel bug reports rich in debugging information
but not dependent on kernel symbol tables or precisely synchronized
source code. Most textdumps I generate are less than 100k including
the full message buffer. Using textdumps with an interactive debugging
session is also useful, with capture being enabled/disabled in order to
record some but not all of the DDB session.
MFC after: 3 months
2007-12-26 11:32:33 +00:00
|
|
|
#ifdef DDB
|
2011-06-07 01:28:12 +00:00
|
|
|
if (textdump && textdump_pending) {
|
|
|
|
coredump = FALSE;
|
Add textdump(4) facility, which provides an alternative form of kernel
dump using mechanically generated/extracted debugging output rather than
a simple memory dump. Current sources of debugging output are:
- DDB output capture buffer, if there is captured output to save
- Kernel message buffer
- Kernel configuration, if included in kernel
- Kernel version string
- Panic message
Textdumps are stored in swap/dump partitions as with regular dumps, but
are laid out as ustar files in order to allow multiple parts to be stored
as a stream of sequentially written blocks. Blocks are written out in
reverse order, as the size of a textdump isn't known a priori. As with
regular dumps, they will be extracted using savecore(8).
One new DDB(4) command is added, "textdump", which accepts "set",
"unset", and "status" arguments. By default, normal kernel dumps are
generated unless "textdump set" is run in order to schedule a textdump.
It can be canceled using "textdump unset" to restore generation of a
normal kernel dump.
Several sysctls exist to configure aspects of textdumps;
debug.ddb.textdump.pending can be set to check whether a textdump is
pending, or set/unset in order to control whether the next kernel dump
will be a textdump from userspace.
While textdumps don't have to be generated as a result of a DDB script
run automatically as part of a kernel panic, this is a particular useful
way to use them, as instead of generating a complete memory dump, a
simple transcript of an automated DDB session can be captured using the
DDB output capture and textdump facilities. This can be used to
generate quite brief kernel bug reports rich in debugging information
but not dependent on kernel symbol tables or precisely synchronized
source code. Most textdumps I generate are less than 100k including
the full message buffer. Using textdumps with an interactive debugging
session is also useful, with capture being enabled/disabled in order to
record some but not all of the DDB session.
MFC after: 3 months
2007-12-26 11:32:33 +00:00
|
|
|
textdump_dumpsys(&dumper);
|
2011-06-07 01:28:12 +00:00
|
|
|
}
|
Add textdump(4) facility, which provides an alternative form of kernel
dump using mechanically generated/extracted debugging output rather than
a simple memory dump. Current sources of debugging output are:
- DDB output capture buffer, if there is captured output to save
- Kernel message buffer
- Kernel configuration, if included in kernel
- Kernel version string
- Panic message
Textdumps are stored in swap/dump partitions as with regular dumps, but
are laid out as ustar files in order to allow multiple parts to be stored
as a stream of sequentially written blocks. Blocks are written out in
reverse order, as the size of a textdump isn't known a priori. As with
regular dumps, they will be extracted using savecore(8).
One new DDB(4) command is added, "textdump", which accepts "set",
"unset", and "status" arguments. By default, normal kernel dumps are
generated unless "textdump set" is run in order to schedule a textdump.
It can be canceled using "textdump unset" to restore generation of a
normal kernel dump.
Several sysctls exist to configure aspects of textdumps;
debug.ddb.textdump.pending can be set to check whether a textdump is
pending, or set/unset in order to control whether the next kernel dump
will be a textdump from userspace.
While textdumps don't have to be generated as a result of a DDB script
run automatically as part of a kernel panic, this is a particular useful
way to use them, as instead of generating a complete memory dump, a
simple transcript of an automated DDB session can be captured using the
DDB output capture and textdump facilities. This can be used to
generate quite brief kernel bug reports rich in debugging information
but not dependent on kernel symbol tables or precisely synchronized
source code. Most textdumps I generate are less than 100k including
the full message buffer. Using textdumps with an interactive debugging
session is also useful, with capture being enabled/disabled in order to
record some but not all of the DDB session.
MFC after: 3 months
2007-12-26 11:32:33 +00:00
|
|
|
#endif
|
2011-06-07 01:28:12 +00:00
|
|
|
if (coredump)
|
Add textdump(4) facility, which provides an alternative form of kernel
dump using mechanically generated/extracted debugging output rather than
a simple memory dump. Current sources of debugging output are:
- DDB output capture buffer, if there is captured output to save
- Kernel message buffer
- Kernel configuration, if included in kernel
- Kernel version string
- Panic message
Textdumps are stored in swap/dump partitions as with regular dumps, but
are laid out as ustar files in order to allow multiple parts to be stored
as a stream of sequentially written blocks. Blocks are written out in
reverse order, as the size of a textdump isn't known a priori. As with
regular dumps, they will be extracted using savecore(8).
One new DDB(4) command is added, "textdump", which accepts "set",
"unset", and "status" arguments. By default, normal kernel dumps are
generated unless "textdump set" is run in order to schedule a textdump.
It can be canceled using "textdump unset" to restore generation of a
normal kernel dump.
Several sysctls exist to configure aspects of textdumps;
debug.ddb.textdump.pending can be set to check whether a textdump is
pending, or set/unset in order to control whether the next kernel dump
will be a textdump from userspace.
While textdumps don't have to be generated as a result of a DDB script
run automatically as part of a kernel panic, this is a particular useful
way to use them, as instead of generating a complete memory dump, a
simple transcript of an automated DDB session can be captured using the
DDB output capture and textdump facilities. This can be used to
generate quite brief kernel bug reports rich in debugging information
but not dependent on kernel symbol tables or precisely synchronized
source code. Most textdumps I generate are less than 100k including
the full message buffer. Using textdumps with an interactive debugging
session is also useful, with capture being enabled/disabled in order to
record some but not all of the DDB session.
MFC after: 3 months
2007-12-26 11:32:33 +00:00
|
|
|
dumpsys(&dumper);
|
2011-06-07 01:28:12 +00:00
|
|
|
|
2008-03-04 07:39:31 +00:00
|
|
|
dumping--;
|
2011-06-07 01:28:12 +00:00
|
|
|
return (0);
|
2002-04-08 06:59:13 +00:00
|
|
|
}
|
|
|
|
|
2005-09-08 06:30:05 +00:00
|
|
|
static int
|
|
|
|
isbufbusy(struct buf *bp)
|
|
|
|
{
|
|
|
|
if (((bp->b_flags & (B_INVAL | B_PERSISTENT)) == 0 &&
|
2008-01-19 17:36:23 +00:00
|
|
|
BUF_ISLOCKED(bp)) ||
|
2005-09-08 06:30:05 +00:00
|
|
|
((bp->b_flags & (B_DELWRI | B_INVAL)) == B_DELWRI))
|
|
|
|
return (1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1996-08-19 02:19:23 +00:00
|
|
|
/*
|
2004-11-07 06:58:45 +00:00
|
|
|
* Shutdown the system cleanly to prepare for reboot, halt, or power off.
|
1996-08-19 02:19:23 +00:00
|
|
|
*/
|
2010-10-18 04:30:27 +00:00
|
|
|
void
|
|
|
|
kern_reboot(int howto)
|
1996-08-19 02:19:23 +00:00
|
|
|
{
|
2004-08-15 19:17:23 +00:00
|
|
|
static int first_buf_printf = 1;
|
1996-08-19 02:19:23 +00:00
|
|
|
|
2004-11-08 04:52:26 +00:00
|
|
|
#if defined(SMP)
|
2004-11-07 06:58:45 +00:00
|
|
|
/*
|
|
|
|
* Bind us to CPU 0 so that all shutdown code runs there. Some
|
|
|
|
* systems don't shutdown properly (i.e., ACPI power off) if we
|
|
|
|
* run on another processor.
|
|
|
|
*/
|
panic: add a switch and infrastructure for stopping other CPUs in SMP case
Historical behavior of letting other CPUs merily go on is a default for
time being. The new behavior can be switched on via
kern.stop_scheduler_on_panic tunable and sysctl.
Stopping of the CPUs has (at least) the following benefits:
- more of the system state at panic time is preserved intact
- threads and interrupts do not interfere with dumping of the system
state
Only one thread runs uninterrupted after panic if stop_scheduler_on_panic
is set. That thread might call code that is also used in normal context
and that code might use locks to prevent concurrent execution of certain
parts. Those locks might be held by the stopped threads and would never
be released. To work around this issue, it was decided that instead of
explicit checks for panic context, we would rather put those checks
inside the locking primitives.
This change has substantial portions written and re-written by attilio
and kib at various times. Other changes are heavily based on the ideas
and patches submitted by jhb and mdf. bde has provided many insights
into the details and history of the current code.
The new behavior may cause problems for systems that use a USB keyboard
for interfacing with system console. This is because of some unusual
locking patterns in the ukbd code which have to be used because on one
hand ukbd is below syscons, but on the other hand it has to interface
with other usb code that uses regular mutexes/Giant for its concurrency
protection. Dumping to USB-connected disks may also be affected.
PR: amd64/139614 (at least)
In cooperation with: attilio, jhb, kib, mdf
Discussed with: arch@, bde
Tested by: Eugene Grosbein <eugen@grosbein.net>,
gnn,
Steven Hartland <killing@multiplay.co.uk>,
glebius,
Andrew Boyer <aboyer@averesystems.com>
(various versions of the patch)
MFC after: 3 months (or never)
2011-12-11 21:02:01 +00:00
|
|
|
if (!SCHEDULER_STOPPED()) {
|
|
|
|
thread_lock(curthread);
|
|
|
|
sched_bind(curthread, 0);
|
|
|
|
thread_unlock(curthread);
|
|
|
|
KASSERT(PCPU_GET(cpuid) == 0, ("boot: not running on cpu 0"));
|
|
|
|
}
|
2004-11-05 18:29:10 +00:00
|
|
|
#endif
|
2006-02-06 10:12:00 +00:00
|
|
|
/* We're in the process of rebooting. */
|
|
|
|
rebooting = 1;
|
2004-11-05 18:29:10 +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
|
|
|
/* We are out of the debugger now. */
|
2004-07-10 21:36:01 +00:00
|
|
|
kdb_active = 0;
|
2001-08-21 23:29:40 +00:00
|
|
|
|
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;
|
2004-07-02 20:21:44 +00:00
|
|
|
#ifndef PREEMPTION
|
2000-09-10 23:06:50 +00:00
|
|
|
int subiter;
|
2004-07-02 20:21:44 +00:00
|
|
|
#endif
|
1996-08-19 02:19:23 +00:00
|
|
|
|
|
|
|
waittime = 0;
|
|
|
|
|
2011-04-28 16:02:05 +00:00
|
|
|
wdog_kern_pat(WD_LASTVAL);
|
2011-09-16 13:58:51 +00:00
|
|
|
sys_sync(curthread, 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;
|
2005-09-08 06:30:05 +00:00
|
|
|
for (bp = &buf[nbuf]; --bp >= buf; )
|
|
|
|
if (isbufbusy(bp))
|
1996-08-19 02:19:23 +00:00
|
|
|
nbusy++;
|
2004-08-15 19:17:23 +00:00
|
|
|
if (nbusy == 0) {
|
|
|
|
if (first_buf_printf)
|
2004-10-04 13:13:23 +00:00
|
|
|
printf("All buffers synced.");
|
1996-08-19 02:19:23 +00:00
|
|
|
break;
|
2004-08-15 19:17:23 +00:00
|
|
|
}
|
|
|
|
if (first_buf_printf) {
|
|
|
|
printf("Syncing disks, buffers remaining... ");
|
|
|
|
first_buf_printf = 0;
|
|
|
|
}
|
1996-08-19 02:19:23 +00:00
|
|
|
printf("%d ", nbusy);
|
2000-09-10 23:06:50 +00:00
|
|
|
if (nbusy < pbusy)
|
|
|
|
iter = 0;
|
|
|
|
pbusy = nbusy;
|
2012-06-03 08:01:12 +00:00
|
|
|
|
2011-04-28 16:02:05 +00:00
|
|
|
wdog_kern_pat(WD_LASTVAL);
|
2011-09-16 13:58:51 +00:00
|
|
|
sys_sync(curthread, NULL);
|
2004-07-02 20:21:44 +00:00
|
|
|
|
|
|
|
#ifdef PREEMPTION
|
|
|
|
/*
|
|
|
|
* Drop Giant and spin for a while to allow
|
|
|
|
* interrupt threads to run.
|
|
|
|
*/
|
|
|
|
DROP_GIANT();
|
1998-03-08 09:59:44 +00:00
|
|
|
DELAY(50000 * iter);
|
2004-07-02 20:21:44 +00:00
|
|
|
PICKUP_GIANT();
|
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* Drop Giant and context switch several times to
|
|
|
|
* allow interrupt threads to run.
|
|
|
|
*/
|
|
|
|
DROP_GIANT();
|
|
|
|
for (subiter = 0; subiter < 50 * iter; subiter++) {
|
Commit 14/14 of sched_lock decomposition.
- Use thread_lock() rather than sched_lock for per-thread scheduling
sychronization.
- Use the per-process spinlock rather than the sched_lock for per-process
scheduling synchronization.
Tested by: kris, current@
Tested on: i386, amd64, ULE, 4BSD, libthr, libkse, PREEMPTION, etc.
Discussed with: kris, attilio, kmacy, jhb, julian, bde (small parts each)
2007-06-05 00:00:57 +00:00
|
|
|
thread_lock(curthread);
|
2004-07-02 20:21:44 +00:00
|
|
|
mi_switch(SW_VOL, NULL);
|
Commit 14/14 of sched_lock decomposition.
- Use thread_lock() rather than sched_lock for per-thread scheduling
sychronization.
- Use the per-process spinlock rather than the sched_lock for per-process
scheduling synchronization.
Tested by: kris, current@
Tested on: i386, amd64, ULE, 4BSD, libthr, libkse, PREEMPTION, etc.
Discussed with: kris, attilio, kmacy, jhb, julian, bde (small parts each)
2007-06-05 00:00:57 +00:00
|
|
|
thread_unlock(curthread);
|
2004-07-02 20:21:44 +00:00
|
|
|
DELAY(1000);
|
|
|
|
}
|
|
|
|
PICKUP_GIANT();
|
|
|
|
#endif
|
1998-11-13 22:40:37 +00:00
|
|
|
}
|
2004-08-10 01:32:05 +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; ) {
|
2005-09-08 06:30:05 +00:00
|
|
|
if (isbufbusy(bp)) {
|
2004-11-04 07:59:57 +00:00
|
|
|
#if 0
|
|
|
|
/* XXX: This is bogus. We should probably have a BO_REMOTE flag instead */
|
2004-06-17 17:16:53 +00:00
|
|
|
if (bp->b_dev == NULL) {
|
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;
|
|
|
|
}
|
2004-11-04 07:59:57 +00:00
|
|
|
#endif
|
1999-11-08 19:36:45 +00:00
|
|
|
nbusy++;
|
2011-09-08 12:56:26 +00:00
|
|
|
if (show_busybufs > 0) {
|
|
|
|
printf(
|
|
|
|
"%d: buf:%p, vnode:%p, flags:%0x, blkno:%jd, lblkno:%jd, buflock:",
|
|
|
|
nbusy, bp, bp->b_vp, bp->b_flags,
|
|
|
|
(intmax_t)bp->b_blkno,
|
|
|
|
(intmax_t)bp->b_lblkno);
|
|
|
|
BUF_LOCKPRINTINFO(bp);
|
|
|
|
if (show_busybufs > 1)
|
|
|
|
vn_printf(bp->b_vp,
|
|
|
|
"vnode content: ");
|
|
|
|
}
|
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).
|
|
|
|
*/
|
2004-08-15 19:17:23 +00:00
|
|
|
printf("Giving up on %d buffers\n", nbusy);
|
1996-08-19 02:19:23 +00:00
|
|
|
DELAY(5000000); /* 5 seconds */
|
|
|
|
} else {
|
2004-08-15 19:17:23 +00:00
|
|
|
if (!first_buf_printf)
|
|
|
|
printf("Final sync complete\n");
|
1996-08-19 02:19:23 +00:00
|
|
|
/*
|
|
|
|
* Unmount filesystems
|
|
|
|
*/
|
|
|
|
if (panicstr == 0)
|
|
|
|
vfs_unmountall();
|
|
|
|
}
|
2006-04-10 10:03:41 +00:00
|
|
|
swapoff_all();
|
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();
|
|
|
|
|
2011-12-17 15:11:22 +00:00
|
|
|
cngrab();
|
|
|
|
|
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);
|
2004-11-07 06:58:45 +00:00
|
|
|
|
2004-07-19 18:03:02 +00:00
|
|
|
if ((howto & (RB_HALT|RB_DUMP)) == RB_DUMP && !cold && !dumping)
|
2011-06-07 01:28:12 +00:00
|
|
|
doadump(TRUE);
|
1998-09-15 08:49:52 +00:00
|
|
|
|
|
|
|
/* 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)
|
|
|
|
{
|
2003-02-14 12:44:48 +00:00
|
|
|
|
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)
|
|
|
|
{
|
2003-02-14 12:44:48 +00:00
|
|
|
|
2010-04-19 23:27:54 +00:00
|
|
|
printf("Rebooting...\n");
|
|
|
|
DELAY(1000000); /* wait 1 sec for printf's to complete and be read */
|
|
|
|
|
2009-08-13 17:09:45 +00:00
|
|
|
/*
|
2010-04-19 23:27:54 +00:00
|
|
|
* Acquiring smp_ipi_mtx here has a double effect:
|
|
|
|
* - it disables interrupts avoiding CPU0 preemption
|
|
|
|
* by fast handlers (thus deadlocking against other CPUs)
|
|
|
|
* - it avoids deadlocks against smp_rendezvous() or, more
|
|
|
|
* generally, threads busy-waiting, with this spinlock held,
|
|
|
|
* and waiting for responses by threads on other CPUs
|
|
|
|
* (ie. smp_tlb_shootdown()).
|
2010-04-20 12:22:06 +00:00
|
|
|
*
|
|
|
|
* For the !SMP case it just needs to handle the former problem.
|
2009-08-13 17:09:45 +00:00
|
|
|
*/
|
2010-04-20 12:22:06 +00:00
|
|
|
#ifdef SMP
|
2010-04-19 23:27:54 +00:00
|
|
|
mtx_lock_spin(&smp_ipi_mtx);
|
2010-04-20 12:22:06 +00:00
|
|
|
#else
|
|
|
|
spinlock_enter();
|
|
|
|
#endif
|
2009-08-13 17:09:45 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-12-11 01:23:50 +00:00
|
|
|
#if defined(WITNESS) || defined(INVARIANTS)
|
2012-12-07 08:25:08 +00:00
|
|
|
static int kassert_warn_only = 0;
|
2012-12-10 23:11:26 +00:00
|
|
|
#ifdef KDB
|
|
|
|
static int kassert_do_kdb = 0;
|
|
|
|
#endif
|
2012-12-07 08:25:08 +00:00
|
|
|
#ifdef KTR
|
|
|
|
static int kassert_do_ktr = 0;
|
|
|
|
#endif
|
|
|
|
static int kassert_do_log = 1;
|
|
|
|
static int kassert_log_pps_limit = 4;
|
|
|
|
static int kassert_log_mute_at = 0;
|
|
|
|
static int kassert_log_panic_at = 0;
|
|
|
|
static int kassert_warnings = 0;
|
|
|
|
|
|
|
|
SYSCTL_NODE(_debug, OID_AUTO, kassert, CTLFLAG_RW, NULL, "kassert options");
|
|
|
|
|
|
|
|
SYSCTL_INT(_debug_kassert, OID_AUTO, warn_only, CTLFLAG_RW | CTLFLAG_TUN,
|
|
|
|
&kassert_warn_only, 0,
|
|
|
|
"KASSERT triggers a panic (1) or just a warning (0)");
|
|
|
|
TUNABLE_INT("debug.kassert.warn_only", &kassert_warn_only);
|
|
|
|
|
2012-12-10 23:11:26 +00:00
|
|
|
#ifdef KDB
|
|
|
|
SYSCTL_INT(_debug_kassert, OID_AUTO, do_kdb, CTLFLAG_RW | CTLFLAG_TUN,
|
|
|
|
&kassert_do_kdb, 0, "KASSERT will enter the debugger");
|
|
|
|
TUNABLE_INT("debug.kassert.do_kdb", &kassert_do_kdb);
|
|
|
|
#endif
|
|
|
|
|
2012-12-07 08:25:08 +00:00
|
|
|
#ifdef KTR
|
|
|
|
SYSCTL_UINT(_debug_kassert, OID_AUTO, do_ktr, CTLFLAG_RW | CTLFLAG_TUN,
|
|
|
|
&kassert_do_ktr, 0,
|
|
|
|
"KASSERT does a KTR, set this to the KTRMASK you want");
|
|
|
|
TUNABLE_INT("debug.kassert.do_ktr", &kassert_do_ktr);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
SYSCTL_INT(_debug_kassert, OID_AUTO, do_log, CTLFLAG_RW | CTLFLAG_TUN,
|
|
|
|
&kassert_do_log, 0, "KASSERT triggers a panic (1) or just a warning (0)");
|
|
|
|
TUNABLE_INT("debug.kassert.do_log", &kassert_do_log);
|
|
|
|
|
|
|
|
SYSCTL_INT(_debug_kassert, OID_AUTO, warnings, CTLFLAG_RW | CTLFLAG_TUN,
|
|
|
|
&kassert_warnings, 0, "number of KASSERTs that have been triggered");
|
|
|
|
TUNABLE_INT("debug.kassert.warnings", &kassert_warnings);
|
|
|
|
|
|
|
|
SYSCTL_INT(_debug_kassert, OID_AUTO, log_panic_at, CTLFLAG_RW | CTLFLAG_TUN,
|
|
|
|
&kassert_log_panic_at, 0, "max number of KASSERTS before we will panic");
|
|
|
|
TUNABLE_INT("debug.kassert.log_panic_at", &kassert_log_panic_at);
|
|
|
|
|
|
|
|
SYSCTL_INT(_debug_kassert, OID_AUTO, log_pps_limit, CTLFLAG_RW | CTLFLAG_TUN,
|
|
|
|
&kassert_log_pps_limit, 0, "limit number of log messages per second");
|
|
|
|
TUNABLE_INT("debug.kassert.log_pps_limit", &kassert_log_pps_limit);
|
|
|
|
|
|
|
|
SYSCTL_INT(_debug_kassert, OID_AUTO, log_mute_at, CTLFLAG_RW | CTLFLAG_TUN,
|
|
|
|
&kassert_log_mute_at, 0, "max number of KASSERTS to log");
|
|
|
|
TUNABLE_INT("debug.kassert.log_mute_at", &kassert_log_mute_at);
|
|
|
|
|
|
|
|
static int kassert_sysctl_kassert(SYSCTL_HANDLER_ARGS);
|
|
|
|
|
|
|
|
SYSCTL_PROC(_debug_kassert, OID_AUTO, kassert,
|
|
|
|
CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_SECURE, NULL, 0,
|
|
|
|
kassert_sysctl_kassert, "I", "set to trigger a test kassert");
|
|
|
|
|
|
|
|
static int
|
|
|
|
kassert_sysctl_kassert(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
int error, i;
|
|
|
|
|
|
|
|
error = sysctl_wire_old_buffer(req, sizeof(int));
|
|
|
|
if (error == 0) {
|
|
|
|
i = 0;
|
|
|
|
error = sysctl_handle_int(oidp, &i, 0, req);
|
|
|
|
}
|
|
|
|
if (error != 0 || req->newptr == NULL)
|
|
|
|
return (error);
|
|
|
|
KASSERT(0, ("kassert_sysctl_kassert triggered kassert %d", i));
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called by KASSERT, this decides if we will panic
|
|
|
|
* or if we will log via printf and/or ktr.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
kassert_panic(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
static char buf[256];
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
(void)vsnprintf(buf, sizeof(buf), fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* panic if we're not just warning, or if we've exceeded
|
|
|
|
* kassert_log_panic_at warnings.
|
|
|
|
*/
|
|
|
|
if (!kassert_warn_only ||
|
|
|
|
(kassert_log_panic_at > 0 &&
|
|
|
|
kassert_warnings >= kassert_log_panic_at)) {
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vpanic(fmt, ap);
|
|
|
|
/* NORETURN */
|
|
|
|
}
|
|
|
|
#ifdef KTR
|
|
|
|
if (kassert_do_ktr)
|
|
|
|
CTR0(ktr_mask, buf);
|
|
|
|
#endif /* KTR */
|
|
|
|
/*
|
|
|
|
* log if we've not yet met the mute limit.
|
|
|
|
*/
|
|
|
|
if (kassert_do_log &&
|
|
|
|
(kassert_log_mute_at == 0 ||
|
|
|
|
kassert_warnings < kassert_log_mute_at)) {
|
|
|
|
static struct timeval lasterr;
|
|
|
|
static int curerr;
|
|
|
|
|
|
|
|
if (ppsratecheck(&lasterr, &curerr, kassert_log_pps_limit)) {
|
|
|
|
printf("KASSERT failed: %s\n", buf);
|
|
|
|
kdb_backtrace();
|
|
|
|
}
|
|
|
|
}
|
2012-12-10 23:11:26 +00:00
|
|
|
#ifdef KDB
|
|
|
|
if (kassert_do_kdb) {
|
|
|
|
kdb_enter(KDB_WHY_KASSERT, buf);
|
|
|
|
}
|
|
|
|
#endif
|
2012-12-07 08:25:08 +00:00
|
|
|
atomic_add_int(&kassert_warnings, 1);
|
|
|
|
}
|
|
|
|
#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.
|
|
|
|
*/
|
|
|
|
void
|
2004-06-06 21:26:49 +00:00
|
|
|
panic(const char *fmt, ...)
|
2012-12-07 08:25:08 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vpanic(fmt, ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vpanic(const char *fmt, va_list ap)
|
1996-08-19 02:19:23 +00:00
|
|
|
{
|
2010-10-09 08:07:49 +00:00
|
|
|
#ifdef SMP
|
panic: add a switch and infrastructure for stopping other CPUs in SMP case
Historical behavior of letting other CPUs merily go on is a default for
time being. The new behavior can be switched on via
kern.stop_scheduler_on_panic tunable and sysctl.
Stopping of the CPUs has (at least) the following benefits:
- more of the system state at panic time is preserved intact
- threads and interrupts do not interfere with dumping of the system
state
Only one thread runs uninterrupted after panic if stop_scheduler_on_panic
is set. That thread might call code that is also used in normal context
and that code might use locks to prevent concurrent execution of certain
parts. Those locks might be held by the stopped threads and would never
be released. To work around this issue, it was decided that instead of
explicit checks for panic context, we would rather put those checks
inside the locking primitives.
This change has substantial portions written and re-written by attilio
and kib at various times. Other changes are heavily based on the ideas
and patches submitted by jhb and mdf. bde has provided many insights
into the details and history of the current code.
The new behavior may cause problems for systems that use a USB keyboard
for interfacing with system console. This is because of some unusual
locking patterns in the ukbd code which have to be used because on one
hand ukbd is below syscons, but on the other hand it has to interface
with other usb code that uses regular mutexes/Giant for its concurrency
protection. Dumping to USB-connected disks may also be affected.
PR: amd64/139614 (at least)
In cooperation with: attilio, jhb, kib, mdf
Discussed with: arch@, bde
Tested by: Eugene Grosbein <eugen@grosbein.net>,
gnn,
Steven Hartland <killing@multiplay.co.uk>,
glebius,
Andrew Boyer <aboyer@averesystems.com>
(various versions of the patch)
MFC after: 3 months (or never)
2011-12-11 21:02:01 +00:00
|
|
|
cpuset_t other_cpus;
|
2010-10-09 08:07:49 +00:00
|
|
|
#endif
|
2002-07-17 02:23:44 +00:00
|
|
|
struct thread *td = curthread;
|
2002-09-19 18:49:46 +00:00
|
|
|
int bootopt, newpanic;
|
1998-09-06 06:25:18 +00:00
|
|
|
static char buf[256];
|
1996-08-19 02:19:23 +00:00
|
|
|
|
2012-11-25 14:22:08 +00:00
|
|
|
spinlock_enter();
|
panic: add a switch and infrastructure for stopping other CPUs in SMP case
Historical behavior of letting other CPUs merily go on is a default for
time being. The new behavior can be switched on via
kern.stop_scheduler_on_panic tunable and sysctl.
Stopping of the CPUs has (at least) the following benefits:
- more of the system state at panic time is preserved intact
- threads and interrupts do not interfere with dumping of the system
state
Only one thread runs uninterrupted after panic if stop_scheduler_on_panic
is set. That thread might call code that is also used in normal context
and that code might use locks to prevent concurrent execution of certain
parts. Those locks might be held by the stopped threads and would never
be released. To work around this issue, it was decided that instead of
explicit checks for panic context, we would rather put those checks
inside the locking primitives.
This change has substantial portions written and re-written by attilio
and kib at various times. Other changes are heavily based on the ideas
and patches submitted by jhb and mdf. bde has provided many insights
into the details and history of the current code.
The new behavior may cause problems for systems that use a USB keyboard
for interfacing with system console. This is because of some unusual
locking patterns in the ukbd code which have to be used because on one
hand ukbd is below syscons, but on the other hand it has to interface
with other usb code that uses regular mutexes/Giant for its concurrency
protection. Dumping to USB-connected disks may also be affected.
PR: amd64/139614 (at least)
In cooperation with: attilio, jhb, kib, mdf
Discussed with: arch@, bde
Tested by: Eugene Grosbein <eugen@grosbein.net>,
gnn,
Steven Hartland <killing@multiplay.co.uk>,
glebius,
Andrew Boyer <aboyer@averesystems.com>
(various versions of the patch)
MFC after: 3 months (or never)
2011-12-11 21:02:01 +00:00
|
|
|
|
2000-09-07 01:33:02 +00:00
|
|
|
#ifdef SMP
|
2001-08-21 22:55:20 +00:00
|
|
|
/*
|
2012-11-25 14:22:08 +00:00
|
|
|
* stop_cpus_hard(other_cpus) should prevent multiple CPUs from
|
|
|
|
* concurrently entering panic. Only the winner will proceed
|
|
|
|
* further.
|
2001-08-21 22:55:20 +00:00
|
|
|
*/
|
2012-11-25 14:22:08 +00:00
|
|
|
if (panicstr == NULL && !kdb_active) {
|
|
|
|
other_cpus = all_cpus;
|
|
|
|
CPU_CLR(PCPU_GET(cpuid), &other_cpus);
|
|
|
|
stop_cpus_hard(other_cpus);
|
panic: add a switch and infrastructure for stopping other CPUs in SMP case
Historical behavior of letting other CPUs merily go on is a default for
time being. The new behavior can be switched on via
kern.stop_scheduler_on_panic tunable and sysctl.
Stopping of the CPUs has (at least) the following benefits:
- more of the system state at panic time is preserved intact
- threads and interrupts do not interfere with dumping of the system
state
Only one thread runs uninterrupted after panic if stop_scheduler_on_panic
is set. That thread might call code that is also used in normal context
and that code might use locks to prevent concurrent execution of certain
parts. Those locks might be held by the stopped threads and would never
be released. To work around this issue, it was decided that instead of
explicit checks for panic context, we would rather put those checks
inside the locking primitives.
This change has substantial portions written and re-written by attilio
and kib at various times. Other changes are heavily based on the ideas
and patches submitted by jhb and mdf. bde has provided many insights
into the details and history of the current code.
The new behavior may cause problems for systems that use a USB keyboard
for interfacing with system console. This is because of some unusual
locking patterns in the ukbd code which have to be used because on one
hand ukbd is below syscons, but on the other hand it has to interface
with other usb code that uses regular mutexes/Giant for its concurrency
protection. Dumping to USB-connected disks may also be affected.
PR: amd64/139614 (at least)
In cooperation with: attilio, jhb, kib, mdf
Discussed with: arch@, bde
Tested by: Eugene Grosbein <eugen@grosbein.net>,
gnn,
Steven Hartland <killing@multiplay.co.uk>,
glebius,
Andrew Boyer <aboyer@averesystems.com>
(various versions of the patch)
MFC after: 3 months (or never)
2011-12-11 21:02:01 +00:00
|
|
|
}
|
2012-11-25 14:22:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We set stop_scheduler here and not in the block above,
|
|
|
|
* because we want to ensure that if panic has been called and
|
|
|
|
* stop_scheduler_on_panic is true, then stop_scheduler will
|
|
|
|
* always be set. Even if panic has been entered from kdb.
|
|
|
|
*/
|
|
|
|
td->td_stopsched = 1;
|
2000-09-07 01:33:02 +00:00
|
|
|
#endif
|
|
|
|
|
2011-06-08 19:28:59 +00:00
|
|
|
bootopt = RB_AUTOBOOT;
|
2002-09-19 18:49:46 +00:00
|
|
|
newpanic = 0;
|
1996-08-19 02:19:23 +00:00
|
|
|
if (panicstr)
|
|
|
|
bootopt |= RB_NOSYNC;
|
2002-09-19 18:49:46 +00:00
|
|
|
else {
|
2011-06-08 19:28:59 +00:00
|
|
|
bootopt |= RB_DUMP;
|
1996-08-19 02:19:23 +00:00
|
|
|
panicstr = fmt;
|
2002-09-19 18:49:46 +00:00
|
|
|
newpanic = 1;
|
|
|
|
}
|
1996-08-19 02:19:23 +00:00
|
|
|
|
2003-06-15 11:43:00 +00:00
|
|
|
if (newpanic) {
|
|
|
|
(void)vsnprintf(buf, sizeof(buf), fmt, ap);
|
1998-09-06 06:25:18 +00:00
|
|
|
panicstr = buf;
|
2011-12-17 15:11:22 +00:00
|
|
|
cngrab();
|
2004-06-06 21:26:49 +00:00
|
|
|
printf("panic: %s\n", buf);
|
2003-06-15 11:43:00 +00:00
|
|
|
} else {
|
|
|
|
printf("panic: ");
|
|
|
|
vprintf(fmt, ap);
|
2004-06-06 21:26:49 +00:00
|
|
|
printf("\n");
|
2003-06-15 11:43:00 +00:00
|
|
|
}
|
1997-05-24 18:35:44 +00:00
|
|
|
#ifdef SMP
|
2004-08-20 17:24:52 +00:00
|
|
|
printf("cpuid = %d\n", PCPU_GET(cpuid));
|
2000-11-29 01:33:15 +00:00
|
|
|
#endif
|
1996-08-19 02:19:23 +00:00
|
|
|
|
2004-07-10 21:36:01 +00:00
|
|
|
#ifdef KDB
|
2002-09-19 18:49:46 +00:00
|
|
|
if (newpanic && trace_on_panic)
|
2004-07-10 21:36:01 +00:00
|
|
|
kdb_backtrace();
|
1996-08-19 02:19:23 +00:00
|
|
|
if (debugger_on_panic)
|
2007-12-25 17:52:02 +00:00
|
|
|
kdb_enter(KDB_WHY_PANIC, "panic");
|
1996-08-19 02:19:23 +00:00
|
|
|
#endif
|
Commit 14/14 of sched_lock decomposition.
- Use thread_lock() rather than sched_lock for per-thread scheduling
sychronization.
- Use the per-process spinlock rather than the sched_lock for per-process
scheduling synchronization.
Tested by: kris, current@
Tested on: i386, amd64, ULE, 4BSD, libthr, libkse, PREEMPTION, etc.
Discussed with: kris, attilio, kmacy, jhb, julian, bde (small parts each)
2007-06-05 00:00:57 +00:00
|
|
|
/*thread_lock(td); */
|
2002-07-17 02:23:44 +00:00
|
|
|
td->td_flags |= TDF_INPANIC;
|
Commit 14/14 of sched_lock decomposition.
- Use thread_lock() rather than sched_lock for per-thread scheduling
sychronization.
- Use the per-process spinlock rather than the sched_lock for per-process
scheduling synchronization.
Tested by: kris, current@
Tested on: i386, amd64, ULE, 4BSD, libthr, libkse, PREEMPTION, etc.
Discussed with: kris, attilio, kmacy, jhb, julian, bde (small parts each)
2007-06-05 00:00:57 +00:00
|
|
|
/* thread_unlock(td); */
|
2001-10-19 23:32:03 +00:00
|
|
|
if (!sync_on_panic)
|
|
|
|
bootopt |= RB_NOSYNC;
|
2010-10-18 04:30:27 +00:00
|
|
|
kern_reboot(bootopt);
|
1996-08-19 02:19:23 +00:00
|
|
|
}
|
|
|
|
|
1999-01-30 19:28:30 +00:00
|
|
|
/*
|
|
|
|
* Support for poweroff delay.
|
2009-09-10 18:24:59 +00:00
|
|
|
*
|
|
|
|
* Please note that setting this delay too short might power off your machine
|
|
|
|
* before the write cache on your hard disk has been flushed, leading to
|
|
|
|
* soft-updates inconsistencies.
|
1999-01-30 19:28:30 +00:00
|
|
|
*/
|
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,
|
2011-12-13 00:38:50 +00:00
|
|
|
&poweroff_delay, 0, "Delay before poweroff to write disk caches (msec)");
|
1999-01-30 19:28:30 +00:00
|
|
|
|
2003-02-14 12:44:48 +00:00
|
|
|
static void
|
1999-08-21 06:24:40 +00:00
|
|
|
poweroff_wait(void *junk, int howto)
|
1999-01-30 19:28:30 +00:00
|
|
|
{
|
2003-02-14 12:44:48 +00:00
|
|
|
|
|
|
|
if (!(howto & RB_POWEROFF) || poweroff_delay <= 0)
|
1999-01-30 19:28:30 +00:00
|
|
|
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,
|
2011-12-13 00:38:50 +00:00
|
|
|
&kproc_shutdown_wait, 0, "Max wait time (sec) to stop for each process");
|
2000-01-07 08:36:44 +00:00
|
|
|
|
|
|
|
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;
|
2004-07-30 01:30:05 +00:00
|
|
|
printf("Waiting (max %d seconds) for system process `%s' to stop...",
|
2009-10-23 15:09:51 +00:00
|
|
|
kproc_shutdown_wait, p->p_comm);
|
2007-10-20 23:23:23 +00:00
|
|
|
error = kproc_suspend(p, kproc_shutdown_wait * hz);
|
2000-01-07 08:36:44 +00:00
|
|
|
|
|
|
|
if (error == EWOULDBLOCK)
|
2004-07-30 01:30:05 +00:00
|
|
|
printf("timed out\n");
|
2000-01-07 08:36:44 +00:00
|
|
|
else
|
2004-07-30 01:30:05 +00:00
|
|
|
printf("done\n");
|
2000-01-07 08:36:44 +00:00
|
|
|
}
|
Here follows the new kernel dumping infrastructure.
Caveats:
The new savecore program is not complete in the sense that it emulates
enough of the old savecores features to do the job, but implements none
of the options yet.
I would appreciate if a userland hacker could help me out getting savecore
to do what we want it to do from a users point of view, compression,
email-notification, space reservation etc etc. (send me email if
you are interested).
Currently, savecore will scan all devices marked as "swap" or "dump" in
/etc/fstab _or_ any devices specified on the command-line.
All architectures but i386 lack an implementation of dumpsys(), but
looking at the i386 version it should be trivial for anybody familiar
with the platform(s) to provide this function.
Documentation is quite sparse at this time, more to come.
Details:
ATA and SCSI drivers should work as the dump formatting code has been
removed. The IDA, TWE and AAC have not yet been converted.
Dumpon now opens the device and uses ioctl(DIOCGKERNELDUMP) to set
the device as dumpdev. To implement the "off" argument, /dev/null
is used as the device.
Savecore will fail if handed any options since they are not (yet)
implemented. All devices marked "dump" or "swap" in /etc/fstab
will be scanned and dumps found will be saved to diskfiles
named from the MD5 hash of the header record. The header record
is dumped in readable format in the .info file. The kernel
is not saved. Only complete dumps will be saved.
All maintainer rights for this code are disclaimed: feel free to
improve and extend.
Sponsored by: DARPA, NAI Labs
2002-03-31 22:37:00 +00:00
|
|
|
|
2007-10-26 08:00:41 +00:00
|
|
|
void
|
|
|
|
kthread_shutdown(void *arg, int howto)
|
|
|
|
{
|
|
|
|
struct thread *td;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (panicstr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
td = (struct thread *)arg;
|
|
|
|
printf("Waiting (max %d seconds) for system thread `%s' to stop...",
|
2009-10-23 15:09:51 +00:00
|
|
|
kproc_shutdown_wait, td->td_name);
|
2007-10-26 08:00:41 +00:00
|
|
|
error = kthread_suspend(td, kproc_shutdown_wait * hz);
|
|
|
|
|
|
|
|
if (error == EWOULDBLOCK)
|
|
|
|
printf("timed out\n");
|
|
|
|
else
|
|
|
|
printf("done\n");
|
|
|
|
}
|
|
|
|
|
2012-11-01 17:01:05 +00:00
|
|
|
static char dumpdevname[sizeof(((struct cdev*)NULL)->si_name)];
|
|
|
|
SYSCTL_STRING(_kern_shutdown, OID_AUTO, dumpdevname, CTLFLAG_RD,
|
|
|
|
dumpdevname, 0, "Device for kernel dumps");
|
|
|
|
|
Here follows the new kernel dumping infrastructure.
Caveats:
The new savecore program is not complete in the sense that it emulates
enough of the old savecores features to do the job, but implements none
of the options yet.
I would appreciate if a userland hacker could help me out getting savecore
to do what we want it to do from a users point of view, compression,
email-notification, space reservation etc etc. (send me email if
you are interested).
Currently, savecore will scan all devices marked as "swap" or "dump" in
/etc/fstab _or_ any devices specified on the command-line.
All architectures but i386 lack an implementation of dumpsys(), but
looking at the i386 version it should be trivial for anybody familiar
with the platform(s) to provide this function.
Documentation is quite sparse at this time, more to come.
Details:
ATA and SCSI drivers should work as the dump formatting code has been
removed. The IDA, TWE and AAC have not yet been converted.
Dumpon now opens the device and uses ioctl(DIOCGKERNELDUMP) to set
the device as dumpdev. To implement the "off" argument, /dev/null
is used as the device.
Savecore will fail if handed any options since they are not (yet)
implemented. All devices marked "dump" or "swap" in /etc/fstab
will be scanned and dumps found will be saved to diskfiles
named from the MD5 hash of the header record. The header record
is dumped in readable format in the .info file. The kernel
is not saved. Only complete dumps will be saved.
All maintainer rights for this code are disclaimed: feel free to
improve and extend.
Sponsored by: DARPA, NAI Labs
2002-03-31 22:37:00 +00:00
|
|
|
/* Registration of dumpers */
|
|
|
|
int
|
2012-11-01 17:01:05 +00:00
|
|
|
set_dumper(struct dumperinfo *di, const char *devname)
|
Here follows the new kernel dumping infrastructure.
Caveats:
The new savecore program is not complete in the sense that it emulates
enough of the old savecores features to do the job, but implements none
of the options yet.
I would appreciate if a userland hacker could help me out getting savecore
to do what we want it to do from a users point of view, compression,
email-notification, space reservation etc etc. (send me email if
you are interested).
Currently, savecore will scan all devices marked as "swap" or "dump" in
/etc/fstab _or_ any devices specified on the command-line.
All architectures but i386 lack an implementation of dumpsys(), but
looking at the i386 version it should be trivial for anybody familiar
with the platform(s) to provide this function.
Documentation is quite sparse at this time, more to come.
Details:
ATA and SCSI drivers should work as the dump formatting code has been
removed. The IDA, TWE and AAC have not yet been converted.
Dumpon now opens the device and uses ioctl(DIOCGKERNELDUMP) to set
the device as dumpdev. To implement the "off" argument, /dev/null
is used as the device.
Savecore will fail if handed any options since they are not (yet)
implemented. All devices marked "dump" or "swap" in /etc/fstab
will be scanned and dumps found will be saved to diskfiles
named from the MD5 hash of the header record. The header record
is dumped in readable format in the .info file. The kernel
is not saved. Only complete dumps will be saved.
All maintainer rights for this code are disclaimed: feel free to
improve and extend.
Sponsored by: DARPA, NAI Labs
2002-03-31 22:37:00 +00:00
|
|
|
{
|
2012-11-02 18:57:38 +00:00
|
|
|
size_t wantcopy;
|
2003-02-14 12:44:48 +00:00
|
|
|
|
Here follows the new kernel dumping infrastructure.
Caveats:
The new savecore program is not complete in the sense that it emulates
enough of the old savecores features to do the job, but implements none
of the options yet.
I would appreciate if a userland hacker could help me out getting savecore
to do what we want it to do from a users point of view, compression,
email-notification, space reservation etc etc. (send me email if
you are interested).
Currently, savecore will scan all devices marked as "swap" or "dump" in
/etc/fstab _or_ any devices specified on the command-line.
All architectures but i386 lack an implementation of dumpsys(), but
looking at the i386 version it should be trivial for anybody familiar
with the platform(s) to provide this function.
Documentation is quite sparse at this time, more to come.
Details:
ATA and SCSI drivers should work as the dump formatting code has been
removed. The IDA, TWE and AAC have not yet been converted.
Dumpon now opens the device and uses ioctl(DIOCGKERNELDUMP) to set
the device as dumpdev. To implement the "off" argument, /dev/null
is used as the device.
Savecore will fail if handed any options since they are not (yet)
implemented. All devices marked "dump" or "swap" in /etc/fstab
will be scanned and dumps found will be saved to diskfiles
named from the MD5 hash of the header record. The header record
is dumped in readable format in the .info file. The kernel
is not saved. Only complete dumps will be saved.
All maintainer rights for this code are disclaimed: feel free to
improve and extend.
Sponsored by: DARPA, NAI Labs
2002-03-31 22:37:00 +00:00
|
|
|
if (di == NULL) {
|
|
|
|
bzero(&dumper, sizeof dumper);
|
2012-11-01 17:01:05 +00:00
|
|
|
dumpdevname[0] = '\0';
|
Here follows the new kernel dumping infrastructure.
Caveats:
The new savecore program is not complete in the sense that it emulates
enough of the old savecores features to do the job, but implements none
of the options yet.
I would appreciate if a userland hacker could help me out getting savecore
to do what we want it to do from a users point of view, compression,
email-notification, space reservation etc etc. (send me email if
you are interested).
Currently, savecore will scan all devices marked as "swap" or "dump" in
/etc/fstab _or_ any devices specified on the command-line.
All architectures but i386 lack an implementation of dumpsys(), but
looking at the i386 version it should be trivial for anybody familiar
with the platform(s) to provide this function.
Documentation is quite sparse at this time, more to come.
Details:
ATA and SCSI drivers should work as the dump formatting code has been
removed. The IDA, TWE and AAC have not yet been converted.
Dumpon now opens the device and uses ioctl(DIOCGKERNELDUMP) to set
the device as dumpdev. To implement the "off" argument, /dev/null
is used as the device.
Savecore will fail if handed any options since they are not (yet)
implemented. All devices marked "dump" or "swap" in /etc/fstab
will be scanned and dumps found will be saved to diskfiles
named from the MD5 hash of the header record. The header record
is dumped in readable format in the .info file. The kernel
is not saved. Only complete dumps will be saved.
All maintainer rights for this code are disclaimed: feel free to
improve and extend.
Sponsored by: DARPA, NAI Labs
2002-03-31 22:37:00 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (dumper.dumper != NULL)
|
|
|
|
return (EBUSY);
|
|
|
|
dumper = *di;
|
2012-11-02 18:57:38 +00:00
|
|
|
wantcopy = strlcpy(dumpdevname, devname, sizeof(dumpdevname));
|
|
|
|
if (wantcopy >= sizeof(dumpdevname)) {
|
2012-11-01 17:01:05 +00:00
|
|
|
printf("set_dumper: device name truncated from '%s' -> '%s'\n",
|
|
|
|
devname, dumpdevname);
|
|
|
|
}
|
Here follows the new kernel dumping infrastructure.
Caveats:
The new savecore program is not complete in the sense that it emulates
enough of the old savecores features to do the job, but implements none
of the options yet.
I would appreciate if a userland hacker could help me out getting savecore
to do what we want it to do from a users point of view, compression,
email-notification, space reservation etc etc. (send me email if
you are interested).
Currently, savecore will scan all devices marked as "swap" or "dump" in
/etc/fstab _or_ any devices specified on the command-line.
All architectures but i386 lack an implementation of dumpsys(), but
looking at the i386 version it should be trivial for anybody familiar
with the platform(s) to provide this function.
Documentation is quite sparse at this time, more to come.
Details:
ATA and SCSI drivers should work as the dump formatting code has been
removed. The IDA, TWE and AAC have not yet been converted.
Dumpon now opens the device and uses ioctl(DIOCGKERNELDUMP) to set
the device as dumpdev. To implement the "off" argument, /dev/null
is used as the device.
Savecore will fail if handed any options since they are not (yet)
implemented. All devices marked "dump" or "swap" in /etc/fstab
will be scanned and dumps found will be saved to diskfiles
named from the MD5 hash of the header record. The header record
is dumped in readable format in the .info file. The kernel
is not saved. Only complete dumps will be saved.
All maintainer rights for this code are disclaimed: feel free to
improve and extend.
Sponsored by: DARPA, NAI Labs
2002-03-31 22:37:00 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2008-01-28 19:04:07 +00:00
|
|
|
/* Call dumper with bounds checking. */
|
|
|
|
int
|
|
|
|
dump_write(struct dumperinfo *di, void *virtual, vm_offset_t physical,
|
|
|
|
off_t offset, size_t length)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (length != 0 && (offset < di->mediaoffset ||
|
|
|
|
offset - di->mediaoffset + length > di->mediasize)) {
|
2011-09-12 20:39:31 +00:00
|
|
|
printf("Attempt to write outside dump device boundaries.\n"
|
|
|
|
"offset(%jd), mediaoffset(%jd), length(%ju), mediasize(%jd).\n",
|
|
|
|
(intmax_t)offset, (intmax_t)di->mediaoffset,
|
|
|
|
(uintmax_t)length, (intmax_t)di->mediasize);
|
|
|
|
return (ENOSPC);
|
2008-01-28 19:04:07 +00:00
|
|
|
}
|
|
|
|
return (di->dumper(di->priv, virtual, physical, offset, length));
|
|
|
|
}
|
|
|
|
|
2008-10-01 22:08:53 +00:00
|
|
|
void
|
|
|
|
mkdumpheader(struct kerneldumpheader *kdh, char *magic, uint32_t archver,
|
|
|
|
uint64_t dumplen, uint32_t blksz)
|
|
|
|
{
|
|
|
|
|
|
|
|
bzero(kdh, sizeof(*kdh));
|
|
|
|
strncpy(kdh->magic, magic, sizeof(kdh->magic));
|
|
|
|
strncpy(kdh->architecture, MACHINE_ARCH, sizeof(kdh->architecture));
|
|
|
|
kdh->version = htod32(KERNELDUMPVERSION);
|
|
|
|
kdh->architectureversion = htod32(archver);
|
|
|
|
kdh->dumplength = htod64(dumplen);
|
|
|
|
kdh->dumptime = htod64(time_second);
|
|
|
|
kdh->blocksize = htod32(blksz);
|
2009-06-13 15:39:12 +00:00
|
|
|
strncpy(kdh->hostname, prison0.pr_hostname, sizeof(kdh->hostname));
|
2008-10-01 22:08:53 +00:00
|
|
|
strncpy(kdh->versionstring, version, sizeof(kdh->versionstring));
|
|
|
|
if (panicstr != NULL)
|
|
|
|
strncpy(kdh->panicstring, panicstr, sizeof(kdh->panicstring));
|
|
|
|
kdh->parity = kerneldump_parity(kdh);
|
|
|
|
}
|