Skip to contentSkip to conversation

net: provide a friendly message when a user passes a bad -net tap, fd=X (v2)

PATCH Jason Wang 1 participant 1 message Oct 12, 2010 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 1784739024.170001286865606278.JavaMail.root@zmail05.collab.prod.int.phx2.redhat.com

Jason Wang

author
#1 lore raw
Quoted 43 lines · ----- "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

---
v1 -> v2
- Remove garbage from unclean commit (spotted by Alex Graf)

net/tap.c +0 -0
index 0147dab..45b1fb6 100644
@@ -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")) {
net/tap.c +2 -0
+        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;
         }
net/tap.c +2 -0
+        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");

net/tap.c

Quoted 3 lines
net/tap.c +3 -0
+            return -1;
+        }
+

Maybe we can use TUNGETFEATURES here to verify whether fd is a tap here?

Quoted 5 lines
         fcntl(fd, F_SETFL, O_NONBLOCK);
 
         vnet_hdr = tap_probe_vnet_hdr(fd);
Signature · 1 line
1.7.0.4