[7150] Introduce VLANClientState::cleanup() (Mark McLoughlin)
Revision: 7150
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=7150 Author: aliguori Date: 2009-04-17 17:11:08 +0000 (Fri, 17 Apr 2009)
Log Message:
-----------
Introduce VLANClientState::cleanup() (Mark McLoughlin)
We're currently leaking memory and file descriptors on device hot-unplug.
Modified Paths:
--------------
trunk/hw/dp8393x.c
trunk/hw/e1000.c
trunk/hw/eepro100.c
trunk/hw/etraxfs_eth.c
trunk/hw/mcf_fec.c
trunk/hw/mipsnet.c
trunk/hw/musicpal.c
trunk/hw/ne2000.c
trunk/hw/pcnet.c
trunk/hw/rtl8139.c
trunk/hw/smc91c111.c
trunk/hw/stellaris_enet.c
trunk/hw/usb-net.c
trunk/hw/virtio-net.c
trunk/hw/virtio.c
trunk/hw/virtio.h
trunk/net.c
trunk/net.h
trunk/tap-win32.cModified: trunk/hw/dp8393x.c
===================================================================
hw/dp8393x.c +16 -4
@@ -156,6 +156,7 @@QEMUTimer *watchdog;int64_t wt_last_update;VLANClientState *vc; +int mmio_index;/* Registers */ uint8_t cam[16 ][6 ];
@@ -858,12 +859,23 @@dp8393x_update_irq (s); } +static void nic_cleanup (VLANClientState *vc) +{ +dp8393xState *s = vc->opaque; + +cpu_unregister_io_memory (s->mmio_index); + +qemu_del_timer (s->watchdog); +qemu_free_timer (s->watchdog); + +qemu_free (s); +} +void dp83932_init (NICInfo *nd,target_phys_addr_t base,int it_shift,qemu_irq irq,void * mem_opaque,void (*memory_rw)(void *opaque,target_phys_addr_t addr,uint8_t *buf,int len,int is_write)) {dp8393xState *s; -int io;qemu_check_nic_model (nd,"dp83932" );
@@ -877,12 +889,12 @@ s->regs[SONIC_SR ] =0x0004 ;/* only revision recognized by Linux */ s->vc =qemu_new_vlan_client (nd->vlan, nd->model, nd->name, - nic_receive, nic_can_receive, s); + nic_receive, nic_can_receive, nic_cleanup, s);qemu_format_nic_info_str (s->vc, nd->macaddr);qemu_register_reset (nic_reset, s);nic_reset (s); - io =cpu_register_io_memory (0 , dp8393x_read, dp8393x_write, s); -cpu_register_physical_memory (base,0x40 << it_shift, io); + s->mmio_index =cpu_register_io_memory (0 , dp8393x_read, dp8393x_write, s); +cpu_register_physical_memory (base,0x40 << it_shift, s->mmio_index); }
Modified: trunk/hw/e1000.c
===================================================================
hw/e1000.c +10 -1
@@ -1033,6 +1033,14 @@ excluded_regs[i] - 4); } +static void +e1000_cleanup (VLANClientState *vc) +{ +E1000State *d = vc->opaque; + +unregister_savevm ("e1000" , d); +} +static int pci_e1000_uninit (PCIDevice *dev) {
@@ -1094,7 +1102,8 @@memset (&d->tx,0 ,sizeof d->tx); d->vc =qemu_new_vlan_client (nd->vlan, nd->model, nd->name, - e1000_receive, e1000_can_receive, d); + e1000_receive, e1000_can_receive, + e1000_cleanup, d); d->vc->link_status_changed = e1000_set_link_status;qemu_format_nic_info_str (d->vc, nd->macaddr);
Modified: trunk/hw/eepro100.c
===================================================================
hw/eepro100.c +22 -1
@@ -1710,6 +1710,25 @@qemu_put_buffer (f, s->configuration,sizeof (s->configuration)); } +static void nic_cleanup (VLANClientState *vc) +{ +EEPRO100State *s = vc->opaque; + +unregister_savevm (vc->model, s); + +eeprom93xx_free (s->eeprom); +} + +static int pci_nic_uninit (PCIDevice *dev) +{ +PCIEEPRO100State *d = (PCIEEPRO100State *) dev; +EEPRO100State *s = &d->eepro100; + +cpu_unregister_io_memory (s->mmio_index); + +return 0 ; +} +static PCIDevice *nic_init (PCIBus * bus,NICInfo * nd,uint32_t device) {PCIEEPRO100State *d;
@@ -1720,6 +1739,7 @@ d = (PCIEEPRO100State *)pci_register_device (bus, nd->model,sizeof (PCIEEPRO100State),-1 ,NULL ,NULL ); + d->dev.unregister = pci_nic_uninit; s = &d->eepro100; s->device = device;
@@ -1750,7 +1770,8 @@nic_reset (s); s->vc =qemu_new_vlan_client (nd->vlan, nd->model, nd->name, - nic_receive, nic_can_receive, s); + nic_receive, nic_can_receive, + nic_cleanup, s);qemu_format_nic_info_str (s->vc, s->macaddr);
Modified: trunk/hw/etraxfs_eth.c
===================================================================
hw/etraxfs_eth.c +12 -1
@@ -554,6 +554,16 @@ ð_writel, }; +static void eth_cleanup (VLANClientState *vc) +{ +struct fs_eth *eth = vc->opaque; + +cpu_unregister_io_memory (eth->ethregs); + +qemu_free (eth->dma_out); +qemu_free (eth); +} +void *etraxfs_eth_init (NICInfo *nd,CPUState *env,qemu_irq *irq,target_phys_addr_t base,int phyaddr) {
@@ -585,7 +595,8 @@cpu_register_physical_memory (base,0x5c , eth->ethregs); eth->vc =qemu_new_vlan_client (nd->vlan, nd->model, nd->name, - eth_receive, eth_can_receive, eth); + eth_receive, eth_can_receive, + eth_cleanup, eth); eth->vc->opaque = eth; eth->vc->link_status_changed = eth_set_link;
Modified: trunk/hw/mcf_fec.c
===================================================================
hw/mcf_fec.c +15 -5
@@ -24,6 +24,7 @@ typedef struct { qemu_irq *irq; + int mmio_index; VLANClientState *vc; uint32_t irq_state; uint32_t eir;
@@ -441,21 +442,30 @@mcf_fec_write }; +static void mcf_fec_cleanup (VLANClientState *vc) +{ +mcf_fec_state *s = vc->opaque; + +cpu_unregister_io_memory (s->mmio_index); + +qemu_free (s); +} +void mcf_fec_init (NICInfo *nd,target_phys_addr_t base,qemu_irq *irq) {mcf_fec_state *s; -int iomemtype;qemu_check_nic_model (nd,"mcf_fec" ); s = (mcf_fec_state *)qemu_mallocz (sizeof (mcf_fec_state)); s->irq = irq; - iomemtype =cpu_register_io_memory (0 , mcf_fec_readfn, - mcf_fec_writefn, s); -cpu_register_physical_memory (base,0x400 , iomemtype); + s->mmio_index =cpu_register_io_memory (0 , mcf_fec_readfn, + mcf_fec_writefn, s); +cpu_register_physical_memory (base,0x400 , s->mmio_index); s->vc =qemu_new_vlan_client (nd->vlan, nd->model, nd->name, - mcf_fec_receive, mcf_fec_can_receive, s); + mcf_fec_receive, mcf_fec_can_receive, + mcf_fec_cleanup, s);memcpy (s->macaddr, nd->macaddr,6 );qemu_format_nic_info_str (s->vc, s->macaddr); }
Modified: trunk/hw/mipsnet.c
===================================================================
hw/mipsnet.c +15 -1
@@ -33,6 +33,7 @@uint32_t intctl;uint8_t rx_buffer[MAX_ETH_FRAME_SIZE ];uint8_t tx_buffer[MAX_ETH_FRAME_SIZE ]; +int io_base;qemu_irq irq;VLANClientState *vc; } MIPSnetState;
@@ -231,6 +232,17 @@return 0 ; } +static void mipsnet_cleanup (VLANClientState *vc) +{ +MIPSnetState *s = vc->opaque; + +unregister_savevm ("mipsnet" , s); + +isa_unassign_ioport (s->io_base,36 ); + +qemu_free (s); +} +void mipsnet_init (int base,qemu_irq irq,NICInfo *nd) {MIPSnetState *s;
@@ -246,10 +258,12 @@register_ioport_write (base,36 ,4 , mipsnet_ioport_write, s);register_ioport_read (base,36 ,4 , mipsnet_ioport_read, s); + s->io_base = base; s->irq = irq;if (nd && nd->vlan) { s->vc =qemu_new_vlan_client (nd->vlan, nd->model, nd->name, - mipsnet_receive, mipsnet_can_receive, s); + mipsnet_receive, mipsnet_can_receive, + mipsnet_cleanup, s); }else { s->vc =NULL ; }
Modified: trunk/hw/musicpal.c
===================================================================
hw/musicpal.c +15 -5
@@ -536,6 +536,7 @@uint32_t smir;uint32_t icr;uint32_t imr; +int mmio_index;int vlan_header;uint32_t tx_queue[2 ];uint32_t rx_queue[4 ];
@@ -745,20 +746,29 @@ mv88w8618_eth_write }; +static void eth_cleanup (VLANClientState *vc) +{ +mv88w8618_eth_state *s = vc->opaque; + +cpu_unregister_io_memory (s->mmio_index); + +qemu_free (s); +} +static void mv88w8618_eth_init (NICInfo *nd,uint32_t base,qemu_irq irq) {mv88w8618_eth_state *s; -int iomemtype;qemu_check_nic_model (nd,"mv88w8618" ); s =qemu_mallocz (sizeof (mv88w8618_eth_state)); s->irq = irq; s->vc =qemu_new_vlan_client (nd->vlan, nd->model, nd->name, - eth_receive, eth_can_receive, s); - iomemtype =cpu_register_io_memory (0 , mv88w8618_eth_readfn, - mv88w8618_eth_writefn, s); -cpu_register_physical_memory (base,MP_ETH_SIZE , iomemtype); + eth_receive, eth_can_receive, + eth_cleanup, s); + s->mmio_index =cpu_register_io_memory (0 , mv88w8618_eth_readfn, + mv88w8618_eth_writefn, s); +cpu_register_physical_memory (base,MP_ETH_SIZE , s->mmio_index); }/* LCD register offsets */
Modified: trunk/hw/ne2000.c
===================================================================
hw/ne2000.c +26 -2
@@ -140,6 +140,7 @@uint8_t curpag;uint8_t mult[8 ];/* multicast mask array */ qemu_irq irq; +int isa_io_base;PCIDevice *pci_dev;VLANClientState *vc;uint8_t macaddr[6 ];
@@ -718,6 +719,19 @@return 0 ; } +static void isa_ne2000_cleanup (VLANClientState *vc) +{ +NE2000State *s = vc->opaque; + +unregister_savevm ("ne2000" , s); + +isa_unassign_ioport (s->isa_io_base,16 ); +isa_unassign_ioport (s->isa_io_base +0x10 ,2 ); +isa_unassign_ioport (s->isa_io_base +0x1f ,1 ); + +qemu_free (s); +} +void isa_ne2000_init (int base,qemu_irq irq,NICInfo *nd) {NE2000State *s;
@@ -736,13 +750,15 @@register_ioport_write (base +0x1f ,1 ,1 , ne2000_reset_ioport_write, s);register_ioport_read (base +0x1f ,1 ,1 , ne2000_reset_ioport_read, s); + s->isa_io_base = base; s->irq = irq;memcpy (s->macaddr, nd->macaddr,6 );ne2000_reset (s); s->vc =qemu_new_vlan_client (nd->vlan, nd->model, nd->name, - ne2000_receive, ne2000_can_receive, s); + ne2000_receive, ne2000_can_receive, + isa_ne2000_cleanup, s);qemu_format_nic_info_str (s->vc, s->macaddr);
@@ -777,6 +793,13 @@register_ioport_read (addr +0x1f ,1 ,1 , ne2000_reset_ioport_read, s); } +static void ne2000_cleanup (VLANClientState *vc) +{ +NE2000State *s = vc->opaque; + +unregister_savevm ("ne2000" , s); +} +PCIDevice *pci_ne2000_init (PCIBus *bus,NICInfo *nd,int devfn) {PCINE2000State *d;
@@ -802,7 +825,8 @@memcpy (s->macaddr, nd->macaddr,6 );ne2000_reset (s); s->vc =qemu_new_vlan_client (nd->vlan, nd->model, nd->name, - ne2000_receive, ne2000_can_receive, s); + ne2000_receive, ne2000_can_receive, + ne2000_cleanup, s);qemu_format_nic_info_str (s->vc, s->macaddr);
Modified: trunk/hw/pcnet.c
===================================================================
hw/pcnet.c +49 -9
119 lines not on this page · raw message
Modified: trunk/hw/rtl8139.c
===================================================================
hw/rtl8139.c +30 -1
@@ -3414,6 +3414,33 @@ }#endif /* RTL8139_ONBOARD_TIMER */ +static void rtl8139_cleanup (VLANClientState *vc) +{ +RTL8139State *s = vc->opaque; + +if (s->cplus_txbuffer) { +qemu_free (s->cplus_txbuffer); + s->cplus_txbuffer =NULL ; + } + +#ifdef RTL8139_ONBOARD_TIMER +qemu_del_timer (s->timer); +qemu_free_timer (s->timer); +#endif + +unregister_savevm ("rtl8139" , s); +} + +static int pci_rtl8139_uninit (PCIDevice *dev) +{ +PCIRTL8139State *d = (PCIRTL8139State *)dev; +RTL8139State *s = &d->rtl8139; + +cpu_unregister_io_memory (s->rtl8139_mmio_io_addr); + +return 0 ; +} +PCIDevice *pci_rtl8139_init (PCIBus *bus,NICInfo *nd,int devfn) {PCIRTL8139State *d;
@@ -3424,6 +3451,7 @@"RTL8139" ,sizeof (PCIRTL8139State), devfn, NULL, NULL); + d->dev.unregister = pci_rtl8139_uninit; pci_conf = d->dev.config;pci_config_set_vendor_id (pci_conf,PCI_VENDOR_ID_REALTEK );pci_config_set_device_id (pci_conf,PCI_DEVICE_ID_REALTEK_8139 );
@@ -3450,7 +3478,8 @@memcpy (s->macaddr, nd->macaddr,6 );rtl8139_reset (s); s->vc =qemu_new_vlan_client (nd->vlan, nd->model, nd->name, - rtl8139_receive, rtl8139_can_receive, s); + rtl8139_receive, rtl8139_can_receive, + rtl8139_cleanup, s);qemu_format_nic_info_str (s->vc, s->macaddr);
Modified: trunk/hw/smc91c111.c
===================================================================
hw/smc91c111.c +14 -5
@@ -42,6 +42,7 @@uint8_t int_level;uint8_t int_mask;uint8_t macaddr[6 ]; +int mmio_index; } smc91c111_state;#define RCR_SOFT_RST 0x8000
@@ -690,24 +691,32 @@smc91c111_writel }; +static void smc91c111_cleanup (VLANClientState *vc) +{ +smc91c111_state *s = vc->opaque; + +cpu_unregister_io_memory (s->mmio_index); +qemu_free (s); +} +void smc91c111_init (NICInfo *nd,uint32_t base,qemu_irq irq) {smc91c111_state *s; -int iomemtype;qemu_check_nic_model (nd,"smc91c111" ); s = (smc91c111_state *)qemu_mallocz (sizeof (smc91c111_state)); - iomemtype =cpu_register_io_memory (0 , smc91c111_readfn, - smc91c111_writefn, s); -cpu_register_physical_memory (base,16 , iomemtype); + s->mmio_index =cpu_register_io_memory (0 , smc91c111_readfn, + smc91c111_writefn, s); +cpu_register_physical_memory (base,16 , s->mmio_index); s->irq = irq;memcpy (s->macaddr, nd->macaddr,6 );smc91c111_reset (s); s->vc =qemu_new_vlan_client (nd->vlan, nd->model, nd->name, - smc91c111_receive, smc91c111_can_receive, s); + smc91c111_receive, smc91c111_can_receive, + smc91c111_cleanup, s);qemu_format_nic_info_str (s->vc, s->macaddr);/* ??? Save/restore. */ }
Modified: trunk/hw/stellaris_enet.c
===================================================================
hw/stellaris_enet.c +18 -5
@@ -69,6 +69,7 @@VLANClientState *vc;qemu_irq irq;uint8_t macaddr[6 ]; +int mmio_index; } stellaris_enet_state;static void stellaris_enet_update (stellaris_enet_state *s)
@@ -384,23 +385,35 @@return 0 ; } +static void stellaris_enet_cleanup (VLANClientState *vc) +{ +stellaris_enet_state *s = vc->opaque; + +unregister_savevm ("stellaris_enet" , s); + +cpu_unregister_io_memory (s->mmio_index); + +qemu_free (s); +} +void stellaris_enet_init (NICInfo *nd,uint32_t base,qemu_irq irq) {stellaris_enet_state *s; -int iomemtype;qemu_check_nic_model (nd,"stellaris" ); s = (stellaris_enet_state *)qemu_mallocz (sizeof (stellaris_enet_state)); - iomemtype =cpu_register_io_memory (0 , stellaris_enet_readfn, - stellaris_enet_writefn, s); -cpu_register_physical_memory (base,0x00001000 , iomemtype); + s->mmio_index =cpu_register_io_memory (0 , stellaris_enet_readfn, + stellaris_enet_writefn, s); +cpu_register_physical_memory (base,0x00001000 , s->mmio_index); s->irq = irq;memcpy (s->macaddr, nd->macaddr,6 );if (nd->vlan) { s->vc =qemu_new_vlan_client (nd->vlan, nd->model, nd->name, - stellaris_enet_receive, stellaris_enet_can_receive, s); + stellaris_enet_receive, + stellaris_enet_can_receive, + stellaris_enet_cleanup, s);qemu_format_nic_info_str (s->vc, s->macaddr); }
Modified: trunk/hw/usb-net.c
===================================================================
hw/usb-net.c +11 -3
@@ -1415,14 +1415,20 @@return !s->in_len; } +static void usbnet_cleanup (VLANClientState *vc) +{ +USBNetState *s = vc->opaque; + +rndis_clear_responsequeue (s); +qemu_free (s); +} +static void usb_net_handle_destroy (USBDevice *dev) {USBNetState *s = (USBNetState *) dev;/* TODO: remove the nd_table[] entry */ qemu_del_vlan_client (s->vc); -rndis_clear_responsequeue (s); -qemu_free (s); }USBDevice *usb_net_init (NICInfo *nd)
@@ -1452,7 +1458,9 @@pstrcpy (s->dev.devname,sizeof (s->dev.devname),"QEMU USB Network Interface" ); s->vc =qemu_new_vlan_client (nd->vlan, nd->model, nd->name, - usbnet_receive, usbnet_can_receive, s); + usbnet_receive, + usbnet_can_receive, + usbnet_cleanup, s);qemu_format_nic_info_str (s->vc, s->mac);
Modified: trunk/hw/virtio-net.c
===================================================================
hw/virtio-net.c +18 -1
@@ -570,6 +570,21 @@return 0 ; } +static void virtio_net_cleanup (VLANClientState *vc) +{ +VirtIONet *n = vc->opaque; + +unregister_savevm ("virtio-net" , n); + +qemu_free (n->mac_table.macs); +qemu_free (n->vlans); + +qemu_del_timer (n->tx_timer); +qemu_free_timer (n->tx_timer); + +virtio_cleanup (&n->vdev); +} +PCIDevice *virtio_net_init (PCIBus *bus,NICInfo *nd,int devfn) {VirtIONet *n;
@@ -598,7 +613,9 @@memcpy (n->mac, nd->macaddr,ETH_ALEN ); n->status =VIRTIO_NET_S_LINK_UP ; n->vc =qemu_new_vlan_client (nd->vlan, nd->model, nd->name, - virtio_net_receive, virtio_net_can_receive, n); + virtio_net_receive, + virtio_net_can_receive, + virtio_net_cleanup, n); n->vc->link_status_changed = virtio_net_set_link_status;qemu_format_nic_info_str (n->vc, n->mac);
Modified: trunk/hw/virtio.c
===================================================================
hw/virtio.c +7 -0
@@ -750,6 +750,13 @@virtio_update_irq (vdev); } +void virtio_cleanup (VirtIODevice *vdev) +{ +if (vdev->config) +qemu_free (vdev->config); +qemu_free (vdev->vq); +} + VirtIODevice *virtio_init_pci(PCIBus *bus, const char *name, uint16_t vendor, uint16_t device, uint16_t subvendor, uint16_t subdevice,
Modified: trunk/hw/virtio.h
===================================================================
hw/virtio.h +2 -0
@@ -117,6 +117,8 @@void virtio_load (VirtIODevice *vdev,QEMUFile *f); +void virtio_cleanup (VirtIODevice *vdev); +void virtio_notify_config (VirtIODevice *vdev);void virtio_queue_set_notification (VirtQueue *vq,int enable);
Modified: trunk/net.c
===================================================================
net.c +50 -21
157 lines not on this page · raw message
Modified: trunk/net.h
===================================================================
net.h +3 -0
@@ -9,6 +9,7 @@typedef struct VLANClientState VLANClientState ; +typedef void (NetCleanup ) (VLANClientState *);typedef void (LinkStatusChanged )(VLANClientState *);struct VLANClientState {
@@ -17,6 +18,7 @@/* Packets may still be sent if this returns zero. It's used to rate-limit the slirp code. */ IOCanRWHandler *fd_can_read; +NetCleanup *cleanup;LinkStatusChanged *link_status_changed;int link_down;void *opaque;
@@ -40,6 +42,7 @@const char *name, IOReadHandler *fd_read, IOCanRWHandler *fd_can_read, + NetCleanup *cleanup, void *opaque);void qemu_del_vlan_client (VLANClientState *vc);VLANClientState *qemu_find_vlan_client (VLANState *vlan,void *opaque);
Modified: trunk/tap-win32.c
===================================================================
tap-win32.c +14 -1
@@ -638,6 +638,18 @@tap_win32_overlapped_t *handle; } TAPState; +static void tap_cleanup (VLANClientState *vc) +{ +TAPState *s = vc->opaque; + +qemu_del_wait_object (s->handle->tap_semaphore,NULL ,NULL ); + +/* FIXME: need to kill thread and close file handle: +tap_win32_close(s); +*/ +qemu_free (s); +} +static void tap_receive (void *opaque,const uint8_t *buf,int size) {TAPState *s = opaque;
@@ -672,7 +684,8 @@return -1 ; } - s->vc =qemu_new_vlan_client (vlan, model, name, tap_receive,NULL , s); + s->vc =qemu_new_vlan_client (vlan, model, name, tap_receive, +NULL , tap_cleanup, s);snprintf (s->vc->info_str,sizeof (s->vc->info_str),"tap: ifname=%s" , ifname);