Date: Thu, 23 Apr 2009 22:20:17 GMT From: Marko Zec <zec@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 161005 for review Message-ID: <200904232220.n3NMKHbm019797@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=161005 Change 161005 by zec@zec_amdx2 on 2009/04/23 22:20:13 Convert ng_base and several ng modules to use the vnet registration / deregistration framework, so that kldloading and unloading of such modules will be possible with multiple active vnets. Affected files ... .. //depot/projects/vimage-commit/src/sys/netgraph/netgraph.h#8 edit .. //depot/projects/vimage-commit/src/sys/netgraph/ng_base.c#12 edit .. //depot/projects/vimage-commit/src/sys/netgraph/ng_eiface.c#11 edit .. //depot/projects/vimage-commit/src/sys/netgraph/ng_ether.c#10 edit .. //depot/projects/vimage-commit/src/sys/netgraph/ng_iface.c#11 edit Differences ... ==== //depot/projects/vimage-commit/src/sys/netgraph/netgraph.h#8 (text+ko) ==== @@ -1123,6 +1123,7 @@ struct ng_type *ng_findtype(const char *type); int ng_make_node_common(struct ng_type *typep, node_p *nodep); int ng_name_node(node_p node, const char *name); +node_p ng_name2noderef(node_p node, const char *name); int ng_newtype(struct ng_type *tp); ng_ID_t ng_node2ID(node_p node); item_p ng_package_data(struct mbuf *m, int flags); ==== //depot/projects/vimage-commit/src/sys/netgraph/ng_base.c#12 (text+ko) ==== @@ -84,6 +84,8 @@ /* Mutex to protect topology events. */ static struct mtx ng_topo_mtx; +static vnet_attach_fn vnet_netgraph_iattach; + #ifdef NETGRAPH_DEBUG static struct mtx ng_nodelist_mtx; /* protects global node/hook lists */ static struct mtx ngq_mtx; /* protects the queue item list */ @@ -227,7 +229,6 @@ /* Imported, these used to be externally visible, some may go back. */ void ng_destroy_hook(hook_p hook); -node_p ng_name2noderef(node_p node, const char *name); int ng_path2noderef(node_p here, const char *path, node_p *dest, hook_p *lasthook); int ng_make_node(const char *type, node_p *nodepp); @@ -3068,6 +3069,26 @@ return (error); } +#ifndef VIMAGE_GLOBALS +static const vnet_modinfo_t vnet_netgraph_modinfo = { + .vmi_id = VNET_MOD_NETGRAPH, + .vmi_name = "netgraph", +#ifdef VIMAGE + .vmi_size = sizeof(struct vnet_netgraph), +#endif + .vmi_iattach = vnet_netgraph_iattach +}; +#endif + +static int +vnet_netgraph_iattach(const void *arg __unused) +{ + + V_nextID = 1; + + return (0); +} + /* * Handle loading and unloading for this code. * The only thing we need to link into is the NETISR strucure. @@ -3082,7 +3103,11 @@ switch (event) { case MOD_LOAD: /* Initialize everything. */ - V_nextID = 1; +#ifndef VIMAGE_GLOBALS + vnet_mod_register(&vnet_netgraph_modinfo); +#else + vnet_netgraph_iattach(NULL); +#endif NG_WORKLIST_LOCK_INIT(); mtx_init(&ng_typelist_mtx, "netgraph types mutex", NULL, MTX_DEF); @@ -3133,6 +3158,7 @@ ngb_mod_event, (NULL) }; + DECLARE_MODULE(netgraph, netgraph_mod, SI_SUB_NETGRAPH, SI_ORDER_MIDDLE); SYSCTL_NODE(_net, OID_AUTO, graph, CTLFLAG_RW, 0, "netgraph Family"); SYSCTL_INT(_net_graph, OID_AUTO, abi_version, CTLFLAG_RD, 0, NG_ABI_VERSION,""); ==== //depot/projects/vimage-commit/src/sys/netgraph/ng_eiface.c#11 (text+ko) ==== @@ -113,10 +113,23 @@ }; NETGRAPH_INIT(eiface, &typestruct); +static vnet_attach_fn ng_eiface_iattach; +static vnet_detach_fn ng_eiface_idetach; + #ifdef VIMAGE_GLOBALS static struct unrhdr *ng_eiface_unit; #endif +#ifndef VIMAGE_GLOBALS +static vnet_modinfo_t vnet_ng_eiface_modinfo = { + .vmi_id = VNET_MOD_NG_EIFACE, + .vmi_name = "ng_eiface", + .vmi_dependson = VNET_MOD_NETGRAPH, + .vmi_iattach = ng_eiface_iattach, + .vmi_idetach = ng_eiface_idetach +}; +#endif + /************************************************************************ INTERFACE STUFF ************************************************************************/ @@ -588,8 +601,18 @@ switch (event) { case MOD_LOAD: V_ng_eiface_unit = new_unrhdr(0, 0xffff, NULL); +#ifndef VIMAGE_GLOBALS + vnet_mod_register(&vnet_ng_eiface_modinfo); +#else + ng_eiface_iattach(NULL); +#endif break; case MOD_UNLOAD: +#ifndef VIMAGE_GLOBALS + vnet_mod_deregister(&vnet_ng_eiface_modinfo); +#else + ng_eiface_idetach(NULL); +#endif delete_unrhdr(V_ng_eiface_unit); break; default: @@ -598,3 +621,21 @@ } return (error); } + +static int ng_eiface_iattach(const void *unused) +{ + INIT_VNET_NETGRAPH(curvnet); + + V_ng_eiface_unit = new_unrhdr(0, 0xffff, NULL); + + return (0); +} + +static int ng_eiface_idetach(const void *unused) +{ + INIT_VNET_NETGRAPH(curvnet); + + delete_unrhdr(V_ng_eiface_unit); + + return (0); +} ==== //depot/projects/vimage-commit/src/sys/netgraph/ng_ether.c#10 (text+ko) ==== @@ -75,6 +75,17 @@ #define IFP2NG(ifp) (IFP2AC((ifp))->ac_netgraph) +static vnet_attach_fn ng_ether_iattach; + +#ifndef VIMAGE_GLOBALS +static vnet_modinfo_t vnet_ng_ether_modinfo = { + .vmi_id = VNET_MOD_NG_ETHER, + .vmi_name = "ng_ether", + .vmi_dependson = VNET_MOD_NETGRAPH, + .vmi_iattach = ng_ether_iattach, +}; +#endif + /* Per-node private data */ struct private { struct ifnet *ifp; /* associated interface */ @@ -287,6 +298,17 @@ priv_p priv; node_p node; + /* + * Do not create / attach an ether node to this ifnet if + * a netgraph node with the same name already exists. + * This should prevent ether nodes to become attached to + * eiface nodes, which is pointless. + */ + if ((node = ng_name2noderef(NULL, ifp->if_xname)) != NULL) { + NG_NODE_UNREF(node); + return; + } + /* Create node */ KASSERT(!IFP2NG(ifp), ("%s: node already exists?", __func__)); if (ng_make_node_common(&ng_ether_typestruct, &node) != 0) { @@ -741,7 +763,6 @@ static int ng_ether_mod_event(module_t mod, int event, void *data) { - struct ifnet *ifp; int error = 0; int s; @@ -761,14 +782,11 @@ ng_ether_input_orphan_p = ng_ether_input_orphan; ng_ether_link_state_p = ng_ether_link_state; - /* Create nodes for any already-existing Ethernet interfaces */ - IFNET_RLOCK(); - TAILQ_FOREACH(ifp, &V_ifnet, if_link) { - if (ifp->if_type == IFT_ETHER - || ifp->if_type == IFT_L2VLAN) - ng_ether_attach(ifp); - } - IFNET_RUNLOCK(); +#ifndef VIMAGE_GLOBALS + vnet_mod_register(&vnet_ng_ether_modinfo); +#else + error = ng_ether_iattach(NULL); +#endif break; case MOD_UNLOAD: @@ -781,6 +799,10 @@ * is MOD_UNLOAD, so there's no need to detach any nodes. */ +#ifndef VIMAGE_GLOBALS + vnet_mod_deregister(&vnet_ng_ether_modinfo); +#endif + /* Unregister function hooks */ ng_ether_attach_p = NULL; ng_ether_detach_p = NULL; @@ -798,3 +820,19 @@ return (error); } +static int ng_ether_iattach(const void *unused) +{ + INIT_VNET_NET(curvnet); + struct ifnet *ifp; + + /* Create nodes for any already-existing Ethernet interfaces */ + IFNET_RLOCK(); + TAILQ_FOREACH(ifp, &V_ifnet, if_link) { + if (ifp->if_type == IFT_ETHER + || ifp->if_type == IFT_L2VLAN) + ng_ether_attach(ifp); + } + IFNET_RUNLOCK(); + + return (0); +} ==== //depot/projects/vimage-commit/src/sys/netgraph/ng_iface.c#11 (text+ko) ==== @@ -209,10 +209,23 @@ }; NETGRAPH_INIT(iface, &typestruct); +static vnet_attach_fn ng_iface_iattach; +static vnet_detach_fn ng_iface_idetach; + #ifdef VIMAGE_GLOBALS static struct unrhdr *ng_iface_unit; #endif +#ifndef VIMAGE_GLOBALS +static vnet_modinfo_t vnet_ng_iface_modinfo = { + .vmi_id = VNET_MOD_NG_IFACE, + .vmi_name = "ng_iface", + .vmi_dependson = VNET_MOD_NETGRAPH, + .vmi_iattach = ng_iface_iattach, + .vmi_idetach = ng_iface_idetach +}; +#endif + /************************************************************************ HELPER STUFF ************************************************************************/ @@ -834,10 +847,18 @@ switch (event) { case MOD_LOAD: - V_ng_iface_unit = new_unrhdr(0, 0xffff, NULL); +#ifndef VIMAGE_GLOBALS + vnet_mod_register(&vnet_ng_iface_modinfo); +#else + ng_iface_iattach(NULL); +#endif break; case MOD_UNLOAD: - delete_unrhdr(V_ng_iface_unit); +#ifndef VIMAGE_GLOBALS + vnet_mod_deregister(&vnet_ng_iface_modinfo); +#else + ng_iface_idetach(NULL); +#endif break; default: error = EOPNOTSUPP; @@ -845,3 +866,21 @@ } return (error); } + +static int ng_iface_iattach(const void *unused) +{ + INIT_VNET_NETGRAPH(curvnet); + + V_ng_iface_unit = new_unrhdr(0, 0xffff, NULL); + + return (0); +} + +static int ng_iface_idetach(const void *unused) +{ + INIT_VNET_NETGRAPH(curvnet); + + delete_unrhdr(V_ng_iface_unit); + + return (0); +}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200904232220.n3NMKHbm019797>