Fix qemu_announce_self() properly
Mark McLoughlin
Appliedcover Fix qemu_announce_self() properly
Hi,
The recent "fix" to qemu_announce_self() will segfault if you use
-netdev. The real root cause of the regression was the removal of the assignment to NICInfo::vc that used to live in qdev_get_vlan_client().
Now that NICs are qdev-ified, we should just iterate over the
qdev tree to find NICs and send out the announce packet from each.
This series does just that. I've only lightly tested it, more
testing and comments welcome.
Pushed to the fix-announce-self-rfc branch at:
git://repo.or.cz/qemu/markmc.git
Cheers,
Mark.
PATCH 1/7 net: remove NICInfo::vc
Since 1cc33683, this field is not set for most devices, so just remove it and its remaining few uses.
--- hw/dp8393x.c | 10 +++++----- hw/etraxfs_eth.c | 10 +++++----- hw/mcf_fec.c | 10 +++++----- hw/mipsnet.c | 10 +++++----- hw/usb-net.c | 14 +++++++------- net.h | 1 - 6 files changed, 27 insertions(+), 28 deletions(-)
hw/dp8393x.c +5 -5
@@ -889,11 +889,11 @@ void dp83932_init(NICInfo *nd, target_phys_addr_t base, int it_shift, s->watchdog =qemu_new_timer (vm_clock, dp8393x_watchdog, s); s->regs[SONIC_SR ] =0x0004 ;/* only revision recognized by Linux */ - s->vc = nd->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , - nd->vlan, nd->netdev, - nd->model, nd->name, - nic_can_receive, nic_receive,NULL ,NULL , - nic_cleanup, s); + s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , + nd->vlan, nd->netdev, + nd->model, nd->name, + nic_can_receive, nic_receive,NULL ,NULL , + nic_cleanup, s);qemu_format_nic_info_str (s->vc, nd->macaddr);qemu_register_reset (nic_reset, s);
hw/etraxfs_eth.c +5 -5
@@ -590,11 +590,11 @@ void *etraxfs_eth_init(NICInfo *nd, target_phys_addr_t base, int phyaddr) eth->ethregs =cpu_register_io_memory (eth_read, eth_write, eth);cpu_register_physical_memory (base,0x5c , eth->ethregs); - eth->vc = nd->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , - nd->vlan, nd->netdev, - nd->model, nd->name, - eth_can_receive, eth_receive, -NULL ,NULL , eth_cleanup, eth); + eth->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , + nd->vlan, nd->netdev, + nd->model, nd->name, + eth_can_receive, eth_receive, +NULL ,NULL , eth_cleanup, eth); eth->vc->opaque = eth; eth->vc->link_status_changed = eth_set_link;
hw/mcf_fec.c +5 -5
@@ -462,11 +462,11 @@ void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq) mcf_fec_writefn, s);cpu_register_physical_memory (base,0x400 , s->mmio_index); - s->vc = nd->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , - nd->vlan, nd->netdev, - nd->model, nd->name, - mcf_fec_can_receive, mcf_fec_receive, -NULL ,NULL , mcf_fec_cleanup, s); + s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , + nd->vlan, nd->netdev, + nd->model, nd->name, + mcf_fec_can_receive, mcf_fec_receive, +NULL ,NULL , mcf_fec_cleanup, s);memcpy (s->macaddr, nd->macaddr,6 );qemu_format_nic_info_str (s->vc, s->macaddr); }
hw/mipsnet.c +5 -5
@@ -263,11 +263,11 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd) s->io_base = base; s->irq = irq;if (nd) { - s->vc = nd->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , - nd->vlan, nd->netdev, - nd->model, nd->name, - mipsnet_can_receive, mipsnet_receive, -NULL ,NULL , mipsnet_cleanup, s); + s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , + nd->vlan, nd->netdev, + nd->model, nd->name, + mipsnet_can_receive, mipsnet_receive, +NULL ,NULL , mipsnet_cleanup, s); }else { s->vc =NULL ; }
hw/usb-net.c +7 -7
@@ -1460,13 +1460,13 @@ USBDevice *usb_net_init(NICInfo *nd)memcpy (s->mac, nd->macaddr,6 ); - s->vc = nd->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , - nd->vlan, nd->netdev, - nd->model, nd->name, - usbnet_can_receive, - usbnet_receive, -NULL ,NULL , - usbnet_cleanup, s); + s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , + nd->vlan, nd->netdev, + nd->model, nd->name, + usbnet_can_receive, + usbnet_receive, +NULL ,NULL , + usbnet_cleanup, s);qemu_format_nic_info_str (s->vc, s->mac);
net.h +0 -1
@@ -124,7 +124,6 @@ struct NICInfo {char *devaddr;VLANState *vlan;VLANClientState *netdev; -VLANClientState *vc;void *private;int used;int bootable;
Signature · 1 line
1.6.2.5
PATCH 2/7 qdev: add "net-client" property
In reply to Mark McLoughlinRather than having each NIC create it's own client, let's create the client early and pass it down to the NIC.
One advantage is that we can add parameters which only the client knows about, without having the NIC know anything about it - e.g. NICs shouldn't know about netdev vs. vlan.
Another advantage is that we can easily get the client associated with a qdev.
--- hw/qdev-properties.c | 25 +++++++++++++++++++++++++ hw/qdev.h | 5 +++++ net.h | 8 +++++--- 3 files changed, 35 insertions(+), 3 deletions(-)
hw/qdev-properties.c +25 -0
@@ -279,6 +279,26 @@ PropertyInfo qdev_prop_chr = { .print = print_chr, }; +/* --- network client object --- */ + +static int print_net_client (DeviceState *dev,Property *prop,char *dest,size_t len) +{ +VLANClientState **ptr =qdev_get_prop_ptr (dev, prop); + +if (*ptr && (*ptr)->name) { +return snprintf (dest, len,"%s" , (*ptr)->name); + }else { +return snprintf (dest, len,"<null>" ); + } +} + +PropertyInfo qdev_prop_net_client = { + .name ="net-client" , + .type =PROP_TYPE_NET_CLIENT , + .size =sizeof (VLANClientState *), + .print = print_net_client, +}; +/* --- netdev device --- */ static int parse_netdev (DeviceState *dev,Property *prop,const char *str)
@@ -558,6 +578,11 @@ void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *valuqdev_prop_set (dev, name, &value,PROP_TYPE_CHR ); } +void qdev_prop_set_net_client (DeviceState *dev,const char *name,VLANClientState *value) +{ +qdev_prop_set (dev, name, &value,PROP_TYPE_NET_CLIENT ); +} +void qdev_prop_set_netdev (DeviceState *dev,const char *name,VLANClientState *value) {qdev_prop_set (dev, name, &value,PROP_TYPE_NETDEV );
hw/qdev.h +5 -0
@@ -79,6 +79,7 @@ enum PropertyType {PROP_TYPE_DRIVE ,PROP_TYPE_CHR ,PROP_TYPE_STRING , +PROP_TYPE_NET_CLIENT ,PROP_TYPE_NETDEV ,PROP_TYPE_VLAN , PROP_TYPE_PTR,
@@ -194,6 +195,7 @@ extern PropertyInfo qdev_prop_chr;extern PropertyInfo qdev_prop_ptr;extern PropertyInfo qdev_prop_macaddr;extern PropertyInfo qdev_prop_drive; +extern PropertyInfo qdev_prop_net_client;extern PropertyInfo qdev_prop_netdev;extern PropertyInfo qdev_prop_vlan;extern PropertyInfo qdev_prop_pci_devfn;
@@ -235,6 +237,8 @@ extern PropertyInfo qdev_prop_pci_devfn; DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*) #define DEFINE_PROP_STRING(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*) +#define DEFINE_PROP_NET_CLIENT(_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_net_client, VLANClientState *) #define DEFINE_PROP_NETDEV(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, VLANClientState*) #define DEFINE_PROP_VLAN(_n, _s, _f) \
@@ -258,6 +262,7 @@ void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);void qdev_prop_set_int32 (DeviceState *dev,const char *name,int32_t value);void qdev_prop_set_uint64 (DeviceState *dev,const char *name,uint64_t value);void qdev_prop_set_chr (DeviceState *dev,const char *name,CharDriverState *value); +void qdev_prop_set_net_client (DeviceState *dev,const char *name,VLANClientState *value);void qdev_prop_set_netdev (DeviceState *dev,const char *name,VLANClientState *value);void qdev_prop_set_vlan (DeviceState *dev,const char *name,VLANState *value);void qdev_prop_set_drive (DeviceState *dev,const char *name,DriveInfo *value);
net.h +5 -3
@@ -14,15 +14,17 @@ struct MACAddr {/* qdev nic properties */ typedef struct NICConf { +VLANClientState *client;MACAddr macaddr;VLANState *vlan;VLANClientState *peer; }NICConf ;#define DEFINE_NIC_PROPERTIES (_state, _conf) \ - DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr), \ - DEFINE_PROP_VLAN("vlan", _state, _conf.vlan), \ - DEFINE_PROP_NETDEV("netdev", _state, _conf.peer) + DEFINE_PROP_NET_CLIENT("net-client", _state, _conf.client), \ + DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr), \ + DEFINE_PROP_VLAN("vlan", _state, _conf.vlan), \ + DEFINE_PROP_NETDEV("netdev", _state, _conf.peer)/* VLANs support */
Signature · 1 line
1.6.2.5
[Qemu-devel] Re: [PATCH 2/7] qdev: add "net-client" property
Quoted 2 lines · Mark McLoughlin
Rather than having each NIC create it's own client, let's create the client early and pass it down to the NIC.
'-device $nic,net-client=$name' doesn't work ...
Quoted 3 lines
One advantage is that we can add parameters which only the client knows about, without having the NIC know anything about it - e.g. NICs shouldn't know about netdev vs. vlan.
What this is needed for?
Quoted 2 lines
Another advantage is that we can easily get the client associated with a qdev.
Looks like this is the *real* reason ...
cheers,
Gerd
PATCH 3/7 net: create the VLANClientState for NICs early
In reply to Mark McLoughlin--- hw/dp8393x.c | 10 +++++----- hw/e1000.c | 10 +++++----- hw/eepro100.c | 10 +++++----- hw/etraxfs_eth.c | 11 +++++------ hw/mcf_fec.c | 10 +++++----- hw/mipsnet.c | 15 ++++++--------- hw/musicpal.c | 10 +++++----- hw/ne2000-isa.c | 10 ++++++---- hw/ne2000.c | 11 +++++++---- hw/pcnet.c | 10 +++++----- hw/qdev.c | 3 +++ hw/rtl8139.c | 11 ++++++----- hw/smc91c111.c | 11 ++++++----- hw/stellaris_enet.c | 12 ++++++------ hw/usb-net.c | 12 +++++------- hw/virtio-net.c | 11 ++++++----- hw/xilinx_ethlite.c | 10 +++++----- net.c | 5 +++++ net.h | 1 + 19 files changed, 97 insertions(+), 86 deletions(-)
hw/dp8393x.c +5 -5
@@ -889,11 +889,11 @@ void dp83932_init(NICInfo *nd, target_phys_addr_t base, int it_shift, s->watchdog =qemu_new_timer (vm_clock, dp8393x_watchdog, s); s->regs[SONIC_SR ] =0x0004 ;/* only revision recognized by Linux */ - s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , - nd->vlan, nd->netdev, - nd->model, nd->name, - nic_can_receive, nic_receive,NULL ,NULL , - nic_cleanup, s); + s->vc = nd->vc; + s->vc->opaque = s; + s->vc->receive = nic_receive; + s->vc->can_receive = nic_can_receive; + s->vc->cleanup = nic_cleanup;qemu_format_nic_info_str (s->vc, nd->macaddr);qemu_register_reset (nic_reset, s);
hw/e1000.c +5 -5
@@ -1107,11 +1107,11 @@ static int pci_e1000_init(PCIDevice *pci_dev) checksum = (uint16_t )EEPROM_SUM - checksum; d->eeprom_data[EEPROM_CHECKSUM_REG ] = checksum; - d->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , - d->conf.vlan, d->conf.peer, - d->dev.qdev.info->name, d->dev.qdev.id, - e1000_can_receive, e1000_receive,NULL , -NULL , e1000_cleanup, d); + d->vc = d->conf.client; + d->vc->opaque = d; + d->vc->can_receive = e1000_can_receive; + d->vc->receive = e1000_receive; + d->vc->cleanup = e1000_cleanup; d->vc->link_status_changed = e1000_set_link_status;qemu_format_nic_info_str (d->vc, macaddr);
hw/eepro100.c +5 -5
@@ -1829,11 +1829,11 @@ static int nic_init(PCIDevice *pci_dev, uint32_t device)nic_reset (s); - s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , - s->conf.vlan, s->conf.peer, - pci_dev->qdev.info->name, pci_dev->qdev.id, - nic_can_receive, nic_receive,NULL ,NULL , - nic_cleanup, s); + s->vc = s->conf.client; + s->vc->opaque = s; + s->vc->can_receive = nic_can_receive; + s->vc->receive = nic_receive; + s->vc->cleanup = nic_cleanup;qemu_format_nic_info_str (s->vc, s->conf.macaddr.a);TRACE (OTHER ,logout ("%s\n" , s->vc->info_str));
hw/etraxfs_eth.c +5 -6
@@ -590,12 +590,11 @@ void *etraxfs_eth_init(NICInfo *nd, target_phys_addr_t base, int phyaddr) eth->ethregs =cpu_register_io_memory (eth_read, eth_write, eth);cpu_register_physical_memory (base,0x5c , eth->ethregs); - eth->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , - nd->vlan, nd->netdev, - nd->model, nd->name, - eth_can_receive, eth_receive, -NULL ,NULL , eth_cleanup, eth); - eth->vc->opaque = eth; + eth->vc = nd->vc; + eth->vc->opaque = eth; + eth->vc->receive = eth_receive; + eth->vc->can_receive = eth_can_receive; + eth->vc->cleanup = eth_cleanup; eth->vc->link_status_changed = eth_set_link;return dma;
hw/mcf_fec.c +5 -5
@@ -462,11 +462,11 @@ void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq) mcf_fec_writefn, s);cpu_register_physical_memory (base,0x400 , s->mmio_index); - s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , - nd->vlan, nd->netdev, - nd->model, nd->name, - mcf_fec_can_receive, mcf_fec_receive, -NULL ,NULL , mcf_fec_cleanup, s); + s->vc = nd->vc; + s->vc->opaque = s; + s->vc->receive = mcf_fec_receive; + s->vc->can_receive = mcf_fec_can_receive; + s->vc->cleanup = mcf_fec_cleanup;memcpy (s->macaddr, nd->macaddr,6 );qemu_format_nic_info_str (s->vc, s->macaddr); }
hw/mipsnet.c +6 -9
@@ -262,15 +262,12 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd) s->io_base = base; s->irq = irq; -if (nd) { - s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , - nd->vlan, nd->netdev, - nd->model, nd->name, - mipsnet_can_receive, mipsnet_receive, -NULL ,NULL , mipsnet_cleanup, s); - }else { - s->vc =NULL ; - } + + s->vc = nd->vc; + s->vc->opaque = s; + s->vc->receive = mipsnet_receive; + s->vc->can_receive = mipsnet_can_receive; + s->vc->cleanup = mipsnet_cleanup;qemu_format_nic_info_str (s->vc, nd->macaddr);
hw/musicpal.c +5 -5
@@ -377,11 +377,11 @@ static int mv88w8618_eth_init(SysBusDevice *dev)mv88w8618_eth_state *s =FROM_SYSBUS (mv88w8618_eth_state, dev);sysbus_init_irq (dev, &s->irq); - s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , - s->conf.vlan, s->conf.peer, - dev->qdev.info->name, dev->qdev.id, - eth_can_receive, eth_receive,NULL , -NULL , eth_cleanup, s); + s->vc = s->conf.client; + s->vc->opaque = s; + s->vc->receive = eth_receive; + s->vc->can_receive = eth_can_receive; + s->vc->cleanup = eth_cleanup; s->mmio_index =cpu_register_io_memory (mv88w8618_eth_readfn, mv88w8618_eth_writefn, s);sysbus_init_mmio (dev,MP_ETH_SIZE , s->mmio_index);
hw/ne2000-isa.c +6 -4
@@ -63,10 +63,12 @@ static int isa_ne2000_initfn(ISADevice *dev)qemu_macaddr_default_if_unset (&s->c.macaddr);ne2000_reset (s); - s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , s->c.vlan, s->c.peer, - dev->qdev.info->name, dev->qdev.id, - ne2000_can_receive, ne2000_receive,NULL , -NULL , isa_ne2000_cleanup, s); + s->vc = s->c.client; + s->vc->opaque = s; + s->vc->receive = ne2000_receive; + s->vc->can_receive = ne2000_can_receive; + s->vc->cleanup = isa_ne2000_cleanup; +qemu_format_nic_info_str (s->vc, s->c.macaddr.a);vmstate_register (-1 , &vmstate_ne2000, s);
hw/ne2000.c +7 -4
@@ -725,10 +725,13 @@ static int pci_ne2000_init(PCIDevice *pci_dev)qemu_macaddr_default_if_unset (&s->c.macaddr);ne2000_reset (s); - s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , s->c.vlan, s->c.peer, - pci_dev->qdev.info->name, pci_dev->qdev.id, - ne2000_can_receive, ne2000_receive,NULL , -NULL , ne2000_cleanup, s); + + s->vc = s->c.client; + s->vc->opaque = s; + s->vc->receive = ne2000_receive; + s->vc->can_receive = ne2000_can_receive; + s->vc->cleanup = ne2000_cleanup; +qemu_format_nic_info_str (s->vc, s->c.macaddr.a);if (!pci_dev->qdev.hotplugged) {
hw/pcnet.c +5 -5
@@ -1897,11 +1897,11 @@ int pcnet_common_init(DeviceState *dev, PCNetState *s, s->poll_timer =qemu_new_timer (vm_clock, pcnet_poll_timer, s);qemu_macaddr_default_if_unset (&s->conf.macaddr); - s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , - s->conf.vlan, s->conf.peer, - dev->info->name, dev->id, - pcnet_can_receive, pcnet_receive,NULL ,NULL , - cleanup, s); + s->vc = s->conf.client; + s->vc->opaque = s; + s->vc->receive = pcnet_receive; + s->vc->can_receive = pcnet_can_receive; + s->vc->cleanup = cleanup;qemu_format_nic_info_str (s->vc, s->conf.macaddr.a);return 0 ; }
hw/qdev.c +3 -0
@@ -366,6 +366,9 @@ void qdev_connect_gpio_out(DeviceState * dev, int n, qemu_irq pin)void qdev_set_nic_properties (DeviceState *dev,NICInfo *nd) {qdev_prop_set_macaddr (dev,"mac" , nd->macaddr); +if (nd->vc) { +qdev_prop_set_net_client (dev,"net-client" , nd->vc); + }if (nd->vlan)qdev_prop_set_vlan (dev,"vlan" , nd->vlan);if (nd->netdev)
hw/rtl8139.c +6 -5
@@ -3332,11 +3332,12 @@ static int pci_rtl8139_init(PCIDevice *dev)qemu_macaddr_default_if_unset (&s->conf.macaddr); - s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , - s->conf.vlan, s->conf.peer, - dev->qdev.info->name, dev->qdev.id, - rtl8139_can_receive, rtl8139_receive,NULL , -NULL , rtl8139_cleanup, s); + s->vc = s->conf.client; + s->vc->opaque = s; + s->vc->receive = rtl8139_receive; + s->vc->can_receive = rtl8139_can_receive; + s->vc->cleanup = rtl8139_cleanup; +qemu_format_nic_info_str (s->vc, s->conf.macaddr.a); s->cplus_txbuffer =NULL ;
hw/smc91c111.c +6 -5
@@ -711,11 +711,12 @@ static int smc91c111_init1(SysBusDevice *dev)smc91c111_reset (s); - s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , - s->conf.vlan, s->conf.peer, - dev->qdev.info->name, dev->qdev.id, - smc91c111_can_receive, smc91c111_receive,NULL , -NULL , smc91c111_cleanup, s); + s->vc = s->conf.client; + s->vc->opaque = s; + s->vc->receive = smc91c111_receive; + s->vc->can_receive = smc91c111_can_receive; + s->vc->cleanup = smc91c111_cleanup; +qemu_format_nic_info_str (s->vc, s->conf.macaddr.a);/* ??? Save/restore. */ return 0 ;
hw/stellaris_enet.c +6 -6
@@ -406,12 +406,12 @@ static int stellaris_enet_init(SysBusDevice *dev)sysbus_init_irq (dev, &s->irq);qemu_macaddr_default_if_unset (&s->conf.macaddr); - s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , - s->conf.vlan, s->conf.peer, - dev->qdev.info->name, dev->qdev.id, - stellaris_enet_can_receive, - stellaris_enet_receive,NULL ,NULL , - stellaris_enet_cleanup, s); + s->vc = s->conf.client; + s->vc->opaque = s; + s->vc->receive = stellaris_enet_receive; + s->vc->can_receive = stellaris_enet_can_receive; + s->vc->cleanup = stellaris_enet_cleanup; +qemu_format_nic_info_str (s->vc, s->conf.macaddr.a);stellaris_enet_reset (s);
hw/usb-net.c +5 -7
@@ -1460,13 +1460,11 @@ USBDevice *usb_net_init(NICInfo *nd)memcpy (s->mac, nd->macaddr,6 ); - s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , - nd->vlan, nd->netdev, - nd->model, nd->name, - usbnet_can_receive, - usbnet_receive, -NULL ,NULL , - usbnet_cleanup, s); + s->vc = nd->vc; + s->vc->opaque = s; + s->vc->receive = usbnet_receive; + s->vc->can_receive = usbnet_can_receive; + s->vc->cleanup = usbnet_cleanup;qemu_format_nic_info_str (s->vc, s->mac);
hw/virtio-net.c +6 -5
@@ -839,11 +839,12 @@ VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf)qemu_macaddr_default_if_unset (&conf->macaddr);memcpy (&n->mac[0 ], &conf->macaddr,sizeof (n->mac)); n->status =VIRTIO_NET_S_LINK_UP ; - n->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , conf->vlan, conf->peer, - dev->info->name, dev->id, - virtio_net_can_receive, - virtio_net_receive,NULL ,NULL , - virtio_net_cleanup, n); + + n->vc = conf->client; + n->vc->opaque = n; + n->vc->can_receive = virtio_net_can_receive; + n->vc->receive = virtio_net_receive; + n->vc->cleanup = virtio_net_cleanup; n->vc->link_status_changed = virtio_net_set_link_status;qemu_format_nic_info_str (n->vc, conf->macaddr.a);
hw/xilinx_ethlite.c +5 -5
@@ -220,11 +220,11 @@ static int xilinx_ethlite_init(SysBusDevice *dev)sysbus_init_mmio (dev,R_MAX *4 , regs);qemu_macaddr_default_if_unset (&s->conf.macaddr); - s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , - s->conf.vlan, s->conf.peer, - dev->qdev.info->name, dev->qdev.id, - eth_can_rx, eth_rx,NULL , -NULL , eth_cleanup, s); + s->vc = s->conf.client; + s->vc->opaque = s; + s->vc->receive = eth_rx; + s->vc->can_receive = eth_can_rx; + s->vc->cleanup = eth_cleanup;qemu_format_nic_info_str (s->vc, s->conf.macaddr.a);return 0 ; }
net.c +5 -0
@@ -2107,6 +2107,11 @@ static int net_init_nic(QemuOpts *opts,return -1 ; } + nd->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , + nd->vlan, nd->netdev, + nd->model, nd->name, +NULL ,NULL ,NULL , +NULL ,NULL ,NULL ); nd->used =1 ;if (vlan) { nd->vlan->nb_guest_devs++;
net.h +1 -0
@@ -126,6 +126,7 @@ struct NICInfo {char *devaddr;VLANState *vlan;VLANClientState *netdev; +VLANClientState *vc;void *private;int used;int bootable;
Signature · 1 line
1.6.2.5
[Qemu-devel] Re: [PATCH 3/7] net: create the VLANClientState for NICs early
Hi,
Quoted 11 lines
hw/e1000.c +0
-3@@ -1107,11 +1107,11 @@ static int pci_e1000_init(PCIDevice *pci_dev) checksum = (uint16_t )EEPROM_SUM - checksum; d->eeprom_data[EEPROM_CHECKSUM_REG ] = checksum; - d->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, - d->conf.vlan, d->conf.peer, - d->dev.qdev.info->name, d->dev.qdev.id,
hw/e1000.c static int pci_e1000_init(PCIDevice *pci_dev) · line 1117
Quoted 10 lines
hw/e1000.c +5
-2- e1000_can_receive, e1000_receive,NULL , - NULL, e1000_cleanup, d); + d->vc = d->conf.client; + d->vc->opaque = d; + d->vc->can_receive = e1000_can_receive; + d->vc->receive = e1000_receive; + d->vc->cleanup = e1000_cleanup; d->vc->link_status_changed = e1000_set_link_status;qemu_format_nic_info_str (d->vc, macaddr);
... and now -device $nic,args is completely broken.
There are netdev, vlan and net-client properties but none of them will work.
If you want to have net.c prepare vlanclientstate (there might be good reasons for it), then it must be properly:
* Create a named vlanclientstate.
* Have drivers lookup the vlanclientstate by name. Pretty much like the netdev peer lookup works today, only with the difference that it is used directly instead of being passed as peer on vlanclient creation.
i.e. something like
-netdev client,id=foo,<moreargs>
-device e1000,client=foo,mac=11:22:33:44:55:66
It is probably a good idea to zap the vlan and netdev properties then, so we don't have tons of different ways to setup a nic. Fortunaly we had no release with the vlan+netdev properties yet, so this shouldn't be a backward compatibility issue IMHO.
Also take care that the creation and destruction is symmetric. If net.c creates the vlanclient it should also net.c's job to clean it up, i.e. all the qemu_del_vlan_client() calls in the nic drivers should go away, otherwise hotplug will have some unpleasant surprises for you.
cheers,
Gerd
PATCH 4/7 net: kill off NICInfo/NICConf::vlan/netdev
In reply to Mark McLoughlinNo valid users left except the announce_self() code which currently crashes when used with -netdev.
Note the assertion in the xen code. Need to figure out how to support the -netdev arg with xen.
--- hw/integratorcp.c | 3 +- hw/mcf5208.c | 3 +- hw/mips_mipssim.c | 3 +- hw/mips_r4k.c | 3 +- hw/qdev-properties.c | 75 -------------------------------------------------- hw/qdev.c | 4 -- hw/qdev.h | 10 ------ hw/syborg.c | 2 +- hw/xen_devconfig.c | 9 +++-- net.c | 20 ++++++------ net.h | 8 +---- savevm.c | 4 ++ 12 files changed, 29 insertions(+), 115 deletions(-)
hw/integratorcp.c +2 -1
@@ -497,8 +497,9 @@ static void integratorcp_init(ram_addr_t ram_size,sysbus_create_simple ("pl050_keyboard" ,0x18000000 , pic[3 ]);sysbus_create_simple ("pl050_mouse" ,0x19000000 , pic[4 ]);sysbus_create_varargs ("pl181" ,0x1c000000 , pic[23 ], pic[24 ],NULL ); -if (nd_table[0 ].vlan) +if (nd_table[0 ].used) {smc91c111_init (&nd_table[0 ],0xc8000000 , pic[27 ]); + }sysbus_create_simple ("pl110" ,0xc0000000 , pic[22 ]);
hw/mcf5208.c +2 -1
@@ -239,8 +239,9 @@ static void mcf5208evb_init(ram_addr_t ram_size,fprintf (stderr,"Too many NICs\n" );exit (1 ); } -if (nd_table[0 ].vlan) +if (nd_table[0 ].used) {mcf_fec_init (&nd_table[0 ],0xfc030000 , pic +36 ); + }/* 0xfc000000 SCM. */ /* 0xfc004000 XBS. */
hw/mips_mipssim.c +2 -1
@@ -187,9 +187,10 @@ mips_mipssim_init (ram_addr_t ram_size,if (serial_hds[0 ])serial_init (0x3f8 , env->irq[4 ],115200 , serial_hds[0 ]); -if (nd_table[0 ].vlan) +if (nd_table[0 ].used) {/* MIPSnet uses the MIPS CPU INT0, which is interrupt 2. */ mipsnet_init (0x4200 , env->irq[2 ], &nd_table[0 ]); + } }static QEMUMachine mips_mipssim_machine = {
hw/mips_r4k.c +2 -1
@@ -265,8 +265,9 @@ void mips_r4k_init (ram_addr_t ram_size,isa_vga_init (); -if (nd_table[0 ].vlan) +if (nd_table[0 ].used) {isa_ne2000_init (0x300 ,9 , &nd_table[0 ]); + }if (drive_get_max_bus (IF_IDE ) >=MAX_IDE_BUS ) {fprintf (stderr,"qemu: too many IDE bus\n" );
hw/qdev-properties.c +0 -75
87 lines not on this page · raw message
hw/qdev.c +0 -4
@@ -369,10 +369,6 @@ void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd)if (nd->vc) {qdev_prop_set_net_client (dev,"net-client" , nd->vc); } -if (nd->vlan) -qdev_prop_set_vlan (dev,"vlan" , nd->vlan); -if (nd->netdev) -qdev_prop_set_netdev (dev,"netdev" , nd->netdev);if (nd->nvectors !=NIC_NVECTORS_UNSPECIFIED &&qdev_prop_exists (dev,"vectors" )) {qdev_prop_set_uint32 (dev,"vectors" , nd->nvectors);
hw/qdev.h +0 -10
@@ -80,8 +80,6 @@ enum PropertyType {PROP_TYPE_CHR ,PROP_TYPE_STRING ,PROP_TYPE_NET_CLIENT , -PROP_TYPE_NETDEV , -PROP_TYPE_VLAN , PROP_TYPE_PTR, };
@@ -196,8 +194,6 @@ extern PropertyInfo qdev_prop_ptr;extern PropertyInfo qdev_prop_macaddr;extern PropertyInfo qdev_prop_drive;extern PropertyInfo qdev_prop_net_client; -extern PropertyInfo qdev_prop_netdev; -extern PropertyInfo qdev_prop_vlan;extern PropertyInfo qdev_prop_pci_devfn;#define DEFINE_PROP (_name, _state, _field, _prop, _type) { \
@@ -239,10 +235,6 @@ extern PropertyInfo qdev_prop_pci_devfn; DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*) #define DEFINE_PROP_NET_CLIENT(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_net_client, VLANClientState *) -#define DEFINE_PROP_NETDEV(_n, _s, _f) \ - DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, VLANClientState*) -#define DEFINE_PROP_VLAN(_n, _s, _f) \ - DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, VLANState*) #define DEFINE_PROP_DRIVE(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_drive, DriveInfo*) #define DEFINE_PROP_MACADDR(_n, _s, _f) \
@@ -263,8 +255,6 @@ void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value);void qdev_prop_set_uint64 (DeviceState *dev,const char *name,uint64_t value);void qdev_prop_set_chr (DeviceState *dev,const char *name,CharDriverState *value);void qdev_prop_set_net_client (DeviceState *dev,const char *name,VLANClientState *value); -void qdev_prop_set_netdev (DeviceState *dev,const char *name,VLANClientState *value); -void qdev_prop_set_vlan (DeviceState *dev,const char *name,VLANState *value);void qdev_prop_set_drive (DeviceState *dev,const char *name,DriveInfo *value);void qdev_prop_set_macaddr (DeviceState *dev,const char *name,uint8_t *value);/* FIXME: Remove opaque pointer properties. */
hw/syborg.c +1 -1
@@ -77,7 +77,7 @@ static void syborg_init(ram_addr_t ram_size,sysbus_create_simple ("syborg,serial" ,0xC0008000 , pic[7 ]);sysbus_create_simple ("syborg,serial" ,0xC0009000 , pic[8 ]); -if (nd_table[0 ].vlan || nd_table[0 ].netdev) { +if (nd_table[0 ].used) {DeviceState *dev;SysBusDevice *s;
hw/xen_devconfig.c +5 -4
@@ -126,15 +126,16 @@ int xen_config_dev_nic(NICInfo *nic)snprintf (mac,sizeof (mac),"%02x:%02x:%02x:%02x:%02x:%02x" , nic->macaddr[0 ], nic->macaddr[1 ], nic->macaddr[2 ], nic->macaddr[3 ], nic->macaddr[4 ], nic->macaddr[5 ]); -xen_be_printf (NULL ,1 ,"config nic %d: mac=\"%s\"\n" , nic->vlan->id, mac); -xen_config_dev_dirs ("vif" ,"qnic" , nic->vlan->id, fe, be,sizeof (fe)); +assert (nic->vc && nic->vc->vlan); +xen_be_printf (NULL ,1 ,"config nic %d: mac=\"%s\"\n" , nic->vc->vlan->id, mac); +xen_config_dev_dirs ("vif" ,"qnic" , nic->vc->vlan->id, fe, be,sizeof (fe));/* frontend */ -xenstore_write_int (fe,"handle" , nic->vlan->id); +xenstore_write_int (fe,"handle" , nic->vc->vlan->id);xenstore_write_str (fe,"mac" , mac);/* backend */ -xenstore_write_int (be,"handle" , nic->vlan->id); +xenstore_write_int (be,"handle" , nic->vc->vlan->id);xenstore_write_str (be,"mac" , mac);/* common stuff */
net.c +10 -10
@@ -2055,7 +2055,8 @@ static int net_init_nic(QemuOpts *opts, {int idx;NICInfo *nd; -const char *netdev; +const char *netdev_str; +VLANClientState *netdev =NULL ; idx =nic_get_free_idx ();if (idx ==-1 || nb_nics >=MAX_NICS ) {
@@ -2067,15 +2068,14 @@ static int net_init_nic(QemuOpts *opts,memset (nd,0 ,sizeof (*nd)); -if ((netdev =qemu_opt_get (opts,"netdev" ))) { - nd->netdev =qemu_find_netdev (netdev); -if (!nd->netdev) { -qemu_error ("netdev '%s' not found\n" , netdev); +if ((netdev_str =qemu_opt_get (opts,"netdev" ))) { + netdev =qemu_find_netdev (netdev_str); +if (!netdev) { +qemu_error ("netdev '%s' not found\n" , netdev_str);return -1 ; } }else {assert (vlan); - nd->vlan = vlan; }if (name) { nd->name =qemu_strdup (name);
@@ -2108,13 +2108,13 @@ static int net_init_nic(QemuOpts *opts, } nd->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , - nd->vlan, nd->netdev, + vlan, netdev, nd->model, nd->name,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ); nd->used =1 ;if (vlan) { - nd->vlan->nb_guest_devs++; + vlan->nb_guest_devs++; } nb_nics++;
@@ -2651,8 +2651,8 @@ int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev)void net_client_uninit (NICInfo *nd) { -if (nd->vlan) { - nd->vlan->nb_guest_devs--; +if (nd->vc && nd->vc->vlan) { + nd->vc->vlan->nb_guest_devs--; } nb_nics--;
net.h +1 -7
@@ -16,15 +16,11 @@ struct MACAddr {typedef struct NICConf {VLANClientState *client;MACAddr macaddr; -VLANState *vlan; -VLANClientState *peer; }NICConf ;#define DEFINE_NIC_PROPERTIES (_state, _conf) \ DEFINE_PROP_NET_CLIENT("net-client", _state, _conf.client), \ - DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr), \ - DEFINE_PROP_VLAN("vlan", _state, _conf.vlan), \ - DEFINE_PROP_NETDEV("netdev", _state, _conf.peer) + DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr)/* VLANs support */
@@ -124,8 +120,6 @@ struct NICInfo {char *model;char *name;char *devaddr; -VLANState *vlan; -VLANClientState *netdev;VLANClientState *vc;void *private;int used;
savevm.c +4 -0
@@ -126,8 +126,10 @@ static int announce_self_create(uint8_t *buf,static void qemu_announce_self_once (void *opaque) {int i, len; +#ifdef FIXME VLANState *vlan;VLANClientState *vc; +#endif uint8_t buf[60 ];static int count =SELF_ANNOUNCE_ROUNDS ;QEMUTimer *timer = *(QEMUTimer **)opaque;
@@ -136,10 +138,12 @@ static void qemu_announce_self_once(void *opaque)if (!nd_table[i].used)continue ; len =announce_self_create (buf, nd_table[i].macaddr); +#ifdef FIXME vlan = nd_table[i].vlan; QTAILQ_FOREACH(vc, &vlan->clients, next) {qemu_send_packet_raw (vc, buf, len); } +#endif }if (--count) {/* delay 50ms, 150ms, 250ms, ... */
Signature · 1 line
1.6.2.5
PATCH 5/7 qdev: add qdev_foreach()
In reply to Mark McLoughlinNo doubt this is the worst idea ever, but the requirement is simple - some way to iterate all NICs in the system.
--- hw/qdev.c | 20 ++++++++++++++++++++ hw/qdev.h | 3 +++ 2 files changed, 23 insertions(+), 0 deletions(-)
hw/qdev.c +20 -0
@@ -401,6 +401,26 @@ BusState *qdev_get_child_bus(DeviceState *dev, const char *name)return NULL ; } +static void qdev_foreach_recursive (BusState *bus,qdev_foreach_func func,void *opaque) +{ +DeviceState *dev; + + QLIST_FOREACH(dev, &bus->children, sibling) { +BusState *child; + +func (dev, opaque); + + QLIST_FOREACH(child, &dev->child_bus, sibling) { +qdev_foreach_recursive (child, func, opaque); + } + } +} + +void qdev_foreach (qdev_foreach_func func,void *opaque) +{ +qdev_foreach_recursive (main_system_bus, func, opaque); +} +static BusState *qbus_find_recursive (BusState *bus,const char *name,const BusInfo *info) {
hw/qdev.h +3 -0
@@ -153,6 +153,9 @@ CharDriverState *qdev_init_chardev(DeviceState *dev);BusState *qdev_get_parent_bus (DeviceState *dev); +typedef void (*qdev_foreach_func )(DeviceState *dev,void *opaque); +void qdev_foreach (qdev_foreach_func func,void *opaque); +/* Convert from a base type to a parent type, with compile time checking. */ #ifdef __GNUC__#define DO_UPCAST (type, field, dev) ( __extension__ ( { \
Signature · 1 line
1.6.2.5
[Qemu-devel] Re: [PATCH 5/7] qdev: add qdev_foreach()
Quoted 2 lines · Mark McLoughlin
No doubt this is the worst idea ever, but the requirement is simple - some way to iterate all NICs in the system.
Doesn't have net.c a list of all vlanclientstates it could use instead?
cheers,
Gerd
[Qemu-devel] Re: [PATCH 5/7] qdev: add qdev_foreach()
Hi Gerd,
Thanks for looking, you're absolutely right that this approach just isn't right with e.g. -device
Quoted 5 lines · Gerd Hoffmann
Quoted 2 lines · Mark McLoughlin
No doubt this is the worst idea ever, but the requirement is simple - some way to iterate all NICs in the system.
Doesn't have
net.ca list of all vlanclientstates it could use instead?
It does, but there's currently no way of getting at each NIC's MAC address.
I've pushed a series of patches to the fix-announce-self-rfc.v2 branch on my tree:
http://repo.or.cz/w/qemu/markmc.git
The idea is to have a NICState struct:
struct NICState {
VLANClientState nc;
MACAddr *macaddr;
void *opaque;
};and similar structs for each net backend.
This way we can have a qemu_foreach_nic() which iterates over each client, checks whether it's a NIC and upcast to NICState.
Still a WIP, but how does that sound?
Thanks,
Mark.
[Qemu-devel] Re: [PATCH 5/7] qdev: add qdev_foreach()
Quoted 4 lines · Mark McLoughlin
I've pushed a series of patches to the fix-announce-self-rfc.v2 branch on my tree:
http://repo.or.cz/w/qemu/markmc.git
Looks much better.
If you have a special version for nics anyway (qemu_new_nic) you can have that one take a NICConf parameter I think.
Is it possible to have NICState embedded, i.e.
typedef struct E1000State_st {
[ ... ]
NICState nic;
[ ... ]
};instead of 'NICState *nic' ?
cheers,
Gerd
PATCH 6/7 qdev: add qdev_prop_get_{macaddr, net_client}()
In reply to Mark McLoughlinProbably the second worst idea in the world, ever.
While iterating over all NICs in the system, we need to be able to query their 'net-client' and 'macaddr' properties.
--- hw/qdev-properties.c | 31 ++++++++++++++++++++++++++++--- hw/qdev.h | 3 +++ 2 files changed, 31 insertions(+), 3 deletions(-)
hw/qdev-properties.c +28 -3
@@ -458,10 +458,10 @@ int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)return prop->info->parse (dev, prop, value); } -void qdev_prop_set (DeviceState *dev,const char *name,void *src,enum PropertyType type) +static void *qdev_prop_get (DeviceState *dev,const char *name, +enum PropertyType type,Property **prop_ret) {Property *prop; -void *dst; prop =qdev_prop_find (dev, name);if (!prop) {
@@ -474,7 +474,20 @@ void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyT __FUNCTION__, dev->info->name, name);abort (); } - dst =qdev_get_prop_ptr (dev, prop); + +if (prop_ret) { + *prop_ret = prop; + } + +return qdev_get_prop_ptr (dev, prop); +} + +void qdev_prop_set (DeviceState *dev,const char *name,void *src,enum PropertyType type) +{ +Property *prop; +void *dst; + + dst =qdev_prop_get (dev, name, type, &prop);memcpy (dst, src, prop->info->size); }
@@ -518,11 +531,23 @@ void qdev_prop_set_net_client(DeviceState *dev, const char *name, VLANClientStatqdev_prop_set (dev, name, &value,PROP_TYPE_NET_CLIENT ); } +VLANClientState *qdev_prop_get_net_client (DeviceState *dev,const char *name) +{ +VLANClientState **clientp =qdev_prop_get (dev, name,PROP_TYPE_NET_CLIENT ,NULL ); +return *clientp; +} +void qdev_prop_set_macaddr (DeviceState *dev,const char *name,uint8_t *value) {qdev_prop_set (dev, name, value,PROP_TYPE_MACADDR ); } +uint8_t *qdev_prop_get_macaddr (DeviceState *dev,const char *name) +{ +uint8_t *mac =qdev_prop_get (dev, name,PROP_TYPE_MACADDR ,NULL ); +return mac; +} +void qdev_prop_set_ptr (DeviceState *dev,const char *name,void *value) {qdev_prop_set (dev, name, &value,PROP_TYPE_PTR );
hw/qdev.h +3 -0
@@ -267,6 +267,9 @@ void qdev_prop_set_defaults(DeviceState *dev, Property *props);void qdev_prop_register_compat (CompatProperty *props);void qdev_prop_set_compat (DeviceState *dev); +VLANClientState *qdev_prop_get_net_client (DeviceState *dev,const char *name); +uint8_t *qdev_prop_get_macaddr (DeviceState *dev,const char *name); +/* This is a nasty hack to allow passing a NULL bus to qdev_create. */ extern struct BusInfo system_bus_info;
Signature · 1 line
1.6.2.5
PATCH 7/7 net: fix qemu_announce_self()
In reply to Mark McLoughlinNow that we have a sane way of iterating over NICs.
--- savevm.c | 43 ++++++++++++++++++++++++++----------------- 1 files changed, 26 insertions(+), 17 deletions(-)
savevm.c +26 -17
@@ -75,6 +75,7 @@#include "qemu-common.h" #include "hw/hw.h" +#include "hw/qdev.h" #include "net.h" #include "monitor.h" #include "sysemu.h"
@@ -123,28 +124,36 @@ static int announce_self_create(uint8_t *buf,return 60 ;/* len (FCS will be added by hardware) */ } -static void qemu_announce_self_once (void *opaque) +static void qemu_announce_self_iter (DeviceState *dev,void *opaque) { -int i, len; -#ifdef FIXME -VLANState *vlan; -VLANClientState *vc; -#endif +VLANClientState *client; +uint8_t *mac;uint8_t buf[60 ]; +int len; + +if (!qdev_prop_exists (dev,"net-client" )) { +return ; + } + + client =qdev_prop_get_net_client (dev,"net-client" ); + mac =qdev_prop_get_macaddr (dev,"mac" ); + +printf ("qemu_announce_self_iter() mac = %p\n" , mac); + + len =announce_self_create (buf, mac); + +printf ("sending packet from %s\n" , client->name); + +qemu_send_packet_raw (client, buf, len); +} + +static void qemu_announce_self_once (void *opaque) +{static int count =SELF_ANNOUNCE_ROUNDS ;QEMUTimer *timer = *(QEMUTimer **)opaque; -for (i =0 ; i <MAX_NICS ; i++) { -if (!nd_table[i].used) -continue ; - len =announce_self_create (buf, nd_table[i].macaddr); -#ifdef FIXME - vlan = nd_table[i].vlan; - QTAILQ_FOREACH(vc, &vlan->clients, next) { -qemu_send_packet_raw (vc, buf, len); - } -#endif - } +qdev_foreach (qemu_announce_self_iter,NULL ); +if (--count) {/* delay 50ms, 150ms, 250ms, ... */ qemu_mod_timer(timer, qemu_get_clock(rt_clock) +
Signature · 1 line
1.6.2.5
Re: [Qemu-devel] [PATCH 7/7] net: fix qemu_announce_self()
On Thu, 2009-11-12 at 20:29 +0000, Mark McLoughlin wrote:
...
savevm.c static int announce_self_create(uint8_t *buf, · line 145
Quoted 5 lines
savevm.c +5
-0+printf ("qemu_announce_self_iter() mac = %p\n" , mac); + + len =announce_self_create (buf, mac); + +printf ("sending packet from %s\n" , client->name);
Ooops, some debugging leftovers. removed in my tree.
Cheers,
Mark.
Re: [Qemu-devel] [PATCH 7/7] net: fix qemu_announce_self()
In reply to Mark McLoughlinQuoted 29 lines · Mark McLoughlin
Now that we have a sane way of iterating over NICs.
Signed-off-by Mark McLoughlin <[email protected]>--- savevm.c | 43 ++++++++++++++++++++++++++----------------- 1 files changed, 26 insertions(+), 17 deletions(-)savevm.c +2
-4@@ -75,6 +75,7 @@#include "qemu-common.h" #include "hw/hw.h" +#include "hw/qdev.h" #include "net.h" #include "monitor.h" #include "sysemu.h" @@ -123,28 +124,36 @@ static int announce_self_create(uint8_t *buf,return 60 ;/* len (FCS will be added by hardware) */ } -static void qemu_announce_self_once (void *opaque) +static void qemu_announce_self_iter (DeviceState *dev,void *opaque) { -int i, len; -#ifdef FIXME -VLANState *vlan;
savevm.c static int announce_self_create(uint8_t *buf, · line 136
Quoted 10 lines
savevm.c +7
-2-VLANClientState *vc; -#endif +VLANClientState *client; +uint8_t *mac;uint8_t buf[60 ]; +int len; + +if (!qdev_prop_exists (dev,"net-client" )) { +return ; + }
This is an ad-hoc "is this a NIC" test. It assumes all NICs have a "net-client" property (trivial), and that no other kind of device ever has a "net-client" property (reasonable). But, as we accumulate more of this type of tests, we'll accumulate more of these assumptions, and having them spread over the code could be confusing. What about collecting the "is this a DEVICE_KIND" tests in one place?
For the record, I still believe that identifying device kind by testing presence of properties is suboptimal[*], but we got more important fish to fry.
savevm.c static int announce_self_create(uint8_t *buf, · line 148
Quoted 12 lines
savevm.c +12
-0+ + client =qdev_prop_get_net_client (dev,"net-client" ); + mac =qdev_prop_get_macaddr (dev,"mac" ); + +printf ("qemu_announce_self_iter() mac = %p\n" , mac); + + len =announce_self_create (buf, mac); + +printf ("sending packet from %s\n" , client->name); + +qemu_send_packet_raw (client, buf, len); +}
[...]
[*] There's no way to test "is this a watchdog" by testing presence of properties. Ability to identify watchdog devices would let us kill watchdog_list.