Skip to contentSkip to conversation

net: Improve layout of 'info network'

PATCH Superseded Jan Kiszka 2 participants 2 messages May 17, 2011 – May 18, 2011

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/2 net: Improve layout of 'info network'

Improve the layout when listing non-vlan clients via 'info network'. The result looks like this:

(qemu) info network
Devices not on any VLAN:
orphan: net=10.0.2.0, restricted=n
virtio-net-pci.0: model=virtio-net-pci,macaddr=52:54:00:12:34:56
\ network2: fd=5
e1000.0: model=e1000,macaddr=52:54:00:12:34:57
\ network1: net=10.0.2.0, restricted=n
rtl8139.0: model=rtl8139,macaddr=52:54:00:12:34:58

ie. peers are grouped, orphans are listed as before.

---
 net.c |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)
net.c +9 -5
index 4f777c3..606ce70 100644
@@ -1224,7 +1224,8 @@ int do_netdev_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
 void do_info_network(Monitor *mon)
 {
     VLANState *vlan;
-    VLANClientState *vc;
+    VLANClientState *vc, *peer;
+    net_client_type type;
 
     QTAILQ_FOREACH(vlan, &vlans, next) {
         monitor_printf(mon, "VLAN %d devices:\n", vlan->id);
@@ -1235,11 +1236,14 @@ void do_info_network(Monitor *mon)
     }
     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);
+        peer = vc->peer;
+        type = vc->info->type;
+        if (!peer || type == NET_CLIENT_TYPE_NIC) {
+            monitor_printf(mon, "  %s: %s\n", vc->name, vc->info_str);
+        }
+        if (peer && type == NET_CLIENT_TYPE_NIC) {
+            monitor_printf(mon, "   \\ %s: %s\n", peer->name, peer->info_str);
         }
-        monitor_printf(mon, "\n");
     }
 }
 
Signature · 1 line
1.7.1
#1 lore raw
Quoted 12 lines · Jan Kiszka

Improve the layout when listing non-vlan clients via 'info network'. The result looks like this:

(qemu) info network
Devices not on any VLAN:
orphan: net=10.0.2.0, restricted=n
virtio-net-pci.0: model=virtio-net-pci,macaddr=52:54:00:12:34:56
\ network2: fd=5
e1000.0: model=e1000,macaddr=52:54:00:12:34:57
\ network1: net=10.0.2.0, restricted=n
rtl8139.0: model=rtl8139,macaddr=52:54:00:12:34:58

Quoted 1 line

ie. peers are grouped, orphans are listed as before.

Cute :)

Quoted 27 lines
---
 net.c |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)
net.c +3 -4
index 4f777c3..606ce70 100644
@@ -1224,7 +1224,8 @@ int do_netdev_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
 void do_info_network(Monitor *mon)
 {
     VLANState *vlan;
-    VLANClientState *vc;
+    VLANClientState *vc, *peer;
+    net_client_type type;
 
     QTAILQ_FOREACH(vlan, &vlans, next) {
         monitor_printf(mon, "VLAN %d devices:\n", vlan->id);
@@ -1235,11 +1236,14 @@ void do_info_network(Monitor *mon)
     }
     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);
+        peer = vc->peer;

net.c void do_info_network(Monitor *mon) · line 1248

Quoted 10 lines
net.c +6 -1
+        type = vc->info->type;
+        if (!peer || type == NET_CLIENT_TYPE_NIC) {
+            monitor_printf(mon, "  %s: %s\n", vc->name, vc->info_str);
+        }
+        if (peer && type == NET_CLIENT_TYPE_NIC) {
+            monitor_printf(mon, "   \\ %s: %s\n", peer->name, peer->info_str);
         }
-        monitor_printf(mon, "\n");
     }
 }

Before: print all members of non_vlan_clients. Show any peering with "peer=ID".

After:

1. print any NIC and any non-NIC without a peer (first if)

2. print NIC's peer, if any (second if)

1+2 together cover all members. Okay. But not obvious to me. Care to explain n a comment? Perhaps something like:

        if (!peer || type == NET_CLIENT_TYPE_NIC) {
            monitor_printf(mon, "  %s: %s\n", vc->name, vc->info_str);
        } /* else it's a netdev connected to a NIC, printed with the NIC */
        if (peer && type == NET_CLIENT_TYPE_NIC) {
            monitor_printf(mon, "   \\ %s: %s\n", peer->name, peer->info_str);
        }