Skip to contentSkip to conversation

Assorted netdev fixes

PATCH Applied Markus Armbruster 4 participants 10 messages Feb 11, 2010 – Feb 19, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Assorted netdev fixes

The fixes fall into three groups:

* Dead code removal.

* Fix bogus "Warning: vlan 0 with no nics" with -device

* When we added network clients not associated with a VLAN (-netdev & friends), we missed a few places. Fix them up.

Markus Armbruster (6):
net: Remove unused net_client_uninit()
net: net_check_clients() runs too early to see -device, fix
net: Fix bogus "Warning: vlan 0 with no nics" with -device
net: net_check_clients() checks only VLAN clients, fix
net: info network shows only VLAN clients, fix
net: Monitor command set_link finds only VLAN clients, fix

 net.c           |   62 +++++++++++++++++++++++++++++++-----------------------
 net.h           |    3 +-
 net/slirp.c     |    4 ---
 net/socket.c    |    4 ---
 net/tap-win32.c |    4 ---
 net/tap.c       |    4 ---
 net/vde.c       |    4 ---
 vl.c            |    2 +
 8 files changed, 39 insertions(+), 48 deletions(-)
#1 lore raw

PATCH 1/6 net: Remove unused net_client_uninit()

Unused since commit 9ad4531e.

---
 net.c |   14 --------------
 net.h |    1 -
 2 files changed, 0 insertions(+), 15 deletions(-)
net.c +0 -14
index 8e951ca..f51d376 100644
@@ -1128,20 +1128,6 @@ int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev)
     return -1;
 }
 
-void net_client_uninit(NICInfo *nd)
-{
-    if (nd->vlan) {
-        nd->vlan->nb_guest_devs--;
-    }
-    nb_nics--;
-
-    qemu_free(nd->model);
-    qemu_free(nd->name);
-    qemu_free(nd->devaddr);
-
-    nd->used = 0;
-}
-
 static int net_host_check_device(const char *device)
 {
     int i;
net.h +0 -1
index 116bb80..ecbd812 100644
@@ -163,7 +163,6 @@ extern const char *legacy_tftp_prefix;
 extern const char *legacy_bootp_filename;
 
 int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev);
-void net_client_uninit(NICInfo *nd);
 int net_client_parse(QemuOptsList *opts_list, const char *str);
 int net_init_clients(void);
 void net_cleanup(void);
Signature · 1 line
1.6.6
#2 lore raw

Re: [Qemu-devel] [PATCH 1/6] net: Remove unused net_client_uninit()

Quoted 4 lines · Markus Armbruster

Unused since commit 9ad4531e.

Applied all. Thanks.

Regards,

Anthony Liguori

Quoted 43 lines
---
  net.c |   14 --------------
  net.h |    1 -
  2 files changed, 0 insertions(+), 15 deletions(-)
net.c +0 -14
index 8e951ca..f51d376 100644
@@ -1128,20 +1128,6 @@ int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev)
      return -1;
  }
 
-void net_client_uninit(NICInfo *nd)
-{
-    if (nd->vlan) {
-        nd->vlan->nb_guest_devs--;
-    }
-    nb_nics--;
-
-    qemu_free(nd->model);
-    qemu_free(nd->name);
-    qemu_free(nd->devaddr);
-
-    nd->used = 0;
-}
-
  static int net_host_check_device(const char *device)
  {
      int i;
net.h +0 -1
index 116bb80..ecbd812 100644
@@ -163,7 +163,6 @@ extern const char *legacy_tftp_prefix;
  extern const char *legacy_bootp_filename;
 
  int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev);
-void net_client_uninit(NICInfo *nd);
  int net_client_parse(QemuOptsList *opts_list, const char *str);
  int net_init_clients(void);
  void net_cleanup(void);
#3 lore raw

Re: [Qemu-devel] [PATCH 1/6] net: Remove unused net_client_uninit()

In reply to Markus Armbruster
Quoted 4 lines · Markus Armbruster

Unused since commit 9ad4531e.

Applied all. Thanks.

Regards,

Anthony Liguori

Quoted 43 lines
---
  net.c |   14 --------------
  net.h |    1 -
  2 files changed, 0 insertions(+), 15 deletions(-)
net.c +0 -14
index 8e951ca..f51d376 100644
@@ -1128,20 +1128,6 @@ int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev)
      return -1;
  }
 
-void net_client_uninit(NICInfo *nd)
-{
-    if (nd->vlan) {
-        nd->vlan->nb_guest_devs--;
-    }
-    nb_nics--;
-
-    qemu_free(nd->model);
-    qemu_free(nd->name);
-    qemu_free(nd->devaddr);
-
-    nd->used = 0;
-}
-
  static int net_host_check_device(const char *device)
  {
      int i;
net.h +0 -1
index 116bb80..ecbd812 100644
@@ -163,7 +163,6 @@ extern const char *legacy_tftp_prefix;
  extern const char *legacy_bootp_filename;
 
  int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev);
-void net_client_uninit(NICInfo *nd);
  int net_client_parse(QemuOptsList *opts_list, const char *str);
  int net_init_clients(void);
  void net_cleanup(void);
#4 lore raw

PATCH 2/6 net: net_check_clients() runs too early to see -device, fix

In reply to Markus Armbruster

Call it right after -device devices get created.

---
 net.c |    4 +---
 net.h |    1 +
 vl.c  |    2 ++
 3 files changed, 4 insertions(+), 3 deletions(-)
net.c +1 -3
index f51d376..38b65f4 100644
@@ -1275,7 +1275,7 @@ void net_cleanup(void)
     }
 }
 
-static void net_check_clients(void)
+void net_check_clients(void)
 {
     VLANState *vlan;
 
@@ -1323,8 +1323,6 @@ int net_init_clients(void)
         return -1;
     }
 
-    net_check_clients();
-
     return 0;
 }
 
net.h +1 -0
index ecbd812..3467c10 100644
@@ -165,6 +165,7 @@ extern const char *legacy_bootp_filename;
 int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev);
 int net_client_parse(QemuOptsList *opts_list, const char *str);
 int net_init_clients(void);
+void net_check_clients(void);
 void net_cleanup(void);
 void net_set_boot_mask(int boot_mask);
 void net_host_device_add(Monitor *mon, const QDict *qdict);
vl.c +2 -0
index 98918ac..084604f 100644
@@ -5897,6 +5897,8 @@ int main(int argc, char **argv, char **envp)
     if (qemu_opts_foreach(&qemu_device_opts, device_init_func, NULL, 1) != 0)
         exit(1);
 
+    net_check_clients();
+
     if (!display_state)
         dumb_display_init();
     /* just use the first displaystate for the moment */
Signature · 1 line
1.6.6
#5 lore raw

PATCH 3/6 net: Fix bogus "Warning: vlan 0 with no nics" with -device

In reply to Markus Armbruster

net_check_clients() prints this when an VLAN has host devices, but no guest devices. It uses VLANState members nb_guest_devs and nb_host_devs to keep track of these devices. However, -device does not update nb_guest_devs, only net_init_nic() does that, for -net nic.

Check the VLAN clients directly, and remove the counters.

---
 net.c           |   25 ++++++++++++++++++-------
 net.h           |    1 -
 net/slirp.c     |    4 ----
 net/socket.c    |    4 ----
 net/tap-win32.c |    4 ----
 net/tap.c       |    4 ----
 net/vde.c       |    4 ----
 7 files changed, 18 insertions(+), 28 deletions(-)
net.c +18 -7
index 38b65f4..509f074 100644
@@ -812,9 +812,6 @@ static int net_init_nic(QemuOpts *opts,
     }
 
     nd->used = 1;
-    if (vlan) {
-        nd->vlan->nb_guest_devs++;
-    }
     nb_nics++;
 
     return idx;
@@ -1278,13 +1275,27 @@ void net_cleanup(void)
 void net_check_clients(void)
 {
     VLANState *vlan;
+    VLANClientState *vc;
+    int has_nic, has_host_dev;
 
     QTAILQ_FOREACH(vlan, &vlans, next) {
-        if (vlan->nb_guest_devs == 0 && vlan->nb_host_devs == 0)
-            continue;
-        if (vlan->nb_guest_devs == 0)
+        QTAILQ_FOREACH(vc, &vlan->clients, next) {
+            switch (vc->info->type) {
+            case NET_CLIENT_TYPE_NIC:
+                has_nic = 1;
+                break;
+            case NET_CLIENT_TYPE_SLIRP:
+            case NET_CLIENT_TYPE_TAP:
+            case NET_CLIENT_TYPE_SOCKET:
+            case NET_CLIENT_TYPE_VDE:
+                has_host_dev = 1;
+                break;
+            default: ;
+            }
+        }
+        if (has_host_dev && !has_nic)
             fprintf(stderr, "Warning: vlan %d with no nics\n", vlan->id);
-        if (vlan->nb_host_devs == 0)
+        if (has_nic && !has_host_dev)
             fprintf(stderr,
                     "Warning: vlan %d is not connected to host network\n",
                     vlan->id);
net.h +0 -1
index 3467c10..33a1eaf 100644
@@ -79,7 +79,6 @@ struct VLANState {
     int id;
     QTAILQ_HEAD(, VLANClientState) clients;
     QTAILQ_ENTRY(VLANState) next;
-    unsigned int nb_guest_devs, nb_host_devs;
     NetQueue *send_queue;
 };
 
net/slirp.c +0 -4
index 361899b..317cca7 100644
@@ -738,10 +738,6 @@ int net_init_slirp(QemuOpts *opts,
         qemu_free(config);
     }
 
-    if (ret != -1 && vlan) {
-        vlan->nb_host_devs++;
-    }
-
     qemu_free(vnet);
 
     return ret;
net/socket.c +0 -4
index 5533737..442a9c7 100644
@@ -569,9 +569,5 @@ int net_init_socket(QemuOpts *opts,
         return -1;
     }
 
-    if (vlan) {
-        vlan->nb_host_devs++;
-    }
-
     return 0;
 }
net/tap-win32.c +0 -4
index b717c17..8370c80 100644
@@ -714,10 +714,6 @@ int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan
         return -1;
     }
 
-    if (vlan) {
-        vlan->nb_host_devs++;
-    }
-
     return 0;
 }
 
net/tap.c +0 -4
index d3492de..7a7320c 100644
@@ -449,9 +449,5 @@ int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan
         }
     }
 
-    if (vlan) {
-        vlan->nb_host_devs++;
-    }
-
     return 0;
 }
net/vde.c +0 -4
index 42b4633..0b46fa6 100644
@@ -127,9 +127,5 @@ int net_init_vde(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan
         return -1;
     }
 
-    if (vlan) {
-        vlan->nb_host_devs++;
-    }
-
     return 0;
 }
Signature · 1 line
1.6.6
#6 lore raw

PATCH 4/6 net: net_check_clients() checks only VLAN clients, fix

In reply to Markus Armbruster

Clients not associated with a VLAN exist since commit d80b9fc6.

---
 net.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
net.c +7 -0
index 509f074..fb425e3 100644
@@ -1300,6 +1300,13 @@ void net_check_clients(void)
                     "Warning: vlan %d is not connected to host network\n",
                     vlan->id);
     }
+    QTAILQ_FOREACH(vc, &non_vlan_clients, next) {
+        if (!vc->peer) {
+            fprintf(stderr, "Warning: %s %s has no peer\n",
+                    vc->info->type == NET_CLIENT_TYPE_NIC ? "nic" : "netdev",
+                    vc->name);
+        }
+    }
 }
 
 static int net_init_client(QemuOpts *opts, void *dummy)
Signature · 1 line
1.6.6
#7 lore raw

PATCH 5/6 net: info network shows only VLAN clients, fix

In reply to Markus Armbruster

Clients not associated with a VLAN exist since commit d80b9fc6.

---
 net.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
net.c +9 -2
index fb425e3..fb89f94 100644
@@ -1210,16 +1210,23 @@ void net_set_boot_mask(int net_boot_mask)
 void do_info_network(Monitor *mon)
 {
     VLANState *vlan;
+    VLANClientState *vc;
 
     QTAILQ_FOREACH(vlan, &vlans, next) {
-        VLANClientState *vc;
-
         monitor_printf(mon, "VLAN %d devices:\n", vlan->id);
 
         QTAILQ_FOREACH(vc, &vlan->clients, next) {
             monitor_printf(mon, "  %s: %s\n", vc->name, vc->info_str);
         }
     }
+    monitor_printf(mon, "Devices not on any VLAN:\n");
+    QTAILQ_FOREACH(vc, &non_vlan_clients, next) {
+        monitor_printf(mon, "  %s: %s", vc->name, vc->info_str);
+        if (vc->peer) {
+            monitor_printf(mon, " peer=%s", vc->peer->name);
+        }
+        monitor_printf(mon, "\n");
+    }
 }
 
 void do_set_link(Monitor *mon, const QDict *qdict)
Signature · 1 line
1.6.6
#8 lore raw

PATCH 6/6 net: Monitor command set_link finds only VLAN clients, fix

In reply to Markus Armbruster

Clients not associated with a VLAN exist since commit d80b9fc6.

---
 net.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
net.c +1 -0
index fb89f94..029b0d7 100644
@@ -1243,6 +1243,7 @@ void do_set_link(Monitor *mon, const QDict *qdict)
             }
         }
     }
+    vc = qemu_find_netdev(name);
 done:
 
     if (!vc) {
Signature · 1 line
1.6.6
Acked-by on the v1 series
#9 lore raw
In reply to Markus Armbruster
Quoted 9 lines · Markus Armbruster

The fixes fall into three groups:

* Dead code removal.

* Fix bogus "Warning: vlan 0 with no nics" with -device

* When we added network clients not associated with a VLAN (-netdev & friends), we missed a few places. Fix them up.

Quoted 7 lines

Markus Armbruster (6):
net: Remove unused net_client_uninit()
net: net_check_clients() runs too early to see -device, fix
net: Fix bogus "Warning: vlan 0 with no nics" with -device
net: net_check_clients() checks only VLAN clients, fix
net: info network shows only VLAN clients, fix
net: Monitor command set_link finds only VLAN clients, fix

Nice. They all look good to me

Cheers,
Mark.