Skip to contentSkip to conversation

Introduce 'info netdevices' with QMP support

PATCH In review Miguel Di Ciurcio Filho 2 participants 15 messages May 18, 2010 – May 27, 2010

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

v4 cover Introduce 'info netdevices' with QMP support

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

#1 lore raw

PATCH v4 1/10 QObject API: introduce qdict_to_qstring() function

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

key1=value1 SEP key2=value2 SEP key3=value3

Handy for debugging and formating the Monitor output.

---
 qdict.c |   55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 qdict.h |    9 +++++++++
 2 files changed, 64 insertions(+), 0 deletions(-)
qdict.c +55 -0
index 175bc17..19c053f 100644
@@ -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'
  *
qdict.h +9 -0
index 5e5902c..8a54733 100644
@@ -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);
Signature · 1 line
1.7.1
#2 lore raw

[Qemu-devel] Re: [PATCH v4 01/10] QObject API: introduce qdict_to_qstring() function

Quoted 8 lines · On Tue, 18 May 2010 14:07:40 -0300 Miguel Di Ciurcio Filho…

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.

It's very better now, some comments below.

Quoted 45 lines
---
 qdict.c |   55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 qdict.h |    9 +++++++++
 2 files changed, 64 insertions(+), 0 deletions(-)
qdict.c +32 -0
index 175bc17..19c053f 100644
@@ -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.
+ *

qdict.c const char *qdict_get_str(const QDict *qdict, const char *key) · line 311

Quoted 10 lines
qdict.c +10 -0
+ * 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.

Quoted 29 lines
qdict.c +13 -0
+    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'
  *
qdict.h +1 -0
index 5e5902c..8a54733 100644
@@ -15,6 +15,7 @@
 
 #include "qobject.h"
 #include "qlist.h"
+#include "qstring.h"
 #include "qemu-queue.h"
 #include <stdint.h>
 

