All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/8] QMP: Introduce query-netdev
@ 2010-06-10 21:36 Miguel Di Ciurcio Filho
  2010-06-10 21:36 ` [Qemu-devel] [PATCH 1/8] QObject API: introduce qdict_to_qstring() function Miguel Di Ciurcio Filho
                   ` (8 more replies)
  0 siblings, 9 replies; 16+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-06-10 21:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: avi, armbru, lcapitulino

This series introduces the protocol specification for querying the backend
network devices and a monitor command to show the same information.

Patch 01 adds a new function qdict_to_qstring().

Patch 02 adds the documentation for query-netdev.

Patch 03 adds a new QDict member to VLANClientState named info_dict.

Patches 04-07 updates all devices to feed information into the new QDict
info_dict.

Patch 08 implements do_info_netdev() for query-netdev and the monitor
command 'info netdev'.

Regards,

Miguel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 1/8] QObject API: introduce qdict_to_qstring() function
  2010-06-10 21:36 [Qemu-devel] [PATCH 0/8] QMP: Introduce query-netdev Miguel Di Ciurcio Filho
@ 2010-06-10 21:36 ` Miguel Di Ciurcio Filho
  2010-06-10 21:36 ` [Qemu-devel] [PATCH 2/8] QMP: Introduce the documentation for query-netdev and info netdev Miguel Di Ciurcio Filho
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-06-10 21:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, lcapitulino, Miguel Di Ciurcio Filho, avi

This is a helper function that converts a QDict to a QString, using
the format:

key1=value1 SEP key2=value2 SEP key3=value3

Handy for debugging and formating the Monitor output.

Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
---
 qdict.c |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 qdict.h |    2 ++
 2 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/qdict.c b/qdict.c
index 175bc17..dc95199 100644
--- a/qdict.c
+++ b/qdict.c
@@ -267,6 +267,66 @@ const char *qdict_get_str(const QDict *qdict, const char *key)
     return qstring_get_str(qobject_to_qstring(obj));
 }
 
