Tue Aug 10 18:06:10 2010 UTC ()
* improve diagnostic print
* deal with a tap quirk when it returns 0 bytes


(pooka)
diff -r1.18 -r1.19 src/sys/rump/net/lib/libvirtif/if_virt.c

cvs diff -r1.18 -r1.19 src/sys/rump/net/lib/libvirtif/if_virt.c (expand / switch to context diff)
--- src/sys/rump/net/lib/libvirtif/if_virt.c 2010/04/05 16:35:30 1.18
+++ src/sys/rump/net/lib/libvirtif/if_virt.c 2010/08/10 18:06:10 1.19
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_virt.c,v 1.18 2010/04/05 16:35:30 joerg Exp $	*/
+/*	$NetBSD: if_virt.c,v 1.19 2010/08/10 18:06:10 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.18 2010/04/05 16:35:30 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_virt.c,v 1.19 2010/08/10 18:06:10 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/condvar.h>
@@ -110,7 +110,8 @@
 	snprintf(tapdev, sizeof(tapdev), "/dev/tap%d", num);
 	fd = rumpuser_open(tapdev, O_RDWR, &error);
 	if (fd == -1) {
-		printf("virtif_create: can't open /dev/tap %d\n", error);
+		printf("virtif_create: can't open /dev/tap%d: %d\n",
+		    num, error);
 		return error;
 	}
 	KASSERT(num < 0x100);
@@ -212,7 +213,7 @@
  again:
 		n = rumpuser_read(sc->sc_tapfd, mtod(m, void *), plen, &error);
 		KASSERT(n < ETHER_MAX_LEN_JUMBO);
-		if (n <= 0) {
+		if (__predict_false(n < 0)) {
 			/*
 			 * work around tap bug: /dev/tap is opened in
 			 * non-blocking mode if it previously was
@@ -227,9 +228,15 @@
 				rumpuser_poll(&pfd, 1, INFTIM, &error);
 				goto again;
 			}
+
 			m_freem(m);
 			break;
 		}
+
+		/* tap sometimes returns EOF.  don't sweat it and plow on */
+		if (__predict_false(n == 0))
+			goto again;
+
 		m->m_len = m->m_pkthdr.len = n;
 		m->m_pkthdr.rcvif = ifp;
 		bpf_mtap(ifp, m);