Module Name:    src
Committed By:   pooka
Date:           Thu Mar 14 01:23:35 UTC 2013

Modified Files:
        src/sys/rump/net/lib/libvirtif: Makefile if_virt.c

Log Message:
Guess the RUMPCOMP_USER stuff wasn't ready to be in the NetBSD tree yet,
so revert previous commits to fix build.  I'll look at rereverting when
toolchain/47644 is fixed and clean buildtests are again possible.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/rump/net/lib/libvirtif/Makefile
cvs rdiff -u -r1.28 -r1.29 src/sys/rump/net/lib/libvirtif/if_virt.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libvirtif/Makefile
diff -u src/sys/rump/net/lib/libvirtif/Makefile:1.4 src/sys/rump/net/lib/libvirtif/Makefile:1.5
--- src/sys/rump/net/lib/libvirtif/Makefile:1.4	Wed Mar 13 21:13:45 2013
+++ src/sys/rump/net/lib/libvirtif/Makefile	Thu Mar 14 01:23:34 2013
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.4 2013/03/13 21:13:45 pooka Exp $
+#	$NetBSD: Makefile,v 1.5 2013/03/14 01:23:34 pooka Exp $
 #
 
 LIB=	rumpnet_virtif
@@ -6,9 +6,7 @@ LIB=	rumpnet_virtif
 SRCS=	if_virt.c
 SRCS+=	component.c
 
-CPPFLAGS+=	-I${.CURDIR}/../../../librump/rumpkern -I${.CURDIR}
-
-RUMPCOMP_USER=	#defined
+CPPFLAGS+=	-I${.CURDIR}/../../../librump/rumpkern
 
 .include <bsd.lib.mk>
 .include <bsd.klinks.mk>

