net: Warn about "-net nic" options which were ignored
authorPeter Maydell <peter.maydell@linaro.org>
Fri, 20 May 2011 15:50:01 +0000 (16:50 +0100)
committerAnthony Liguori <aliguori@us.ibm.com>
Wed, 22 Jun 2011 12:18:39 +0000 (07:18 -0500)
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.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/qdev.c
net.c
net.h

index 9519f5dd57a53184175804edfaf30fa53758f9bc..29879019832dab7ba90ebb57f9a4cd895544c522 100644 (file)
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -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)
diff --git a/net.c b/net.c
index 68c28406211afa98244ddd6524988131b386a528..a104976b0b65814cb217c3fd9902f6e4ac2c9b8d 100644 (file)
--- a/net.c
+++ b/net.c
@@ -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)
diff --git a/net.h b/net.h
index 6ceca50fc38b0b2c73a38a1fcf93a9a7f30d6576..5b883a96bacee1d9cff5a49b40a7efbbe4a1b2f8 100644 (file)
--- a/net.h
+++ b/net.h
@@ -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;
 };