qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v4 0/10] Introduce 'info netdevices' with QMP support
@ 2010-05-18 17:07 Miguel Di Ciurcio Filho
  2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 01/10] QObject API: introduce qdict_to_qstring() function Miguel Di Ciurcio Filho
                   ` (10 more replies)
  0 siblings, 11 replies; 15+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-05-18 17:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, lcapitulino

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.

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

Patch 01 adds a new function qdict_to_qstring().

Patch 02 adds the function qemu_nic_format_info_dict and adds a new 
QDict member to VLANClientState named info_dict.

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

Patch 10 introduces 'info netdevices'.

These series of patches were made on top of the qmp-unstable tree[1].

Regards,

Miguel

[1] http://repo.or.cz/w/qemu/qmp-unstable.git

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

* [Qemu-devel] [PATCH v4 01/10] QObject API: introduce qdict_to_qstring() function
  2010-05-18 17:07 [Qemu-devel] [PATCH v4 0/10] Introduce 'info netdevices' with QMP support Miguel Di Ciurcio Filho
@ 2010-05-18 17:07 ` Miguel Di Ciurcio Filho
  2010-05-27 17:50   ` [Qemu-devel] " Luiz Capitulino
  2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 02/10] net: introduce qemu_nic_format_info_dict and VLANClientState->info_dict Miguel Di Ciurcio Filho
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 15+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-05-18 17:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, lcapitulino

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 |   55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 qdict.h |    9 +++++++++
 2 files changed, 64 insertions(+), 0 deletions(-)

diff --git a/qdict.c b/qdict.c
index 175bc17..19c053f 100644
--- a/qdict.c
+++ b/qdict.c
@@ -267,6 +267,61 @@ const char *qdict_get_str(const QDict *qdict, const char *key)
     return qstring_get_str(qobject_to_qstring(obj));
 }
 
+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->qdict_iter_current_key++;
+
+    if (pack->qdict_iter_current_key < pack->qdict_iter_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->qdict_iter_current_key = 0;
+    pack->qdict_iter_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..8a54733 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>
 
@@ -32,6 +33,13 @@ typedef struct QDict {
     QLIST_HEAD(,QDictEntry) table[QDICT_HASH_SIZE];
 } QDict;
 
+struct qstring_pack {
+    QString *str;
+    size_t qdict_iter_total_keys;
+    size_t qdict_iter_current_key;
+    const char *separator;
+};
+
 /* Object API */
 QDict *qdict_new(void);
 size_t qdict_size(const QDict *qdict);
@@ -55,6 +63,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] 15+ messages in thread

* [Qemu-devel] [PATCH v4 02/10] net: introduce qemu_nic_format_info_dict and VLANClientState->info_dict
  2010-05-18 17:07 [Qemu-devel] [PATCH v4 0/10] Introduce 'info netdevices' with QMP support Miguel Di Ciurcio Filho
  2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 01/10] QObject API: introduce qdict_to_qstring() function Miguel Di Ciurcio Filho
@ 2010-05-18 17:07 ` Miguel Di Ciurcio Filho
  2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 03/10] net: various devices: add qemu_format_nic_info_dict Miguel Di Ciurcio Filho
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-05-18 17:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, lcapitulino

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 the information
of a NIC.

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

diff --git a/net.c b/net.c
index efa8b3d..9e8a8ab 100644
--- a/net.c
+++ b/net.c
@@ -173,6 +173,22 @@ void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6])
              macaddr[3], macaddr[4], macaddr[5]);
 }
 
+void qemu_format_nic_info_dict(VLANClientState *vc, uint8_t macaddr[6])
+{
+    char mac[18];
+
+    if (vc->info_dict == NULL) {
+        vc->info_dict = qdict_new();
+    }
+
+    snprintf(mac, sizeof(mac), "%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)
 {
     static int index = 0;
@@ -301,6 +317,7 @@ void qemu_del_vlan_client(VLANClientState *vc)
 
     qemu_free(vc->name);
     qemu_free(vc->model);
+    QDECREF(vc->info_dict);
     qemu_free(vc);
 }
 
diff --git a/net.h b/net.h
index b83f615..4566f7d 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;
 };
 
@@ -111,6 +112,7 @@ ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf,
 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);
-- 
1.7.1

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

* [Qemu-devel] [PATCH v4 03/10] net: various devices: add qemu_format_nic_info_dict
  2010-05-18 17:07 [Qemu-devel] [PATCH v4 0/10] Introduce 'info netdevices' with QMP support Miguel Di Ciurcio Filho
  2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 01/10] QObject API: introduce qdict_to_qstring() function Miguel Di Ciurcio Filho
  2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 02/10] net: introduce qemu_nic_format_info_dict and VLANClientState->info_dict Miguel Di Ciurcio Filho
@ 2010-05-18 17:07 ` Miguel Di Ciurcio Filho
  2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 04/10] net: xen: introduce info_dict Miguel Di Ciurcio Filho
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-05-18 17:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, lcapitulino

These are simple one line additions of qemu_format_nic_info_dict.

Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
---
 hw/dp8393x.c        |    1 +
 hw/e1000.c          |    1 +
 hw/eepro100.c       |    2 ++
 hw/lan9118.c        |    2 ++
 hw/mcf_fec.c        |    1 +
 hw/mipsnet.c        |    1 +
 hw/ne2000-isa.c     |    1 +
 hw/ne2000.c         |    1 +
 hw/pcnet.c          |    1 +
 hw/rtl8139.c        |    1 +
 hw/smc91c111.c      |    1 +
 hw/stellaris_enet.c |    1 +
 hw/usb-net.c        |    1 +
 hw/virtio-net.c     |    2 ++
 hw/xilinx_ethlite.c |    1 +
 15 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/hw/dp8393x.c b/hw/dp8393x.c
index e65e4d1..31fb1cb 100644
--- a/hw/dp8393x.c
+++ b/hw/dp8393x.c
@@ -905,6 +905,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);
 
diff --git a/hw/e1000.c b/hw/e1000.c
index 34cc451..faee35c 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -1126,6 +1126,7 @@ static int pci_e1000_init(PCIDevice *pci_dev)
                           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;
 }
 
diff --git a/hw/eepro100.c b/hw/eepro100.c
index a74d834..bd210ff 100644
--- a/hw/eepro100.c
+++ b/hw/eepro100.c
@@ -1887,6 +1887,8 @@ static int e100_nic_init(PCIDevice *pci_dev)
                           pci_dev->qdev.info->name, pci_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);
+
     TRACE(OTHER, logout("%s\n", s->nic->nc.info_str));
 
     qemu_register_reset(nic_reset, s);
diff --git a/hw/lan9118.c b/hw/lan9118.c
index 16d3330..c392666 100644
--- a/hw/lan9118.c
+++ b/hw/lan9118.c
@@ -233,6 +233,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)
@@ -1131,6 +1132,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];
diff --git a/hw/mcf_fec.c b/hw/mcf_fec.c
index 4e7fbed..1d3e280 100644
--- a/hw/mcf_fec.c
+++ b/hw/mcf_fec.c
@@ -477,4 +477,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);
 }
diff --git a/hw/mipsnet.c b/hw/mipsnet.c
index a066f63..9134fd0 100644
--- a/hw/mipsnet.c
+++ b/hw/mipsnet.c
@@ -281,6 +281,7 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd)
                               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);
diff --git a/hw/ne2000-isa.c b/hw/ne2000-isa.c
index 03a5a1f..3cc2503 100644
--- a/hw/ne2000-isa.c
+++ b/hw/ne2000-isa.c
@@ -85,6 +85,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;
 }
diff --git a/hw/ne2000.c b/hw/ne2000.c
index 78fe14f..fb92c8b 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -738,6 +738,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;
diff --git a/hw/pcnet.c b/hw/pcnet.c
index 5e63eb5..5356ab4 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -1898,6 +1898,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;
 }
 
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index 72e2242..a5cd1fb 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -3383,6 +3383,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;
diff --git a/hw/smc91c111.c b/hw/smc91c111.c
index f7d58e1..d62a5fd 100644
--- a/hw/smc91c111.c
+++ b/hw/smc91c111.c
@@ -729,6 +729,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;
 }
diff --git a/hw/stellaris_enet.c b/hw/stellaris_enet.c
index d1d755e..fec9470 100644
--- a/hw/stellaris_enet.c
+++ b/hw/stellaris_enet.c
@@ -417,6 +417,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,
diff --git a/hw/usb-net.c b/hw/usb-net.c
index a43bd17..9dacaaa 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1454,6 +1454,7 @@ static int usb_net_initfn(USBDevice *dev)
     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,
diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index d602c56..e70c05c 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -91,6 +91,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);
     }
 }
 
@@ -911,6 +912,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;
diff --git a/hw/xilinx_ethlite.c b/hw/xilinx_ethlite.c
index 37e33ec..ea4fb96 100644
--- a/hw/xilinx_ethlite.c
+++ b/hw/xilinx_ethlite.c
@@ -231,6 +231,7 @@ static int xilinx_ethlite_init(SysBusDevice *dev)
     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;
 }
 
-- 
1.7.1

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

* [Qemu-devel] [PATCH v4 04/10] net: xen: introduce info_dict
  2010-05-18 17:07 [Qemu-devel] [PATCH v4 0/10] Introduce 'info netdevices' with QMP support Miguel Di Ciurcio Filho
                   ` (2 preceding siblings ...)
  2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 03/10] net: various devices: add qemu_format_nic_info_dict Miguel Di Ciurcio Filho
@ 2010-05-18 17:07 ` Miguel Di Ciurcio Filho
  2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 05/10] net: tap/tap-win32: " Miguel Di Ciurcio Filho
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-05-18 17:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, lcapitulino

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

diff --git a/hw/xen_nic.c b/hw/xen_nic.c
index 08055b8..1820059 100644
--- a/hw/xen_nic.c
+++ b/hw/xen_nic.c
@@ -321,6 +321,11 @@ static int net_init(struct XenDevice *xendev)
     snprintf(netdev->nic->nc.info_str, sizeof(netdev->nic->nc.info_str),
              "nic: xenbus vif macaddr=%s", netdev->mac);
 
+    netdev->nic->nc.info_dict = qdict_new();
+    qdict_put(netdev->nic->nc.info_dict, "macaddr",
+        qstring_from_str(netdev->mac));
+    qdict_put(netdev->nic->nc.info_dict, "model", qstring_from_str("xen"));
+
     /* fill info */
     xenstore_write_be_int(&netdev->xendev, "feature-rx-copy", 1);
     xenstore_write_be_int(&netdev->xendev, "feature-rx-flip", 0);
-- 
1.7.1

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

* [Qemu-devel] [PATCH v4 05/10] net: tap/tap-win32: introduce info_dict
  2010-05-18 17:07 [Qemu-devel] [PATCH v4 0/10] Introduce 'info netdevices' with QMP support Miguel Di Ciurcio Filho
                   ` (3 preceding siblings ...)
  2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 04/10] net: xen: introduce info_dict Miguel Di Ciurcio Filho
@ 2010-05-18 17:07 ` Miguel Di Ciurcio Filho
  2010-05-27 17:50   ` [Qemu-devel] " Luiz Capitulino
  2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 06/10] net: vde: " Miguel Di Ciurcio Filho
                   ` (5 subsequent siblings)
  10 siblings, 1 reply; 15+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-05-18 17:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, lcapitulino

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

diff --git a/net/tap-win32.c b/net/tap-win32.c
index 74348da..54c6725 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>
@@ -691,7 +693,12 @@ static int tap_win32_init(VLANState *vlan, const char *model,
     s = DO_UPCAST(TAPState, nc, nc);
 
     snprintf(s->nc.info_str, sizeof(s->nc.info_str),
-             "tap: ifname=%s", ifname);
+                "tap: ifname=%s", ifname);
+
+    nc->info_dict = qdict_new()
+
+    qdict_put(nc->info_dict, "ifname", qstring_from_str(ifname));
+    qdict_put(nc->info_dict, "model", qstring_from_str("tap"));
 
     s->handle = handle;
 
diff --git a/net/tap.c b/net/tap.c
index 0147dab..d71f312 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 "qdict.h"
+#include "qint.h"
 
 #include "net/tap-linux.h"
 
@@ -448,17 +451,30 @@ 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");
         downscript = qemu_opt_get(opts, "downscript");
 
         snprintf(s->nc.info_str, sizeof(s->nc.info_str),
-                 "ifname=%s,script=%s,downscript=%s",
+                "ifname=%s,script=%s,downscript=%s",
                  ifname, script, downscript);
 
+        obj = qobject_from_jsonf("{ 'model': 'tap', '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);
-- 
1.7.1

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

* [Qemu-devel] [PATCH v4 06/10] net: vde: introduce info_dict
  2010-05-18 17:07 [Qemu-devel] [PATCH v4 0/10] Introduce 'info netdevices' with QMP support Miguel Di Ciurcio Filho
                   ` (4 preceding siblings ...)
  2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 05/10] net: tap/tap-win32: " Miguel Di Ciurcio Filho
