Skip to contentSkip to conversation

net: reimplement -net nic diagnostic fix

PATCH Applied Peter Maydell 4 participants 16 messages May 20, 2011 – Jun 22, 2011

lore
Share & tools
lore
#0 lore raw

cover net: reimplement -net nic diagnostic fix

This patchset reverts commit f68b9d672, which was triggering spuriously for NICs created via -device rather than -net nic. It then reimplements the improved diagnostics with a different approach which only applies to '-net nic'. (It's only -net nic devices that can be ignored (ie not instantiated); -device nic devices are always instantiated. Checking for -device user errors like "this device wasn't plugged into any bus" is a separate issue not addressed here.)

Apologies for the regression.

Peter Maydell (3):
Revert "net: Improve the warnings for dubious command line option
combinations"
net: Don't warn about the default network setup
net: Warn about "-net nic" options which were ignored

 hw/qdev.c |    1 +
 net.c     |   42 +++++++++++++++++++-----------------------
 net.h     |    3 ++-
 3 files changed, 22 insertions(+), 24 deletions(-)
#1 lore raw

PATCH 1/3 Revert "net: Improve the warnings for dubious command line option combinations"

This reverts commit f68b9d672b90dedc79aeb9b44607f484dbe46a6b. That attempt at diagnosing unused -net nic options failed to account for NICs created via -device; back it out cleanly in preparation for implementing in a different manner.

---
 net.c |   31 -------------------------------
 1 files changed, 0 insertions(+), 31 deletions(-)
net.c +0 -31
index 4f777c3..1b521a9 100644
@@ -1304,22 +1304,6 @@ void net_check_clients(void)
 {
     VLANState *vlan;
     VLANClientState *vc;
-    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) {
         int has_nic = 0, has_host_dev = 0;
@@ -1327,7 +1311,6 @@ void net_check_clients(void)
         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:
@@ -1347,26 +1330,12 @@ 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)
Signature · 1 line
1.7.1
#2 lore raw

PATCH 2/3 net: Don't warn about the default network setup

In reply to Peter Maydell

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
(2) CONFIG_SLIRP not set, so the implicit "-net nic" sets up a nic that isn't connected to anything

---
 net.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
net.c +12 -0
index 1b521a9..68c2840 100644
@@ -1305,6 +1305,18 @@ void net_check_clients(void)
     VLANState *vlan;
     VLANClientState *vc;
 
+    /* Don't warn about the default network setup that you get if
+     * no command line -net or -netdev 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
+     * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
+     * sets up a nic that isn't connected to anything.
+     */
+    if (default_net) {
+        return;
+    }
+
     QTAILQ_FOREACH(vlan, &vlans, next) {
         int has_nic = 0, has_host_dev = 0;
 
Signature · 1 line
1.7.1
#3 lore raw

Re: [Qemu-devel] [PATCH 2/3] net: Don't warn about the default network setup

Quoted 5 lines · Peter Maydell

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

Maybe such board should declare no_nic, similar to no_parallel & friends. But that's out of this patch's scope.

This complaint is only added in the next patch, isn't it? I don't mind.

Quoted 2 lines

(2) CONFIG_SLIRP not set, so the implicit "-net nic" sets up a nic that isn't connected to anything

This one's already there, I think.

#4 lore raw

Re: [Qemu-devel] [PATCH 2/3] net: Don't warn about the default network setup

Quoted 10 lines · Markus Armbruster
Quoted 5 lines · Peter Maydell

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

Maybe such board should declare no_nic, similar to no_parallel & friends.  But that's out of this patch's scope.

I think in the brave new qdev world this kind of thing should be handled generically by warning about any -device requested devices which couldn't be plugged into anything sensible.

Quoted 1 line

This complaint is only added in the next patch, isn't it?  I don't mind.

It won't explicitly say "you asked for a NIC and didn't get one", but it will make the obscurer complaint "Warning: vlan 0 with no nics", because the implicit '-net user' is then not connected to anything. I was deliberately slightly vague with the comment text so it would be true both before and after the following patch :-)

Quoted 4 lines
Quoted 2 lines

(2) CONFIG_SLIRP not set, so the implicit "-net nic" sets up a nic that isn't connected to anything

This one's already there, I think.

No, without this patch qemu will complain
"Warning: vlan 0 is not connected to host network" if you configured with --disable-slirp.

(--disable-slirp seems to have been left out of configure --help; I assume that's an oversight.)

-- PMM

#5 lore raw

PATCH 3/3 net: Warn about "-net nic" options which were ignored

In reply to Peter Maydell

Diagnose the case where the user asked for a NIC via "-net nic" but the board didn't instantiate that NIC (for example where the user asked for two NICs but the board only supports one). Note that this diagnostic doesn't apply to NICs created through -device, because those are always instantiated.

---
 hw/qdev.c |    1 +
 net.c     |   15 +++++++++++++++
 net.h     |    3 ++-
 3 files changed, 18 insertions(+), 1 deletions(-)
hw/qdev.c +1 -0
index 9519f5d..2987901 100644
@@ -468,6 +468,7 @@ void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd)
         qdev_prop_exists(dev, "vectors")) {
         qdev_prop_set_uint32(dev, "vectors", nd->nvectors);
     }
+    nd->instantiated = 1;
 }
 
 BusState *qdev_get_child_bus(DeviceState *dev, const char *name)
net.c +15 -0
index 68c2840..a104976 100644
@@ -1304,6 +1304,7 @@ void net_check_clients(void)
 {
     VLANState *vlan;
     VLANClientState *vc;
+    int i;
 
     /* Don't warn about the default network setup that you get if
      * no command line -net or -netdev options are specified. There
@@ -1348,6 +1349,20 @@ void net_check_clients(void)
                     vc->name);
         }
     }
+
+    /* Check that all NICs requested via -net nic actually got created.
+     * NICs created via -device don't need to be checked here because
+     * they are always instantiated.
+     */
+    for (i = 0; i < MAX_NICS; i++) {
+        NICInfo *nd = &nd_table[i];
+        if (nd->used && !nd->instantiated) {
+            fprintf(stderr, "Warning: requested NIC (%s, model %s) "
+                    "was not created (not supported by this machine?)\n",
+                    nd->name ? nd->name : "anonymous",
+                    nd->model ? nd->model : "unspecified");
+        }
+    }
 }
 
 static int net_init_client(QemuOpts *opts, void *dummy)
net.h +2 -1
index 6ceca50..5b883a9 100644
@@ -133,7 +133,8 @@ struct NICInfo {
     char *devaddr;
     VLANState *vlan;
     VLANClientState *netdev;
-    int used;
+    int used;         /* is this slot in nd_table[] being used? */
+    int instantiated; /* does this NICInfo correspond to an instantiated NIC? */
     int nvectors;
 };
 
Signature · 1 line
1.7.1
#6 lore raw

Re: [Qemu-devel] [PATCH 3/3] net: Warn about "-net nic" options which were ignored

Quoted 45 lines · Peter Maydell

Diagnose the case where the user asked for a NIC via "-net nic" but the board didn't instantiate that NIC (for example where the user asked for two NICs but the board only supports one). Note that this diagnostic doesn't apply to NICs created through -device, because those are always instantiated.

---
 hw/qdev.c |    1 +
 net.c     |   15 +++++++++++++++
 net.h     |    3 ++-
 3 files changed, 18 insertions(+), 1 deletions(-)
hw/qdev.c +1 -0
index 9519f5d..2987901 100644
@@ -468,6 +468,7 @@ void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd)
         qdev_prop_exists(dev, "vectors")) {
         qdev_prop_set_uint32(dev, "vectors", nd->nvectors);
     }
+    nd->instantiated = 1;
 }
 
 BusState *qdev_get_child_bus(DeviceState *dev, const char *name)
net.c +5 -0
index 68c2840..a104976 100644
@@ -1304,6 +1304,7 @@ void net_check_clients(void)
 {
     VLANState *vlan;
     VLANClientState *vc;
+    int i;
 
     /* Don't warn about the default network setup that you get if
      * no command line -net or -netdev options are specified. There
@@ -1348,6 +1349,20 @@ void net_check_clients(void)
                     vc->name);
         }
     }
+
+    /* Check that all NICs requested via -net nic actually got created.
+     * NICs created via -device don't need to be checked here because
+     * they are always instantiated.

net.c void net_check_clients(void) · line 1365

Quoted 10 lines
net.c +10 -0
+     */
+    for (i = 0; i < MAX_NICS; i++) {
+        NICInfo *nd = &nd_table[i];
+        if (nd->used && !nd->instantiated) {
+            fprintf(stderr, "Warning: requested NIC (%s, model %s) "
+                    "was not created (not supported by this machine?)\n",
+                    nd->name ? nd->name : "anonymous",
+                    nd->model ? nd->model : "unspecified");
+        }
+    }

Nicer message would be possible if NICInfo had a Location for error_print_loc(). Out of this patch's scope.

Quoted 16 lines
net.c +0 -0
 }
 
 static int net_init_client(QemuOpts *opts, void *dummy)
