Convert do_info_network() to QObject/QMP
Subsystems (3)
v3 cover Convert do_info_network() to QObject/QMP
The VLANClientState structure has the member info_str, a simple string that is filled with information about NIC devices and used on monitor calls.
There is no coherent formatting of this string by all the NIC devices, making it difficult to parse and represent this information over QMP.
Patch 01 adds a new function qdict_to_qstring().
Patch 02 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
PATCH v3 1/12 QObject API: add qdict_to_qstring() function
This is a helper function that converts a QDict to a QString, using the format:
key1=value1 SPACE key2=value2 SPACE key3=value3
Handy for debugging and other things.
--- qdict.c | 41 +++++++++++++++++++++++++++++++++++++++++ qdict.h | 3 +++ 2 files changed, 44 insertions(+), 0 deletions(-)
qdict.c +41 -0
@@ -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 */
qdict.h +3 -0
@@ -3,6 +3,7 @@#include "qobject.h" #include "qlist.h" +#include "qstring.h" #include "qemu-queue.h" #include <stdint.h>
@@ -43,6 +44,8 @@ int qdict_get_bool(const QDict *qdict, const char *key);QList *qdict_get_qlist (const QDict *qdict,const char *key);QDict *qdict_get_qdict (const QDict *qdict,const char *key);const char *qdict_get_str (const QDict *qdict,const char *key); +void qdict_to_qstring_iter (const char *key,QObject *obj,void *opaque); +QString *qdict_to_qstring (const QDict *qdict);int64_t qdict_get_try_int (const QDict *qdict,const char *key,int64_t err_value);const char *qdict_get_try_str (const QDict *qdict,const char *key);
Signature · 1 line
1.7.0.4
[Qemu-devel] Re: [PATCH v3 01/12] QObject API: add qdict_to_qstring() function
Quoted 5 lines · On Thu, 15 Apr 2010 11:06:56 -0300 Miguel Di Ciurcio Filho…
This is a helper function that converts a QDict to a QString, using the format:
key1=value1 SPACE key2=value2 SPACE key3=value3
Handy for debugging and other things.
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.
Quoted 80 lines
Signed-off-by Miguel Di Ciurcio Filho <[email protected]>--- qdict.c | 41 +++++++++++++++++++++++++++++++++++++++++ qdict.h | 3 +++ 2 files changed, 44 insertions(+), 0 deletions(-)qdict.c +41
-0@@ -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 */ qdict.h +3
-0@@ -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);
PATCH v3 2/12 net: add qemu_nic_format_info_dict and VLANClientState->info_dict
In reply to Miguel Di Ciurcio FilhoThere 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.
--- net.c | 16 ++++++++++++++++ net.h | 2 ++ 2 files changed, 18 insertions(+), 0 deletions(-)
net.c +16 -0
@@ -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); }
net.h +2 -0
@@ -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.0.4
[Qemu-devel] Re: [PATCH v3 02/12] net: add qemu_nic_format_info_dict and VLANClientState->info_dict
Quoted 28 lines · On Thu, 15 Apr 2010 11:06:57 -0300 Miguel Di Ciurcio Filho…
There is no standard format when formatting VLANClientState.info_str, so it is difficult to extract information and transmit it over QMP.
This patch adds
info_dict, a QDict to better handle the information of a NIC.Patches that convert the devices to use this new function will follow.
Signed-off-by Miguel Di Ciurcio Filho <[email protected]>--- net.c | 16 ++++++++++++++++ net.h | 2 ++ 2 files changed, 18 insertions(+), 0 deletions(-)net.c +2
-0@@ -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;
net.c void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]) · line 181
Quoted 7 lines
net.c +4
-0@@ -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).
Quoted 40 lines
net.c +10
-0+ +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); }net.h +2
-0@@ -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);
PATCH v3 3/12 net: eepro100: replace qemu_format_nic_info_str by qemu_format_nic_info_dict
In reply to Miguel Di Ciurcio Filho--- hw/eepro100.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-)
hw/eepro100.c +8 -2
@@ -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);
Signature · 1 line
1.7.0.4
Re: [Qemu-devel] [PATCH v3 03/12] net: eepro100: replace qemu_format_nic_info_str by qemu_format_nic_info_dict
Quoted 10 lines · Miguel Di Ciurcio Filho
Signed-off-by Miguel Di Ciurcio Filho<[email protected]>--- hw/eepro100.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-)hw/eepro100.c +0
-0
hw/eepro100.c static int nic_init(PCIDevice *pci_dev, uint32_t device) · line 1985
Quoted 10 lines
hw/eepro100.c +5
-2@@ -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~
PATCH v3 4/12 net: various devices: replace qemu_format_nic_info_str by qemu_format_nic_info_dict
In reply to Miguel Di Ciurcio FilhoThese are simple one line changes to replace qemu_format_nic_info_str.
--- 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(-)
hw/dp8393x.c +1 -1
@@ -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);
hw/e1000.c +1 -1
@@ -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 ; }
hw/lan9118.c +2 -2
@@ -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];
hw/mcf_fec.c +1 -1
@@ -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); }
hw/mipsnet.c +1 -1
@@ -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);
hw/ne2000-isa.c +1 -1
@@ -84,7 +84,7 @@ static int isa_ne2000_initfn(ISADevice *dev) s->nic =qemu_new_nic (&net_ne2000_isa_info, &s->c, dev->qdev.info->name, dev->qdev.id, s); -qemu_format_nic_info_str (&s->nic->nc, s->c.macaddr.a); +qemu_format_nic_info_dict (&s->nic->nc, s->c.macaddr.a);return 0 ; }
hw/ne2000.c +1 -1
@@ -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 ;
hw/pcnet.c +1 -1
@@ -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 ; }
hw/rtl8139.c +1 -1
@@ -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 ;
hw/smc91c111.c +1 -1
@@ -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 ; }
hw/stellaris_enet.c +1 -1
@@ -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,
hw/usb-net.c +1 -1
@@ -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,
hw/virtio-net.c +2 -2
@@ -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 ;
hw/xilinx_ethlite.c +1 -1
@@ -230,7 +230,7 @@ static int xilinx_ethlite_init(SysBusDevice *dev)qemu_macaddr_default_if_unset (&s->conf.macaddr); s->nic =qemu_new_nic (&net_xilinx_ethlite_info, &s->conf, dev->qdev.info->name, dev->qdev.id, s); -qemu_format_nic_info_str (&s->nic->nc, s->conf.macaddr.a); +qemu_format_nic_info_dict (&s->nic->nc, s->conf.macaddr.a);return 0 ; }
Signature · 1 line
1.7.0.4
PATCH v3 5/12 net: slirp: use info_dict instead of info_str
In reply to Miguel Di Ciurcio Filho--- net/slirp.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)
net/slirp.c +6 -2
@@ -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);
Signature · 1 line
1.7.0.4
[Qemu-devel] Re: [PATCH v3 05/12] net: slirp: use info_dict instead of info_str
Quoted 20 lines · On Thu, 15 Apr 2010 11:07:00 -0300 Miguel Di Ciurcio Filho…
Signed-off-by Miguel Di Ciurcio Filho <[email protected]>--- net/slirp.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)net/slirp.c +3
-0@@ -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)
net/slirp.c static int net_slirp_init(VLANState *vlan, const char *model, · line 248
Quoted 8 lines
net/slirp.c +3
-2@@ -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?
Quoted 3 lines
net/slirp.c +0
-0s =DO_UPCAST (SlirpState, nc, nc);
PATCH v3 6/12 net: tap/tap-win32: use info_dict instead of info_str
In reply to Miguel Di Ciurcio Filho--- net/tap-win32.c | 9 ++++++--- net/tap.c | 18 +++++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-)
net/tap-win32.c +6 -3
@@ -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;
net/tap.c +13 -5
@@ -39,6 +39,9 @@#include "qemu-char.h" #include "qemu-common.h" #include "qemu-error.h" +#include "qdict.h" +#include "qint.h" +#include "qstring.h" #include "net/tap-linux.h"
@@ -447,18 +450,23 @@ int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan }if (qemu_opt_get (opts,"fd" )) { -snprintf (s->nc.info_str,sizeof (s->nc.info_str),"fd=%d" , fd); +if (s->nc.info_dict ==NULL ) + s->nc.info_dict =qdict_new (); + +qdict_put (s->nc.info_dict,"fd" ,qint_from_int (fd)); }else {const char *ifname, *script, *downscript; +if (s->nc.info_dict ==NULL ) + s->nc.info_dict =qdict_new (); ifname =qemu_opt_get (opts,"ifname" ); script =qemu_opt_get (opts,"script" ); downscript =qemu_opt_get (opts,"downscript" ); -snprintf (s->nc.info_str,sizeof (s->nc.info_str), -"ifname=%s,script=%s,downscript=%s" , - ifname, script, downscript); - +qdict_put (s->nc.info_dict,"ifname" ,qstring_from_str (ifname)); +qdict_put (s->nc.info_dict,"script" ,qstring_from_str (script)); +qdict_put (s->nc.info_dict,"downscript" ,qstring_from_str (downscript)); +if (strcmp (downscript,"no" ) !=0 ) {snprintf (s->down_script,sizeof (s->down_script),"%s" , downscript);snprintf (s->down_script_arg,sizeof (s->down_script_arg),"%s" , ifname);
Signature · 1 line
1.7.0.4
[Qemu-devel] Re: [PATCH v3 06/12] net: tap/tap-win32: use info_dict instead of info_str
Quoted 20 lines · On Thu, 15 Apr 2010 11:07:01 -0300 Miguel Di Ciurcio Filho…
Signed-off-by Miguel Di Ciurcio Filho <[email protected]>--- net/tap-win32.c | 9 ++++++--- net/tap.c | 18 +++++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-)net/tap-win32.c +2
-0@@ -32,6 +32,8 @@#include "net.h" #include "sysemu.h" #include "qemu-error.h" +#include "qdict.h" +#include "qstring.h" #include <stdio.h> #include <windows.h> #include <winioctl.h>
net/tap-win32.c static int tap_win32_init(VLANState *vlan, const char *model, · line 695
Quoted 9 lines
net/tap-win32.c +2
-3@@ -688,10 +690,11 @@ static int tap_win32_init(VLANState *vlan, const char *model, nc =qemu_new_net_client (&net_tap_win32_info, vlan,NULL , model, name); - s =DO_UPCAST (TAPState, nc, nc); + nc->info_dict =qdict_new (); -snprintf (s->nc.info_str,sizeof (s->nc.info_str), -"tap: ifname=%s" , ifname); +qdict_put (nc->info_dict,"ifname" ,qstring_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..
Quoted 20 lines
net/tap-win32.c +2
-0+ + s =DO_UPCAST (TAPState, nc, nc); s->handle = handle;net/tap.c +3
-0@@ -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"
net/tap.c int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan · line 454
Quoted 6 lines
net/tap.c +2
-1@@ -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.
Quoted 8 lines
net/tap.c +4
-0+ +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" );
net/tap.c int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan · line 468
Quoted 10 lines
net/tap.c +3
-4script =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()?
Quoted 4 lines
net/tap.c +1
-0+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);
PATCH v3 7/12 net: vde: use info_dict instead of info_str
In reply to Miguel Di Ciurcio Filho--- net/vde.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
net/vde.c +7 -2
@@ -31,6 +31,9 @@#include "qemu-char.h" #include "qemu-common.h" #include "qemu-option.h" +#include "qdict.h" +#include "qstring.h" +#include "qint.h" #include "sysemu.h" typedef struct VDEState {
@@ -99,8 +102,10 @@ static int net_vde_init(VLANState *vlan, const char *model, nc =qemu_new_net_client (&net_vde_info, vlan,NULL , model, name); -snprintf (nc->info_str,sizeof (nc->info_str),"sock=%s,fd=%d" , - sock,vde_datafd (vde)); + nc->info_dict =qdict_new (); + +qdict_put (nc->info_dict,"sock" ,qstring_from_str (sock)); +qdict_put (nc->info_dict,"fd" ,qint_from_int (vde_datafd (vde))); s =DO_UPCAST (VDEState, nc, nc);
Signature · 1 line
1.7.0.4
PATCH v3 8/12 net: dump: use info_dict instead of info_str
In reply to Miguel Di Ciurcio Filho--- net/dump.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)
net/dump.c +6 -2
@@ -27,6 +27,9 @@#include "sysemu.h" #include "qemu-error.h" #include "qemu-log.h" +#include "qdict.h" +#include "qstring.h" +#include "qint.h" typedef struct DumpState { VLANClientState nc;
@@ -128,8 +131,9 @@ static int net_dump_init(VLANState *vlan, const char *device, nc =qemu_new_net_client (&net_dump_info, vlan,NULL , device, name); -snprintf (nc->info_str,sizeof (nc->info_str), -"dump to %s (len=%d)" , filename, len); + nc->info_dict =qdict_new (); +qdict_put (nc->info_dict,"filename" ,qstring_from_str (filename)); +qdict_put (nc->info_dict,"len" ,qint_from_int (len)); s =DO_UPCAST (DumpState, nc, nc);
Signature · 1 line
1.7.0.4
PATCH v3 9/12 net: socket: use info_dict instead of info_str
In reply to Miguel Di Ciurcio Filho--- net/socket.c | 47 ++++++++++++++++++++++++++++++++--------------- 1 files changed, 32 insertions(+), 15 deletions(-)
net/socket.c +32 -15
@@ -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 ; }
Signature · 1 line
1.7.0.4
[Qemu-devel] Re: [PATCH v3 09/12] net: socket: use info_dict instead of info_str
Quoted 28 lines · On Thu, 15 Apr 2010 11:07:04 -0300 Miguel Di Ciurcio Filho…
Signed-off-by Miguel Di Ciurcio Filho <[email protected]>--- net/socket.c | 47 ++++++++++++++++++++++++++++++++--------------- 1 files changed, 32 insertions(+), 15 deletions(-)net/socket.c +4
-4@@ -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" : "",
net/socket.c static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, · line 281
Quoted 10 lines
net/socket.c +7
-1- inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); + + nc->info_dict =qdict_new (); +qdict_put (nc->info_dict,"fd" ,qint_from_int (fd)); +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.
Quoted 64 lines
net/socket.c +1
-0+qdict_put (nc->info_dict,"cloned" ,qbool_from_int (is_connected));s = DO_UPCAST(NetSocketState, nc, nc);net/socket.c +20
-10@@ -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 ; }
PATCH v3 10/12 net: xen: use info_dict instead of info_str
In reply to Miguel Di Ciurcio Filho--- hw/xen_nic.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
hw/xen_nic.c +4 -2
@@ -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 );
Signature · 1 line
1.7.0.4
PATCH v3 11/12 monitor/net: Convert do_info_network() to QObject/QMP
In reply to Miguel Di Ciurcio FilhoEach 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:
--- monitor.c | 3 +- net.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- net.h | 3 +- 3 files changed, 122 insertions(+), 11 deletions(-)
monitor.c +2 -1
@@ -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",
net.c +118 -9
152 lines not on this page · raw message
net.h +2 -1
@@ -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 */
Signature · 1 line
1.7.0.4
[Qemu-devel] Re: [PATCH v3 11/12] monitor/net: Convert do_info_network() to QObject/QMP
Quoted 4 lines · On Thu, 15 Apr 2010 11:07:06 -0300 Miguel Di Ciurcio Filho…
Each device is represented by a QDict. The returned QObject is a QList of all devices.
This commit slightly changes the monitor output when 'info network' is used.
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:
Quoted 8 lines
Old output:
(qemu) info network
VLAN 1 devices:e1000.0: model=e1000,macaddr=52:54:00:12:34:56VLAN 0 devices:
tap.0: ifname=tap0,script=/etc/kvm/kvm-ifup,downscript=/etc/qemu-ifdown
Devices not on any VLAN:
Quoted 6 lines
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'
Quoted 86 lines
Signed-off-by Miguel Di Ciurcio Filho <[email protected]>--- monitor.c | 3 +- net.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- net.h | 3 +- 3 files changed, 122 insertions(+), 11 deletions(-)monitor.c +2
-1@@ -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",net.c +48
-1@@ -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" ); +
net.c void net_set_boot_mask(int net_boot_mask) · line 1345
Quoted 10 lines
net.c +10
-0+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()
net.c void net_set_boot_mask(int net_boot_mask) · line 1352
Quoted 7 lines
net.c +7
-0+* +* 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?
net.c void net_set_boot_mask(int net_boot_mask) · line 1354
Quoted 2 lines
net.c +2
-0+* - "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
Quoted 11 lines
net.c +11
-0+* - "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)
net.c void net_set_boot_mask(int net_boot_mask) · line 1375
Quoted 10 lines
net.c +10
-0+* +* 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().
net.c void net_set_boot_mask(int net_boot_mask) · line 1385
Quoted 11 lines
net.c +5
-1+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.
Quoted 22 lines
net.c +11
-6QTAILQ_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); - }
net.c void net_set_boot_mask(int net_boot_mask) · line 1410
Quoted 10 lines
net.c +9
-1-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?
Quoted 25 lines
net.c +5
-0+ +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;net.h +2
-1@@ -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 */
PATCH v3 12/12 net: Remove info_str from VLANClientState, not needed anymore
In reply to Miguel Di Ciurcio Filho--- net.c | 9 --------- net.h | 2 -- 2 files changed, 0 insertions(+), 11 deletions(-)
net.c +0 -9
@@ -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 ();
net.h +0 -2
@@ -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);
Signature · 1 line
1.7.0.4