PERFORCE change 155295 for review
Marko Zec
zec at FreeBSD.org
Fri Dec 26 06:41:48 PST 2008
http://perforce.freebsd.org/chv.cgi?CH=155295
Change 155295 by zec at zec_tca51 on 2008/12/26 14:41:10
Use vnet_mod_register() and the accompanying infrastructure for
invoking vnet_foo_iattach() initializer functions even in GENERIC
kernel builds, not only for options VIMAGE ones.
This change should unbreak network stack initialization for GENERIC
builds.
Note that with options VIMAGE_GLOBALS defined the initializer
functions are still invoked directly from the traditional
SYSINIT() / protosw / modevent handlers, instead of / without
the initializer functions being first registered to the vimage
framework and then (indirectly) invoked by the vimage framework.
Affected files ...
.. //depot/projects/vimage/src/sys/kern/kern_vimage.c#74 edit
.. //depot/projects/vimage/src/sys/net/if.c#61 edit
.. //depot/projects/vimage/src/sys/net/if_gif.c#23 edit
.. //depot/projects/vimage/src/sys/net/if_loop.c#35 edit
.. //depot/projects/vimage/src/sys/net/route.c#39 edit
.. //depot/projects/vimage/src/sys/netinet/accf_http.c#7 edit
.. //depot/projects/vimage/src/sys/netinet/if_ether.c#34 edit
.. //depot/projects/vimage/src/sys/netinet/ip_fw2.c#63 edit
.. //depot/projects/vimage/src/sys/netinet/ip_input.c#46 edit
.. //depot/projects/vimage/src/sys/netinet6/ip6_input.c#45 edit
.. //depot/projects/vimage/src/sys/netipsec/ipsec.c#37 edit
.. //depot/projects/vimage/src/sys/netipsec/xform_ah.c#22 edit
.. //depot/projects/vimage/src/sys/netipsec/xform_esp.c#21 edit
.. //depot/projects/vimage/src/sys/netipsec/xform_ipcomp.c#17 edit
.. //depot/projects/vimage/src/sys/netipsec/xform_ipip.c#22 edit
.. //depot/projects/vimage/src/sys/sys/vimage.h#77 edit
Differences ...
==== //depot/projects/vimage/src/sys/kern/kern_vimage.c#74 (text+ko) ====
@@ -71,11 +71,14 @@
MALLOC_DEFINE(M_VPROCG, "vprocg", "process group control block");
MALLOC_DEFINE(M_VCPU, "vcpu", "cpu resource control block");
+#ifndef VIMAGE_GLOBALS
+static int vnet_mod_constructor(struct vnet_modlink *);
+static int vnet_mod_destructor(struct vnet_modlink *);
+#endif
+
#ifdef VIMAGE
static struct vimage *vi_alloc(struct vimage *, char *);
static int vi_destroy(struct vimage *);
-static int vnet_mod_constructor(struct vnet_modlink *);
-static int vnet_mod_destructor(struct vnet_modlink *);
#endif
#ifndef VIMAGE
@@ -182,13 +185,11 @@
TAILQ_INSERT_TAIL(&vnet_modlink_head, vml, vml_mod_le);
-#ifdef VIMAGE
VNET_FOREACH(vnet_iter) {
CURVNET_SET_QUIET(vnet_iter);
vnet_mod_constructor(vml);
CURVNET_RESTORE();
}
-#endif
/* Check for pending modules depending on us */
do {
@@ -209,33 +210,7 @@
}
} while (vml_iter != NULL);
}
-#endif /* !VIMAGE_GLOBALS */
-
-#ifdef VIMAGE
-struct vimage_list_head vimage_head;
-struct vnet_list_head vnet_head;
-struct vprocg_list_head vprocg_head;
-struct vcpu_list_head vcpu_head;
-
-struct cv vnet_list_condvar;
-struct mtx vnet_list_refc_mtx;
-int vnet_list_refc = 0;
-
-struct mtx vcpu_list_mtx;
-
-#define VNET_LIST_LOCK() \
- mtx_lock(&vnet_list_refc_mtx); \
- while (vnet_list_refc != 0) \
- cv_wait(&vnet_list_condvar, &vnet_list_refc_mtx);
-
-#define VNET_LIST_UNLOCK() \
- mtx_unlock(&vnet_list_refc_mtx);
-static u_int last_vi_id = 0;
-static u_int last_vnet_id = 0;
-static u_int last_vprocg_id = 0;
-static u_int last_vcpu_id = 0;
-
void
vnet_mod_deregister(const struct vnet_modinfo *vmi)
{
@@ -266,6 +241,95 @@
vi_free(vml, M_VIMAGE);
}
+static int vnet_mod_constructor(struct vnet_modlink *vml)
+{
+ const struct vnet_modinfo *vmi = vml->vml_modinfo;
+
+#ifdef DEBUG_ORDERING
+ printf("instatiating vnet_%s", vmi->vmi_name);
+ if (vml->vml_iarg)
+ printf("/%s", vml->vml_iname);
+ printf(": ");
+ if (vmi->vmi_struct_size)
+ printf("malloc(%d); ", vmi->vmi_struct_size);
+ if (vmi->vmi_iattach != NULL)
+ printf("iattach()");
+ printf("\n");
+#endif
+
+#ifdef VIMAGE
+ if (vmi->vmi_struct_size) {
+ void *mem = vi_malloc(vmi->vmi_struct_size, M_VNET,
+ M_NOWAIT | M_ZERO);
+ if (mem == NULL) /* XXX should return error, not panic */
+ panic("vi_alloc: malloc for %s\n", vmi->vmi_name);
+ curvnet->mod_data[vmi->vmi_id] = mem;
+ }
+#endif
+
+ if (vmi->vmi_iattach != NULL)
+ vmi->vmi_iattach(vml->vml_iarg);
+
+ 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(); ");
+ if (vmi->vmi_struct_size)
+ printf("free()");
+ printf("\n");
+#endif
+
+ if (vmi->vmi_idetach)
+ vmi->vmi_idetach(vml->vml_iarg);
+
+#ifdef VIMAGE
+ if (vmi->vmi_struct_size) {
+ if (curvnet->mod_data[vmi->vmi_id] == NULL)
+ panic("vi_destroy: %s\n", vmi->vmi_name);
+ vi_free(curvnet->mod_data[vmi->vmi_id], M_VNET);
+ curvnet->mod_data[vmi->vmi_id] = NULL;
+ }
+#endif
+
+ return (0);
+}
+#endif /* !VIMAGE_GLOBALS */
+
+#ifdef VIMAGE
+struct vimage_list_head vimage_head;
+struct vnet_list_head vnet_head;
+struct vprocg_list_head vprocg_head;
+struct vcpu_list_head vcpu_head;
+
+struct cv vnet_list_condvar;
+struct mtx vnet_list_refc_mtx;
+int vnet_list_refc = 0;
+
+struct mtx vcpu_list_mtx;
+
+#define VNET_LIST_LOCK() \
+ mtx_lock(&vnet_list_refc_mtx); \
+ while (vnet_list_refc != 0) \
+ cv_wait(&vnet_list_condvar, &vnet_list_refc_mtx);
+
+#define VNET_LIST_UNLOCK() \
+ mtx_unlock(&vnet_list_refc_mtx);
+
+static u_int last_vi_id = 0;
+static u_int last_vnet_id = 0;
+static u_int last_vprocg_id = 0;
+static u_int last_vcpu_id = 0;
+
struct vimage *
vnet2vimage(struct vnet *vnet)
{
@@ -772,66 +836,8 @@
return (0);
}
-
-static int vnet_mod_constructor(struct vnet_modlink *vml)
-{
- const struct vnet_modinfo *vmi = vml->vml_modinfo;
-
-#ifdef DEBUG_ORDERING
- printf("instatiating vnet_%s", vmi->vmi_name);
- if (vml->vml_iarg)
- printf("/%s", vml->vml_iname);
- printf(": ");
- if (vmi->vmi_struct_size)
- printf("malloc(%d); ", vmi->vmi_struct_size);
- if (vmi->vmi_iattach != NULL)
- printf("iattach()");
- printf("\n");
-#endif
+#endif /* VIMAGE */
- if (vmi->vmi_struct_size) {
- void *mem = vi_malloc(vmi->vmi_struct_size, M_VNET,
- M_NOWAIT | M_ZERO);
- if (mem == NULL) /* XXX should return error, not panic */
- panic("vi_alloc: malloc for %s\n", vmi->vmi_name);
- curvnet->mod_data[vmi->vmi_id] = mem;
- }
-
- if (vmi->vmi_iattach != NULL)
- vmi->vmi_iattach(vml->vml_iarg);
-
- 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(); ");
- if (vmi->vmi_struct_size)
- printf("free()");
- printf("\n");
-#endif
-
- if (vmi->vmi_idetach)
- vmi->vmi_idetach(vml->vml_iarg);
-
- if (vmi->vmi_struct_size) {
- if (curvnet->mod_data[vmi->vmi_id] == NULL)
- panic("vi_destroy: %s\n", vmi->vmi_name);
- vi_free(curvnet->mod_data[vmi->vmi_id], M_VNET);
- curvnet->mod_data[vmi->vmi_id] = NULL;
- }
-
- return 0;
-}
-
static void
vi_init(void *unused)
{
@@ -840,6 +846,7 @@
TAILQ_INIT(&vnet_modlink_head);
TAILQ_INIT(&vnet_modpending_head);
+#ifdef VIMAGE
LIST_INIT(&vimage_head);
LIST_INIT(&vnet_head);
LIST_INIT(&vprocg_head);
@@ -854,6 +861,7 @@
/* We MUST clear curvnet in vi_init_done before going SMP. */
curvnet = LIST_FIRST(&vnet_head);
+#endif
}
static void
@@ -861,7 +869,9 @@
{
struct vnet_modlink *vml_iter;
+#ifdef VIMAGE
curvnet = NULL;
+#endif
if (TAILQ_EMPTY(&vnet_modpending_head))
return;
@@ -877,6 +887,7 @@
SYSINIT(vimage, SI_SUB_VIMAGE, SI_ORDER_FIRST, vi_init, NULL);
SYSINIT(vimage_done, SI_SUB_VIMAGE_DONE, SI_ORDER_FIRST, vi_init_done, NULL);
+#ifdef VIMAGE
#ifdef DDB
static void
db_vnet_ptr(void *arg)
@@ -905,5 +916,4 @@
}
}
#endif
-
#endif /* VIMAGE */
==== //depot/projects/vimage/src/sys/net/if.c#61 (text+ko) ====
@@ -51,6 +51,7 @@
#include <sys/protosw.h>
#include <sys/kernel.h>
#include <sys/lock.h>
+#include <sys/module.h>
#include <sys/rwlock.h>
#include <sys/sockio.h>
#include <sys/syslog.h>
@@ -182,7 +183,24 @@
};
VNET_MOD_DECLARE(NET, net, vnet_net_iattach, vnet_net_idetach,
- NONE, vnet_net_symmap)
+ NONE, vnet_net_symmap);
+
+static int foo_handler(module_t mod, int /*modeventtype_t*/ what, void *arg);
+
+static int
+foo_handler(module_t mod, int /*modeventtype_t*/ what, void *arg)
+{
+ return (0);
+}
+
+static moduledata_t mod_data= {
+ "vnet_net",
+ foo_handler,
+ 0
+};
+
+MODULE_VERSION(vnet_net, 1);
+DECLARE_MODULE(vnet_net, mod_data, SI_SUB_EXEC, SI_ORDER_ANY);
#endif
/*
@@ -384,7 +402,7 @@
if_init(void *dummy __unused)
{
-#ifdef VIMAGE
+#ifndef VIMAGE_GLOBALS
vnet_mod_register(&vnet_net_modinfo);
#else
vnet_net_iattach(NULL);
==== //depot/projects/vimage/src/sys/net/if_gif.c#23 (text+ko) ====
@@ -158,7 +158,7 @@
SYSCTL_V_INT(V_NET, vnet_gif, _net_link_gif, OID_AUTO, parallel_tunnels,
CTLFLAG_RW, parallel_tunnels, 0, "Allow parallel tunnels?");
-VNET_MOD_DECLARE(GIF, gif, NULL, vnet_gif_iattach, NET, NULL)
+VNET_MOD_DECLARE(GIF, gif, vnet_gif_iattach, NULL, NET, NULL)
/* copy from src/sys/net/if_ethersubr.c */
static const u_char etherbroadcastaddr[ETHER_ADDR_LEN] =
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
@@ -284,7 +284,7 @@
case MOD_LOAD:
mtx_init(&gif_mtx, "gif_mtx", NULL, MTX_DEF);
-#ifdef VIMAGE
+#ifndef VIMAGE_GLOBALS
vnet_mod_register(&vnet_gif_modinfo);
#else
vnet_gif_iattach(NULL);
==== //depot/projects/vimage/src/sys/net/if_loop.c#35 (text+ko) ====
@@ -228,7 +228,7 @@
switch (type) {
case MOD_LOAD:
mtx_init(&lo_mtx, "lo_mtx", NULL, MTX_DEF);
-#ifdef VIMAGE
+#ifndef VIMAGE_GLOBALS
vnet_mod_register(&vnet_loif_modinfo);
#else
vnet_loif_iattach(NULL);
==== //depot/projects/vimage/src/sys/net/route.c#39 (text+ko) ====
@@ -206,9 +206,9 @@
}
return (0);
}
+#endif
VNET_MOD_DECLARE_STATELESS(RTABLE, rtable, rtable_init, rtable_idetach, NET);
-#endif
static void
route_init(void)
@@ -223,7 +223,7 @@
NULL, NULL, UMA_ALIGN_PTR, 0);
rn_init(); /* initialize all zeroes, all ones, mask table */
-#ifdef VIMAGE
+#ifndef VIMAGE_GLOBALS
vnet_mod_register(&vnet_rtable_modinfo);
#else
rtable_init(NULL);
==== //depot/projects/vimage/src/sys/netinet/accf_http.c#7 (text+ko) ====
@@ -399,7 +399,7 @@
switch (event) {
case MOD_LOAD:
-#ifdef VIMAGE
+#ifndef VIMAGE_GLOBALS
vnet_mod_register(&vnet_accf_http_modinfo);
#else
vnet_accf_http_iattach(NULL);
==== //depot/projects/vimage/src/sys/netinet/if_ether.c#34 (text+ko) ====
@@ -811,7 +811,8 @@
static void
arp_init(void)
{
-#ifdef VIMAGE
+
+#ifndef VIMAGE_GLOBALS
vnet_mod_register(&vnet_arp_modinfo);
#else
arp_iattach(NULL);
==== //depot/projects/vimage/src/sys/netinet/ip_fw2.c#63 (text+ko) ====
@@ -4627,7 +4627,7 @@
}
#endif
-#ifdef VIMAGE
+#ifndef VIMAGE_GLOBALS
vnet_mod_register(&vnet_ipfw_modinfo);
#else
vnet_ipfw_iattach(NULL);
==== //depot/projects/vimage/src/sys/netinet/ip_input.c#46 (text+ko) ====
@@ -223,13 +223,14 @@
static void ip_freef(struct ipqhead *, struct ipq *);
-#ifdef VIMAGE
+#ifndef VIMAGE_GLOBALS
static void vnet_inet_register(void);
VNET_MOD_DECLARE(INET, inet, NULL, NULL, NET, NULL)
static void vnet_inet_register()
{
+
vnet_mod_register(&vnet_inet_modinfo);
}
==== //depot/projects/vimage/src/sys/netinet6/ip6_input.c#45 (text+ko) ====
@@ -161,7 +161,7 @@
static struct mbuf *ip6_pullexthdr(struct mbuf *, size_t, int);
#endif
-#ifdef VIMAGE
+#ifndef VIMAGE_GLOBALS
static void vnet_inet6_register(void);
VNET_MOD_DECLARE(INET6, inet6, NULL, NULL, INET, NULL)
@@ -173,7 +173,7 @@
}
SYSINIT(inet6, SI_SUB_PROTO_BEGIN, SI_ORDER_FIRST, vnet_inet6_register, 0);
-#endif /* VIMAGE */
+#endif
/*
* IP6 initialization: fill in IP6 protocol switch table.
==== //depot/projects/vimage/src/sys/netipsec/ipsec.c#37 (text+ko) ====
@@ -2001,7 +2001,8 @@
static void
ipsec_attach(void)
{
-#ifdef VIMAGE
+
+#ifndef VIMAGE_GLOBALS
vnet_mod_register(&vnet_ipsec_modinfo);
#else
vnet_ipsec_iattach(NULL);
==== //depot/projects/vimage/src/sys/netipsec/xform_ah.c#22 (text+ko) ====
@@ -1236,7 +1236,7 @@
ah_attach(void)
{
-#ifdef VIMAGE
+#ifndef VIMAGE_GLOBALS
vnet_mod_register(&vnet_ah_modinfo);
#else
ah_iattach(NULL);
==== //depot/projects/vimage/src/sys/netipsec/xform_esp.c#21 (text+ko) ====
@@ -1021,7 +1021,8 @@
static void
esp_attach(void)
{
-#ifdef VIMAGE
+
+#ifndef VIMAGE_GLOBALS
vnet_mod_register(&vnet_esp_modinfo);
#else
esp_iattach(NULL);
==== //depot/projects/vimage/src/sys/netipsec/xform_ipcomp.c#17 (text+ko) ====
@@ -615,7 +615,7 @@
ipcomp_attach(void)
{
-#ifdef VIMAGE
+#ifndef VIMAGE_GLOBALS
vnet_mod_register(&vnet_ipcomp_modinfo);
#else
ipcomp_iattach(NULL);
==== //depot/projects/vimage/src/sys/netipsec/xform_ipip.c#22 (text+ko) ====
@@ -731,7 +731,8 @@
static void
ipe4_attach(void)
{
-#ifdef VIMAGE
+
+#ifndef VIMAGE_GLOBALS
vnet_mod_register(&vnet_ipip_modinfo);
#else
ipip_iattach(NULL);
==== //depot/projects/vimage/src/sys/sys/vimage.h#77 (text+ko) ====
@@ -74,6 +74,9 @@
{ #name, offsetof(struct vnet_##mod, _##name), \
sizeof(((struct vnet_##mod *) curthread)->_##name) }
+#define VNET_MOD_NONE_VERSION 2008122301
+
+#ifndef VIMAGE_GLOBALS
#ifdef VIMAGE
#define VNET_MOD_DECLARE(m_name_uc, m_name_lc, m_iattach, m_idetach, \
m_dependson, m_symmap) \
@@ -96,22 +99,33 @@
.vmi_iattach = m_iattach, \
.vmi_idetach = m_idetach \
};
-#else
-#ifdef VIMAGE_GLOBALS
+#else /* !VIMAGE */
#define VNET_MOD_DECLARE(m_name_uc, m_name_lc, m_iattach, m_idetach, \
- m_dependson, m_symmap)
-#define VNET_MOD_DECLARE_STATELESS(m_name_uc, m_name_lc, m_iattach, m_idetach, \
- m_dependson)
-#else
-#define VNET_MOD_DECLARE(m_name_uc, m_name_lc, m_iattach, m_idetach, \
m_dependson, m_symmap) \
static const struct vnet_modinfo vnet_##m_name_lc##_modinfo = { \
+ .vmi_id = VNET_MOD_##m_name_uc, \
+ .vmi_dependson = VNET_MOD_##m_dependson, \
+ .vmi_name = #m_name_lc, \
+ .vmi_iattach = m_iattach, \
+ .vmi_struct_size = \
+ sizeof(struct vnet_##m_name_lc), \
.vmi_symmap = m_symmap \
};
#define VNET_MOD_DECLARE_STATELESS(m_name_uc, m_name_lc, m_iattach, m_idetach, \
+ m_dependson) \
+ static const struct vnet_modinfo vnet_##m_name_lc##_modinfo = { \
+ .vmi_id = VNET_MOD_##m_name_uc, \
+ .vmi_dependson = VNET_MOD_##m_dependson, \
+ .vmi_name = #m_name_lc, \
+ .vmi_iattach = m_iattach \
+};
+#endif
+#else /* VIMAGE_GLOBALS */
+#define VNET_MOD_DECLARE(m_name_uc, m_name_lc, m_iattach, m_idetach, \
+ m_dependson, m_symmap)
+#define VNET_MOD_DECLARE_STATELESS(m_name_uc, m_name_lc, m_iattach, m_idetach, \
m_dependson)
#endif
-#endif
typedef int vnet_attach_fn(const void *);
typedef int vnet_detach_fn(const void *);
More information about the p4-projects
mailing list