Date: Mon, 11 Dec 2006 12:19:52 GMT From: Marko Zec <zec@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 111450 for review Message-ID: <200612111219.kBBCJqUp048837@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=111450 Change 111450 by zec@zec_tca51 on 2006/12/11 12:19:51 At vnet creation time allow vnet modules to be initialized either before or after initializing protocol domains. Modules that have have declared "attach" methods must have their flags set either to VNET_MFLAG_ORDER_1ST or VNET_MFLAG_ORDER_2ND. In particular, this change ensures that the "net" module is attached, i.e. has its memory allocated, before protocol domains are initialized, while rtable_init() and loif attach are called afterwards. This seems to be the most tricky part of the stack virtualization process to be done right, and needs much more thought. Affected files ... .. //depot/projects/vimage/src/sys/kern/kern_vimage.c#8 edit .. //depot/projects/vimage/src/sys/net/if.c#7 edit .. //depot/projects/vimage/src/sys/net/if_loop.c#6 edit .. //depot/projects/vimage/src/sys/net/route.c#3 edit .. //depot/projects/vimage/src/sys/sys/vimage.h#7 edit Differences ... ==== //depot/projects/vimage/src/sys/kern/kern_vimage.c#8 (text+ko) ==== @@ -80,7 +80,7 @@ static struct vnet_modlink vnet_modules[VNET_MOD_MAX]; static TAILQ_HEAD(, vnet_modlink) vnet_modlink_head; -int vnet_mod_register(modinfo) +void vnet_mod_register(modinfo) struct vnet_modinfo *modinfo; { /* @@ -89,11 +89,8 @@ * an ID at registration time. */ - if (modinfo->id < 0 || modinfo->id >= VNET_MOD_MAX) - return EFAULT; - - if (vnet_modules[modinfo->id].modinfo != NULL) - return EEXIST; + VNET_ASSERT(modinfo->id > 0 || modinfo->id < VNET_MOD_MAX) + VNET_ASSERT(vnet_modules[modinfo->id].modinfo == NULL) vnet_modules[modinfo->id].modinfo = modinfo; TAILQ_INSERT_TAIL(&vnet_modlink_head, @@ -104,30 +101,20 @@ modinfo->i_attach(); VNETB_ITERLOOP_END(); } - - return 0; } -int vnet_mod_deregister(modinfo) +void vnet_mod_deregister(modinfo) struct vnet_modinfo *modinfo; { - if (modinfo->id < 0 || modinfo->id >= VNET_MOD_MAX) - return EFAULT; + VNET_ASSERT(vnet_modules[modinfo->id].modinfo == modinfo) - if (vnet_modules[modinfo->id].modinfo != modinfo) - return EFAULT; - if (modinfo->i_detach) { VNETB_ITERLOOP_BEGIN(); modinfo->i_detach(); VNETB_ITERLOOP_END(); } - return 0; - vnet_modules[modinfo->id].modinfo = NULL; - - return 0; } struct vimage *vnetb2vimage(vnetb) @@ -454,31 +441,45 @@ LIST_INSERT_HEAD(&vcpu_head, vcpu, vcpu_le); CURVNETB_SET(vnetb); + /* + * Initialize modules with ORDER_1ST flag set + */ + struct vnet_modlink *modlnk_i; + TAILQ_FOREACH(modlnk_i, &vnet_modlink_head, mod_le) + if (modlnk_i->modinfo->i_attach != NULL && + modlnk_i->modinfo->flags & VNET_MFLAG_ORDER_1ST) { + VNET_ASSERT(!(modlnk_i->modinfo->flags & \ + VNET_MFLAG_ORDER_2ND)); + modlnk_i->modinfo->i_attach(); + } + + /* + * Initialize domains. + */ for (dp = domains; dp; dp = dp->dom_next) { printf("initializing domain: %s\n", dp->dom_name); struct protosw *pr; - for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++){ + for (pr = dp->dom_protosw; + pr < dp->dom_protoswNPROTOSW; pr++) { if (pr->pr_usrreqs == 0) panic("domaininit: %ssw[%d] has no usrreqs!", - dp->dom_name, - (int)(pr - dp->dom_protosw)); - if (pr->pr_init) { - printf(" proto %d\n", pr->pr_protocol); + dp->dom_name, + (int)(pr - dp->dom_protosw)); + if (pr->pr_init) pr->pr_init(); - } } } - struct vnet_modlink *modlnk_i; + /* + * Initialize modules with ORDER_2ND flag set + */ TAILQ_FOREACH(modlnk_i, &vnet_modlink_head, mod_le) - if (modlnk_i->modinfo->i_attach != NULL) { - printf(" module %s\n", - modlnk_i->modinfo->name); + if (modlnk_i->modinfo->i_attach != NULL && + modlnk_i->modinfo->flags & VNET_MFLAG_ORDER_2ND) { + VNET_ASSERT(!(modlnk_i->modinfo->flags & \ + VNET_MFLAG_ORDER_1ST)); modlnk_i->modinfo->i_attach(); } -#if 0 - rtable_init((void **)vnetb->rt_tables); -#endif CURVNETB_RESTORE(); printf("done.\n"); ==== //depot/projects/vimage/src/sys/net/if.c#7 (text+ko) ==== @@ -163,6 +163,7 @@ static struct vnet_modinfo vnet_net_modinfo = { .id = VNET_MOD_NET, + .flags = VNET_MFLAG_ORDER_1ST, .name = "net", .symmap = vnet_net_symmap, .i_attach = vnet_net_iattach, @@ -340,7 +341,6 @@ struct vnet_net *vnet_net; if (curvnetb == &vnetb_0) { - vnet_mod_register(&vnet_net_modinfo); vnet_net = &vnet_net_0; } else { vnet_net = malloc(sizeof(struct vnet_net), ==== //depot/projects/vimage/src/sys/net/if_loop.c#6 (text+ko) ==== @@ -182,6 +182,7 @@ #ifdef VIMAGE static struct vnet_modinfo vnet_loif_modinfo = { .id = VNET_MOD_LOIF, + .flags = VNET_MFLAG_ORDER_2ND, .name = "loif", .symmap = NULL, .i_attach = vnet_loif_iattach, ==== //depot/projects/vimage/src/sys/net/route.c#3 (text+ko) ==== @@ -80,6 +80,7 @@ #ifdef VIMAGE static struct vnet_modinfo vnet_rtable_modinfo = { .id = VNET_MOD_RTABLE, + .flags = VNET_MFLAG_ORDER_2ND, .name = "rtable", .i_attach = rtable_init }; ==== //depot/projects/vimage/src/sys/sys/vimage.h#7 (text+ko) ==== @@ -99,8 +99,12 @@ typedef int vnet_start_t(void); typedef int vnet_stop_t(void); +#define VNET_MFLAG_ORDER_1ST 0x0001 +#define VNET_MFLAG_ORDER_2ND 0x0002 + struct vnet_modinfo { int id; + int flags; char *name; struct vnet_symmap *symmap; /* Per-instance method hooks */ @@ -182,8 +186,8 @@ #endif /* !VIMAGE */ #ifdef VIMAGE -int vnet_mod_register(struct vnet_modinfo *); -int vnet_mod_deregister(struct vnet_modinfo *); +void vnet_mod_register(struct vnet_modinfo *); +void vnet_mod_deregister(struct vnet_modinfo *); void printcpuinfo(struct vprocg *); struct vimage *vi_alloc(char *, int, int, int);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200612111219.kBBCJqUp048837>