diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2015-12-11 16:07:03 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2015-12-11 16:07:03 +0000 |
commit | ca6d8af89a72201986473d8cb000d091063097ca (patch) | |
tree | 637cf0fda218c2cec40e1323667040f1761432bc /sys/kern | |
parent | adaf58bdb03df7ca0d5ca5d5f4ff6f89cc946cae (diff) |
Replace mountroothook_establish(9) by config_mountroot(9) a narrower API
similar to config_defer(9).
ok mikeb@, deraadt@
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/init_main.c | 4 | ||||
-rw-r--r-- | sys/kern/kern_subr.c | 6 | ||||
-rw-r--r-- | sys/kern/subr_autoconf.c | 58 |
3 files changed, 59 insertions, 9 deletions
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index 9de115cb56c..94b65a6630e 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init_main.c,v 1.246 2015/11/08 20:45:57 naddy Exp $ */ +/* $OpenBSD: init_main.c,v 1.247 2015/12/11 16:07:02 mpi Exp $ */ /* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */ /* @@ -536,7 +536,7 @@ main(void *framep) cpu_boot_secondary_processors(); #endif - domountroothooks(); + config_process_deferred_mountroot(); /* * Okay, now we can let init(8) exec! It's off to userland! diff --git a/sys/kern/kern_subr.c b/sys/kern/kern_subr.c index c236b9fb4ca..8e0b5dfcde4 100644 --- a/sys/kern/kern_subr.c +++ b/sys/kern/kern_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_subr.c,v 1.44 2015/03/14 03:38:50 jsg Exp $ */ +/* $OpenBSD: kern_subr.c,v 1.45 2015/12/11 16:07:02 mpi Exp $ */ /* $NetBSD: kern_subr.c,v 1.15 1996/04/09 17:21:56 ragge Exp $ */ /* @@ -184,13 +184,11 @@ hashinit(int elements, int type, int flags, u_long *hashmask) } /* - * "Mountroot/startup hook" types, functions, and variables. + * "startup hook" types, functions, and variables. */ struct hook_desc_head startuphook_list = TAILQ_HEAD_INITIALIZER(startuphook_list); -struct hook_desc_head mountroothook_list = - TAILQ_HEAD_INITIALIZER(mountroothook_list); void * hook_establish(struct hook_desc_head *head, int tail, void (*fn)(void *), diff --git a/sys/kern/subr_autoconf.c b/sys/kern/subr_autoconf.c index bb6041b34b3..ebf8aaec540 100644 --- a/sys/kern/subr_autoconf.c +++ b/sys/kern/subr_autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_autoconf.c,v 1.89 2015/09/11 20:43:23 dlg Exp $ */ +/* $OpenBSD: subr_autoconf.c,v 1.90 2015/12/11 16:07:02 mpi Exp $ */ /* $NetBSD: subr_autoconf.c,v 1.21 1996/04/04 06:06:18 cgd Exp $ */ /* @@ -88,7 +88,9 @@ struct deferred_config { }; TAILQ_HEAD(, deferred_config) deferred_config_queue; +TAILQ_HEAD(, deferred_config) mountroot_config_queue; +void *config_rootsearch(cfmatch_t, char *, void *); void config_process_deferred_children(struct device *); struct devicelist alldevs; /* list of all devices */ @@ -112,6 +114,7 @@ void config_init(void) { TAILQ_INIT(&deferred_config_queue); + TAILQ_INIT(&mountroot_config_queue); TAILQ_INIT(&alldevs); } @@ -676,6 +679,39 @@ config_defer(struct device *dev, void (*func)(struct device *)) } /* + * Defer the configuration of the specified device until after + * root file system is mounted. + */ +void +config_mountroot(struct device *dev, void (*func)(struct device *)) +{ + struct deferred_config *dc; + + /* + * No need to defer if root file system is already mounted. + */ + if (rootvp != NULL) { + (*func)(dev); + return; + } + +#ifdef DIAGNOSTIC + for (dc = TAILQ_FIRST(&mountroot_config_queue); dc != NULL; + dc = TAILQ_NEXT(dc, dc_queue)) { + if (dc->dc_dev == dev) + panic("config_mountroot: deferred twice"); + } +#endif + + if ((dc = malloc(sizeof(*dc), M_DEVBUF, M_NOWAIT)) == NULL) + panic("config_mountroot: can't allocate defer structure"); + + dc->dc_dev = dev; + dc->dc_func = func; + TAILQ_INSERT_TAIL(&mountroot_config_queue, dc, dc_queue); +} + +/* * Process the deferred configuration queue for a device. */ void @@ -696,6 +732,22 @@ config_process_deferred_children(struct device *parent) } /* + * Process the deferred configuration queue after the root file + * system is mounted . + */ +void +config_process_deferred_mountroot(void) +{ + struct deferred_config *dc; + + while ((dc = TAILQ_FIRST(&mountroot_config_queue)) != NULL) { + TAILQ_REMOVE(&mountroot_config_queue, dc, dc_queue); + (*dc->dc_func)(dc->dc_dev); + free(dc, M_DEVBUF, 0); + } +} + +/* * Manipulate the config_pending semaphore. */ void @@ -874,7 +926,7 @@ device_lookup(struct cfdriver *cd, int unit) if (unit >= 0 && unit < cd->cd_ndevs) dv = (struct device *)(cd->cd_devs[unit]); - + if (!dv) return (NULL); @@ -906,7 +958,7 @@ device_mpath(void) if (mpath_cd.cd_ndevs < 1) return (NULL); - + return (mpath_cd.cd_devs[0]); #else return (NULL); |