Add a new at_shutdown queue, SHUTDOWN_FINAL. This queue is run at

splhigh() after any system dumps have completed.  SHUTDOWN_POST_SYNC
isn't quite late enough for disk controllers.

Converted at_shutdown queues to use the queue(3) macros.
This commit is contained in:
Justin T. Gibbs 1998-09-15 08:49:52 +00:00
parent a8abf21632
commit 2cfa0a0381

View File

@ -36,7 +36,7 @@
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* @(#)kern_shutdown.c 8.3 (Berkeley) 1/21/94 * @(#)kern_shutdown.c 8.3 (Berkeley) 1/21/94
* $Id: kern_shutdown.c,v 1.37 1998/08/23 14:18:08 des Exp $ * $Id: kern_shutdown.c,v 1.38 1998/09/06 06:25:04 ache Exp $
*/ */
#include "opt_ddb.h" #include "opt_ddb.h"
@ -52,6 +52,7 @@
#include <sys/malloc.h> #include <sys/malloc.h>
#include <sys/kernel.h> #include <sys/kernel.h>
#include <sys/mount.h> #include <sys/mount.h>
#include <sys/queue.h>
#include <sys/sysctl.h> #include <sys/sysctl.h>
#include <sys/conf.h> #include <sys/conf.h>
#include <sys/sysproto.h> #include <sys/sysproto.h>
@ -107,17 +108,18 @@ const char *panicstr;
* callout list for things to do a shutdown * callout list for things to do a shutdown
*/ */
typedef struct shutdown_list_element { typedef struct shutdown_list_element {
struct shutdown_list_element *next; LIST_ENTRY(shutdown_list_element) links;
bootlist_fn function; bootlist_fn function;
void *arg; void *arg;
} *sle_p; } *sle_p;
/* /*
* there are two shutdown lists. Some things need to be shut down * There are three shutdown lists. Some things need to be shut down
* Earlier than others. * earlier than others.
*/ */
static sle_p shutdown_list1; LIST_HEAD(shutdown_list, shutdown_list_element);
static sle_p shutdown_list2;
static struct shutdown_list shutdown_lists[SHUTDOWN_FINAL + 1];
static void boot __P((int)) __dead2; static void boot __P((int)) __dead2;
static void dumpsys __P((void)); static void dumpsys __P((void));
@ -183,12 +185,8 @@ boot(howto)
/* /*
* Do any callouts that should be done BEFORE syncing the filesystems. * Do any callouts that should be done BEFORE syncing the filesystems.
*/ */
ep = shutdown_list1; LIST_FOREACH(ep, &shutdown_lists[SHUTDOWN_PRE_SYNC], links)
while (ep) {
shutdown_list1 = ep->next;
(*ep->function)(howto, ep->arg); (*ep->function)(howto, ep->arg);
ep = ep->next;
}
/* /*
* Now sync filesystems * Now sync filesystems
@ -210,7 +208,8 @@ boot(howto)
for (iter = 0; iter < 20; iter++) { for (iter = 0; iter < 20; iter++) {
nbusy = 0; nbusy = 0;
for (bp = &buf[nbuf]; --bp >= buf; ) { for (bp = &buf[nbuf]; --bp >= buf; ) {
if ((bp->b_flags & (B_BUSY | B_INVAL)) == B_BUSY) { if ((bp->b_flags & (B_BUSY | B_INVAL))
== B_BUSY) {
nbusy++; nbusy++;
} else if ((bp->b_flags & (B_DELWRI | B_INVAL)) } else if ((bp->b_flags & (B_DELWRI | B_INVAL))
== B_DELWRI) { == B_DELWRI) {
@ -233,7 +232,8 @@ boot(howto)
#ifdef SHOW_BUSYBUFS #ifdef SHOW_BUSYBUFS
nbusy = 0; nbusy = 0;
for (bp = &buf[nbuf]; --bp >= buf; ) { for (bp = &buf[nbuf]; --bp >= buf; ) {
if ((bp->b_flags & (B_BUSY | B_INVAL)) == B_BUSY) { if ((bp->b_flags & (B_BUSY | B_INVAL))
== B_BUSY) {
nbusy++; nbusy++;
printf( printf(
"%d: dev:%08lx, flags:%08lx, blkno:%ld, lblkno:%ld\n", "%d: dev:%08lx, flags:%08lx, blkno:%ld, lblkno:%ld\n",
@ -252,20 +252,28 @@ boot(howto)
if (panicstr == 0) if (panicstr == 0)
vfs_unmountall(); vfs_unmountall();
} }
DELAY(100000); /* wait for console output to finish */ DELAY(100000); /* wait for console output to finish */
} }
/* /*
* Ok, now do things that assume all filesystem activity has * Ok, now do things that assume all filesystem activity has
* been completed. * been completed.
*/ */
ep = shutdown_list2; LIST_FOREACH(ep, &shutdown_lists[SHUTDOWN_POST_SYNC], links)
while (ep) {
shutdown_list2 = ep->next;
(*ep->function)(howto, ep->arg); (*ep->function)(howto, ep->arg);
ep = ep->next;
}
splhigh(); splhigh();
if ((howto & (RB_HALT|RB_DUMP) == RB_DUMP) && !cold) {
savectx(&dumppcb);
#ifdef __i386__
dumppcb.pcb_cr3 = rcr3();
#endif
dumpsys();
}
/* Now that we're going to really halt the system... */
LIST_FOREACH(ep, &shutdown_lists[SHUTDOWN_FINAL], links)
(*ep->function)(howto, ep->arg);
if (howto & RB_HALT) { if (howto & RB_HALT) {
cpu_power_down(); cpu_power_down();
printf("\n"); printf("\n");
@ -276,38 +284,33 @@ boot(howto)
cpu_halt(); cpu_halt();
/* NOTREACHED */ /* NOTREACHED */
default: default:
howto &= ~RB_HALT;
break; break;
} }
} else { } else if (howto & RB_DUMP) {
if (howto & RB_DUMP) { /* System Paniced */
if (!cold) {
savectx(&dumppcb);
#ifdef __i386__
dumppcb.pcb_cr3 = rcr3();
#endif
dumpsys();
}
if (PANIC_REBOOT_WAIT_TIME != 0) { if (PANIC_REBOOT_WAIT_TIME != 0) {
if (PANIC_REBOOT_WAIT_TIME != -1) { if (PANIC_REBOOT_WAIT_TIME != -1) {
int loop; int loop;
printf("Automatic reboot in %d seconds - press a key on the console to abort\n", printf("Automatic reboot in %d seconds - "
PANIC_REBOOT_WAIT_TIME); "press a key on the console to abort\n",
for (loop = PANIC_REBOOT_WAIT_TIME * 10; loop > 0; --loop) { PANIC_REBOOT_WAIT_TIME);
DELAY(1000 * 100); /* 1/10th second */ for (loop = PANIC_REBOOT_WAIT_TIME * 10;
/* Did user type a key? */ loop > 0; --loop) {
if (cncheckc() != -1) DELAY(1000 * 100); /* 1/10th second */
break; /* Did user type a key? */
} if (cncheckc() != -1)
if (!loop) break;
goto die;
} }
} else { /* zero time specified - reboot NOW */ if (!loop)
goto die; goto die;
} }
printf("--> Press a key on the console to reboot <--\n"); } else { /* zero time specified - reboot NOW */
cngetc(); goto die;
} }
printf("--> Press a key on the console to reboot <--\n");
cngetc();
} }
die: die:
printf("Rebooting...\n"); printf("Rebooting...\n");
@ -437,30 +440,24 @@ panic(const char *fmt, ...)
* returns 0 on success. * returns 0 on success.
*/ */
int int
at_shutdown(bootlist_fn function, void *arg, int position) at_shutdown(bootlist_fn function, void *arg, int queue)
{ {
sle_p ep, *epp; sle_p ep;
switch(position) { if (queue < SHUTDOWN_PRE_SYNC
case SHUTDOWN_PRE_SYNC: || queue > SHUTDOWN_FINAL) {
epp = &shutdown_list1; printf("at_shutdown: bad exit callout queue %d specified\n",
break; queue);
case SHUTDOWN_POST_SYNC:
epp = &shutdown_list2;
break;
default:
printf("bad exit callout list specified\n");
return (EINVAL); return (EINVAL);
} }
if (rm_at_shutdown(function, arg)) if (rm_at_shutdown(function, arg))
printf("exit callout entry already present\n"); printf("at_shutdown: exit callout entry was already present\n");
ep = malloc(sizeof(*ep), M_TEMP, M_NOWAIT); ep = malloc(sizeof(*ep), M_TEMP, M_NOWAIT);
if (ep == NULL) if (ep == NULL)
return (ENOMEM); return (ENOMEM);
ep->next = *epp;
ep->function = function; ep->function = function;
ep->arg = arg; ep->arg = arg;
*epp = ep; LIST_INSERT_HEAD(&shutdown_lists[queue], ep, links);
return (0); return (0);
} }
@ -471,33 +468,19 @@ at_shutdown(bootlist_fn function, void *arg, int position)
int int
rm_at_shutdown(bootlist_fn function, void *arg) rm_at_shutdown(bootlist_fn function, void *arg)
{ {
sle_p *epp, ep; sle_p ep;
int count; int count;
int queue;
count = 0; count = 0;
epp = &shutdown_list1; for (queue = SHUTDOWN_PRE_SYNC; queue < SHUTDOWN_FINAL; queue++) {
ep = *epp; LIST_FOREACH(ep, &shutdown_lists[queue], links) {
while (ep) { if ((ep->function == function) && (ep->arg == arg)) {
if ((ep->function == function) && (ep->arg == arg)) { LIST_REMOVE(ep, links);
*epp = ep->next; free(ep, M_TEMP);
free(ep, M_TEMP); count++;
count++; }
} else {
epp = &ep->next;
} }
ep = *epp;
}
epp = &shutdown_list2;
ep = *epp;
while (ep) {
if ((ep->function == function) && (ep->arg == arg)) {
*epp = ep->next;
free(ep, M_TEMP);
count++;
} else {
epp = &ep->next;
}
ep = *epp;
} }
return (count); return (count);
} }