From patchwork Wed Feb 21 10:18:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 10231743 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4D8C260209 for ; Wed, 21 Feb 2018 10:20:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 387EE28AC1 for ; Wed, 21 Feb 2018 10:20:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D5C428AE5; Wed, 21 Feb 2018 10:20:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C8B2D28AC1 for ; Wed, 21 Feb 2018 10:20:29 +0000 (UTC) Received: from localhost ([::1]:59894 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eoRVa-0005wZ-Ve for patchwork-qemu-devel@patchwork.kernel.org; Wed, 21 Feb 2018 05:20:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53756) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eoRUC-0004hq-0W for qemu-devel@nongnu.org; Wed, 21 Feb 2018 05:18:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eoRU7-0001Ur-1N for qemu-devel@nongnu.org; Wed, 21 Feb 2018 05:18:51 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50128 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eoRU6-0001UN-TB for qemu-devel@nongnu.org; Wed, 21 Feb 2018 05:18:46 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 608078182D06 for ; Wed, 21 Feb 2018 10:18:44 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-123.ams2.redhat.com [10.36.116.123]) by smtp.corp.redhat.com (Postfix) with ESMTP id E4CC52024CA7; Wed, 21 Feb 2018 10:18:42 +0000 (UTC) From: Thomas Huth To: qemu-devel@nongnu.org, Jason Wang , "Dr. David Alan Gilbert" Date: Wed, 21 Feb 2018 11:18:30 +0100 Message-Id: <1519208316-18812-2-git-send-email-thuth@redhat.com> In-Reply-To: <1519208316-18812-1-git-send-email-thuth@redhat.com> References: <1519208316-18812-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 21 Feb 2018 10:18:44 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 21 Feb 2018 10:18:44 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'thuth@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 1/7] net: Move error reporting from net_init_client/netdev to the calling site X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP It looks strange that net_init_client() and net_init_netdev() both take an "Error **errp" parameter, but then do the error reporting with "error_report_err(local_err)" on their own. Let's move the error reporting to the calling site instead to simplify this code a little bit. Reviewed-by: Eric Blake Reviewed-by: Paolo Bonzini Signed-off-by: Thomas Huth --- include/net/net.h | 2 +- net/net.c | 29 +++++------------------------ vl.c | 3 ++- 3 files changed, 8 insertions(+), 26 deletions(-) diff --git a/include/net/net.h b/include/net/net.h index 3fc48e4..bdd4d9f 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -206,7 +206,7 @@ extern const char *legacy_bootp_filename; int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp); int net_client_parse(QemuOptsList *opts_list, const char *str); -int net_init_clients(void); +int net_init_clients(Error **errp); void net_check_clients(void); void net_cleanup(void); void hmp_host_net_add(Monitor *mon, const QDict *qdict); diff --git a/net/net.c b/net/net.c index 7d42925..e213a61 100644 --- a/net/net.c +++ b/net/net.c @@ -1520,46 +1520,27 @@ void net_check_clients(void) static int net_init_client(void *dummy, QemuOpts *opts, Error **errp) { - Error *local_err = NULL; - - net_client_init(opts, false, &local_err); - if (local_err) { - error_report_err(local_err); - return -1; - } - - return 0; + return net_client_init(opts, false, errp); } static int net_init_netdev(void *dummy, QemuOpts *opts, Error **errp) { - Error *local_err = NULL; - int ret; - - ret = net_client_init(opts, true, &local_err); - if (local_err) { - error_report_err(local_err); - return -1; - } - - return ret; + return net_client_init(opts, true, errp); } -int net_init_clients(void) +int net_init_clients(Error **errp) { - QemuOptsList *net = qemu_find_opts("net"); - net_change_state_entry = qemu_add_vm_change_state_handler(net_vm_change_state_handler, NULL); QTAILQ_INIT(&net_clients); if (qemu_opts_foreach(qemu_find_opts("netdev"), - net_init_netdev, NULL, NULL)) { + net_init_netdev, NULL, errp)) { return -1; } - if (qemu_opts_foreach(net, net_init_client, NULL, NULL)) { + if (qemu_opts_foreach(qemu_find_opts("net"), net_init_client, NULL, errp)) { return -1; } diff --git a/vl.c b/vl.c index 9e7235d..698b681 100644 --- a/vl.c +++ b/vl.c @@ -4476,7 +4476,8 @@ int main(int argc, char **argv, char **envp) colo_info_init(); - if (net_init_clients() < 0) { + if (net_init_clients(&err) < 0) { + error_report_err(err); exit(1); }