Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 24 Apr 2009 12:21:14 GMT
From:      Marko Zec <zec@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 161028 for review
Message-ID:  <200904241221.n3OCLEZ4041248@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=161028

Change 161028 by zec@zec_tpx32 on 2009/04/24 12:20:39

	Integrate vimage-commit -> vimage-commit2
	
	... in order to reduce the output of makemeat2.pl.

Affected files ...

.. //depot/projects/vimage-commit2/src/sys/kern/kern_vimage.c#17 integrate
.. //depot/projects/vimage-commit2/src/sys/net/if_loop.c#26 integrate
.. //depot/projects/vimage-commit2/src/sys/netgraph/netgraph.h#21 integrate
.. //depot/projects/vimage-commit2/src/sys/netgraph/ng_base.c#25 integrate
.. //depot/projects/vimage-commit2/src/sys/netgraph/ng_eiface.c#20 integrate
.. //depot/projects/vimage-commit2/src/sys/netgraph/ng_ether.c#13 integrate
.. //depot/projects/vimage-commit2/src/sys/netgraph/ng_iface.c#19 integrate
.. //depot/projects/vimage-commit2/src/sys/sys/vimage.h#42 integrate

Differences ...

==== //depot/projects/vimage-commit2/src/sys/kern/kern_vimage.c#17 (text+ko) ====

@@ -48,6 +48,7 @@
 static TAILQ_HEAD(vnet_modpending_head, vnet_modlink) vnet_modpending_head;
 static void vnet_mod_complete_registration(struct vnet_modlink *);
 static int vnet_mod_constructor(struct vnet_modlink *);
+static int vnet_mod_destructor(struct vnet_modlink *);
 
 #ifdef VIMAGE
 /* curvnet should be thread-local - this is only a temporary step */
@@ -151,6 +152,36 @@
 	} while (vml_iter != NULL);
 }
 
+void
+vnet_mod_deregister(const struct vnet_modinfo *vmi)
+{
+	vnet_mod_deregister_multi(vmi, NULL, NULL);
+}
+
+void
+vnet_mod_deregister_multi(const struct vnet_modinfo *vmi, void *iarg,
+    char *iname)
+{
+	VNET_ITERATOR_DECL(vnet_iter);
+	struct vnet_modlink *vml;
+
+	TAILQ_FOREACH(vml, &vnet_modlink_head, vml_mod_le)
+		if (vml->vml_modinfo == vmi && vml->vml_iarg == iarg)
+			break;
+	if (vml == NULL)
+		panic("cannot deregister unregistered vnet module %s",
+		    vmi->vmi_name);
+
+	VNET_FOREACH(vnet_iter) {
+		CURVNET_SET_QUIET(vnet_iter);
+		vnet_mod_destructor(vml);
+		CURVNET_RESTORE();
+	}
+
+	TAILQ_REMOVE(&vnet_modlink_head, vml, vml_mod_le);
+	free(vml, M_VIMAGE);
+}
+
 static int vnet_mod_constructor(struct vnet_modlink *vml)
 {
 	const struct vnet_modinfo *vmi = vml->vml_modinfo;
@@ -160,8 +191,10 @@
 	if (vml->vml_iarg)
 		printf("/%s", vml->vml_iname);
 	printf(": ");
+#ifdef VIMAGE
 	if (vmi->vmi_size)
 		printf("malloc(%zu); ", vmi->vmi_size);
+#endif
 	if (vmi->vmi_iattach != NULL)
 		printf("iattach()");
 	printf("\n");
@@ -183,6 +216,41 @@
 	return (0);
 }
 
+
+static int
+vnet_mod_destructor(struct vnet_modlink *vml)
+{
+	const struct vnet_modinfo *vmi = vml->vml_modinfo;
+
+#ifdef DEBUG_ORDERING
+	printf("destroying vnet_%s", vmi->vmi_name);
+	if (vml->vml_iarg)
+		printf("/%s", vml->vml_iname);
+	printf(": ");
+	if (vmi->vmi_idetach != NULL)
+		printf("idetach(); ");
+#ifdef VIMAGE
+	if (vmi->vmi_size)
+		printf("free()");
+#endif
+	printf("\n");
+#endif
+
+	if (vmi->vmi_idetach)
+		vmi->vmi_idetach(vml->vml_iarg);
+
+#ifdef VIMAGE
+	if (vmi->vmi_size) {
+		if (curvnet->mod_data[vmi->vmi_id] == NULL)
+			panic("vi_destroy: %s\n", vmi->vmi_name);
+		free(curvnet->mod_data[vmi->vmi_id], M_VNET);
+		curvnet->mod_data[vmi->vmi_id] = NULL;
+	}
+#endif
+
+	return (0);
+}
+
 /*
  * vi_symlookup() attempts to resolve name to address queries for
  * variables which have been moved from global namespace to virtualization

==== //depot/projects/vimage-commit2/src/sys/net/if_loop.c#26 (text+ko) ====


==== //depot/projects/vimage-commit2/src/sys/netgraph/netgraph.h#21 (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-commit2/src/sys/netgraph/ng_base.c#25 (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,27 @@
 	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)
+{
+	INIT_VNET_NETGRAPH(curvnet);
+
+	V_nextID = 1;
+
+	return (0);
+}
+
 /*
  * Handle loading and unloading for this code.
  * The only thing we need to link into is the NETISR strucure.
@@ -3083,7 +3105,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);

==== //depot/projects/vimage-commit2/src/sys/netgraph/ng_eiface.c#20 (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
  ************************************************************************/
@@ -591,10 +604,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:
-		delete_unrhdr(V_ng_eiface_unit);
+#ifndef VIMAGE_GLOBALS
+		vnet_mod_deregister(&vnet_ng_eiface_modinfo);
+#else
+		ng_eiface_idetach(NULL);
+#endif
 		break;
 	default:
 		error = EOPNOTSUPP;
@@ -602,3 +623,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-commit2/src/sys/netgraph/ng_ether.c#13 (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,18 @@
 	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 may be problematic due to naming
+	 * clashes.
+	 */
+	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,8 +764,6 @@
 static int
 ng_ether_mod_event(module_t mod, int event, void *data)
 {
-	INIT_VNET_NET(curvnet); /* XXX move to iattach - revisit! */
-	struct ifnet *ifp;
 	int error = 0;
 	int s;
 
@@ -762,14 +783,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:
@@ -782,6 +800,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;
@@ -799,3 +821,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-commit2/src/sys/netgraph/ng_iface.c#19 (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
  ************************************************************************/
@@ -837,10 +850,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;
@@ -848,3 +869,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);
+}

==== //depot/projects/vimage-commit2/src/sys/sys/vimage.h#42 (text+ko) ====

@@ -123,6 +123,8 @@
 int	vi_symlookup(struct kld_sym_lookup *, char *);
 void	vnet_mod_register(const struct vnet_modinfo *);
 void	vnet_mod_register_multi(const struct vnet_modinfo *, void *, char *);
+void	vnet_mod_deregister(const struct vnet_modinfo *);
+void	vnet_mod_deregister_multi(const struct vnet_modinfo *, void *, char *);
 
 #endif /* !VIMAGE_GLOBALS */
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200904241221.n3OCLEZ4041248>