@ 2010-05-18 17:07 ` Miguel Di Ciurcio Filho
  2010-05-27 17:51   ` [Qemu-devel] " Luiz Capitulino
  2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 07/10] net: dump: " Miguel Di Ciurcio Filho
                   ` (4 subsequent siblings)
  10 siblings, 1 reply; 15+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-05-18 17:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, lcapitulino

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

diff --git a/net/vde.c b/net/vde.c
index 0b46fa6..6a3d0ba 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 {
@@ -100,7 +103,13 @@ 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));
+                sock, vde_datafd(vde));
+
+
+    nc->info_dict = qdict_new();
+    qdict_put(nc->info_dict, "sock", qstring_from_str(sock));
+    qdict_put(nc->info_dict, "model", qstring_from_str("vde"));
+    qdict_put(nc->info_dict, "fd", qint_from_int(vde_datafd(vde)));
 
     s = DO_UPCAST(VDEState, nc, nc);
 
-- 
1.7.1

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

* [Qemu-devel] [PATCH v4 07/10] net: dump: introduce info_dict
  2010-05-18 17:07 [Qemu-devel] [PATCH v4 0/10] Introduce 'info netdevices' with QMP support Miguel Di Ciurcio Filho
                   ` (5 preceding siblings ...)
  2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 06/10] net: vde: " Miguel Di Ciurcio Filho
@ 2010-05-18 17:07 ` Miguel Di Ciurcio Filho
  2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 08/10] net: slirp: " Miguel Di Ciurcio Filho
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-05-18 17:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, lcapitulino

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

diff --git a/net/dump.c b/net/dump.c
index 6db7ecf..32514ad 100644
--- a/net/dump.c
+++ b/net/dump.c
@@ -26,6 +26,9 @@
 #include "qemu-common.h"
 #include "sysemu.h"
 #include "qemu-error.h"
+#include "qdict.h"
+#include "qstring.h"
+#include "qint.h"
 #include "qemu-log.h"
 
 typedef struct DumpState {
@@ -129,7 +132,12 @@ 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);
+                "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));
+    qdict_put(nc->info_dict, "model", qstring_from_str("dump"));
 
     s = DO_UPCAST(DumpState, nc, nc);
 
-- 
1.7.1

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

* [Qemu-devel] [PATCH v4 08/10] net: slirp: introduce info_dict
  2010-05-18 17:07 [Qemu-devel] [PATCH v4 0/10] Introduce 'info netdevices' with QMP support Miguel Di Ciurcio Filho
                   ` (6 preceding siblings ...)
  2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 07/10] net: dump: " Miguel Di Ciurcio Filho
@ 2010-05-18 17:07 ` Miguel Di Ciurcio Filho
  2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 09/10] net: socket: " Miguel Di Ciurcio Filho
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-05-18 17:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, lcapitulino

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

diff --git a/net/slirp.c b/net/slirp.c
index b41c60a..a6e25ff 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -32,6 +32,9 @@
 #include "monitor.h"
 #include "sysemu.h"
 #include "qemu_socket.h"
+#include "qdict.h"
+#include "qbool.h"
+#include "qstring.h"
 #include "slirp/libslirp.h"
 
 static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
@@ -241,7 +244,12 @@ 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');
+            "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, "model", qstring_from_str("slirp"));
+    qdict_put(nc->info_dict, "restricted", qbool_from_int(restricted));
 
     s = DO_UPCAST(SlirpState, nc, nc);
 
-- 
1.7.1

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

* [Qemu-devel] [PATCH v4 09/10] net: socket: introduce info_dict
  2010-05-18 17:07 [Qemu-devel] [PATCH v4 0/10] Introduce 'info netdevices' with QMP support Miguel Di Ciurcio Filho
                   ` (7 preceding siblings ...)
  2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 08/10] net: slirp: " Miguel Di Ciurcio Filho
@ 2010-05-18 17:07 ` Miguel Di Ciurcio Filho
  2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 10/10] monitor/net: introduce 'info netdevices' with QMP support Miguel Di Ciurcio Filho
  2010-05-27 17:50 ` [Qemu-devel] Re: [PATCH v4 0/10] Introduce " Luiz Capitulino
  10 siblings, 0 replies; 15+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-05-18 17:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, lcapitulino

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

