diff options
author | rwatson <rwatson@FreeBSD.org> | 2009-07-23 20:46:49 +0000 |
---|---|---|
committer | rwatson <rwatson@FreeBSD.org> | 2009-07-23 20:46:49 +0000 |
commit | b3be1c6e3bd7d3b5cf946ddb04c1c5811644229b (patch) | |
tree | 0191b21173debdadfbf9f7565dfc5a8b9eefe94a /sys/net/if_loop.c | |
parent | fc8defe5dd957eaee1f1c841d45804df5bbf20f5 (diff) | |
download | FreeBSD-src-b3be1c6e3bd7d3b5cf946ddb04c1c5811644229b.zip FreeBSD-src-b3be1c6e3bd7d3b5cf946ddb04c1c5811644229b.tar.gz |
Introduce and use a sysinit-based initialization scheme for virtual
network stacks, VNET_SYSINIT:
- Add VNET_SYSINIT and VNET_SYSUNINIT macros to declare events that will
occur each time a network stack is instantiated and destroyed. In the
!VIMAGE case, these are simply mapped into regular SYSINIT/SYSUNINIT.
For the VIMAGE case, we instead use SYSINIT's to track their order and
properties on registration, using them for each vnet when created/
destroyed, or immediately on module load for already-started vnets.
- Remove vnet_modinfo mechanism that existed to serve this purpose
previously, as well as its dependency scheme: we now just use the
SYSINIT ordering scheme.
- Implement VNET_DOMAIN_SET() to allow protocol domains to declare that
they want init functions to be called for each virtual network stack
rather than just once at boot, compiling down to DOMAIN_SET() in the
non-VIMAGE case.
- Walk all virtualized kernel subsystems and make use of these instead
of modinfo or DOMAIN_SET() for init/uninit events. In some cases,
convert modular components from using modevent to using sysinit (where
appropriate). In some cases, do minor rejuggling of SYSINIT ordering
to make room for or better manage events.
Portions submitted by: jhb (VNET_SYSINIT), bz (cleanup)
Discussed with: jhb, bz, julian, zec
Reviewed by: bz
Approved by: re (VIMAGE blanket)
Diffstat (limited to 'sys/net/if_loop.c')
-rw-r--r-- | sys/net/if_loop.c | 56 |
1 files changed, 15 insertions, 41 deletions
diff --git a/sys/net/if_loop.c b/sys/net/if_loop.c index 7889570..043c808 100644 --- a/sys/net/if_loop.c +++ b/sys/net/if_loop.c @@ -103,30 +103,14 @@ int looutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, struct route *ro); static int lo_clone_create(struct if_clone *, int, caddr_t); static void lo_clone_destroy(struct ifnet *); -static int vnet_loif_iattach(const void *); -#ifdef VIMAGE -static int vnet_loif_idetach(const void *); -#endif VNET_DEFINE(struct ifnet *, loif); /* Used externally */ #ifdef VIMAGE -static VNET_DEFINE(struct ifc_simple_data *, lo_cloner_data); -static VNET_DEFINE(struct if_clone *, lo_cloner); +static VNET_DEFINE(struct ifc_simple_data, lo_cloner_data); +static VNET_DEFINE(struct if_clone, lo_cloner); #define V_lo_cloner_data VNET(lo_cloner_data) #define V_lo_cloner VNET(lo_cloner) - -MALLOC_DEFINE(M_LO_CLONER, "lo_cloner", "lo_cloner"); -#endif - -#ifdef VIMAGE -static const vnet_modinfo_t vnet_loif_modinfo = { - .vmi_id = VNET_MOD_LOIF, - .vmi_dependson = VNET_MOD_IF_CLONE, - .vmi_name = "loif", - .vmi_iattach = vnet_loif_iattach, - .vmi_idetach = vnet_loif_idetach -}; #endif IFC_SIMPLE_DECLARE(lo, 1); @@ -170,37 +154,32 @@ lo_clone_create(struct if_clone *ifc, int unit, caddr_t params) return (0); } -static int -vnet_loif_iattach(const void *unused __unused) +static void +vnet_loif_init(const void *unused __unused) { #ifdef VIMAGE - V_lo_cloner = malloc(sizeof(*V_lo_cloner), M_LO_CLONER, - M_WAITOK | M_ZERO); - V_lo_cloner_data = malloc(sizeof(*V_lo_cloner_data), M_LO_CLONER, - M_WAITOK | M_ZERO); - bcopy(&lo_cloner, V_lo_cloner, sizeof(*V_lo_cloner)); - bcopy(lo_cloner.ifc_data, V_lo_cloner_data, sizeof(*V_lo_cloner_data)); - V_lo_cloner->ifc_data = V_lo_cloner_data; - if_clone_attach(V_lo_cloner); + V_lo_cloner = lo_cloner; + V_lo_cloner_data = lo_cloner_data; + V_lo_cloner.ifc_data = &V_lo_cloner_data; + if_clone_attach(&V_lo_cloner); #else if_clone_attach(&lo_cloner); #endif - return (0); } +VNET_SYSINIT(vnet_loif_init, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_ANY, + vnet_loif_init, NULL); #ifdef VIMAGE -static int -vnet_loif_idetach(const void *unused __unused) +static void +vnet_loif_uninit(const void *unused __unused) { - if_clone_detach(V_lo_cloner); - free(V_lo_cloner, M_LO_CLONER); - free(V_lo_cloner_data, M_LO_CLONER); + if_clone_detach(&V_lo_cloner); V_loif = NULL; - - return (0); } +VNET_SYSUNINIT(vnet_loif_uninit, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_ANY, + vnet_loif_uninit, NULL); #endif static int @@ -209,11 +188,6 @@ loop_modevent(module_t mod, int type, void *data) switch (type) { case MOD_LOAD: -#ifdef VIMAGE - vnet_mod_register(&vnet_loif_modinfo); -#else - vnet_loif_iattach(NULL); -#endif break; case MOD_UNLOAD: |