From owner-p4-projects@FreeBSD.ORG Sun Jul 6 16:47:53 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id A63D41065679; Sun, 6 Jul 2008 16:47:53 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6A3961065673 for ; Sun, 6 Jul 2008 16:47:53 +0000 (UTC) (envelope-from julian@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 562BF8FC1F for ; Sun, 6 Jul 2008 16:47:53 +0000 (UTC) (envelope-from julian@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m66GlrpP056735 for ; Sun, 6 Jul 2008 16:47:53 GMT (envelope-from julian@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.2/8.14.1/Submit) id m66GlrM5056733 for perforce@freebsd.org; Sun, 6 Jul 2008 16:47:53 GMT (envelope-from julian@freebsd.org) Date: Sun, 6 Jul 2008 16:47:53 GMT Message-Id: <200807061647.m66GlrM5056733@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to julian@freebsd.org using -f From: Julian Elischer To: Perforce Change Reviews Cc: Subject: PERFORCE change 144794 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Jul 2008 16:47:54 -0000 http://perforce.freebsd.org/chv.cgi?CH=144794 Change 144794 by julian@julian_trafmon1 on 2008/07/06 16:46:59 A bit more stuff added.. e.g symmap stuff. saving before taking kids on picnic. Affected files ... .. //depot/projects/vimage/porting_to_vimage.txt#3 edit Differences ... ==== //depot/projects/vimage/porting_to_vimage.txt#3 (text+ko) ==== @@ -112,7 +112,38 @@ could rely on the current thread being a good reference for the correct virtual machine. -As an example of virtualising a dummy module named the FOO module +When a new module is defined for virtualisation. The following +structure defining macro is used to define it to the framework. + + +#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_idetach = m_idetach, \ + .vmi_struct_size = \ + sizeof(struct vnet_##m_name_lc), \ + .vmi_symmap = m_symmap \ +The ID we allocated in the temporary first step in "Details" is +the first entry here. Eventually this should be automatically done +by module name. The DEPENDSON field tells us the order that modules +should be initialised in a new virtual machine. This may later need +to be changes to a list of text module names for dynamic calculation. +The rest of the fields are self explanatory.. +With the exception of the symmap entry. +The symmap allows us to intercept calls by libkvm to the +linker when it is looking up symbols and to redirect it +dynamically. this allows for example "netstat -r" to find the +routing tables for THIS virtual machine. (cute eh?) +(of course that won't work for core dumps). (XXX *needs thought *) + + + + +As example of virtualising a dummy module named the FOO module the following code might be added to a special vfoo.h or at least to the exisitng foo.h file: @@ -129,7 +160,7 @@ #define VNET_FOO(sym) VSYM(vnet_foo, sym) -#ifdef VIMAGE +#if (defined(VIMAGE) || defined(FUTURE)) struct vnet_foo { int _foo_counter struct foo_bar _foo_barx; @@ -158,16 +189,59 @@ #include [...] +#ifndef VIMAGE + /* initially the globals would have been here, + * and for now we will leave them here when not using VIMAGE. + * In the future we will instead have a static version of the structure. + */ +# if defined(FUTURE) + struct vnet_foo vnet_foo_globals; +# else /* !FUTURE */ + int foo_counter = 0; + struct foo_bar foo_barx = {}; +# endif /* !FUTURE */ +#endif /* !VIMAGE */ + +[...] + +#if (defined(VIMAGE) || defined(FUTURE)) static vnet_attach_fn vnet_foo_iattach; -#ifdef VIMAGE static vnet_detach_fn vnet_foo_idetach; -#endif /* VIMAGE */ +#endif +#ifdef VIMAGE +/* If we have symbols we need to divert for libkvm + * then put them in here. We may net need to do anything if + * the symbols are not used by libkvm. + */ +static struct vnet_symmap vnet_net_symmap[] = { + VNET_SYMMAP(foo, foo_counter), + VNET_SYMMAP(foo, foo_barx), + VNET_SYMMAP_END +}; +/* + * Declare our module and state that we want to be done after the + * loopback interface is initialised for the virtual machine. + */ VNET_MOD_DECLARE(FOO, foo, vnet_foo_iattach, - vnet_foo_idetach, LOIF, NULL) + vnet_foo_idetach, LOIF, vnet_foo_symmap) +#endif /* VIMAGE */ [...] +/* a pre-exisiting 'foo' function that will be converted. */ +void +foo_work(void) +{ + INIT_VNET_FOO(curvnet); /* Add this at the front */ + + V_foo_counter++; /* add "V_" to teh front */ + [...] + V_foo_barx.mumble = V_foo_counter; /* and here too */ + [...] +} + +#if (defined(VIMAGE) || defined(FUTURE)) static int vnet_foo_iattach(const void *unused) { INIT_VNET_FOO(curvnet); @@ -176,6 +250,7 @@ bzero (&V_foo_barx, sizeof (V_foo_barx)); return 0; } +#endif #ifdef VIMAGE static int vnet_foo_idetach(const void *unused) @@ -204,9 +279,13 @@ #ifdef VIMAGE /* This will do the work for each vortual machine. */ vnet_mod_register(&vnet_foo_modinfo); -#else +#else /* !VIMAGE */ +#ifdef FUTURE /* otherwise do the initialisation directly */ vnet_foo_iattach(NULL); +#else /* !FUTURE */ +/* otherwise the intialisation is done statically */ +#endif /* !FUTURE */ #endif /* !VIMAGE */ break; case MOD_UNLOAD: