All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v3 00/12] Convert do_info_network() to QObject/QMP
@ 2010-04-15 14:06 Miguel Di Ciurcio Filho
  2010-04-15 14:06 ` [Qemu-devel] [PATCH v3 01/12] QObject API: add qdict_to_qstring() function Miguel Di Ciurcio Filho
                   ` (11 more replies)
  0 siblings, 12 replies; 20+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-04-15 14:06 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.

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-10 updates all devices to feed information into the new QDict info_dict.

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

Patch 12 removes info_str from VLANClientState and the function
qemu_nic_format_info_str.

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] 20+ messages in thread

* [Qemu-devel] [PATCH v3 01/12] QObject API: add qdict_to_qstring() function
  2010-04-15 14:06 [Qemu-devel] [PATCH v3 00/12] Convert do_info_network() to QObject/QMP Miguel Di Ciurcio Filho
@ 2010-04-15 14:06 ` Miguel Di Ciurcio Filho
  2010-04-23 21:04   ` [Qemu-devel] " Luiz Capitulino
  2010-04-15 14:06 ` [Qemu-devel] [PATCH v3 02/12] net: add qemu_nic_format_info_dict and VLANClientState->info_dict Miguel Di Ciurcio Filho
                   ` (10 subsequent siblings)
  11 siblings, 1 reply; 20+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-04-15 14:06 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 SPACE key2=value2 SPACE key3=value3

Handy for debugging and other things.

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

diff --git a/qdict.c b/qdict.c
index aae57bf..fddade0 100644
--- a/qdict.c
+++ b/qdict.c
@@ -324,6 +324,47 @@ 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.
+ *
+ * Nested lists and dicts are not supported, yet.
+ *
+ * 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
  */
diff --git a/qdict.h b/qdict.h
index 579dcdd..6731555 100644
--- a/qdict.h
+++ b/qdict.h
@@ -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);
-- 
1.7.0.4

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

* [Qemu-devel] [PATCH v3 02/12] net: add qemu_nic_format_info_dict and VLANClientState->info_dict
  2010-04-15 14:06 [Qemu-devel] [PATCH v3 00/12] Convert do_info_network() to QObject/QMP Miguel Di Ciurcio Filho
  2010-04-15 14:06 ` [Qemu-devel] [PATCH v3 01/12] QObject API: add qdict_to_qstring() function Miguel Di Ciurcio Filho
@ 2010-04-15 14:06 ` Miguel Di Ciurcio Filho
  2010-04-23 21:05   ` [Qemu-devel] " Luiz Capitulino
  2010-04-15 14:06 ` [Qemu-devel] [PATCH v3 03/12] net: eepro100: replace qemu_format_nic_info_str by qemu_format_nic_info_dict Miguel Di Ciurcio Filho
                   ` (9 subsequent siblings)
  11 siblings, 1 reply; 20+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-04-15 14:06 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.

Patches that convert the devices to use this new function will follow.

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

diff --git a/net.c b/net.c
index d7d76eb..8c02f28 100644
--- a/net.c
+++ b/net.c
@@ -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;
@@ -173,6 +175,19 @@ 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])
+{
+    vc->info_dict = qdict_new();
+    char mac[18];
+
+    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 +316,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 c7a3a1b..d12276a 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.0.4

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

* [Qemu-devel] [PATCH v3 03/12] net: eepro100: replace qemu_format_nic_info_str by qemu_format_nic_info_dict
  2010-04-15 14:06 [Qemu-devel] [PATCH v3 00/12] Convert do_info_network() to QObject/QMP Miguel Di Ciurcio Filho
  2010-04-15 14:06 ` [Qemu-devel] [PATCH v3 01/12] QObject API: add qdict_to_qstring() function Miguel Di Ciurcio Filho
  2010-04-15 14:06 ` [Qemu-devel] [PATCH v3 02/12] net: add qemu_nic_format_info_dict and VLANClientState->info_dict Miguel Di Ciurcio Filho
@ 2010-04-15 14:06 ` Miguel Di Ciurcio Filho
  2010-04-15 15:32   ` Richard Henderson
  2010-04-15 14:06 ` [Qemu-devel] [PATCH v3 04/12] net: various devices: " Miguel Di Ciurcio Filho
                   ` (8 subsequent siblings)
  11 siblings, 1 reply; 20+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-04-15 14:06 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, lcapitulino

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

diff --git a/hw/eepro100.c b/hw/eepro100.c
index 7db6fb5..457bda8 100644
--- a/hw/eepro100.c
+++ b/hw/eepro100.c
@@ -1978,8 +1978,14 @@ 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);
+
+#ifdef DEBUG_EEPRO100
+    QString *qstring;
+    qstring = qdict_to_qstring(s->nic->nc.info_dict);
+    TRACE(OTHER, logout("%s\n", qstring_get_str(qstring)));
+    QDECREF(qstring);
+#endif
 
     qemu_register_reset(nic_reset, s);
 
-- 
1.7.0.4

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

* [Qemu-devel] [PATCH v3 04/12] net: various devices: replace qemu_format_nic_info_str by qemu_format_nic_info_dict
  2010-04-15 14:06 [Qemu-devel] [PATCH v3 00/12] Convert do_info_network() to QObject/QMP Miguel Di Ciurcio Filho
                   ` (2 preceding siblings ...)
  2010-04-15 14:06 ` [Qemu-devel] [PATCH v3 03/12] net: eepro100: replace qemu_format_nic_info_str by qemu_format_nic_info_dict Miguel Di Ciurcio Filho
@ 2010-04-15 14:06 ` Miguel Di Ciurcio Filho
  2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 05/12] net: slirp: use info_dict instead of info_str Miguel Di Ciurcio Filho
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-04-15 14:06 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, lcapitulino

These are simple one line changes to replace qemu_format_nic_info_str.

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

diff --git a/hw/dp8393x.c b/hw/dp8393x.c
index e65e4d1..ebb41a2 100644
--- a/hw/dp8393x.c
+++ b/hw/dp8393x.c
@@ -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);
 
diff --git a/hw/e1000.c b/hw/e1000.c
index fd3059a..7cbff0d 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -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;
 }
 
diff --git a/hw/lan9118.c b/hw/lan9118.c
index 16d3330..07f9429 100644
--- a/hw/lan9118.c
+++ b/hw/lan9118.c
@@ -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];
diff --git a/hw/mcf_fec.c b/hw/mcf_fec.c
index 4e7fbed..1e592d2 100644
--- a/hw/mcf_fec.c
+++ b/hw/mcf_fec.c
@@ -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);
 }
diff --git a/hw/mipsnet.c b/hw/mipsnet.c
index a066f63..96bb588 100644
--- a/hw/mipsnet.c
+++ b/hw/mipsnet.c
@@ -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);
diff --git a/hw/ne2000-isa.c b/hw/ne2000-isa.c
index 03a5a1f..d5403d9 100644
--- a/hw/ne2000-isa.c
+++ b/hw/ne2000-isa.c
@@ -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;
 }
diff --git a/hw/ne2000.c b/hw/ne2000.c
index 78fe14f..6a91ec0 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -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;
diff --git a/hw/pcnet.c b/hw/pcnet.c
index 5e63eb5..7df39c4 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -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;
 }
 
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index 72e2242..ee4fc5d 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -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;
diff --git a/hw/smc91c111.c b/hw/smc91c111.c
index c1a88c9..767fc19 100644
--- a/hw/smc91c111.c
+++ b/hw/smc91c111.c
@@ -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;
 }
diff --git a/hw/stellaris_enet.c b/hw/stellaris_enet.c
index d1d755e..cf28670 100644
--- a/hw/stellaris_enet.c
+++ b/hw/stellaris_enet.c
@@ -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,
diff --git a/hw/usb-net.c b/hw/usb-net.c
index ff0ca44..1583425 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -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,
diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 970ba06..482a176 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -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;
diff --git a/hw/xilinx_ethlite.c b/hw/xilinx_ethlite.c
index 37e33ec..345aea7 100644
--- a/hw/xilinx_ethlite.c
+++ b/hw/xilinx_ethlite.c
@@ -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;
 }
 
-- 
1.7.0.4

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

* [Qemu-devel] [PATCH v3 05/12] net: slirp: use info_dict instead of info_str
  2010-04-15 14:06 [Qemu-devel] [PATCH v3 00/12] Convert do_info_network() to QObject/QMP Miguel Di Ciurcio Filho
                   ` (3 preceding siblings ...)
  2010-04-15 14:06 ` [Qemu-devel] [PATCH v3 04/12] net: various devices: " Miguel Di Ciurcio Filho
@ 2010-04-15 14:07 ` Miguel Di Ciurcio Filho
  2010-04-23 21:06   ` [Qemu-devel] " Luiz Capitulino
  2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 06/12] net: tap/tap-win32: " Miguel Di Ciurcio Filho
                   ` (6 subsequent siblings)
  11 siblings, 1 reply; 20+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-04-15 14:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, lcapitulino

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

diff --git a/net/slirp.c b/net/slirp.c
index b41c60a..eb9d261 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)
@@ -240,8 +243,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", qbool_from_int(restricted));
 
     s = DO_UPCAST(SlirpState, nc, nc);
 
-- 
1.7.0.4

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

* [Qemu-devel] [PATCH v3 06/12] net: tap/tap-win32: use info_dict instead of info_str
  2010-04-15 14:06 [Qemu-devel] [PATCH v3 00/12] Convert do_info_network() to QObject/QMP Miguel Di Ciurcio Filho
                   ` (4 preceding siblings ...)
  2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 05/12] net: slirp: use info_dict instead of info_str Miguel Di Ciurcio Filho
