Skip to contentSkip to conversation

QMP: Introduce query-netdev

PATCH In review Miguel Di Ciurcio Filho 3 participants 16 messages Jun 10, 2010 – Jun 16, 2010

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

cover QMP: Introduce query-netdev

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

#1 lore raw

PATCH 1/8 QObject API: introduce qdict_to_qstring() function

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.

---
 qdict.c |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 qdict.h |    2 ++
 2 files changed, 62 insertions(+), 0 deletions(-)
qdict.c +60 -0
index 175bc17..dc95199 100644
@@ -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'
  *
qdict.h +2 -0
index 5e5902c..0c64089 100644
@@ -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);
Signature · 1 line
1.7.1
#2 lore raw

PATCH 2/8 QMP: Introduce the documentation for query-netdev and info netdev

In reply to Miguel Di Ciurcio Filho

These commands show the information about active backend network devices.

---
 qemu-monitor.hx |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 53 insertions(+), 0 deletions(-)
qemu-monitor.hx +53 -0
index f6a94f2..14a0ba1 100644
@@ -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
Signature · 1 line
1.7.1
#3 lore raw

Re: [Qemu-devel] [PATCH 2/8] QMP: Introduce the documentation for query-netdev and info netdev

Quoted 23 lines · Miguel Di Ciurcio Filho

These commands show the information about active backend network devices.

---
 qemu-monitor.hx |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 53 insertions(+), 0 deletions(-)
qemu-monitor.hx +8 -0
index f6a94f2..14a0ba1 100644
@@ -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

qemu-monitor.hx show the various VLANs and the associated devices · line 1694

Quoted 10 lines
qemu-monitor.hx +10 -0
+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?

qemu-monitor.hx show the various VLANs and the associated devices · line 1697

Quoted 3 lines
qemu-monitor.hx +3 -0
+
+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.

[...]

#4 lore raw

Re: [Qemu-devel] [PATCH 2/8] QMP: Introduce the documentation for query-netdev and info netdev

Quoted 10 lines · Markus Armbruster
Quoted 6 lines
+- "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.

Quoted 6 lines

qemu-monitor.hx show the various VLANs and the associated devices · line 1697

Quoted 3 lines
qemu-monitor.hx +3 -0
+
+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

#5 lore raw

[Qemu-devel] Re: [PATCH 2/8] QMP: Introduce the documentation for query-netdev and info netdev

In reply to Miguel Di Ciurcio Filho
Quoted 22 lines · On Thu, 10 Jun 2010 18:36:59 -0300 Miguel Di Ciurcio Filho…

These commands show the information about active backend network devices.

---
 qemu-monitor.hx |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 53 insertions(+), 0 deletions(-)
qemu-monitor.hx +7 -0
index f6a94f2..14a0ba1 100644
@@ -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
+----------------
+

qemu-monitor.hx show the various VLANs and the associated devices · line 1693

Quoted 10 lines
qemu-monitor.hx +10 -0
+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.

qemu-monitor.hx show the various VLANs and the associated devices · line 1694

Quoted 1 line
qemu-monitor.hx +1 -0
+- "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.

#6 lore raw

[Qemu-devel] Re: [PATCH 2/8] QMP: Introduce the documentation for query-netdev and info netdev

Quoted 8 lines · Luiz Capitulino
Quoted 8 lines
qemu-monitor.hx +8 -0
+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:
Quoted 9 lines
Quoted 6 lines

+

+- "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.

Quoted 5 lines
Quoted 1 line

+- "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

#7 lore raw

PATCH 3/8 net: Introduce VLANClientState->info_dict

In reply to Miguel Di Ciurcio Filho

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.

---
 net.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
net.h +1 -0
index b83f615..acc1645 100644
@@ -66,6 +66,7 @@ struct VLANClientState {
     char *model;
     char *name;
     char info_str[256];
+    QDict *info_dict;
     unsigned receive_disabled : 1;
 };
 
Signature · 1 line
1.7.1
#8 lore raw

[Qemu-devel] Re: [PATCH 3/8] net: Introduce VLANClientState->info_dict

Quoted 15 lines · On Thu, 10 Jun 2010 18:37:00 -0300 Miguel Di Ciurcio Filho…

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.

---
 net.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
net.h +0 -0
index b83f615..acc1645 100644

net.h struct VLANClientState { · line 72

Quoted 7 lines
net.h +1 -0
@@ -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.

#9 lore raw

PATCH 4/8 net: tap/tap-win32: introduce info_dict

In reply to Miguel Di Ciurcio Filho
---
 net/tap-win32.c |    6 ++++++
 net/tap.c       |   20 ++++++++++++++++++++
 2 files changed, 26 insertions(+), 0 deletions(-)
net/tap-win32.c +6 -0
index 74348da..3833592 100644
@@ -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);
net/tap.c +20 -0
index 0147dab..30ed3da 100644
@@ -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;
Signature · 1 line
1.7.1
#10 lore raw

[Qemu-devel] Re: [PATCH 4/8] net: tap/tap-win32: introduce info_dict

Quoted 65 lines · On Thu, 10 Jun 2010 18:37:01 -0300 Miguel Di Ciurcio Filho…
---
 net/tap-win32.c |    6 ++++++
 net/tap.c       |   20 ++++++++++++++++++++
 2 files changed, 26 insertions(+), 0 deletions(-)
net/tap-win32.c +6 -0
index 74348da..3833592 100644
@@ -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);
net/tap.c +11 -0
index 0147dab..30ed3da 100644
@@ -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);

net/tap.c int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan · line 482

Quoted 10 lines
net/tap.c +6 -0
+
+        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?

Quoted 13 lines
net/tap.c +3 -0
     }
 
     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;
#11 lore raw

PATCH 5/8 net: vde: introduce info_dict

In reply to Miguel Di Ciurcio Filho
---
 net/vde.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
net/vde.c +8 -0
index 0b46fa6..0fe7c09 100644
@@ -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;
Signature · 1 line
1.7.1
#12 lore raw

PATCH 6/8 net: socket: introduce info_dict

In reply to Miguel Di Ciurcio Filho
---
 net/socket.c |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
net/socket.c +21 -0
index 1c4e153..aad9eb8 100644
@@ -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;
 
 }
Signature · 1 line
1.7.1
#13 lore raw

PATCH 7/8 net: slirp: introduce info_dict

In reply to Miguel Di Ciurcio Filho
---
 net/slirp.c |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)
net/slirp.c +16 -1
index b41c60a..5735009 100644
@@ -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
 
Signature · 1 line
1.7.1
#14 lore raw

PATCH 8/8 monitor/net: introduce 'info netdev' with QMP support

In reply to Miguel Di Ciurcio Filho
---
 monitor.c |    8 +++++
 net.c     |   96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 net.h     |    2 +
 3 files changed, 106 insertions(+), 0 deletions(-)
monitor.c +8 -0
index 15b53b9..0038214 100644
@@ -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     = "",
net.c +96 -0

108 lines not on this page · raw message

net.h +2 -0
index acc1645..65bbf27 100644
@@ -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 */
Signature · 1 line
1.7.1
#15 lore raw
In reply to Miguel Di Ciurcio Filho
Quoted 2 lines · On Thu, 10 Jun 2010 18:36:57 -0300 Miguel Di Ciurcio Filho…

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).

Quoted 17 lines

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