DragonFly bugs List (threaded) for 2007-06
DragonFly BSD
DragonFly bugs List (threaded) for 2007-06
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: [issue647] rough-draft VKERNEL host-initiated shutdown patch


From: Chris Turner <c.turner@xxxxxxxxxxxxxxxxxxx>
Date: Sat, 16 Jun 2007 19:22:13 -0400

Matthew Dillon wrote:
>    I think the platform init code is too early.   The memory subsystem
>    isn't really initialized until it gets into the middle mi_startup().
>
>    What I recommend is that you create a SYSINIT in
>    platform/vkernel/i38/exception.c with a priority of SI_BOOT2_MACHDEP
>    to create the thread.  This looks kinda messy, but it should work.
>

Okay. All set (+= roff updates per Sascha).

You'd mostly done all the work.. but now I understand the sysinit
things a bit more so that's good for something - and thanks! Would have
taken me all day to track things down, although my ctags-foo is improving :)

One thing that I did change (aside from minor <75 column reformatting, etc)
was that in the SYSINIT with the SI_BOOT2_MACHDEP, I'd get a panic before
init.. (see below)

I started to trace through this this but thought 'why not just try setting
this up later on in the sequence' which is why this is now set to
SI_BOOT2_PROC0, which is the lowest-numbered item in the sysinit_sub_id
enum that worked for me (TM).

Also, I'm wondering why you suggested resetting the mailbox flag to -1
when it is already nonzero.. kept this as is, but just for curiosity..

I'll knock out the pidfile thing in a few hours time.

Thanks,

- Chris

below:

real memory = 33554432 (32768K bytes)
avail memory = 30138368 (29432K bytes)
initclocks
panic: zone: invalid zone
Trace beginning at frame 0xbfbff858
(null)(8211300,828cf40,822e45f,bfbff888,0) at 0x80b5c20
(null)() at 0x80b5c20
Debugger("panic")
Stopped at      0x81f9615:      movb    $0,0x82bb898
db> trace
(null)(8211189,828cf40,822e45f,bfbff888,0) at 0x81f9615
(null)() at 0x80b5c35
db>

Index: share/man/man7/vkernel.7
===================================================================
RCS file: /var/local/apps/dcvs/src/share/man/man7/vkernel.7,v
retrieving revision 1.18
diff -r1.18 vkernel.7
205,207c205,210
< The virtual kernel enables all terminal signals while in
< .Xr ddb 4
< mode but only enables
---
> The virtual kernel only enables 
> .Dv SIGQUIT
> and 
> .Dv SIGTERM 
> while operating in regular console mode. 
> Sending 
210,211c213
< while operating as a console which causes the virtual kernel to enter its
< internal
---
> to the virtual kernel causes the virtual kernel to enter its internal
213c215,222
< debugger.
---
> debugger and re-enable all other terminal signals. 
> Sending
> .Dv SIGTERM 
> to the virtual kernel triggers a clean shutdown by passing a 
> .Dv SIGUSR2 
> to the virtual kernel's 
> .Xr init 8
> process.
Index: sys/platform/vkernel/i386/exception.c
===================================================================
RCS file: /var/local/apps/dcvs/src/sys/platform/vkernel/i386/exception.c,v
retrieving revision 1.5
diff -r1.5 exception.c
41a42,43
> #include <sys/kthread.h>
> #include <sys/reboot.h>
58a61,68
> /* signal shutdown thread misc. */
> 
> static void sigshutdown_daemon( void );
> static struct thread *sigshutdown_thread;
> static struct kproc_desc sigshut_kp = {
> 	"sigshutdown", sigshutdown_daemon, &sigshutdown_thread
> };
> 
69a80
> 
73a85,90
> 
> 	bzero(&sa, sizeof(sa));
> 	sigemptyset(&sa.sa_mask);
> 	sa.sa_flags |= SA_MAILBOX | SA_NODEFER;
> 	sa.sa_mailbox = &mdcpu->gd_shutdown;
> 	sigaction(SIGTERM, &sa, NULL);
97a115,139
> /*
>  * This function runs in a thread dedicated to external shutdown signals.
>  *
>  * Currently, when a vkernel recieves a SIGTERM, either the VKERNEL init(8) 
>  * is signaled with SIGUSR2, or the VKERNEL simply shuts down, preventing
>  * fsck's when the VKERNEL is restarted.
>  */ 
> static void
> sigshutdown_daemon( void )
> {
> 	while (mdcpu->gd_shutdown == 0) {
> 		tsleep(&mdcpu->gd_shutdown, 0, "sswait", 0);
> 	}
> 	mdcpu->gd_shutdown = 0;
> 	kprintf("Caught SIGTERM from host system. Shutting down...\n");
> 	if (initproc != NULL) {
> 		ksignal(initproc, SIGUSR2);
> 	}
> 	else {
> 		reboot(RB_POWEROFF);
> 	}	
> }
> SYSINIT(sigshutdown, SI_BOOT2_PROC0, SI_ORDER_ANY, 
> 	kproc_start, &sigshut_kp); 
> 
Index: sys/platform/vkernel/i386/trap.c
===================================================================
RCS file: /var/local/apps/dcvs/src/sys/platform/vkernel/i386/trap.c,v
retrieving revision 1.23
diff -r1.23 trap.c
1424a1425
> 
Index: sys/platform/vkernel/include/globaldata.h
===================================================================
RCS file: /var/local/apps/dcvs/src/sys/platform/vkernel/include/globaldata.h,v
retrieving revision 1.5
diff -r1.5 globaldata.h
86c86,87
< 	int		gd_mailbox;	/* signal delivery mailbox */
---
> 	int		gd_mailbox;	/* I/O signal delivery mailbox */
> 	int		gd_shutdown;    /* Shutdown signal delivery mailbox */
Index: sys/platform/vkernel/platform/kqueue.c
===================================================================
RCS file: /var/local/apps/dcvs/src/sys/platform/vkernel/platform/kqueue.c,v
retrieving revision 1.3
diff -r1.3 kqueue.c
109a110,119
> 	/*
> 	 * we only need to wake up our shutdown thread once.  
> 	 * Keep it non-zero so the shutdown thread can detect it.
> 	 */
> 
> 	if (mdcpu->gd_shutdown > 0) {
> 		mdcpu->gd_shutdown = -1;
> 		wakeup(&mdcpu->gd_shutdown);
> 	}
> 
111a122
> 


[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]