@ 2010-04-15 14:07 ` Miguel Di Ciurcio Filho
  2010-04-23 21:08   ` [Qemu-devel] " Luiz Capitulino
  2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 07/12] net: vde: " Miguel Di Ciurcio Filho
                   ` (5 subsequent siblings)
  11 siblings, 1 reply; 20+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-04-15 14: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, 19 insertions(+), 8 deletions(-)

diff --git a/net/tap-win32.c b/net/tap-win32.c
index 74348da..a54cd31 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>
@@ -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_from_str(ifname));
+    
+    s = DO_UPCAST(TAPState, nc, nc);
 
     s->handle = handle;
 
diff --git a/net/tap.c b/net/tap.c
index 303d69f..8ba7eed 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 "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);
-- 
1.7.0.4

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

* [Qemu-devel] [PATCH v3 07/12] net: vde: use info_dict instead of info_str
  2010-04-15 14:06 [Qemu-devel] [PATCH v3 00/12] Convert do_info_network() to QObject/QMP Miguel Di Ciurcio Filho
                   ` (5 preceding siblings ...)
  2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 06/12] net: tap/tap-win32: " Miguel Di Ciurcio Filho
@ 2010-04-15 14:07 ` Miguel Di Ciurcio Filho
  2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 08/12] net: dump: " Miguel Di Ciurcio Filho
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-04-15 14:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, lcapitulino

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

diff --git a/net/vde.c b/net/vde.c
index 0b46fa6..f582878 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 {
@@ -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);
 
-- 
1.7.0.4

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

* [Qemu-devel] [PATCH v3 08/12] net: dump: use info_dict instead of info_str
  2010-04-15 14:06 [Qemu-devel] [PATCH v3 00/12] Convert do_info_network() to QObject/QMP Miguel Di Ciurcio Filho
                   ` (6 preceding siblings ...)
  2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 07/12] net: vde: " Miguel Di Ciurcio Filho
@ 2010-04-15 14:07 ` Miguel Di Ciurcio Filho
  2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 09/12] net: socket: " Miguel Di Ciurcio Filho
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-04-15 14:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, lcapitulino

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

diff --git a/net/dump.c b/net/dump.c
index 6db7ecf..dea7f7d 100644
--- a/net/dump.c
+++ b/net/dump.c
@@ -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);
 
-- 
1.7.0.4

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

* [Qemu-devel] [PATCH v3 09/12] net: socket: use info_dict instead of info_str
  2010-04-15 14:06 [Qemu-devel] [PATCH v3 00/12] Convert do_info_network() to QObject/QMP Miguel Di Ciurcio Filho
                   ` (7 preceding siblings ...)
  2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 08/12] net: dump: " Miguel Di Ciurcio Filho
@ 2010-04-15 14:07 ` Miguel Di Ciurcio Filho
  2010-04-23 21:10   ` [Qemu-devel] " Luiz Capitulino
  2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 10/12] net: xen: " Miguel Di Ciurcio Filho
                   ` (2 subsequent siblings)
  11 siblings, 1 reply; 20+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-04-15 14:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, lcapitulino

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

diff --git a/net/socket.c b/net/socket.c
index 1c4e153..fa5d24d 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -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,14 @@ 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));
+    qdict_put(nc->info_dict, "host",
+        qstring_from_str(inet_ntoa(saddr.sin_addr)));
+    qdict_put(nc->info_dict, "service", qint_from_int(ntohs(saddr.sin_port)));
+    qdict_put(nc->info_dict, "family", qstring_from_str("ipv4"));
+    qdict_put(nc->info_dict, "cloned", qbool_from_int(is_connected));
 
     s = DO_UPCAST(NetSocketState, nc, nc);
 
@@ -306,8 +313,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 +374,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",
-                 inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
+        s1->nc.info_dict = qdict_new();
+
+        qdict_put(s1->nc.info_dict, "host",
+            qstring_from_str(inet_ntoa(saddr.sin_addr)));
+        qdict_put(s1->nc.info_dict, "service", qint_from_int(ntohs(saddr.sin_port)));
+        qdict_put(s1->nc.info_dict, "family", qstring_from_str("ipv4"));
     }
 }
 
@@ -459,9 +470,12 @@ 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",
-             inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
+
+    s->nc.info_dict = qdict_new();
+    qdict_put(s->nc.info_dict, "host",
+        qstring_from_str(inet_ntoa(saddr.sin_addr)));
+    qdict_put(s->nc.info_dict, "service", qint_from_int(ntohs(saddr.sin_port)));
+    qdict_put(s->nc.info_dict, "family", qstring_from_str("ipv4"));
     return 0;
 }
 
@@ -487,10 +501,13 @@ static int net_socket_mcast_init(VLANState *vlan,
         return -1;
 
     s->dgram_dst = saddr;
+    
+    s->nc.info_dict = qdict_new();
+    qdict_put(s->nc.info_dict, "host",
+        qstring_from_str(inet_ntoa(saddr.sin_addr)));
+    qdict_put(s->nc.info_dict, "service", qint_from_int(ntohs(saddr.sin_port)));
+    qdict_put(s->nc.info_dict, "family", qstring_from_str("ipv4"));
 
-    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;
 
 }
-- 
1.7.0.4

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

* [Qemu-devel] [PATCH v3 10/12] net: xen: use info_dict instead of info_str
  2010-04-15 14:06 [Qemu-devel] [PATCH v3 00/12] Convert do_info_network() to QObject/QMP Miguel Di Ciurcio Filho
                   ` (8 preceding siblings ...)
  2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 09/12] net: socket: " Miguel Di Ciurcio Filho
