From patchwork Wed May 27 10:03:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 477043 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 9C15E1402A2 for ; Wed, 27 May 2015 20:09:28 +1000 (AEST) Received: from localhost ([::1]:52891 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YxYH8-0006f1-Od for incoming@patchwork.ozlabs.org; Wed, 27 May 2015 06:09:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56314) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YxYBU-0004tY-CN for qemu-devel@nongnu.org; Wed, 27 May 2015 06:03:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YxYBQ-0002BN-HE for qemu-devel@nongnu.org; Wed, 27 May 2015 06:03:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38522) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YxYBQ-0002BB-6Y for qemu-devel@nongnu.org; Wed, 27 May 2015 06:03:32 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t4RA3UgL000798 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 27 May 2015 06:03:30 -0400 Received: from localhost (ovpn-112-78.ams2.redhat.com [10.36.112.78]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t4RA3TnI012984; Wed, 27 May 2015 06:03:29 -0400 From: Stefan Hajnoczi To: Date: Wed, 27 May 2015 11:03:00 +0100 Message-Id: <1432720988-20200-10-git-send-email-stefanha@redhat.com> In-Reply-To: <1432720988-20200-1-git-send-email-stefanha@redhat.com> References: <1432720988-20200-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Maydell , Markus Armbruster , Stefan Hajnoczi Subject: [Qemu-devel] [PULL 09/17] tap: Convert net_init_tap_one() to Error X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Markus Armbruster [Dropped %s from "tap: open vhost char device failed: %s" since error_setg_errno() already prints a human-readable error string and there is no format string argument. --Stefan] Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-id: 1431691143-1015-9-git-send-email-armbru@redhat.com Signed-off-by: Stefan Hajnoczi --- net/tap.c | 70 ++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/net/tap.c b/net/tap.c index d54222d..49f8586 100644 --- a/net/tap.c +++ b/net/tap.c @@ -600,11 +600,11 @@ static int net_tap_init(const NetdevTapOptions *tap, int *vnet_hdr, #define MAX_TAP_QUEUES 1024 -static int net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, - const char *model, const char *name, - const char *ifname, const char *script, - const char *downscript, const char *vhostfdname, - int vnet_hdr, int fd) +static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, + const char *model, const char *name, + const char *ifname, const char *script, + const char *downscript, const char *vhostfdname, + int vnet_hdr, int fd, Error **errp) { Error *err = NULL; TAPState *s = net_tap_fd_init(peer, model, name, fd, vnet_hdr); @@ -612,8 +612,8 @@ static int net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, tap_set_sndbuf(s->fd, tap, &err); if (err) { - error_report_err(err); - return -1; + error_propagate(errp, err); + return; } if (tap->has_fd || tap->has_fds) { @@ -644,30 +644,28 @@ static int net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, if (tap->has_vhostfd || tap->has_vhostfds) { vhostfd = monitor_fd_param(cur_mon, vhostfdname, &err); if (vhostfd == -1) { - error_report_err(err); - return -1; + error_propagate(errp, err); + return; } } else { vhostfd = open("/dev/vhost-net", O_RDWR); if (vhostfd < 0) { - error_report("tap: open vhost char device failed: %s", - strerror(errno)); - return -1; + error_setg_errno(errp, errno, + "tap: open vhost char device failed"); + return; } } options.opaque = (void *)(uintptr_t)vhostfd; s->vhost_net = vhost_net_init(&options); if (!s->vhost_net) { - error_report("vhost-net requested but could not be initialized"); - return -1; + error_setg(errp, + "vhost-net requested but could not be initialized"); + return; } } else if (tap->has_vhostfd || tap->has_vhostfds) { - error_report("vhostfd= is not valid without vhost"); - return -1; + error_setg(errp, "vhostfd= is not valid without vhost"); } - - return 0; } static int get_fds(char *str, char *fds[], int max) @@ -741,9 +739,11 @@ int net_init_tap(const NetClientOptions *opts, const char *name, vnet_hdr = tap_probe_vnet_hdr(fd); - if (net_init_tap_one(tap, peer, "tap", name, NULL, - script, downscript, - vhostfdname, vnet_hdr, fd)) { + net_init_tap_one(tap, peer, "tap", name, NULL, + script, downscript, + vhostfdname, vnet_hdr, fd, &err); + if (err) { + error_report_err(err); return -1; } } else if (tap->has_fds) { @@ -786,10 +786,12 @@ int net_init_tap(const NetClientOptions *opts, const char *name, return -1; } - if (net_init_tap_one(tap, peer, "tap", name, ifname, - script, downscript, - tap->has_vhostfds ? vhost_fds[i] : NULL, - vnet_hdr, fd)) { + net_init_tap_one(tap, peer, "tap", name, ifname, + script, downscript, + tap->has_vhostfds ? vhost_fds[i] : NULL, + vnet_hdr, fd, &err); + if (err) { + error_report_err(err); return -1; } } @@ -810,9 +812,11 @@ int net_init_tap(const NetClientOptions *opts, const char *name, fcntl(fd, F_SETFL, O_NONBLOCK); vnet_hdr = tap_probe_vnet_hdr(fd); - if (net_init_tap_one(tap, peer, "bridge", name, ifname, - script, downscript, vhostfdname, - vnet_hdr, fd)) { + net_init_tap_one(tap, peer, "bridge", name, ifname, + script, downscript, vhostfdname, + vnet_hdr, fd, &err); + if (err) { + error_report_err(err); close(fd); return -1; } @@ -846,10 +850,12 @@ int net_init_tap(const NetClientOptions *opts, const char *name, } } - if (net_init_tap_one(tap, peer, "tap", name, ifname, - i >= 1 ? "no" : script, - i >= 1 ? "no" : downscript, - vhostfdname, vnet_hdr, fd)) { + net_init_tap_one(tap, peer, "tap", name, ifname, + i >= 1 ? "no" : script, + i >= 1 ? "no" : downscript, + vhostfdname, vnet_hdr, fd, &err); + if (err) { + error_report_err(err); close(fd); return -1; }