Received: from [140.186.70.92] (port=36866 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P4MVy-0001Db-NS for qemu-devel@nongnu.org; Fri, 08 Oct 2010 19:38:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P4MVw-0006Yq-Fb for qemu-devel@nongnu.org; Fri, 08 Oct 2010 19:38:13 -0400 Received: from e38.co.us.ibm.com ([32.97.110.159]:50408) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P4MVw-0006Yl-2r for qemu-devel@nongnu.org; Fri, 08 Oct 2010 19:38:12 -0400 Received: from d03relay03.boulder.ibm.com (d03relay03.boulder.ibm.com [9.17.195.228]) by e38.co.us.ibm.com (8.14.4/8.13.1) with ESMTP id o98NUJXB031274 for ; Fri, 8 Oct 2010 17:30:19 -0600 Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d03relay03.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o98NcAgf176784 for ; Fri, 8 Oct 2010 17:38:10 -0600 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o98NcAtq029818 for ; Fri, 8 Oct 2010 17:38:10 -0600 From: Anthony Liguori Date: Fri, 8 Oct 2010 18:38:06 -0500 Message-Id: <1286581086-12857-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 (v2) 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 --- v1 -> v2 - Remove garbage from unclean commit (spotted by Alex Graf) 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