diff --git a/net/socket.c b/net/socket.c
index 1c4e153..5be1b54 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,16 @@ 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("{ 'model': 'socket', \
+        '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 +380,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 +476,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 +509,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] 15+ messages in thread

* [Qemu-devel] [PATCH v4 10/10] monitor/net: introduce 'info netdevices' with QMP support
  2010-05-18 17:07 [Qemu-devel] [PATCH v4 0/10] Introduce 'info netdevices' with QMP support Miguel Di Ciurcio Filho
                   ` (8 preceding siblings ...)
  2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 09/10] net: socket: " Miguel Di Ciurcio Filho
@ 2010-05-18 17:07 ` Miguel Di Ciurcio Filho
  2010-05-27 17:50 ` [Qemu-devel] Re: [PATCH v4 0/10] Introduce " Luiz Capitulino
  10 siblings, 0 replies; 15+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-05-18 17:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, lcapitulino

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

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

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

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

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

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

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

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

* [Qemu-devel] Re: [PATCH v4 0/10] Introduce 'info netdevices' with QMP support
  2010-05-18 17:07 [Qemu-devel] [PATCH v4 0/10] Introduce 'info netdevices' with QMP support Miguel Di Ciurcio Filho
                   ` (9 preceding siblings ...)
  2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 10/10] monitor/net: introduce 'info netdevices' with QMP support Miguel Di Ciurcio Filho
@ 2010-05-27 17:50 ` Luiz Capitulino
  10 siblings, 0 replies; 15+ messages in thread
From: Luiz Capitulino @ 2010-05-27 17:50 UTC (permalink / raw)
  To: Miguel Di Ciurcio Filho; +Cc: qemu-devel, armbru

On Tue, 18 May 2010 14:07:39 -0300
Miguel Di Ciurcio Filho <miguel.filho@gmail.com> wrote:

> 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.
> 
> To make the transition to QMP safe, we leave the current 'info network' command
> as is, and introduce a new one: 'info netdevices'.

 Sorry for the long delay in reviewing this series..

 Most important comment is: QMP development process is changing and now
it's required that any protocol change updates the qemu-monitor.hx file
with QMP info.

 However, it's not merged yet so you could base your series on top of
this series, which is also in my master branch:

http://lists.gnu.org/archive/html/qemu-devel/2010-05/msg01605.html

 Another option is to send the doc patch separately w/o any code and
only go back to code when there's consensus wrt new command.

 Small comments on separate patches follow.

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

* [Qemu-devel] Re: [PATCH v4 01/10] QObject API: introduce qdict_to_qstring() function
  2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 01/10] QObject API: introduce qdict_to_qstring() function Miguel Di Ciurcio Filho
@ 2010-05-27 17:50   ` Luiz Capitulino
  0 siblings, 0 replies; 15+ messages in thread
From: Luiz Capitulino @ 2010-05-27 17:50 UTC (permalink / raw)
  To: Miguel Di Ciurcio Filho; +Cc: qemu-devel, armbru

On Tue, 18 May 2010 14:07:40 -0300
Miguel Di Ciurcio Filho <miguel.filho@gmail.com> wrote:

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

 It's very better now, some comments below.

> ---
>  qdict.c |   55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  qdict.h |    9 +++++++++
>  2 files changed, 64 insertions(+), 0 deletions(-)
> 
> diff --git a/qdict.c b/qdict.c
> index 175bc17..19c053f 100644
> --- a/qdict.c
> +++ b/qdict.c
> @@ -267,6 +267,61 @@ const char *qdict_get_str(const QDict *qdict, const char *key)
>      return qstring_get_str(qobject_to_qstring(obj));
>  }
>  
> +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->qdict_iter_current_key++;
> +
> +    if (pack->qdict_iter_current_key < pack->qdict_iter_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));

 You can allocate on the stack.

> +    pack->str = str;
> +    pack->qdict_iter_current_key = 0;
> +    pack->qdict_iter_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..8a54733 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>
>  
> @@ -32,6 +33,13 @@ typedef struct QDict {
>      QLIST_HEAD(,QDictEntry) table[QDICT_HASH_SIZE];
>  } QDict;
>  
> +struct qstring_pack {
> +    QString *str;
> +    size_t qdict_iter_total_keys;
> +    size_t qdict_iter_current_key;
> +    const char *separator;
> +};

 The header file should contain only public interfaces, qstring_pack is
