Source-Changes-HG archive

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

[src/trunk]: src/sys wait for config_mountroot threads to complete before we ...



details:   https://anonhg.NetBSD.org/src/rev/d250de43590b
branches:  trunk
changeset: 336562:d250de43590b
user:      mrg <mrg%NetBSD.org@localhost>
date:      Fri Mar 06 09:28:15 2015 +0000

description:
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

diffstat:

 sys/kern/init_main.c     |   7 +++++--
 sys/kern/subr_autoconf.c |  35 +++++++++++++++++++++++++++++++----
 sys/sys/device.h         |   3 ++-
 3 files changed, 38 insertions(+), 7 deletions(-)

diffs (112 lines):

diff -r 24756dc7f5dc -r d250de43590b sys/kern/init_main.c
--- a/sys/kern/init_main.c      Fri Mar 06 03:35:00 2015 +0000
+++ b/sys/kern/init_main.c      Fri Mar 06 09:28:15 2015 +0000
@@ -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 @@
            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!
         */
diff -r 24756dc7f5dc -r d250de43590b sys/kern/subr_autoconf.c
--- a/sys/kern/subr_autoconf.c  Fri Mar 06 03:35:00 2015 +0000
+++ b/sys/kern/subr_autoconf.c  Fri Mar 06 09:28:15 2015 +0000
@@ -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 @@
 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,12 +483,37 @@
        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);
+}
+
 /*
  * Announce device attach/detach to userland listeners.
  */
diff -r 24756dc7f5dc -r d250de43590b sys/sys/device.h
--- a/sys/sys/device.h  Fri Mar 06 03:35:00 2015 +0000
+++ b/sys/sys/device.h  Fri Mar 06 09:28:15 2015 +0000
@@ -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 @@
 
 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 *);



Home | Main Index | Thread Index | Old Index