From patchwork Wed Jun 2 17:33:01 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 54411 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6C709B7D20 for ; Thu, 3 Jun 2010 04:26:55 +1000 (EST) Received: from localhost ([127.0.0.1]:36911 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OJsOO-0001xm-0Q for incoming@patchwork.ozlabs.org; Wed, 02 Jun 2010 14:10:16 -0400 Received: from [140.186.70.92] (port=33387 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OJroZ-0008SN-Cz for qemu-devel@nongnu.org; Wed, 02 Jun 2010 13:33:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OJroR-0005UG-7g for qemu-devel@nongnu.org; Wed, 02 Jun 2010 13:33:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56495) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OJroR-0005U6-1P for qemu-devel@nongnu.org; Wed, 02 Jun 2010 13:33:07 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o52HX5EG003172 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 2 Jun 2010 13:33:06 -0400 Received: from localhost (vpn-10-141.rdu.redhat.com [10.11.10.141]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o52HX1cV020294 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Wed, 2 Jun 2010 13:33:04 -0400 Date: Wed, 2 Jun 2010 14:33:01 -0300 From: Luiz Capitulino To: qemu-devel@nongnu.org Message-ID: <20100602143301.0289520c@redhat.com> Organization: Red Hat Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: mjt@tls.msk.ru Subject: [Qemu-devel] [PATCH] give some useful error messages when tap open X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Michael Tokarev 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 Signed-off-by: Luiz Capitulino --- IMPORTANT: this an old fix that got forgotten, probably because it was submitted in the middle of thread. I've just compiled tested it. net/tap-linux.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-) diff --git a/net/tap-linux.c b/net/tap-linux.c index 03b8301..c92983c 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -33,14 +33,16 @@ #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; }