+struct qstring_pack {
+    QString *str;
+    size_t total_keys;
+    size_t current_key;
+    const char *separator;
+};
+
+static void qdict_to_qstring_iter(const char *key, QObject *obj, void *opaque)
+{
+    struct qstring_pack *pack = opaque;
+    qstring_append(pack->str, key);
+    qstring_append(pack->str, "=");
+    switch (qobject_type(obj)) {
+    case QTYPE_QSTRING:
+        qstring_append(pack->str, qstring_get_str(qobject_to_qstring(obj)));
+        break;
+    case QTYPE_QINT:
+        qstring_append_int(pack->str, qint_get_int(qobject_to_qint(obj)));
+        break;
+    case QTYPE_QBOOL:
+        qstring_append(pack->str, qbool_get_int(qobject_to_qbool(obj)) ? "true" :
+        "false" );
+        break;
+    default:
+        qstring_append(pack->str, "NULL");
+    }
+
+    pack->current_key++;
+
+    if (pack->current_key < pack->total_keys) {
+        qstring_append(pack->str, pack->separator);
+    }
+}
+
+/**
+ * qdict_to_qstring(): Format a string with the keys and values of a QDict.
+ *
+ * Nested lists and dicts are not supported, yet.
+ *
+ * Return a pointer to a QString, with the following format:
+ *    key1=value1 SEP key2=value2 SEP key3=value3
+ */
+QString *qdict_to_qstring(const QDict *qdict, const char *separator)
+{
+    struct qstring_pack *pack;
+    QString *str;
+    str = qstring_new();
+
+    pack = qemu_malloc(sizeof(*pack));
+    pack->str = str;
+    pack->current_key = 0;
+    pack->total_keys = qdict_size(qdict);
+    pack->separator = separator;
+
+    qdict_iter(qdict, qdict_to_qstring_iter, pack);
+
+    qemu_free(pack);
+
+    return str;
+}
 /**
  * qdict_get_try_int(): Try to get integer mapped by 'key'
  *
diff --git a/qdict.h b/qdict.h
index 5e5902c..0c64089 100644
--- a/qdict.h
+++ b/qdict.h
@@ -15,6 +15,7 @@
 
 #include "qobject.h"
 #include "qlist.h"
+#include "qstring.h"
 #include "qemu-queue.h"
 #include <stdint.h>
 
@@ -55,6 +56,7 @@ int qdict_get_bool(const QDict *qdict, const char *key);
 QList *qdict_get_qlist(const QDict *qdict, const char *key);
 QDict *qdict_get_qdict(const QDict *qdict, const char *key);
 const char *qdict_get_str(const QDict *qdict, const char *key);
+QString *qdict_to_qstring(const QDict *qdict, const char *separator);
 int64_t qdict_get_try_int(const QDict *qdict, const char *key,
                           int64_t err_value);
 const char *qdict_get_try_str(const QDict *qdict, const char *key);
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 2/8] QMP: Introduce the documentation for query-netdev and info netdev
  2010-06-10 21:36 [Qemu-devel] [PATCH 0/8] QMP: Introduce query-netdev Miguel Di Ciurcio Filho
  2010-06-10 21:36 ` [Qemu-devel] [PATCH 1/8] QObject API: introduce qdict_to_qstring() function Miguel Di Ciurcio Filho
@ 2010-06-10 21:36 ` Miguel Di Ciurcio Filho
  2010-06-11 11:37   ` Markus Armbruster
  2010-06-16 17:39   ` [Qemu-devel] " Luiz Capitulino
  2010-06-10 21:37 ` [Qemu-devel] [PATCH 3/8] net: Introduce VLANClientState->info_dict Miguel Di Ciurcio Filho
                   ` (6 subsequent siblings)
  8 siblings, 2 replies; 16+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-06-10 21:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, lcapitulino, Miguel Di Ciurcio Filho, avi

These commands show the information about active backend network devices.

Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
---
 qemu-monitor.hx |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/qemu-monitor.hx b/qemu-monitor.hx
index f6a94f2..14a0ba1 100644
--- a/qemu-monitor.hx
+++ b/qemu-monitor.hx
@@ -1674,6 +1674,59 @@ show the various VLANs and the associated devices
 ETEXI
 
 STEXI
+@item info netdev
+show information about the current backend network devices
+ETEXI
+SQMP
+query-netdev
+----------------
+
+Each device is represented by a json-object. The returned value is a json-array
+of all devices.
+
+Each json-object contain the following:
+
+- "id": the device's ID, must be unique (json-string)
+- "vlan": QEMU's internal vlan identification. Only present if the device is
+  attached to a VLAN (json-int, optional)
+- "peer": ID of the frontend device when on a 1:1 relationship (json-string,
+  optional)
+- "info": json-object containing the configuration information about the device.
+
+Note: The supported device information is the same one supported by the '-net'
+command-line argument, which are listed in the '-help' output or QEMU's manual.
+
+Example:
+
+-> { "execute": "query-netdev" }
+<- {
+      "return": [
+         {
+            "id": "tap.0",
+            "type": "tap",
+            "vlan": 0,
+            "info": {
+               "script": "/etc/qemu-ifup",
+               "downscript": "/etc/qemu-ifdown",
+               "ifname": "tap0",
+               "vhost": true
+            },
+         },
+         {
+            "id": "user.0",
+            "type": "user",
+            "peer": "e1000.0",
+            "info": {
+               "net": "10.0.2.0",
+               "netmask": "255.255.255.0"
+            },
+         },
+      ]
+   }
+
+EQMP
+
+STEXI
 @item info chardev
 show the character devices
 ETEXI
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 3/8] net: Introduce VLANClientState->info_dict
  2010-06-10 21:36 [Qemu-devel] [PATCH 0/8] QMP: Introduce query-netdev Miguel Di Ciurcio Filho
  2010-06-10 21:36 ` [Qemu-devel] [PATCH 1/8] QObject API: introduce qdict_to_qstring() function Miguel Di Ciurcio Filho
  2010-06-10 21:36 ` [Qemu-devel] [PATCH 2/8] QMP: Introduce the documentation for query-netdev and info netdev Miguel Di Ciurcio Filho
@ 2010-06-10 21:37 ` Miguel Di Ciurcio Filho
  2010-06-16 17:40   ` [Qemu-devel] " Luiz Capitulino
  2010-06-10 21:37 ` [Qemu-devel] [PATCH 4/8] net: tap/tap-win32: introduce info_dict Miguel Di Ciurcio Filho
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 16+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-06-10 21:37 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, lcapitulino, Miguel Di Ciurcio Filho, avi

There is no standard format when formatting VLANClientState.info_str,
so it is difficult to extract information and transmit it over QMP.

This patch adds info_dict, a QDict to better handle this information.

Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
---
 net.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/net.h b/net.h
index b83f615..acc1645 100644
--- a/net.h
+++ b/net.h
@@ -66,6 +66,7 @@ struct VLANClientState {
     char *model;
     char *name;
     char info_str[256];
+    QDict *info_dict;
     unsigned receive_disabled : 1;
 };
 
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 4/8] net: tap/tap-win32: introduce info_dict
  2010-06-10 21:36 [Qemu-devel] [PATCH 0/8] QMP: Introduce query-netdev Miguel Di Ciurcio Filho
                   ` (2 preceding siblings ...)
  2010-06-10 21:37 ` [Qemu-devel] [PATCH 3/8] net: Introduce VLANClientState->info_dict Miguel Di Ciurcio Filho
@ 2010-06-10 21:37 ` Miguel Di Ciurcio Filho
  2010-06-16 17:41   ` [Qemu-devel] " Luiz Capitulino
  2010-06-10 21:37 ` [Qemu-devel] [PATCH 5/8] net: vde: " Miguel Di Ciurcio Filho
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 16+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-06-10 21:37 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, lcapitulino, Miguel Di Ciurcio Filho, avi

Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
---
 net/tap-win32.c |    6 ++++++
 net/tap.c       |   20 ++++++++++++++++++++
 2 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/net/tap-win32.c b/net/tap-win32.c
index 74348da..3833592 100644
--- a/net/tap-win32.c
+++ b/net/tap-win32.c
@@ -32,6 +32,8 @@
 #include "net.h"
 #include "sysemu.h"
 #include "qemu-error.h"
+#include "qdict.h"
+#include "qstring.h"
 #include <stdio.h>
 #include <windows.h>
 #include <winioctl.h>
@@ -693,6 +695,10 @@ static int tap_win32_init(VLANState *vlan, const char *model,
     snprintf(s->nc.info_str, sizeof(s->nc.info_str),
              "tap: ifname=%s", ifname);
 
+    nc->info_dict = qdict_new()
+
+    qdict_put(nc->info_dict, "ifname", qstring_from_str(ifname));
+
     s->handle = handle;
 
     qemu_add_wait_object(s->handle->tap_semaphore, tap_win32_send, s);
diff --git a/net/tap.c b/net/tap.c
index 0147dab..30ed3da 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -39,6 +39,9 @@
 #include "qemu-char.h"
 #include "qemu-common.h"
 #include "qemu-error.h"
+#include "qjson.h"
+#include "qint.h"
+#include "qbool.h"
 
 #include "net/tap-linux.h"
 
@@ -448,8 +451,13 @@ int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan
 
     if (qemu_opt_get(opts, "fd")) {
         snprintf(s->nc.info_str, sizeof(s->nc.info_str), "fd=%d", fd);
+        assert(s->nc.info_dict == NULL);
+
+        s->nc.info_dict = qdict_new();
+        qdict_put(s->nc.info_dict, "fd", qint_from_int(fd));
     } else {
         const char *ifname, *script, *downscript;
+        QObject *obj;
 
         ifname     = qemu_opt_get(opts, "ifname");
         script     = qemu_opt_get(opts, "script");
@@ -459,10 +467,19 @@ int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan
                  "ifname=%s,script=%s,downscript=%s",
                  ifname, script, downscript);
 
+        obj = qobject_from_jsonf("{ 'ifname': %s, \
+            'script': %s,'downscript': %s }",
+            ifname, script, downscript);
+
+        assert(s->nc.info_dict == NULL);
+        s->nc.info_dict = qobject_to_qdict(obj);
+
         if (strcmp(downscript, "no") != 0) {
             snprintf(s->down_script, sizeof(s->down_script), "%s", downscript);
             snprintf(s->down_script_arg, sizeof(s->down_script_arg), "%s", ifname);
         }
+
+
     }
 
     if (qemu_opt_get_bool(opts, "vhost", !!qemu_opt_get(opts, "vhostfd"))) {
@@ -481,6 +498,9 @@ int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan
             error_report("vhost-net requested but could not be initialized");
             return -1;
         }
+        qdict_put(s->nc.info_dict, "vhost", qbool_from_int(1));
+        qdict_put(s->nc.info_dict, "vhostfd", qint_from_int(vhostfd));
+
     } else if (qemu_opt_get(opts, "vhostfd")) {
         error_report("vhostfd= is not valid without vhost");
         return -1;
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 5/8] net: vde: introduce info_dict
  2010-06-10 21:36 [Qemu-devel] [PATCH 0/8] QMP: Introduce query-netdev Miguel Di Ciurcio Filho
                   ` (3 preceding siblings ...)
  2010-06-10 21:37 ` [Qemu-devel] [PATCH 4/8] net: tap/tap-win32: introduce info_dict Miguel Di Ciurcio Filho
@ 2010-06-10 21:37 ` Miguel Di Ciurcio Filho
  2010-06-10 21:37 ` [Qemu-devel] [PATCH 6/8] net: socket: " Miguel Di Ciurcio Filho
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-06-10 21:37 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, lcapitulino, Miguel Di Ciurcio Filho, avi

Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
---
 net/vde.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/net/vde.c b/net/vde.c
index 0b46fa6..0fe7c09 100644
--- a/net/vde.c
+++ b/net/vde.c
@@ -31,6 +31,9 @@
 #include "qemu-char.h"
 #include "qemu-common.h"
 #include "qemu-option.h"
+#include "qdict.h"
+#include "qstring.h"
+#include "qint.h"
 #include "sysemu.h"
 
 typedef struct VDEState {
@@ -102,6 +105,11 @@ static int net_vde_init(VLANState *vlan, const char *model,
     snprintf(nc->info_str, sizeof(nc->info_str), "sock=%s,fd=%d",
              sock, vde_datafd(vde));
 
+    assert(nc->info_dict == NULL);
+    nc->info_dict = qdict_new();
+    qdict_put(nc->info_dict, "sock", qstring_from_str(sock));
+    qdict_put(nc->info_dict, "fd", qint_from_int(vde_datafd(vde)));
+
     s = DO_UPCAST(VDEState, nc, nc);
 
     s->vde = vde;
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 6/8] net: socket: introduce info_dict
  2010-06-10 21:36 [Qemu-devel] [PATCH 0/8] QMP: Introduce query-netdev Miguel Di Ciurcio Filho
                   ` (4 preceding siblings ...)
  2010-06-10 21:37 ` [Qemu-devel] [PATCH 5/8] net: vde: " Miguel Di Ciurcio Filho
@ 2010-06-10 21:37 ` Miguel Di Ciurcio Filho
  2010-06-10 21:37 ` [Qemu-devel] [PATCH 7/8] net: slirp: " Miguel Di Ciurcio Filho
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-06-10 21:37 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, lcapitulino, Miguel Di Ciurcio Filho, avi

Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
---
 net/socket.c |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/net/socket.c b/net/socket.c
index 1c4e153..aad9eb8 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -28,6 +28,7 @@
 #include "net.h"
 #include "qemu-char.h"
 #include "qemu-common.h"
+#include "qjson.h"
 #include "qemu-error.h"
 #include "qemu-option.h"
 #include "qemu_socket.h"
@@ -49,6 +50,15 @@ typedef struct NetSocketListenState {
     int fd;
 } NetSocketListenState;
 
+static QDict *net_socket_format_info_dict(const char *host,
+                                        int service,
+                                        const char *family,
+                                        int is_server)
+{
+    return qobject_to_qdict(qobject_from_jsonf("{'host': %s, 'family': %s, \
+            'service': %d, 'server': %i }", host, family, service, is_server));
+}
+
 /* XXX: we consider we can send the whole packet without blocking */
 static ssize_t net_socket_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
 {
@@ -369,6 +379,9 @@ static void net_socket_accept(void *opaque)
         snprintf(s1->nc.info_str, sizeof(s1->nc.info_str),
                  "socket: connection from %s:%d",
                  inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
+
+        s1->nc.info_dict = net_socket_format_info_dict(inet_ntoa(saddr.sin_addr),
+            ntohs(saddr.sin_port), "ipv4", 1);
     }
 }
 
