Module Name: src Committed By: mrg Date: Fri Mar 6 09:28:16 UTC 2015
Modified Files: src/sys/kern: init_main.c subr_autoconf.c src/sys/sys: device.h Log Message: wait for config_mountroot threads to complete before we tell init it can start up. this solves the problem where a console device needs mountroot to complete attaching, and must create wsdisplay0 before init tries to open /dev/console. fixes PR#49709. XXX: pullup-7 To generate a diff of this commit: cvs rdiff -u -r1.461 -r1.462 src/sys/kern/init_main.c cvs rdiff -u -r1.233 -r1.234 src/sys/kern/subr_autoconf.c cvs rdiff -u -r1.146 -r1.147 src/sys/sys/device.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/init_main.c diff -u src/sys/kern/init_main.c:1.461 src/sys/kern/init_main.c:1.462 --- src/sys/kern/init_main.c:1.461 Thu Nov 27 14:38:09 2014 +++ src/sys/kern/init_main.c Fri Mar 6 09:28:15 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: init_main.c,v 1.461 2014/11/27 14:38:09 uebayasi Exp $ */ +/* $NetBSD: init_main.c,v 1.462 2015/03/06 09:28:15 mrg Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -97,7 +97,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.461 2014/11/27 14:38:09 uebayasi Exp $"); +__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.462 2015/03/06 09:28:15 mrg Exp $"); #include "opt_ddb.h" #include "opt_ipsec.h" @@ -712,6 +712,9 @@ main(void) uvm_aiodone_worker, NULL, PRI_VM, IPL_NONE, WQ_MPSAFE)) panic("fork aiodoned"); + /* Wait for final configure threads to complete. */ + config_finalize_mountroot(); + /* * Okay, now we can let init(8) exec! It's off to userland! */ Index: src/sys/kern/subr_autoconf.c diff -u src/sys/kern/subr_autoconf.c:1.233 src/sys/kern/subr_autoconf.c:1.234 --- src/sys/kern/subr_autoconf.c:1.233 Thu Nov 6 08:46:04 2014 +++ src/sys/kern/subr_autoconf.c Fri Mar 6 09:28:15 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_autoconf.c,v 1.233 2014/11/06 08:46:04 uebayasi Exp $ */ +/* $NetBSD: subr_autoconf.c,v 1.234 2015/03/06 09:28:15 mrg Exp $ */ /* * Copyright (c) 1996, 2000 Christopher G. Demetriou @@ -77,7 +77,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.233 2014/11/06 08:46:04 uebayasi Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.234 2015/03/06 09:28:15 mrg Exp $"); #ifdef _KERNEL_OPT #include "opt_ddb.h" @@ -202,6 +202,8 @@ int interrupt_config_threads = 8; struct deferred_config_head mountroot_config_queue = TAILQ_HEAD_INITIALIZER(mountroot_config_queue); int mountroot_config_threads = 2; +static lwp_t **mountroot_config_lwpids; +static size_t mountroot_config_lwpids_size; static bool root_is_mounted = false; static void config_process_deferred(struct deferred_config_head *, device_t); @@ -481,10 +483,35 @@ config_create_mountrootthreads(void) if (!root_is_mounted) root_is_mounted = true; + mountroot_config_lwpids_size = sizeof(mountroot_config_lwpids) * + mountroot_config_threads; + mountroot_config_lwpids = kmem_alloc(mountroot_config_lwpids_size, + KM_NOSLEEP); + KASSERT(mountroot_config_lwpids); for (i = 0; i < mountroot_config_threads; i++) { - (void)kthread_create(PRI_NONE, 0, NULL, - config_mountroot_thread, NULL, NULL, "configroot"); + mountroot_config_lwpids[i] = 0; + (void)kthread_create(PRI_NONE, KTHREAD_MUSTJOIN, NULL, + config_mountroot_thread, NULL, + &mountroot_config_lwpids[i], + "configroot"); + } +} + +void +config_finalize_mountroot(void) +{ + int i, error; + + for (i = 0; i < mountroot_config_threads; i++) { + if (mountroot_config_lwpids[i] == 0) + continue; + + error = kthread_join(mountroot_config_lwpids[i]); + if (error) + printf("%s: thread %x joined with error %d\n", + __func__, i, error); } + kmem_free(mountroot_config_lwpids, mountroot_config_lwpids_size); } /* Index: src/sys/sys/device.h diff -u src/sys/sys/device.h:1.146 src/sys/sys/device.h:1.147 --- src/sys/sys/device.h:1.146 Sat Nov 22 11:04:57 2014 +++ src/sys/sys/device.h Fri Mar 6 09:28:15 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: device.h,v 1.146 2014/11/22 11:04:57 mlelstv Exp $ */ +/* $NetBSD: device.h,v 1.147 2015/03/06 09:28:15 mrg Exp $ */ /* * Copyright (c) 1996, 2000 Christopher G. Demetriou @@ -479,6 +479,7 @@ void config_create_mountrootthreads(void int config_finalize_register(device_t, int (*)(device_t)); void config_finalize(void); +void config_finalize_mountroot(void); void config_twiddle_init(void); void config_twiddle_fn(void *);