Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/rump/net/lib/libvirtif Guess the RUMPCOMP_USER stuff was...



details:   https://anonhg.NetBSD.org/src/rev/2c4f90a3255d
branches:  trunk
changeset: 785443:2c4f90a3255d
user:      pooka <pooka%NetBSD.org@localhost>
date:      Thu Mar 14 01:23:34 2013 +0000

description:
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.

diffstat:

 sys/rump/net/lib/libvirtif/Makefile  |   6 +--
 sys/rump/net/lib/libvirtif/if_virt.c |  60 +++++++++++++++++++++++------------
 2 files changed, 41 insertions(+), 25 deletions(-)

diffs (185 lines):

diff -r ec6f70633cb9 -r 2c4f90a3255d sys/rump/net/lib/libvirtif/Makefile
--- a/sys/rump/net/lib/libvirtif/Makefile       Wed Mar 13 21:35:18 2013 +0000
+++ b/sys/rump/net/lib/libvirtif/Makefile       Thu Mar 14 01:23:34 2013 +0000
@@ -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 @@
 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>
diff -r ec6f70633cb9 -r 2c4f90a3255d sys/rump/net/lib/libvirtif/if_virt.c
--- a/sys/rump/net/lib/libvirtif/if_virt.c      Wed Mar 13 21:35:18 2013 +0000
+++ b/sys/rump/net/lib/libvirtif/if_virt.c      Thu Mar 14 01:23:34 2013 +0000
@@ -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 @@
 #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 @@
 
 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 @@
 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 @@
        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 @@
                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 @@
        return rv;
 }
 
+/* just send everything in-context */
 static void
 virtif_start(struct ifnet *ifp)
 {
@@ -250,21 +252,35 @@
        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 @@
        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 @@
                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);
        }



Home | Main Index | Thread Index | Old Index