qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
To: qemu-devel@nongnu.org
Cc: armbru@redhat.com, lcapitulino@redhat.com
Subject: [Qemu-devel] [PATCH v4 10/10] monitor/net: introduce 'info netdevices' with QMP support
Date: Tue, 18 May 2010 14:07:49 -0300	[thread overview]
Message-ID: <1274202469-9332-11-git-send-email-miguel.filho@gmail.com> (raw)
In-Reply-To: <1274202469-9332-1-git-send-email-miguel.filho@gmail.com>

To make the transition to QMP safe, we leave the current 'info network' command
as is, and introduce a new one: 'info netdevices'.

After tree series of patches, converting 'info network' to QMP have become
difficult, specially due to keep the monitor output compatible, since the
network device drivers arbritary write to an string about its state,
using no pattern.

Each device is represented by a QDict. The returned QObject is a QList
containing all devices.

(qemu) info netdevices
  tap.0: vlan=0,script=/etc/kvm/kvm-ifup,downscript=/etc/kvm/kvm-ifdown,model=tap,ifname=tap0
  e1000.0: vlan=0,model=e1000,macaddr=52:54:00:12:34:56

QMP sample:
{
   "return":[
      {
         "name":"tap.0",
         "vlan":0,
         "info":{
            "script":"/etc/kvm/kvm-ifup",
            "downscript":"/etc/kvm/kvm-ifdown",
            "model":"tap",
            "ifname":"tap0"
         }
      },
      {
         "name":"e1000.0",
         "vlan":0,
         "info":{
            "model":"e1000",
            "macaddr":"52:54:00:12:34:56"
         }
      }
   ]
}

Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
---
 monitor.c |    8 ++++++
 net.c     |   79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 net.h     |    2 +
 3 files changed, 89 insertions(+), 0 deletions(-)

diff --git a/monitor.c b/monitor.c
index 4c95d7b..0d1a0c1 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2423,6 +2423,14 @@ static const mon_cmd_t info_cmds[] = {
         .mhandler.info = do_info_network,
     },
     {
+        .name       = "netdevices",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show information about network devices",
+        .user_print = do_info_netdevices_print,
+        .mhandler.info_new = do_info_netdevices,
+    },
+    {
         .name       = "chardev",
         .args_type  = "",
         .params     = "",
diff --git a/net.c b/net.c
index 9e8a8ab..2757ed2 100644
--- a/net.c
+++ b/net.c
@@ -34,6 +34,7 @@
 #include "monitor.h"
 #include "sysemu.h"
 #include "qemu-common.h"
+#include "qjson.h"
 #include "qemu_socket.h"
 #include "hw/qdev.h"
 
@@ -1266,6 +1267,84 @@ void do_info_network(Monitor *mon)
     }
 }
 
+static void netdevices_iter(QObject *obj, void *opaque)
+{
+
+    Monitor *mon = opaque;
+    QDict *net_device = qobject_to_qdict(obj);
+
+
+    monitor_printf(mon, "  %s: ", qdict_get_str(net_device, "name"));
+
+    if (qdict_haskey(net_device, "vlan")) {
+        monitor_printf(mon, "vlan=%d,", (int)qdict_get_int(net_device, "vlan"));
+    }
+
+    if (qdict_haskey(net_device, "peer")) {
+        monitor_printf(mon, "peer=%s,", qdict_get_str(net_device, "peer"));
+    }
+
+    monitor_printf(mon,
+        qstring_get_str(qdict_to_qstring(qdict_get_qdict(net_device,
+"info"), ",")));
+
+    monitor_printf(mon, "\n");
+
+}
+
+void do_info_netdevices_print(Monitor *mon, const QObject *ret_data)
+{
+
+    QList *net_devices;
+
+    net_devices = qobject_to_qlist(ret_data);
+
+    qlist_iter(net_devices, netdevices_iter, mon);
+
+}
+
+void do_info_netdevices(Monitor *mon, QObject **ret_data)
+{
+    VLANState *vlan;
+    VLANClientState *vc;
+    QDict *net_device;
+    QList *device_list;
+    device_list = qlist_new();
+    QObject *obj;
+
+    QTAILQ_FOREACH(vlan, &vlans, next) {
+
+        QTAILQ_FOREACH(vc, &vlan->clients, next) {
+
+            obj = qobject_from_jsonf("{ 'vlan': %d, 'name': %s }", vlan->id,
+                        vc->name);
+            net_device = qobject_to_qdict(obj);
+
+            QINCREF(vc->info_dict);
+            qdict_put(net_device, "info", vc->info_dict);
+
+            qlist_append(device_list, net_device);
+
+        }
+    }
+
+    QTAILQ_FOREACH(vc, &non_vlan_clients, next) {
+        obj = qobject_from_jsonf("{ 'name': %s }", vc->name);
+        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 4566f7d..9b3700c 100644
--- a/net.h
+++ b/net.h
@@ -120,6 +120,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_netdevices_print(Monitor *mon, const QObject *ret_data);
+void do_info_netdevices(Monitor *mon, QObject **ret_data);
 int do_set_link(Monitor *mon, const QDict *qdict, QObject **ret_data);
 
 /* NIC info */
-- 
1.7.1

  parent reply	other threads:[~2010-05-18 17:19 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-18 17:07 [Qemu-devel] [PATCH v4 0/10] Introduce 'info netdevices' with QMP support Miguel Di Ciurcio Filho
2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 01/10] QObject API: introduce qdict_to_qstring() function Miguel Di Ciurcio Filho
2010-05-27 17:50   ` [Qemu-devel] " Luiz Capitulino
2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 02/10] net: introduce qemu_nic_format_info_dict and VLANClientState->info_dict Miguel Di Ciurcio Filho
2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 03/10] net: various devices: add qemu_format_nic_info_dict Miguel Di Ciurcio Filho
2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 04/10] net: xen: introduce info_dict Miguel Di Ciurcio Filho
2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 05/10] net: tap/tap-win32: " Miguel Di Ciurcio Filho
2010-05-27 17:50   ` [Qemu-devel] " Luiz Capitulino
2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 06/10] net: vde: " Miguel Di Ciurcio Filho
2010-05-27 17:51   ` [Qemu-devel] " Luiz Capitulino
2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 07/10] net: dump: " Miguel Di Ciurcio Filho
2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 08/10] net: slirp: " Miguel Di Ciurcio Filho
2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 09/10] net: socket: " Miguel Di Ciurcio Filho
2010-05-18 17:07 ` Miguel Di Ciurcio Filho [this message]
2010-05-27 17:50 ` [Qemu-devel] Re: [PATCH v4 0/10] Introduce 'info netdevices' with QMP support Luiz Capitulino

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1274202469-9332-11-git-send-email-miguel.filho@gmail.com \
    --to=miguel.filho@gmail.com \
    --cc=armbru@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).