Index: src/sys/rump/net/lib/libvirtif/if_virt.c
diff -u src/sys/rump/net/lib/libvirtif/if_virt.c:1.28 src/sys/rump/net/lib/libvirtif/if_virt.c:1.29
--- src/sys/rump/net/lib/libvirtif/if_virt.c:1.28	Wed Mar 13 21:13:45 2013
+++ src/sys/rump/net/lib/libvirtif/if_virt.c	Thu Mar 14 01:23:34 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_virt.c,v 1.28 2013/03/13 21:13:45 pooka Exp $	*/
+/*	$NetBSD: if_virt.c,v 1.29 2013/03/14 01:23:34 pooka Exp $	*/
 
 /*
  * Copyright (c) 2008 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_virt.c,v 1.28 2013/03/13 21:13:45 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_virt.c,v 1.29 2013/03/14 01:23:34 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/condvar.h>
@@ -49,12 +49,11 @@ __KERNEL_RCSID(0, "$NetBSD: if_virt.c,v 
 #include <netinet/in_var.h>
 
 #include <rump/rump.h>
+#include <rump/rumpuser.h>
 
 #include "rump_private.h"
 #include "rump_net_private.h"
 
-#include "rumpcomp_user.h"
-
 /*
  * Virtual interface for userspace purposes.  Uses tap(4) to
  * interface with the kernel and just simply shovels data
@@ -70,7 +69,7 @@ static void	virtif_stop(struct ifnet *, 
 
 struct virtif_sc {
 	struct ethercom sc_ec;
-	struct virtif_user *sc_viu;
+	int sc_tapfd;
 	bool sc_dying;
 	struct lwp *sc_l_snd, *sc_l_rcv;
 	kmutex_t sc_mtx;
@@ -89,23 +88,27 @@ int
 rump_virtif_create(int num)
 {
 	struct virtif_sc *sc;
-	struct virtif_user *viu;
 	struct ifnet *ifp;
 	uint8_t enaddr[ETHER_ADDR_LEN] = { 0xb2, 0x0a, 0x00, 0x0b, 0x0e, 0x01 };
-	int error = 0;
+	char tapdev[16];
+	int fd, error = 0;
 
 	if (num >= 0x100)
 		return E2BIG;
 
-	if ((viu = rumpcomp_virtif_create(num)) == NULL)
-		return ENXIO;
-
+	snprintf(tapdev, sizeof(tapdev), "/dev/tap%d", num);
+	fd = rumpuser_open(tapdev, RUMPUSER_OPEN_RDWR, &error);
+	if (fd == -1) {
+		printf("virtif_create: can't open /dev/tap%d: %d\n",
+		    num, error);
+		return error;
+	}
 	enaddr[2] = cprng_fast32() & 0xff;
 	enaddr[5] = num;
 
 	sc = kmem_zalloc(sizeof(*sc), KM_SLEEP);
 	sc->sc_dying = false;
-	sc->sc_viu = viu;
+	sc->sc_tapfd = fd;
 
 	mutex_init(&sc->sc_mtx, MUTEX_DEFAULT, IPL_NONE);
 	cv_init(&sc->sc_cv, "virtsnd");
@@ -165,8 +168,6 @@ virtif_unclone(struct ifnet *ifp)
 	cv_broadcast(&sc->sc_cv);
 	mutex_exit(&sc->sc_mtx);
 
-	rumpcomp_virtif_dying(sc->sc_viu);
-
 	virtif_stop(ifp, 1);
 	if_down(ifp);
 
@@ -179,7 +180,7 @@ virtif_unclone(struct ifnet *ifp)
 		sc->sc_l_rcv = NULL;
 	}
 
-	rumpcomp_virtif_destroy(sc->sc_viu);
+	rumpuser_close(sc->sc_tapfd, NULL);
 
 	mutex_destroy(&sc->sc_mtx);
 	cv_destroy(&sc->sc_cv);
@@ -219,6 +220,7 @@ virtif_ioctl(struct ifnet *ifp, u_long c
 	return rv;
 }
 
+/* just send everything in-context */
 static void
 virtif_start(struct ifnet *ifp)
 {
@@ -250,21 +252,35 @@ virtif_receiver(void *arg)
 	struct virtif_sc *sc = ifp->if_softc;
 	struct mbuf *m;
 	size_t plen = ETHER_MAX_LEN_JUMBO+1;
+	struct pollfd pfd;
 	ssize_t n;
+	int error, rv;
+
+	pfd.fd = sc->sc_tapfd;
+	pfd.events = POLLIN;
 
 	for (;;) {
 		m = m_gethdr(M_WAIT, MT_DATA);
 		MEXTMALLOC(m, plen, M_WAIT);
 
  again:
+		/* poll, but periodically check if we should die */
+		rv = rumpuser_poll(&pfd, 1, POLLTIMO_MS, &error);
 		if (sc->sc_dying) {
 			m_freem(m);
 			break;
 		}
-		
-		n = rumpcomp_virtif_recv(sc->sc_viu, mtod(m, void *), plen);
-		if (n < 0) {
-			printf("%s: read hypercall failed. host if down?\n",
+		if (rv == 0)
+			goto again;
+
+		n = rumpuser_read(sc->sc_tapfd, mtod(m, void *), plen, &error);
+		KASSERT(n < ETHER_MAX_LEN_JUMBO);
+		if (__predict_false(n < 0)) {
+			if (n == -1 && error == EAGAIN) {
+				goto again;
+			}
+
+			printf("%s: read from /dev/tap failed. host is down?\n",
 			    ifp->if_xname);
 			mutex_enter(&sc->sc_mtx);
 			/* could check if need go, done soon anyway */
@@ -298,8 +314,8 @@ virtif_sender(void *arg)
 	struct ifnet *ifp = arg;
 	struct virtif_sc *sc = ifp->if_softc;
 	struct mbuf *m, *m0;
-	struct iovec io[LB_SH];
-	int i;
+	struct rumpuser_iovec io[LB_SH];
+	int i, error;
 
 	mutex_enter(&sc->sc_mtx);
 	KERNEL_LOCK(1, NULL);
@@ -325,9 +341,11 @@ virtif_sender(void *arg)
 		if (i == LB_SH)
 			panic("lazy bum");
 		bpf_mtap(ifp, m0);
+		KERNEL_UNLOCK_LAST(curlwp);
 
-		rumpcomp_virtif_send(sc->sc_viu, io, i);
+		rumpuser_writev(sc->sc_tapfd, io, i, &error);
 
+		KERNEL_LOCK(1, NULL);
 		m_freem(m0);
 		mutex_enter(&sc->sc_mtx);
 	}

Reply via email to