@ 2010-04-15 14:07 ` Miguel Di Ciurcio Filho
  2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 11/12] monitor/net: Convert do_info_network() to QObject/QMP Miguel Di Ciurcio Filho
  2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 12/12] net: Remove info_str from VLANClientState, not needed anymore Miguel Di Ciurcio Filho
  11 siblings, 0 replies; 20+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-04-15 14: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 |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/hw/xen_nic.c b/hw/xen_nic.c
index 08055b8..d51839d 100644
--- a/hw/xen_nic.c
+++ b/hw/xen_nic.c
@@ -43,6 +43,8 @@
 #include "net/checksum.h"
 #include "net/util.h"
 #include "qemu-char.h"
+#include "qdict.h"
+#include "qstring.h"
 #include "xen_backend.h"
 
 /* ------------------------------------------------------------- */
@@ -318,8 +320,8 @@ static int net_init(struct XenDevice *xendev)
     netdev->nic = qemu_new_nic(&net_xen_info, &netdev->conf,
                                "xen", NULL, netdev);
 
-    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));
 
     /* fill info */
     xenstore_write_be_int(&netdev->xendev, "feature-rx-copy", 1);
-- 
1.7.0.4

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

* [Qemu-devel] [PATCH v3 11/12] monitor/net: Convert do_info_network() to QObject/QMP
  2010-04-15 14:06 [Qemu-devel] [PATCH v3 00/12] Convert do_info_network() to QObject/QMP Miguel Di Ciurcio Filho
                   ` (9 preceding siblings ...)
  2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 10/12] net: xen: " Miguel Di Ciurcio Filho
@ 2010-04-15 14:07 ` Miguel Di Ciurcio Filho
  2010-04-23 21:13   ` [Qemu-devel] " Luiz Capitulino
  2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 12/12] net: Remove info_str from VLANClientState, not needed anymore Miguel Di Ciurcio Filho
  11 siblings, 1 reply; 20+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-04-15 14:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, lcapitulino

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.

Old output:
  (qemu) info network
  VLAN 1 devices:
    e1000.0: model=e1000,macaddr=52:54:00:12:34:56
  VLAN 0 devices:
    tap.0: ifname=tap0,script=/etc/kvm/kvm-ifup,downscript=/etc/qemu-ifdown
  Devices not on any VLAN:

New output:
  (qemu) info network
  Devices on VLANs:
    e1000.0: vlan=1 model=e1000 macaddr=52:54:00:12:34:56
    tap.0: vlan=0 script=/etc/kvm/kvm-ifup downscript=/etc/qemu-ifdown ifname=tap0
  Devices not on any VLAN:

Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
---
 monitor.c |    3 +-
 net.c     |  127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 net.h     |    3 +-
 3 files changed, 122 insertions(+), 11 deletions(-)

diff --git a/monitor.c b/monitor.c
index 4c6275e..34781ba 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2610,7 +2610,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",
diff --git a/net.c b/net.c
index 8c02f28..46e8873 100644
--- a/net.c
+++ b/net.c
@@ -35,6 +35,8 @@
 #include "sysemu.h"
 #include "qemu-common.h"
 #include "qemu_socket.h"
+#include "qemu-objects.h"
+#include "qobject.h"
 #include "qdict.h"
 #include "qstring.h"
 #include "hw/qdev.h"
@@ -1285,28 +1287,135 @@ void net_set_boot_mask(int net_boot_mask)
     }
 }
 
-void do_info_network(Monitor *mon)
+static 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");
+}
+
+static 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"));
+
+    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_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 that may contain any of the following, depending on
+ * the type of the device:
+ *          - "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
+ *          - "host": IP address of a socket
+ *          - "service": port of a socket
+ *          - "family": Internet protocol family (IPv4 or IPv6)
+ *
+ * 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);
 }
 
