summaryrefslogtreecommitdiffstats
path: root/sys/kern/uipc_domain.c
diff options
context:
space:
mode:
authorzec <zec@FreeBSD.org>2009-04-11 05:58:58 +0000
committerzec <zec@FreeBSD.org>2009-04-11 05:58:58 +0000
commitb39b54e6de5e755fbd3b04aab7097f86a580683b (patch)
tree618d4d0f8f12ea508843080db84d79333f116cac /sys/kern/uipc_domain.c
parent66be48ef8d10d34872de501bf489edaa11e2ebc4 (diff)
downloadFreeBSD-src-b39b54e6de5e755fbd3b04aab7097f86a580683b.zip
FreeBSD-src-b39b54e6de5e755fbd3b04aab7097f86a580683b.tar.gz
Introduce vnet module registration / initialization framework with
dependency tracking and ordering enforcement. With this change, per-vnet initialization functions introduced with r190787 are no longer directly called from traditional initialization functions (which cc in most cases inlined to pre-r190787 code), but are instead registered via the vnet framework first, and are invoked only after all prerequisite modules have been initialized. In the long run, this framework should allow us to both initialize and dismantle multiple vnet instances in a correct order. The problem this change aims to solve is how to replay the initialization sequence of various network stack components, which have been traditionally triggered via different mechanisms (SYSINIT, protosw). Note that this initialization sequence was and still can be subtly different depending on whether certain pieces of code have been statically compiled into the kernel, loaded as modules by boot loader, or kldloaded at run time. The approach is simple - we record the initialization sequence established by the traditional mechanisms whenever vnet_mod_register() is called for a particular vnet module. The vnet_mod_register_multi() variant allows a single initializer function to be registered multiple times but with different arguments - currently this is only used in kern/uipc_domain.c by net_add_domain() with different struct domain * as arguments, which allows for protosw-registered initialization routines to be invoked in a correct order by the new vnet initialization framework. For the purpose of identifying vnet modules, each vnet module has to have a unique ID, which is statically assigned in sys/vimage.h. Dynamic assignment of vnet module IDs is not supported yet. A vnet module may specify a single prerequisite module at registration time by filling in the vmi_dependson field of its vnet_modinfo struct with the ID of the module it depends on. Unless specified otherwise, all vnet modules depend on VNET_MOD_NET (container for ifnet list head, rt_tables etc.), which thus has to and will always be initialized first. The framework will panic if it detects any unresolved dependencies before completing system initialization. Detection of unresolved dependencies for vnet modules registered after boot (kldloaded modules) is not provided. Note that the fact that each module can specify only a single prerequisite may become problematic in the long run. In particular, INET6 depends on INET being already instantiated, due to TCP / UDP structures residing in INET container. IPSEC also depends on INET, which will in turn additionally complicate making INET6-only kernel configs a reality. The entire registration framework can be compiled out by turning on the VIMAGE_GLOBALS kernel config option. Reviewed by: bz Approved by: julian (mentor)
Diffstat (limited to 'sys/kern/uipc_domain.c')
-rw-r--r--sys/kern/uipc_domain.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/sys/kern/uipc_domain.c b/sys/kern/uipc_domain.c
index 9c9b05f..df35bcb 100644
--- a/sys/kern/uipc_domain.c
+++ b/sys/kern/uipc_domain.c
@@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$");
#include <sys/mutex.h>
#include <sys/socketvar.h>
#include <sys/systm.h>
+#include <sys/vimage.h>
#include <vm/uma.h>
/*
@@ -64,6 +65,8 @@ static void domainfinalize(void *);
SYSINIT(domainfin, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_FIRST, domainfinalize,
NULL);
+static vnet_attach_fn net_init_domain;
+
static struct callout pffast_callout;
static struct callout pfslow_callout;
@@ -100,6 +103,14 @@ struct pr_usrreqs nousrreqs = {
.pru_sopoll = pru_sopoll_notsupp,
};
+#ifndef VIMAGE_GLOBALS
+vnet_modinfo_t vnet_domain_modinfo = {
+ .vmi_id = VNET_MOD_DOMAIN,
+ .vmi_name = "domain",
+ .vmi_iattach = net_init_domain
+};
+#endif
+
static void
protosw_init(struct protosw *pr)
{
@@ -159,9 +170,10 @@ protosw_init(struct protosw *pr)
* Note: you cant unload it again because a socket may be using it.
* XXX can't fail at this time.
*/
-static void
-net_init_domain(struct domain *dp)
+static int
+net_init_domain(const void *arg)
{
+ const struct domain *dp = arg;
struct protosw *pr;
if (dp->dom_init)
@@ -175,6 +187,7 @@ net_init_domain(struct domain *dp)
max_datalen = MHLEN - max_hdr;
if (max_datalen < 1)
panic("%s: max_datalen < 1", __func__);
+ return (0);
}
/*
@@ -210,7 +223,11 @@ net_add_domain(void *data)
"domainfinalize()\n", dp->dom_name);
#endif
mtx_unlock(&dom_mtx);
+#ifndef VIMAGE_GLOBALS
+ vnet_mod_register_multi(&vnet_domain_modinfo, dp, dp->dom_name);
+#else
net_init_domain(dp);
+#endif
}
static void
OpenPOWER on IntegriCloud