From patchwork Tue Mar 22 18:39:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 87954 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]) by ozlabs.org (Postfix) with ESMTP id 6AC32B6F75 for ; Wed, 23 Mar 2011 05:45:56 +1100 (EST) Received: from localhost ([127.0.0.1]:51885 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q26VY-0003Po-W5 for incoming@patchwork.ozlabs.org; Tue, 22 Mar 2011 14:40:45 -0400 Received: from [140.186.70.92] (port=58366 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q26Ug-0003L9-L1 for qemu-devel@nongnu.org; Tue, 22 Mar 2011 14:39:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q26Ud-00086w-Sb for qemu-devel@nongnu.org; Tue, 22 Mar 2011 14:39:49 -0400 Received: from mnementh.archaic.org.uk ([81.2.115.146]:49924) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q26Ud-00085r-JS for qemu-devel@nongnu.org; Tue, 22 Mar 2011 14:39:47 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1Q26UW-00027Q-35; Tue, 22 Mar 2011 18:39:40 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Tue, 22 Mar 2011 18:39:40 +0000 Message-Id: <1300819180-8121-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.3 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 81.2.115.146 Cc: Mark McLoughlin , Anthony Liguori , Aurelien Jarno , patches@linaro.org Subject: [Qemu-devel] [PATCH] net: Improve the warnings for dubious command line option combinations 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 Improve the warnings we give if the user specified a combination of -net options which don't make much sense: * Fix a bug where we would only complain about the first VLAN having no NIC or no host network connection; we now diagnose this situation for all VLANs * Don't warn about anything if the config is the implicit default "-net user -net nic" rather than one specified by the user (this will only kick in for boards with no NIC or if CONFIG_SLIRP is not set) * Diagnose the case where the user asked for NICs which the board didn't instantiate (for example where the user asked for two NICs but the board only supports one) Signed-off-by: Peter Maydell --- The motivation for this patch is that I thought it made more sense to complain about unused NIC specifications in generic code than force every board to do it; see discussion of the vexpress patch http://patchwork.ozlabs.org/patch/85727/ net.c | 34 +++++++++++++++++++++++++++++++++- 1 files changed, 33 insertions(+), 1 deletions(-) diff --git a/net.c b/net.c index ddcca97..9d3aaf5 100644 --- a/net.c +++ b/net.c @@ -1305,12 +1305,30 @@ void net_check_clients(void) { VLANState *vlan; VLANClientState *vc; - int has_nic = 0, has_host_dev = 0; + int has_nic, has_host_dev; + int seen_nics = 0; + + /* Don't warn about the default network setup that you get if + * no command line -net options are specified. There are two + * cases that we would otherwise complain about: + * (1) board doesn't support a NIC but the implicit "-net nic" + * requested one; we'd otherwise complain about more NICs being + * specified than we support, and also that the vlan set up by + * the implicit "-net user" didn't have any NICs connected to it + * (2) CONFIG_SLIRP not set: we'd otherwise complain about the + * implicit "-net nic" setting up a nic that wasn't connected to + * anything. + */ + if (default_net) { + return; + } QTAILQ_FOREACH(vlan, &vlans, next) { + has_nic = has_host_dev = 0; QTAILQ_FOREACH(vc, &vlan->clients, next) { switch (vc->info->type) { case NET_CLIENT_TYPE_NIC: + seen_nics++; has_nic = 1; break; case NET_CLIENT_TYPE_SLIRP: @@ -1330,12 +1348,26 @@ void net_check_clients(void) vlan->id); } QTAILQ_FOREACH(vc, &non_vlan_clients, next) { + if (vc->info->type == NET_CLIENT_TYPE_NIC) { + seen_nics++; + } if (!vc->peer) { fprintf(stderr, "Warning: %s %s has no peer\n", vc->info->type == NET_CLIENT_TYPE_NIC ? "nic" : "netdev", vc->name); } } + if (seen_nics != nb_nics) { + /* Number of NICs requested by user on command line doesn't match + * the number the model actually registered with us. + * This will generally only happen for models of embedded boards + * with no PCI bus or similar. PCI based machines can instantiate + * all requested NICs as PCI devices but usually embedded boards + * only have a single NIC. + */ + fprintf(stderr, "Warning: more nics requested than this machine " + "supports; some have been ignored\n"); + } } static int net_init_client(QemuOpts *opts, void *dummy)