PERFORCE change 144794 for review
Julian Elischer
julian at FreeBSD.org
Sun Jul 6 16:47:54 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=144794
Change 144794 by julian at 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 <dir/vfoo.h>
[...]
+#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:
More information about the p4-projects
mailing list