net.h +2 -1
index 6ceca50..5b883a9 100644
@@ -133,7 +133,8 @@ struct NICInfo {
     char *devaddr;
     VLANState *vlan;
     VLANClientState *netdev;
-    int used;
+    int used;         /* is this slot in nd_table[] being used? */
+    int instantiated; /* does this NICInfo correspond to an instantiated NIC? */
     int nvectors;
 };
#7 lore raw
In reply to Peter Maydell
Quoted 8 lines · Peter Maydell

This patchset reverts commit f68b9d672, which was triggering spuriously for NICs created via -device rather than -net nic. It then reimplements the improved diagnostics with a different approach which only applies to '-net nic'. (It's only -net nic devices that can be ignored (ie not instantiated); -device nic devices are always instantiated. Checking for -device user errors like "this device wasn't plugged into any bus" is a separate issue not addressed here.)

But we still have the problem that qemu_new_nic does not call net_init_nic. That means e.g. that NICs instantiated via -device don't participate in automatic MAC assignment. Maybe fixing that makes this series obsolete.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#8 lore raw
Quoted 10 lines · Jan Kiszka
Quoted 8 lines · Peter Maydell

This patchset reverts commit f68b9d672, which was triggering spuriously for NICs created via -device rather than -net nic. It then reimplements the improved diagnostics with a different approach which only applies to '-net nic'. (It's only -net nic devices that can be ignored (ie not instantiated); -device nic devices are always instantiated. Checking for -device user errors like "this device wasn't plugged into any bus" is a separate issue not addressed here.)

Quoted 4 lines

But we still have the problem that qemu_new_nic does not call net_init_nic. That means e.g. that NICs instantiated via -device don't participate in automatic MAC assignment. Maybe fixing that makes this series obsolete.

I think that avoiding MAC address clashes should be done by having net_init_nic() call qemu_macaddr_default_if_unset() rather than doing its own MAC assignment.

Having qemu_new_nic() call net_init_nic() is a bit tricky because (a) as you said earlier you need to avoid doing it for NICs which were created from nd_table entries in the first place and (b) it imposes a new limit on the number of NICs you can create via -device which wasn't there before (because nd_table is fixed size).

I think I agree with Paul Brook's comment on IRC that the real long term solution is for nd_table[] to go away completely, (ie not for the new qdev option code to add entries in nd_table[] by calling net_init_nic().)

-- PMM

#9 lore raw
Quoted 11 lines · Peter Maydell
Quoted 10 lines · Jan Kiszka
Quoted 8 lines · Peter Maydell

This patchset reverts commit f68b9d672, which was triggering spuriously for NICs created via -device rather than -net nic. It then reimplements the improved diagnostics with a different approach which only applies to '-net nic'. (It's only -net nic devices that can be ignored (ie not instantiated); -device nic devices are always instantiated. Checking for -device user errors like "this device wasn't plugged into any bus" is a separate issue not addressed here.)

Quoted 7 lines
Quoted 4 lines

But we still have the problem that qemu_new_nic does not call net_init_nic. That means e.g. that NICs instantiated via -device don't participate in automatic MAC assignment. Maybe fixing that makes this series obsolete.

I think that avoiding MAC address clashes should be done by having net_init_nic() call qemu_macaddr_default_if_unset()

You mean qemu_new_nic? Otherwise it wouldn't help. Will have a look to move that over.

Quoted 9 lines

rather than doing its own MAC assignment.

Having qemu_new_nic() call net_init_nic() is a bit tricky because (a) as you said earlier you need to avoid doing it for NICs which were created from nd_table entries in the first place and (b) it imposes a new limit on the number of NICs you can create via -device which wasn't there before (because nd_table is fixed size).

Quoted 4 lines

I think I agree with Paul Brook's comment on IRC that the real long term solution is for nd_table[] to go away completely, (ie not for the new qdev option code to add entries in nd_table[] by calling net_init_nic().)

I don't disagree that nd_table is better removed. Then let's address all those issues separately.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#10 lore raw
Quoted 6 lines · Jan Kiszka
Quoted 2 lines · Peter Maydell

I think that avoiding MAC address clashes should be done by having net_init_nic() call qemu_macaddr_default_if_unset()

You mean qemu_new_nic? Otherwise it wouldn't help. Will have a look to move that over.

No, I mean net_init_nic(). At the moment there are two bits of code which generate a fresh MAC address:
1. qemu_macaddr_default_if_unset() -- init routines for qdev network devices call this
2. net_init_nic() -- devices created via -net nic get their MAC address assigned here; if the underlying device is qdev then by the time the qdev init routine is called the macaddr is already set so it isn't overridden

So if the code in 2. calls qemu_macaddr_default_if_unset instead then we only have one function with a static variable which doles out autogenerated MAC addresses.

-- PMM

#11 lore raw
Quoted 17 lines · Peter Maydell
Quoted 6 lines · Jan Kiszka
Quoted 2 lines · Peter Maydell

I think that avoiding MAC address clashes should be done by having net_init_nic() call qemu_macaddr_default_if_unset()

You mean qemu_new_nic? Otherwise it wouldn't help. Will have a look to move that over.

No, I mean net_init_nic(). At the moment there are two bits of code which generate a fresh MAC address:
1. qemu_macaddr_default_if_unset() -- init routines for qdev network devices call this
2. net_init_nic() -- devices created via -net nic get their MAC address assigned here; if the underlying device is qdev then by the time the qdev init routine is called the macaddr is already set so it isn't overridden

Quoted 3 lines

So if the code in 2. calls qemu_macaddr_default_if_unset instead then we only have one function with a static variable which doles out autogenerated MAC addresses.

Ah, I see. I thought qdev would always assign the same MAC. Then it's fine.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#12 lore raw
In reply to Peter Maydell
Quoted 10 lines · Peter Maydell

This patchset reverts commit f68b9d672, which was triggering spuriously for NICs created via -device rather than -net nic. It then reimplements the improved diagnostics with a different approach which only applies to '-net nic'. (It's only -net nic devices that can be ignored (ie not instantiated); -device nic devices are always instantiated. Checking for -device user errors like "this device wasn't plugged into any bus" is a separate issue not addressed here.)

Apologies for the regression.

Looks good to me.

#13 lore raw
In reply to Peter Maydell

Combination 'ping' and 'oops I forgot to cc the net/ maintainers'...

-- PMM

Quoted 21 lines · Peter Maydell

This patchset reverts commit f68b9d672, which was triggering spuriously for NICs created via -device rather than -net nic. It then reimplements the improved diagnostics with a different approach which only applies to '-net nic'. (It's only -net nic devices that can be ignored (ie not instantiated); -device nic devices are always instantiated. Checking for -device user errors like "this device wasn't plugged into any bus" is a separate issue not addressed here.)

Apologies for the regression.

Peter Maydell (3):
 Revert "net: Improve the warnings for dubious command line option combinations"
 net: Don't warn about the default network setup
 net: Warn about "-net nic" options which were ignored

 hw/qdev.c |    1 +
 net.c     |   42 +++++++++++++++++++----------------------- net.h     |    3 ++-

 3 files changed, 22 insertions(+), 24 deletions(-)
#14 lore raw

Ping^2 ?

Quoted 26 lines · Peter Maydell

Combination 'ping' and 'oops I forgot to cc the net/ maintainers'...

-- PMM

Quoted 21 lines · Peter Maydell

This patchset reverts commit f68b9d672, which was triggering spuriously for NICs created via -device rather than -net nic. It then reimplements the improved diagnostics with a different approach which only applies to '-net nic'. (It's only -net nic devices that can be ignored (ie not instantiated); -device nic devices are always instantiated. Checking for -device user errors like "this device wasn't plugged into any bus" is a separate issue not addressed here.)

Apologies for the regression.

Peter Maydell (3):
 Revert "net: Improve the warnings for dubious command line option combinations"
 net: Don't warn about the default network setup
 net: Warn about "-net nic" options which were ignored

 hw/qdev.c |    1 +
 net.c     |   42 +++++++++++++++++++----------------------- net.h     |    3 ++-

 3 files changed, 22 insertions(+), 24 deletions(-)
#15 lore raw
In reply to Peter Maydell
Quoted 10 lines · Peter Maydell

This patchset reverts commit f68b9d672, which was triggering spuriously for NICs created via -device rather than -net nic. It then reimplements the improved diagnostics with a different approach which only applies to '-net nic'. (It's only -net nic devices that can be ignored (ie not instantiated); -device nic devices are always instantiated. Checking for -device user errors like "this device wasn't plugged into any bus" is a separate issue not addressed here.)

Apologies for the regression.

Applied all. Thanks.

Regards,

Anthony Liguori

Quoted 14 lines

Peter Maydell (3):
Revert "net: Improve the warnings for dubious command line option
combinations"
net: Don't warn about the default network setup
net: Warn about "-net nic" options which were ignored

  hw/qdev.c |    1 +
  net.c     |   42 +++++++++++++++++++-----------------------
  net.h     |    3 ++-
  3 files changed, 22 insertions(+), 24 deletions(-)