Skip to contentSkip to conversation

Convert do_info_network() to QObject/QMP

PATCH Superseded Miguel Di Ciurcio Filho 2 participants 31 messages Apr 8, 2010 – Apr 9, 2010

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover Convert do_info_network() to QObject/QMP

The VLANClientState structure has the member info_str, a simple string that is filled with information about NIC devices and used on monitor calls.

There is no coherent formatting of this string by all the NIC devices, making it difficult to parse and represent this information over QMP.

Patch 01 adds a new function qdict_to_qstring().

Patch 02 replaces the function qemu_nic_format_info_str by qemu_nic_format_info_dict, adds a new QDict member to VLANClientState named info_dict.

Patches 03-21 updates all devices to feed information into the new QDict.

Patch 22 converts the 'info network' monitor command to QObject, enabling QMP support.

Regards,

Miguel

#1 lore raw

PATCH 1/22 QObject API: add qdict_to_qstring() function

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

key1=value1 SPACE key2=value2 SPACE key3=value3

Handy for debugging and other things.

---
 qdict.c |   39 +++++++++++++++++++++++++++++++++++++++
 qdict.h |    3 +++
 2 files changed, 42 insertions(+), 0 deletions(-)
qdict.c +39 -0
index aae57bf..ca1a60b 100644
@@ -324,6 +324,45 @@ void qdict_iter(const QDict *qdict,
     }
 }
 
+void qdict_to_qstring_iter(const char *key, QObject *obj, void *opaque)
+{
+    QString *str = opaque;
+    
+    qstring_append(str, key);
+    qstring_append(str, "=");
+    switch (qobject_type(obj)) {
+    case QTYPE_QSTRING:
+        qstring_append(str, qstring_get_str(qobject_to_qstring(obj)));
+        break;
+    case QTYPE_QINT:
+        qstring_append_int(str, qint_get_int(qobject_to_qint(obj)));
+        break;
+    case QTYPE_QBOOL:
+        qstring_append(str, qbool_get_int(qobject_to_qbool(obj)) ? "true" :
+        "false" );
+        break;
+    default:
+        qstring_append(str, "NULL");
+    }
+
+    qstring_append(str, " ");
+}
+
+/**
+ * qdict_to_qstring(): Format a string with the keys and values of a QDict
+ *
+ * Return a pointer to a QString, with the following format:
+ *    key1=value1 SPACE key2=value2 SPACE key3=value3
+ */
+QString *qdict_to_qstring(const QDict *qdict)
+{
+    QString *str;
+    str = qstring_new();
+    qdict_iter(qdict, qdict_to_qstring_iter, str);
+
+    return str;
+}
+
 /**
  * qentry_destroy(): Free all the memory allocated by a QDictEntry
  */
qdict.h +3 -0
index 579dcdd..6731555 100644
@@ -3,6 +3,7 @@
 
 #include "qobject.h"
 #include "qlist.h"
+#include "qstring.h"
 #include "qemu-queue.h"
 #include <stdint.h>
 
@@ -43,6 +44,8 @@ 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);
+void qdict_to_qstring_iter(const char *key, QObject *obj, void *opaque);
+QString *qdict_to_qstring(const QDict *qdict);
 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.0.3
#2 lore raw

[Qemu-devel] Re: [PATCH 01/22] QObject API: add qdict_to_qstring() function

Quoted 40 lines · On Thu, 8 Apr 2010 17:16:18 -0300 Miguel Di Ciurcio Filho…

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

key1=value1 SPACE key2=value2 SPACE key3=value3

Handy for debugging and other things.

---
 qdict.c |   39 +++++++++++++++++++++++++++++++++++++++
 qdict.h |    3 +++
 2 files changed, 42 insertions(+), 0 deletions(-)
qdict.c +20 -0
index aae57bf..ca1a60b 100644
@@ -324,6 +324,45 @@ void qdict_iter(const QDict *qdict,
     }
 }
 
+void qdict_to_qstring_iter(const char *key, QObject *obj, void *opaque)
+{
+    QString *str = opaque;
+    
+    qstring_append(str, key);
+    qstring_append(str, "=");
+    switch (qobject_type(obj)) {
+    case QTYPE_QSTRING:
+        qstring_append(str, qstring_get_str(qobject_to_qstring(obj)));
+        break;
+    case QTYPE_QINT:
+        qstring_append_int(str, qint_get_int(qobject_to_qint(obj)));
+        break;
+    case QTYPE_QBOOL:
+        qstring_append(str, qbool_get_int(qobject_to_qbool(obj)) ? "true" :
+        "false" );
+        break;
+    default:
+        qstring_append(str, "NULL");
+    }

qdict.c void qdict_iter(const QDict *qdict, · line 356

Quoted 10 lines
qdict.c +10 -0
+
+    qstring_append(str, " ");
+}
+
+/**
+ * qdict_to_qstring(): Format a string with the keys and values of a QDict
+ *
+ * Return a pointer to a QString, with the following format:
+ *    key1=value1 SPACE key2=value2 SPACE key3=value3
+ */

It's a good idea to mention that nested lists and dicts are not
supported.

Quoted 33 lines
qdict.c +9 -0
+QString *qdict_to_qstring(const QDict *qdict)
+{
+    QString *str;
+    str = qstring_new();
+    qdict_iter(qdict, qdict_to_qstring_iter, str);
+
+    return str;
+}
+
 /**
  * qentry_destroy(): Free all the memory allocated by a QDictEntry
  */
qdict.h +3 -0
index 579dcdd..6731555 100644
@@ -3,6 +3,7 @@
 
 #include "qobject.h"
 #include "qlist.h"
+#include "qstring.h"
 #include "qemu-queue.h"
 #include <stdint.h>
 
@@ -43,6 +44,8 @@ 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);
+void qdict_to_qstring_iter(const char *key, QObject *obj, void *opaque);
+QString *qdict_to_qstring(const QDict *qdict);
 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);
#3 lore raw

PATCH 2/22 net: replace qemu_nic_format_info_str and VLANClientState->info_str by QDicts

In reply to Miguel Di Ciurcio Filho

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

This patch changes info_str from a simple string to a QDict.

Patches that convert the devices to this new format will follow.

---
 net.c |   14 ++++++++++----
 net.h |    4 ++--
 2 files changed, 12 insertions(+), 6 deletions(-)
net.c +10 -4
index 3ede738..ad01732 100644
@@ -35,6 +35,8 @@
 #include "sysemu.h"
 #include "qemu-common.h"
 #include "qemu_socket.h"
+#include "qdict.h"
+#include "qstring.h"
 #include "hw/qdev.h"
 
 static QTAILQ_HEAD(, VLANState) vlans;
@@ -164,13 +166,17 @@ int parse_host_port(struct sockaddr_in *saddr, const char *str)
     return 0;
 }
 
-void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6])
+void qemu_format_nic_info_dict(VLANClientState *vc, uint8_t macaddr[6])
 {
-    snprintf(vc->info_str, sizeof(vc->info_str),
-             "model=%s,macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
-             vc->model,
+    vc->info_dict = qdict_new();
+    char mac[18];
+
+    snprintf(mac, 18, "%02x:%02x:%02x:%02x:%02x:%02x",
              macaddr[0], macaddr[1], macaddr[2],
              macaddr[3], macaddr[4], macaddr[5]);
+
+    qdict_put(vc->info_dict, "macaddr", qstring_from_str(mac));
+    qdict_put(vc->info_dict, "model", qstring_from_str(vc->model));
 }
 
 void qemu_macaddr_default_if_unset(MACAddr *macaddr)
net.h +2 -2
index 16f19c5..b744294 100644
@@ -65,7 +65,7 @@ struct VLANClientState {
     NetQueue *send_queue;
     char *model;
     char *name;
-    char info_str[256];
+    QDict *info_dict;
     unsigned receive_disabled : 1;
 };
 
@@ -110,7 +110,7 @@ ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf,
                                int size, NetPacketSent *sent_cb);
 void qemu_purge_queued_packets(VLANClientState *vc);
 void qemu_flush_queued_packets(VLANClientState *vc);
-void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
+void qemu_format_nic_info_dict(VLANClientState *vc, uint8_t macaddr[6]);
 void qemu_macaddr_default_if_unset(MACAddr *macaddr);
 int qemu_show_nic_models(const char *arg, const char *const *models);
 void qemu_check_nic_model(NICInfo *nd, const char *model);
Signature · 1 line
1.7.0.3
#4 lore raw

[Qemu-devel] Re: [PATCH 02/22] net: replace qemu_nic_format_info_str and VLANClientState->info_str by QDicts

Quoted 6 lines · On Thu, 8 Apr 2010 17:16:19 -0300 Miguel Di Ciurcio Filho…

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

This patch changes info_str from a simple string to a QDict.

Patches that convert the devices to this new format will follow.

This will break the build of each individual patch, which will break
git bisect. Each individual patch should build when applied.

To fix that, you can add the new function and only drop the current one
when the full conversion is done. The temporary duplication is ok.

More comments below.

Quoted 25 lines
---
 net.c |   14 ++++++++++----
 net.h |    4 ++--
 2 files changed, 12 insertions(+), 6 deletions(-)
net.c +3 -1
index 3ede738..ad01732 100644
@@ -35,6 +35,8 @@
 #include "sysemu.h"
 #include "qemu-common.h"
 #include "qemu_socket.h"
+#include "qdict.h"
+#include "qstring.h"
 #include "hw/qdev.h"
 
 static QTAILQ_HEAD(, VLANState) vlans;
@@ -164,13 +166,17 @@ int parse_host_port(struct sockaddr_in *saddr, const char *str)
     return 0;
 }
 
-void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6])
+void qemu_format_nic_info_dict(VLANClientState *vc, uint8_t macaddr[6])

net.c int parse_host_port(struct sockaddr_in *saddr, const char *str) · line 176

Quoted 10 lines
net.c +4 -3
 {
-    snprintf(vc->info_str, sizeof(vc->info_str),
-             "model=%s,macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
-             vc->model,
+    vc->info_dict = qdict_new();
+    char mac[18];
+
+    snprintf(mac, 18, "%02x:%02x:%02x:%02x:%02x:%02x",
              macaddr[0], macaddr[1], macaddr[2],
              macaddr[3], macaddr[4], macaddr[5]);

sizeof(mac) is better.

Quoted 11 lines
net.c +3 -0
+
+    qdict_put(vc->info_dict, "macaddr", qstring_from_str(mac));
+    qdict_put(vc->info_dict, "model", qstring_from_str(vc->model));
 }
 
 void qemu_macaddr_default_if_unset(MACAddr *macaddr)
net.h +0 -0
index 16f19c5..b744294 100644

net.h struct VLANClientState { · line 68

Quoted 5 lines
net.h +1 -1
@@ -65,7 +65,7 @@ struct VLANClientState {
     NetQueue *send_queue;
     char *model;
     char *name;
-    char info_str[256];
+    QDict *info_dict;

Isn't VLANClientState freed somewhere? At least in netdev_del it should.. So,
you have to do a QDECREF(info_dict) there.

Quoted 12 lines
net.h +1 -1
     unsigned receive_disabled : 1;
 };
 
@@ -110,7 +110,7 @@ ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf,
                                int size, NetPacketSent *sent_cb);
 void qemu_purge_queued_packets(VLANClientState *vc);
 void qemu_flush_queued_packets(VLANClientState *vc);
-void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
+void qemu_format_nic_info_dict(VLANClientState *vc, uint8_t macaddr[6]);
 void qemu_macaddr_default_if_unset(MACAddr *macaddr);
 int qemu_show_nic_models(const char *arg, const char *const *models);
 void qemu_check_nic_model(NICInfo *nd, const char *model);
#5 lore raw

PATCH 3/22 net: dp8393x: replace qemu_format_nic_info_str by qemu_format_nic_info_dict

In reply to Miguel Di Ciurcio Filho
---
 hw/dp8393x.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/dp8393x.c +1 -1
index e65e4d1..ebb41a2 100644
@@ -904,7 +904,7 @@ void dp83932_init(NICInfo *nd, target_phys_addr_t base, int it_shift,
 
     s->nic = qemu_new_nic(&net_dp83932_info, &s->conf, nd->model, nd->name, s);
 
-    qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
+    qemu_format_nic_info_dict(&s->nic->nc, s->conf.macaddr.a);
     qemu_register_reset(nic_reset, s);
     nic_reset(s);
 
Signature · 1 line
1.7.0.3
#6 lore raw

PATCH 4/22 net: e1000: replace qemu_format_nic_info_str by qemu_format_nic_info_dict

In reply to Miguel Di Ciurcio Filho
---
 hw/e1000.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/e1000.c +1 -1
index fd3059a..7cbff0d 100644
@@ -1125,7 +1125,7 @@ static int pci_e1000_init(PCIDevice *pci_dev)
     d->nic = qemu_new_nic(&net_e1000_info, &d->conf,
                           d->dev.qdev.info->name, d->dev.qdev.id, d);
 
-    qemu_format_nic_info_str(&d->nic->nc, macaddr);
+    qemu_format_nic_info_dict(&d->nic->nc, macaddr);
     return 0;
 }
 
Signature · 1 line
1.7.0.3
#7 lore raw

PATCH 5/22 net: eepro100: replace qemu_format_nic_info_str by qemu_format_nic_info_dict

In reply to Miguel Di Ciurcio Filho
---
 hw/eepro100.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
hw/eepro100.c +5 -2
index 7db6fb5..329fe15 100644
@@ -47,6 +47,8 @@
 #include "pci.h"
 #include "net.h"
 #include "eeprom93xx.h"
+#include "qdict.h"
+#include "qstring.h"
 
 #define KiB 1024
 
@@ -1978,8 +1980,9 @@ static int nic_init(PCIDevice *pci_dev, uint32_t device)
     s->nic = qemu_new_nic(&net_eepro100_info, &s->conf,
                           pci_dev->qdev.info->name, pci_dev->qdev.id, s);
 
-    qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
-    TRACE(OTHER, logout("%s\n", s->nic->nc.info_str));
+    qemu_format_nic_info_dict(&s->nic->nc, s->conf.macaddr.a);
+    TRACE(OTHER, logout("%s\n",
+        qstring_get_str(qdict_to_qstring(s->nic->nc.info_dic))));
 
     qemu_register_reset(nic_reset, s);
 
Signature · 1 line
1.7.0.3
#8 lore raw

[Qemu-devel] Re: [PATCH 05/22] net: eepro100: replace qemu_format_nic_info_str by qemu_format_nic_info_dict

Quoted 19 lines · On Thu, 8 Apr 2010 17:16:22 -0300 Miguel Di Ciurcio Filho…
---
 hw/eepro100.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
hw/eepro100.c +2 -0
index 7db6fb5..329fe15 100644
@@ -47,6 +47,8 @@
 #include "pci.h"
 #include "net.h"
 #include "eeprom93xx.h"
+#include "qdict.h"
+#include "qstring.h"
 
 #define KiB 1024
 

hw/eepro100.c static int nic_init(PCIDevice *pci_dev, uint32_t device) · line 1985

Quoted 8 lines
hw/eepro100.c +3 -2
@@ -1978,8 +1980,9 @@ static int nic_init(PCIDevice *pci_dev, uint32_t device)
     s->nic = qemu_new_nic(&net_eepro100_info, &s->conf,
                           pci_dev->qdev.info->name, pci_dev->qdev.id, s);
 
-    qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
-    TRACE(OTHER, logout("%s\n", s->nic->nc.info_str));
+    qemu_format_nic_info_dict(&s->nic->nc, s->conf.macaddr.a);
+    TRACE(OTHER, logout("%s\n",
+        qstring_get_str(qdict_to_qstring(s->nic->nc.info_dic))));

You have to free the returned qstring.

Quoted 3 lines
hw/eepro100.c +0 -0
     qemu_register_reset(nic_reset, s);
 
#9 lore raw

PATCH 6/22 net: ne2000: replace qemu_format_nic_info_str by qemu_format_nic_info_dict

In reply to Miguel Di Ciurcio Filho
---
 hw/ne2000-isa.c |    2 +-
 hw/ne2000.c     |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
hw/ne2000-isa.c +1 -1
index 03a5a1f..d5403d9 100644
@@ -84,7 +84,7 @@ static int isa_ne2000_initfn(ISADevice *dev)
 
     s->nic = qemu_new_nic(&net_ne2000_isa_info, &s->c,
                           dev->qdev.info->name, dev->qdev.id, s);
-    qemu_format_nic_info_str(&s->nic->nc, s->c.macaddr.a);
+    qemu_format_nic_info_dict(&s->nic->nc, s->c.macaddr.a);
 
     return 0;
 }
hw/ne2000.c +1 -1
index 78fe14f..6a91ec0 100644
@@ -737,7 +737,7 @@ static int pci_ne2000_init(PCIDevice *pci_dev)
 
     s->nic = qemu_new_nic(&net_ne2000_info, &s->c,
                           pci_dev->qdev.info->name, pci_dev->qdev.id, s);
-    qemu_format_nic_info_str(&s->nic->nc, s->c.macaddr.a);
+    qemu_format_nic_info_dict(&s->nic->nc, s->c.macaddr.a);
 
     if (!pci_dev->qdev.hotplugged) {
         static int loaded = 0;
Signature · 1 line
1.7.0.3
#10 lore raw

PATCH 7/22 net: pcnet: replace qemu_format_nic_info_str by qemu_format_nic_info_dict

In reply to Miguel Di Ciurcio Filho
---
 hw/pcnet.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/pcnet.c +1 -1
index 5e63eb5..7df39c4 100644
@@ -1897,7 +1897,7 @@ int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info)
 
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
     s->nic = qemu_new_nic(info, &s->conf, dev->info->name, dev->id, s);
-    qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
+    qemu_format_nic_info_dict(&s->nic->nc, s->conf.macaddr.a);
     return 0;
 }
 
Signature · 1 line
1.7.0.3
#11 lore raw

PATCH 8/22 net: lan9118: replace qemu_format_nic_info_str by qemu_format_nic_info_dict

In reply to Miguel Di Ciurcio Filho
---
 hw/lan9118.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
hw/lan9118.c +2 -2
index 16d3330..07f9429 100644
@@ -232,7 +232,7 @@ static void lan9118_update(lan9118_state *s)
 
 static void lan9118_mac_changed(lan9118_state *s)
 {
-    qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
+    qemu_format_nic_info_dict(&s->nic->nc, s->conf.macaddr.a);
 }
 
 static void lan9118_reload_eeprom(lan9118_state *s)
@@ -1130,7 +1130,7 @@ static int lan9118_init1(SysBusDevice *dev)
 
     s->nic = qemu_new_nic(&net_lan9118_info, &s->conf,
                           dev->qdev.info->name, dev->qdev.id, s);
-    qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
+    qemu_format_nic_info_dict(&s->nic->nc, s->conf.macaddr.a);
     s->eeprom[0] = 0xa5;
     for (i = 0; i < 6; i++) {
         s->eeprom[i + 1] = s->conf.macaddr.a[i];
Signature · 1 line
1.7.0.3
#12 lore raw

PATCH 9/22 net: mcf_fec: replace qemu_format_nic_info_str by qemu_format_nic_info_dict

In reply to Miguel Di Ciurcio Filho
---
 hw/mcf_fec.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/mcf_fec.c +1 -1
index 4e7fbed..1e592d2 100644
@@ -476,5 +476,5 @@ void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq)
 
     s->nic = qemu_new_nic(&net_mcf_fec_info, &s->conf, nd->model, nd->name, s);
 
-    qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
+    qemu_format_nic_info_dict(&s->nic->nc, s->conf.macaddr.a);
 }
Signature · 1 line
1.7.0.3
#13 lore raw

PATCH 10/22 net: mipsnet: replace qemu_format_nic_info_str by qemu_format_nic_info_dict