@@ -462,6 +475,10 @@ static int net_socket_connect_init(VLANState *vlan,
     snprintf(s->nc.info_str, sizeof(s->nc.info_str),
              "socket: connect to %s:%d",
              inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
+
+    s->nc.info_dict = net_socket_format_info_dict(inet_ntoa(saddr.sin_addr),
+        ntohs(saddr.sin_port), "ipv4", 0);
+
     return 0;
 }
 
@@ -491,6 +508,10 @@ static int net_socket_mcast_init(VLANState *vlan,
     snprintf(s->nc.info_str, sizeof(s->nc.info_str),
              "socket: mcast=%s:%d",
              inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
+
+    s->nc.info_dict = net_socket_format_info_dict(inet_ntoa(saddr.sin_addr),
+        ntohs(saddr.sin_port), "ipv4", 0);
+
     return 0;
 
 }
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 7/8] net: slirp: introduce info_dict
  2010-06-10 21:36 [Qemu-devel] [PATCH 0/8] QMP: Introduce query-netdev Miguel Di Ciurcio Filho
                   ` (5 preceding siblings ...)
  2010-06-10 21:37 ` [Qemu-devel] [PATCH 6/8] net: socket: " Miguel Di Ciurcio Filho
@ 2010-06-10 21:37 ` Miguel Di Ciurcio Filho
  2010-06-10 21:37 ` [Qemu-devel] [PATCH 8/8] monitor/net: introduce 'info netdev' with QMP support Miguel Di Ciurcio Filho
  2010-06-16 17:44 ` [Qemu-devel] Re: [PATCH 0/8] QMP: Introduce query-netdev Luiz Capitulino
  8 siblings, 0 replies; 16+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-06-10 21:37 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, lcapitulino, Miguel Di Ciurcio Filho, avi

Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
---
 net/slirp.c |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/net/slirp.c b/net/slirp.c
index b41c60a..5735009 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -32,6 +32,10 @@
 #include "monitor.h"
 #include "sysemu.h"
 #include "qemu_socket.h"
+#include "qdict.h"
+#include "qbool.h"
+#include "qstring.h"
+#include "qjson.h"
 #include "slirp/libslirp.h"
 
 static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
@@ -243,6 +247,12 @@ static int net_slirp_init(VLANState *vlan, const char *model,
     snprintf(nc->info_str, sizeof(nc->info_str),
              "net=%s, restricted=%c", inet_ntoa(net), restricted ? 'y' : 'n');
 
+    assert(nc->info_dict == NULL);
+    nc->info_dict = qobject_to_qdict(qobject_from_jsonf("{'net': %s,\
+        'host': %s, 'dhcp': %s, 'dns': %s }", inet_ntoa(net), inet_ntoa(host),
+                        inet_ntoa(dhcp), inet_ntoa(dns)));
+    qdict_put(nc->info_dict, "restricted", qbool_from_int(restricted));
+
     s = DO_UPCAST(SlirpState, nc, nc);
 
     s->slirp = slirp_init(restricted, net, mask, host, vhostname,
@@ -265,8 +275,13 @@ static int net_slirp_init(VLANState *vlan, const char *model,
         smb_export = legacy_smb_export;
     }
     if (smb_export) {
-        if (slirp_smb(s, smb_export, smbsrv) < 0)
+        if (slirp_smb(s, smb_export, smbsrv) < 0) {
             goto error;
+        } else {
+            qdict_put(nc->info_dict, "smb", qstring_from_str(smb_export));
+            qdict_put(nc->info_dict, "smbserver",
+                qstring_from_str(inet_ntoa(smbsrv)));
+        }
     }
 #endif
 
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 8/8] monitor/net: introduce 'info netdev' with QMP support
  2010-06-10 21:36 [Qemu-devel] [PATCH 0/8] QMP: Introduce query-netdev Miguel Di Ciurcio Filho
                   ` (6 preceding siblings ...)
  2010-06-10 21:37 ` [Qemu-devel] [PATCH 7/8] net: slirp: " Miguel Di Ciurcio Filho
@ 2010-06-10 21:37 ` Miguel Di Ciurcio Filho
  2010-06-16 17:44 ` [Qemu-devel] Re: [PATCH 0/8] QMP: Introduce query-netdev Luiz Capitulino
  8 siblings, 0 replies; 16+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-06-10 21:37 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, lcapitulino, Miguel Di Ciurcio Filho, avi

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

diff --git a/monitor.c b/monitor.c
index 15b53b9..0038214 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2425,6 +2425,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 4cb93ed..ed68b61 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;
@@ -1252,6 +1254,100 @@ void do_info_network(Monitor *mon)
     }
 }
 
+static void netdev_iter(QObject *obj, void *opaque)
+{
+
+    Monitor *mon = opaque;
+    QDict *net_device = qobject_to_qdict(obj);
+
+    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, "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_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)
+{
+    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) {
+
+            if (vc->info->type == NET_CLIENT_TYPE_NONE ||
+                vc->info->type == NET_CLIENT_TYPE_NIC ||
+                vc->info->type == NET_CLIENT_TYPE_DUMP) {
+                continue;
+            }
+
+            obj = qobject_from_jsonf("{ 'vlan': %d, 'id': %s, 'type': %s}", vlan->id,
+                        vc->name, vc->model);
+
+            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) {
+
+        if (vc->info->type == NET_CLIENT_TYPE_NONE ||
+            vc->info->type == NET_CLIENT_TYPE_NIC ||
+            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 acc1645..65bbf27 100644
--- a/net.h
+++ b/net.h
@@ -119,6 +119,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 */
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 2/8] QMP: Introduce the documentation for query-netdev and info netdev
  2010-06-10 21:36 ` [Qemu-devel] [PATCH 2/8] QMP: Introduce the documentation for query-netdev and info netdev Miguel Di Ciurcio Filho
@ 2010-06-11 11:37   ` Markus Armbruster
  2010-06-11 11:47     ` Miguel Di Ciurcio Filho
  2010-06-16 17:39   ` [Qemu-devel] " Luiz Capitulino
  1 sibling, 1 reply; 16+ messages in thread
From: Markus Armbruster @ 2010-06-11 11:37 UTC (permalink / raw)
  To: Miguel Di Ciurcio Filho; +Cc: avi, qemu-devel, lcapitulino

Miguel Di Ciurcio Filho <miguel.filho@gmail.com> writes:

> These commands show the information about active backend network devices.
>
> Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
> ---
>  qemu-monitor.hx |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 53 insertions(+), 0 deletions(-)
>
> diff --git a/qemu-monitor.hx b/qemu-monitor.hx
> index f6a94f2..14a0ba1 100644
> --- a/qemu-monitor.hx
> +++ b/qemu-monitor.hx
> @@ -1674,6 +1674,59 @@ show the various VLANs and the associated devices
>  ETEXI
>  
>  STEXI
> +@item info netdev
> +show information about the current backend network devices
> +ETEXI
> +SQMP
> +query-netdev
> +----------------
> +
> +Each device is represented by a json-object. The returned value is a json-array
> +of all devices.
> +
> +Each json-object contain the following:
> +
> +- "id": the device's ID, must be unique (json-string)
> +- "vlan": QEMU's internal vlan identification. Only present if the device is
> +  attached to a VLAN (json-int, optional)
> +- "peer": ID of the frontend device when on a 1:1 relationship (json-string,
> +  optional)
> +- "info": json-object containing the configuration information about the device.

Didn't we agree to have two separate query commands, one for net devices
on VLANs, and another one for the rest?

> +
> +Note: The supported device information is the same one supported by the '-net'
> +command-line argument, which are listed in the '-help' output or QEMU's manual.

Not sure a pointer to -help suffices here.

[...]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 2/8] QMP: Introduce the documentation for query-netdev and info netdev
  2010-06-11 11:37   ` Markus Armbruster
@ 2010-06-11 11:47     ` Miguel Di Ciurcio Filho
  0 siblings, 0 replies; 16+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-06-11 11:47 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: avi, qemu-devel, lcapitulino

On Fri, Jun 11, 2010 at 8:37 AM, Markus Armbruster <armbru@redhat.com> wrote:
>> +- "id": the device's ID, must be unique (json-string)
>> +- "vlan": QEMU's internal vlan identification. Only present if the device is
>> +  attached to a VLAN (json-int, optional)
>> +- "peer": ID of the frontend device when on a 1:1 relationship (json-string,
>> +  optional)
>> +- "info": json-object containing the configuration information about the device.
>
> Didn't we agree to have two separate query commands, one for net devices
> on VLANs, and another one for the rest?
>

There were no consensus or requirement about that on the previous thread.

>> +
>> +Note: The supported device information is the same one supported by the '-net'
>> +command-line argument, which are listed in the '-help' output or QEMU's manual.
>
> Not sure a pointer to -help suffices here.
>

Various parts of the documentation have the same structure: e.g.:
netdev_add. If it is really necessary, I could send a new version
without just a pointer to -help.

Regards,

Miguel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Qemu-devel] Re: [PATCH 2/8] QMP: Introduce the documentation for query-netdev and info netdev
  2010-06-10 21:36 ` [Qemu-devel] [PATCH 2/8] QMP: Introduce the documentation for query-netdev and info netdev Miguel Di Ciurcio Filho
  2010-06-11 11:37   ` Markus Armbruster
@ 2010-06-16 17:39   ` Luiz Capitulino
  2010-06-16 21:55     ` Miguel Di Ciurcio Filho
  1 sibling, 1 reply; 16+ messages in thread
From: Luiz Capitulino @ 2010-06-16 17:39 UTC (permalink / raw)
  To: Miguel Di Ciurcio Filho; +Cc: avi, qemu-devel, armbru

On Thu, 10 Jun 2010 18:36:59 -0300
Miguel Di Ciurcio Filho <miguel.filho@gmail.com> wrote:

> These commands show the information about active backend network devices.
> 
> Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
> ---
>  qemu-monitor.hx |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 53 insertions(+), 0 deletions(-)
> 
> diff --git a/qemu-monitor.hx b/qemu-monitor.hx
> index f6a94f2..14a0ba1 100644
> --- a/qemu-monitor.hx
> +++ b/qemu-monitor.hx
> @@ -1674,6 +1674,59 @@ show the various VLANs and the associated devices
>  ETEXI
>  
>  STEXI
> +@item info netdev
> +show information about the current backend network devices
> +ETEXI
> +SQMP
> +query-netdev
> +----------------
> +
> +Each device is represented by a json-object. The returned value is a json-array
> +of all devices.
> +
> +Each json-object contain the following:
> +
> +- "id": the device's ID, must be unique (json-string)
> +- "vlan": QEMU's internal vlan identification. Only present if the device is
> +  attached to a VLAN (json-int, optional)
> +- "peer": ID of the frontend device when on a 1:1 relationship (json-string,
> +  optional)

 'type' is missing.

> +- "info": json-object containing the configuration information about the device.

 We need a list of all backends (maybe in 'type') and then we need to list all
possible cases for 'info'.

 I have some other comments, otherwise looks good.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Qemu-devel] Re: [PATCH 3/8] net: Introduce VLANClientState->info_dict
  2010-06-10 21:37 ` [Qemu-devel] [PATCH 3/8] net: Introduce VLANClientState->info_dict Miguel Di Ciurcio Filho
@ 2010-06-16 17:40   ` Luiz Capitulino
  0 siblings, 0 replies; 16+ messages in thread
From: Luiz Capitulino @ 2010-06-16 17:40 UTC (permalink / raw)
  To: Miguel Di Ciurcio Filho; +Cc: avi, qemu-devel, armbru

On Thu, 10 Jun 2010 18:37:00 -0300
Miguel Di Ciurcio Filho <miguel.filho@gmail.com> wrote:

> There is no standard format when formatting VLANClientState.info_str,
> so it is difficult to extract information and transmit it over QMP.
> 
> This patch adds info_dict, a QDict to better handle this information.
> 
> Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
> ---
>  net.h |    1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
> 
> diff --git a/net.h b/net.h
> index b83f615..acc1645 100644
> --- a/net.h
> +++ b/net.h
> @@ -66,6 +66,7 @@ struct VLANClientState {
>      char *model;
>      char *name;
>      char info_str[256];
> +    QDict *info_dict;
>      unsigned receive_disabled : 1;
>  };
>  

 You need to free it, you had a patch for that.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Qemu-devel] Re: [PATCH 4/8] net: tap/tap-win32: introduce info_dict
  2010-06-10 21:37 ` [Qemu-devel] [PATCH 4/8] net: tap/tap-win32: introduce info_dict Miguel Di Ciurcio Filho
@ 2010-06-16 17:41   ` Luiz Capitulino
  0 siblings, 0 replies; 16+ messages in thread
From: Luiz Capitulino @ 2010-06-16 17:41 UTC (permalink / raw)
  To: Miguel Di Ciurcio Filho; +Cc: avi, qemu-devel, armbru

On Thu, 10 Jun 2010 18:37:01 -0300
Miguel Di Ciurcio Filho <miguel.filho@gmail.com> wrote:

> Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
> ---
>  net/tap-win32.c |    6 ++++++
>  net/tap.c       |   20 ++++++++++++++++++++
>  2 files changed, 26 insertions(+), 0 deletions(-)
> 
> diff --git a/net/tap-win32.c b/net/tap-win32.c
> index 74348da..3833592 100644
> --- a/net/tap-win32.c
> +++ b/net/tap-win32.c
> @@ -32,6 +32,8 @@
>  #include "net.h"
>  #include "sysemu.h"
>  #include "qemu-error.h"
> +#include "qdict.h"
> +#include "qstring.h"
>  #include <stdio.h>
>  #include <windows.h>
>  #include <winioctl.h>
> @@ -693,6 +695,10 @@ static int tap_win32_init(VLANState *vlan, const char *model,
>      snprintf(s->nc.info_str, sizeof(s->nc.info_str),
>               "tap: ifname=%s", ifname);
>  
> +    nc->info_dict = qdict_new()
> +
> +    qdict_put(nc->info_dict, "ifname", qstring_from_str(ifname));
> +
>      s->handle = handle;
>  
>      qemu_add_wait_object(s->handle->tap_semaphore, tap_win32_send, s);
> diff --git a/net/tap.c b/net/tap.c
> index 0147dab..30ed3da 100644
> --- a/net/tap.c
> +++ b/net/tap.c
> @@ -39,6 +39,9 @@
>  #include "qemu-char.h"
>  #include "qemu-common.h"
>  #include "qemu-error.h"
> +#include "qjson.h"
> +#include "qint.h"
> +#include "qbool.h"
>  
>  #include "net/tap-linux.h"
>  
> @@ -448,8 +451,13 @@ int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan
>  
>      if (qemu_opt_get(opts, "fd")) {
>          snprintf(s->nc.info_str, sizeof(s->nc.info_str), "fd=%d", fd);
> +        assert(s->nc.info_dict == NULL);
> +
> +        s->nc.info_dict = qdict_new();
> +        qdict_put(s->nc.info_dict, "fd", qint_from_int(fd));
>      } else {
>          const char *ifname, *script, *downscript;
> +        QObject *obj;
>  
>          ifname     = qemu_opt_get(opts, "ifname");
>          script     = qemu_opt_get(opts, "script");
> @@ -459,10 +467,19 @@ int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan
>                   "ifname=%s,script=%s,downscript=%s",
>                   ifname, script, downscript);
>  
> +        obj = qobject_from_jsonf("{ 'ifname': %s, \
> +            'script': %s,'downscript': %s }",
> +            ifname, script, downscript);
> +
> +        assert(s->nc.info_dict == NULL);
> +        s->nc.info_dict = qobject_to_qdict(obj);
> +
>          if (strcmp(downscript, "no") != 0) {
>              snprintf(s->down_script, sizeof(s->down_script), "%s", downscript);
>              snprintf(s->down_script_arg, sizeof(s->down_script_arg), "%s", ifname);
>          }
> +
> +

 New lines?

>      }
>  
>      if (qemu_opt_get_bool(opts, "vhost", !!qemu_opt_get(opts, "vhostfd"))) {
> @@ -481,6 +498,9 @@ int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan
>              error_report("vhost-net requested but could not be initialized");
>              return -1;
>          }
> +        qdict_put(s->nc.info_dict, "vhost", qbool_from_int(1));
> +        qdict_put(s->nc.info_dict, "vhostfd", qint_from_int(vhostfd));
> +
>      } else if (qemu_opt_get(opts, "vhostfd")) {
>          error_report("vhostfd= is not valid without vhost");
>          return -1;

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Qemu-devel] Re: [PATCH 0/8] QMP: Introduce query-netdev
  2010-06-10 21:36 [Qemu-devel] [PATCH 0/8] QMP: Introduce query-netdev Miguel Di Ciurcio Filho
                   ` (7 preceding siblings ...)
  2010-06-10 21:37 ` [Qemu-devel] [PATCH 8/8] monitor/net: introduce 'info netdev' with QMP support Miguel Di Ciurcio Filho
@ 2010-06-16 17:44 ` Luiz Capitulino
  8 siblings, 0 replies; 16+ messages in thread
From: Luiz Capitulino @ 2010-06-16 17:44 UTC (permalink / raw)
  To: Miguel Di Ciurcio Filho; +Cc: avi, qemu-devel, armbru

On Thu, 10 Jun 2010 18:36:57 -0300
Miguel Di Ciurcio Filho <miguel.filho@gmail.com> wrote:

> This series introduces the protocol specification for querying the backend
> network devices and a monitor command to show the same information.

 Please, add changelog info next time so that it's easier to know what has
changed since the last submission.

 General state looks good to me, most important point is to complete the
doc and get acks from spec reviewers (apart from fixing small issues, of course).

> 
> Patch 01 adds a new function qdict_to_qstring().
> 
> Patch 02 adds the documentation for query-netdev.
> 
> Patch 03 adds a new QDict member to VLANClientState named info_dict.
> 
> Patches 04-07 updates all devices to feed information into the new QDict
> info_dict.
> 
> Patch 08 implements do_info_netdev() for query-netdev and the monitor
> command 'info netdev'.
> 
> Regards,
> 
> Miguel
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Qemu-devel] Re: [PATCH 2/8] QMP: Introduce the documentation for query-netdev and info netdev
  2010-06-16 17:39   ` [Qemu-devel] " Luiz Capitulino
@ 2010-06-16 21:55     ` Miguel Di Ciurcio Filho
  0 siblings, 0 replies; 16+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-06-16 21:55 UTC (permalink / raw)
  To: Luiz Capitulino; +Cc: avi, qemu-devel, armbru