+
 int do_set_link(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
     VLANState *vlan;
diff --git a/net.h b/net.h
index d12276a..058420e 100644
--- a/net.h
+++ b/net.h
@@ -119,7 +119,8 @@ 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 do_info_network_print(Monitor *mon, const QObject *ret_data);
+void do_info_network(Monitor *mon, QObject **ret_data);
 int do_set_link(Monitor *mon, const QDict *qdict, QObject **ret_data);
 
 /* NIC info */
-- 
1.7.0.4

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

* [Qemu-devel] [PATCH v3 12/12] net: Remove info_str from VLANClientState, not needed anymore
  2010-04-15 14:06 [Qemu-devel] [PATCH v3 00/12] Convert do_info_network() to QObject/QMP Miguel Di Ciurcio Filho
                   ` (10 preceding siblings ...)
  2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 11/12] monitor/net: Convert do_info_network() to QObject/QMP Miguel Di Ciurcio Filho
@ 2010-04-15 14:07 ` Miguel Di Ciurcio Filho
  11 siblings, 0 replies; 20+ messages in thread
From: Miguel Di Ciurcio Filho @ 2010-04-15 14:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, lcapitulino

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

diff --git a/net.c b/net.c
index 46e8873..5dfe24d 100644
--- a/net.c
+++ b/net.c
@@ -168,15 +168,6 @@ 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])
-{
-    snprintf(vc->info_str, sizeof(vc->info_str),
-             "model=%s,macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
-             vc->model,
-             macaddr[0], macaddr[1], macaddr[2],
-             macaddr[3], macaddr[4], macaddr[5]);
-}
-
 void qemu_format_nic_info_dict(VLANClientState *vc, uint8_t macaddr[6])
 {
     vc->info_dict = qdict_new();
diff --git a/net.h b/net.h
index 058420e..243bc3c 100644
--- a/net.h
+++ b/net.h
@@ -65,7 +65,6 @@ struct VLANClientState {
     NetQueue *send_queue;
     char *model;
     char *name;
-    char info_str[256];
     QDict *info_dict;
     unsigned receive_disabled : 1;
 };
@@ -111,7 +110,6 @@ 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);
-- 
1.7.0.4

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

* Re: [Qemu-devel] [PATCH v3 03/12] net: eepro100: replace qemu_format_nic_info_str by qemu_format_nic_info_dict
  2010-04-15 14:06 ` [Qemu-devel] [PATCH v3 03/12] net: eepro100: replace qemu_format_nic_info_str by qemu_format_nic_info_dict Miguel Di Ciurcio Filho
@ 2010-04-15 15:32   ` Richard Henderson
  0 siblings, 0 replies; 20+ messages in thread
From: Richard Henderson @ 2010-04-15 15:32 UTC (permalink / raw)
  To: Miguel Di Ciurcio Filho; +Cc: lcapitulino, qemu-devel, armbru

On 04/15/2010 07:06 AM, Miguel Di Ciurcio Filho wrote:
> Signed-off-by: Miguel Di Ciurcio Filho<miguel.filho@gmail.com>
> ---
>   hw/eepro100.c |   10 ++++++++--
>   1 files changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/hw/eepro100.c b/hw/eepro100.c
> index 7db6fb5..457bda8 100644
> --- a/hw/eepro100.c
> +++ b/hw/eepro100.c
> @@ -1978,8 +1978,14 @@ 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);
> +
> +#ifdef DEBUG_EEPRO100
> +    QString *qstring;
> +    qstring = qdict_to_qstring(s->nic->nc.info_dict);

This isn't C++ or C99 -- declarations have to come at the start
of a block.  You need to add { } here inside the ifdef.


r~

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

* [Qemu-devel] Re: [PATCH v3 01/12] QObject API: add qdict_to_qstring() function
  2010-04-15 14:06 ` [Qemu-devel] [PATCH v3 01/12] QObject API: add qdict_to_qstring() function Miguel Di Ciurcio Filho
@ 2010-04-23 21:04   ` Luiz Capitulino
  0 siblings, 0 replies; 20+ messages in thread
From: Luiz Capitulino @ 2010-04-23 21:04 UTC (permalink / raw)
  To: Miguel Di Ciurcio Filho; +Cc: qemu-devel, armbru

On Thu, 15 Apr 2010 11:06:56 -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 SPACE key2=value2 SPACE key3=value3
> 
> Handy for debugging and other things.

 Something I don't remember if we talked about is: why not use commas
instead of whitespaces?

 I believe it's because there's a trailing whitespace there ;) I don't
think it's difficult to add a qstring_rstrip() though.

> 
> Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
> ---
>  qdict.c |   41 +++++++++++++++++++++++++++++++++++++++++
>  qdict.h |    3 +++
>  2 files changed, 44 insertions(+), 0 deletions(-)
> 
> diff --git a/qdict.c b/qdict.c
> index aae57bf..fddade0 100644
> --- a/qdict.c
> +++ b/qdict.c
> @@ -324,6 +324,47 @@ 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.
> + *
> + * Nested lists and dicts are not supported, yet.
> + *
> + * 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
>   */
> diff --git a/qdict.h b/qdict.h
> index 579dcdd..6731555 100644
> --- a/qdict.h
> +++ b/qdict.h
> @@ -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);

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

* [Qemu-devel] Re: [PATCH v3 02/12] net: add qemu_nic_format_info_dict and VLANClientState->info_dict
  2010-04-15 14:06 ` [Qemu-devel] [PATCH v3 02/12] net: add qemu_nic_format_info_dict and VLANClientState->info_dict Miguel Di Ciurcio Filho
@ 2010-04-23 21:05   ` Luiz Capitulino
  0 siblings, 0 replies; 20+ messages in thread
