Hi,

I've had to make some changes to sys/rump/dev/lib/libmd/md_component.c, in
order to be able to build a md(4) memory disk using MD_KMEM_FIXED as a
standalone rump component:

--- a/sys/rump/dev/lib/libmd/md_component.c
+++ b/sys/rump/dev/lib/libmd/md_component.c
@@ -34,6 +34,8 @@ __KERNEL_RCSID(0, "$NetBSD: md_component.c,v 1.1 2014/03/17 
11:30:40 pooka Exp $
 #include <sys/mbuf.h>
 #include <sys/stat.h>
 
+#include <dev/md.h>
+
 #include "ioconf.c"
 
 #include "rump_private.h"
@@ -42,6 +44,16 @@ __KERNEL_RCSID(0, "$NetBSD: md_component.c,v 1.1 2014/03/17 
11:30:40 pooka Exp $
 
 extern void mdattach(int); /* XXX */
 
+#ifdef MEMORY_DISK_HOOKS
+void md_stub_hook(int, struct md_conf *);
+void
+md_stub_hook(int unit, struct md_conf *md)
+{
+}
+__weak_alias(md_attach_hook,md_stub_hook);
+__weak_alias(md_open_hook,md_stub_hook);
+#endif
+
 RUMP_COMPONENT(RUMP_COMPONENT_DEV)
 {
         extern const struct bdevsw md_bdevsw;

This is because the only interface to configure an MD_KMEM_FIXED type image
is through the use of md_{attach,open}_hook. The weak symbols are necessary
if the user wishes to link in -lrumpdev_md without a separate component
containing the image, ie. for normal use from userspace.

Further, the build requires -DMEMORY_DISK_HOOKS added to CPPFLAGS , should
this  be added to Makefile.rump, or should it be left to be specified by
the user (e.g. build-rr.sh if used by rumprun in future)?

With the above change, I can now trivially build a standalone rump
component containing an md image:

----
static char rumpmd_image[] = "Hello, World\n";

void
md_attach_hook(int unit, struct md_conf *md)
{
        md->md_addr = (void *)rumpmd_image;
        md->md_size = strlen(rumpmd_image);
        md->md_type = MD_KMEM_FIXED;
        aprint_verbose("rumpmd%d attached\n", unit);
}

void
md_open_hook(int unit, struct md_conf *md)
{

}

RUMP_COMPONENT(RUMP_COMPONENT_DEV)
{

        aprint_verbose("rumpmd init\n");
}
----

There's a comment in sys/dev/md.c about replacing the hooks with passing in
the config via aux to md_attach() so that would be another way to go about
it, not that I understand how to get that aux info to md_attach() in the
first place.

Comments? I'm not 100% sure if this is the cleanest way to do things, but
it's certainly minimal.

-mato

Reply via email to