diff mbox

[v2,7/7] monitor/net: introduce 'info netdev' with QMP support

Message ID 1277909584-13012-8-git-send-email-miguel.filho@gmail.com
State New
Headers show

Commit Message

Miguel Di Ciurcio Filho June 30, 2010, 2:53 p.m. UTC
Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
---
 monitor.c |    8 +++++++
 net.c     |   71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 net.h     |    2 +
 3 files changed, 81 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/monitor.c b/monitor.c
index 170b269..b44768c 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2314,6 +2314,14 @@  static const mon_cmd_t info_cmds[] = {
         .mhandler.info = do_info_network,
     },
     {
+        .name       = "netdev",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show information about network backend devices",
+        .user_print = do_info_netdev_print,
+        .mhandler.info_new = do_info_netdev,
+    },
+    {
         .name       = "chardev",
         .args_type  = "",
         .params     = "",
diff --git a/net.c b/net.c
index 2936fe6..bbb8998 100644
--- a/net.c
+++ b/net.c
@@ -36,6 +36,8 @@ 
 #include "qemu-common.h"
 #include "qemu_socket.h"
 #include "hw/qdev.h"
+#include "qdict.h"
+#include "qjson.h"
 
 static QTAILQ_HEAD(, VLANState) vlans;
 static QTAILQ_HEAD(, VLANClientState) non_vlan_clients;
@@ -1249,6 +1251,75 @@  void do_info_network(Monitor *mon)
     }
 }
 
+static void netdev_iter(QObject *obj, void *opaque)
+{
+
+    Monitor *mon = opaque;
+    QDict *net_device = qobject_to_qdict(obj);
+    QString *qstring;
+
+    monitor_printf(mon, "%s: ", qdict_get_str(net_device, "id"));
+
+    monitor_printf(mon, "type=%s,", qdict_get_str(net_device, "type"));
+
+    if (qdict_haskey(net_device, "peer")) {
+        monitor_printf(mon, "peer=%s,", qdict_get_str(net_device, "peer"));
+    }
+
+    qstring = qdict_to_qstring(qdict_get_qdict(net_device, "info"), ",");
+    monitor_printf(mon, qstring_get_str(qstring));
+    QDECREF(qstring);
+
+    monitor_printf(mon, "\n");
+
+}
+
+void do_info_netdev_print(Monitor *mon, const QObject *ret_data)
+{
+
+    QList *net_devices;
+
+    net_devices = qobject_to_qlist(ret_data);
+
+    qlist_iter(net_devices, netdev_iter, mon);
+
+}
+
+void do_info_netdev(Monitor *mon, QObject **ret_data)
+{
+    VLANClientState *vc;
+    QDict *net_device;
+    QList *device_list;
+    device_list = qlist_new();
+    QObject *obj;
+
+    QTAILQ_FOREACH(vc, &non_vlan_clients, next) {
+
+        if (vc->info->type == NET_CLIENT_TYPE_NONE ||
+            vc->info->type == NET_CLIENT_TYPE_NIC ||
+            vc->info->type == NET_CLIENT_TYPE_SOCKET ||
+            vc->info->type == NET_CLIENT_TYPE_DUMP) {
+            continue;
+        }
+
+        obj = qobject_from_jsonf("{'id': %s, 'type': %s}",
+            vc->name, vc->model);
+
+        net_device = qobject_to_qdict(obj);
+
+        QINCREF(vc->info_dict);
+        qdict_put(net_device, "info", vc->info_dict);
+
+        if (vc->peer) {
+            qdict_put(net_device, "peer", qstring_from_str(vc->peer->name));
+        }
+
+        qlist_append(device_list, net_device);
+    }
+
+    *ret_data = QOBJECT(device_list);
+}
+
 int do_set_link(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
     VLANState *vlan;
diff --git a/net.h b/net.h
index cfe837f..69a3c9f 100644
--- a/net.h
+++ b/net.h
@@ -118,6 +118,8 @@  int qemu_find_nic_model(NICInfo *nd, const char * const *models,
                         const char *default_model);
 
 void do_info_network(Monitor *mon);
+void do_info_netdev_print(Monitor *mon, const QObject *ret_data);
+void do_info_netdev(Monitor *mon, QObject **ret_data);
 int do_set_link(Monitor *mon, const QDict *qdict, QObject **ret_data);
 
 /* NIC info */