From: Luiz Capitulino @ 2010-04-23 21:05 UTC (permalink / raw)
  To: Miguel Di Ciurcio Filho; +Cc: qemu-devel, armbru

On Thu, 15 Apr 2010 11:06:57 -0300
Miguel Di Ciurcio Filho <miguel.filho@gmail.com> wrote:

> There is no standard format when formatting VLANClientState.info_str,
> so it is difficult to extract information and transmit it over QMP.
> 
> This patch adds info_dict, a QDict to better handle the information
> of a NIC.
> 
> Patches that convert the devices to use this new function will follow.
> 
> Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
> ---
>  net.c |   16 ++++++++++++++++
>  net.h |    2 ++
>  2 files changed, 18 insertions(+), 0 deletions(-)
> 
> diff --git a/net.c b/net.c
> index d7d76eb..8c02f28 100644
> --- a/net.c
> +++ b/net.c
> @@ -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;
> @@ -173,6 +175,19 @@ 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])
> +{
> +    vc->info_dict = qdict_new();
> +    char mac[18];

 Better style:

char mac[18];

vc->info_dict = qdict_new();

 Also, I'd do:

assert(vc->info_dict == NULL);

 Before assigning it a new dict, just to be sure that it's not called twice for
the same 'vc' (which would leak memory).

> +
> +    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 +316,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 c7a3a1b..d12276a 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);

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

* [Qemu-devel] Re: [PATCH v3 05/12] net: slirp: use info_dict instead of info_str
  2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 05/12] net: slirp: use info_dict instead of info_str Miguel Di Ciurcio Filho
@ 2010-04-23 21:06   ` Luiz Capitulino
  0 siblings, 0 replies; 20+ messages in thread
From: Luiz Capitulino @ 2010-04-23 21:06 UTC (permalink / raw)
  To: Miguel Di Ciurcio Filho; +Cc: qemu-devel, armbru

On Thu, 15 Apr 2010 11:07:00 -0300
Miguel Di Ciurcio Filho <miguel.filho@gmail.com> wrote:

> Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
> ---
>  net/slirp.c |    8 ++++++--
>  1 files changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/net/slirp.c b/net/slirp.c
> index b41c60a..eb9d261 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)
> @@ -240,8 +243,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", qbool_from_int(restricted));

 This is going to be freed by qemu_del_vlan_client(), right?

>  
>      s = DO_UPCAST(SlirpState, nc, nc);
>  

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

* [Qemu-devel] Re: [PATCH v3 06/12] net: tap/tap-win32: use info_dict instead of info_str
  2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 06/12] net: tap/tap-win32: " Miguel Di Ciurcio Filho
@ 2010-04-23 21:08   ` Luiz Capitulino
  0 siblings, 0 replies; 20+ messages in thread
From: Luiz Capitulino @ 2010-04-23 21:08 UTC (permalink / raw)
  To: Miguel Di Ciurcio Filho; +Cc: qemu-devel, armbru

On Thu, 15 Apr 2010 11:07:01 -0300
Miguel Di Ciurcio Filho <miguel.filho@gmail.com> wrote:

> Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
> ---
>  net/tap-win32.c |    9 ++++++---
>  net/tap.c       |   18 +++++++++++++-----
>  2 files changed, 19 insertions(+), 8 deletions(-)
> 
> diff --git a/net/tap-win32.c b/net/tap-win32.c
> index 74348da..a54cd31 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>
> @@ -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_from_str(ifname));

 Isn't it better/needed to also do:

qdict_put(nc->info_dict, "tap", qbool_from_int(1));

 So that you can reliably recognize this is a tap nic? Another option
is to have model=tap, although I'm not sure if it has any undesirable
implication.

 What do you think, Markus?

 Note that same applies for slirp,vde etc..

> +    
> +    s = DO_UPCAST(TAPState, nc, nc);
>  
>      s->handle = handle;
>  
> diff --git a/net/tap.c b/net/tap.c
> index 303d69f..8ba7eed 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 "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();

 Style: in QEMU if you to have to use braces.

> +
> +        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));

 Did you consider using qobject_from_jsonf()?

> +        
>          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] 20+ messages in thread

* [Qemu-devel] Re: [PATCH v3 09/12] net: socket: use info_dict instead of info_str
  2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 09/12] net: socket: " Miguel Di Ciurcio Filho