On Wed, Jun 16, 2010 at 2:39 PM, Luiz Capitulino <lcapitulino@redhat.com> wrote:
>> +SQMP
>> +query-netdev
>> +----------------
>> +
>> +Each device is represented by a json-object. The returned value is a json-array
>> +of all devices.
>> +
>> +Each json-object contain the following:
>> +
>> +- "id": the device's ID, must be unique (json-string)
>> +- "vlan": QEMU's internal vlan identification. Only present if the device is
>> +  attached to a VLAN (json-int, optional)
>> +- "peer": ID of the frontend device when on a 1:1 relationship (json-string,
>> +  optional)
>
>  'type' is missing.
>

Actually, 'type' goes inside the 'info' object.

>> +- "info": json-object containing the configuration information about the device.
>
>  We need a list of all backends (maybe in 'type') and then we need to list all
> possible cases for 'info'.
>

Roger that.

Regards,

Miguel

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2010-06-16 21:55 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-10 21:36 [Qemu-devel] [PATCH 0/8] QMP: Introduce query-netdev Miguel Di Ciurcio Filho
2010-06-10 21:36 ` [Qemu-devel] [PATCH 1/8] QObject API: introduce qdict_to_qstring() function Miguel Di Ciurcio Filho
2010-06-10 21:36 ` [Qemu-devel] [PATCH 2/8] QMP: Introduce the documentation for query-netdev and info netdev Miguel Di Ciurcio Filho
2010-06-11 11:37   ` Markus Armbruster
2010-06-11 11:47     ` Miguel Di Ciurcio Filho
2010-06-16 17:39   ` [Qemu-devel] " Luiz Capitulino
2010-06-16 21:55     ` Miguel Di Ciurcio Filho
2010-06-10 21:37 ` [Qemu-devel] [PATCH 3/8] net: Introduce VLANClientState->info_dict Miguel Di Ciurcio Filho
2010-06-16 17:40   ` [Qemu-devel] " Luiz Capitulino
2010-06-10 21:37 ` [Qemu-devel] [PATCH 4/8] net: tap/tap-win32: introduce info_dict Miguel Di Ciurcio Filho
2010-06-16 17:41   ` [Qemu-devel] " Luiz Capitulino
2010-06-10 21:37 ` [Qemu-devel] [PATCH 5/8] net: vde: " Miguel Di Ciurcio Filho
2010-06-10 21:37 ` [Qemu-devel] [PATCH 6/8] net: socket: " Miguel Di Ciurcio Filho
2010-06-10 21:37 ` [Qemu-devel] [PATCH 7/8] net: slirp: " Miguel Di Ciurcio Filho
2010-06-10 21:37 ` [Qemu-devel] [PATCH 8/8] monitor/net: introduce 'info netdev' with QMP support Miguel Di Ciurcio Filho
2010-06-16 17:44 ` [Qemu-devel] Re: [PATCH 0/8] QMP: Introduce query-netdev Luiz Capitulino

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.