something internal to qdict.c so please move this right above
qdict_to_qstring_iter() also suggest shorter names like 'total_keys'.

> +
>  /* Object API */
>  QDict *qdict_new(void);
>  size_t qdict_size(const QDict *qdict);
> @@ -55,6 +63,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);

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

* [Qemu-devel] Re: [PATCH v4 05/10] net: tap/tap-win32: introduce info_dict
  2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 05/10] net: tap/tap-win32: " Miguel Di Ciurcio Filho
@ 2010-05-27 17:50   ` Luiz Capitulino
  0 siblings, 0 replies; 15+ messages in thread
From: Luiz Capitulino @ 2010-05-27 17:50 UTC (permalink / raw)
  To: Miguel Di Ciurcio Filho; +Cc: qemu-devel, armbru

On Tue, 18 May 2010 14:07:44 -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 |    9 ++++++++-
>  net/tap.c       |   18 +++++++++++++++++-
>  2 files changed, 25 insertions(+), 2 deletions(-)
> 
> diff --git a/net/tap-win32.c b/net/tap-win32.c
> index 74348da..54c6725 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>
> @@ -691,7 +693,12 @@ static int tap_win32_init(VLANState *vlan, const char *model,
>      s = DO_UPCAST(TAPState, nc, nc);
>  
>      snprintf(s->nc.info_str, sizeof(s->nc.info_str),
> -             "tap: ifname=%s", ifname);
> +                "tap: ifname=%s", ifname);

 Did you change this by accident?

> +
> +    nc->info_dict = qdict_new()
> +
> +    qdict_put(nc->info_dict, "ifname", qstring_from_str(ifname));
> +    qdict_put(nc->info_dict, "model", qstring_from_str("tap"));

 So, this is the kind of thing that deserves attention when documenting,
we need to make it clear in the doc what's each format we support, ie.
xen, tap, vde, dump, slirp and socket.

>  
>      s->handle = handle;
>  
> diff --git a/net/tap.c b/net/tap.c
> index 0147dab..d71f312 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 "qdict.h"
> +#include "qint.h"
>  
>  #include "net/tap-linux.h"
>  
> @@ -448,17 +451,30 @@ 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");
>          downscript = qemu_opt_get(opts, "downscript");
>  
>          snprintf(s->nc.info_str, sizeof(s->nc.info_str),
> -                 "ifname=%s,script=%s,downscript=%s",
> +                "ifname=%s,script=%s,downscript=%s",

 Another accidental change, I think.

>                   ifname, script, downscript);
>  
> +        obj = qobject_from_jsonf("{ 'model': 'tap', '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);

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

* [Qemu-devel] Re: [PATCH v4 06/10] net: vde: introduce info_dict
  2010-05-18 17:07 ` [Qemu-devel] [PATCH v4 06/10] net: vde: " Miguel Di Ciurcio Filho
@ 2010-05-27 17:51   ` Luiz Capitulino
  0 siblings, 0 replies; 15+ messages in thread
From: Luiz Capitulino @ 2010-05-27 17:51 UTC (permalink / raw)
  To: Miguel Di Ciurcio Filho; +Cc: qemu-devel, armbru

On Tue, 18 May 2010 14:07:45 -0300
Miguel Di Ciurcio Filho <miguel.filho@gmail.com> wrote:

> Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
> ---
>  net/vde.c |   11 ++++++++++-
>  1 files changed, 10 insertions(+), 1 deletions(-)
> 
> diff --git a/net/vde.c b/net/vde.c
> index 0b46fa6..6a3d0ba 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 {
> @@ -100,7 +103,13 @@ 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));
> +                sock, vde_datafd(vde));

 This change is not needed.

> +
> +
> +    nc->info_dict = qdict_new();
> +    qdict_put(nc->info_dict, "sock", qstring_from_str(sock));
> +    qdict_put(nc->info_dict, "model", qstring_from_str("vde"));
> +    qdict_put(nc->info_dict, "fd", qint_from_int(vde_datafd(vde)));
>  
>      s = DO_UPCAST(VDEState, nc, nc);
>  

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

end of thread, other threads:[~2010-05-27 17:51 UTC | newest]

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).