@ 2010-04-23 21:10   ` Luiz Capitulino
  0 siblings, 0 replies; 20+ messages in thread
From: Luiz Capitulino @ 2010-04-23 21:10 UTC (permalink / raw)
  To: Miguel Di Ciurcio Filho; +Cc: qemu-devel, armbru

On Thu, 15 Apr 2010 11:07:04 -0300
Miguel Di Ciurcio Filho <miguel.filho@gmail.com> wrote:

> Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
> ---
>  net/socket.c |   47 ++++++++++++++++++++++++++++++++---------------
>  1 files changed, 32 insertions(+), 15 deletions(-)
> 
> diff --git a/net/socket.c b/net/socket.c
> index 1c4e153..fa5d24d 100644
> --- a/net/socket.c
> +++ b/net/socket.c
> @@ -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,14 @@ 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));


> +    qdict_put(nc->info_dict, "host",
> +        qstring_from_str(inet_ntoa(saddr.sin_addr)));
> +    qdict_put(nc->info_dict, "service", qint_from_int(ntohs(saddr.sin_port)));
> +    qdict_put(nc->info_dict, "family", qstring_from_str("ipv4"));

 Please, move the block above to a function, it's really duplicated in
the other hunks.

 Also, I think you identify the type of the socket here, eg. listen, connect,
etc.

> +    qdict_put(nc->info_dict, "cloned", qbool_from_int(is_connected));
>  
>      s = DO_UPCAST(NetSocketState, nc, nc);
>  
> @@ -306,8 +313,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 +374,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",
> -                 inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
> +        s1->nc.info_dict = qdict_new();
> +
> +        qdict_put(s1->nc.info_dict, "host",
> +            qstring_from_str(inet_ntoa(saddr.sin_addr)));
> +        qdict_put(s1->nc.info_dict, "service", qint_from_int(ntohs(saddr.sin_port)));
> +        qdict_put(s1->nc.info_dict, "family", qstring_from_str("ipv4"));
>      }
>  }
>  
> @@ -459,9 +470,12 @@ 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",
> -             inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
> +
> +    s->nc.info_dict = qdict_new();
> +    qdict_put(s->nc.info_dict, "host",
> +        qstring_from_str(inet_ntoa(saddr.sin_addr)));
> +    qdict_put(s->nc.info_dict, "service", qint_from_int(ntohs(saddr.sin_port)));
> +    qdict_put(s->nc.info_dict, "family", qstring_from_str("ipv4"));
>      return 0;
>  }
>  
> @@ -487,10 +501,13 @@ static int net_socket_mcast_init(VLANState *vlan,
>          return -1;
>  
>      s->dgram_dst = saddr;
> +    
> +    s->nc.info_dict = qdict_new();
> +    qdict_put(s->nc.info_dict, "host",
> +        qstring_from_str(inet_ntoa(saddr.sin_addr)));
> +    qdict_put(s->nc.info_dict, "service", qint_from_int(ntohs(saddr.sin_port)));
> +    qdict_put(s->nc.info_dict, "family", qstring_from_str("ipv4"));
>  
> -    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;
>  
>  }

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

* [Qemu-devel] Re: [PATCH v3 11/12] monitor/net: Convert do_info_network() to QObject/QMP
  2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 11/12] monitor/net: Convert do_info_network() to QObject/QMP Miguel Di Ciurcio Filho
@ 2010-04-23 21:13   ` Luiz Capitulino
  0 siblings, 0 replies; 20+ messages in thread
From: Luiz Capitulino @ 2010-04-23 21:13 UTC (permalink / raw)
  To: Miguel Di Ciurcio Filho; +Cc: qemu-devel, armbru

On Thu, 15 Apr 2010 11:07:06 -0300
Miguel Di Ciurcio Filho <miguel.filho@gmail.com> wrote:

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

 Actually, it's much more than that.

 For example, the socket (connection type) was:

(qemu) info network
VLAN 0 devices:
  foobar.1: socket: connection from 127.0.0.1:41383
Devices not on any VLAN:
(qemu)

 Now it became:

(qemu) info network
Devices on VLANs:
  foobar.1: vlan=0 family=ipv4 service=41390 host=127.0.0.1  
Devices not on any VLAN:
(qemu)

 So, we're degrading the user Monitor here.

 My suggestion is:

 1. If a device already print "low-level" info (eg. slirp), then it's
    ok to just dump the dict. Actually, this is going to be the default
    behavior for new devices (when we get them)

 2. If a device prints a user-friendly formatted string, then we'll have to
    maintain it (eg. socket). You can do that by checking the device
    model in the iterator and formatting the user-friendly string
    accordingly.

    Another possibility is to have a 'user_str' in VLANClientState, which
    can be formatted at 'info_dict' creation time.

 Also, this change:

> Old output:
>   (qemu) info network
>   VLAN 1 devices:
>     e1000.0: model=e1000,macaddr=52:54:00:12:34:56
>   VLAN 0 devices:
>     tap.0: ifname=tap0,script=/etc/kvm/kvm-ifup,downscript=/etc/qemu-ifdown
>   Devices not on any VLAN:
> 
> New output:
>   (qemu) info network
>   Devices on VLANs:
>     e1000.0: vlan=1 model=e1000 macaddr=52:54:00:12:34:56
>     tap.0: vlan=0 script=/etc/kvm/kvm-ifup downscript=/etc/qemu-ifdown ifname=tap0
>   Devices not on any VLAN:

 doesn't look so good either, as 'info network' won't be that useful if we
get several devices and several vlans. Not sure whether this is a real scenario,
but at least the current code supports it.

 An (inefficient) way to maintain the old format is:

1. Add a key with the number of vlans to the dict (say 'vlans_total')

2. In do_info_network_print() loop using vlans_total in the conditional,
   like this:

   for (i = 0; i < vlans_total; i++) {
        monitor_printf(mon, "VLAN %d devices\n", i);
        qlist_iter(...)
   }

   Also put 'i' either into a global variable or allocate a struct to pass
   it and 'mon' down

3. In vlan_devices_iter() only print devices that correspond to vlan 'i'

> 
> Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
> ---
>  monitor.c |    3 +-
>  net.c     |  127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
>  net.h     |    3 +-
>  3 files changed, 122 insertions(+), 11 deletions(-)
> 
> diff --git a/monitor.c b/monitor.c
> index 4c6275e..34781ba 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -2610,7 +2610,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",
> diff --git a/net.c b/net.c
> index 8c02f28..46e8873 100644
> --- a/net.c
> +++ b/net.c
> @@ -35,6 +35,8 @@
>  #include "sysemu.h"
>  #include "qemu-common.h"
>  #include "qemu_socket.h"
> +#include "qemu-objects.h"
> +#include "qobject.h"
>  #include "qdict.h"
>  #include "qstring.h"
>  #include "hw/qdev.h"
> @@ -1285,28 +1287,135 @@ void net_set_boot_mask(int net_boot_mask)
>      }
>  }
>  
> -void do_info_network(Monitor *mon)
> +static 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");
> +}
> +
> +static 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"));
> +
> +    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_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

 It's do_info_network()

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

 Isn't 'name' the device id?

> + * - "vlan": only present if the device is attached to a VLAN, it is the id
> + * of the VLAN

 Please, fix the indentation, like:

* - "vlan": only present if the device is attached to a VLAN, it is the id
            of the VLAN

> + * - "info": it is a QDict that may contain any of the following, depending on
> + * the type of the device:
> + *          - "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
> + *          - "host": IP address of a socket
> + *          - "service": port of a socket
> + *          - "family": Internet protocol family (IPv4 or IPv6)
> + *
> + * 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" } } ]
> + */

 Please, indent this, like bdrv_info().

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

 This is also used by the other loop, let's declare it as a function
variable to avoid duplication.

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

 Did you check if 'peer' is QMPable?

> +
> +        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 d12276a..058420e 100644
> --- a/net.h
> +++ b/net.h
> @@ -119,7 +119,8 @@ 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 do_info_network_print(Monitor *mon, const QObject *ret_data);
> +void do_info_network(Monitor *mon, QObject **ret_data);
>  int do_set_link(Monitor *mon, const QDict *qdict, QObject **ret_data);
>  
>  /* NIC info */

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

end of thread, other threads:[~2010-04-23 21:13 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-15 14:06 [Qemu-devel] [PATCH v3 00/12] Convert do_info_network() to QObject/QMP Miguel Di Ciurcio Filho
2010-04-15 14:06 ` [Qemu-devel] [PATCH v3 01/12] QObject API: add qdict_to_qstring() function Miguel Di Ciurcio Filho
2010-04-23 21:04   ` [Qemu-devel] " Luiz Capitulino
2010-04-15 14:06 ` [Qemu-devel] [PATCH v3 02/12] net: add qemu_nic_format_info_dict and VLANClientState->info_dict Miguel Di Ciurcio Filho
2010-04-23 21:05   ` [Qemu-devel] " Luiz Capitulino
2010-04-15 14:06 ` [Qemu-devel] [PATCH v3 03/12] net: eepro100: replace qemu_format_nic_info_str by qemu_format_nic_info_dict Miguel Di Ciurcio Filho
2010-04-15 15:32   ` Richard Henderson
2010-04-15 14:06 ` [Qemu-devel] [PATCH v3 04/12] net: various devices: " Miguel Di Ciurcio Filho
2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 05/12] net: slirp: use info_dict instead of info_str Miguel Di Ciurcio Filho
2010-04-23 21:06   ` [Qemu-devel] " Luiz Capitulino
2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 06/12] net: tap/tap-win32: " Miguel Di Ciurcio Filho
2010-04-23 21:08   ` [Qemu-devel] " Luiz Capitulino
2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 07/12] net: vde: " Miguel Di Ciurcio Filho
2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 08/12] net: dump: " Miguel Di Ciurcio Filho
2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 09/12] net: socket: " Miguel Di Ciurcio Filho
2010-04-23 21:10   ` [Qemu-devel] " Luiz Capitulino
2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 10/12] net: xen: " Miguel Di Ciurcio Filho
2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 11/12] monitor/net: Convert do_info_network() to QObject/QMP Miguel Di Ciurcio Filho
2010-04-23 21:13   ` [Qemu-devel] " Luiz Capitulino
2010-04-15 14:07 ` [Qemu-devel] [PATCH v3 12/12] net: Remove info_str from VLANClientState, not needed anymore Miguel Di Ciurcio Filho

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