Received: from [140.186.70.92] (port=48955 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P4L40-0002ji-Ca for qemu-devel@nongnu.org; Fri, 08 Oct 2010 18:05:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P4L3z-0005z0-4z for qemu-devel@nongnu.org; Fri, 08 Oct 2010 18:05:16 -0400 Received: from e3.ny.us.ibm.com ([32.97.182.143]:45742) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P4L3z-0005xQ-2m for qemu-devel@nongnu.org; Fri, 08 Oct 2010 18:05:15 -0400 Received: from d01relay02.pok.ibm.com (d01relay02.pok.ibm.com [9.56.227.234]) by e3.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id o98LmWOG029841 for ; Fri, 8 Oct 2010 17:48:32 -0400 Received: from d03av05.boulder.ibm.com (d03av05.boulder.ibm.com [9.17.195.85]) by d01relay02.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o98M51Zo457058 for ; Fri, 8 Oct 2010 18:05:01 -0400 Received: from d03av05.boulder.ibm.com (loopback [127.0.0.1]) by d03av05.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o98M50Rq029728 for ; Fri, 8 Oct 2010 16:05:00 -0600 From: Anthony Liguori Date: Fri, 8 Oct 2010 17:04:56 -0500 Message-Id: <1286575496-10314-1-git-send-email-aliguori@us.ibm.com> Subject: [Qemu-devel] [PATCH] net: provide a friendly message when a user passes a bad -net tap, fd=X List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori A lot of people copy libvirt's command line from ps -ef and then wonder why the VM isn't working correctly. Let's be kind and tell them what they should do instead. Without this patch, if you run with an invalid -net tap,fd=X, the guest still runs and we poll 100% on a bad file descriptor. With this patch, you get: qemu: -net tap,fd=42: invalid fd= for tap network device. If you're copying from libvirt, use `virsh dom2xml-to-native' instead qemu: -net tap,fd=42: Device 'tap' could not be initialized Signed-off-by: Anthony Liguori diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c index 1d83400..5f9f749 100644 --- a/hw/usb-uhci.c +++ b/hw/usb-uhci.c @@ -64,7 +64,7 @@ #define UHCI_PORT_CSC (1 << 1) #define UHCI_PORT_CCS (1 << 0) -#define FRAME_TIMER_FREQ 1000 +#define FRAME_TIMER_FREQ 500 #define FRAME_MAX_LOOPS 100 @@ -1054,7 +1054,7 @@ static void uhci_frame_timer(void *opaque) UHCIState *s = opaque; /* prepare the timer for the next frame */ - s->expire_time += (get_ticks_per_sec() / FRAME_TIMER_FREQ); + s->expire_time = qemu_get_clock(vm_clock) + (get_ticks_per_sec() / FRAME_TIMER_FREQ); if (!(s->cmd & UHCI_CMD_RS)) { /* Full stop */ diff --git a/net/tap.c b/net/tap.c index 0147dab..45b1fb6 100644 --- a/net/tap.c +++ b/net/tap.c @@ -405,6 +405,8 @@ int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan int fd, vnet_hdr = 0; if (qemu_opt_get(opts, "fd")) { + int flags; + if (qemu_opt_get(opts, "ifname") || qemu_opt_get(opts, "script") || qemu_opt_get(opts, "downscript") || @@ -418,6 +420,11 @@ int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan return -1; } + if (fcntl(fd, F_GETFL, &flags) == -1) { + error_report("invalid fd= for tap network device. If you're copying from libvirt, use `virsh dom2xml-to-native' instead"); + return -1; + } + fcntl(fd, F_SETFL, O_NONBLOCK); vnet_hdr = tap_probe_vnet_hdr(fd); -- 1.7.0.4