From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=59628 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P5YYa-0005aN-5v for qemu-devel@nongnu.org; Tue, 12 Oct 2010 02:41:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P5YYZ-0007Gc-31 for qemu-devel@nongnu.org; Tue, 12 Oct 2010 02:41:52 -0400 Received: from mx3-phx2.redhat.com ([209.132.183.24]:46353 helo=mx01.colomx.prod.int.phx2.redhat.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P5YYY-0007GL-SF for qemu-devel@nongnu.org; Tue, 12 Oct 2010 02:41:51 -0400 Date: Tue, 12 Oct 2010 02:41:49 -0400 (EDT) From: Jason Wang Message-ID: <858043178.170041286865709512.JavaMail.root@zmail05.collab.prod.int.phx2.redhat.com> In-Reply-To: <1784739024.170001286865606278.JavaMail.root@zmail05.collab.prod.int.phx2.redhat.com> Subject: Re: [Qemu-devel] [PATCH] net: provide a friendly message when a user passes a bad -net tap, fd=X (v2) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: qemu-devel@nongnu.org ----- "Anthony Liguori" wrote: > 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; > + } > + Maybe we can use TUNGETFEATURES here to verify whether fd is a tap here? > fcntl(fd, F_SETFL, O_NONBLOCK); > > vnet_hdr = tap_probe_vnet_hdr(fd); > -- > 1.7.0.4