]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
give some useful error messages when tap open
authorMichael Tokarev <mjt@tls.msk.ru>
Wed, 2 Jun 2010 17:33:01 +0000 (14:33 -0300)
committerAnthony Liguori <aliguori@us.ibm.com>
Tue, 22 Jun 2010 20:15:30 +0000 (15:15 -0500)
In net/tap-linux.c, when manipulation of /dev/net/tun fails, it prints
(with fprintf) something like this:

  warning: could not open /dev/net/tun: no virtual network emulation

this has 2 issues:
 1) it is not a warning really, it's a fatal error (kvm exits after
that),
 2) there's no indication as of what's actually wrong: printing errno there
    is helpful.

The patch below removes the "warning" prefix, uses %m (since it's linux,
%m is available as format modifier), and changes fprintf() to %qemu_error().
Now it prints something like this instead:

 could not configure /dev/net/tun: Device or resource busy

(there are 2 messages like that in the same function)

This fixes Debian bug #578154, see
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=578154

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
net/tap-linux.c

index 03b83012f85656ef5c7d909fda33a12f3c301639..c92983cb5386be156ffea1faaf213aad209f8393 100644 (file)
 #include "qemu-common.h"
 #include "qemu-error.h"
 
+#define PATH_NET_TUN "/dev/net/tun"
+
 int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required)
 {
     struct ifreq ifr;
     int fd, ret;
 
-    TFR(fd = open("/dev/net/tun", O_RDWR));
+    TFR(fd = open(PATH_NET_TUN, O_RDWR));
     if (fd < 0) {
-        fprintf(stderr, "warning: could not open /dev/net/tun: no virtual network emulation\n");
+        error_report("could not open %s: %m", PATH_NET_TUN);
         return -1;
     }
     memset(&ifr, 0, sizeof(ifr));
@@ -71,7 +73,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required
         pstrcpy(ifr.ifr_name, IFNAMSIZ, "tap%d");
     ret = ioctl(fd, TUNSETIFF, (void *) &ifr);
     if (ret != 0) {
-        fprintf(stderr, "warning: could not configure /dev/net/tun: no virtual network emulation\n");
+        error_report("could not configure %s (%s): %m", PATH_NET_TUN, ifr.ifr_name);
         close(fd);
         return -1;
     }