qdict.h typedef struct QDict { · line 41

Quoted 9 lines
qdict.h +6 -0
@@ -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'.

Quoted 12 lines
qdict.h +2 -0
+
 /* 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);
#3 lore raw

PATCH v4 2/10 net: introduce qemu_nic_format_info_dict and VLANClientState->info_dict

In reply to Miguel Di Ciurcio Filho

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

This patch adds info_dict, a QDict to better handle the information of a NIC.

---
 net.c |   17 +++++++++++++++++
 net.h |    2 ++
 2 files changed, 19 insertions(+), 0 deletions(-)
net.c +17 -0
index efa8b3d..9e8a8ab 100644
@@ -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);
 }
 
net.h +2 -0
index b83f615..4566f7d 100644
@@ -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);
Signature · 1 line
1.7.1
#4 lore raw

PATCH v4 3/10 net: various devices: add qemu_format_nic_info_dict

In reply to Miguel Di Ciurcio Filho

These are simple one line additions of qemu_format_nic_info_dict.

---
 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(-)
hw/dp8393x.c +1 -0
index e65e4d1..31fb1cb 100644
@@ -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);
 
hw/e1000.c +1 -0
index 34cc451..faee35c 100644
@@ -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;
 }
 
hw/eepro100.c +2 -0
index a74d834..bd210ff 100644
@@ -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);
hw/lan9118.c +2 -0
index 16d3330..c392666 100644
@@ -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];
hw/mcf_fec.c +1 -0
index 4e7fbed..1d3e280 100644
@@ -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);
 }
hw/mipsnet.c +1 -0
index a066f63..9134fd0 100644
@@ -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);
hw/ne2000-isa.c +1 -0
index 03a5a1f..3cc2503 100644
@@ -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;
 }
hw/ne2000.c +1 -0
index 78fe14f..fb92c8b 100644
@@ -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;
hw/pcnet.c +1 -0
index 5e63eb5..5356ab4 100644
@@ -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;
 }
 
hw/rtl8139.c +1 -0
index 72e2242..a5cd1fb 100644
@@ -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;
hw/smc91c111.c +1 -0
index f7d58e1..d62a5fd 100644
@@ -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;
 }
hw/stellaris_enet.c +1 -0
index d1d755e..fec9470 100644
@@ -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,
hw/usb-net.c +1 -0
index a43bd17..9dacaaa 100644
@@ -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,
hw/virtio-net.c +2 -0
index d602c56..e70c05c 100644
@@ -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;
hw/xilinx_ethlite.c +1 -0
index 37e33ec..ea4fb96 100644
@@ -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;
 }
 
Signature · 1 line
1.7.1
#5 lore raw

PATCH v4 4/10 net: xen: introduce info_dict

In reply to Miguel Di Ciurcio Filho
---
 hw/xen_nic.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
hw/xen_nic.c +5 -0
index 08055b8..1820059 100644
@@ -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);
Signature · 1 line
1.7.1
#6 lore raw

PATCH v4 5/10 net: tap/tap-win32: introduce info_dict

In reply to Miguel Di Ciurcio Filho
---
 net/tap-win32.c |    9 ++++++++-
 net/tap.c       |   18 +++++++++++++++++-
 2 files changed, 25 insertions(+), 2 deletions(-)
net/tap-win32.c +8 -1
index 74348da..54c6725 100644
@@ -32,6 +32,8 @@
 #include "net.h"
 #include "sysemu.h"
 #include "qemu-error.h"
+#include "qdict.h"
+#include "qstring.h"
 #include <stdio.h>
 #include <windows.h>
 #include <winioctl.h>
@@ -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;
 
net/tap.c +17 -1
index 0147dab..d71f312 100644
@@ -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);
Signature · 1 line
1.7.1
#7 lore raw

[Qemu-devel] Re: [PATCH v4 05/10] net: tap/tap-win32: introduce info_dict

Quoted 20 lines · On Tue, 18 May 2010 14:07:44 -0300 Miguel Di Ciurcio Filho…
---
 net/tap-win32.c |    9 ++++++++-
 net/tap.c       |   18 +++++++++++++++++-
 2 files changed, 25 insertions(+), 2 deletions(-)
net/tap-win32.c +2 -0
index 74348da..54c6725 100644
@@ -32,6 +32,8 @@
 #include "net.h"
 #include "sysemu.h"
 #include "qemu-error.h"
+#include "qdict.h"
+#include "qstring.h"
 #include <stdio.h>
 #include <windows.h>
 #include <winioctl.h>

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

Quoted 5 lines
net/tap-win32.c +1 -1
@@ -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?

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

Quoted 5 lines
net/tap-win32.c +5 -0
+
+    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.

Quoted 27 lines
net/tap-win32.c +0 -0
     s->handle = handle;
 
net/tap.c +8 -0
index 0147dab..d71f312 100644
@@ -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 {

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

Quoted 10 lines
net/tap.c +2 -1
         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.

Quoted 12 lines
net/tap.c +7 -0
                  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);
#8 lore raw

PATCH v4 6/10 net: vde: introduce info_dict

In reply to Miguel Di Ciurcio Filho
---
 net/vde.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
net/vde.c +10 -1
index 0b46fa6..6a3d0ba 100644
@@ -31,6 +31,9 @@
 #include "qemu-char.h"
 #include "qemu-common.h"
 #include "qemu-option.h"
+#include "qdict.h"
+#include "qstring.h"
+#include "qint.h"
 #include "sysemu.h"
 
 typedef struct VDEState {
@@ -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);
 
Signature · 1 line
1.7.1
#9 lore raw

[Qemu-devel] Re: [PATCH v4 06/10] net: vde: introduce info_dict

Quoted 20 lines · On Tue, 18 May 2010 14:07:45 -0300 Miguel Di Ciurcio Filho…
---
 net/vde.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
net/vde.c +3 -0
index 0b46fa6..6a3d0ba 100644
@@ -31,6 +31,9 @@
 #include "qemu-char.h"
 #include "qemu-common.h"
 #include "qemu-option.h"
+#include "qdict.h"
+#include "qstring.h"
+#include "qint.h"
 #include "sysemu.h"
 
 typedef struct VDEState {

net/vde.c static int net_vde_init(VLANState *vlan, const char *model, · line 106

Quoted 5 lines
net/vde.c +1 -1
@@ -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.

Quoted 9 lines
net/vde.c +6 -0
+
+
+    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);
 
#10 lore raw

PATCH v4 7/10 net: dump: introduce info_dict

In reply to Miguel Di Ciurcio Filho
---
 net/dump.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
net/dump.c +9 -1
index 6db7ecf..32514ad 100644
@@ -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);
 
Signature · 1 line
1.7.1
#11 lore raw

PATCH v4 8/10 net: slirp: introduce info_dict

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

PATCH v4 9/10 net: socket: introduce info_dict

In reply to Miguel Di Ciurcio Filho
---
 net/socket.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
net/socket.c +22 -0
index 1c4e153..5be1b54 100644
@@ -28,6 +28,7 @@
 #include "net.h"
 #include "qemu-char.h"
 #include "qemu-common.h"
+#include "qjson.h"
 #include "qemu-error.h"
 #include "qemu-option.h"
 #include "qemu_socket.h"
@@ -49,6 +50,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;
 
 }
Signature · 1 line
1.7.1
#13 lore raw

PATCH v4 10/10 monitor/net: introduce 'info netdevices' with QMP support

In reply to Miguel Di Ciurcio Filho

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

]
}

---
 monitor.c |    8 ++++++
 net.c     |   79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 net.h     |    2 +
 3 files changed, 89 insertions(+), 0 deletions(-)
monitor.c +8 -0
index 4c95d7b..0d1a0c1 100644
@@ -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     = "",
net.c +79 -0

91 lines not on this page · raw message

net.h +2 -0
index 4566f7d..9b3700c 100644
@@ -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 */
Signature · 1 line
1.7.1
#14 lore raw
In reply to Miguel Di Ciurcio Filho
Quoted 8 lines · On Tue, 18 May 2010 14:07:39 -0300 Miguel Di Ciurcio Filho…

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

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

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.