In reply to Miguel Di Ciurcio Filho
---
 hw/mipsnet.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/mipsnet.c +1 -1
index a066f63..96bb588 100644
@@ -280,7 +280,7 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd)
         s->nic = qemu_new_nic(&net_mipsnet_info, &s->conf,
                               nd->model, nd->name, s);
 
-        qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
+        qemu_format_nic_info_dict(&s->nic->nc, s->conf.macaddr.a);
     }
 
     mipsnet_reset(s);
Signature · 1 line
1.7.0.3
#14 lore raw

PATCH 11/22 net: rtl8139: replace qemu_format_nic_info_str by qemu_format_nic_info_dict

In reply to Miguel Di Ciurcio Filho
---
 hw/rtl8139.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/rtl8139.c +1 -1
index 72e2242..ee4fc5d 100644
@@ -3382,7 +3382,7 @@ static int pci_rtl8139_init(PCIDevice *dev)
 
     s->nic = qemu_new_nic(&net_rtl8139_info, &s->conf,
                           dev->qdev.info->name, dev->qdev.id, s);
-    qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
+    qemu_format_nic_info_dict(&s->nic->nc, s->conf.macaddr.a);
 
     s->cplus_txbuffer = NULL;
     s->cplus_txbuffer_len = 0;
Signature · 1 line
1.7.0.3
#15 lore raw

PATCH 12/22 net: smc91c111: replace qemu_format_nic_info_str by qemu_format_nic_info_dict

In reply to Miguel Di Ciurcio Filho
---
 hw/smc91c111.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/smc91c111.c +1 -1
index c1a88c9..767fc19 100644
@@ -721,7 +721,7 @@ static int smc91c111_init1(SysBusDevice *dev)
 
     s->nic = qemu_new_nic(&net_smc91c111_info, &s->conf,
                           dev->qdev.info->name, dev->qdev.id, s);
-    qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
+    qemu_format_nic_info_dict(&s->nic->nc, s->conf.macaddr.a);
     /* ??? Save/restore.  */
     return 0;
 }
Signature · 1 line
1.7.0.3
#16 lore raw

PATCH 13/22 net: stellaris_enet: replace qemu_format_nic_info_str by qemu_format_nic_info_dict

In reply to Miguel Di Ciurcio Filho
---
 hw/stellaris_enet.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/stellaris_enet.c +1 -1
index d1d755e..cf28670 100644
@@ -416,7 +416,7 @@ static int stellaris_enet_init(SysBusDevice *dev)
 
     s->nic = qemu_new_nic(&net_stellaris_enet_info, &s->conf,
                           dev->qdev.info->name, dev->qdev.id, s);
-    qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
+    qemu_format_nic_info_dict(&s->nic->nc, s->conf.macaddr.a);
 
     stellaris_enet_reset(s);
     register_savevm("stellaris_enet", -1, 1,
Signature · 1 line
1.7.0.3
#17 lore raw

PATCH 14/22 net: usb-net: replace qemu_format_nic_info_str by qemu_format_nic_info_dict

In reply to Miguel Di Ciurcio Filho
---
 hw/usb-net.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/usb-net.c +1 -1
index ff0ca44..1583425 100644
@@ -1454,7 +1454,7 @@ static int usb_net_initfn(USBDevice *dev)
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
     s->nic = qemu_new_nic(&net_usbnet_info, &s->conf,
                           s->dev.qdev.info->name, s->dev.qdev.id, s);
-    qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
+    qemu_format_nic_info_dict(&s->nic->nc, s->conf.macaddr.a);
     snprintf(s->usbstring_mac, sizeof(s->usbstring_mac),
              "%02x%02x%02x%02x%02x%02x",
              0x40,
Signature · 1 line
1.7.0.3
#18 lore raw

PATCH 15/22 net: virtio-net: replace qemu_format_nic_info_str by qemu_format_nic_info_dict

In reply to Miguel Di Ciurcio Filho
---
 hw/virtio-net.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
hw/virtio-net.c +2 -2
index 970ba06..482a176 100644
@@ -89,7 +89,7 @@ static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config)
 
     if (memcmp(netcfg.mac, n->mac, ETH_ALEN)) {
         memcpy(n->mac, netcfg.mac, ETH_ALEN);
-        qemu_format_nic_info_str(&n->nic->nc, n->mac);
+        qemu_format_nic_info_dict(&n->nic->nc, n->mac);
     }
 }
 
@@ -916,7 +916,7 @@ VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf)
 
     n->nic = qemu_new_nic(&net_virtio_info, conf, dev->info->name, dev->id, n);
 
-    qemu_format_nic_info_str(&n->nic->nc, conf->macaddr.a);
+    qemu_format_nic_info_dict(&n->nic->nc, conf->macaddr.a);
 
     n->tx_timer = qemu_new_timer(vm_clock, virtio_net_tx_timer, n);
     n->tx_timer_active = 0;
Signature · 1 line
1.7.0.3
#19 lore raw

PATCH 16/22 net: xilinx_ethlite: replace qemu_format_nic_info_str by qemu_format_nic_info_dict

In reply to Miguel Di Ciurcio Filho
---
 hw/xilinx_ethlite.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/xilinx_ethlite.c +1 -1
index 37e33ec..345aea7 100644
@@ -230,7 +230,7 @@ static int xilinx_ethlite_init(SysBusDevice *dev)
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
     s->nic = qemu_new_nic(&net_xilinx_ethlite_info, &s->conf,
                           dev->qdev.info->name, dev->qdev.id, s);
-    qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
+    qemu_format_nic_info_dict(&s->nic->nc, s->conf.macaddr.a);
     return 0;
 }
 
Signature · 1 line
1.7.0.3
#20 lore raw

PATCH 17/22 net: dump: replace qemu_format_nic_info_str by qemu_format_nic_info_dict

In reply to Miguel Di Ciurcio Filho
---
 net/dump.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
net/dump.c +6 -2
index 6db7ecf..dea7f7d 100644
@@ -27,6 +27,9 @@
 #include "sysemu.h"
 #include "qemu-error.h"
 #include "qemu-log.h"
