Pull up following revision(s) (requested by mrg in ticket #576): sys/kern/init_main.c: revision 1.462 sys/kern/subr_autoconf.c: revision 1.234 sys/sys/device.h: revision 1.147 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-7diff -r1.458.2.1 -r1.458.2.2 src/sys/kern/init_main.c
(snj)
--- src/sys/kern/init_main.c 2014/08/15 12:58:45 1.458.2.1
+++ src/sys/kern/init_main.c 2015/03/09 08:56:01 1.458.2.2
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: init_main.c,v 1.458.2.1 2014/08/15 12:58:45 martin Exp $ */ | 1 | /* $NetBSD: init_main.c,v 1.458.2.2 2015/03/09 08:56:01 snj Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -87,27 +87,27 @@ | @@ -87,27 +87,27 @@ | |||
87 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 87 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
88 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 88 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
89 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 89 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
90 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 90 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
91 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 91 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
92 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 92 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
93 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 93 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
94 | * SUCH DAMAGE. | 94 | * SUCH DAMAGE. | |
95 | * | 95 | * | |
96 | * @(#)init_main.c 8.16 (Berkeley) 5/14/95 | 96 | * @(#)init_main.c 8.16 (Berkeley) 5/14/95 | |
97 | */ | 97 | */ | |
98 | 98 | |||
99 | #include <sys/cdefs.h> | 99 | #include <sys/cdefs.h> | |
100 | __KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.458.2.1 2014/08/15 12:58:45 martin Exp $"); | 100 | __KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.458.2.2 2015/03/09 08:56:01 snj Exp $"); | |
101 | 101 | |||
102 | #include "opt_ddb.h" | 102 | #include "opt_ddb.h" | |
103 | #include "opt_ipsec.h" | 103 | #include "opt_ipsec.h" | |
104 | #include "opt_modular.h" | 104 | #include "opt_modular.h" | |
105 | #include "opt_ntp.h" | 105 | #include "opt_ntp.h" | |
106 | #include "opt_pipe.h" | 106 | #include "opt_pipe.h" | |
107 | #include "opt_syscall_debug.h" | 107 | #include "opt_syscall_debug.h" | |
108 | #include "opt_sysv.h" | 108 | #include "opt_sysv.h" | |
109 | #include "opt_fileassoc.h" | 109 | #include "opt_fileassoc.h" | |
110 | #include "opt_ktrace.h" | 110 | #include "opt_ktrace.h" | |
111 | #include "opt_pax.h" | 111 | #include "opt_pax.h" | |
112 | #include "opt_compat_netbsd.h" | 112 | #include "opt_compat_netbsd.h" | |
113 | #include "opt_wapbl.h" | 113 | #include "opt_wapbl.h" | |
@@ -702,26 +702,29 @@ main(void) | @@ -702,26 +702,29 @@ main(void) | |||
702 | NULL, NULL, "pgdaemon")) | 702 | NULL, NULL, "pgdaemon")) | |
703 | panic("fork pagedaemon"); | 703 | panic("fork pagedaemon"); | |
704 | 704 | |||
705 | /* Create the filesystem syncer kernel thread. */ | 705 | /* Create the filesystem syncer kernel thread. */ | |
706 | if (kthread_create(PRI_IOFLUSH, KTHREAD_MPSAFE, NULL, sched_sync, | 706 | if (kthread_create(PRI_IOFLUSH, KTHREAD_MPSAFE, NULL, sched_sync, | |
707 | NULL, NULL, "ioflush")) | 707 | NULL, NULL, "ioflush")) | |
708 | panic("fork syncer"); | 708 | panic("fork syncer"); | |
709 | 709 | |||
710 | /* Create the aiodone daemon kernel thread. */ | 710 | /* Create the aiodone daemon kernel thread. */ | |
711 | if (workqueue_create(&uvm.aiodone_queue, "aiodoned", | 711 | if (workqueue_create(&uvm.aiodone_queue, "aiodoned", | |
712 | uvm_aiodone_worker, NULL, PRI_VM, IPL_NONE, WQ_MPSAFE)) | 712 | uvm_aiodone_worker, NULL, PRI_VM, IPL_NONE, WQ_MPSAFE)) | |
713 | panic("fork aiodoned"); | 713 | panic("fork aiodoned"); | |
714 | 714 | |||
715 | /* Wait for final configure threads to complete. */ | |||
716 | config_finalize_mountroot(); | |||
717 | ||||
715 | /* | 718 | /* | |
716 | * Okay, now we can let init(8) exec! It's off to userland! | 719 | * Okay, now we can let init(8) exec! It's off to userland! | |
717 | */ | 720 | */ | |
718 | mutex_enter(proc_lock); | 721 | mutex_enter(proc_lock); | |
719 | start_init_exec = 1; | 722 | start_init_exec = 1; | |
720 | cv_broadcast(&lbolt); | 723 | cv_broadcast(&lbolt); | |
721 | mutex_exit(proc_lock); | 724 | mutex_exit(proc_lock); | |
722 | 725 | |||
723 | /* The scheduler is an infinite loop. */ | 726 | /* The scheduler is an infinite loop. */ | |
724 | uvm_scheduler(); | 727 | uvm_scheduler(); | |
725 | /* NOTREACHED */ | 728 | /* NOTREACHED */ | |
726 | } | 729 | } | |
727 | 730 |
--- src/sys/kern/subr_autoconf.c 2014/08/10 16:44:36 1.231
+++ src/sys/kern/subr_autoconf.c 2015/03/09 08:56:01 1.231.2.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: subr_autoconf.c,v 1.231 2014/08/10 16:44:36 tls Exp $ */ | 1 | /* $NetBSD: subr_autoconf.c,v 1.231.2.1 2015/03/09 08:56:01 snj Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1996, 2000 Christopher G. Demetriou | 4 | * Copyright (c) 1996, 2000 Christopher G. Demetriou | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -67,27 +67,27 @@ | @@ -67,27 +67,27 @@ | |||
67 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 67 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
68 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 68 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
69 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 69 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
70 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 70 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
71 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 71 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
72 | * SUCH DAMAGE. | 72 | * SUCH DAMAGE. | |
73 | * | 73 | * | |
74 | * from: Header: subr_autoconf.c,v 1.12 93/02/01 19:31:48 torek Exp (LBL) | 74 | * from: Header: subr_autoconf.c,v 1.12 93/02/01 19:31:48 torek Exp (LBL) | |
75 | * | 75 | * | |
76 | * @(#)subr_autoconf.c 8.3 (Berkeley) 5/17/94 | 76 | * @(#)subr_autoconf.c 8.3 (Berkeley) 5/17/94 | |
77 | */ | 77 | */ | |
78 | 78 | |||
79 | #include <sys/cdefs.h> | 79 | #include <sys/cdefs.h> | |
80 | __KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.231 2014/08/10 16:44:36 tls Exp $"); | 80 | __KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.231.2.1 2015/03/09 08:56:01 snj Exp $"); | |
81 | 81 | |||
82 | #ifdef _KERNEL_OPT | 82 | #ifdef _KERNEL_OPT | |
83 | #include "opt_ddb.h" | 83 | #include "opt_ddb.h" | |
84 | #include "drvctl.h" | 84 | #include "drvctl.h" | |
85 | #endif | 85 | #endif | |
86 | 86 | |||
87 | #include <sys/param.h> | 87 | #include <sys/param.h> | |
88 | #include <sys/device.h> | 88 | #include <sys/device.h> | |
89 | #include <sys/disklabel.h> | 89 | #include <sys/disklabel.h> | |
90 | #include <sys/conf.h> | 90 | #include <sys/conf.h> | |
91 | #include <sys/kauth.h> | 91 | #include <sys/kauth.h> | |
92 | #include <sys/kmem.h> | 92 | #include <sys/kmem.h> | |
93 | #include <sys/systm.h> | 93 | #include <sys/systm.h> | |
@@ -192,26 +192,28 @@ struct deferred_config { | @@ -192,26 +192,28 @@ struct deferred_config { | |||
192 | void (*dc_func)(device_t); | 192 | void (*dc_func)(device_t); | |
193 | }; | 193 | }; | |
194 | 194 | |||
195 | TAILQ_HEAD(deferred_config_head, deferred_config); | 195 | TAILQ_HEAD(deferred_config_head, deferred_config); | |
196 | 196 | |||
197 | struct deferred_config_head deferred_config_queue = | 197 | struct deferred_config_head deferred_config_queue = | |
198 | TAILQ_HEAD_INITIALIZER(deferred_config_queue); | 198 | TAILQ_HEAD_INITIALIZER(deferred_config_queue); | |
199 | struct deferred_config_head interrupt_config_queue = | 199 | struct deferred_config_head interrupt_config_queue = | |
200 | TAILQ_HEAD_INITIALIZER(interrupt_config_queue); | 200 | TAILQ_HEAD_INITIALIZER(interrupt_config_queue); | |
201 | int interrupt_config_threads = 8; | 201 | int interrupt_config_threads = 8; | |
202 | struct deferred_config_head mountroot_config_queue = | 202 | struct deferred_config_head mountroot_config_queue = | |
203 | TAILQ_HEAD_INITIALIZER(mountroot_config_queue); | 203 | TAILQ_HEAD_INITIALIZER(mountroot_config_queue); | |
204 | int mountroot_config_threads = 2; | 204 | int mountroot_config_threads = 2; | |
205 | static lwp_t **mountroot_config_lwpids; | |||
206 | static size_t mountroot_config_lwpids_size; | |||
205 | static bool root_is_mounted = false; | 207 | static bool root_is_mounted = false; | |
206 | 208 | |||
207 | static void config_process_deferred(struct deferred_config_head *, device_t); | 209 | static void config_process_deferred(struct deferred_config_head *, device_t); | |
208 | 210 | |||
209 | /* Hooks to finalize configuration once all real devices have been found. */ | 211 | /* Hooks to finalize configuration once all real devices have been found. */ | |
210 | struct finalize_hook { | 212 | struct finalize_hook { | |
211 | TAILQ_ENTRY(finalize_hook) f_list; | 213 | TAILQ_ENTRY(finalize_hook) f_list; | |
212 | int (*f_func)(device_t); | 214 | int (*f_func)(device_t); | |
213 | device_t f_dev; | 215 | device_t f_dev; | |
214 | }; | 216 | }; | |
215 | static TAILQ_HEAD(, finalize_hook) config_finalize_list = | 217 | static TAILQ_HEAD(, finalize_hook) config_finalize_list = | |
216 | TAILQ_HEAD_INITIALIZER(config_finalize_list); | 218 | TAILQ_HEAD_INITIALIZER(config_finalize_list); | |
217 | static int config_finalize_done; | 219 | static int config_finalize_done; | |
@@ -471,30 +473,55 @@ config_mountroot_thread(void *cookie) | @@ -471,30 +473,55 @@ config_mountroot_thread(void *cookie) | |||
471 | kmem_free(dc, sizeof(*dc)); | 473 | kmem_free(dc, sizeof(*dc)); | |
472 | } | 474 | } | |
473 | kthread_exit(0); | 475 | kthread_exit(0); | |
474 | } | 476 | } | |
475 | 477 | |||
476 | void | 478 | void | |
477 | config_create_mountrootthreads(void) | 479 | config_create_mountrootthreads(void) | |
478 | { | 480 | { | |
479 | int i; | 481 | int i; | |
480 | 482 | |||
481 | if (!root_is_mounted) | 483 | if (!root_is_mounted) | |
482 | root_is_mounted = true; | 484 | root_is_mounted = true; | |
483 | 485 | |||
486 | mountroot_config_lwpids_size = sizeof(mountroot_config_lwpids) * | |||
487 | mountroot_config_threads; | |||
488 | mountroot_config_lwpids = kmem_alloc(mountroot_config_lwpids_size, | |||
489 | KM_NOSLEEP); | |||
490 | KASSERT(mountroot_config_lwpids); | |||
484 | for (i = 0; i < mountroot_config_threads; i++) { | 491 | for (i = 0; i < mountroot_config_threads; i++) { | |
485 | (void)kthread_create(PRI_NONE, 0, NULL, | 492 | mountroot_config_lwpids[i] = 0; | |
486 | config_mountroot_thread, NULL, NULL, "configroot"); | 493 | (void)kthread_create(PRI_NONE, KTHREAD_MUSTJOIN, NULL, | |
494 | config_mountroot_thread, NULL, | |||
495 | &mountroot_config_lwpids[i], | |||
496 | "configroot"); | |||
497 | } | |||
498 | } | |||
499 | ||||
500 | void | |||
501 | config_finalize_mountroot(void) | |||
502 | { | |||
503 | int i, error; | |||
504 | ||||
505 | for (i = 0; i < mountroot_config_threads; i++) { | |||
506 | if (mountroot_config_lwpids[i] == 0) | |||
507 | continue; | |||
508 | ||||
509 | error = kthread_join(mountroot_config_lwpids[i]); | |||
510 | if (error) | |||
511 | printf("%s: thread %x joined with error %d\n", | |||
512 | __func__, i, error); | |||
487 | } | 513 | } | |
514 | kmem_free(mountroot_config_lwpids, mountroot_config_lwpids_size); | |||
488 | } | 515 | } | |
489 | 516 | |||
490 | /* | 517 | /* | |
491 | * Announce device attach/detach to userland listeners. | 518 | * Announce device attach/detach to userland listeners. | |
492 | */ | 519 | */ | |
493 | static void | 520 | static void | |
494 | devmon_report_device(device_t dev, bool isattach) | 521 | devmon_report_device(device_t dev, bool isattach) | |
495 | { | 522 | { | |
496 | #if NDRVCTL > 0 | 523 | #if NDRVCTL > 0 | |
497 | prop_dictionary_t ev; | 524 | prop_dictionary_t ev; | |
498 | const char *parent; | 525 | const char *parent; | |
499 | const char *what; | 526 | const char *what; | |
500 | device_t pdev = device_parent(dev); | 527 | device_t pdev = device_parent(dev); |
--- src/sys/sys/device.h 2013/10/12 16:49:01 1.144
+++ src/sys/sys/device.h 2015/03/09 08:56:02 1.144.4.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: device.h,v 1.144 2013/10/12 16:49:01 christos Exp $ */ | 1 | /* $NetBSD: device.h,v 1.144.4.1 2015/03/09 08:56:02 snj Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1996, 2000 Christopher G. Demetriou | 4 | * Copyright (c) 1996, 2000 Christopher G. Demetriou | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -466,26 +466,27 @@ int config_detach_children(device_t, int | @@ -466,26 +466,27 @@ int config_detach_children(device_t, int | |||
466 | bool config_detach_all(int); | 466 | bool config_detach_all(int); | |
467 | int config_deactivate(device_t); | 467 | int config_deactivate(device_t); | |
468 | void config_defer(device_t, void (*)(device_t)); | 468 | void config_defer(device_t, void (*)(device_t)); | |
469 | void config_deferred(device_t); | 469 | void config_deferred(device_t); | |
470 | void config_interrupts(device_t, void (*)(device_t)); | 470 | void config_interrupts(device_t, void (*)(device_t)); | |
471 | void config_mountroot(device_t, void (*)(device_t)); | 471 | void config_mountroot(device_t, void (*)(device_t)); | |
472 | void config_pending_incr(device_t); | 472 | void config_pending_incr(device_t); | |
473 | void config_pending_decr(device_t); | 473 | void config_pending_decr(device_t); | |
474 | void config_create_interruptthreads(void); | 474 | void config_create_interruptthreads(void); | |
475 | void config_create_mountrootthreads(void); | 475 | void config_create_mountrootthreads(void); | |
476 | 476 | |||
477 | int config_finalize_register(device_t, int (*)(device_t)); | 477 | int config_finalize_register(device_t, int (*)(device_t)); | |
478 | void config_finalize(void); | 478 | void config_finalize(void); | |
479 | void config_finalize_mountroot(void); | |||
479 | 480 | |||
480 | void config_twiddle_init(void); | 481 | void config_twiddle_init(void); | |
481 | void config_twiddle_fn(void *); | 482 | void config_twiddle_fn(void *); | |
482 | 483 | |||
483 | void null_childdetached(device_t, device_t); | 484 | void null_childdetached(device_t, device_t); | |
484 | 485 | |||
485 | device_t device_lookup(cfdriver_t, int); | 486 | device_t device_lookup(cfdriver_t, int); | |
486 | void *device_lookup_private(cfdriver_t, int); | 487 | void *device_lookup_private(cfdriver_t, int); | |
487 | void device_register(device_t, void *); | 488 | void device_register(device_t, void *); | |
488 | void device_register_post_config(device_t, void *); | 489 | void device_register_post_config(device_t, void *); | |
489 | 490 | |||
490 | devclass_t device_class(device_t); | 491 | devclass_t device_class(device_t); | |
491 | cfdata_t device_cfdata(device_t); | 492 | cfdata_t device_cfdata(device_t); |