Determine the interface name and the names of exported symbols based

on VIRTIF_BASE.  This allows using various different packet-shoveling
backends in the same rump kernel.
This commit is contained in:
pooka 2013-07-04 11:46:51 +00:00
parent c664b621d8
commit be1e0a384e
6 changed files with 56 additions and 35 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.6 2013/03/15 11:30:23 pooka Exp $
# $NetBSD: Makefile,v 1.7 2013/07/04 11:46:51 pooka Exp $
#
LIB= rumpnet_virtif
@ -7,8 +7,10 @@ SRCS= if_virt.c
SRCS+= component.c
CPPFLAGS+= -I${.CURDIR}/../../../librump/rumpkern -I${.CURDIR}
CPPFLAGS+= -DVIRTIF_BASE=virt
RUMPCOMP_USER= #defined
RUMPCOMP_USER_CPPFLAGS+= -DVIRTIF_BASE=virt
.include <bsd.lib.mk>
.include <bsd.klinks.mk>

View File

@ -1,4 +1,4 @@
/* $NetBSD: component.c,v 1.3 2010/10/19 19:19:41 pooka Exp $ */
/* $NetBSD: component.c,v 1.4 2013/07/04 11:46:51 pooka Exp $ */
/*
* Copyright (c) 2009 Antti Kantee. All Rights Reserved.
@ -28,7 +28,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: component.c,v 1.3 2010/10/19 19:19:41 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: component.c,v 1.4 2013/07/04 11:46:51 pooka Exp $");
#include <sys/param.h>
#include <sys/domain.h>
@ -38,10 +38,11 @@ __KERNEL_RCSID(0, "$NetBSD: component.c,v 1.3 2010/10/19 19:19:41 pooka Exp $");
#include "rump_private.h"
#include "rump_net_private.h"
#include "if_virt.h"
RUMP_COMPONENT(RUMP_COMPONENT_NET_IF)
{
extern struct if_clone virtif_cloner; /* XXX */
extern struct if_clone VIF_CLONER; /* XXX */
if_clone_attach(&virtif_cloner);
if_clone_attach(&VIF_CLONER);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_virt.c,v 1.35 2013/07/03 20:17:07 pooka Exp $ */
/* $NetBSD: if_virt.c,v 1.36 2013/07/04 11:46:51 pooka Exp $ */
/*
* Copyright (c) 2008, 2013 Antti Kantee. All Rights Reserved.
@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_virt.c,v 1.35 2013/07/03 20:17:07 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_virt.c,v 1.36 2013/07/04 11:46:51 pooka Exp $");
#include <sys/param.h>
#include <sys/condvar.h>
@ -53,6 +53,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_virt.c,v 1.35 2013/07/03 20:17:07 pooka Exp $");
#include "rump_private.h"
#include "rump_net_private.h"
#include "if_virt.h"
#include "rumpcomp_user.h"
/*
@ -61,10 +62,6 @@ __KERNEL_RCSID(0, "$NetBSD: if_virt.c,v 1.35 2013/07/03 20:17:07 pooka Exp $");
* hypercall implementation.
*/
#ifndef VIRTIF_BASE
#define VIRTIF_BASE "virt"
#endif
static int virtif_init(struct ifnet *);
static int virtif_ioctl(struct ifnet *, u_long, void *);
static void virtif_start(struct ifnet *);
@ -84,8 +81,8 @@ static void virtif_sender(void *);
static int virtif_clone(struct if_clone *, int);
static int virtif_unclone(struct ifnet *);
struct if_clone virtif_cloner =
IF_CLONE_INITIALIZER(VIRTIF_BASE, virtif_clone, virtif_unclone);
struct if_clone VIF_CLONER =
IF_CLONE_INITIALIZER(VIF_NAME, virtif_clone, virtif_unclone);
static int
virtif_clone(struct if_clone *ifc, int num)
@ -99,7 +96,7 @@ virtif_clone(struct if_clone *ifc, int num)
if (num >= 0x100)
return E2BIG;
if ((error = rumpcomp_virtif_create(num, &viu)) != 0)
if ((error = VIFHYPER_CREATE(num, &viu)) != 0)
return error;
enaddr[2] = cprng_fast32() & 0xff;
@ -110,20 +107,19 @@ virtif_clone(struct if_clone *ifc, int num)
sc->sc_viu = viu;
mutex_init(&sc->sc_mtx, MUTEX_DEFAULT, IPL_NONE);
cv_init(&sc->sc_cv, VIRTIF_BASE "snd");
cv_init(&sc->sc_cv, VIF_NAME "snd");
ifp = &sc->sc_ec.ec_if;
sprintf(ifp->if_xname, "%s%d", VIRTIF_BASE, num);
sprintf(ifp->if_xname, "%s%d", VIF_NAME, num);
ifp->if_softc = sc;
if (rump_threads) {
if ((error = kthread_create(PRI_NONE, KTHREAD_MUSTJOIN, NULL,
virtif_receiver, ifp, &sc->sc_l_rcv,
VIRTIF_BASE "ifr")) != 0)
virtif_receiver, ifp, &sc->sc_l_rcv, VIF_NAME "ifr")) != 0)
goto out;
if ((error = kthread_create(PRI_NONE,
KTHREAD_MUSTJOIN | KTHREAD_MPSAFE, NULL,
virtif_sender, ifp, &sc->sc_l_snd, VIRTIF_BASE "ifs")) != 0)
virtif_sender, ifp, &sc->sc_l_snd, VIF_NAME "ifs")) != 0)
goto out;
} else {
printf("WARNING: threads not enabled, receive NOT working\n");
@ -161,7 +157,7 @@ virtif_unclone(struct ifnet *ifp)
cv_broadcast(&sc->sc_cv);
mutex_exit(&sc->sc_mtx);
rumpcomp_virtif_dying(sc->sc_viu);
VIFHYPER_DYING(sc->sc_viu);
virtif_stop(ifp, 1);
if_down(ifp);
@ -175,7 +171,7 @@ virtif_unclone(struct ifnet *ifp)
sc->sc_l_rcv = NULL;
}
rumpcomp_virtif_destroy(sc->sc_viu);
VIFHYPER_DESTROY(sc->sc_viu);
mutex_destroy(&sc->sc_mtx);
cv_destroy(&sc->sc_cv);
@ -259,7 +255,7 @@ virtif_receiver(void *arg)
break;
}
error = rumpcomp_virtif_recv(sc->sc_viu,
error = VIFHYPER_RECV(sc->sc_viu,
mtod(m, void *), plen, &n);
if (error) {
printf("%s: read hypercall failed %d. host if down?\n",
@ -324,7 +320,7 @@ virtif_sender(void *arg)
panic("lazy bum");
bpf_mtap(ifp, m0);
rumpcomp_virtif_send(sc->sc_viu, io, i);
VIFHYPER_SEND(sc->sc_viu, io, i);
m_freem(m0);
mutex_enter(&sc->sc_mtx);

View File

@ -0,0 +1,21 @@
/* $NetBSD: if_virt.h,v 1.1 2013/07/04 11:46:51 pooka Exp $ */
#ifndef VIRTIF_BASE
#error Define VIRTIF_BASE
#endif
#define VIF_STRING(x) #x
#define VIF_STRINGIFY(x) VIF_STRING(x)
#define VIF_CONCAT(x,y) x##y
#define VIF_CONCAT3(x,y,z) x##y##z
#define VIF_BASENAME(x,y) VIF_CONCAT(x,y)
#define VIF_BASENAME3(x,y,z) VIF_CONCAT3(x,y,z)
#define VIF_CLONER VIF_BASENAME(VIRTIF_BASE,_cloner)
#define VIF_NAME VIF_STRINGIFY(VIRTIF_BASE)
#define VIFHYPER_CREATE VIF_BASENAME3(rumpcomp_,VIRTIF_BASE,_create)
#define VIFHYPER_DYING VIF_BASENAME3(rumpcomp_,VIRTIF_BASE,_dying)
#define VIFHYPER_DESTROY VIF_BASENAME3(rumpcomp_,VIRTIF_BASE,_destroy)
#define VIFHYPER_SEND VIF_BASENAME3(rumpcomp_,VIRTIF_BASE,_send)
#define VIFHYPER_RECV VIF_BASENAME3(rumpcomp_,VIRTIF_BASE,_recv)

View File

@ -1,4 +1,4 @@
/* $NetBSD: rumpcomp_user.c,v 1.7 2013/07/04 09:48:01 pooka Exp $ */
/* $NetBSD: rumpcomp_user.c,v 1.8 2013/07/04 11:46:51 pooka Exp $ */
/*
* Copyright (c) 2013 Antti Kantee. All Rights Reserved.
@ -45,6 +45,7 @@
#include <rump/rumpuser_component.h>
#include "if_virt.h"
#include "rumpcomp_user.h"
struct virtif_user {
@ -96,7 +97,7 @@ opentapdev(int devnum)
}
int
rumpcomp_virtif_create(int devnum, struct virtif_user **viup)
VIFHYPER_CREATE(int devnum, struct virtif_user **viup)
{
struct virtif_user *viu = NULL;
void *cookie;
@ -127,7 +128,7 @@ rumpcomp_virtif_create(int devnum, struct virtif_user **viup)
}
void
rumpcomp_virtif_send(struct virtif_user *viu,
VIFHYPER_SEND(struct virtif_user *viu,
struct iovec *iov, size_t iovlen)
{
void *cookie = rumpuser_component_unschedule();
@ -141,7 +142,7 @@ rumpcomp_virtif_send(struct virtif_user *viu,
/* how often to check for interface going south */
#define POLLTIMO_MS 10
int
rumpcomp_virtif_recv(struct virtif_user *viu,
VIFHYPER_RECV(struct virtif_user *viu,
void *data, size_t dlen, size_t *rcv)
{
void *cookie = rumpuser_component_unschedule();
@ -186,7 +187,7 @@ rumpcomp_virtif_recv(struct virtif_user *viu,
#undef POLLTIMO_MS
void
rumpcomp_virtif_dying(struct virtif_user *viu)
VIFHYPER_DYING(struct virtif_user *viu)
{
/* no locking necessary. it'll be seen eventually */
@ -194,7 +195,7 @@ rumpcomp_virtif_dying(struct virtif_user *viu)
}
void
rumpcomp_virtif_destroy(struct virtif_user *viu)
VIFHYPER_DESTROY(struct virtif_user *viu)
{
void *cookie = rumpuser_component_unschedule();

View File

@ -1,4 +1,4 @@
/* $NetBSD: rumpcomp_user.h,v 1.3 2013/04/30 00:03:54 pooka Exp $ */
/* $NetBSD: rumpcomp_user.h,v 1.4 2013/07/04 11:46:51 pooka Exp $ */
/*
* Copyright (c) 2013 Antti Kantee. All Rights Reserved.
@ -27,9 +27,9 @@
struct virtif_user;
int rumpcomp_virtif_create(int, struct virtif_user **);
void rumpcomp_virtif_dying(struct virtif_user *);
void rumpcomp_virtif_destroy(struct virtif_user *);
int VIFHYPER_CREATE(int, struct virtif_user **);
void VIFHYPER_DYING(struct virtif_user *);
void VIFHYPER_DESTROY(struct virtif_user *);
void rumpcomp_virtif_send(struct virtif_user *, struct iovec *, size_t);
int rumpcomp_virtif_recv(struct virtif_user *, void *, size_t, size_t *);
void VIFHYPER_SEND(struct virtif_user *, struct iovec *, size_t);
int VIFHYPER_RECV(struct virtif_user *, void *, size_t, size_t *);