+#include "qdict.h"
+#include "qstring.h"
+#include "qint.h"
 
 typedef struct DumpState {
     VLANClientState nc;
@@ -128,8 +131,9 @@ static int net_dump_init(VLANState *vlan, const char *device,
 
     nc = qemu_new_net_client(&net_dump_info, vlan, NULL, device, name);
 
-    snprintf(nc->info_str, sizeof(nc->info_str),
-             "dump to %s (len=%d)", filename, len);
+    nc->info_dict = qdict_new();
+    qdict_put(nc->info_dict, "filename", qstring_from_str(filename));
+    qdict_put(nc->info_dict, "len", qint_from_int(len));
 
     s = DO_UPCAST(DumpState, nc, nc);
 
Signature · 1 line
1.7.0.3
#21 lore raw

PATCH 18/22 net: slirp: replace qemu_format_nic_info_str by qemu_format_nic_info_dict

In reply to Miguel Di Ciurcio Filho
---
 net/slirp.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
net/slirp.c +5 -2
index b41c60a..4036b92 100644
@@ -32,6 +32,8 @@
 #include "monitor.h"
 #include "sysemu.h"
 #include "qemu_socket.h"
+#include "qdict.h"
+#include "qstring.h"
 #include "slirp/libslirp.h"
 
 static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
@@ -240,8 +242,9 @@ static int net_slirp_init(VLANState *vlan, const char *model,
 
     nc = qemu_new_net_client(&net_slirp_info, vlan, NULL, model, name);
 
-    snprintf(nc->info_str, sizeof(nc->info_str),
-             "net=%s, restricted=%c", inet_ntoa(net), restricted ? 'y' : 'n');
+    nc->info_dict = qdict_new();
+    qdict_put(nc->info_dict, "net", qstring_from_str(inet_ntoa(net)));
+    qdict_put(nc->info_dict, "restricted", qstring_from_str( restricted ? "y" : "n"));
 
     s = DO_UPCAST(SlirpState, nc, nc);
 
Signature · 1 line
1.7.0.3
#22 lore raw

[Qemu-devel] Re: [PATCH 18/22] net: slirp: replace qemu_format_nic_info_str by qemu_format_nic_info_dict

Quoted 19 lines · On Thu, 8 Apr 2010 17:16:35 -0300 Miguel Di Ciurcio Filho…
---
 net/slirp.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
net/slirp.c +2 -0
index b41c60a..4036b92 100644
@@ -32,6 +32,8 @@
 #include "monitor.h"
 #include "sysemu.h"
 #include "qemu_socket.h"
+#include "qdict.h"
+#include "qstring.h"
 #include "slirp/libslirp.h"
 
 static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)

net/slirp.c static int net_slirp_init(VLANState *vlan, const char *model, · line 247

Quoted 8 lines
net/slirp.c +3 -2
@@ -240,8 +242,9 @@ static int net_slirp_init(VLANState *vlan, const char *model,
 
     nc = qemu_new_net_client(&net_slirp_info, vlan, NULL, model, name);
 
-    snprintf(nc->info_str, sizeof(nc->info_str),
-             "net=%s, restricted=%c", inet_ntoa(net), restricted ? 'y' : 'n');
+    nc->info_dict = qdict_new();
+    qdict_put(nc->info_dict, "net", qstring_from_str(inet_ntoa(net)));
+    qdict_put(nc->info_dict, "restricted", qstring_from_str( restricted ? "y" : "n"));

Better to use qbool here.

Quoted 3 lines
net/slirp.c +0 -0
     s = DO_UPCAST(SlirpState, nc, nc);
 
#23 lore raw

PATCH 19/22 net: socket: replace qemu_format_nic_info_str by qemu_format_nic_info_dict

In reply to Miguel Di Ciurcio Filho
---
 net/socket.c |   47 ++++++++++++++++++++++++++++++++++-------------
 1 files changed, 34 insertions(+), 13 deletions(-)
net/socket.c +34 -13
index 1c4e153..3521e21 100644
@@ -28,6 +28,10 @@
 #include "net.h"
 #include "qemu-char.h"
 #include "qemu-common.h"
+#include "qdict.h"
+#include "qstring.h"
+#include "qbool.h"
+#include "qint.h"
 #include "qemu-error.h"
 #include "qemu-option.h"
 #include "qemu_socket.h"
@@ -266,11 +270,16 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan,
     }
 
     nc = qemu_new_net_client(&net_dgram_socket_info, vlan, NULL, model, name);
-
-    snprintf(nc->info_str, sizeof(nc->info_str),
-	    "socket: fd=%d (%s mcast=%s:%d)",
-	    fd, is_connected ? "cloned" : "",
-	    inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
+    
+    nc->info_dict = qdict_new();
+    qdict_put(nc->info_dict, "fd", qint_from_int(fd));
+    
+    char mcast_addr[22];
+    snprintf(mcast_addr, strlen(mcast_addr), "%s:%d",
+                     inet_ntoa(saddr.sin_addr),
+                     ntohs(saddr.sin_port));
+    qdict_put(nc->info_dict, "mcast", qstring_from_str(mcast_addr));
+    qdict_put(nc->info_dict, "cloned", qbool_from_int(is_connected));
 
     s = DO_UPCAST(NetSocketState, nc, nc);
 
@@ -306,8 +315,9 @@ static NetSocketState *net_socket_fd_init_stream(VLANState *vlan,
     NetSocketState *s;
 
     nc = qemu_new_net_client(&net_socket_info, vlan, NULL, model, name);
+    nc->info_dict = qdict_new();
 
-    snprintf(nc->info_str, sizeof(nc->info_str), "socket: fd=%d", fd);
+    qdict_put(nc->info_dict, "fd", qint_from_int(fd));
 
     s = DO_UPCAST(NetSocketState, nc, nc);
 
@@ -366,9 +376,12 @@ static void net_socket_accept(void *opaque)
     if (!s1) {
         closesocket(fd);
     } else {
-        snprintf(s1->nc.info_str, sizeof(s1->nc.info_str),
-                 "socket: connection from %s:%d",
+        char connection_from[22];
+        s1->nc.info_dict = qdict_new();
+
+        snprintf(connection_from, strlen(connection_from), "%s:%d", 
                  inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
+        qdict_put(s1->nc.info_dict, "connection_from", qstring_from_str(connection_from));
     }
 }
 
@@ -459,9 +472,13 @@ static int net_socket_connect_init(VLANState *vlan,
     s = net_socket_fd_init(vlan, model, name, fd, connected);
     if (!s)
         return -1;
-    snprintf(s->nc.info_str, sizeof(s->nc.info_str),
-             "socket: connect to %s:%d",
+
+    char connect_to[22];
+    s->nc.info_dict = qdict_new();
+
+    snprintf(connect_to, strlen(connect_to), "%s:%d", 
              inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
+    qdict_put(s->nc.info_dict, "connect_to", qstring_from_str(connect_to));
     return 0;
 }
 
@@ -487,10 +504,14 @@ static int net_socket_mcast_init(VLANState *vlan,
         return -1;
 
     s->dgram_dst = saddr;
+    
+    s->nc.info_dict = qdict_new();
+    char mcast_addr[22];
+    snprintf(mcast_addr, strlen(mcast_addr), "%s:%d",
+                     inet_ntoa(saddr.sin_addr),
+                     ntohs(saddr.sin_port));
+    qdict_put(s->nc.info_dict, "mcast", qstring_from_str(mcast_addr));
 
-    snprintf(s->nc.info_str, sizeof(s->nc.info_str),
-             "socket: mcast=%s:%d",
-             inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
     return 0;
 
 }
Signature · 1 line
1.7.0.3
#24 lore raw

[Qemu-devel] Re: [PATCH 19/22] net: socket: replace qemu_format_nic_info_str by qemu_format_nic_info_dict

Quoted 28 lines · On Thu, 8 Apr 2010 17:16:36 -0300 Miguel Di Ciurcio Filho…
---
 net/socket.c |   47 ++++++++++++++++++++++++++++++++++-------------
 1 files changed, 34 insertions(+), 13 deletions(-)
net/socket.c +4 -4
index 1c4e153..3521e21 100644
@@ -28,6 +28,10 @@
 #include "net.h"
 #include "qemu-char.h"
 #include "qemu-common.h"
+#include "qdict.h"
+#include "qstring.h"
+#include "qbool.h"
+#include "qint.h"
 #include "qemu-error.h"
 #include "qemu-option.h"
 #include "qemu_socket.h"
@@ -266,11 +270,16 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan,
     }
 
     nc = qemu_new_net_client(&net_dgram_socket_info, vlan, NULL, model, name);
-
-    snprintf(nc->info_str, sizeof(nc->info_str),
-	    "socket: fd=%d (%s mcast=%s:%d)",
-	    fd, is_connected ? "cloned" : "",

net/socket.c static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, · line 281

Quoted 10 lines
net/socket.c +9 -1
-	    inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
+    
+    nc->info_dict = qdict_new();
+    qdict_put(nc->info_dict, "fd", qint_from_int(fd));
+    
+    char mcast_addr[22];
+    snprintf(mcast_addr, strlen(mcast_addr), "%s:%d",
+                     inet_ntoa(saddr.sin_addr),
+                     ntohs(saddr.sin_port));
+    qdict_put(nc->info_dict, "mcast", qstring_from_str(mcast_addr));

We should break 'mcast', otherwise QMP clients will have to parse it. Maybe
you can make vnc.c::put_addr_qdict() public and use it (with a better name).

Note that this is also valid for 'connection_from' and all the others..

Quoted 64 lines
net/socket.c +21 -8
+    qdict_put(nc->info_dict, "cloned", qbool_from_int(is_connected));
 
     s = DO_UPCAST(NetSocketState, nc, nc);
 
@@ -306,8 +315,9 @@ static NetSocketState *net_socket_fd_init_stream(VLANState *vlan,
     NetSocketState *s;
 
     nc = qemu_new_net_client(&net_socket_info, vlan, NULL, model, name);
+    nc->info_dict = qdict_new();
 
-    snprintf(nc->info_str, sizeof(nc->info_str), "socket: fd=%d", fd);
+    qdict_put(nc->info_dict, "fd", qint_from_int(fd));
 
     s = DO_UPCAST(NetSocketState, nc, nc);
 
@@ -366,9 +376,12 @@ static void net_socket_accept(void *opaque)
     if (!s1) {
         closesocket(fd);
     } else {
-        snprintf(s1->nc.info_str, sizeof(s1->nc.info_str),
-                 "socket: connection from %s:%d",
+        char connection_from[22];
+        s1->nc.info_dict = qdict_new();
+
+        snprintf(connection_from, strlen(connection_from), "%s:%d", 
                  inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
+        qdict_put(s1->nc.info_dict, "connection_from", qstring_from_str(connection_from));
     }
 }
 
@@ -459,9 +472,13 @@ static int net_socket_connect_init(VLANState *vlan,
     s = net_socket_fd_init(vlan, model, name, fd, connected);
     if (!s)
         return -1;
-    snprintf(s->nc.info_str, sizeof(s->nc.info_str),
-             "socket: connect to %s:%d",
+
+    char connect_to[22];
+    s->nc.info_dict = qdict_new();
+
+    snprintf(connect_to, strlen(connect_to), "%s:%d", 
              inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
+    qdict_put(s->nc.info_dict, "connect_to", qstring_from_str(connect_to));
     return 0;
 }
 
@@ -487,10 +504,14 @@ static int net_socket_mcast_init(VLANState *vlan,
         return -1;
 
     s->dgram_dst = saddr;
+    
+    s->nc.info_dict = qdict_new();
+    char mcast_addr[22];
+    snprintf(mcast_addr, strlen(mcast_addr), "%s:%d",
+                     inet_ntoa(saddr.sin_addr),
+                     ntohs(saddr.sin_port));
+    qdict_put(s->nc.info_dict, "mcast", qstring_from_str(mcast_addr));
 
-    snprintf(s->nc.info_str, sizeof(s->nc.info_str),
-             "socket: mcast=%s:%d",
-             inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
     return 0;
 
 }
#25 lore raw

PATCH 20/22 net: tap: replace qemu_format_nic_info_str by info_dict

In reply to Miguel Di Ciurcio Filho
---
 net/tap-win32.c |    9 ++++++---
 net/tap.c       |   18 +++++++++++++-----
 2 files changed, 19 insertions(+), 8 deletions(-)
net/tap-win32.c +6 -3
index 74348da..8e0ad2d 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>
@@ -688,10 +690,11 @@ static int tap_win32_init(VLANState *vlan, const char *model,
 
     nc = qemu_new_net_client(&net_tap_win32_info, vlan, NULL, model, name);
 
-    s = DO_UPCAST(TAPState, nc, nc);
+    nc->info_dict = qdict_new();
 
-    snprintf(s->nc.info_str, sizeof(s->nc.info_str),
-             "tap: ifname=%s", ifname);
+    qdict_put(nc->info_dict, "ifname", qstring_to_str(ifname));
+    
+    s = DO_UPCAST(TAPState, nc, nc);
 
     s->handle = handle;
 
net/tap.c +13 -5
index 303d69f..8ba7eed 100644
@@ -39,6 +39,9 @@
 #include "qemu-char.h"
 #include "qemu-common.h"
 #include "qemu-error.h"
+#include "qdict.h"
+#include "qint.h"
+#include "qstring.h"
 
 #include "net/tap-linux.h"
 
@@ -447,18 +450,23 @@ 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);
+        if (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;
+        if (s->nc.info_dict == NULL)
+            s->nc.info_dict = qdict_new();
 
         ifname     = qemu_opt_get(opts, "ifname");
         script     = qemu_opt_get(opts, "script");
         downscript = qemu_opt_get(opts, "downscript");
 
-        snprintf(s->nc.info_str, sizeof(s->nc.info_str),
-                 "ifname=%s,script=%s,downscript=%s",
-                 ifname, script, downscript);
-
+        qdict_put(s->nc.info_dict, "ifname", qstring_from_str(ifname));
+        qdict_put(s->nc.info_dict, "script", qstring_from_str(script));
+        qdict_put(s->nc.info_dict, "downscript", qstring_from_str(downscript));
+        
         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);
Signature · 1 line
1.7.0.3
#26 lore raw

[Qemu-devel] Re: [PATCH 20/22] net: tap: replace qemu_format_nic_info_str by info_dict

Quoted 20 lines · On Thu, 8 Apr 2010 17:16:37 -0300 Miguel Di Ciurcio Filho…
---
 net/tap-win32.c |    9 ++++++---
 net/tap.c       |   18 +++++++++++++-----
 2 files changed, 19 insertions(+), 8 deletions(-)
net/tap-win32.c +2 -0
index 74348da..8e0ad2d 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>

net/tap-win32.c static int tap_win32_init(VLANState *vlan, const char *model, · line 695

Quoted 9 lines
net/tap-win32.c +2 -3
@@ -688,10 +690,11 @@ static int tap_win32_init(VLANState *vlan, const char *model,
 
     nc = qemu_new_net_client(&net_tap_win32_info, vlan, NULL, model, name);
 
-    s = DO_UPCAST(TAPState, nc, nc);
+    nc->info_dict = qdict_new();
 
-    snprintf(s->nc.info_str, sizeof(s->nc.info_str),
-             "tap: ifname=%s", ifname);
+    qdict_put(nc->info_dict, "ifname", qstring_to_str(ifname));

qstring_from_str() is better.

Quoted 48 lines
net/tap-win32.c +2 -0
+    
+    s = DO_UPCAST(TAPState, nc, nc);
 
     s->handle = handle;
 
net/tap.c +13 -5
index 303d69f..8ba7eed 100644
@@ -39,6 +39,9 @@
 #include "qemu-char.h"
 #include "qemu-common.h"
 #include "qemu-error.h"
+#include "qdict.h"
+#include "qint.h"
+#include "qstring.h"
 
 #include "net/tap-linux.h"
 
@@ -447,18 +450,23 @@ 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);
+        if (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;
+        if (s->nc.info_dict == NULL)
+            s->nc.info_dict = qdict_new();
 
         ifname     = qemu_opt_get(opts, "ifname");
         script     = qemu_opt_get(opts, "script");
         downscript = qemu_opt_get(opts, "downscript");
 
-        snprintf(s->nc.info_str, sizeof(s->nc.info_str),
-                 "ifname=%s,script=%s,downscript=%s",
-                 ifname, script, downscript);
-
+        qdict_put(s->nc.info_dict, "ifname", qstring_from_str(ifname));
+        qdict_put(s->nc.info_dict, "script", qstring_from_str(script));
+        qdict_put(s->nc.info_dict, "downscript", qstring_from_str(downscript));
+        
         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);
#27 lore raw

PATCH 21/22 net: vde: replace qemu_format_nic_info_str by info_dict

In reply to Miguel Di Ciurcio Filho
---
 net/vde.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
net/vde.c +7 -2
index 0b46fa6..f582878 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 {
@@ -99,8 +102,10 @@ static int net_vde_init(VLANState *vlan, const char *model,
 
     nc = qemu_new_net_client(&net_vde_info, vlan, NULL, model, name);
 
-    snprintf(nc->info_str, sizeof(nc->info_str), "sock=%s,fd=%d",
-             sock, vde_datafd(vde));
+    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);
 
Signature · 1 line
1.7.0.3
#28 lore raw

PATCH 22/22 monitor/net: Convert do_info_network() to QObject/QMP

In reply to Miguel Di Ciurcio Filho

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

This commit slightly changes the monitor output when 'info network' is used.

---
 monitor.c |    3 +-
 net.c     |  133 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------
 net.h     |    6 ++-
 3 files changed, 126 insertions(+), 16 deletions(-)
monitor.c +2 -1
index 822dc27..0b3fdfc 100644
@@ -2604,7 +2604,8 @@ static const mon_cmd_t info_cmds[] = {
         .args_type  = "",
         .params     = "",
         .help       = "show the network state",
-        .mhandler.info = do_info_network,
+        .user_print = do_info_network_print,
+        .mhandler.info_new = do_info_network,
     },
     {
         .name       = "chardev",
net.c +119 -14

162 lines not on this page · raw message

net.h +5 -1
index b744294..d1cf6ab 100644
@@ -6,6 +6,7 @@
 #include "qemu-common.h"
 #include "qdict.h"
 #include "qemu-option.h"
+#include "qobject.h"
 #include "net/queue.h"
 
 struct MACAddr {
@@ -117,7 +118,10 @@ void qemu_check_nic_model(NICInfo *nd, const char *model);
 int qemu_find_nic_model(NICInfo *nd, const char * const *models,
                         const char *default_model);
 
-void do_info_network(Monitor *mon);
+void vlan_devices_iter(QObject *obj, void *opaque);
+void non_vlan_devices_iter(QObject *obj, void *opaque);
+void do_info_network_print(Monitor *mon, const QObject *ret_data);
+void do_info_network(Monitor *mon, QObject **ret_data);
 void do_set_link(Monitor *mon, const QDict *qdict);
 
 /* NIC info */
Signature · 1 line
1.7.0.3
#29 lore raw

[Qemu-devel] Re: [PATCH 22/22] monitor/net: Convert do_info_network() to QObject/QMP

Quoted 84 lines · On Thu, 8 Apr 2010 17:16:39 -0300 Miguel Di Ciurcio Filho…

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

This commit slightly changes the monitor output when 'info network' is used.

---
 monitor.c |    3 +-
 net.c     |  133 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------
 net.h     |    6 ++-
 3 files changed, 126 insertions(+), 16 deletions(-)
monitor.c +2 -1
index 822dc27..0b3fdfc 100644
@@ -2604,7 +2604,8 @@ static const mon_cmd_t info_cmds[] = {
         .args_type  = "",
         .params     = "",
         .help       = "show the network state",
-        .mhandler.info = do_info_network,
+        .user_print = do_info_network_print,
+        .mhandler.info_new = do_info_network,
     },
     {
         .name       = "chardev",
net.c +30 -4
index ad01732..c59ae5b 100644
@@ -33,10 +33,10 @@
 #include "net/util.h"
 #include "monitor.h"
 #include "sysemu.h"
+#include "qstring.h"
 #include "qemu-common.h"
 #include "qemu_socket.h"
-#include "qdict.h"
-#include "qstring.h"
+#include "qemu-objects.h"
 #include "hw/qdev.h"
 
 static QTAILQ_HEAD(, VLANState) vlans;
@@ -174,7 +174,7 @@ void qemu_format_nic_info_dict(VLANClientState *vc, uint8_t macaddr[6])
     snprintf(mac, 18, "%02x:%02x:%02x:%02x:%02x:%02x",
              macaddr[0], macaddr[1], macaddr[2],
              macaddr[3], macaddr[4], macaddr[5]);
-
+            
     qdict_put(vc->info_dict, "macaddr", qstring_from_str(mac));
     qdict_put(vc->info_dict, "model", qstring_from_str(vc->model));
 }
@@ -1224,26 +1224,131 @@ void net_set_boot_mask(int net_boot_mask)
     }
 }
 
-void do_info_network(Monitor *mon)
+void vlan_devices_iter(QObject *obj, void *opaque)
+{
+
+    Monitor *mon = opaque;
+    QDict *net_device = qobject_to_qdict(obj);
+        
+    if (!qdict_haskey(net_device, "vlan"))
+        return;
+
+    monitor_printf(mon, "  %s: vlan=%d ", qdict_get_str(net_device, "name"),
+        (int)qdict_get_int(net_device, "vlan"));
+    monitor_printf(mon,
+        qstring_get_str(qdict_to_qstring(qdict_get_qdict(net_device, "info"))));
+    
+    monitor_printf(mon, " \n");
+}
+
+void non_vlan_devices_iter(QObject *obj, void *opaque)
+{
+
+    Monitor *mon = opaque;
+    QDict *net_device = qobject_to_qdict(obj);
+    
+    if (qdict_haskey(net_device, "vlan"))
+        return;
+    
+    monitor_printf(mon, "  %s: ", qdict_get_str(net_device, "name"));

net.c void net_set_boot_mask(int net_boot_mask) · line 1263

Quoted 10 lines
net.c +10 -0
+    
+    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");
+        
+}

The iterators can be private, I think.

Quoted 29 lines
net.c +29 -0
+
+void do_info_network_print(Monitor *mon, const QObject *ret_data)
+{
+    QList *qlist;
+    
+    qlist = qobject_to_qlist(ret_data);
+    
+    monitor_printf(mon, "Devices on VLANs:\n");
+
+    qlist_iter(qlist, vlan_devices_iter, mon);
+
+    monitor_printf(mon, "Devices not on any VLAN:\n");
+    
+    qlist_iter(qlist, non_vlan_devices_iter, mon);
+    
+}
+
+/**
+ * do_network_info(): Network information
+ *
+ * Each network device information is stored in a QDict and the
+ * returned QObject is a QList of all devices.
+ *
+ * The QDict contains the following:
+ *
+ * - "name": device name
+ * - "vlan": only present if the device is attached to a VLAN, it is the id
+ * of the VLAN
+ * - "info": it is a QDict containing any of the following: 

net.c void net_set_boot_mask(int net_boot_mask) · line 1302

Quoted 10 lines
net.c +10 -0
+ *          - "model": type of the device
+ *          - "macaddr": MAC address
+ *          - "script": path to script used to configure the device
+ *          - "downscript": path to script used to deconfigure the device
+ *          - "fd": handle to the device
+ *          - "ifname": name of the host device connected to the guest device
+ *          - "mcast": multicast address
+ *          - "cloned": true if the device is multicast clone
+ *          - "connection_from": IP/port pair of an incomming connection
+ *          - "connect_to": IP/port pair of an outgoing connection

Any of them are mandatory or all of them are optional, meaning that
they depend on the device? If so, maybe it's better to explain a bit more.

Quoted 86 lines
net.c +40 -10
+ *
+ * Example:
+ *
+ * [ { "name": "tap.0", "vlan": 0, 
+       "info": { "script": "/etc/kvm/kvm-ifup", "downscript": "/etc/qemu-ifdown", 
+       "ifname": "tap0" } }, 
+     { "name": "e1000.0", "vlan": 1,
+      "info": { "model": "e1000", "macaddr": "52:54:00:12:34:56" } } ]
+ */
+void do_info_network(Monitor *mon, QObject **ret_data)
 {
     VLANState *vlan;
     VLANClientState *vc;
-
+    QDict *net_device;
+    QList *device_list;
+    device_list = qlist_new();
+        
     QTAILQ_FOREACH(vlan, &vlans, next) {
-        monitor_printf(mon, "VLAN %d devices:\n", vlan->id);
-
+        QObject *obj;
+        
         QTAILQ_FOREACH(vc, &vlan->clients, next) {
-            monitor_printf(mon, "  %s: %s\n", vc->name, vc->info_str);
+
+            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, qobject_to_qdict(obj));
+
         }
     }
-    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);
-        }
-        monitor_printf(mon, "\n");
+        QObject *obj;
+        
+        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);
 }
 
 void do_set_link(Monitor *mon, const QDict *qdict)
net.h +5 -1
index b744294..d1cf6ab 100644
@@ -6,6 +6,7 @@
 #include "qemu-common.h"
 #include "qdict.h"
 #include "qemu-option.h"
+#include "qobject.h"
 #include "net/queue.h"
 
 struct MACAddr {
@@ -117,7 +118,10 @@ void qemu_check_nic_model(NICInfo *nd, const char *model);
 int qemu_find_nic_model(NICInfo *nd, const char * const *models,
                         const char *default_model);
 
-void do_info_network(Monitor *mon);
+void vlan_devices_iter(QObject *obj, void *opaque);
+void non_vlan_devices_iter(QObject *obj, void *opaque);
+void do_info_network_print(Monitor *mon, const QObject *ret_data);
+void do_info_network(Monitor *mon, QObject **ret_data);
 void do_set_link(Monitor *mon, const QDict *qdict);
 
 /* NIC info */
#30 lore raw
In reply to Miguel Di Ciurcio Filho
Quoted 8 lines · On Thu, 8 Apr 2010 17:16:17 -0300 Miguel Di Ciurcio Filho…

The VLANClientState structure has the member info_str, a simple string that is filled with information about NIC devices and used on monitor calls.

There is no coherent formatting of this string by all the NIC devices, making it difficult to parse and represent this information over QMP.

Patch 01 adds a new function qdict_to_qstring().

Quoted 8 lines

Patch 02 replaces the function qemu_nic_format_info_str by qemu_nic_format_info_dict, adds a new QDict member to VLANClientState named info_dict.

Patches 03-21 updates all devices to feed information into the new QDict.

Patch 22 converts the 'info network' monitor command to QObject, enabling QMP support.

This series has a number of small things to improve, but seems the right
approach to me and in general looks very good. I'll followup individual patches.

Two issues:

1. The following sequence triggers an assert()

(qemu) netdev_add user,id=foo
(qemu) info network

The netdev_add command is available in my tree (see below).

2. The last patch conflicts with patches from Markus, you can rebase against my tree to solve that:

git://repo.or.cz/qemu/qmp-unstable.git